From patchwork Thu Jul 16 18:21:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 6810201 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 142EFC05AC for ; Thu, 16 Jul 2015 18:22:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1F0C620680 for ; Thu, 16 Jul 2015 18:22:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F24D420673 for ; Thu, 16 Jul 2015 18:22:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756237AbbGPSWQ (ORCPT ); Thu, 16 Jul 2015 14:22:16 -0400 Received: from albert.telenet-ops.be ([195.130.137.90]:33408 "EHLO albert.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756239AbbGPSWG (ORCPT ); Thu, 16 Jul 2015 14:22:06 -0400 Received: from ayla.of.borg ([84.193.93.87]) by albert.telenet-ops.be with bizsmtp id t6N31q0031t5w8s066N3Ax; Thu, 16 Jul 2015 20:22:04 +0200 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1ZFnnG-000084-Lt; Thu, 16 Jul 2015 20:22:02 +0200 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1ZFnnH-0007MI-FH; Thu, 16 Jul 2015 20:22:03 +0200 From: Geert Uytterhoeven To: Magnus Damm , Laurent Pinchart , Nobuhiro Iwamatsu , Yoshihiro Kaneko , Kazuya Mizuguchi , Koji Matsuoka , Wolfram Sang , Guennadi Liakhovetski Cc: linux-sh@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH/RFC v2 27/29] serial: sh-sci: Pass scatterlist to sci_dma_rx_push() Date: Thu, 16 Jul 2015 20:21:58 +0200 Message-Id: <1437070920-28069-28-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1437070920-28069-1-git-send-email-geert+renesas@glider.be> References: <1437070920-28069-1-git-send-email-geert+renesas@glider.be> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently sci_dma_rx_push() has to find the active scatterlist itself, but in some cases the caller already knows. Hence let the caller pass the scatterlist, and introduce a helper to find the active DMA request while we're at it. Signed-off-by: Geert Uytterhoeven --- drivers/tty/serial/sh-sci.c | 48 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 0e99c570e2da4d64..64589a04f1d36c74 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -1301,24 +1301,15 @@ static void sci_dma_tx_complete(void *arg) } /* Locking: called with port lock held */ -static int sci_dma_rx_push(struct sci_port *s, size_t count) +static int sci_dma_rx_push(struct sci_port *s, struct scatterlist *sg, + size_t count) { struct uart_port *port = &s->port; struct tty_port *tport = &port->state->port; - int i, active, room; + int i, room; room = tty_buffer_request_room(tport, count); - if (s->active_rx == s->cookie_rx[0]) { - active = 0; - } else if (s->active_rx == s->cookie_rx[1]) { - active = 1; - } else { - dev_err(port->dev, "%s: Rx cookie %d not found!\n", __func__, - s->active_rx); - return 0; - } - if (room < count) dev_warn(port->dev, "Rx overrun: dropping %zu bytes\n", count - room); @@ -1326,27 +1317,41 @@ static int sci_dma_rx_push(struct sci_port *s, size_t count) return room; for (i = 0; i < room; i++) - tty_insert_flip_char(tport, ((u8 *)sg_virt(&s->sg_rx[active]))[i], - TTY_NORMAL); + tty_insert_flip_char(tport, ((u8 *)sg_virt(sg))[i], TTY_NORMAL); port->icount.rx += room; return room; } +static int sci_dma_rx_find_active(struct sci_port *s) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(s->cookie_rx); i++) + if (s->active_rx == s->cookie_rx[i]) + return i; + + dev_err(s->port.dev, "%s: Rx cookie %u not found!\n", __func__, + s->active_rx); + return -1; +} + static void sci_dma_rx_complete(void *arg) { struct sci_port *s = arg; struct uart_port *port = &s->port; unsigned long flags; - int count; + int active, count = 0; dev_dbg(port->dev, "%s(%d) active cookie %d\n", __func__, port->line, s->active_rx); spin_lock_irqsave(&port->lock, flags); - count = sci_dma_rx_push(s, s->buf_len_rx); + active = sci_dma_rx_find_active(s); + if (active >= 0) + count = sci_dma_rx_push(s, &s->sg_rx[active], s->buf_len_rx); mod_timer(&s->rx_timer, jiffies + s->rx_timeout); @@ -1458,13 +1463,8 @@ static void work_fn_rx(struct work_struct *work) int new; spin_lock_irqsave(&port->lock, flags); - if (s->active_rx == s->cookie_rx[0]) { - new = 0; - } else if (s->active_rx == s->cookie_rx[1]) { - new = 1; - } else { - dev_err(port->dev, "%s: Rx cookie %d not found!\n", __func__, - s->active_rx); + new = sci_dma_rx_find_active(s); + if (new < 0) { spin_unlock_irqrestore(&port->lock, flags); return; } @@ -1482,7 +1482,7 @@ static void work_fn_rx(struct work_struct *work) dev_dbg(port->dev, "Read %zu bytes with cookie %d\n", read, s->active_rx); - count = sci_dma_rx_push(s, read); + count = sci_dma_rx_push(s, &s->sg_rx[new], read); if (count) tty_flip_buffer_push(&port->state->port);