@@ -84,6 +84,8 @@ static struct kmem_cache *fwtty_txn_cache;
8484struct tty_driver * fwtty_driver ;
8585static struct tty_driver * fwloop_driver ;
8686
87+ static struct dentry * fwserial_debugfs ;
88+
8789struct fwtty_transaction ;
8890typedef void (* fwtty_transaction_cb )(struct fw_card * card , int rcode ,
8991 void * data , size_t length ,
@@ -1568,11 +1570,71 @@ static int fwtty_proc_show(struct seq_file *m, void *v)
15681570 return 0 ;
15691571}
15701572
1573+ static int fwtty_debugfs_stats_show (struct seq_file * m , void * v )
1574+ {
1575+ struct fw_serial * serial = m -> private ;
1576+ struct fwtty_port * port ;
1577+ int i ;
1578+
1579+ for (i = 0 ; i < num_ports ; ++ i ) {
1580+ port = fwtty_port_get (serial -> ports [i ]-> index );
1581+ if (port ) {
1582+ seq_printf (m , "%2d:" , port -> index );
1583+ fwtty_proc_show_port (m , port );
1584+ fwtty_debugfs_show_port (m , port );
1585+ fwtty_port_put (port );
1586+ seq_printf (m , "\n" );
1587+ }
1588+ }
1589+ return 0 ;
1590+ }
1591+
1592+ static int fwtty_debugfs_peers_show (struct seq_file * m , void * v )
1593+ {
1594+ struct fw_serial * serial = m -> private ;
1595+ struct fwtty_peer * peer ;
1596+
1597+ rcu_read_lock ();
1598+ seq_printf (m , "card: %s guid: %016llx\n" ,
1599+ dev_name (serial -> card -> device ),
1600+ (unsigned long long ) serial -> card -> guid );
1601+ list_for_each_entry_rcu (peer , & serial -> peer_list , list )
1602+ fwtty_debugfs_show_peer (m , peer );
1603+ rcu_read_unlock ();
1604+ return 0 ;
1605+ }
1606+
15711607static int fwtty_proc_open (struct inode * inode , struct file * fp )
15721608{
15731609 return single_open (fp , fwtty_proc_show , NULL );
15741610}
15751611
1612+ static int fwtty_stats_open (struct inode * inode , struct file * fp )
1613+ {
1614+ return single_open (fp , fwtty_debugfs_stats_show , inode -> i_private );
1615+ }
1616+
1617+ static int fwtty_peers_open (struct inode * inode , struct file * fp )
1618+ {
1619+ return single_open (fp , fwtty_debugfs_peers_show , inode -> i_private );
1620+ }
1621+
1622+ static const struct file_operations fwtty_stats_fops = {
1623+ .owner = THIS_MODULE ,
1624+ .open = fwtty_stats_open ,
1625+ .read = seq_read ,
1626+ .llseek = seq_lseek ,
1627+ .release = single_release ,
1628+ };
1629+
1630+ static const struct file_operations fwtty_peers_fops = {
1631+ .owner = THIS_MODULE ,
1632+ .open = fwtty_peers_open ,
1633+ .read = seq_read ,
1634+ .llseek = seq_lseek ,
1635+ .release = single_release ,
1636+ };
1637+
15761638static const struct file_operations fwtty_proc_fops = {
15771639 .owner = THIS_MODULE ,
15781640 .open = fwtty_proc_open ,
@@ -2309,6 +2371,17 @@ static int fwserial_create(struct fw_unit *unit)
23092371 serial -> ports [j ]-> loopback = true;
23102372 }
23112373
2374+ if (!IS_ERR_OR_NULL (fwserial_debugfs )) {
2375+ serial -> debugfs = debugfs_create_dir (dev_name (& unit -> device ),
2376+ fwserial_debugfs );
2377+ if (!IS_ERR_OR_NULL (serial -> debugfs )) {
2378+ debugfs_create_file ("peers" , 0444 , serial -> debugfs ,
2379+ serial , & fwtty_peers_fops );
2380+ debugfs_create_file ("stats" , 0444 , serial -> debugfs ,
2381+ serial , & fwtty_stats_fops );
2382+ }
2383+ }
2384+
23122385 list_add_rcu (& serial -> list , & fwserial_list );
23132386
23142387 fwtty_notice (& unit , "TTY over FireWire on device %s (guid %016llx)" ,
@@ -2321,6 +2394,8 @@ static int fwserial_create(struct fw_unit *unit)
23212394 fwtty_err (& unit , "unable to add peer unit device (%d)" , err );
23222395
23232396 /* fall-through to error processing */
2397+ debugfs_remove_recursive (serial -> debugfs );
2398+
23242399 list_del_rcu (& serial -> list );
23252400 if (create_loop_dev )
23262401 tty_unregister_device (fwloop_driver , loop_idx (serial -> ports [j ]));
@@ -2412,6 +2487,8 @@ static int fwserial_remove(struct device *dev)
24122487 /* unlink from the fwserial_list here */
24132488 list_del_rcu (& serial -> list );
24142489
2490+ debugfs_remove_recursive (serial -> debugfs );
2491+
24152492 for (i = 0 ; i < num_ttys ; ++ i )
24162493 fwserial_close_port (fwtty_driver , serial -> ports [i ]);
24172494 if (create_loop_dev )
@@ -2806,6 +2883,9 @@ static int __init fwserial_init(void)
28062883{
28072884 int err , num_loops = !!(create_loop_dev );
28082885
2886+ /* XXX: placeholder for a "firewire" debugfs node */
2887+ fwserial_debugfs = debugfs_create_dir (KBUILD_MODNAME , NULL );
2888+
28092889 /* num_ttys/num_ports must not be set above the static alloc avail */
28102890 if (num_ttys + num_loops > MAX_CARD_PORTS )
28112891 num_ttys = MAX_CARD_PORTS - num_loops ;
@@ -2920,6 +3000,7 @@ static int __init fwserial_init(void)
29203000 tty_unregister_driver (fwtty_driver );
29213001put_tty :
29223002 put_tty_driver (fwtty_driver );
3003+ debugfs_remove_recursive (fwserial_debugfs );
29233004 return err ;
29243005}
29253006
@@ -2935,6 +3016,7 @@ static void __exit fwserial_exit(void)
29353016 }
29363017 tty_unregister_driver (fwtty_driver );
29373018 put_tty_driver (fwtty_driver );
3019+ debugfs_remove_recursive (fwserial_debugfs );
29383020}
29393021
29403022module_init (fwserial_init );
0 commit comments