Skip to content

Commit

Permalink
xocl: Make ulite work with kfifo replacement of circ_buf
Browse files Browse the repository at this point in the history
In linux v6.10 https://git.kernel.org/linus/1788cf6a91d9 switched tty port's
from circ_buf to kfifo.

Signed-off-by: Dmitry Safonov <[email protected]>
  • Loading branch information
0x7f454c46 committed Oct 22, 2024
1 parent 2d72575 commit ce06d4e
Showing 1 changed file with 49 additions and 5 deletions.
54 changes: 49 additions & 5 deletions src/runtime_src/core/pcie/driver/linux/xocl/subdev/ulite.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,51 @@ static int ulite_receive(struct uart_port *port, int stat)
return 1;
}

/* commit 1788cf6a91d9 ("tty: serial: switch from circ_buf to kfifo") */
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 10, 0)
static inline bool ulite_uart_is_empty(struct uart_port *p)
{
return uart_circ_empty(&p->state->xmit);
}
static inline unsigned ulite_uart_pending(struct uart_port *p)
{
return uart_circ_chars_pending(&p->state->xmit);
}
static inline int ulite_uart_pop_char(struct uart_port *port)
{
struct circ_buf *xmit = &port->state->xmit;
u8 ret = xmit->buf[xmit->tail];

/*
* When the tail of the circular buffer is reached, the next
* byte is transferred to the beginning of the buffer.
*/
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE-1);
return ret;
}
#else
static inline bool ulite_uart_is_empty(struct uart_port *p)
{
return kfifo_is_empty(&p->state->port.xmit_fifo);
}
static inline unsigned ulite_uart_pending(struct uart_port *p)
{
return kfifo_len(&p->state->port.xmit_fifo);
}
static inline int ulite_uart_pop_char(struct uart_port *port)
{
struct tty_port *tport = &port->state->port;
u8 ret;

if (!kfifo_get(&tport->xmit_fifo, &ret))
return -1;
return ret;
}
#endif

static int ulite_transmit(struct uart_port *port, int stat)
{
struct circ_buf *xmit = &port->state->xmit;
int ch;

if (stat & ULITE_STATUS_TXFULL)
return 0;
Expand All @@ -200,15 +242,17 @@ static int ulite_transmit(struct uart_port *port, int stat)
return 1;
}

if (uart_circ_empty(xmit) || uart_tx_stopped(port))
if (ulite_uart_is_empty(port) || uart_tx_stopped(port))
return 0;

uart_out32(xmit->buf[xmit->tail], ULITE_TX, port);
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE-1);
ch = ulite_uart_pop_char(port);
if (ch <= 0)
return 0;
uart_out32((char)ch, ULITE_TX, port);
port->icount.tx++;

/* wake up */
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
if (ulite_uart_pending(port) < WAKEUP_CHARS)
uart_write_wakeup(port);

return 1;
Expand Down

0 comments on commit ce06d4e

Please sign in to comment.