Skip to content

Commit 0533502

Browse files
geertugregkh
authored andcommitted
serial: sh-sci: Pass scatterlist to sci_dma_rx_push()
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 <geert+renesas@glider.be> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 04928b7 commit 0533502

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

drivers/tty/serial/sh-sci.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,52 +1301,57 @@ static void sci_dma_tx_complete(void *arg)
13011301
}
13021302

13031303
/* Locking: called with port lock held */
1304-
static int sci_dma_rx_push(struct sci_port *s, size_t count)
1304+
static int sci_dma_rx_push(struct sci_port *s, struct scatterlist *sg,
1305+
size_t count)
13051306
{
13061307
struct uart_port *port = &s->port;
13071308
struct tty_port *tport = &port->state->port;
1308-
int i, active, room;
1309+
int i, room;
13091310

13101311
room = tty_buffer_request_room(tport, count);
13111312

1312-
if (s->active_rx == s->cookie_rx[0]) {
1313-
active = 0;
1314-
} else if (s->active_rx == s->cookie_rx[1]) {
1315-
active = 1;
1316-
} else {
1317-
dev_err(port->dev, "%s: Rx cookie %d not found!\n", __func__,
1318-
s->active_rx);
1319-
return 0;
1320-
}
1321-
13221313
if (room < count)
13231314
dev_warn(port->dev, "Rx overrun: dropping %zu bytes\n",
13241315
count - room);
13251316
if (!room)
13261317
return room;
13271318

13281319
for (i = 0; i < room; i++)
1329-
tty_insert_flip_char(tport, ((u8 *)sg_virt(&s->sg_rx[active]))[i],
1330-
TTY_NORMAL);
1320+
tty_insert_flip_char(tport, ((u8 *)sg_virt(sg))[i], TTY_NORMAL);
13311321

13321322
port->icount.rx += room;
13331323

13341324
return room;
13351325
}
13361326

1327+
static int sci_dma_rx_find_active(struct sci_port *s)
1328+
{
1329+
unsigned int i;
1330+
1331+
for (i = 0; i < ARRAY_SIZE(s->cookie_rx); i++)
1332+
if (s->active_rx == s->cookie_rx[i])
1333+
return i;
1334+
1335+
dev_err(s->port.dev, "%s: Rx cookie %d not found!\n", __func__,
1336+
s->active_rx);
1337+
return -1;
1338+
}
1339+
13371340
static void sci_dma_rx_complete(void *arg)
13381341
{
13391342
struct sci_port *s = arg;
13401343
struct uart_port *port = &s->port;
13411344
unsigned long flags;
1342-
int count;
1345+
int active, count = 0;
13431346

13441347
dev_dbg(port->dev, "%s(%d) active cookie %d\n", __func__, port->line,
13451348
s->active_rx);
13461349

13471350
spin_lock_irqsave(&port->lock, flags);
13481351

1349-
count = sci_dma_rx_push(s, s->buf_len_rx);
1352+
active = sci_dma_rx_find_active(s);
1353+
if (active >= 0)
1354+
count = sci_dma_rx_push(s, &s->sg_rx[active], s->buf_len_rx);
13501355

13511356
mod_timer(&s->rx_timer, jiffies + s->rx_timeout);
13521357

@@ -1445,13 +1450,8 @@ static void work_fn_rx(struct work_struct *work)
14451450
int new;
14461451

14471452
spin_lock_irqsave(&port->lock, flags);
1448-
if (s->active_rx == s->cookie_rx[0]) {
1449-
new = 0;
1450-
} else if (s->active_rx == s->cookie_rx[1]) {
1451-
new = 1;
1452-
} else {
1453-
dev_err(port->dev, "%s: Rx cookie %d not found!\n", __func__,
1454-
s->active_rx);
1453+
new = sci_dma_rx_find_active(s);
1454+
if (new < 0) {
14551455
spin_unlock_irqrestore(&port->lock, flags);
14561456
return;
14571457
}
@@ -1468,7 +1468,7 @@ static void work_fn_rx(struct work_struct *work)
14681468
dev_dbg(port->dev, "Read %u bytes with cookie %d\n", read,
14691469
s->active_rx);
14701470

1471-
count = sci_dma_rx_push(s, read);
1471+
count = sci_dma_rx_push(s, &s->sg_rx[new], read);
14721472

14731473
if (count)
14741474
tty_flip_buffer_push(&port->state->port);

0 commit comments

Comments
 (0)