Re: [git pull] clk: renesas: Updates for v4.19

2018-07-06 Thread Stephen Boyd
Quoting Geert Uytterhoeven (2018-07-04 02:45:52)
> Hi Mike, Stephen,
> 
> The following changes since commit ce397d215ccd07b8ae3f71db689aedb85d56ab40:
> 
>   Linux 4.18-rc1 (2018-06-17 08:04:49 +0900)
> 
> are available in the Git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git 
> tags/clk-renesas-for-v4.19-tag1
> 
> for you to fetch changes up to 4c3d88526eba214357150764a0e3e5308acbef4a:
> 
>   clk: renesas: Renesas R9A06G032 clock driver (2018-06-25 11:17:13 +0200)
> 
> 
> clk: renesas: Updates for v4.19
> 
>   - Add support for Crypto Engine clocks on R-Car H3,
>   - Add support for the new RZ/N1D SoC.
> 

Thanks. Pulled into clk-next.


[PATCH v2] serial: sh-sci: Stop RX FIFO timer during port shutdown

2018-07-06 Thread Geert Uytterhoeven
The RX FIFO timer may be armed when the port is shut down, hence the
timer function may still be called afterwards.

Fix this race condition by deleting the timer during port shutdown.

Fixes: 039403765e5da3c6 ("serial: sh-sci: SCIFA/B RX FIFO software timeout")
Signed-off-by: Geert Uytterhoeven 
Reviewed-by: Simon Horman 
---
Tested with scifa0 on r8a7740/armadillo, after

echo 2000 > /sys/devices/platform/e6c4.serial/rx_fifo_timeout

v2:
  - Add Reviewed-by.
---
 drivers/tty/serial/sh-sci.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 360664a9adf66632..6eb65160e0150f27 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2098,6 +2098,8 @@ static void sci_shutdown(struct uart_port *port)
}
 #endif
 
+   if (s->rx_trigger > 1 && s->rx_fifo_timeout > 0)
+   del_timer_sync(>rx_fifo_timer);
sci_free_irq(s);
sci_free_dma(port);
 }
-- 
2.17.1



[PATCH v2 0/3] serial: sh-sci: Fix port shutdown DMA race conditions

2018-07-06 Thread Geert Uytterhoeven
Hi all,

This patch series fixes race conditions between DMA use and port
shutdown on Renesas "SCIF" serial ports, causing e.g.

sh-sci e655.serial: Failed preparing Tx DMA descriptor
Unable to handle kernel read from unreadable memory at virtual address 

...
Call trace:
 sci_tx_dma_release+0x50/0xfc
 work_fn_tx+0x128/0x22c
 process_one_work+0x394/0x62c
 worker_thread+0x21c/0x324
 kthread+0x118/0x128
 ret_from_fork+0x10/0x18

I have no guaranteed way to reproducis this issue. I see it sometimes
when doing a partial login on a port running getty, and letting getty
time out.

The first two patches simplify DMA release handling, and make sure the
work function is not called after port shutdown.
The last patch switches the driver to the new
dmaengine_terminate_(a)sync() functions, now DMA release is done from a
single point.

Changes compared to v1:
  - Remove unused variable port in sci_[rt]x_dma_release(),
  - Drop accidentally appended debug version of the real patch series.

Please review. Thanks!

Geert Uytterhoeven (3):
  serial: sh-sci: Postpone DMA release when falling back to PIO
  serial: sh-sci: Stop TX DMA workqueue during port shutdown
  serial: sh-sci: Stop using deprecated dmaengine_terminate_all()

 drivers/tty/serial/sh-sci.c | 95 ++---
 1 file changed, 47 insertions(+), 48 deletions(-)

-- 
2.17.1

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


[PATCH v2 3/3] serial: sh-sci: Stop using deprecated dmaengine_terminate_all()

2018-07-06 Thread Geert Uytterhoeven
As of commit b36f09c3c441a6e5 ("dmaengine: Add transfer termination
synchronization support"), dmaengine_terminate_all() is deprecated.

Replace calls to dmaengine_terminate_all() in DMA release code by calls
to dmaengine_terminate_sync(), as the latter waits until all running
completion callbacks have finished.

Replace calls to dmaengine_terminate_all() in DMA failure paths by calls
to dmaengine_terminate_async(), as these are usually done in atomic
context.

Signed-off-by: Geert Uytterhoeven 
---
v2:
  - No changes.
---
 drivers/tty/serial/sh-sci.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 939749073e7bdb11..360664a9adf66632 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1220,7 +1220,7 @@ static void sci_rx_dma_release(struct sci_port *s)
 
s->chan_rx_saved = s->chan_rx = NULL;
s->cookie_rx[0] = s->cookie_rx[1] = -EINVAL;
-   dmaengine_terminate_all(chan);
+   dmaengine_terminate_sync(chan);
dma_free_coherent(chan->device->dev, s->buf_len_rx * 2, s->rx_buf[0],
  sg_dma_address(>sg_rx[0]));
dma_release_channel(chan);
@@ -1296,7 +1296,7 @@ static void sci_tx_dma_release(struct sci_port *s)
cancel_work_sync(>work_tx);
s->chan_tx_saved = s->chan_tx = NULL;
s->cookie_tx = -EINVAL;
-   dmaengine_terminate_all(chan);
+   dmaengine_terminate_sync(chan);
dma_unmap_single(chan->device->dev, s->tx_dma_addr, UART_XMIT_SIZE,
 DMA_TO_DEVICE);
dma_release_channel(chan);
@@ -1334,7 +1334,7 @@ static void sci_submit_rx(struct sci_port *s)
 
 fail:
if (i)
-   dmaengine_terminate_all(chan);
+   dmaengine_terminate_async(chan);
for (i = 0; i < 2; i++)
s->cookie_rx[i] = -EINVAL;
s->active_rx = -EINVAL;
@@ -1452,7 +1452,7 @@ static enum hrtimer_restart rx_timer_fn(struct hrtimer *t)
}
 
/* Handle incomplete DMA receive */
-   dmaengine_terminate_all(s->chan_rx);
+   dmaengine_terminate_async(s->chan_rx);
read = sg_dma_len(>sg_rx[active]) - state.residue;
 
if (read) {
-- 
2.17.1



[PATCH v2 1/3] serial: sh-sci: Postpone DMA release when falling back to PIO

2018-07-06 Thread Geert Uytterhoeven
When the sh-sci driver detects an issue with DMA during operation, it
falls backs to PIO, and releases all DMA resources.

As releasing DMA resources immediately has no advantages, but
complicates the code, and is susceptible to races, it is better to
postpone this to port shutdown.

This allows to remove the locking from sci_rx_dma_release() and
sci_tx_dma_release(), but requires keeping a copy of the DMA channel
pointers for release during port shutdown.

Signed-off-by: Geert Uytterhoeven 
---
v2:
  - Remove unused variable port in sci_[rt]x_dma_release().
---
 drivers/tty/serial/sh-sci.c | 83 ++---
 1 file changed, 41 insertions(+), 42 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index c181eb37f98509e6..674dc65454ae0684 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -135,6 +135,8 @@ struct sci_port {
struct dma_chan *chan_rx;
 
 #ifdef CONFIG_SERIAL_SH_SCI_DMA
+   struct dma_chan *chan_tx_saved;
+   struct dma_chan *chan_rx_saved;
dma_cookie_tcookie_tx;
dma_cookie_tcookie_rx[2];
dma_cookie_tactive_rx;
@@ -1212,25 +1214,16 @@ static int sci_dma_rx_find_active(struct sci_port *s)
return -1;
 }
 
-static void sci_rx_dma_release(struct sci_port *s, bool enable_pio)
+static void sci_rx_dma_release(struct sci_port *s)
 {
-   struct dma_chan *chan = s->chan_rx;
-   struct uart_port *port = >port;
-   unsigned long flags;
+   struct dma_chan *chan = s->chan_rx_saved;
 
-   spin_lock_irqsave(>lock, flags);
-   s->chan_rx = NULL;
+   s->chan_rx_saved = s->chan_rx = NULL;
s->cookie_rx[0] = s->cookie_rx[1] = -EINVAL;
-   spin_unlock_irqrestore(>lock, flags);
dmaengine_terminate_all(chan);
dma_free_coherent(chan->device->dev, s->buf_len_rx * 2, s->rx_buf[0],
  sg_dma_address(>sg_rx[0]));
dma_release_channel(chan);
-   if (enable_pio) {
-   spin_lock_irqsave(>lock, flags);
-   sci_start_rx(port);
-   spin_unlock_irqrestore(>lock, flags);
-   }
 }
 
 static void start_hrtimer_us(struct hrtimer *hrt, unsigned long usec)
@@ -1289,33 +1282,30 @@ static void sci_dma_rx_complete(void *arg)
 fail:
spin_unlock_irqrestore(>lock, flags);
dev_warn(port->dev, "Failed submitting Rx DMA descriptor\n");
-   sci_rx_dma_release(s, true);
+   /* Switch to PIO */
+   spin_lock_irqsave(>lock, flags);
+   s->chan_rx = NULL;
+   sci_start_rx(port);
+   spin_unlock_irqrestore(>lock, flags);
 }
 
-static void sci_tx_dma_release(struct sci_port *s, bool enable_pio)
+static void sci_tx_dma_release(struct sci_port *s)
 {
-   struct dma_chan *chan = s->chan_tx;
-   struct uart_port *port = >port;
-   unsigned long flags;
+   struct dma_chan *chan = s->chan_tx_saved;
 
-   spin_lock_irqsave(>lock, flags);
-   s->chan_tx = NULL;
+   s->chan_tx_saved = s->chan_tx = NULL;
s->cookie_tx = -EINVAL;
-   spin_unlock_irqrestore(>lock, flags);
dmaengine_terminate_all(chan);
dma_unmap_single(chan->device->dev, s->tx_dma_addr, UART_XMIT_SIZE,
 DMA_TO_DEVICE);
dma_release_channel(chan);
-   if (enable_pio) {
-   spin_lock_irqsave(>lock, flags);
-   sci_start_tx(port);
-   spin_unlock_irqrestore(>lock, flags);
-   }
 }
 
 static void sci_submit_rx(struct sci_port *s)
 {
struct dma_chan *chan = s->chan_rx;
+   struct uart_port *port = >port;
+   unsigned long flags;
int i;
 
for (i = 0; i < 2; i++) {
@@ -1347,7 +1337,11 @@ static void sci_submit_rx(struct sci_port *s)
for (i = 0; i < 2; i++)
s->cookie_rx[i] = -EINVAL;
s->active_rx = -EINVAL;
-   sci_rx_dma_release(s, true);
+   /* Switch to PIO */
+   spin_lock_irqsave(>lock, flags);
+   s->chan_rx = NULL;
+   sci_start_rx(port);
+   spin_unlock_irqrestore(>lock, flags);
 }
 
 static void work_fn_tx(struct work_struct *work)
@@ -1357,6 +1351,7 @@ static void work_fn_tx(struct work_struct *work)
struct dma_chan *chan = s->chan_tx;
struct uart_port *port = >port;
struct circ_buf *xmit = >state->xmit;
+   unsigned long flags;
dma_addr_t buf;
 
/*
@@ -1378,9 +1373,7 @@ static void work_fn_tx(struct work_struct *work)
   DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
if (!desc) {
dev_warn(port->dev, "Failed preparing Tx DMA descriptor\n");
-   /* switch to PIO */
-   sci_tx_dma_release(s, true);
-   return;
+   goto switch_to_pio;
}
 
dma_sync_single_for_device(chan->device->dev, buf, s->tx_dma_len,
@@ -1393,15 

[PATCH v2 2/3] serial: sh-sci: Stop TX DMA workqueue during port shutdown

2018-07-06 Thread Geert Uytterhoeven
The transmit DMA workqueue is never stopped, hence the work function may
be called after the port has been shut down.

Fix this race condition by cancelling queued work, if any, before DMA
release.  Don't initialize the work if DMA initialization failed, as it
won't be used anyway.

Signed-off-by: Geert Uytterhoeven 
---
v2:
  - No changes.
---
 drivers/tty/serial/sh-sci.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 674dc65454ae0684..939749073e7bdb11 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1293,6 +1293,7 @@ static void sci_tx_dma_release(struct sci_port *s)
 {
struct dma_chan *chan = s->chan_tx_saved;
 
+   cancel_work_sync(>work_tx);
s->chan_tx_saved = s->chan_tx = NULL;
s->cookie_tx = -EINVAL;
dmaengine_terminate_all(chan);
@@ -1548,10 +1549,9 @@ static void sci_request_dma(struct uart_port *port)
__func__, UART_XMIT_SIZE,
port->state->xmit.buf, >tx_dma_addr);
 
+   INIT_WORK(>work_tx, work_fn_tx);
s->chan_tx_saved = s->chan_tx = chan;
}
-
-   INIT_WORK(>work_tx, work_fn_tx);
}
 
chan = sci_request_dma_chan(port, DMA_DEV_TO_MEM);
-- 
2.17.1



[PATCH v2] dt-bindings: watchdog: renesas-wdt: Add support for the R8A77990 wdt

2018-07-06 Thread Geert Uytterhoeven
From: Masaharu Hayakawa 

Document support for the Watchdog Timer (WDT) Controller in the Renesas
R-Car E3 (R8A77990) SoC.

No driver update is needed.

Signed-off-by: Masaharu Hayakawa 
Signed-off-by: Geert Uytterhoeven 
Reviewed-by: Guenter Roeck 
Acked-by: Rob Herring 
---
v2:
  - Add Reviewed-by, Acked-by.
---
 Documentation/devicetree/bindings/watchdog/renesas-wdt.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/watchdog/renesas-wdt.txt 
b/Documentation/devicetree/bindings/watchdog/renesas-wdt.txt
index f24d802b8056f6c6..5d47a262474cfe0e 100644
--- a/Documentation/devicetree/bindings/watchdog/renesas-wdt.txt
+++ b/Documentation/devicetree/bindings/watchdog/renesas-wdt.txt
@@ -16,6 +16,7 @@ Required properties:
 - "renesas,r8a7796-wdt" (R-Car M3-W)
 - "renesas,r8a77965-wdt" (R-Car M3-N)
 - "renesas,r8a77970-wdt" (R-Car V3M)
+- "renesas,r8a77990-wdt" (R-Car E3)
 - "renesas,r8a77995-wdt" (R-Car D3)
 - "renesas,r7s72100-wdt" (RZ/A1)
The generic compatible string must be:
-- 
2.17.1



Re: [PATCH 5/5] ARM: shmobile: defconfig: Set CONFIG_LOCALVERSION

2018-07-06 Thread Geert Uytterhoeven
Hi Simon,

On Thu, Jul 5, 2018 at 5:55 PM Simon Horman  wrote:
> On Wed, Jul 04, 2018 at 01:43:33PM +0200, Geert Uytterhoeven wrote:
> > This allows to derive the kernel flavor from the kernel version at
> > runtime.
>
> For my edification could you expand on what this is used for?

With this, the kernel version (as printed during boot, and returned by
e.g. "uname -r") will be something like

4.18.0-rc3-shmobile-02146-gd2f8e14acc47b8ea

instead of

dmesg-4.18.0-rc3

which makes it easy to differentiate them from

4.18.0-rc3-koelsch-02146-gd2f8e14acc47b8ea
4.17.0-rc1-rcar2-initrd-00547-g19c9f87b5c449c23-dirty

which are built from my personal configs for Koelsch resp. R-Car Gen2
with initrd.

> > Signed-off-by: Geert Uytterhoeven 

> > --- a/arch/arm/configs/shmobile_defconfig
> > +++ b/arch/arm/configs/shmobile_defconfig
> > @@ -1,3 +1,4 @@
> > +CONFIG_LOCALVERSION="-shmobile"

We already have

CONFIG_LOCALVERSION="-arm64-renesas"

in arch/arm64/configs/renesas_defconfig, to differentiate kernels built
from that config with kernels built from arm64 defconfig (which set it to
"-arm64" in my local tree).

All of this makes it easy to keep e.g. a collection of boot logs using
"dmesg > dmesg-$(uname -r)", and compare them.

Thanks!

Gr{oetje,eeting}s,

Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH v2 3/4] mmc: renesas_sdhi: Fix sampling clock position selecting

2018-07-06 Thread Geert Uytterhoeven
On Thu, Jul 5, 2018 at 4:20 PM Niklas Söderlund
 wrote:
> From: Masaharu Hayakawa 
>
> When tuning each tap is issued CMD19 twice and the result of both runs
> recorded in host->taps. If the result is different between the two runs
> the wrong sampling clock position was selected. Fix this by merging the
> two runs and only keep the result for each tap if it was good in both
> sets.
>
> Signed-off-by: Masaharu Hayakawa 
> [Niklas: update commit message]
> Signed-off-by: Niklas Söderlund 

> --- a/drivers/mmc/host/renesas_sdhi_core.c
> +++ b/drivers/mmc/host/renesas_sdhi_core.c
> @@ -384,6 +384,19 @@ static int renesas_sdhi_select_tuning(struct 
> tmio_mmc_host *host)
> /* Clear SCC_RVSREQ */
> sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSREQ, 0);
>
> +   /*
> +* When tuning CMD19 is issued twice for each tap, merge the
> +* result requiring the tap to be good in both runs before
> +* consider it for tuning selection.

considering


Gr{oetje,eeting}s,

Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH v2 1/4] mmc: tmio: Fix tuning flow

2018-07-06 Thread Geert Uytterhoeven
Hi Niklas,

On Thu, Jul 5, 2018 at 4:20 PM Niklas Söderlund
 wrote:
> From: Masaharu Hayakawa 
>
> If the return value of mmc_send_tuning() is error other than -EILSEQ,
> the tuning fails and process goes out of for_loop. The correct
> processing is to judge their TAP as not good (NG) and continue.
>
> Signed-off-by: Masaharu Hayakawa 
> [Niklas: update commit message]
> Signed-off-by: Niklas Söderlund 
>
> ---
>
> * Changes since v1
> - Change '!mmc_send_tuning()' to 'mmc_send_tuning() == 0'.
> ---
>  drivers/mmc/host/tmio_mmc_core.c | 5 +
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/mmc/host/tmio_mmc_core.c 
> b/drivers/mmc/host/tmio_mmc_core.c
> index 416f9e078fda8b24..000fa9dff784ecb0 100644
> --- a/drivers/mmc/host/tmio_mmc_core.c
> +++ b/drivers/mmc/host/tmio_mmc_core.c
> @@ -817,10 +817,7 @@ static int tmio_mmc_execute_tuning(struct mmc_host *mmc, 
> u32 opcode)
> if (host->prepare_tuning)
> host->prepare_tuning(host, i % host->tap_num);
>
> -   ret = mmc_send_tuning(mmc, opcode, NULL);
> -   if (ret && ret != -EILSEQ)
> -   goto out;

I'd just drop the two lines above, and keep the assignment to and test of ret.
Kernel coding style is to not do checks on function return values in
if statements,
but assign to and check an intermediate variable.

> -   if (ret == 0)
> +   if (mmc_send_tuning(mmc, opcode, NULL) == 0)
> set_bit(i, host->taps);
>
> usleep_range(1000, 1200);

Gr{oetje,eeting}s,

Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds


Re: [PATCH v2] dmaengine: rcar-dmac: convert to SPDX identifiers

2018-07-06 Thread Vinod
On 04-07-18, 00:34, Kuninori Morimoto wrote:
> 
> From: Kuninori Morimoto 
> 
> This patch is using C++ comment style for SPDX line only,
> because driver author want it.

Applied, thanks

-- 
~Vinod