Message ID | 20241126082535.1878554-1-carlos.song@nxp.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [v2] i2c: imx: support DMA defer probing | expand |
On 26.11.2024 16:25:35, carlos.song@nxp.com wrote: > From: Carlos Song <carlos.song@nxp.com> > > Return -EPROBE_DEFER when dma_request_slave_channel() because DMA driver > have not ready yet. > > Move i2c_imx_dma_request() before registering I2C adapter to avoid > infinite loop of .probe() calls to the same driver, see "e8c220fac415 > Revert "i2c: imx: improve the error handling in i2c_imx_dma_request()"" > and "Documentation/driver-api/driver-model/driver.rst". > > Use CPU mode to avoid stuck registering i2c adapter when DMA resources > are unavailable. > > Signed-off-by: Carlos Song <carlos.song@nxp.com> > Signed-off-by: Clark Wang <xiaoning.wang@nxp.com> > --- > Change for V2: > - According to Frank's comments, wrap at 75 char and Simplify fix code > at i2c_imx_dma_request(). > - Use strict patch check, fix alignment warning at i2c_imx_dma_request() > --- > drivers/i2c/busses/i2c-imx.c | 21 +++++++++++++-------- > 1 file changed, 13 insertions(+), 8 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c > index 5ed4cb61e262..4e5633166a1e 100644 > --- a/drivers/i2c/busses/i2c-imx.c > +++ b/drivers/i2c/busses/i2c-imx.c > @@ -397,17 +397,16 @@ static void i2c_imx_reset_regs(struct imx_i2c_struct *i2c_imx) > } > > /* Functions for DMA support */ > -static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, > - dma_addr_t phy_addr) > +static int i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, dma_addr_t phy_addr) > { > struct imx_i2c_dma *dma; > struct dma_slave_config dma_sconfig; > - struct device *dev = &i2c_imx->adapter.dev; > + struct device *dev = i2c_imx->adapter.dev.parent; > int ret; > > dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); > if (!dma) > - return; > + return -ENOMEM; > > dma->chan_tx = dma_request_chan(dev, "tx"); > if (IS_ERR(dma->chan_tx)) { > @@ -452,7 +451,7 @@ static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, > dev_info(dev, "using %s (tx) and %s (rx) for DMA transfers\n", > dma_chan_name(dma->chan_tx), dma_chan_name(dma->chan_rx)); > > - return; > + return 0; > > fail_rx: > dma_release_channel(dma->chan_rx); > @@ -460,6 +459,8 @@ static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, > dma_release_channel(dma->chan_tx); > fail_al: > devm_kfree(dev, dma); > + > + return ret; > } > > static void i2c_imx_dma_callback(void *arg) > @@ -1803,6 +1804,13 @@ static int i2c_imx_probe(struct platform_device *pdev) > if (ret == -EPROBE_DEFER) > goto clk_notifier_unregister; > > + /* Init DMA config if supported */ > + ret = i2c_imx_dma_request(i2c_imx, phy_addr); > + if (ret == -EPROBE_DEFER) { > + dev_err(&pdev->dev, "DMA not ready, go defer probe!\n"); > + goto clk_notifier_unregister; > + } Don't spam the logs if the driver defers probing, it's not a error. And it looks strange to ignore all other errors here. Either add a comment here, something like "continue without DMA", or let the function return 0 in case the driver should continue and propagate the error if the caller should take care of it. Marc
Hello Carlos, On 26.11.24 09:25, carlos.song@nxp.com wrote: > From: Carlos Song <carlos.song@nxp.com> > > Return -EPROBE_DEFER when dma_request_slave_channel() because DMA driver > have not ready yet. > > Move i2c_imx_dma_request() before registering I2C adapter to avoid > infinite loop of .probe() calls to the same driver, see "e8c220fac415 > Revert "i2c: imx: improve the error handling in i2c_imx_dma_request()"" > and "Documentation/driver-api/driver-model/driver.rst". > > Use CPU mode to avoid stuck registering i2c adapter when DMA resources > are unavailable. Wouldn't this break probe for all i2c-imx users who have CONFIG_IMX_SDMA disabled? Also I am wondering on what kernel version and what configuration (CONFIG_I2C_IMX=?, CONFIG_IMX_SDMA=?) you have that made you run into this situation. I'd have expected that with fw_devlink enabled, the I2C controller wouldn't be probed before the DMA provider is available. Cheers, Ahmad > > Signed-off-by: Carlos Song <carlos.song@nxp.com> > Signed-off-by: Clark Wang <xiaoning.wang@nxp.com> > --- > Change for V2: > - According to Frank's comments, wrap at 75 char and Simplify fix code > at i2c_imx_dma_request(). > - Use strict patch check, fix alignment warning at i2c_imx_dma_request() > --- > drivers/i2c/busses/i2c-imx.c | 21 +++++++++++++-------- > 1 file changed, 13 insertions(+), 8 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c > index 5ed4cb61e262..4e5633166a1e 100644 > --- a/drivers/i2c/busses/i2c-imx.c > +++ b/drivers/i2c/busses/i2c-imx.c > @@ -397,17 +397,16 @@ static void i2c_imx_reset_regs(struct imx_i2c_struct *i2c_imx) > } > > /* Functions for DMA support */ > -static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, > - dma_addr_t phy_addr) > +static int i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, dma_addr_t phy_addr) > { > struct imx_i2c_dma *dma; > struct dma_slave_config dma_sconfig; > - struct device *dev = &i2c_imx->adapter.dev; > + struct device *dev = i2c_imx->adapter.dev.parent; > int ret; > > dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); > if (!dma) > - return; > + return -ENOMEM; > > dma->chan_tx = dma_request_chan(dev, "tx"); > if (IS_ERR(dma->chan_tx)) { > @@ -452,7 +451,7 @@ static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, > dev_info(dev, "using %s (tx) and %s (rx) for DMA transfers\n", > dma_chan_name(dma->chan_tx), dma_chan_name(dma->chan_rx)); > > - return; > + return 0; > > fail_rx: > dma_release_channel(dma->chan_rx); > @@ -460,6 +459,8 @@ static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, > dma_release_channel(dma->chan_tx); > fail_al: > devm_kfree(dev, dma); > + > + return ret; > } > > static void i2c_imx_dma_callback(void *arg) > @@ -1803,6 +1804,13 @@ static int i2c_imx_probe(struct platform_device *pdev) > if (ret == -EPROBE_DEFER) > goto clk_notifier_unregister; > > + /* Init DMA config if supported */ > + ret = i2c_imx_dma_request(i2c_imx, phy_addr); > + if (ret == -EPROBE_DEFER) { > + dev_err(&pdev->dev, "DMA not ready, go defer probe!\n"); > + goto clk_notifier_unregister; > + } > + > /* Add I2C adapter */ > ret = i2c_add_numbered_adapter(&i2c_imx->adapter); > if (ret < 0) > @@ -1817,9 +1825,6 @@ static int i2c_imx_probe(struct platform_device *pdev) > i2c_imx->adapter.name); > dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n"); > > - /* Init DMA config if supported */ > - i2c_imx_dma_request(i2c_imx, phy_addr); > - > return 0; /* Return OK */ > > clk_notifier_unregister:
> -----Original Message----- > From: Marc Kleine-Budde <mkl@pengutronix.de> > Sent: Tuesday, November 26, 2024 4:56 PM > To: Carlos Song <carlos.song@nxp.com> > Cc: Frank Li <frank.li@nxp.com>; o.rempel@pengutronix.de; > kernel@pengutronix.de; andi.shyti@kernel.org; shawnguo@kernel.org; > s.hauer@pengutronix.de; festevam@gmail.com; imx@lists.linux.dev; > linux-i2c@vger.kernel.org; linux-arm-kernel@lists.infradead.org; > linux-kernel@vger.kernel.org > Subject: [EXT] Re: [PATCH v2] i2c: imx: support DMA defer probing > > On 26.11.2024 16:25:35, carlos.song@nxp.com wrote: > > From: Carlos Song <carlos.song@nxp.com> > > > > Return -EPROBE_DEFER when dma_request_slave_channel() because DMA > > driver have not ready yet. > > > > Move i2c_imx_dma_request() before registering I2C adapter to avoid > > infinite loop of .probe() calls to the same driver, see "e8c220fac415 > > Revert "i2c: imx: improve the error handling in i2c_imx_dma_request()"" > > and "Documentation/driver-api/driver-model/driver.rst". > > > > Use CPU mode to avoid stuck registering i2c adapter when DMA resources > > are unavailable. > > > > Signed-off-by: Carlos Song <carlos.song@nxp.com> > > Signed-off-by: Clark Wang <xiaoning.wang@nxp.com> > > --- > > Change for V2: > > - According to Frank's comments, wrap at 75 char and Simplify fix code > > at i2c_imx_dma_request(). > > - Use strict patch check, fix alignment warning at > > i2c_imx_dma_request() > > --- > > drivers/i2c/busses/i2c-imx.c | 21 +++++++++++++-------- > > 1 file changed, 13 insertions(+), 8 deletions(-) > > > > diff --git a/drivers/i2c/busses/i2c-imx.c > > b/drivers/i2c/busses/i2c-imx.c index 5ed4cb61e262..4e5633166a1e 100644 > > --- a/drivers/i2c/busses/i2c-imx.c > > +++ b/drivers/i2c/busses/i2c-imx.c > > @@ -397,17 +397,16 @@ static void i2c_imx_reset_regs(struct > > imx_i2c_struct *i2c_imx) } > > > > /* Functions for DMA support */ > > -static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, > > - dma_addr_t phy_addr) > > +static int i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, > > +dma_addr_t phy_addr) > > { > > struct imx_i2c_dma *dma; > > struct dma_slave_config dma_sconfig; > > - struct device *dev = &i2c_imx->adapter.dev; > > + struct device *dev = i2c_imx->adapter.dev.parent; > > int ret; > > > > dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); > > if (!dma) > > - return; > > + return -ENOMEM; > > > > dma->chan_tx = dma_request_chan(dev, "tx"); > > if (IS_ERR(dma->chan_tx)) { > > @@ -452,7 +451,7 @@ static void i2c_imx_dma_request(struct > imx_i2c_struct *i2c_imx, > > dev_info(dev, "using %s (tx) and %s (rx) for DMA transfers\n", > > dma_chan_name(dma->chan_tx), dma_chan_name(dma->chan_rx)); > > > > - return; > > + return 0; > > > > fail_rx: > > dma_release_channel(dma->chan_rx); > > @@ -460,6 +459,8 @@ static void i2c_imx_dma_request(struct > imx_i2c_struct *i2c_imx, > > dma_release_channel(dma->chan_tx); > > fail_al: > > devm_kfree(dev, dma); > > + > > + return ret; > > } > > > > static void i2c_imx_dma_callback(void *arg) @@ -1803,6 +1804,13 @@ > > static int i2c_imx_probe(struct platform_device *pdev) > > if (ret == -EPROBE_DEFER) > > goto clk_notifier_unregister; > > > > + /* Init DMA config if supported */ > > + ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > + if (ret == -EPROBE_DEFER) { > > + dev_err(&pdev->dev, "DMA not ready, go defer probe!\n"); > > + goto clk_notifier_unregister; > > + } > > Don't spam the logs if the driver defers probing, it's not a error. And it looks > strange to ignore all other errors here. Either add a comment here, something > like "continue without DMA", or let the function return > 0 in case the driver should continue and propagate the error if the caller should > take care of it. > Hi, Thank you for your suggestion! I agree with you. I will change to this logic: ret = i2c_imx_dma_request(i2c_imx, phy_addr); if (ret) { if (ret == -EPROBE_DEFER) goto clk_notifier_unregister; dev_info(&pdev->dev, "use pio mode\n"); } Ret = 0 -----> enable DMA successfully -------> no print Ret!=0 -----> defer probe ---------> no print and try again Ret!=0 -----> fail to enable DMA ------> remind now is using pio mode Do you think the logic is acceptable? > Marc > > -- > Pengutronix e.K. | Marc Kleine-Budde | > Embedded Linux | https://www.pengutronix.de | > Vertretung Nürnberg | Phone: +49-5121-206917-129 | > Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
On 26.11.2024 10:15:27, Carlos Song wrote: > > > static void i2c_imx_dma_callback(void *arg) @@ -1803,6 +1804,13 @@ > > > static int i2c_imx_probe(struct platform_device *pdev) > > > if (ret == -EPROBE_DEFER) > > > goto clk_notifier_unregister; > > > > > > + /* Init DMA config if supported */ > > > + ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > > + if (ret == -EPROBE_DEFER) { > > > + dev_err(&pdev->dev, "DMA not ready, go defer probe!\n"); > > > + goto clk_notifier_unregister; > > > + } > > > > Don't spam the logs if the driver defers probing, it's not a error. And it looks > > strange to ignore all other errors here. Either add a comment here, something > > like "continue without DMA", or let the function return > > 0 in case the driver should continue and propagate the error if the caller should > > take care of it. > > > > Hi, > Thank you for your suggestion! I agree with you. > I will change to this logic: > ret = i2c_imx_dma_request(i2c_imx, phy_addr); > if (ret) { > if (ret == -EPROBE_DEFER) > goto clk_notifier_unregister; > dev_info(&pdev->dev, "use pio mode\n"); > } > > Ret = 0 -----> enable DMA successfully -------> no print > Ret!=0 -----> defer probe ---------> no print and try again > Ret!=0 -----> fail to enable DMA ------> remind now is using pio mode > > Do you think the logic is acceptable? Yes, the other option is to move the logic into i2c_imx_dma_request() and let it return 0 in case of DMA or fallback to PIO, or an error in case of probe defer or a fatal error. This way the probe function will look like this: ret = i2c_imx_dma_request(i2c_imx, phy_addr); if (ret) return dev_err_probe(&pdev->dev, ret, "Failed to setup DMA\n"); regards, Marc
> -----Original Message----- > From: Marc Kleine-Budde <mkl@pengutronix.de> > Sent: Tuesday, November 26, 2024 6:24 PM > To: Carlos Song <carlos.song@nxp.com> > Cc: Frank Li <frank.li@nxp.com>; o.rempel@pengutronix.de; > kernel@pengutronix.de; andi.shyti@kernel.org; shawnguo@kernel.org; > s.hauer@pengutronix.de; festevam@gmail.com; imx@lists.linux.dev; > linux-i2c@vger.kernel.org; linux-arm-kernel@lists.infradead.org; > linux-kernel@vger.kernel.org > Subject: [EXT] Re: [PATCH v2] i2c: imx: support DMA defer probing > > On 26.11.2024 10:15:27, Carlos Song wrote: > > > > static void i2c_imx_dma_callback(void *arg) @@ -1803,6 +1804,13 > > > > @@ static int i2c_imx_probe(struct platform_device *pdev) > > > > if (ret == -EPROBE_DEFER) > > > > goto clk_notifier_unregister; > > > > > > > > + /* Init DMA config if supported */ > > > > + ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > > > + if (ret == -EPROBE_DEFER) { > > > > + dev_err(&pdev->dev, "DMA not ready, go defer probe!\n"); > > > > + goto clk_notifier_unregister; > > > > + } > > > > > > Don't spam the logs if the driver defers probing, it's not a error. > > > And it looks strange to ignore all other errors here. Either add a > > > comment here, something like "continue without DMA", or let the > > > function return > > > 0 in case the driver should continue and propagate the error if the > > > caller should take care of it. > > > > > > > Hi, > > Thank you for your suggestion! I agree with you. > > I will change to this logic: > > ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > if (ret) { > > if (ret == -EPROBE_DEFER) > > goto clk_notifier_unregister; > > dev_info(&pdev->dev, "use pio mode\n"); > > } > > > > Ret = 0 -----> enable DMA successfully -------> no print > > Ret!=0 -----> defer probe ---------> no print and try again > > Ret!=0 -----> fail to enable DMA ------> remind now is using pio > > mode > > > > Do you think the logic is acceptable? > > Yes, the other option is to move the logic into i2c_imx_dma_request() and let it > return 0 in case of DMA or fallback to PIO, or an error in case of probe defer or a > fatal error. > > This way the probe function will look like this: > > ret = i2c_imx_dma_request(i2c_imx, phy_addr); > if (ret) > return dev_err_probe(&pdev->dev, ret, "Failed to setup > DMA\n"); > Sorry, I have some different ideas... 1. DMA mode should be optional for i2c-imx, because i2c-imx can accept DMA mode not enabled, because it still can work in CPU mode. If we use return dev_err_probe(), we have to return error at i2c_imx_dma_request() for "some fatal error", it will cause i2c_adapter can not be registered, then kill i2c adapter register. If we always return 0 at i2c_imx_dma_request(), dev_err_probe will not work forever. So from my point, if DMA is not working well, just output a log to remind now i2c is always working at CPU mode, we have no DMA, this is enough. 2. when really defer probe, return dev_err_probe will return defer probe directly, but we still need to goto clk_notifier_unregister branch to free irq, clk_notifier_unregister and disable runtime pm. So we still need more judgement at probe function to handle this. So I prefer this logic: ret = i2c_imx_dma_request(i2c_imx, phy_addr); if (ret) { if (ret == -EPROBE_DEFER) goto clk_notifier_unregister; dev_info(&pdev->dev, "use pio mode\n"); } > > regards, > Marc > > -- > Pengutronix e.K. | Marc Kleine-Budde | > Embedded Linux | https://www.pengutronix.de | > Vertretung Nürnberg | Phone: +49-5121-206917-129 | > Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
On 26.11.2024 12:07:59, Carlos Song wrote: > > > > -----Original Message----- > > From: Marc Kleine-Budde <mkl@pengutronix.de> > > Sent: Tuesday, November 26, 2024 6:24 PM > > To: Carlos Song <carlos.song@nxp.com> > > Cc: Frank Li <frank.li@nxp.com>; o.rempel@pengutronix.de; > > kernel@pengutronix.de; andi.shyti@kernel.org; shawnguo@kernel.org; > > s.hauer@pengutronix.de; festevam@gmail.com; imx@lists.linux.dev; > > linux-i2c@vger.kernel.org; linux-arm-kernel@lists.infradead.org; > > linux-kernel@vger.kernel.org > > Subject: [EXT] Re: [PATCH v2] i2c: imx: support DMA defer probing > > > > On 26.11.2024 10:15:27, Carlos Song wrote: > > > > > static void i2c_imx_dma_callback(void *arg) @@ -1803,6 +1804,13 > > > > > @@ static int i2c_imx_probe(struct platform_device *pdev) > > > > > if (ret == -EPROBE_DEFER) > > > > > goto clk_notifier_unregister; > > > > > > > > > > + /* Init DMA config if supported */ > > > > > + ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > > > > + if (ret == -EPROBE_DEFER) { > > > > > + dev_err(&pdev->dev, "DMA not ready, go defer probe!\n"); > > > > > + goto clk_notifier_unregister; > > > > > + } > > > > > > > > Don't spam the logs if the driver defers probing, it's not a error. > > > > And it looks strange to ignore all other errors here. Either add a > > > > comment here, something like "continue without DMA", or let the > > > > function return > > > > 0 in case the driver should continue and propagate the error if the > > > > caller should take care of it. > > > > > > > > > > Hi, > > > Thank you for your suggestion! I agree with you. > > > I will change to this logic: > > > ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > > if (ret) { > > > if (ret == -EPROBE_DEFER) > > > goto clk_notifier_unregister; > > > dev_info(&pdev->dev, "use pio mode\n"); > > > } > > > > > > Ret = 0 -----> enable DMA successfully -------> no print > > > Ret!=0 -----> defer probe ---------> no print and try again > > > Ret!=0 -----> fail to enable DMA ------> remind now is using pio > > > mode > > > > > > Do you think the logic is acceptable? > > > > Yes, the other option is to move the logic into i2c_imx_dma_request() and let it > > return 0 in case of DMA or fallback to PIO, or an error in case of probe defer or a > > fatal error. > > > > This way the probe function will look like this: > > > > ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > if (ret) > > return dev_err_probe(&pdev->dev, ret, "Failed to setup > > DMA\n"); > > > > Sorry, I have some different ideas... > 1. DMA mode should be optional for i2c-imx, because i2c-imx can accept DMA mode not enabled, because it still can work in CPU mode. ACK > If we use return dev_err_probe(), we have to return error at i2c_imx_dma_request() for "some fatal error", it will cause i2c_adapter can not be registered, then kill i2c adapter register. i2c_imx_dma_request should only return an error if PIO mode is not an option. > If we always return 0 at i2c_imx_dma_request(), dev_err_probe will not work forever. So from my point, if DMA is not working well, just output a log to remind now i2c is always > working at CPU mode, we have no DMA, this is enough. ACK > 2. when really defer probe, return dev_err_probe will return defer probe directly, but we still need to goto clk_notifier_unregister branch to free irq, clk_notifier_unregister and disable runtime pm. > So we still need more judgement at probe function to handle this. Not quite "dev_err_probe()" will not defer probe directly, the return in "return dev_err_probe();" does. This should work: ret = i2c_imx_dma_request(i2c_imx, phy_addr); if (ret) { dev_err_probe(&pdev->dev, ret, "Failed to setup DMA\n"); goto clk_notifier_unregister; } > So I prefer this logic: This also works, LGTM! > ret = i2c_imx_dma_request(i2c_imx, phy_addr); > if (ret) { > if (ret == -EPROBE_DEFER) > goto clk_notifier_unregister; > dev_info(&pdev->dev, "use pio mode\n"); > } regards, Marc
> > > > > > > -----Original Message----- > > > From: Marc Kleine-Budde <mkl@pengutronix.de> > > > Sent: Tuesday, November 26, 2024 6:24 PM > > > To: Carlos Song <carlos.song@nxp.com> > > > Cc: Frank Li <frank.li@nxp.com>; o.rempel@pengutronix.de; > > > kernel@pengutronix.de; andi.shyti@kernel.org; shawnguo@kernel.org; > > > s.hauer@pengutronix.de; festevam@gmail.com; imx@lists.linux.dev; > > > linux-i2c@vger.kernel.org; linux-arm-kernel@lists.infradead.org; > > > linux-kernel@vger.kernel.org > > > Subject: [EXT] Re: [PATCH v2] i2c: imx: support DMA defer probing > > > > > > On 26.11.2024 10:15:27, Carlos Song wrote: > > > > > > static void i2c_imx_dma_callback(void *arg) @@ -1803,6 > > > > > > +1804,13 @@ static int i2c_imx_probe(struct platform_device *pdev) > > > > > > if (ret == -EPROBE_DEFER) > > > > > > goto clk_notifier_unregister; > > > > > > > > > > > > + /* Init DMA config if supported */ > > > > > > + ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > > > > > + if (ret == -EPROBE_DEFER) { > > > > > > + dev_err(&pdev->dev, "DMA not ready, go defer probe!\n"); > > > > > > + goto clk_notifier_unregister; > > > > > > + } > > > > > > > > > > Don't spam the logs if the driver defers probing, it's not a error. > > > > > And it looks strange to ignore all other errors here. Either add > > > > > a comment here, something like "continue without DMA", or let > > > > > the function return > > > > > 0 in case the driver should continue and propagate the error if > > > > > the caller should take care of it. > > > > > > > > > > > > > Hi, > > > > Thank you for your suggestion! I agree with you. > > > > I will change to this logic: > > > > ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > > > if (ret) { > > > > if (ret == -EPROBE_DEFER) > > > > goto clk_notifier_unregister; > > > > dev_info(&pdev->dev, "use pio mode\n"); > > > > } > > > > > > > > Ret = 0 -----> enable DMA successfully -------> no print > > > > Ret!=0 -----> defer probe ---------> no print and try again > > > > Ret!=0 -----> fail to enable DMA ------> remind now is using pio > > > > mode > > > > > > > > Do you think the logic is acceptable? > > > > > > Yes, the other option is to move the logic into > > > i2c_imx_dma_request() and let it return 0 in case of DMA or fallback > > > to PIO, or an error in case of probe defer or a fatal error. > > > > > > This way the probe function will look like this: > > > > > > ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > > if (ret) > > > return dev_err_probe(&pdev->dev, ret, "Failed to > > > setup DMA\n"); > > > > > > > Sorry, I have some different ideas... > > 1. DMA mode should be optional for i2c-imx, because i2c-imx can accept DMA > mode not enabled, because it still can work in CPU mode. > > ACK > > > If we use return dev_err_probe(), we have to return error at > i2c_imx_dma_request() for "some fatal error", it will cause i2c_adapter can not > be registered, then kill i2c adapter register. > > i2c_imx_dma_request should only return an error if PIO mode is not an option. > > > If we always return 0 at i2c_imx_dma_request(), dev_err_probe will not > work forever. So from my point, if DMA is not working well, just output a log to > remind now i2c is always > > working at CPU mode, we have no DMA, this is enough. > > ACK > > > 2. when really defer probe, return dev_err_probe will return defer probe > directly, but we still need to goto clk_notifier_unregister branch to free irq, > clk_notifier_unregister and disable runtime pm. > > So we still need more judgement at probe function to handle this. > > Not quite "dev_err_probe()" will not defer probe directly, the return in "return > dev_err_probe();" does. This should work: > > ret = i2c_imx_dma_request(i2c_imx, phy_addr); > if (ret) { > dev_err_probe(&pdev->dev, ret, "Failed to setup > DMA\n"); > goto clk_notifier_unregister; > } > > > > So I prefer this logic: > > This also works, LGTM! > I will apply it in V3. Thank you for your ack! > > ret = i2c_imx_dma_request(i2c_imx, phy_addr); if (ret) { > > if (ret == -EPROBE_DEFER) > > goto clk_notifier_unregister; > > dev_info(&pdev->dev, "use pio mode\n"); } > > regards, > Marc > > -- > Pengutronix e.K. | Marc Kleine-Budde | > Embedded Linux | https://www.pengutronix.de | > Vertretung Nürnberg | Phone: +49-5121-206917-129 | > Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
> > > > > > > -----Original Message----- > > > From: Marc Kleine-Budde <mkl@pengutronix.de> > > > Sent: Tuesday, November 26, 2024 6:24 PM > > > To: Carlos Song <carlos.song@nxp.com> > > > Cc: Frank Li <frank.li@nxp.com>; o.rempel@pengutronix.de; > > > kernel@pengutronix.de; andi.shyti@kernel.org; shawnguo@kernel.org; > > > s.hauer@pengutronix.de; festevam@gmail.com; imx@lists.linux.dev; > > > linux-i2c@vger.kernel.org; linux-arm-kernel@lists.infradead.org; > > > linux-kernel@vger.kernel.org > > > Subject: [EXT] Re: [PATCH v2] i2c: imx: support DMA defer probing > > > > > > On 26.11.2024 10:15:27, Carlos Song wrote: > > > > > > static void i2c_imx_dma_callback(void *arg) @@ -1803,6 > > > > > > +1804,13 @@ static int i2c_imx_probe(struct platform_device *pdev) > > > > > > if (ret == -EPROBE_DEFER) > > > > > > goto clk_notifier_unregister; > > > > > > > > > > > > + /* Init DMA config if supported */ > > > > > > + ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > > > > > + if (ret == -EPROBE_DEFER) { > > > > > > + dev_err(&pdev->dev, "DMA not ready, go defer probe!\n"); > > > > > > + goto clk_notifier_unregister; > > > > > > + } > > > > > > > > > > Don't spam the logs if the driver defers probing, it's not a error. > > > > > And it looks strange to ignore all other errors here. Either add > > > > > a comment here, something like "continue without DMA", or let > > > > > the function return > > > > > 0 in case the driver should continue and propagate the error if > > > > > the caller should take care of it. > > > > > > > > > > > > > Hi, > > > > Thank you for your suggestion! I agree with you. > > > > I will change to this logic: > > > > ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > > > if (ret) { > > > > if (ret == -EPROBE_DEFER) > > > > goto clk_notifier_unregister; > > > > dev_info(&pdev->dev, "use pio mode\n"); > > > > } > > > > > > > > Ret = 0 -----> enable DMA successfully -------> no print > > > > Ret!=0 -----> defer probe ---------> no print and try again > > > > Ret!=0 -----> fail to enable DMA ------> remind now is using pio > > > > mode > > > > > > > > Do you think the logic is acceptable? > > > > > > Yes, the other option is to move the logic into > > > i2c_imx_dma_request() and let it return 0 in case of DMA or fallback > > > to PIO, or an error in case of probe defer or a fatal error. > > > > > > This way the probe function will look like this: > > > > > > ret = i2c_imx_dma_request(i2c_imx, phy_addr); > > > if (ret) > > > return dev_err_probe(&pdev->dev, ret, "Failed to > > > setup DMA\n"); > > > > > > > Sorry, I have some different ideas... > > 1. DMA mode should be optional for i2c-imx, because i2c-imx can accept DMA > mode not enabled, because it still can work in CPU mode. > > ACK > > > If we use return dev_err_probe(), we have to return error at > i2c_imx_dma_request() for "some fatal error", it will cause i2c_adapter can not > be registered, then kill i2c adapter register. > > i2c_imx_dma_request should only return an error if PIO mode is not an option. > > > If we always return 0 at i2c_imx_dma_request(), dev_err_probe will not > work forever. So from my point, if DMA is not working well, just output a log to > remind now i2c is always > > working at CPU mode, we have no DMA, this is enough. > > ACK > > > 2. when really defer probe, return dev_err_probe will return defer probe > directly, but we still need to goto clk_notifier_unregister branch to free irq, > clk_notifier_unregister and disable runtime pm. > > So we still need more judgement at probe function to handle this. > > Not quite "dev_err_probe()" will not defer probe directly, the return in "return > dev_err_probe();" does. This should work: > > ret = i2c_imx_dma_request(i2c_imx, phy_addr); > if (ret) { > dev_err_probe(&pdev->dev, ret, "Failed to setup > DMA\n"); > goto clk_notifier_unregister; > } > > > > So I prefer this logic: > > This also works, LGTM! > > > ret = i2c_imx_dma_request(i2c_imx, phy_addr); if (ret) { > > if (ret == -EPROBE_DEFER) > > goto clk_notifier_unregister; > > dev_info(&pdev->dev, "use pio mode\n"); } > I have carefully considered your suggestion. If DMA fail, i2c needs to show error log indeed. So I made V3 patch, is it what we expected? > Marc > > -- > Pengutronix e.K. | Marc Kleine-Budde | > Embedded Linux | https://www.pengutronix.de | > Vertretung Nürnberg | Phone: +49-5121-206917-129 | > Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 5ed4cb61e262..4e5633166a1e 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -397,17 +397,16 @@ static void i2c_imx_reset_regs(struct imx_i2c_struct *i2c_imx) } /* Functions for DMA support */ -static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, - dma_addr_t phy_addr) +static int i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, dma_addr_t phy_addr) { struct imx_i2c_dma *dma; struct dma_slave_config dma_sconfig; - struct device *dev = &i2c_imx->adapter.dev; + struct device *dev = i2c_imx->adapter.dev.parent; int ret; dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); if (!dma) - return; + return -ENOMEM; dma->chan_tx = dma_request_chan(dev, "tx"); if (IS_ERR(dma->chan_tx)) { @@ -452,7 +451,7 @@ static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, dev_info(dev, "using %s (tx) and %s (rx) for DMA transfers\n", dma_chan_name(dma->chan_tx), dma_chan_name(dma->chan_rx)); - return; + return 0; fail_rx: dma_release_channel(dma->chan_rx); @@ -460,6 +459,8 @@ static void i2c_imx_dma_request(struct imx_i2c_struct *i2c_imx, dma_release_channel(dma->chan_tx); fail_al: devm_kfree(dev, dma); + + return ret; } static void i2c_imx_dma_callback(void *arg) @@ -1803,6 +1804,13 @@ static int i2c_imx_probe(struct platform_device *pdev) if (ret == -EPROBE_DEFER) goto clk_notifier_unregister; + /* Init DMA config if supported */ + ret = i2c_imx_dma_request(i2c_imx, phy_addr); + if (ret == -EPROBE_DEFER) { + dev_err(&pdev->dev, "DMA not ready, go defer probe!\n"); + goto clk_notifier_unregister; + } + /* Add I2C adapter */ ret = i2c_add_numbered_adapter(&i2c_imx->adapter); if (ret < 0) @@ -1817,9 +1825,6 @@ static int i2c_imx_probe(struct platform_device *pdev) i2c_imx->adapter.name); dev_info(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n"); - /* Init DMA config if supported */ - i2c_imx_dma_request(i2c_imx, phy_addr); - return 0; /* Return OK */ clk_notifier_unregister: