Repository navigation
ASoC: SOF: Intel: ipc4: tx/rx ack race and sequencing fixes #3843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d2ef2da
e50382f
210fb3f
5d11585
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,10 +37,12 @@ irqreturn_t cnl_ipc4_irq_thread(int irq, void *context) | |
| { | ||
| struct sof_ipc4_msg notification_data = {{ 0 }}; | ||
| struct snd_sof_dev *sdev = context; | ||
| bool ack_received = false; | ||
| bool ipc_irq = false; | ||
| u32 hipcida, hipctdr; | ||
|
|
||
| hipcida = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCIDA); | ||
| hipctdr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCTDR); | ||
|
plbossart marked this conversation as resolved.
Resolved
plbossart marked this conversation as resolved.
Resolved
|
||
| if (hipcida & CNL_DSP_REG_HIPCIDA_DONE) { | ||
| /* DSP received the message */ | ||
| snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, | ||
|
|
@@ -49,9 +51,9 @@ irqreturn_t cnl_ipc4_irq_thread(int irq, void *context) | |
| cnl_ipc_dsp_done(sdev); | ||
|
|
||
| ipc_irq = true; | ||
| ack_received = true; | ||
| } | ||
|
|
||
| hipctdr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, CNL_DSP_REG_HIPCTDR); | ||
| if (hipctdr & CNL_DSP_REG_HIPCTDR_BUSY) { | ||
| /* Message from DSP (reply or notification) */ | ||
| u32 hipctdd = snd_sof_dsp_read(sdev, HDA_DSP_BAR, | ||
|
|
@@ -70,6 +72,7 @@ irqreturn_t cnl_ipc4_irq_thread(int irq, void *context) | |
| spin_lock_irq(&sdev->ipc_lock); | ||
|
|
||
| snd_sof_ipc_get_reply(sdev); | ||
| cnl_ipc_host_done(sdev); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. But does this close the race window completely? What if a reply arrives, but the sending thread sends a new message from the host to the DSP before we ack here? Maybe even before the interrupt triggers?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can not have two tx messages at the same time. they are serialized with a higher level mutex, the next message can only proceed if the previous got the reply. No, the checking of the tx channel that it is free is not going to fix this race as there is still (I have seen that with only the busy patch) that the tx channel from host was free, we sent a message, fw handled and tried to send a reply, but the kernel still have not managed to ack the reply. The fw delayed message handling is broken, so we ended up with IPC timeout. |
||
| snd_sof_ipc_reply(sdev, data->primary); | ||
|
|
||
| spin_unlock_irq(&sdev->ipc_lock); | ||
|
|
@@ -86,10 +89,10 @@ irqreturn_t cnl_ipc4_irq_thread(int irq, void *context) | |
| sdev->ipc->msg.rx_data = ¬ification_data; | ||
| snd_sof_ipc_msgs_rx(sdev); | ||
| sdev->ipc->msg.rx_data = NULL; | ||
| } | ||
|
|
||
| /* Let DSP know that we have finished processing the message */ | ||
| cnl_ipc_host_done(sdev); | ||
| /* Let DSP know that we have finished processing the message */ | ||
| cnl_ipc_host_done(sdev); | ||
| } | ||
|
|
||
| ipc_irq = true; | ||
| } | ||
|
|
@@ -98,6 +101,13 @@ irqreturn_t cnl_ipc4_irq_thread(int irq, void *context) | |
| /* This interrupt is not shared so no need to return IRQ_NONE. */ | ||
| dev_dbg_ratelimited(sdev->dev, "nothing to do in IPC IRQ thread\n"); | ||
|
|
||
| if (ack_received) { | ||
| struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; | ||
|
|
||
| if (hdev->delayed_ipc_tx_msg) | ||
| cnl_ipc4_send_msg(sdev, hdev->delayed_ipc_tx_msg); | ||
| } | ||
|
|
||
| return IRQ_HANDLED; | ||
| } | ||
|
|
||
|
|
@@ -251,8 +261,16 @@ static bool cnl_compact_ipc_compress(struct snd_sof_ipc_msg *msg, | |
|
|
||
| int cnl_ipc4_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) | ||
| { | ||
| struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; | ||
| struct sof_ipc4_msg *msg_data = msg->msg_data; | ||
|
|
||
| if (hda_ipc4_tx_is_busy(sdev)) { | ||
| hdev->delayed_ipc_tx_msg = msg; | ||
| return 0; | ||
| } | ||
|
|
||
| hdev->delayed_ipc_tx_msg = NULL; | ||
|
|
||
| /* send the message via mailbox */ | ||
| if (msg_data->data_size) | ||
| sof_mailbox_write(sdev, sdev->host_box.offset, msg_data->data_ptr, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -681,6 +681,17 @@ void hda_ipc4_dump(struct snd_sof_dev *sdev) | |
| hipci, hipcie, hipct, hipcte, hipcctl); | ||
| } | ||
|
|
||
| bool hda_ipc4_tx_is_busy(struct snd_sof_dev *sdev) | ||
| { | ||
| struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; | ||
| const struct sof_intel_dsp_desc *chip = hda->desc; | ||
| u32 val; | ||
|
|
||
| val = snd_sof_dsp_read(sdev, HDA_DSP_BAR, chip->ipc_req); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there no internal IPC state indicator to check that we're busy after having sent a request and expecting a response?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the hardware handshake between the two processors. We are doing to be safe even if the DSP does something unexpected, but not totally invalid. |
||
|
|
||
| return !!(val & chip->ipc_req_mask); | ||
| } | ||
|
|
||
| static int hda_init(struct snd_sof_dev *sdev) | ||
| { | ||
| struct hda_bus *hbus; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,8 +90,16 @@ static bool mtl_dsp_check_sdw_irq(struct snd_sof_dev *sdev) | |
|
|
||
| static int mtl_ipc_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) | ||
| { | ||
| struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; | ||
| struct sof_ipc4_msg *msg_data = msg->msg_data; | ||
|
|
||
| if (hda_ipc4_tx_is_busy(sdev)) { | ||
| hdev->delayed_ipc_tx_msg = msg; | ||
| return 0; | ||
| } | ||
|
|
||
| hdev->delayed_ipc_tx_msg = NULL; | ||
|
|
||
| /* send the message via mailbox */ | ||
| if (msg_data->data_size) | ||
| sof_mailbox_write(sdev, sdev->host_box.offset, msg_data->data_ptr, | ||
|
|
@@ -492,11 +500,13 @@ static irqreturn_t mtl_ipc_irq_thread(int irq, void *context) | |
| { | ||
| struct sof_ipc4_msg notification_data = {{ 0 }}; | ||
| struct snd_sof_dev *sdev = context; | ||
| bool ack_received = false; | ||
| bool ipc_irq = false; | ||
| u32 hipcida; | ||
| u32 hipctdr; | ||
|
|
||
| hipcida = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXIDA); | ||
| hipctdr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXTDR); | ||
|
|
||
| /* reply message from DSP */ | ||
| if (hipcida & MTL_DSP_REG_HFIPCXIDA_DONE) { | ||
|
|
@@ -507,9 +517,9 @@ static irqreturn_t mtl_ipc_irq_thread(int irq, void *context) | |
| mtl_ipc_dsp_done(sdev); | ||
|
|
||
| ipc_irq = true; | ||
| ack_received = true; | ||
| } | ||
|
|
||
| hipctdr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXTDR); | ||
| if (hipctdr & MTL_DSP_REG_HFIPCXTDR_BUSY) { | ||
| /* Message from DSP (reply or notification) */ | ||
| u32 extension = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXTDDY); | ||
|
|
@@ -530,6 +540,7 @@ static irqreturn_t mtl_ipc_irq_thread(int irq, void *context) | |
| spin_lock_irq(&sdev->ipc_lock); | ||
|
|
||
| snd_sof_ipc_get_reply(sdev); | ||
| mtl_ipc_host_done(sdev); | ||
|
RanderWang marked this conversation as resolved.
Resolved
|
||
| snd_sof_ipc_reply(sdev, data->primary); | ||
|
|
||
| spin_unlock_irq(&sdev->ipc_lock); | ||
|
|
@@ -546,9 +557,9 @@ static irqreturn_t mtl_ipc_irq_thread(int irq, void *context) | |
| sdev->ipc->msg.rx_data = ¬ification_data; | ||
| snd_sof_ipc_msgs_rx(sdev); | ||
| sdev->ipc->msg.rx_data = NULL; | ||
| } | ||
|
|
||
| mtl_ipc_host_done(sdev); | ||
| mtl_ipc_host_done(sdev); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't able to figure out what this change fixes. The commit message is a bit too cryptic to me.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sequence which I have seen twice:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving the reply acking fixes this by making sure that we only send a new message after we have certainly acked the reception of the reply. With the fix on the firmware side, this should not be needed anymore, but I rather play safe. |
||
|
|
||
| ipc_irq = true; | ||
| } | ||
|
|
@@ -558,6 +569,13 @@ static irqreturn_t mtl_ipc_irq_thread(int irq, void *context) | |
| dev_dbg_ratelimited(sdev->dev, "nothing to do in IPC IRQ thread\n"); | ||
| } | ||
|
|
||
| if (ack_received) { | ||
| struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; | ||
|
|
||
| if (hdev->delayed_ipc_tx_msg) | ||
| mtl_ipc_send_msg(sdev, hdev->delayed_ipc_tx_msg); | ||
| } | ||
|
|
||
| return IRQ_HANDLED; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.