drivers: i2c: qup: Some misc fixes
Subsystems (2)
cover drivers: i2c: qup: Some misc fixes
One for fixing the bug with CONFIG_DEBUG_SG enabled and another to suspend the transfer for all errors instead of just for nack.
Sricharan R (2):
drivers: i2c: qup: Fix broken dma when CONFIG_DEBUG_SG is enabled.
drivers: i2c: qup: Fix error handling
drivers/i2c/busses/i2c-qup.c | 87 +++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 45 deletions(-)
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH 1/2 drivers: i2c: qup: Fix broken dma when CONFIG_DEBUG_SG is enabled
With CONFIG_DEBUG_SG is enabled and when dma mode is used, below dump is seen,
------------[ cut here ]------------ kernel BUG at include/linux/scatterlist.h:140! Internal error: Oops - BUG: 0 [#1] PREEMPT SMP Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.4.0-00459-g9f087b9-dirty #7 Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC (DT) task: ffffffc036868000 ti: ffffffc036870000 task.ti: ffffffc036870000 PC is at qup_sg_set_buf.isra.13+0x138/0x154 LR is at qup_sg_set_buf.isra.13+0x50/0x154 pc : [<ffffffc0005a0ed8>] lr : [<ffffffc0005a0df0>] pstate: 60000145
sp : ffffffc0368735c0
x29: ffffffc0368735c0 x28: ffffffc036873752
x27: ffffffc035233018 x26: ffffffc000c4e000
x25: 0000000000000000 x24: 0000000000000004
x23: 0000000000000000 x22: ffffffc035233668
x21: ffffff80004e3000 x20: ffffffc0352e0018
x19: 0000004000000000 x18: 0000000000000028
x17: 0000000000000004 x16: ffffffc0017a39c8
x15: 0000000000001cdf x14: ffffffc0019929d8
x13: ffffffc0352e0018 x12: 0000000000000000
x11: 0000000000000001 x10: 0000000000000001
x9 : ffffffc0012b2d70 x8 : ffffff80004e3000
x7 : 0000000000000018 x6 : 0000000030000000
x5 : ffffffc00199f018 x4 : ffffffc035233018
x3 : 0000000000000004 x2 : 00000000c0000000
x1 : 0000000000000003 x0 : 0000000000000000
Process swapper/0 (pid: 1, stack limit = 0xffffffc036870020)
Stack: (0xffffffc0368735c0 to 0xffffffc036874000)
Change allocation of sg buffers from dma_coherent memory to kzalloc to fix the issue.
--- drivers/i2c/busses/i2c-qup.c | 53 ++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 36 deletions(-)
drivers/i2c/busses/i2c-qup.c +17 -36
@@ -585,8 +585,8 @@ static void qup_i2c_bam_cb(void *data) }static int qup_sg_set_buf (struct scatterlist *sg,void *buf, -struct qup_i2c_tag *tg,unsigned int buflen, -struct qup_i2c_dev *qup,int map,int dir) +unsigned int buflen,struct qup_i2c_dev *qup, +int dir) {int ret;
@@ -595,9 +595,6 @@ static int qup_sg_set_buf(struct scatterlist *sg, void *buf,if (!ret)return -EINVAL ; -if (!map) -sg_dma_address (sg) = tg->addr + ((u8 *)buf - tg->start); -return 0 ; }
@@ -670,16 +667,15 @@ static int qup_i2c_bam_do_xfer(struct qup_i2c_dev *qup, struct i2c_msg *msg,/* scratch buf to read the start and len tags */ ret =qup_sg_set_buf (&qup->brx.sg[rx_buf++], &qup->brx.tag.start[0 ], - &qup->brx.tag, -2 , qup,0 ,0 ); +2 , qup,DMA_FROM_DEVICE );if (ret)return ret; ret =qup_sg_set_buf (&qup->brx.sg[rx_buf++], &msg->buf[limit * i], -NULL , tlen, qup, -1 ,DMA_FROM_DEVICE ); + tlen, qup, +DMA_FROM_DEVICE );if (ret)return ret;
@@ -688,7 +684,7 @@ static int qup_i2c_bam_do_xfer(struct qup_i2c_dev *qup, struct i2c_msg *msg, } ret =qup_sg_set_buf (&qup->btx.sg[tx_buf++], &qup->start_tag.start[off], - &qup->start_tag, len, qup,0 ,0 ); + len, qup,DMA_TO_DEVICE );if (ret)return ret;
@@ -696,8 +692,7 @@ static int qup_i2c_bam_do_xfer(struct qup_i2c_dev *qup, struct i2c_msg *msg,/* scratch buf to read the BAM EOT and FLUSH tags */ ret =qup_sg_set_buf (&qup->brx.sg[rx_buf++], &qup->brx.tag.start[0 ], - &qup->brx.tag,2 , - qup,0 ,0 ); +2 , qup,DMA_FROM_DEVICE );if (ret)return ret; }else {
@@ -709,17 +704,15 @@ static int qup_i2c_bam_do_xfer(struct qup_i2c_dev *qup, struct i2c_msg *msg, len =qup_i2c_set_tags (tags, qup, msg,1 ); ret =qup_sg_set_buf (&qup->btx.sg[tx_buf++], - tags, - &qup->start_tag, len, - qup,0 ,0 ); + tags, len, + qup,DMA_TO_DEVICE );if (ret)return ret; tx_len += len; ret =qup_sg_set_buf (&qup->btx.sg[tx_buf++], &msg->buf[limit * i], -NULL , tlen, qup,1 , -DMA_TO_DEVICE ); + tlen, qup,DMA_TO_DEVICE );if (ret)return ret; i++;
@@ -738,8 +731,7 @@ static int qup_i2c_bam_do_xfer(struct qup_i2c_dev *qup, struct i2c_msg *msg,QUP_BAM_FLUSH_STOP ; ret =qup_sg_set_buf (&qup->btx.sg[tx_buf++], &qup->btx.tag.start[0 ], - &qup->btx.tag, len, - qup,0 ,0 ); + len, qup,DMA_TO_DEVICE );if (ret)return ret; tx_nents +=1 ;
@@ -1268,6 +1260,8 @@ static int qup_i2c_xfer_v2(struct i2c_adapter *adap, } } + idx =0 ; + do { if (msgs[idx].len == 0) { ret = -EINVAL;
@@ -1407,27 +1401,21 @@ static int qup_i2c_probe(struct platform_device *pdev)/* 2 tag bytes for each block + 5 for start, stop tags */ size = blocks *2 +5 ; - qup->dpool =dma_pool_create ("qup_i2c-dma-pool" , &pdev->dev, - size,4 ,0 ); - qup->start_tag.start =dma_pool_alloc (qup->dpool,GFP_KERNEL , - &qup->start_tag.addr); + qup->start_tag.start =devm_kzalloc (&pdev->dev, + size,GFP_KERNEL );if (!qup->start_tag.start) { ret = -ENOMEM ; goto fail_dma; } - qup->brx.tag.start =dma_pool_alloc (qup->dpool, -GFP_KERNEL , - &qup->brx.tag.addr); + qup->brx.tag.start =devm_kzalloc (&pdev->dev,2 ,GFP_KERNEL );if (!qup->brx.tag.start) { ret = -ENOMEM ; goto fail_dma; } - qup->btx.tag.start =dma_pool_alloc (qup->dpool, -GFP_KERNEL , - &qup->btx.tag.addr); + qup->btx.tag.start =devm_kzalloc (&pdev->dev,2 ,GFP_KERNEL );if (!qup->btx.tag.start) { ret = -ENOMEM ; goto fail_dma;
@@ -1566,13 +1554,6 @@ static int qup_i2c_remove(struct platform_device *pdev)struct qup_i2c_dev *qup =platform_get_drvdata (pdev);if (qup->is_dma) { -dma_pool_free (qup->dpool, qup->start_tag.start, - qup->start_tag.addr); -dma_pool_free (qup->dpool, qup->brx.tag.start, - qup->brx.tag.addr); -dma_pool_free (qup->dpool, qup->btx.tag.start, - qup->btx.tag.addr); -dma_pool_destroy (qup->dpool);dma_release_channel (qup->btx.dma);dma_release_channel (qup->brx.dma); }
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCH 1/2] drivers: i2c: qup: Fix broken dma when CONFIG_DEBUG_SG is enabled
Quoted 29 lines · Sricharan R
With
CONFIG_DEBUG_SGis enabled and when dma mode is used, below dump is seen,------------[ cut here ]------------ kernel BUG at include/linux/scatterlist.h:140! Internal error: Oops - BUG: 0 [#1] PREEMPT SMP Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.4.0-00459-g9f087b9-dirty #7 Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC (DT) task: ffffffc036868000 ti: ffffffc036870000 task.ti: ffffffc036870000 PC is at qup_sg_set_buf.isra.13+0x138/0x154 LR is at qup_sg_set_buf.isra.13+0x50/0x154 pc : [<ffffffc0005a0ed8>] lr : [<ffffffc0005a0df0>] pstate: 60000145sp :
ffffffc0368735c0
x29:ffffffc0368735c0x28:ffffffc036873752
x27:ffffffc035233018x26:ffffffc000c4e000
x25: 0000000000000000 x24: 0000000000000004
x23: 0000000000000000 x22:ffffffc035233668
x21:ffffff80004e3000x20:ffffffc0352e0018
x19: 0000004000000000 x18: 0000000000000028
x17: 0000000000000004 x16:ffffffc0017a39c8
x15:0000000000001cdfx14:ffffffc0019929d8
x13:ffffffc0352e0018x12: 0000000000000000
x11: 0000000000000001 x10: 0000000000000001
x9 :ffffffc0012b2d70x8 :ffffff80004e3000
x7 : 0000000000000018 x6 : 0000000030000000
x5 :ffffffc00199f018x4 :ffffffc035233018
x3 : 0000000000000004 x2 :00000000c0000000
x1 : 0000000000000003 x0 : 0000000000000000
Quoted 7 lines
Process swapper/0 (pid: 1, stack limit =
0xffffffc036870020)Stack: (0xffffffc0368735c0 to 0xffffffc036874000)Change allocation of sg buffers from
dma_coherentmemory to kzalloc to fix the issue.Signed-off-by Sricharan R <[email protected]>
Looks fine.
PATCH 2/2 drivers: i2c: qup: Fix error handling
In reply to Sricharan RAmong the bus errors reported from the QUP_MASTER_STATUS register only NACK is considered and transfer gets suspended, while other errors are ignored. Correct this and suspend the transfer for other errors as well. This avoids unnessecary 'timeouts' which happens when waiting for events that would never happen when there is already an error condition on the bus.
--- drivers/i2c/busses/i2c-qup.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
drivers/i2c/busses/i2c-qup.c +25 -9
@@ -310,6 +310,7 @@ static int qup_i2c_wait_ready(struct qup_i2c_dev *qup, int op, bool val,u32 opflags;u32 status;u32 shift =__ffs (op); +int ret =0 ; len *= qup->one_byte_t;/* timeout after a wait of twice the max time */
@@ -321,18 +322,31 @@ static int qup_i2c_wait_ready(struct qup_i2c_dev *qup, int op, bool val,if (((opflags & op) >> shift) == val) {if ((op ==QUP_OUT_NOT_EMPTY ) && qup->is_last) { -if (!(status &I2C_STATUS_BUS_ACTIVE )) -return 0 ; +if (!(status &I2C_STATUS_BUS_ACTIVE )) { + ret =0 ; + goto done; + } }else { -return 0 ; + ret =0 ; + goto done; } } -if (time_after (jiffies, timeout)) -return -ETIMEDOUT ; - +if (time_after (jiffies, timeout)) { + ret = -ETIMEDOUT ; + goto done; + }usleep_range (len, len *2 ); } + +done: +if (qup->bus_err || qup->qup_err) { +if (qup->bus_err &QUP_I2C_NACK_FLAG ) +dev_err (qup->dev,"NACK from %x\n" , qup->msg->addr); + ret = -EIO ; + } + +return ret; } static void qup_i2c_set_write_mode_v2(struct qup_i2c_dev *qup,
@@ -882,10 +896,9 @@ static int qup_i2c_wait_for_complete(struct qup_i2c_dev *qup, }if (qup->bus_err || qup->qup_err) { -if (qup->bus_err &QUP_I2C_NACK_FLAG ) { +if (qup->bus_err &QUP_I2C_NACK_FLAG )dev_err (qup->dev,"NACK from %x\n" , msg->addr); - ret = -EIO ; - } + ret = -EIO ; }return ret;
@@ -1227,6 +1240,9 @@ static int qup_i2c_xfer_v2(struct i2c_adapter *adap,struct qup_i2c_dev *qup =i2c_get_adapdata (adap);int ret, len, idx =0 , use_dma =0 ; + qup->bus_err =0 ; + qup->qup_err =0 ; + ret =pm_runtime_get_sync (qup->dev);if (ret <0 ) goto out;
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCH 2/2] drivers: i2c: qup: Fix error handling
Quoted 11 lines · Sricharan R
Among the bus errors reported from the
QUP_MASTER_STATUSregister only NACK is considered and transfer gets suspended, while other errors are ignored. Correct this and suspend the transfer for other errors as well. This avoids unnessecary 'timeouts' which happens when waiting for events that would never happen when there is already an error condition on the bus.Signed-off-by Sricharan R <[email protected]>--- drivers/i2c/busses/i2c-qup.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
<snip>
drivers/i2c/busses/i2c-qup.c static int qup_i2c_xfer_v2(struct i2c_adapter *adap, · line 1245
Quoted 7 lines
drivers/i2c/busses/i2c-qup.c +3
-0@@ -1227,6 +1240,9 @@ static int qup_i2c_xfer_v2(struct i2c_adapter *adap,struct qup_i2c_dev *qup =i2c_get_adapdata (adap);int ret, len, idx =0 , use_dma =0 ; + qup->bus_err =0 ; + qup->qup_err =0 ; +
What about the initial setting of these? Does this need to be removed from the main xfer function?
Quoted 3 lines
drivers/i2c/busses/i2c-qup.c +0
-0ret =pm_runtime_get_sync (qup->dev);if (ret <0 ) goto out;
RE: [PATCH 2/2] drivers: i2c: qup: Fix error handling
Hi Andy,
Quoted 20 lines
-----Original Message-----
From: Andy Gross [mailto:andy.gross at linaro.org]
Sent: Thursday, May 05, 2016 10:52 PM
To: Sricharan R <[email protected]>
Cc: devicetree at vger.kernel.org; architt at codeaurora.org; linux-arm- msm at vger.kernel.org; ntelkar at codeaurora.org; galak at codeaurora.org; linux-kernel at vger.kernel.org; linux-i2c at vger.kernel.org; iivanov at mm- sol.com; agross at codeaurora.org; dmaengine at vger.kernel.org; linux-arm- kernel at lists.infradead.org
Subject: Re: [PATCH 2/2] drivers: i2c: qup: Fix error handlingQuoted 1 line · Sricharan R
Among the bus errors reported from the
QUP_MASTER_STATUSregisteronly
Quoted 6 lines
NACK is considered and transfer gets suspended, while other errors are ignored. Correct this and suspend the transfer for other errors as well. This avoids unnessecary 'timeouts' which happens when waiting for events that would never happen when there is already an error condition on the bus.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Sricharan R <[email protected]>--- drivers/i2c/busses/i2c-qup.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)Reviewed-by Andy Gross <[email protected]>
Thanks.
Quoted 4 lines
<snip>
Review static int qup_i2c_xfer_v2(struct i2c_adapter
Quoted 1 line
(quoted diff) +0
-0@@ -1227,6 +1240,9 @@ static int qup_i2c_xfer_v2(struct i2c_adapter*adap,
Quoted 8 lines
drivers/i2c/busses/i2c-qup.c static int qup_i2c_xfer_v2(struct i2c_adapter *adap, · line 1245
Quoted 6 lines
drivers/i2c/busses/i2c-qup.c +3
-0struct qup_i2c_dev *qup =i2c_get_adapdata (adap);int ret, len, idx =0 , use_dma =0 ; + qup->bus_err =0 ; + qup->qup_err =0 ; +What about the initial setting of these? Does this need to be removed
from
Quoted 1 line
the main xfer function?
Thanks for the catch. Will remove in bam_xfer , redundant. Now that there are i2x_xfer_v2 and i2c_xfer,
its not set in the old i2c_xfer call, where as it should be set there as well. I will change this and resend.
Regards,
Sricharan
From: Naveen Kaje <[email protected]>
Hi Sricharan,
I tested these changes. They did not cause any regressions on QDF2432. Note that QDF2432 does not use DMA mode.
I based my patches (http://marc.info/?l=linux-i2c&m=146231797008963&w=2 and http://marc.info/?l=linux-i2c&m=146231798708969&w=2) on top of these fixes. There are no merge conflicts.
Thanks,
Naveen
---
One for fixing the bug with CONFIG_DEBUG_SG enabled and another to suspend the transfer for all errors instead of just for nack.
Sricharan R (2):
drivers: i2c: qup: Fix broken dma when CONFIG_DEBUG_SG is enabled.
drivers: i2c: qup: Fix error handling
drivers/i2c/busses/i2c-qup.c | 87 +++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 45 deletions(-)
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation