public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tom Rini <trini@kernel.crashing.org>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org, trini@kernel.crashing.org
Subject: [patch 12/16] KGDBoE I/O driver
Date: Mon, 29 Aug 2005 09:11:21 -0700	[thread overview]
Message-ID: <resend.12.2982005.trini@kernel.crashing.org> (raw)
In-Reply-To: <resend.11.2982005.trini@kernel.crashing.org>


This is the simple KGDB over Ethernet I/O driver that uses netpoll for all of
the heavy lifting.  At one point this was very similar to the version Matt
Mackall wrote and is currently in Andrew's tree.  Since then it has been
reworked to fit into our model.

---

 linux-2.6.13-trini/drivers/net/Makefile |    1 
 linux-2.6.13-trini/drivers/net/kgdboe.c |  208 ++++++++++++++++++++++++++++
 linux-2.6.13-trini/lib/Kconfig.debug    |   24 +++
 3 files changed, 233 insertions(+)

diff -puN /dev/null drivers/net/kgdboe.c
--- /dev/null	2005-08-08 08:07:04.272443000 -0700
+++ linux-2.6.13-trini/drivers/net/kgdboe.c	2005-08-08 19:16:03.000000000 -0700
@@ -0,0 +1,208 @@
+/*
+ * drivers/net/kgdboe.c
+ *
+ * A network interface for GDB.
+ * Based upon 'gdbserial' by David Grothe <dave@gcom.com>
+ * and Scott Foehner <sfoehner@engr.sgi.com>
+ *
+ * Maintainers: Amit S. Kale <amitkale@linsyssoft.com> and
+ * 		Tom Rini <trini@kernel.crashing.org>
+ *
+ * 2004 (c) Amit S. Kale <amitkale@linsyssoft.com>
+ * 2004-2005 (c) MontaVista Software, Inc.
+ * 2005 (c) Wind River Systems, Inc.
+ *
+ * Other folks:
+ * San Mehat <nettwerk@biodome.org>
+ * Robert Walsh <rjwalsh@durables.org>
+ * wangdi <wangdi@clusterfs.com>.
+ * Matt Mackall <mpm@selenic.com>
+ * Pavel Machek <pavel@suse.cz>
+ * Jason Wessel <jason.wessel@windriver.com>
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ *
+ * Changes:
+ * 3/10/05 - Jason Wessel <jason.wessel@windriver.com>
+ * - Added ability to compile/load as module
+ *
+ * Known problems:
+ * - There is no way to deny the unloading of the module
+ *   if KGDB is connected, but an attempt is made to handle it
+ */
+
+#include <linux/kernel.h>
+#include <linux/interrupt.h>
+#include <linux/string.h>
+#include <linux/kgdb.h>
+#include <linux/netpoll.h>
+#include <linux/init.h>
+
+#include <asm/atomic.h>
+
+#define IN_BUF_SIZE 512		/* power of 2, please */
+#define OUT_BUF_SIZE 30		/* We don't want to send too big of a packet. */
+
+static char in_buf[IN_BUF_SIZE], out_buf[OUT_BUF_SIZE];
+static int in_head, in_tail, out_count;
+static atomic_t in_count;
+/* 0 = unconfigured, 1 = netpoll options parsed, 2 = fully configured. */
+static int configured;
+
+static void rx_hook(struct netpoll *np, int port, char *msg, int len);
+static void eth_pre_exception_handler(void);
+static void eth_post_exception_handler(void);
+static int eth_get_char(void);
+static void eth_flush_buf(void);
+static void eth_put_char(int chr);
+int init_kgdboe(void);
+
+static struct netpoll np = {
+	.name = "kgdboe",
+	.dev_name = "eth0",
+	.rx_hook = rx_hook,
+	.local_port = 6443,
+	.remote_port = 6442,
+	.remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
+};
+
+MODULE_DESCRIPTION("KGDB driver for network interfaces");
+MODULE_LICENSE("GPL");
+static char config[256];
+module_param_string(kgdboe, config, 256, 0);
+MODULE_PARM_DESC(kgdboe, " kgdboe=[src-port]@[src-ip]/[dev],"
+		 "[tgt-port]@<tgt-ip>/<tgt-macaddr>\n");
+
+static struct kgdb_io local_kgdb_io_ops = {
+	.read_char = eth_get_char,
+	.write_char = eth_put_char,
+	.init = init_kgdboe,
+	.flush = eth_flush_buf,
+	.pre_exception = eth_pre_exception_handler,
+	.post_exception = eth_post_exception_handler
+};
+
+static void eth_pre_exception_handler(void)
+{
+	netpoll_set_trap(1);
+}
+
+static void eth_post_exception_handler(void)
+{
+	netpoll_set_trap(0);
+}
+
+static int eth_get_char(void)
+{
+	int chr;
+
+	while (atomic_read(&in_count) == 0)
+		netpoll_poll(&np);
+
+	chr = in_buf[in_tail++];
+	in_tail &= (IN_BUF_SIZE - 1);
+	atomic_dec(&in_count);
+	return chr;
+}
+
+static void eth_flush_buf(void)
+{
+	if (out_count && np.dev) {
+		netpoll_send_udp(&np, out_buf, out_count);
+		memset(out_buf, 0, sizeof(out_buf));
+		out_count = 0;
+	}
+}
+
+static void eth_put_char(int chr)
+{
+	out_buf[out_count++] = chr;
+	if (out_count == OUT_BUF_SIZE)
+		eth_flush_buf();
+}
+
+static void rx_hook(struct netpoll *np, int port, char *msg, int len)
+{
+	int i;
+
+	np->remote_port = port;
+
+	/*
+	 * This could be GDB trying to attach.  But it could also be GDB
+	 * finishing up a session, with kgdb_connected=0 but GDB sending
+	 * an ACK for the final packet.  To make sure we don't try and
+	 * make a breakpoint when GDB is leaving, make sure that if
+	 * !kgdb_connected the only len == 1 packet we allow is ^C.
+	 */
+	if (!kgdb_connected && (len != 1 || msg[0] == 3) &&
+	    !atomic_read(&kgdb_setting_breakpoint))
+		tasklet_schedule(&kgdb_tasklet_breakpoint);
+
+	for (i = 0; i < len; i++) {
+		if (msg[i] == 3)
+			tasklet_schedule(&kgdb_tasklet_breakpoint);
+
+		if (atomic_read(&in_count) >= IN_BUF_SIZE) {
+			/* buffer overflow, clear it */
+			in_head = in_tail = 0;
+			atomic_set(&in_count, 0);
+			break;
+		}
+		in_buf[in_head++] = msg[i];
+		in_head &= (IN_BUF_SIZE - 1);
+		atomic_inc(&in_count);
+	}
+}
+
+static int option_setup(char *opt)
+{
+	configured = !netpoll_parse_options(&np, opt);
+	return 0;
+}
+
+__setup("kgdboe=", option_setup);
+
+int init_kgdboe(void)
+{
+	/* Already done? */
+	if (configured == 2)
+		return 0;
+
+	if (strlen(config))
+		option_setup(config);
+
+	if (!configured) {
+		printk("kgdboe: configuration incorrect - kgdboe not "
+		       "loaded.\n");
+		printk("  Usage: kgdboe=[src-port]@[src-ip]/[dev],[tgt-port]"
+		       "@<tgt-ip>/[tgt-macaddr]\n");
+		return -EINVAL;
+	}
+
+	if (netpoll_setup(&np)) {
+		printk("kgdboe: netpoll_setup failed kgdboe failed\n");
+		return -EINVAL;
+	}
+
+	if (kgdb_register_io_module(&local_kgdb_io_ops))
+		return -EINVAL;
+
+	printk(KERN_INFO "kgdboe: debugging over ethernet enabled\n");
+
+	configured = 2;
+
+	return 0;
+}
+
+static void cleanup_kgdboe(void)
+{
+	netpoll_cleanup(&np);
+	configured = 0;
+
+	kgdb_unregister_io_module(&local_kgdb_io_ops);
+}
+
+module_init(init_kgdboe);
+module_exit(cleanup_kgdboe);
diff -puN drivers/net/Makefile~eth drivers/net/Makefile
--- linux-2.6.13/drivers/net/Makefile~eth	2005-08-08 19:16:03.000000000 -0700
+++ linux-2.6.13-trini/drivers/net/Makefile	2005-08-08 19:16:03.000000000 -0700
@@ -195,3 +195,4 @@ obj-$(CONFIG_IRDA) += irda/
 obj-$(CONFIG_ETRAX_ETHERNET) += cris/
 
 obj-$(CONFIG_NETCONSOLE) += netconsole.o
+obj-$(CONFIG_KGDBOE) += kgdboe.o
diff -puN lib/Kconfig.debug~eth lib/Kconfig.debug
--- linux-2.6.13/lib/Kconfig.debug~eth	2005-08-08 19:16:03.000000000 -0700
+++ linux-2.6.13-trini/lib/Kconfig.debug	2005-08-08 19:16:03.000000000 -0700
@@ -217,6 +217,18 @@ config KGDB_8250_NOMODULE
 	  GDB.  This is independent of the normal (SERIAL_8250) driver
 	  for this chipset.
 
+config KGDBOE_NOMODULE
+	bool "KGDB: On ethernet - in kernel"
+	select KGDBOE
+	select NETPOLL
+	select NETPOLL_TRAP
+	select NETPOLL_RX
+	help
+	  Uses the NETPOLL API to communicate with the host GDB via UDP.
+	  In order for this to work, the ethernet interface specified must
+	  support the NETPOLL API, and this must be initialized at boot.
+	  See the documentation for syntax.
+
 config KGDB_MPSC
 	bool "KGDB on MV64x60 MPSC"
 	depends on SERIAL_MPSC
@@ -247,6 +259,18 @@ config KGDB_SH_SCI
 
 endchoice
 
+config KGDBOE
+	tristate "KGDB: On ethernet" if !KGDBOE_NOMODULE
+	depends on m && KGDB_ONLY_MODULES
+	select NETPOLL
+	select NETPOLL_TRAP
+	select NETPOLL_RX
+	help
+	  Uses the NETPOLL API to communicate with the host GDB via UDP.
+	  In order for this to work, the ethernet interface specified must
+	  support the NETPOLL API, and this must be initialized at boot.
+	  See the documentation for syntax.
+
 config KGDB_8250
 	tristate "KGDB: On generic serial port (8250)" if !KGDB_8250_NOMODULE
 	depends on m && KGDB_ONLY_MODULES
_

  reply	other threads:[~2005-08-29 16:12 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1.2982005.trini@kernel.crashing.org>
2005-08-29 16:08 ` [patch 01/16] Add a KGDB core Tom Rini
2005-08-29 16:09   ` [patch 02/16] Add support for i386 platforms to KGDB Tom Rini
2005-08-29 16:09     ` [patch 03/16] Add support for PowerPC32 " Tom Rini
2005-08-29 16:09       ` [patch 04/16] I/O driver for 8250-compatible UARTs Tom Rini
2005-08-29 16:09         ` [patch 05/16] Add support for MIPS platforms to KGDB Tom Rini
2005-08-29 16:10           ` [patch 06/16] Add support for IA64 " Tom Rini
2005-08-29 16:10             ` [patch 07/16] x86_64: Rename KDB_VECTOR to DEBUGGER_VECTOR Tom Rini
2005-08-29 16:10               ` [patch 08/16] Add support for X86_64 platforms to KGDB Tom Rini
2005-08-29 16:10                 ` [patch 09/16] Add support for SuperH " Tom Rini
2005-08-29 16:10                   ` [patch 10/16] Add support for ARM " Tom Rini
2005-08-29 16:11                     ` [patch 11/16] Add support for PowerPC64 " Tom Rini
2005-08-29 16:11                       ` Tom Rini [this message]
2005-08-29 16:11                         ` [patch 13/16] Add CFI DWARF2 annotation support Tom Rini
2005-08-29 16:11                           ` [patch 14/16] Minor SysRq keyboard bugfix for KGDB Tom Rini
2005-08-29 16:11                             ` [patch 15/16] Allow KGDB to work well with loaded modules Tom Rini
2005-08-29 16:12                               ` [patch 16/16] Add hardware breakpoint support for i386 Tom Rini
2005-08-29 21:23                                 ` Andi Kleen
2005-08-31 14:39                                   ` Tom Rini
2005-08-30  1:06                                 ` Keith Owens
2005-08-29 17:13                 ` [patch 08/16] Add support for X86_64 platforms to KGDB Andi Kleen
2005-08-29 17:45                   ` Tom Rini
2005-08-29 18:46                     ` Andi Kleen
2005-08-29 18:49                       ` Tom Rini
2005-08-29 16:18         ` [patch 04/16] I/O driver for 8250-compatible UARTs Russell King
2005-08-29 16:28           ` Tom Rini
2005-08-31 19:38         ` Bjorn Helgaas
2005-08-31 20:10           ` Tom Rini
2005-08-31 21:03             ` Russell King
2005-08-31 21:23               ` Tom Rini
2005-08-31 21:19             ` Bjorn Helgaas
2005-08-31 22:15               ` Tom Rini
2005-08-29 19:55     ` [patch 2/3] x86_64: Run setup_per_cpu_areas and trap_init sooner Andi Kleen
2005-08-29 20:03       ` Tom Rini
2005-08-30  7:33   ` [patch 1/3] x86_64: Add a notify_die() call to the "no context" part of do_page_fault() George Anzinger
2005-08-30 14:06     ` Tom Rini
2005-08-30 14:50       ` George Anzinger
2005-08-30 19:53         ` Tom Rini

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=resend.12.2982005.trini@kernel.crashing.org \
    --to=trini@kernel.crashing.org \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@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