Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753930AbdCOLrC (ORCPT ); Wed, 15 Mar 2017 07:47:02 -0400 Received: from esa4.microchip.iphmx.com ([68.232.154.123]:6600 "EHLO esa4.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753872AbdCOLrA (ORCPT ); Wed, 15 Mar 2017 07:47:00 -0400 X-Greylist: delayed 570 seconds by postgrey-1.27 at vger.kernel.org; Wed, 15 Mar 2017 07:46:59 EDT X-IronPort-AV: E=Sophos;i="5.36,168,1486450800"; d="scan'208";a="209406" Subject: Re: [PATCH] tty/serial: atmel_serial: BUG: stop DMA from transmitting in stop_tx To: Richard Genoud , Alexandre Belloni , Cyrille Pitchen , References: <20161213162756.16139-1-richard.genoud@gmail.com> CC: Greg Kroah-Hartman , , From: Nicolas Ferre Organization: atmel Message-ID: Date: Wed, 15 Mar 2017 12:37:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <20161213162756.16139-1-richard.genoud@gmail.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: =?Windows-1252?Q?H4sIAAAAAAAAC+NgFnrGKsWRWlGSWpSXmKPExsXCxeXDoluufjLCYM6r?= =?Windows-1252?Q?PfM4LTquLWayuPf9PLNF8+L1bBabHl9jtbi8aw6bxZnFvewWs3euYXJg?= =?Windows-1252?Q?91jwayuLx5NNFxk9ds66y+6xf+4ado/NS+o9Pm+SC2CLYs3MS8qvSGDN?= =?Windows-1252?Q?2L17HmvBM5GKE/tvszQwvhToYuTiEBJYziix8+p6li5GTg5hgWiJU+ee?= =?Windows-1252?Q?MoIkRAQOMEq8eX6QHSQhJGArsfv/LGYQm1mgUGLzwhNMIDabgK7E2QlP?= =?Windows-1252?Q?2LoYOTj4BYQlzkyNBwnzCthILJrymhXEZhFQlejcuxWsXFQgQmL+01VM?= =?Windows-1252?Q?EDWCEidnPgHbyylgJ7Hs7BQmiPEGEkcWzWGFsOUlmrfOZoY4QUWi730/?= =?Windows-1252?Q?2DkSAoESrxd/hLKdJF4efckGYdtJHJ5+ESpuL3F2zWa4mp+7drBC2NoS?= =?Windows-1252?Q?21/tg7J1JLYd7GeBsG0l9syYyARhu0s8eLQcyvaVmPWwAaomSqJhwQmm?= =?Windows-1252?Q?CYxSs5C8MAvJ2bOQnL2AkXkVo7Szh59ucJiua4Szh4GhXm5yRoFubmJm?= =?Windows-1252?Q?nl5yfu4mRkiMq+5gvPUv/BCjJAeTkihv+Y8TEUJ8SfkplRmJxRnxRaU5?= =?Windows-1252?Q?qcWHGGU4OJQkeAXVTkYICRalpqdWpGXmAJMNTJqJg/MQowQHj5IIrwFI?= =?Windows-1252?Q?DW9xQWJucWY6RP4Uo6SUOG+IKlBCACSRUZoH13uJUVRKmHeDFFCOpyC1?= =?Windows-1252?Q?KDezBCJ+i1GM4yETx2MmIZa8/LxUKaBTGYDAgPEVozgHo5IwbxPIOJ7M?= =?Windows-1252?Q?vBK4Na+ALmACuuDthxMgF5QkIqSkGhjVnRfPMfwcE/1uS6Hta80/GTvj?= =?Windows-1252?Q?729e1PerMPDOku3dn6ZXFx/nkRWRLKqKNppRrDalX1LRZPqG+bMNZ1t8?= =?Windows-1252?Q?uNXA51MZv93jt/9zZdaeyeJxH8y2S5y+E7TFUCfwlOplhcRedv9TE6+s?= =?Windows-1252?Q?49t6+6DvtIzOW9pyWyp5VQoUPsjLCh97d+VL0HHmIyVKLMUZiYZazEXF?= =?Windows-1252?Q?iQCElHVOeQMAAA=3D=3D?= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2590 Lines: 72 Le 13/12/2016 ? 17:27, Richard Genoud a ?crit : > If we don't disable the transmitter in atmel_stop_tx, the DMA buffer > continues to send data until it is emptied. > This cause problems with the flow control (CTS is asserted and data are > still sent). > > So, disabling the transmitter in atmel_stop_tx is a sane thing to do. > > Tested on at91sam9g35-cm(DMA) > Tested for regressions on sama5d2-xplained(Fifo) and at91sam9g20ek(PDC) > > Cc: (beware, this won't apply before 4.3) > Signed-off-by: Richard Genoud > --- > drivers/tty/serial/atmel_serial.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > NB: this is not for the 4.10 merge window, I'm just sending it now to > have some comments if someone is againts it. > > diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c > index 168b10cad47b..f9d42de5ab2d 100644 > --- a/drivers/tty/serial/atmel_serial.c > +++ b/drivers/tty/serial/atmel_serial.c > @@ -481,6 +481,14 @@ static void atmel_stop_tx(struct uart_port *port) > /* disable PDC transmit */ > atmel_uart_writel(port, ATMEL_PDC_PTCR, ATMEL_PDC_TXTDIS); > } > + > + /* > + * Disable the transmitter. > + * This is mandatory when DMA is used, otherwise the DMA buffer > + * is fully transmitted. > + */ > + atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXDIS); > + > /* Disable interrupts */ > atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask); > > @@ -513,6 +521,9 @@ static void atmel_start_tx(struct uart_port *port) > > /* Enable interrupts */ > atmel_uart_writel(port, ATMEL_US_IER, atmel_port->tx_done_mask); > + > + /* re-enable the transmitter */ > + atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXEN); > } > > /* Hi Richard, I've just discovered that I have some weird behavior with this patch. On current Linus' tree, with sama5d2 + DMA, I see some garbage characters coming out of the console when I try to stop my system (reboot/halt) [1]. Moreover, and I do understand that it's not the problem right here, when applied on our linux-4.4-at91 branch (our vendor tree actually), it hangs the boot process as it seems that a burst of open/close of the serial port happens while starting the rootfs. It's definitively my own problem, but it can bring light to what we are seeing on Mainline... I think that we may need to flush the DMA channel in this atmel_stop_tx() function. Best regards, [1] If you want to test, you need to apply this patch for eMMC BTW: https://patchwork.kernel.org/patch/9617489/ -- Nicolas Ferre