ipc: Implement FIFO queue to fix sequence inconsistency
The SVA history buffer is out of order if there are
more than 2 continuous RX buffer done from GLINK. Implement
FIFO to ensure sequence consistency.
Change-Id: If70e2d0160e8f3140d621298b0db03bd89ba88ba
Signed-off-by: Xiaojun Sang <xsang@codeaurora.org>
diff --git a/ipc/wcd-dsp-glink.c b/ipc/wcd-dsp-glink.c
index eae6acc..0a9ce85 100644
--- a/ipc/wcd-dsp-glink.c
+++ b/ipc/wcd-dsp-glink.c
@@ -109,6 +109,8 @@
/* Respone buffer related */
u8 rsp_cnt;
struct wdsp_glink_rsp_que rsp[RESP_QUEUE_SIZE];
+ u8 write_idx;
+ u8 read_idx;
struct completion rsp_complete;
struct mutex rsp_mutex;
@@ -203,13 +205,19 @@
mutex_lock(&wpriv->rsp_mutex);
rsp_cnt = wpriv->rsp_cnt;
if (rsp_cnt >= RESP_QUEUE_SIZE) {
- dev_err(wpriv->dev, "%s: Resp Queue is Full\n", __func__);
- rsp_cnt = 0;
+ dev_err(wpriv->dev, "%s: Resp Queue is Full. Ignore latest and keep oldest.\n",
+ __func__);
+ mutex_unlock(&wpriv->rsp_mutex);
+ glink_rx_done(handle, ptr, true);
+ return;
}
- dev_dbg(wpriv->dev, "%s: copy into buffer %d\n", __func__, rsp_cnt);
+ dev_dbg(wpriv->dev, "%s: rsp_cnt = %d copy into buffer %d\n",
+ __func__, rsp_cnt, wpriv->write_idx);
- memcpy(wpriv->rsp[rsp_cnt].buf, rx_buf, size);
- wpriv->rsp[rsp_cnt].buf_size = size;
+ memcpy(wpriv->rsp[wpriv->write_idx].buf, rx_buf, size);
+ wpriv->rsp[wpriv->write_idx].buf_size = size;
+
+ wpriv->write_idx = (wpriv->write_idx + 1) % RESP_QUEUE_SIZE;
wpriv->rsp_cnt = ++rsp_cnt;
mutex_unlock(&wpriv->rsp_mutex);
@@ -779,10 +787,11 @@
mutex_lock(&wpriv->rsp_mutex);
if (wpriv->rsp_cnt) {
wpriv->rsp_cnt--;
- dev_dbg(wpriv->dev, "%s: read from buffer %d\n",
- __func__, wpriv->rsp_cnt);
+ dev_dbg(wpriv->dev, "%s: rsp_cnt=%d read from buffer %d\n",
+ __func__, wpriv->rsp_cnt, wpriv->read_idx);
- rsp = &wpriv->rsp[wpriv->rsp_cnt];
+ rsp = &wpriv->rsp[wpriv->read_idx];
+ wpriv->read_idx = (wpriv->read_idx + 1) % RESP_QUEUE_SIZE;
if (count < rsp->buf_size) {
ret1 = copy_to_user(buf, &rsp->buf, count);
/* Return the number of bytes copied */