Repository navigation
Conversation
In IPC4 protocol, responses are sent over a separate set of mailbox registers. This creates the following problem: a) msg received, IPC IRQ b) IRQ masked c) handle IPC command, possible in separate core d) when command handled, send the IPC reply e) IPC driver complete callback called f) acknowledge the message (by writing BUSY + DONE) g) unmask IRQ The problem is that the acknowledgement in step (f) is optional part of the protocol, and in fact, driver in IPC4 mode will consider the reply in step (d) as a signal that it can send more messages. If driver sends a new message in quick succession, this may be lost. This patch addresses the problem by moving the acknowledge step earlier so that the sequence becomes: A) msg received, IPC IRQ B) IRQ masked C) acknowledge the message (by writing BUSY + DONE) D) handle IPC command, possible in separate core E) when command handled, send the IPC reply F) IPC driver complete callback called G) unmask IRQ BugLink: thesofproject#6173 Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
|
Tested this internally (Intel test run 15066 ) and seems there are still failures. There's a potential conflict with the newly added mtrace notifications. It seems sending a fw-to-host notification between steps (C) and (E), leads to errors still. I did get locally get 250 iterations through with the notifications enabled, but another 250 iteration run hit an error. Without any fix, a 50 iteration run already hit the error. |
@kv2019i, I think the safe sequence would be: Iow, reordering C, D and E and the reason is that the ack have other meaning: it is telling the host side that the communication channel is free, the DSP no longer uses the data from the previous message and the host (if it desire to do so) can send a new message. The problem with the implemented sequence (ACK as the last step, after the reply is sent) is rather racy, especially that the reply sending and ACK is detached and to complicate things we also have delayed replies, and some message (SET_DX) do not even receive an ACK. |
Let me create a draft PR for the kernel side to see how that one deals with the timeouts... |
|
@kv2019i, with this thesofproject/linux#3841 we would have a bit more insight on the IPC level of things. |
|
|
|
||
| #if CONFIG_IPC_MAJOR_4 | ||
| #if CAVS_VERSION < CAVS_VERSION_1_8 | ||
| #error "Invalid configuration for IPC4." |
There was a problem hiding this comment.
Are you sure about this? If yes, then it should be a separate patch deprecating CAVS_VERSION_1_5 ?
In current code we only have checks:
#if CAVS_VERSION == CAVS_VERSION_1_5
...
#else
...
#endif There was a problem hiding this comment.
Probably not, if this approach is ok, maybe we need to keep the 1.5 support around for IPC4.
| #if CAVS_VERSION < CAVS_VERSION_1_8 | ||
| #error "Invalid configuration for IPC4." | ||
| #endif | ||
| #define IPC4_EARLY_ACK 1 /* ack with DONE immediately */ |
There was a problem hiding this comment.
Basically with this you made sure that IPC4_EARLY_ACK is only defined in case CONFIG_IPC_MAJOR_4 and when CONFIG_IPC_MAJOR_4 is set the IPC4_EARLY_ACK is also. You can just use the CONFIG_IPC_MAJOR_4 in place of IPC4_EARLY_ACK
There was a problem hiding this comment.
True, but I kind of prefer to have more meaning in the ifdefs. It makes the code body more readable. Well, avoiding ifdefs to begin with would be even better, but if you have to do it, having some semantics seems helpful. But yeah, style issue.
| #endif | ||
|
|
||
| /* perform command */ | ||
| ipc_cmd(hdr); |
There was a problem hiding this comment.
Right, I see. the reply is sent as a new message within ipc_cmd() at the end of the handling.
In theory host software could rely on the BUSY to decide to send a new message or not, so if we clear it before we processed the message from the registers and mailbox then there is a chance that the host changes the content under our feet...
One way to be safer is to add a flag to struct ipc_msg, something like bool reply_message. If it is true then do the ack before sending the reply message itself. The flag is ignored for IPC3.
|
@ujfalusi wrote:
Ok, this problem was solved -> #6242 With a fix to this, the tests are now rock solid. |
|
@mwasko fyi - is there a IPC4 expert who could also advise here ? |
@marcinszkudlinski, @mmaka1 can you provide feedback? |
|
is there any problem with MTL ? |
| * do this before we send the response | ||
| */ | ||
| ipc_write(IPC_DIPCTDR, ipc_read(IPC_DIPCTDR) | IPC_DIPCTDR_BUSY); | ||
| ipc_write(IPC_DIPCTDA, ipc_read(IPC_DIPCTDA) | IPC_DIPCTDA_DONE); |
There was a problem hiding this comment.
According to cAVS 2.5 HW Arch Spec, IPC flow should be implemented as follows:
- DSP receives the interrupt, reads message from DIPCTDR, DIPCTDD and L2 local memory
- DSP clears BUSY by writing 1 to DIPCTDR
- DSP process the message
- DSP set DONE by writing DIPCTDA
Replacing 3. and 4. will violate the architecture flow.
Note: in closed-source cAVS, BUSY is cleared together with set DONE, after processing the message, so moment of clearing BUSY seems to not to be critical.
At present cAVS closed-source solution, BUSY and DONE are triggered after processing message from host and before writing response. It seems to be the best way.
There was a problem hiding this comment.
Thanks @pblaszko ! Indeed, this is what @ujfalusi also commented in last Friday in #6239 (comment) . And yes, this seems to be the correct thing.
The key seems to be whether busy+done clearance is done before or after the response is sent. We are err'ing towards the direction that host/kernel should handle even the case where busy+done is cleared only at the end (i.e. the original sequence).
@kv2019i do you mean host driver? Host driver should not consider (d) as IPC completion. After receiving reply from DSP, driver should set HIPCTDA.DONE, and still wait until DSP clears it. Only then Host driver may send next message to DSP. Maybe the problem you're observing lays in driver, not FW? |
|
@pblaszko wrote:
Ok thanks. And yes, I was talking of the host kernel driver, and indeed this seems to make sense. @ujfalusi is now making the changes in thesofproject/linux#3843 . @ujfalusi please check the above |
|
Concluding this PR. Basicly in short:
Let's first get the kernel changes in, and submit a separate PR to enhance the FW implementation. Closing this one. |
Note: issue found by @ujfalusi - he has a kernel side fix to the same problem.
In IPC4 protocol, responses are sent over a separate set of
mailbox registers. This creates the following problem:
a) msg received, IPC IRQ
b) IRQ masked
c) handle IPC command, possible in separate core
d) when command handled, send the IPC reply
e) IPC driver complete callback called
f) acknowledge the message (by writing BUSY + DONE)
g) unmask IRQ
The problem is that the acknowledgement in step (f) is
optional part of the protocol, and in fact, driver in IPC4 mode
will consider the reply in step (d) as a signal that it can send
more messages. If driver sends a new message in quick succession,
this may be lost.
This patch addresses the problem by moving the acknowledge
step earlier so that the sequence becomes:
A) msg received, IPC IRQ
B) IRQ masked
C) acknowledge the message (by writing BUSY + DONE)
D) handle IPC command, possible in separate core
E) when command handled, send the IPC reply
F) IPC driver complete callback called
G) unmask IRQ
BugLink: #6173
Signed-off-by: Kai Vehmanen kai.vehmanen@linux.intel.com