[PATCH v5 13/20] firmware: arm_scmi: refactor in preparation to support per-protocol channels

2018-02-12 Thread Sudeep Holla
In order to support per-protocol channels if available, we need to
factor out all the mailbox channel information(Tx/Rx payload and
channel handle) out of the main SCMI instance information structure.

This patch refactors the existing channel information into a separate
chan_info structure.

Cc: Arnd Bergmann 
Cc: Greg Kroah-Hartman 
Signed-off-by: Sudeep Holla 
---
 drivers/firmware/arm_scmi/driver.c | 86 --
 1 file changed, 54 insertions(+), 32 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c 
b/drivers/firmware/arm_scmi/driver.c
index 0108bb39d0f6..5dd54f72b587 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -102,6 +102,22 @@ struct scmi_desc {
 };
 
 /**
+ * struct scmi_chan_info - Structure representing a SCMI channel informfation
+ *
+ * @cl: Mailbox Client
+ * @chan: Transmit/Receive mailbox channel
+ * @payload: Transmit/Receive mailbox channel payload area
+ * @dev: Reference to device in the SCMI hierarchy corresponding to this
+ *  channel
+ */
+struct scmi_chan_info {
+   struct mbox_client cl;
+   struct mbox_chan *chan;
+   void __iomem *payload;
+   struct device *dev;
+};
+
+/**
  * struct scmi_info - Structure representing a  SCMI instance
  *
  * @dev: Device pointer
@@ -109,10 +125,8 @@ struct scmi_desc {
  * @handle: Instance of SCMI handle to send to clients
  * @version: SCMI revision information containing protocol version,
  * implementation version and (sub-)vendor identification.
- * @cl: Mailbox Client
- * @tx_chan: Transmit mailbox channel
- * @tx_payload: Transmit mailbox channel payload area
  * @minfo: Message info
+ * @tx_cinfo: Reference to SCMI channel information
  * @protocols_imp: list of protocols implemented, currently maximum of
  * MAX_PROTOCOLS_IMP elements allocated by the base protocol
  * @node: list head
@@ -123,16 +137,14 @@ struct scmi_info {
const struct scmi_desc *desc;
struct scmi_revision_info version;
struct scmi_handle handle;
-   struct mbox_client cl;
-   struct mbox_chan *tx_chan;
-   void __iomem *tx_payload;
struct scmi_xfers_info minfo;
+   struct scmi_chan_info *tx_cinfo;
u8 *protocols_imp;
struct list_head node;
int users;
 };
 
-#define client_to_scmi_info(c) container_of(c, struct scmi_info, cl)
+#define client_to_scmi_chan_info(c) container_of(c, struct scmi_chan_info, cl)
 #define handle_to_scmi_info(h) container_of(h, struct scmi_info, handle)
 
 /*
@@ -215,10 +227,11 @@ static void scmi_rx_callback(struct mbox_client *cl, void 
*m)
 {
u16 xfer_id;
struct scmi_xfer *xfer;
-   struct scmi_info *info = client_to_scmi_info(cl);
+   struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl);
+   struct device *dev = cinfo->dev;
+   struct scmi_info *info = dev_get_drvdata(dev);
struct scmi_xfers_info *minfo = >minfo;
-   struct device *dev = info->dev;
-   struct scmi_shared_mem __iomem *mem = info->tx_payload;
+   struct scmi_shared_mem __iomem *mem = cinfo->payload;
 
xfer_id = MSG_XTRACT_TOKEN(ioread32(>msg_header));
 
@@ -269,8 +282,8 @@ static inline u32 pack_scmi_header(struct scmi_msg_hdr *hdr)
 static void scmi_tx_prepare(struct mbox_client *cl, void *m)
 {
struct scmi_xfer *t = m;
-   struct scmi_info *info = client_to_scmi_info(cl);
-   struct scmi_shared_mem __iomem *mem = info->tx_payload;
+   struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl);
+   struct scmi_shared_mem __iomem *mem = cinfo->payload;
 
/* Mark channel busy + clear error */
iowrite32(0x0, >channel_status);
@@ -349,15 +362,15 @@ void scmi_one_xfer_put(const struct scmi_handle *handle, 
struct scmi_xfer *xfer)
 }
 
 static bool
-scmi_xfer_poll_done(const struct scmi_info *info, struct scmi_xfer *xfer)
+scmi_xfer_poll_done(const struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
 {
-   struct scmi_shared_mem *mem = info->tx_payload;
-   u16 xfer_id = MSG_XTRACT_TOKEN(le32_to_cpu(mem->msg_header));
+   struct scmi_shared_mem __iomem *mem = cinfo->payload;
+   u16 xfer_id = MSG_XTRACT_TOKEN(ioread32(>msg_header));
 
if (xfer->hdr.seq != xfer_id)
return false;
 
-   return le32_to_cpu(mem->channel_status) &
+   return ioread32(>channel_status) &
(SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR |
SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE);
 }
@@ -379,8 +392,9 @@ int scmi_do_xfer(const struct scmi_handle *handle, struct 
scmi_xfer *xfer)
int timeout;
struct scmi_info *info = handle_to_scmi_info(handle);
struct device *dev = info->dev;
+   struct scmi_chan_info *cinfo = info->tx_cinfo;
 
-   ret = mbox_send_message(info->tx_chan, xfer);
+   ret = mbox_send_message(cinfo->chan, xfer);
if (ret < 0) {
  

[PATCH v5 13/20] firmware: arm_scmi: refactor in preparation to support per-protocol channels

2018-02-12 Thread Sudeep Holla
In order to support per-protocol channels if available, we need to
factor out all the mailbox channel information(Tx/Rx payload and
channel handle) out of the main SCMI instance information structure.

This patch refactors the existing channel information into a separate
chan_info structure.

Cc: Arnd Bergmann 
Cc: Greg Kroah-Hartman 
Signed-off-by: Sudeep Holla 
---
 drivers/firmware/arm_scmi/driver.c | 86 --
 1 file changed, 54 insertions(+), 32 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c 
b/drivers/firmware/arm_scmi/driver.c
index 0108bb39d0f6..5dd54f72b587 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -102,6 +102,22 @@ struct scmi_desc {
 };
 
 /**
+ * struct scmi_chan_info - Structure representing a SCMI channel informfation
+ *
+ * @cl: Mailbox Client
+ * @chan: Transmit/Receive mailbox channel
+ * @payload: Transmit/Receive mailbox channel payload area
+ * @dev: Reference to device in the SCMI hierarchy corresponding to this
+ *  channel
+ */
+struct scmi_chan_info {
+   struct mbox_client cl;
+   struct mbox_chan *chan;
+   void __iomem *payload;
+   struct device *dev;
+};
+
+/**
  * struct scmi_info - Structure representing a  SCMI instance
  *
  * @dev: Device pointer
@@ -109,10 +125,8 @@ struct scmi_desc {
  * @handle: Instance of SCMI handle to send to clients
  * @version: SCMI revision information containing protocol version,
  * implementation version and (sub-)vendor identification.
- * @cl: Mailbox Client
- * @tx_chan: Transmit mailbox channel
- * @tx_payload: Transmit mailbox channel payload area
  * @minfo: Message info
+ * @tx_cinfo: Reference to SCMI channel information
  * @protocols_imp: list of protocols implemented, currently maximum of
  * MAX_PROTOCOLS_IMP elements allocated by the base protocol
  * @node: list head
@@ -123,16 +137,14 @@ struct scmi_info {
const struct scmi_desc *desc;
struct scmi_revision_info version;
struct scmi_handle handle;
-   struct mbox_client cl;
-   struct mbox_chan *tx_chan;
-   void __iomem *tx_payload;
struct scmi_xfers_info minfo;
+   struct scmi_chan_info *tx_cinfo;
u8 *protocols_imp;
struct list_head node;
int users;
 };
 
-#define client_to_scmi_info(c) container_of(c, struct scmi_info, cl)
+#define client_to_scmi_chan_info(c) container_of(c, struct scmi_chan_info, cl)
 #define handle_to_scmi_info(h) container_of(h, struct scmi_info, handle)
 
 /*
@@ -215,10 +227,11 @@ static void scmi_rx_callback(struct mbox_client *cl, void 
*m)
 {
u16 xfer_id;
struct scmi_xfer *xfer;
-   struct scmi_info *info = client_to_scmi_info(cl);
+   struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl);
+   struct device *dev = cinfo->dev;
+   struct scmi_info *info = dev_get_drvdata(dev);
struct scmi_xfers_info *minfo = >minfo;
-   struct device *dev = info->dev;
-   struct scmi_shared_mem __iomem *mem = info->tx_payload;
+   struct scmi_shared_mem __iomem *mem = cinfo->payload;
 
xfer_id = MSG_XTRACT_TOKEN(ioread32(>msg_header));
 
@@ -269,8 +282,8 @@ static inline u32 pack_scmi_header(struct scmi_msg_hdr *hdr)
 static void scmi_tx_prepare(struct mbox_client *cl, void *m)
 {
struct scmi_xfer *t = m;
-   struct scmi_info *info = client_to_scmi_info(cl);
-   struct scmi_shared_mem __iomem *mem = info->tx_payload;
+   struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl);
+   struct scmi_shared_mem __iomem *mem = cinfo->payload;
 
/* Mark channel busy + clear error */
iowrite32(0x0, >channel_status);
@@ -349,15 +362,15 @@ void scmi_one_xfer_put(const struct scmi_handle *handle, 
struct scmi_xfer *xfer)
 }
 
 static bool
-scmi_xfer_poll_done(const struct scmi_info *info, struct scmi_xfer *xfer)
+scmi_xfer_poll_done(const struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
 {
-   struct scmi_shared_mem *mem = info->tx_payload;
-   u16 xfer_id = MSG_XTRACT_TOKEN(le32_to_cpu(mem->msg_header));
+   struct scmi_shared_mem __iomem *mem = cinfo->payload;
+   u16 xfer_id = MSG_XTRACT_TOKEN(ioread32(>msg_header));
 
if (xfer->hdr.seq != xfer_id)
return false;
 
-   return le32_to_cpu(mem->channel_status) &
+   return ioread32(>channel_status) &
(SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR |
SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE);
 }
@@ -379,8 +392,9 @@ int scmi_do_xfer(const struct scmi_handle *handle, struct 
scmi_xfer *xfer)
int timeout;
struct scmi_info *info = handle_to_scmi_info(handle);
struct device *dev = info->dev;
+   struct scmi_chan_info *cinfo = info->tx_cinfo;
 
-   ret = mbox_send_message(info->tx_chan, xfer);
+   ret = mbox_send_message(cinfo->chan, xfer);
if (ret < 0) {
dev_dbg(dev, "mbox send fail %d\n", ret);

[PATCH v5 13/20] firmware: arm_scmi: refactor in preparation to support per-protocol channels

2018-01-02 Thread Sudeep Holla
In order to support per-protocol channels if available, we need to
factor out all the mailbox channel information(Tx/Rx payload and
channel handle) out of the main SCMI instance information structure.

This patch refactors the existing channel information into a separate
chan_info structure.

Cc: Arnd Bergmann 
Signed-off-by: Sudeep Holla 
---
 drivers/firmware/arm_scmi/driver.c | 86 --
 1 file changed, 54 insertions(+), 32 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c 
b/drivers/firmware/arm_scmi/driver.c
index 0c9dda72f10c..24acb421208c 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -105,6 +105,22 @@ struct scmi_desc {
 };
 
 /**
+ * struct scmi_chan_info - Structure representing a SCMI channel informfation
+ *
+ * @cl: Mailbox Client
+ * @chan: Transmit/Receive mailbox channel
+ * @payload: Transmit/Receive mailbox channel payload area
+ * @dev: Reference to device in the SCMI hierarchy corresponding to this
+ *  channel
+ */
+struct scmi_chan_info {
+   struct mbox_client cl;
+   struct mbox_chan *chan;
+   void __iomem *payload;
+   struct device *dev;
+};
+
+/**
  * struct scmi_info - Structure representing a  SCMI instance
  *
  * @dev: Device pointer
@@ -112,10 +128,8 @@ struct scmi_desc {
  * @handle: Instance of SCMI handle to send to clients
  * @version: SCMI revision information containing protocol version,
  * implementation version and (sub-)vendor identification.
- * @cl: Mailbox Client
- * @tx_chan: Transmit mailbox channel
- * @tx_payload: Transmit mailbox channel payload area
  * @minfo: Message info
+ * @tx_cinfo: Reference to SCMI channel information
  * @protocols_imp: list of protocols implemented, currently maximum of
  * MAX_PROTOCOLS_IMP elements allocated by the base protocol
  * @node: list head
@@ -126,16 +140,14 @@ struct scmi_info {
const struct scmi_desc *desc;
struct scmi_revision_info version;
struct scmi_handle handle;
-   struct mbox_client cl;
-   struct mbox_chan *tx_chan;
-   void __iomem *tx_payload;
struct scmi_xfers_info minfo;
+   struct scmi_chan_info *tx_cinfo;
u8 *protocols_imp;
struct list_head node;
int users;
 };
 
-#define client_to_scmi_info(c) container_of(c, struct scmi_info, cl)
+#define client_to_scmi_chan_info(c) container_of(c, struct scmi_chan_info, cl)
 #define handle_to_scmi_info(h) container_of(h, struct scmi_info, handle)
 
 /*
@@ -218,10 +230,11 @@ static void scmi_rx_callback(struct mbox_client *cl, void 
*m)
 {
u16 xfer_id;
struct scmi_xfer *xfer;
-   struct scmi_info *info = client_to_scmi_info(cl);
+   struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl);
+   struct device *dev = cinfo->dev;
+   struct scmi_info *info = dev_get_drvdata(dev);
struct scmi_xfers_info *minfo = >minfo;
-   struct device *dev = info->dev;
-   struct scmi_shared_mem __iomem *mem = info->tx_payload;
+   struct scmi_shared_mem __iomem *mem = cinfo->payload;
 
xfer_id = MSG_XTRACT_TOKEN(ioread32(>msg_header));
 
@@ -272,8 +285,8 @@ static inline u32 pack_scmi_header(struct scmi_msg_hdr *hdr)
 static void scmi_tx_prepare(struct mbox_client *cl, void *m)
 {
struct scmi_xfer *t = m;
-   struct scmi_info *info = client_to_scmi_info(cl);
-   struct scmi_shared_mem __iomem *mem = info->tx_payload;
+   struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl);
+   struct scmi_shared_mem __iomem *mem = cinfo->payload;
 
/* Mark channel busy + clear error */
iowrite32(0x0, >channel_status);
@@ -366,15 +379,15 @@ void scmi_one_xfer_put(const struct scmi_handle *handle, 
struct scmi_xfer *xfer)
 }
 
 static bool
-scmi_xfer_poll_done(const struct scmi_info *info, struct scmi_xfer *xfer)
+scmi_xfer_poll_done(const struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
 {
-   struct scmi_shared_mem *mem = info->tx_payload;
-   u16 xfer_id = MSG_XTRACT_TOKEN(le32_to_cpu(mem->msg_header));
+   struct scmi_shared_mem __iomem *mem = cinfo->payload;
+   u16 xfer_id = MSG_XTRACT_TOKEN(ioread32(>msg_header));
 
if (xfer->hdr.seq != xfer_id)
return false;
 
-   return le32_to_cpu(mem->channel_status) &
+   return ioread32(>channel_status) &
(SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR |
SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE);
 }
@@ -396,8 +409,9 @@ int scmi_do_xfer(const struct scmi_handle *handle, struct 
scmi_xfer *xfer)
int timeout;
struct scmi_info *info = handle_to_scmi_info(handle);
struct device *dev = info->dev;
+   struct scmi_chan_info *cinfo = info->tx_cinfo;
 
-   ret = mbox_send_message(info->tx_chan, xfer);
+   ret = mbox_send_message(cinfo->chan, xfer);
if (ret < 0) {
dev_dbg(dev, "mbox send fail %d\n", ret);

[PATCH v5 13/20] firmware: arm_scmi: refactor in preparation to support per-protocol channels

2018-01-02 Thread Sudeep Holla
In order to support per-protocol channels if available, we need to
factor out all the mailbox channel information(Tx/Rx payload and
channel handle) out of the main SCMI instance information structure.

This patch refactors the existing channel information into a separate
chan_info structure.

Cc: Arnd Bergmann 
Signed-off-by: Sudeep Holla 
---
 drivers/firmware/arm_scmi/driver.c | 86 --
 1 file changed, 54 insertions(+), 32 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c 
b/drivers/firmware/arm_scmi/driver.c
index 0c9dda72f10c..24acb421208c 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -105,6 +105,22 @@ struct scmi_desc {
 };
 
 /**
+ * struct scmi_chan_info - Structure representing a SCMI channel informfation
+ *
+ * @cl: Mailbox Client
+ * @chan: Transmit/Receive mailbox channel
+ * @payload: Transmit/Receive mailbox channel payload area
+ * @dev: Reference to device in the SCMI hierarchy corresponding to this
+ *  channel
+ */
+struct scmi_chan_info {
+   struct mbox_client cl;
+   struct mbox_chan *chan;
+   void __iomem *payload;
+   struct device *dev;
+};
+
+/**
  * struct scmi_info - Structure representing a  SCMI instance
  *
  * @dev: Device pointer
@@ -112,10 +128,8 @@ struct scmi_desc {
  * @handle: Instance of SCMI handle to send to clients
  * @version: SCMI revision information containing protocol version,
  * implementation version and (sub-)vendor identification.
- * @cl: Mailbox Client
- * @tx_chan: Transmit mailbox channel
- * @tx_payload: Transmit mailbox channel payload area
  * @minfo: Message info
+ * @tx_cinfo: Reference to SCMI channel information
  * @protocols_imp: list of protocols implemented, currently maximum of
  * MAX_PROTOCOLS_IMP elements allocated by the base protocol
  * @node: list head
@@ -126,16 +140,14 @@ struct scmi_info {
const struct scmi_desc *desc;
struct scmi_revision_info version;
struct scmi_handle handle;
-   struct mbox_client cl;
-   struct mbox_chan *tx_chan;
-   void __iomem *tx_payload;
struct scmi_xfers_info minfo;
+   struct scmi_chan_info *tx_cinfo;
u8 *protocols_imp;
struct list_head node;
int users;
 };
 
-#define client_to_scmi_info(c) container_of(c, struct scmi_info, cl)
+#define client_to_scmi_chan_info(c) container_of(c, struct scmi_chan_info, cl)
 #define handle_to_scmi_info(h) container_of(h, struct scmi_info, handle)
 
 /*
@@ -218,10 +230,11 @@ static void scmi_rx_callback(struct mbox_client *cl, void 
*m)
 {
u16 xfer_id;
struct scmi_xfer *xfer;
-   struct scmi_info *info = client_to_scmi_info(cl);
+   struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl);
+   struct device *dev = cinfo->dev;
+   struct scmi_info *info = dev_get_drvdata(dev);
struct scmi_xfers_info *minfo = >minfo;
-   struct device *dev = info->dev;
-   struct scmi_shared_mem __iomem *mem = info->tx_payload;
+   struct scmi_shared_mem __iomem *mem = cinfo->payload;
 
xfer_id = MSG_XTRACT_TOKEN(ioread32(>msg_header));
 
@@ -272,8 +285,8 @@ static inline u32 pack_scmi_header(struct scmi_msg_hdr *hdr)
 static void scmi_tx_prepare(struct mbox_client *cl, void *m)
 {
struct scmi_xfer *t = m;
-   struct scmi_info *info = client_to_scmi_info(cl);
-   struct scmi_shared_mem __iomem *mem = info->tx_payload;
+   struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl);
+   struct scmi_shared_mem __iomem *mem = cinfo->payload;
 
/* Mark channel busy + clear error */
iowrite32(0x0, >channel_status);
@@ -366,15 +379,15 @@ void scmi_one_xfer_put(const struct scmi_handle *handle, 
struct scmi_xfer *xfer)
 }
 
 static bool
-scmi_xfer_poll_done(const struct scmi_info *info, struct scmi_xfer *xfer)
+scmi_xfer_poll_done(const struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
 {
-   struct scmi_shared_mem *mem = info->tx_payload;
-   u16 xfer_id = MSG_XTRACT_TOKEN(le32_to_cpu(mem->msg_header));
+   struct scmi_shared_mem __iomem *mem = cinfo->payload;
+   u16 xfer_id = MSG_XTRACT_TOKEN(ioread32(>msg_header));
 
if (xfer->hdr.seq != xfer_id)
return false;
 
-   return le32_to_cpu(mem->channel_status) &
+   return ioread32(>channel_status) &
(SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR |
SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE);
 }
@@ -396,8 +409,9 @@ int scmi_do_xfer(const struct scmi_handle *handle, struct 
scmi_xfer *xfer)
int timeout;
struct scmi_info *info = handle_to_scmi_info(handle);
struct device *dev = info->dev;
+   struct scmi_chan_info *cinfo = info->tx_cinfo;
 
-   ret = mbox_send_message(info->tx_chan, xfer);
+   ret = mbox_send_message(cinfo->chan, xfer);
if (ret < 0) {
dev_dbg(dev, "mbox send fail %d\n", ret);
return ret;
@@ -413,11