MPFS system controller/mailbox fixes
Subsystems (4)
Conor Dooley
maintainerv2 cover MPFS system controller/mailbox fixes
Hey Jassi, all,
Here are some fixes for the system controller on PolarFire SoC that I ran into while implementing support for using the system controller to re-program the FPGA. A few are just minor bits that I fixed in passing, but the bulk of the patchset is changes to how the mailbox figures out if a "service" has completed.
Prior to implementing this particular functionality, the services requested from the system controller, via its mailbox interface, always triggered an interrupt when the system controller was finished with the service.
Unfortunately some of the services used to validate the FPGA images before programming them do not trigger an interrupt if they fail. For example, the service that checks whether an FPGA image is actually a newer version than what is already programmed, does not trigger an interrupt, unless the image is actually newer than the one currently programmed. If it has an earlier version, no interrupt is triggered and a status is set in the system controller's status register to signify the reason for the failure.
In order to differentiate between the service succeeding & the system controller being inoperative or otherwise unable to function, I had to switch the controller to poll a busy bit in the system controller's registers to see if it has completed a service.
This makes sense anyway, as the interrupt corresponds to "data ready" rather than "tx done", so I have changed the mailbox controller driver to do that & left the interrupt solely for signalling data ready. It just so happened that all of the services that I had worked with and tested up to this point were "infallible" & did not set a status, so the particular code paths were never tested.
Jassi, the mailbox and soc patches depend on each other, as the change in what the interrupt is used for requires changing the client driver's behaviour too, as mbox_send_message() will now return when the system controller is no longer busy rather than when the data is ready. I'm happy to send the lot via the soc tree with your Ack and/or reivew, if that also works you?
Secondly, I have a question about what to do if a service does fail, but not due to a timeout - eg the above example where the "new" image for the FPGA is actually older than the one that currently exists. Ideally, if a service fails due to something other than the transaction timing out, I would go and read the status registers to see what the cause of failure was.
I could not find a function in the mailbox framework that allows the client to request that sort of information from the client. Trying to do something with the auxiliary bus, or exporting some function to a device specific header seemed like a circumvention of the mailbox framework.
Do you think it would be a good idea to implement something like mbox_client_peek_status(struct mbox_chan *chan, void *data) to allow clients to request this type of information?
It'd certainly allow me to report the actual errors to the drivers implementing the service & make better decisions there about how to proceed.
Perhaps I have missed some way of doing this kind of thing that (should have been) staring me in the face!
Thanks,
Conor.
Changes in v2:
- up the timeout to 30 seconds, as required for services like image validation, which may vary significantly in execution time
- fixed a typo!
Conor Dooley (7):
mailbox: mpfs: fix an incorrect mask width
mailbox: mpfs: switch to txdone_poll
mailbox: mpfs: ditch a useless busy check
soc: microchip: mpfs: fix some horrible alignment
soc: microchip: mpfs: use a consistent completion timeout
soc: microchip: mpfs: simplify error handling in
mpfs_blocking_transaction()
soc: microchip: mpfs: handle timeouts and failed services differently
drivers/mailbox/mailbox-mpfs.c | 25 ++++++---- drivers/soc/microchip/mpfs-sys-controller.c | 52 ++++++++++++++------- 2 files changed, 51 insertions(+), 26 deletions(-)
base-commit: 88603b6dc419445847923fcb7fe5080067a30f98
Signature · 7 lines
2.39.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Conor Dooley
maintainerPATCH v2 1/7 mailbox: mpfs: fix an incorrect mask width
The system controller registers on PolarFire SoC are 32 bits wide, so 16 + 16 as the first input to GENMASK_ULL() gives a 33 bit wide mask. It probably should have been immediately obvious when it was pointed out during review that the width required using GENMASK_ULL() - but I scarcely knew what I was doing at the time and missed it. The mistake ends up being moot as it is a mask after all, but it is incorrect and should be fixed.
No functional change intended.
--- drivers/mailbox/mailbox-mpfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mailbox/mailbox-mpfs.c +2 -1
@@ -39,7 +39,7 @@#define SCB_CTRL_NOTIFY_MASK BIT(SCB_CTRL_NOTIFY)#define SCB_CTRL_POS (16) -#define SCB_CTRL_MASK GENMASK_ULL(SCB_CTRL_POS + SCB_MASK_WIDTH, SCB_CTRL_POS) +#define SCB_CTRL_MASK GENMASK(SCB_CTRL_POS + SCB_MASK_WIDTH - 1, SCB_CTRL_POS)/* SCBCTRL service status register */
@@ -118,6 +118,7 @@ static int mpfs_mbox_send_data(struct mbox_chan *chan, void *data) } opt_sel = ((msg->mbox_offset <<7u ) | (msg->cmd_opcode &0x7fu )); + tx_trigger = (opt_sel <<SCB_CTRL_POS ) &SCB_CTRL_MASK ; tx_trigger |=SCB_CTRL_REQ_MASK |SCB_STATUS_NOTIFY_MASK ;writel_relaxed (tx_trigger, mbox->ctrl_base +SERVICES_CR_OFFSET );
Signature · 7 lines
2.39.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Conor Dooley
maintainerPATCH v2 2/7 mailbox: mpfs: switch to txdone_poll
In reply to Conor DooleyThe system controller on PolarFire SoC has no interrupt to signify that the TX has been completed. The interrupt instead signals that a service requested by the mailbox client has succeeded. If a service fails, there will be no interrupt delivered.
Switch to polling the busy register to determine whether transmission has completed.
--- drivers/mailbox/mailbox-mpfs.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/mailbox/mailbox-mpfs.c +10 -2
@@ -79,6 +79,13 @@ static bool mpfs_mbox_busy(struct mpfs_mbox *mbox)return status &SCB_STATUS_BUSY_MASK ; } +static bool mpfs_mbox_last_tx_done (struct mbox_chan *chan) +{ +struct mpfs_mbox *mbox = (struct mpfs_mbox *)chan->con_priv; + +return !mpfs_mbox_busy (mbox); +} +static int mpfs_mbox_send_data (struct mbox_chan *chan,void *data) {struct mpfs_mbox *mbox = (struct mpfs_mbox *)chan->con_priv;
@@ -183,7 +190,6 @@ static irqreturn_t mpfs_mbox_inbox_isr(int irq, void *data)mpfs_mbox_rx_data (chan); -mbox_chan_txdone (chan,0 );return IRQ_HANDLED ; }
@@ -213,6 +219,7 @@ static const struct mbox_chan_ops mpfs_mbox_ops = { .send_data = mpfs_mbox_send_data, .startup = mpfs_mbox_startup, .shutdown = mpfs_mbox_shutdown, + .last_tx_done = mpfs_mbox_last_tx_done, };static int mpfs_mbox_probe (struct platform_device *pdev)
@@ -248,7 +255,8 @@ static int mpfs_mbox_probe(struct platform_device *pdev) mbox->controller.num_chans =1 ; mbox->controller.chans = mbox->chans; mbox->controller.ops = &mpfs_mbox_ops; - mbox->controller.txdone_irq = true; + mbox->controller.txdone_poll = true; + mbox->controller.txpoll_period =10u ; ret =devm_mbox_controller_register (&pdev->dev, &mbox->controller);if (ret) {
Signature · 1 line
2.39.0
Conor Dooley
maintainerPATCH v2 3/7 mailbox: mpfs: ditch a useless busy check
In reply to Conor Dooleympfs_mbox_rx_data() already checks if the system controller is busy before attempting to do anything, so drop the second check before reading any data.
No functional change intended.
--- drivers/mailbox/mailbox-mpfs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/mailbox/mailbox-mpfs.c +4 -6
@@ -170,12 +170,10 @@ static void mpfs_mbox_rx_data(struct mbox_chan *chan)if (response->resp_status)return ; -if (!mpfs_mbox_busy (mbox)) { -for (i =0 ; i < num_words; i++) { - response->resp_msg[i] = -readl_relaxed (mbox->mbox_base - + mbox->resp_offset + i *0x4 ); - } +for (i =0 ; i < num_words; i++) { + response->resp_msg[i] = +readl_relaxed (mbox->mbox_base + + mbox->resp_offset + i *0x4 ); }mbox_chan_received_data (chan, response);
Signature · 7 lines
2.39.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Conor Dooley
maintainerPATCH v2 4/7 soc: microchip: mpfs: fix some horrible alignment
In reply to Conor Dooleympfs_sys_controller_delete() has some horrible alignment that upsets my OCD... Move the RHS of the assignment to a new line for greater satifaction.
--- drivers/soc/microchip/mpfs-sys-controller.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/microchip/mpfs-sys-controller.c +2 -2
@@ -66,8 +66,8 @@ static void rx_callback(struct mbox_client *client, void *msg)static void mpfs_sys_controller_delete (struct kref *kref) { - struct mpfs_sys_controller *sys_controller = container_of(kref, struct mpfs_sys_controller, - consumers); +struct mpfs_sys_controller *sys_controller = + container_of(kref, struct mpfs_sys_controller, consumers);mbox_free_channel (sys_controller->chan);kfree (sys_controller);
Signature · 1 line
2.39.0
Conor Dooley
maintainerPATCH v2 5/7 soc: microchip: mpfs: use a consistent completion timeout
In reply to Conor DooleyCompletion timeouts use jiffies, so passing a number directly will produce inconsistent timeouts depending on config. Define the timeout in ms and convert it to jiffies instead.
Since a define is being created where one previously did not exist, pick a suitable timeout duration. Most services will complete nearly immediately, but those relating to image verification and re-programming the FPGA take significant amounts of time. 30 seconds is a suitable timeout for those situations, although most services will complete in under 100 ms.
--- drivers/soc/microchip/mpfs-sys-controller.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/soc/microchip/mpfs-sys-controller.c +9 -1
@@ -11,12 +11,19 @@#include <linux/slab.h> #include <linux/kref.h> #include <linux/module.h> +#include <linux/jiffies.h> #include <linux/interrupt.h> #include <linux/of_platform.h> #include <linux/mailbox_client.h> #include <linux/platform_device.h> #include <soc/microchip/mpfs.h> +/* +* This timeout must be long, as some services (example: image authentication) +* take many seconds to complete +*/ +#define MPFS_SYS_CTRL_TIMEOUT_MS 30000 +static DEFINE_MUTEX (transaction_lock);struct mpfs_sys_controller {
@@ -28,6 +35,7 @@ struct mpfs_sys_controller {int mpfs_blocking_transaction (struct mpfs_sys_controller *sys_controller,struct mpfs_mss_msg *msg) { +unsigned long timeout =msecs_to_jiffies (MPFS_SYS_CTRL_TIMEOUT_MS );int ret, err; err =mutex_lock_interruptible (&transaction_lock);
@@ -38,7 +46,7 @@ int mpfs_blocking_transaction(struct mpfs_sys_controller *sys_controller, struct ret =mbox_send_message (sys_controller->chan, msg);if (ret >=0 ) { -if (wait_for_completion_timeout (&sys_controller->c,HZ )) { +if (wait_for_completion_timeout (&sys_controller->c, timeout)) { ret =0 ; }else { ret = -ETIMEDOUT ;
Signature · 7 lines
2.39.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Conor Dooley
maintainerPATCH v2 6/7 soc: microchip: mpfs: simplify error handling in mpfs_blocking_transaction()
In reply to Conor DooleyThe error handling has a kinda weird nested-if setup that is not really adding anything. Switch it to more of an early return arrangement as a predatory step for adding different handing for timeouts and failed services.
--- drivers/soc/microchip/mpfs-sys-controller.c | 28 ++++++++++----------- 1 file changed, 13 insertions(+), 15 deletions(-)
drivers/soc/microchip/mpfs-sys-controller.c +13 -15
@@ -36,28 +36,26 @@ struct mpfs_sys_controller {int mpfs_blocking_transaction (struct mpfs_sys_controller *sys_controller,struct mpfs_mss_msg *msg) {unsigned long timeout =msecs_to_jiffies (MPFS_SYS_CTRL_TIMEOUT_MS ); -int ret, err; +int ret; - err =mutex_lock_interruptible (&transaction_lock); -if (err) -return err; + ret =mutex_lock_interruptible (&transaction_lock); +if (ret) +return ret;reinit_completion (&sys_controller->c); ret =mbox_send_message (sys_controller->chan, msg); -if (ret >=0 ) { -if (wait_for_completion_timeout (&sys_controller->c, timeout)) { - ret =0 ; - }else { - ret = -ETIMEDOUT ; -dev_warn (sys_controller->client.dev, -"MPFS sys controller transaction timeout\n" ); - } - }else { -dev_err (sys_controller->client.dev, -"mpfs sys controller transaction returned %d\n" , ret); +if (ret <0 ) + goto out; + + ret =0 ;/* mbox_send_message returns positive integers on success */ +if (!wait_for_completion_timeout (&sys_controller->c, timeout)) { + ret = -ETIMEDOUT ; +dev_warn (sys_controller->client.dev, +"MPFS sys controller transaction timeout\n" ); } +out:mutex_unlock (&transaction_lock);return ret;
Signature · 7 lines
2.39.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Conor Dooley
maintainerPATCH v2 7/7 soc: microchip: mpfs: handle timeouts and failed services differently
In reply to Conor DooleyThe system controller will only deliver an interrupt if a service succeeds. This leaves us in the unfortunate position with current code where there is no way to differentiate between a legitimate timeout where the service has not completed & where it has completed, but failed.
mbox_send_message() has its own completion, and it will time out of the system controller does not lower the busy flag. In this case, a timeout has occurred and the error can be propagated back to the caller.
If the busy flag is lowered, but no interrupt has arrived to trigger the rx callback, the service can be deemed to have failed. Report EBADMSG in this case so that callers can differentiate.
--- drivers/soc/microchip/mpfs-sys-controller.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/soc/microchip/mpfs-sys-controller.c +15 -3
@@ -45,14 +45,25 @@ int mpfs_blocking_transaction(struct mpfs_sys_controller *sys_controller, structreinit_completion (&sys_controller->c); ret =mbox_send_message (sys_controller->chan, msg); -if (ret <0 ) +if (ret <0 ) { +dev_warn (sys_controller->client.dev, +"MPFS sys controller service timeout\n" ); goto out; + } ret =0 ;/* mbox_send_message returns positive integers on success */ + +/* +* Unfortunately, the system controller will only deliver an interrupt +* if a service succeeds. mbox_send_message() will block until the busy +* flag is gone. If the busy flag is gone but no interrupt has arrived +* to trigger the rx callback then the service can be deemed to have +* failed. +*/ if (!wait_for_completion_timeout (&sys_controller->c, timeout)) { - ret = -ETIMEDOUT ; + ret = -EBADMSG ;dev_warn (sys_controller->client.dev, -"MPFS sys controller transaction timeout\n" ); +"MPFS sys controller service failed\n" ); } out:
@@ -110,6 +121,7 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev) sys_controller->client.dev = dev; sys_controller->client.rx_callback = rx_callback; sys_controller->client.tx_block =1U ; + sys_controller->client.tx_tout =msecs_to_jiffies (MPFS_SYS_CTRL_TIMEOUT_MS ); sys_controller->chan =mbox_request_channel (&sys_controller->client,0 );if (IS_ERR (sys_controller->chan)) {
Signature · 7 lines
2.39.0 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv