linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Joakim Zhang <qiangqing.zhang@nxp.com>,
	"linux-can@vger.kernel.org" <linux-can@vger.kernel.org>
Cc: "kernel@pengutronix.de" <kernel@pengutronix.de>
Subject: Re: [PATCH 5/5] can: flexcan: flexcan_close(): change order if commands to properly shut down the controller
Date: Thu, 19 Nov 2020 10:49:38 +0100	[thread overview]
Message-ID: <104ac870-4560-0ecb-7aef-d663c7288dda@pengutronix.de> (raw)
In-Reply-To: <DB8PR04MB6795CBAA8B6729A478E2BE9CE6E00@DB8PR04MB6795.eurprd04.prod.outlook.com>


[-- Attachment #1.1: Type: text/plain, Size: 3219 bytes --]

On 11/19/20 10:46 AM, Joakim Zhang wrote:
> 
>> -----Original Message-----
>> From: Marc Kleine-Budde <mkl@pengutronix.de>
>> Sent: 2020年11月19日 16:53
>> To: linux-can@vger.kernel.org
>> Cc: Joakim Zhang <qiangqing.zhang@nxp.com>; kernel@pengutronix.de; Marc
>> Kleine-Budde <mkl@pengutronix.de>
>> Subject: [PATCH 5/5] can: flexcan: flexcan_close(): change order if commands
>> to properly shut down the controller
>>
>> There haven been reports, that the flexcan_close() soradically hangs during
>> simultanious ifdown, sending of CAN messages and probably open CAN bus:
>>
>> | (__schedule) from [<808bbd34>] (schedule+0x90/0xb8)
>> | (schedule) from [<808bf274>] (schedule_timeout+0x1f8/0x24c)
>> | (schedule_timeout) from [<8016be44>] (msleep+0x18/0x1c)
>> | (msleep) from [<80746a64>] (napi_disable+0x60/0x70)
>> | (napi_disable) from [<8052fdd0>] (flexcan_close+0x2c/0x140)
>> | (flexcan_close) from [<80744930>] (__dev_close_many+0xb8/0xd8)
>> | (__dev_close_many) from [<8074db9c>] (__dev_change_flags+0xd0/0x1a0)
>> | (__dev_change_flags) from [<8074dc84>] (dev_change_flags+0x18/0x48)
>> | (dev_change_flags) from [<80760c24>] (do_setlink+0x44c/0x7b4)
>> | (do_setlink) from [<80761560>] (rtnl_newlink+0x374/0x68c)
>>
>> I was unable to reproduce the issue, but a cleanup of the flexcan close
>> sequence has probably fixed the problem at the reporting user.
>>
>> This patch changes the sequence in flexcan_close() to:
>> - stop the TX queue
>> - disable the interrupts on the chip level and wait via free_irq()
>>   synchronously for the interrupt handler to finish
>> - disable RX offload, which disables synchronously NAPI
>> - disable the flexcan on the chip level
>> - free RX offload
>> - disable the transceiver
>> - close the CAN device
>> - disable the clocks
>>
>> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
>> ---
>>  drivers/net/can/flexcan.c | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c index
>> 0fb768dee99f..002e93f2b249 100644
>> --- a/drivers/net/can/flexcan.c
>> +++ b/drivers/net/can/flexcan.c
>> @@ -1789,15 +1789,16 @@ static int flexcan_close(struct net_device *dev)
>>  	struct flexcan_priv *priv = netdev_priv(dev);
>>
>>  	netif_stop_queue(dev);
>> +	flexcan_chip_interrupts_disable(dev);
>> +	free_irq(dev->irq, dev);
>>  	can_rx_offload_disable(&priv->offload);
>>  	flexcan_chip_stop_disable_on_error(dev);
>>  	flexcan_chip_interrupts_disable(dev);
> 
> Hi Marc,
> 
> Is it a special treatment? flexcan_chip_interrupts_disable called twice?

Thanks for catching this. It's a mistake, will fix.

> 	flexcan_chip_interrupts_disable(dev);
> 	free_irq(dev->irq, dev);
>   	can_rx_offload_disable(&priv->offload);
>   	flexcan_chip_stop_disable_on_error(dev);
>   	flexcan_chip_interrupts_disable(dev);

Thanks for the review,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      reply	other threads:[~2020-11-19  9:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-19  8:52 [net-next PATCH 0/5] flexcan: fix hanging flexcan_close() Marc Kleine-Budde
2020-11-19  8:52 ` [PATCH 1/5] can: flexcan: factor out enabling and disabling of interrupts into separate function Marc Kleine-Budde
2020-11-19  8:52 ` [PATCH 2/5] can: flexcan: move enabling/disabling of interrupts from flexcan_chip_{start,stop}() to callers Marc Kleine-Budde
2020-11-19  8:52 ` [PATCH 3/5] can: flexcan: flexcan_rx_offload_setup(): factor out mailbox and rx-offload setup into separate function Marc Kleine-Budde
2020-11-19  8:52 ` [PATCH 4/5] can: flexcan: flexcan_open(): completely initialize controller before requesting IRQ Marc Kleine-Budde
2020-11-19  8:52 ` [PATCH 5/5] can: flexcan: flexcan_close(): change order if commands to properly shut down the controller Marc Kleine-Budde
2020-11-19  9:46   ` Joakim Zhang
2020-11-19  9:49     ` Marc Kleine-Budde [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=104ac870-4560-0ecb-7aef-d663c7288dda@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=kernel@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=qiangqing.zhang@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).