Skip to content

Commit 393abb6

Browse files
Jiri Slaby (SUSE)gregkh
authored andcommitted
tty: serial: 8250_omap: fix TX with DMA for am33xx
commit b495021 upstream. Commit 1788cf6 ("tty: serial: switch from circ_buf to kfifo") introduced an error in the TX DMA handling for 8250_omap. When the OMAP_DMA_TX_KICK flag is set, the "skip_byte" is pulled from the kfifo and emitted directly in order to start the DMA. While the kfifo is updated, dma->tx_size is not decreased. This leads to uart_xmit_advance() called in omap_8250_dma_tx_complete() advancing the kfifo by one too much. In practice, transmitting N bytes has been seen to result in the last N-1 bytes being sent repeatedly. This change fixes the problem by moving all of the dma setup after the OMAP_DMA_TX_KICK handling and using kfifo_len() instead of the DMA size for the 4-byte cutoff check. This slightly changes the behaviour at buffer wraparound, but it still transmits the correct bytes somehow. Now, the "skip_byte" would no longer be accounted to the stats. As previously, dma->tx_size included also this skip byte, up->icount.tx was updated by aforementioned uart_xmit_advance() in omap_8250_dma_tx_complete(). Fix this by using the uart_fifo_out() helper instead of bare kfifo_get(). Based on patch by Mans Rullgard <mans@mansr.com> Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org> Fixes: 1788cf6 ("tty: serial: switch from circ_buf to kfifo") Link: https://lore.kernel.org/all/20250506150748.3162-1-mans@mansr.com/ Reported-by: Mans Rullgard <mans@mansr.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20250522053835.3495975-1-jirislaby@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 00ddc7d commit 393abb6

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

drivers/tty/serial/8250/8250_omap.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,16 +1168,6 @@ static int omap_8250_tx_dma(struct uart_8250_port *p)
11681168
return 0;
11691169
}
11701170

1171-
sg_init_table(&sg, 1);
1172-
ret = kfifo_dma_out_prepare_mapped(&tport->xmit_fifo, &sg, 1,
1173-
UART_XMIT_SIZE, dma->tx_addr);
1174-
if (ret != 1) {
1175-
serial8250_clear_THRI(p);
1176-
return 0;
1177-
}
1178-
1179-
dma->tx_size = sg_dma_len(&sg);
1180-
11811171
if (priv->habit & OMAP_DMA_TX_KICK) {
11821172
unsigned char c;
11831173
u8 tx_lvl;
@@ -1202,18 +1192,22 @@ static int omap_8250_tx_dma(struct uart_8250_port *p)
12021192
ret = -EBUSY;
12031193
goto err;
12041194
}
1205-
if (dma->tx_size < 4) {
1195+
if (kfifo_len(&tport->xmit_fifo) < 4) {
12061196
ret = -EINVAL;
12071197
goto err;
12081198
}
1209-
if (!kfifo_get(&tport->xmit_fifo, &c)) {
1199+
if (!uart_fifo_out(&p->port, &c, 1)) {
12101200
ret = -EINVAL;
12111201
goto err;
12121202
}
12131203
skip_byte = c;
1214-
/* now we need to recompute due to kfifo_get */
1215-
kfifo_dma_out_prepare_mapped(&tport->xmit_fifo, &sg, 1,
1216-
UART_XMIT_SIZE, dma->tx_addr);
1204+
}
1205+
1206+
sg_init_table(&sg, 1);
1207+
ret = kfifo_dma_out_prepare_mapped(&tport->xmit_fifo, &sg, 1, UART_XMIT_SIZE, dma->tx_addr);
1208+
if (ret != 1) {
1209+
ret = -EINVAL;
1210+
goto err;
12171211
}
12181212

12191213
desc = dmaengine_prep_slave_sg(dma->txchan, &sg, 1, DMA_MEM_TO_DEV,
@@ -1223,6 +1217,7 @@ static int omap_8250_tx_dma(struct uart_8250_port *p)
12231217
goto err;
12241218
}
12251219

1220+
dma->tx_size = sg_dma_len(&sg);
12261221
dma->tx_running = 1;
12271222

12281223
desc->callback = omap_8250_dma_tx_complete;

0 commit comments

Comments
 (0)