linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: yegorslists@googlemail.com
To: linux-usb@vger.kernel.org
Cc: johan@kernel.org, gregkh@linuxfoundation.org,
	Yegor Yefremov <yegorslists@googlemail.com>
Subject: [PATCH] USB: serial: add port statistics
Date: Wed, 18 Sep 2019 11:14:15 +0200	[thread overview]
Message-ID: <20190918091415.23683-1-yegorslists@googlemail.com> (raw)

From: Yegor Yefremov <yegorslists@googlemail.com>

Add additional port statistics like received and transmitted bytes
the way /proc/tty/driver/serial does.

As usbserial driver already provides USB related information and
this line is longer than 100 characters, this patch adds an
additional line with the same port number:

0: module:ftdi_sio name:"FTDI USB Serial Device" vendor:0403 ...
0: tx:112 rx:0

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
---
 drivers/usb/serial/usb-serial.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index a3179fea38c8..154e65b6895f 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -42,6 +42,9 @@
 #define USB_SERIAL_TTY_MAJOR	188
 #define USB_SERIAL_TTY_MINORS	512	/* should be enough for a while */
 
+static int serial_get_icount(struct tty_struct *tty,
+				struct serial_icounter_struct *icount);
+
 /* There is no MODULE_DEVICE_TABLE for usbserial.c.  Instead
    the MODULE_DEVICE_TABLE declarations in each serial driver
    cause the "hotplug" program to pull in whatever module is necessary
@@ -471,10 +474,13 @@ static int serial_proc_show(struct seq_file *m, void *v)
 
 	seq_puts(m, "usbserinfo:1.0 driver:2.0\n");
 	for (i = 0; i < USB_SERIAL_TTY_MINORS; ++i) {
+		struct tty_struct *tty;
+		struct serial_icounter_struct icount;
 		port = usb_serial_port_get_by_minor(i);
 		if (port == NULL)
 			continue;
 		serial = port->serial;
+		tty = port->port.tty;
 
 		seq_printf(m, "%d:", i);
 		if (serial->type->driver.owner)
@@ -491,6 +497,22 @@ static int serial_proc_show(struct seq_file *m, void *v)
 		seq_printf(m, " path:%s", tmp);
 
 		seq_putc(m, '\n');
+		if (!serial_get_icount(tty, &icount)) {
+			seq_printf(m, "%d:", i);
+			seq_printf(m, " tx:%d rx:%d",
+					icount.tx, icount.rx);
+			if (icount.frame)
+				seq_printf(m, " fe:%d",	icount.frame);
+			if (icount.parity)
+				seq_printf(m, " pe:%d",	icount.parity);
+			if (icount.brk)
+				seq_printf(m, " brk:%d", icount.brk);
+			if (icount.overrun)
+				seq_printf(m, " oe:%d", icount.overrun);
+			if (icount.buf_overrun)
+				seq_printf(m, " bo:%d", icount.buf_overrun);
+			seq_putc(m, '\n');
+		}
 		usb_serial_put(serial);
 		mutex_unlock(&serial->disc_mutex);
 	}
-- 
2.17.0


             reply	other threads:[~2019-09-18  9:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-18  9:14 yegorslists [this message]
2019-09-18 11:08 ` [PATCH] USB: serial: add port statistics Greg KH
2019-09-18 11:22   ` Yegor Yefremov
2019-09-18 11:45     ` Greg KH
2019-09-18 11:51       ` Yegor Yefremov
2019-09-18 12:02         ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190918091415.23683-1-yegorslists@googlemail.com \
    --to=yegorslists@googlemail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).