@@ -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-
600546static 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
666604out :
@@ -1101,20 +1039,13 @@ static int fwtty_port_activate(struct tty_port *tty_port,
11011039static 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 );
0 commit comments