linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: james_p_freyensee@linux.intel.com
To: gregkh@suse.de
Cc: linux-kernel@vger.kernel.org, suhail.ahmed@intel.com,
	james_p_freyensee@linux.intel.com
Subject: [PATCH 08/12] n_tracesink ldisc addition.
Date: Tue,  8 Feb 2011 11:34:53 -0800	[thread overview]
Message-ID: <1297193697-5417-9-git-send-email-james_p_freyensee@linux.intel.com> (raw)
In-Reply-To: <1297193697-5417-8-git-send-email-james_p_freyensee@linux.intel.com>

From: J Freyensee <james_p_freyensee@linux.intel.com>

This patch adds n_tracesink line discipline driver, which is
part of the Intel-Atom PTI implementation solution.

Signed-off-by: J Freyensee <james_p_freyensee@linux.intel.com>
---
 drivers/tty/n_tracesink.c |  253 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 253 insertions(+), 0 deletions(-)
 create mode 100644 drivers/tty/n_tracesink.c

diff --git a/drivers/tty/n_tracesink.c b/drivers/tty/n_tracesink.c
new file mode 100644
index 0000000..0d072e3
--- /dev/null
+++ b/drivers/tty/n_tracesink.c
@@ -0,0 +1,253 @@
+/*
+ *  n_tracesink.c - Trace data router and sink path through tty space.
+ *
+ *  Copyright (C) Intel 2010
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * The trace sink uses the Linux line discipline framework to receive
+ * trace data coming from the PTI source line discipline driver
+ * to a user-desired tty port, like USB.
+ * This is to provide a way to extract modem trace data on
+ * devices that do not have a PTI HW module, or just need modem
+ * trace data to come out of a different HW output port.
+ * This is part of a solution for the P1149.7, compact JTAG, standard.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <linux/tty.h>
+#include <linux/tty_ldisc.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <asm-generic/bug.h>
+#include <linux/n_tracesink.h>
+
+/* Other ldisc drivers use 65536 which basically means,
+ * 'I can always accept 64k' and flow control is off.
+ * This number is deemed appropriate for this driver.
+ */
+#define RECEIVE_ROOM	65536
+#define DRIVERNAME	"n_tracesink"
+
+/* there is a quirk with this ldisc is he can write data
+ * to a tty from anyone calling his kernel API, which
+ * meets customer requirements in the drivers/misc/pti.c
+ * project.  So he needs to know when he can and cannot write when
+ * the API is called. In theory, the API can be called
+ * after an init() but before a successful open() which
+ * would crash the system if tty is not checked.
+ */
+static struct tty_struct *this_tty;
+static DEFINE_MUTEX(writelock);
+
+/**
+ * n_tracesink_open() - Called when a tty is opened by a SW entity.
+ * @tty: terminal device to the ldisc.
+ *
+ * Return:
+ *      0 for success,
+ *      -EFAULT = couldn't get a tty kref n_tracesink will sit
+ *       on top of
+ *      -EEXIST = open() called successfully once and it cannot
+ *      be called again.
+ *
+ * Caveats: open() should only be successful the first time a
+ * SW entity calls it.
+ */
+static int n_tracesink_open(struct tty_struct *tty)
+{
+	int retval = -EEXIST;
+
+	mutex_lock(&writelock);
+	if (this_tty == NULL) {
+
+		this_tty = tty_kref_get(tty);
+
+		if (this_tty == NULL)
+			retval = -EFAULT;
+		else {
+			tty->disc_data = this_tty;
+			tty_driver_flush_buffer(tty);
+			retval = 0;
+		}
+	}
+	mutex_unlock(&writelock);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_close() - close connection
+ * @tty: terminal device to the ldisc.
+ *
+ * Called when a software entity wants to close a connection.
+ */
+static void n_tracesink_close(struct tty_struct *tty)
+{
+
+	tty_driver_flush_buffer(tty);
+
+	mutex_lock(&writelock);
+	tty_kref_put(this_tty);
+	this_tty = NULL;
+	mutex_unlock(&writelock);
+
+	tty->disc_data = NULL;
+}
+
+/**
+ * n_tracesink_read() - read request from user space
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * function that allows read() functionality in userspace. By default if this
+ * is not implemented it returns -EIO. This module is functioning like a
+ * router via n_tracesink_receivebuf(), and there is no real requirement
+ * to implement this function. However, an error return value other than
+ * -EIO should be used just to show that there was an intent not to have
+ * this function implemented.  Return value based on read() man pages.
+ *
+ * Return:
+ *	 -EINVAL
+ */
+static ssize_t n_tracesink_read(struct tty_struct *tty, struct file *file,
+				unsigned char __user *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ * n_tracesink_write() - Function that allows write() in userspace.
+ * @tty:  terminal device passed into the ldisc.
+ * @file: pointer to open file object.
+ * @buf:  pointer to the data buffer that gets eventually returned.
+ * @nr:   number of bytes of the data buffer that is returned.
+ *
+ * By default if this is not implemented, it returns -EIO.
+ * This should not be implemented, ever, because
+ * 1. this driver is functioning like a router via
+ *    n_tracesink_receivebuf()
+ * 2. No writes to HW will ever go through this line discpline driver.
+ * However, an error return value other than -EIO should be used
+ * just to show that there was an intent not to have this function
+ * implemented.  Return value based on write() man pages.
+ *
+ * Return:
+ *	-EINVAL
+ */
+static ssize_t n_tracesink_write(struct tty_struct *tty, struct file *file,
+				 const unsigned char *buf, size_t nr) {
+	return -EINVAL;
+}
+
+/**
+ *  mipi_pti_sinkdata() - Kernel API function used to route
+ *			trace debugging data to user-defined
+ *			port like USB.
+ *
+ * @buf:   Trace debuging data buffer to write to tty target
+ *         port. Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ *         return with no write occuring.
+ *
+ * Caveat: If this line discipline does not set the tty it sits
+ * on top of via an open() call, this API function will not
+ * call the tty's write() call because it will have no pointer
+ * to call the write().
+ */
+
+void n_tracesink_datadrain(u8 *cp, int count)
+{
+	mutex_lock(&writelock);
+
+	if ((cp != NULL) && (count > 0) && (this_tty != NULL))
+		this_tty->ops->write(this_tty, cp, count);
+
+	mutex_unlock(&writelock);
+}
+EXPORT_SYMBOL_GPL(n_tracesink_datadrain);
+
+/* Flush buffer is not impelemented as the ldisc has no internal buffering
+ * so the tty_driver_flush_buffer() is sufficient for this driver's needs.
+ */
+
+/*
+ * tty_ldisc function operations for this driver.
+ */
+static struct tty_ldisc_ops tty_n_tracesink = {
+	.owner		= THIS_MODULE,
+	.magic		= TTY_LDISC_MAGIC,
+	.name		= DRIVERNAME,
+	.open		= n_tracesink_open,
+	.close		= n_tracesink_close,
+	.read		= n_tracesink_read,
+	.write		= n_tracesink_write
+};
+
+/**
+ * n_tracesink_init-	module initialisation
+ *
+ * Registers this module as a line discipline driver.
+ *
+ * Return:
+ *	0 for success, any other value error.
+ */
+static int __init n_tracesink_init(void)
+{
+	int retval;
+
+	/* Note N_TRACESINK is defined in linux/tty.h */
+	retval = tty_register_ldisc(N_TRACESINK, &tty_n_tracesink);
+
+	if (retval < 0)
+		pr_err("%s: Registration failed: %d\n",
+					__func__, retval);
+
+	return retval;
+}
+
+/**
+ * n_tracesink_exit -	module unload
+ *
+ * Removes this module as a line discipline driver.
+ */
+static void __exit n_tracesink_exit(void)
+{
+	int retval;
+
+	retval = tty_unregister_ldisc(N_TRACESINK);
+
+	if (retval < 0)
+		pr_err("%s: Unregistration failed: %d\n",
+					__func__,  retval);
+}
+
+module_init(n_tracesink_init);
+module_exit(n_tracesink_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jay Freyensee");
+MODULE_ALIAS_LDISC(N_TRACESINK);
+MODULE_DESCRIPTION("Trace sink ldisc driver");
-- 
1.6.6.1


  reply	other threads:[~2011-02-08 19:36 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-08 19:34 Resend: Request for review and addition of PTI implementation into kernel james_p_freyensee
2011-02-08 19:34 ` [PATCH 01/12] export kernel call get_task_comm() james_p_freyensee
2011-02-08 19:34   ` [PATCH 02/12] Kernel documentation for the PTI feature james_p_freyensee
2011-02-08 19:34     ` [PATCH 03/12] Intel PTI implementaiton of 1149 james_p_freyensee
2011-02-08 19:34       ` [PATCH 04/12] PTI Kconfig change in misc james_p_freyensee
2011-02-08 19:34         ` [PATCH 05/12] PTI misc Makefile addition james_p_freyensee
2011-02-08 19:34           ` [PATCH 06/12] PTI header file james_p_freyensee
2011-02-08 19:34             ` [PATCH 07/12] n_tracerouter and n_tracesink additions james_p_freyensee
2011-02-08 19:34               ` james_p_freyensee [this message]
2011-02-08 19:34                 ` [PATCH 09/12] n_tracesink header file james_p_freyensee
2011-02-08 19:34                   ` [PATCH 10/12] n_tracerouter ldisc driver james_p_freyensee
2011-02-08 19:34                     ` [PATCH 11/12] n_tracerouter and n_tracesink Kconfig james_p_freyensee
2011-02-08 19:34                       ` [PATCH 12/12] n_tracerouter and n_tracesink Makefile addition james_p_freyensee
2011-02-08 21:03                       ` [PATCH 11/12] n_tracerouter and n_tracesink Kconfig Randy Dunlap
2011-02-17 19:23                   ` [PATCH 09/12] n_tracesink header file Greg KH
2011-02-17 19:45                     ` J Freyensee
2011-02-17 19:54                       ` Greg KH
2011-02-17 20:10                         ` J Freyensee
2011-02-17 21:43                           ` Greg KH
2011-02-22 20:22                             ` J Freyensee
2011-02-22 20:26                               ` Greg KH
2011-02-22 22:55                                 ` J Freyensee
2011-02-17 19:21               ` [PATCH 07/12] n_tracerouter and n_tracesink additions Greg KH
2011-02-17 19:43                 ` J Freyensee
2011-02-17 19:54                   ` Greg KH
2011-02-17 20:11                     ` J Freyensee
2011-02-24 11:52                   ` Alan Cox
2011-02-17 19:20             ` [PATCH 06/12] PTI header file Greg KH
2011-02-17 19:41               ` J Freyensee
2011-02-17 19:55                 ` Greg KH
2011-02-17 20:13                   ` J Freyensee
2011-02-17 19:20         ` [PATCH 04/12] PTI Kconfig change in misc Greg KH
2011-02-17 19:35           ` J Freyensee
2011-02-17 19:45             ` Greg KH
2011-02-08 20:55     ` [PATCH 02/12] Kernel documentation for the PTI feature Randy Dunlap
2011-02-08 19:38   ` [PATCH 01/12] export kernel call get_task_comm() Christoph Hellwig
2011-02-08 19:44     ` james_p_freyensee
2011-02-08 20:04       ` Christoph Hellwig
2011-02-08 20:35         ` james_p_freyensee
2011-02-08 20:28       ` Alan Cox
2011-02-08 20:28         ` Christoph Hellwig
2011-02-08 20:36           ` Alan Cox
2011-02-15 10:57             ` Christoph Hellwig
2011-02-22 18:38   ` J Freyensee
2011-02-22 18:41     ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2011-02-09  0:17 [PATCH 02/12] Kernel documentation for the PTI feature james_p_freyensee
2011-02-09  0:17 ` [PATCH 03/12] Intel PTI implementaiton of 1149 james_p_freyensee
2011-02-09  0:17   ` [PATCH 04/12] PTI Kconfig change in misc james_p_freyensee
2011-02-09  0:17     ` [PATCH 05/12] PTI misc Makefile addition james_p_freyensee
2011-02-09  0:17       ` [PATCH 06/12] PTI header file james_p_freyensee
2011-02-09  0:17         ` [PATCH 07/12] n_tracerouter and n_tracesink additions james_p_freyensee
2011-02-09  0:17           ` [PATCH 08/12] n_tracesink ldisc addition james_p_freyensee

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=1297193697-5417-9-git-send-email-james_p_freyensee@linux.intel.com \
    --to=james_p_freyensee@linux.intel.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=suhail.ahmed@intel.com \
    /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).