Skip to content

Commit 5ee40e8

Browse files
committed
Merge patch series "mailbox,soc: mpfs: add support for fallible services"
Conor Dooley <[email protected]> says: 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. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Conor Dooley <[email protected]>
2 parents 49f965b + 8f943dd commit 5ee40e8

File tree

2 files changed

+67
-40
lines changed

2 files changed

+67
-40
lines changed

drivers/mailbox/mailbox-mpfs.c

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define SCB_CTRL_NOTIFY_MASK BIT(SCB_CTRL_NOTIFY)
4040

4141
#define SCB_CTRL_POS (16)
42-
#define SCB_CTRL_MASK GENMASK_ULL(SCB_CTRL_POS + SCB_MASK_WIDTH, SCB_CTRL_POS)
42+
#define SCB_CTRL_MASK GENMASK(SCB_CTRL_POS + SCB_MASK_WIDTH - 1, SCB_CTRL_POS)
4343

4444
/* SCBCTRL service status register */
4545

@@ -79,6 +79,27 @@ static bool mpfs_mbox_busy(struct mpfs_mbox *mbox)
7979
return status & SCB_STATUS_BUSY_MASK;
8080
}
8181

82+
static bool mpfs_mbox_last_tx_done(struct mbox_chan *chan)
83+
{
84+
struct mpfs_mbox *mbox = (struct mpfs_mbox *)chan->con_priv;
85+
struct mpfs_mss_response *response = mbox->response;
86+
u32 val;
87+
88+
if (mpfs_mbox_busy(mbox))
89+
return false;
90+
91+
/*
92+
* The service status is stored in bits 31:16 of the SERVICES_SR
93+
* register & is only valid when the system controller is not busy.
94+
* Failed services are intended to generated interrupts, but in reality
95+
* this does not happen, so the status must be checked here.
96+
*/
97+
val = readl_relaxed(mbox->ctrl_base + SERVICES_SR_OFFSET);
98+
response->resp_status = (val & SCB_STATUS_MASK) >> SCB_STATUS_POS;
99+
100+
return true;
101+
}
102+
82103
static int mpfs_mbox_send_data(struct mbox_chan *chan, void *data)
83104
{
84105
struct mpfs_mbox *mbox = (struct mpfs_mbox *)chan->con_priv;
@@ -118,6 +139,7 @@ static int mpfs_mbox_send_data(struct mbox_chan *chan, void *data)
118139
}
119140

120141
opt_sel = ((msg->mbox_offset << 7u) | (msg->cmd_opcode & 0x7fu));
142+
121143
tx_trigger = (opt_sel << SCB_CTRL_POS) & SCB_CTRL_MASK;
122144
tx_trigger |= SCB_CTRL_REQ_MASK | SCB_STATUS_NOTIFY_MASK;
123145
writel_relaxed(tx_trigger, mbox->ctrl_base + SERVICES_CR_OFFSET);
@@ -130,16 +152,14 @@ static void mpfs_mbox_rx_data(struct mbox_chan *chan)
130152
struct mpfs_mbox *mbox = (struct mpfs_mbox *)chan->con_priv;
131153
struct mpfs_mss_response *response = mbox->response;
132154
u16 num_words = ALIGN((response->resp_size), (4)) / 4U;
133-
u32 i, status;
155+
u32 i;
134156

135157
if (!response->resp_msg) {
136158
dev_err(mbox->dev, "failed to assign memory for response %d\n", -ENOMEM);
137159
return;
138160
}
139161

140162
/*
141-
* The status is stored in bits 31:16 of the SERVICES_SR register.
142-
* It is only valid when BUSY == 0.
143163
* We should *never* get an interrupt while the controller is
144164
* still in the busy state. If we do, something has gone badly
145165
* wrong & the content of the mailbox would not be valid.
@@ -150,24 +170,10 @@ static void mpfs_mbox_rx_data(struct mbox_chan *chan)
150170
return;
151171
}
152172

153-
status = readl_relaxed(mbox->ctrl_base + SERVICES_SR_OFFSET);
154-
155-
/*
156-
* If the status of the individual servers is non-zero, the service has
157-
* failed. The contents of the mailbox at this point are not be valid,
158-
* so don't bother reading them. Set the status so that the driver
159-
* implementing the service can handle the result.
160-
*/
161-
response->resp_status = (status & SCB_STATUS_MASK) >> SCB_STATUS_POS;
162-
if (response->resp_status)
163-
return;
164-
165-
if (!mpfs_mbox_busy(mbox)) {
166-
for (i = 0; i < num_words; i++) {
167-
response->resp_msg[i] =
168-
readl_relaxed(mbox->mbox_base
169-
+ mbox->resp_offset + i * 0x4);
170-
}
173+
for (i = 0; i < num_words; i++) {
174+
response->resp_msg[i] =
175+
readl_relaxed(mbox->mbox_base
176+
+ mbox->resp_offset + i * 0x4);
171177
}
172178

173179
mbox_chan_received_data(chan, response);
@@ -182,7 +188,6 @@ static irqreturn_t mpfs_mbox_inbox_isr(int irq, void *data)
182188

183189
mpfs_mbox_rx_data(chan);
184190

185-
mbox_chan_txdone(chan, 0);
186191
return IRQ_HANDLED;
187192
}
188193

@@ -212,6 +217,7 @@ static const struct mbox_chan_ops mpfs_mbox_ops = {
212217
.send_data = mpfs_mbox_send_data,
213218
.startup = mpfs_mbox_startup,
214219
.shutdown = mpfs_mbox_shutdown,
220+
.last_tx_done = mpfs_mbox_last_tx_done,
215221
};
216222

217223
static int mpfs_mbox_probe(struct platform_device *pdev)
@@ -247,7 +253,8 @@ static int mpfs_mbox_probe(struct platform_device *pdev)
247253
mbox->controller.num_chans = 1;
248254
mbox->controller.chans = mbox->chans;
249255
mbox->controller.ops = &mpfs_mbox_ops;
250-
mbox->controller.txdone_irq = true;
256+
mbox->controller.txdone_poll = true;
257+
mbox->controller.txpoll_period = 10u;
251258

252259
ret = devm_mbox_controller_register(&pdev->dev, &mbox->controller);
253260
if (ret) {

drivers/soc/microchip/mpfs-sys-controller.c

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111
#include <linux/slab.h>
1212
#include <linux/kref.h>
1313
#include <linux/module.h>
14+
#include <linux/jiffies.h>
1415
#include <linux/interrupt.h>
1516
#include <linux/of_platform.h>
1617
#include <linux/mailbox_client.h>
1718
#include <linux/platform_device.h>
1819
#include <soc/microchip/mpfs.h>
1920

21+
/*
22+
* This timeout must be long, as some services (example: image authentication)
23+
* take significant time to complete
24+
*/
25+
#define MPFS_SYS_CTRL_TIMEOUT_MS 30000
26+
2027
static DEFINE_MUTEX(transaction_lock);
2128

2229
struct mpfs_sys_controller {
@@ -28,28 +35,40 @@ struct mpfs_sys_controller {
2835

2936
int mpfs_blocking_transaction(struct mpfs_sys_controller *sys_controller, struct mpfs_mss_msg *msg)
3037
{
31-
int ret, err;
38+
unsigned long timeout = msecs_to_jiffies(MPFS_SYS_CTRL_TIMEOUT_MS);
39+
int ret;
3240

33-
err = mutex_lock_interruptible(&transaction_lock);
34-
if (err)
35-
return err;
41+
ret = mutex_lock_interruptible(&transaction_lock);
42+
if (ret)
43+
return ret;
3644

3745
reinit_completion(&sys_controller->c);
3846

3947
ret = mbox_send_message(sys_controller->chan, msg);
40-
if (ret >= 0) {
41-
if (wait_for_completion_timeout(&sys_controller->c, HZ)) {
42-
ret = 0;
43-
} else {
44-
ret = -ETIMEDOUT;
45-
dev_warn(sys_controller->client.dev,
46-
"MPFS sys controller transaction timeout\n");
47-
}
48+
if (ret < 0) {
49+
dev_warn(sys_controller->client.dev, "MPFS sys controller service timeout\n");
50+
goto out;
51+
}
52+
53+
/*
54+
* Unfortunately, the system controller will only deliver an interrupt
55+
* if a service succeeds. mbox_send_message() will block until the busy
56+
* flag is gone. If the busy flag is gone but no interrupt has arrived
57+
* to trigger the rx callback then the service can be deemed to have
58+
* failed.
59+
* The caller can then interrogate msg::response::resp_status to
60+
* determine the cause of the failure.
61+
* mbox_send_message() returns positive integers in the success path, so
62+
* ret needs to be cleared if we do get an interrupt.
63+
*/
64+
if (!wait_for_completion_timeout(&sys_controller->c, timeout)) {
65+
ret = -EBADMSG;
66+
dev_warn(sys_controller->client.dev, "MPFS sys controller service failed\n");
4867
} else {
49-
dev_err(sys_controller->client.dev,
50-
"mpfs sys controller transaction returned %d\n", ret);
68+
ret = 0;
5169
}
5270

71+
out:
5372
mutex_unlock(&transaction_lock);
5473

5574
return ret;
@@ -66,8 +85,8 @@ static void rx_callback(struct mbox_client *client, void *msg)
6685

6786
static void mpfs_sys_controller_delete(struct kref *kref)
6887
{
69-
struct mpfs_sys_controller *sys_controller = container_of(kref, struct mpfs_sys_controller,
70-
consumers);
88+
struct mpfs_sys_controller *sys_controller =
89+
container_of(kref, struct mpfs_sys_controller, consumers);
7190

7291
mbox_free_channel(sys_controller->chan);
7392
kfree(sys_controller);
@@ -104,6 +123,7 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
104123
sys_controller->client.dev = dev;
105124
sys_controller->client.rx_callback = rx_callback;
106125
sys_controller->client.tx_block = 1U;
126+
sys_controller->client.tx_tout = msecs_to_jiffies(MPFS_SYS_CTRL_TIMEOUT_MS);
107127

108128
sys_controller->chan = mbox_request_channel(&sys_controller->client, 0);
109129
if (IS_ERR(sys_controller->chan)) {

0 commit comments

Comments
 (0)