Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hsu dma optimize #35

Merged
merged 3 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions drivers/tty/serial/8250/8250.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct uart_8250_dma {
unsigned char tx_running;
unsigned char tx_err;
unsigned char rx_running;

unsigned int dma_tx_nents;
struct scatterlist tx_sgl[2];
};

struct old_serial_port {
Expand Down
29 changes: 24 additions & 5 deletions drivers/tty/serial/8250/8250_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ static void __dma_rx_complete(void *param)
int serial8250_tx_dma(struct uart_8250_port *p)
{
struct uart_8250_dma *dma = p->dma;
struct scatterlist *sgl = dma->tx_sgl;
struct circ_buf *xmit = &p->port.state->xmit;
struct dma_async_tx_descriptor *desc;
int ret;
size_t chunk1, chunk2;
int head, tail;

if (dma->tx_running)
return 0;
Expand All @@ -75,12 +78,28 @@ int serial8250_tx_dma(struct uart_8250_port *p)
return 0;
}

dma->tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
head = READ_ONCE(xmit->head);
tail = READ_ONCE(xmit->tail);
dma->dma_tx_nents = 1;
chunk1 = CIRC_CNT_TO_END(head, tail, UART_XMIT_SIZE);
chunk2 = CIRC_CNT(head, tail, UART_XMIT_SIZE) - chunk1;
if (chunk2 == 0) {
sg_init_one(sgl, xmit->buf + tail, chunk1);
} else {
dma->dma_tx_nents++;
sg_init_table(sgl, dma->dma_tx_nents);
sg_set_buf(&sgl[0], xmit->buf + tail, chunk1);
sg_set_buf(&sgl[1], xmit->buf, chunk2);
sg_dma_address(&sgl[1]) = dma->tx_addr;
sg_dma_len(&sgl[1]) = chunk2;
}
sg_dma_address(&sgl[0]) = dma->tx_addr + tail;
sg_dma_len(&sgl[0]) = chunk1;
dma->tx_size = chunk1 + chunk2;

desc = dmaengine_prep_slave_single(dma->txchan,
dma->tx_addr + xmit->tail,
dma->tx_size, DMA_MEM_TO_DEV,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
desc = dmaengine_prep_slave_sg(dma->txchan, sgl, dma->dma_tx_nents,
DMA_MEM_TO_DEV,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
if (!desc) {
ret = -EBUSY;
goto err;
Expand Down
27 changes: 27 additions & 0 deletions drivers/tty/serial/8250/8250_mid.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ static int tng_handle_irq(struct uart_port *p)
err = hsu_dma_get_status(chip, mid->dma_index * 2 + 1, &status);
if (err > 0) {
serial8250_rx_dma_flush(up);
/* Immediately after flushing arm DMA again */
if (up->dma) up->dma->rx_dma(up);
ret |= 1;
} else if (err == 0)
ret |= hsu_dma_do_irq(chip, mid->dma_index * 2 + 1, status);
Expand Down Expand Up @@ -232,6 +234,29 @@ static void mid8250_set_termios(struct uart_port *p,
serial8250_do_set_termios(p, termios, old);
}

static int mid8250_startup(struct uart_port *port)
{
struct uart_8250_port *up = up_to_u8250p(port);
int ret;

ret = serial8250_do_startup(port);

/* Arm Rx DMA at ->startup() time */

if (up->dma) up->dma->rx_dma(up);

return ret;
}

static void mid8250_shutdown(struct uart_port *port)
{
struct uart_8250_port *up = up_to_u8250p(port);

if (up->dma) serial8250_rx_dma_flush(up);

serial8250_do_shutdown(port);
}

static bool mid8250_dma_filter(struct dma_chan *chan, void *param)
{
struct hsu_dma_slave *s = param;
Expand Down Expand Up @@ -306,6 +331,8 @@ static int mid8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
uart.port.uartclk = mid->board->base_baud * 16;
uart.port.flags = UPF_SHARE_IRQ | UPF_FIXED_PORT | UPF_FIXED_TYPE;
uart.port.set_termios = mid8250_set_termios;
uart.port.startup = mid8250_startup;
uart.port.shutdown = mid8250_shutdown;

uart.port.mapbase = pci_resource_start(pdev, bar);
uart.port.membase = pcim_iomap(pdev, bar, 0);
Expand Down