Skip to content

Commit c4a8dab

Browse files
peterhurleygregkh
authored andcommitted
staging/fwserial: Rip out rx buffering
Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7e1e71d commit c4a8dab

3 files changed

Lines changed: 28 additions & 117 deletions

File tree

‎drivers/staging/fwserial/fwserial.c‎

Lines changed: 27 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,27 @@ static int fwtty_write_port_status(struct fwtty_port *port)
456456
return err;
457457
}
458458

459-
static void __fwtty_throttle(struct fwtty_port *port, struct tty_struct *tty)
459+
static void fwtty_throttle_port(struct fwtty_port *port)
460460
{
461+
struct tty_struct *tty;
461462
unsigned old;
462463

464+
tty = tty_port_tty_get(&port->port);
465+
if (!tty)
466+
return;
467+
468+
spin_lock_bh(&port->lock);
469+
463470
old = port->mctrl;
464471
port->mctrl |= OOB_RX_THROTTLE;
465472
if (C_CRTSCTS(tty))
466473
port->mctrl &= ~TIOCM_RTS;
467474
if (~old & OOB_RX_THROTTLE)
468475
__fwtty_write_port_status(port);
476+
477+
spin_unlock_bh(&port->lock);
478+
479+
tty_kref_put(tty);
469480
}
470481

471482
/**
@@ -532,74 +543,8 @@ static void fwtty_emit_breaks(struct work_struct *work)
532543
port->icount.brk += brk;
533544
}
534545

535-
static void fwtty_pushrx(struct work_struct *work)
536-
{
537-
struct fwtty_port *port = to_port(work, push);
538-
struct tty_struct *tty;
539-
struct buffered_rx *buf, *next;
540-
int n, c = 0;
541-
542-
spin_lock_bh(&port->lock);
543-
list_for_each_entry_safe(buf, next, &port->buf_list, list) {
544-
n = tty_insert_flip_string_fixed_flag(&port->port, buf->data,
545-
TTY_NORMAL, buf->n);
546-
c += n;
547-
port->buffered -= n;
548-
if (n < buf->n) {
549-
if (n > 0) {
550-
memmove(buf->data, buf->data + n, buf->n - n);
551-
buf->n -= n;
552-
}
553-
tty = tty_port_tty_get(&port->port);
554-
if (tty) {
555-
__fwtty_throttle(port, tty);
556-
tty_kref_put(tty);
557-
}
558-
break;
559-
} else {
560-
list_del(&buf->list);
561-
kfree(buf);
562-
}
563-
}
564-
if (c > 0)
565-
tty_flip_buffer_push(&port->port);
566-
567-
if (list_empty(&port->buf_list))
568-
clear_bit(BUFFERING_RX, &port->flags);
569-
spin_unlock_bh(&port->lock);
570-
}
571-
572-
static int fwtty_buffer_rx(struct fwtty_port *port, unsigned char *d, size_t n)
573-
{
574-
struct buffered_rx *buf;
575-
size_t size = (n + sizeof(struct buffered_rx) + 0xFF) & ~0xFF;
576-
577-
if (port->buffered + n > HIGH_WATERMARK) {
578-
fwtty_err_ratelimited(port, "overflowed rx buffer: buffered: %d new: %zu wtrmk: %d\n",
579-
port->buffered, n, HIGH_WATERMARK);
580-
return 0;
581-
}
582-
buf = kmalloc(size, GFP_ATOMIC);
583-
if (!buf)
584-
return 0;
585-
INIT_LIST_HEAD(&buf->list);
586-
buf->n = n;
587-
memcpy(buf->data, d, n);
588-
589-
spin_lock_bh(&port->lock);
590-
list_add_tail(&buf->list, &port->buf_list);
591-
port->buffered += n;
592-
if (port->buffered > port->stats.watermark)
593-
port->stats.watermark = port->buffered;
594-
set_bit(BUFFERING_RX, &port->flags);
595-
spin_unlock_bh(&port->lock);
596-
597-
return n;
598-
}
599-
600546
static int fwtty_rx(struct fwtty_port *port, unsigned char *data, size_t len)
601547
{
602-
struct tty_struct *tty;
603548
int c, n = len;
604549
unsigned lsr;
605550
int err = 0;
@@ -636,31 +581,24 @@ static int fwtty_rx(struct fwtty_port *port, unsigned char *data, size_t len)
636581
goto out;
637582
}
638583

639-
if (!test_bit(BUFFERING_RX, &port->flags)) {
640-
c = tty_insert_flip_string_fixed_flag(&port->port, data,
641-
TTY_NORMAL, n);
642-
if (c > 0)
643-
tty_flip_buffer_push(&port->port);
644-
n -= c;
645-
646-
if (n) {
647-
/* start buffering and throttling */
648-
n -= fwtty_buffer_rx(port, &data[c], n);
649-
650-
tty = tty_port_tty_get(&port->port);
651-
if (tty) {
652-
spin_lock_bh(&port->lock);
653-
__fwtty_throttle(port, tty);
654-
spin_unlock_bh(&port->lock);
655-
tty_kref_put(tty);
656-
}
657-
}
658-
} else
659-
n -= fwtty_buffer_rx(port, data, n);
584+
c = tty_insert_flip_string_fixed_flag(&port->port, data, TTY_NORMAL, n);
585+
if (c > 0)
586+
tty_flip_buffer_push(&port->port);
587+
n -= c;
660588

661589
if (n) {
662590
port->overrun = true;
663591
err = -EIO;
592+
fwtty_err_ratelimited(port, "flip buffer overrun\n");
593+
594+
} else {
595+
/* throttle the sender if remaining flip buffer space has
596+
* reached high watermark to avoid losing data which may be
597+
* in-flight. Since the AR request context is 32k, that much
598+
* data may have _already_ been acked.
599+
*/
600+
if (tty_buffer_space_avail(&port->port) < HIGH_WATERMARK)
601+
fwtty_throttle_port(port);
664602
}
665603

666604
out:
@@ -1101,20 +1039,13 @@ static int fwtty_port_activate(struct tty_port *tty_port,
11011039
static void fwtty_port_shutdown(struct tty_port *tty_port)
11021040
{
11031041
struct fwtty_port *port = to_port(tty_port, port);
1104-
struct buffered_rx *buf, *next;
11051042

11061043
/* TODO: cancel outstanding transactions */
11071044

11081045
cancel_delayed_work_sync(&port->emit_breaks);
11091046
cancel_delayed_work_sync(&port->drain);
1110-
cancel_work_sync(&port->push);
11111047

11121048
spin_lock_bh(&port->lock);
1113-
list_for_each_entry_safe(buf, next, &port->buf_list, list) {
1114-
list_del(&buf->list);
1115-
kfree(buf);
1116-
}
1117-
port->buffered = 0;
11181049
port->flags = 0;
11191050
port->break_ctl = 0;
11201051
port->overrun = 0;
@@ -1264,8 +1195,6 @@ static void fwtty_unthrottle(struct tty_struct *tty)
12641195

12651196
profile_fifo_avail(port, port->stats.unthrottle);
12661197

1267-
schedule_work(&port->push);
1268-
12691198
spin_lock_bh(&port->lock);
12701199
port->mctrl &= ~OOB_RX_THROTTLE;
12711200
if (C_CRTSCTS(tty))
@@ -1523,8 +1452,7 @@ static void fwtty_debugfs_show_port(struct seq_file *m, struct fwtty_port *port)
15231452

15241453
seq_printf(m, " dr:%d st:%d err:%d lost:%d", stats.dropped,
15251454
stats.tx_stall, stats.fifo_errs, stats.lost);
1526-
seq_printf(m, " pkts:%d thr:%d wtrmk:%d", stats.sent, stats.throttled,
1527-
stats.watermark);
1455+
seq_printf(m, " pkts:%d thr:%d", stats.sent, stats.throttled);
15281456

15291457
if (port->port.console) {
15301458
seq_puts(m, "\n ");
@@ -2302,8 +2230,6 @@ static int fwserial_create(struct fw_unit *unit)
23022230
INIT_DELAYED_WORK(&port->drain, fwtty_drain_tx);
23032231
INIT_DELAYED_WORK(&port->emit_breaks, fwtty_emit_breaks);
23042232
INIT_WORK(&port->hangup, fwtty_do_hangup);
2305-
INIT_WORK(&port->push, fwtty_pushrx);
2306-
INIT_LIST_HEAD(&port->buf_list);
23072233
init_waitqueue_head(&port->wait_tx);
23082234
port->max_payload = link_speed_to_max_payload(SCODE_100);
23092235
dma_fifo_init(&port->tx_fifo);

‎drivers/staging/fwserial/fwserial.h‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ struct stats {
166166
unsigned sent;
167167
unsigned lost;
168168
unsigned throttled;
169-
unsigned watermark;
170169
unsigned reads[DISTRIBUTION_MAX_INDEX + 1];
171170
unsigned writes[DISTRIBUTION_MAX_INDEX + 1];
172171
unsigned txns[DISTRIBUTION_MAX_INDEX + 1];
@@ -183,12 +182,6 @@ struct fwconsole_ops {
183182
#define FWCON_NOTIFY_ATTACH 1
184183
#define FWCON_NOTIFY_DETACH 2
185184

186-
struct buffered_rx {
187-
struct list_head list;
188-
size_t n;
189-
unsigned char data[0];
190-
};
191-
192185
/**
193186
* fwtty_port: structure used to track/represent underlying tty_port
194187
* @port: underlying tty_port
@@ -223,11 +216,6 @@ struct buffered_rx {
223216
* The work can race with the writer but concurrent sending is
224217
* prevented with the IN_TX flag. Scheduled under lock to
225218
* limit scheduling when fifo has just been drained.
226-
* @push: work responsible for pushing buffered rx to the ldisc.
227-
* rx can become buffered if the tty buffer is filled before the
228-
* ldisc throttles the sender.
229-
* @buf_list: list of buffered rx yet to be sent to ldisc
230-
* @buffered: byte count of buffered rx
231219
* @tx_fifo: fifo used to store & block-up writes for dma to remote
232220
* @max_payload: max bytes transmissable per dma (based on peer's max_payload)
233221
* @status_mask: UART_LSR_* bitmask significant to rx (based on termios)
@@ -267,9 +255,6 @@ struct fwtty_port {
267255
spinlock_t lock;
268256
unsigned mctrl;
269257
struct delayed_work drain;
270-
struct work_struct push;
271-
struct list_head buf_list;
272-
int buffered;
273258
struct dma_fifo tx_fifo;
274259
int max_payload;
275260
unsigned status_mask;
@@ -291,7 +276,6 @@ struct fwtty_port {
291276
/* bit #s for flags field */
292277
#define IN_TX 0
293278
#define STOP_TX 1
294-
#define BUFFERING_RX 2
295279

296280
/* bitmasks for special mctrl/mstatus bits */
297281
#define OOB_RX_THROTTLE 0x00010000

‎drivers/tty/tty_buffer.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ int tty_buffer_space_avail(struct tty_port *port)
9292
int space = port->buf.mem_limit - atomic_read(&port->buf.mem_used);
9393
return max(space, 0);
9494
}
95+
EXPORT_SYMBOL_GPL(tty_buffer_space_avail);
9596

9697
static void tty_buffer_reset(struct tty_buffer *p, size_t size)
9798
{

0 commit comments

Comments
 (0)