Whamcloud - gitweb
update .snap on smfs
[fs/lustre-release.git] / lustre / kernel_patches / patches / kgdb-over-netpoll.patch
1  l-mpm/Documentation/i386/kgdb/kgdbeth.txt |   88 +----
2  l-mpm/arch/i386/kernel/irq.c              |   10 
3  l-mpm/arch/i386/kernel/kgdb_stub.c        |  107 +-----
4  l-mpm/arch/i386/lib/kgdb_serial.c         |    2 
5  l-mpm/drivers/net/Makefile                |    5 
6  l-mpm/drivers/net/kgdb_eth.c              |  464 ++++--------------------------
7  l-mpm/include/asm-i386/kgdb.h                  |   11 
8  l-mpm/net/core/dev.c                      |    4 
9  8 files changed, 129 insertions(+), 562 deletions(-)
10
11 Index: linux-2.6.0-test6/drivers/net/kgdb_eth.c
12 ===================================================================
13 --- linux-2.6.0-test6.orig/drivers/net/kgdb_eth.c       2003-10-12 13:12:22.000000000 +0800
14 +++ linux-2.6.0-test6/drivers/net/kgdb_eth.c    2003-10-12 13:12:25.000000000 +0800
15 @@ -7,36 +7,26 @@
16   *
17   * Twiddled for 2.6 by Robert Walsh <rjwalsh@durables.org>
18   * and wangdi <wangdi@clusterfs.com>.
19 + *
20 + * Refactored for netpoll API by Matt Mackall <mpm@selenic.com>
21 + *
22   */
23  
24 -#include <linux/module.h>
25 -#include <linux/errno.h>
26 -#include <linux/signal.h>
27  #include <linux/sched.h>
28 -#include <linux/timer.h>
29  #include <linux/interrupt.h>
30  #include <linux/config.h>
31 -#include <linux/major.h>
32  #include <linux/string.h>
33 -#include <linux/fcntl.h>
34 -#include <linux/termios.h>
35 -#include <asm/kgdb.h>
36 -#include <linux/if_ether.h>
37 -#include <linux/netdevice.h>
38 -#include <linux/etherdevice.h>
39 -#include <linux/skbuff.h>
40 -#include <linux/delay.h>
41 -#include <net/tcp.h>
42 -#include <net/udp.h>
43 +#include <linux/netpoll.h>
44  
45  #include <asm/system.h>
46 +#include <asm/kgdb.h>
47  #include <asm/io.h>
48 -#include <asm/segment.h>
49  #include <asm/bitops.h>
50  #include <asm/system.h>
51  #include <asm/irq.h>
52  #include <asm/atomic.h>
53  
54 +
55  #define        GDB_BUF_SIZE    512             /* power of 2, please */
56  
57  static char    kgdb_buf[GDB_BUF_SIZE] ;
58 @@ -44,26 +34,28 @@
59  static atomic_t        kgdb_buf_in_cnt ;
60  static int     kgdb_buf_out_inx ;
61  
62 +#define ETH_QUEUE_SIZE 256
63 +static char eth_queue[ETH_QUEUE_SIZE];
64 +static int outgoing_queue;
65 +
66  extern void    set_debug_traps(void) ;         /* GDB routine */
67  extern void    breakpoint(void);
68  
69 -unsigned int   kgdb_remoteip = 0;
70 -unsigned short kgdb_listenport = 6443;
71 -unsigned short kgdb_sendport= 6442;
72 -int            kgdb_eth = -1; /* Default tty mode */
73 -unsigned char  kgdb_remotemac[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
74 -unsigned char  kgdb_localmac[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
75 -volatile int   kgdb_eth_is_initializing = 0;
76 -int            kgdb_eth_need_breakpoint[NR_CPUS];
77 +int kgdboe = 0; /* Default tty mode */
78 +int kgdb_eth_need_breakpoint[NR_CPUS];
79  
80 -struct net_device *kgdb_netdevice = NULL;
81 +static void rx_hook(struct netpoll *np, int port, char *msg, int len);
82  
83 -/*
84 - * Get a char if available, return -1 if nothing available.
85 - * Empty the receive buffer first, then look at the interface hardware.
86 - */
87 -static int
88 -read_char(void)
89 +static struct netpoll np = {
90 +       .name = "kgdboe",
91 +       .dev_name = "eth0",
92 +       .rx_hook = rx_hook,
93 +       .local_port = 6443,
94 +       .remote_port = 6442,
95 +       .remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
96 +};
97 +
98 +static int read_char(void)
99  {
100         /* intr routine has queued chars */
101         if (atomic_read(&kgdb_buf_in_cnt) != 0)
102 @@ -79,287 +71,32 @@
103         return -1; /* no data */
104  }
105  
106 -/*
107 - * Wait until the interface can accept a char, then write it.
108 - */
109 -static void
110 -write_buffer(char *buf, int len)
111 +static void write_buffer(char *buf, int len)
112  {
113 -       int                     total_len, eth_len, ip_len, udp_len;
114 -       struct in_device        *in_dev;
115 -       struct sk_buff          *skb;
116 -       struct udphdr           *udph;
117 -       struct iphdr            *iph;
118 -       struct ethhdr           *eth;
119 -
120 -       if (!(in_dev = (struct in_device *) kgdb_netdevice->ip_ptr)) {
121 -               panic("No in_device available for interface!\n");
122 -       }
123 -
124 -       if (!(in_dev->ifa_list)) {
125 -               panic("No interface address set for interface!\n");
126 -       }
127 -
128 -       udp_len = len + sizeof(struct udphdr);
129 -       ip_len = eth_len = udp_len + sizeof(struct iphdr);
130 -       total_len = eth_len + ETH_HLEN;
131 -
132 -       if (!(skb = alloc_skb(total_len, GFP_ATOMIC))) {
133 +       if (!np.dev)
134                 return;
135 -       }
136 -
137 -       atomic_set(&skb->users, 1);
138 -       skb_reserve(skb, total_len - len);
139 -
140 -       memcpy(skb->data, (unsigned char *) buf, len);
141 -       skb->len += len;
142 -
143 -       udph = (struct udphdr *) skb_push(skb, sizeof(*udph));
144 -       udph->source = htons(kgdb_listenport);
145 -       udph->dest   = htons(kgdb_sendport);
146 -       udph->len    = htons(udp_len);
147 -       udph->check  = 0;
148 -
149 -       iph = (struct iphdr *)skb_push(skb, sizeof(*iph));
150 -       iph->version  = 4;
151 -       iph->ihl      = 5;
152 -       iph->tos      = 0;
153 -       iph->tot_len  = htons(ip_len);
154 -       iph->id       = 0;
155 -       iph->frag_off = 0;
156 -       iph->ttl      = 64;
157 -       iph->protocol = IPPROTO_UDP;
158 -       iph->check    = 0;
159 -       iph->saddr    = in_dev->ifa_list->ifa_address;
160 -       iph->daddr    = kgdb_remoteip;
161 -       iph->check    = ip_fast_csum((unsigned char *)iph, iph->ihl);
162 -
163 -       eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);
164 -       eth->h_proto = htons(ETH_P_IP);
165 -       memcpy(eth->h_source, kgdb_localmac, kgdb_netdevice->addr_len);
166 -       memcpy(eth->h_dest, kgdb_remotemac, kgdb_netdevice->addr_len);
167 -
168 -repeat:
169 -       spin_lock(&kgdb_netdevice->xmit_lock);
170 -       kgdb_netdevice->xmit_lock_owner = smp_processor_id();
171 -
172 -       if (netif_queue_stopped(kgdb_netdevice)) {
173 -               kgdb_netdevice->xmit_lock_owner = -1;
174 -               spin_unlock(&kgdb_netdevice->xmit_lock);
175 -
176 -               kgdb_netdevice->poll_controller(kgdb_netdevice);
177 -               goto repeat;
178 -       }
179 -
180 -       kgdb_netdevice->hard_start_xmit(skb, kgdb_netdevice);
181 -       kgdb_netdevice->xmit_lock_owner = -1;
182 -       spin_unlock(&kgdb_netdevice->xmit_lock);
183 +       netpoll_send_udp(&np, buf, len);
184  }
185  
186  /*
187 - * In the interrupt state the target machine will not respond to any
188 - * arp requests, so handle them here.
189 - */
190 -
191 -static struct sk_buff *send_skb = NULL;
192 -
193 -void
194 -kgdb_eth_reply_arp(void)
195 -{
196 -       if (send_skb) {
197 -               spin_lock(&kgdb_netdevice->xmit_lock);
198 -               kgdb_netdevice->xmit_lock_owner = smp_processor_id();
199 -               kgdb_netdevice->hard_start_xmit(send_skb, kgdb_netdevice);
200 -               kgdb_netdevice->xmit_lock_owner = -1;
201 -               spin_unlock(&kgdb_netdevice->xmit_lock);
202 -               send_skb = NULL;
203 -       }
204 -}
205 -
206 -static int
207 -make_arp_request(struct sk_buff *skb)
208 -{
209 -       struct arphdr *arp;
210 -       unsigned char *arp_ptr;
211 -       int type = ARPOP_REPLY;
212 -       int ptype = ETH_P_ARP;
213 -       u32 sip, tip;
214 -       unsigned char *sha, *tha;
215 -       struct in_device *in_dev = (struct in_device *) kgdb_netdevice->ip_ptr;
216 -
217 -       /* No arp on this interface */
218 -
219 -       if (kgdb_netdevice->flags & IFF_NOARP) {
220 -               return 0;
221 -       }
222 -
223 -       if (!pskb_may_pull(skb, (sizeof(struct arphdr) +
224 -                                (2 * kgdb_netdevice->addr_len) +
225 -                                (2 * sizeof(u32))))) {
226 -               return 0;
227 -       }
228 -
229 -       skb->h.raw = skb->nh.raw = skb->data;
230 -       arp = skb->nh.arph;
231 -
232 -       if ((arp->ar_hrd != htons(ARPHRD_ETHER) &&
233 -            arp->ar_hrd != htons(ARPHRD_IEEE802)) ||
234 -           arp->ar_pro != htons(ETH_P_IP)) {
235 -               return 0;
236 -       }
237 -
238 -       /* Understand only these message types */
239 -
240 -       if (arp->ar_op != htons(ARPOP_REQUEST)) {
241 -               return 0;
242 -       }
243 -
244 -       /* Extract fields */
245 -
246 -       arp_ptr= (unsigned char *)(arp+1);
247 -       sha = arp_ptr;
248 -       arp_ptr += kgdb_netdevice->addr_len;
249 -       memcpy(&sip, arp_ptr, 4);
250 -       arp_ptr += 4;
251 -       tha = arp_ptr;
252 -       arp_ptr += kgdb_netdevice->addr_len;
253 -       memcpy(&tip, arp_ptr, 4);
254 -
255 -       if (tip != in_dev->ifa_list->ifa_address) {
256 -               return 0;
257 -       }
258 -
259 -       if (kgdb_remoteip != sip) {
260 -               return 0;
261 -       }
262 -
263 -       /*
264 -        * Check for bad requests for 127.x.x.x and requests for multicast
265 -        * addresses.  If this is one such, delete it.
266 -        */
267 -
268 -       if (LOOPBACK(tip) || MULTICAST(tip)) {
269 -               return 0;
270 -       }
271 -
272 -       /* reply to the ARP request */
273 -
274 -       send_skb = alloc_skb(sizeof(struct arphdr) + 2 * (kgdb_netdevice->addr_len + 4) + LL_RESERVED_SPACE(kgdb_netdevice), GFP_ATOMIC);
275 -
276 -       if (send_skb == NULL) {
277 -               return 0;
278 -       }
279 -
280 -       skb_reserve(send_skb, LL_RESERVED_SPACE(kgdb_netdevice));
281 -       send_skb->nh.raw = send_skb->data;
282 -       arp = (struct arphdr *) skb_put(send_skb, sizeof(struct arphdr) + 2 * (kgdb_netdevice->addr_len + 4));
283 -       send_skb->dev = kgdb_netdevice;
284 -       send_skb->protocol = htons(ETH_P_ARP);
285 -
286 -       /* Fill the device header for the ARP frame */
287 -
288 -       if (kgdb_netdevice->hard_header &&
289 -           kgdb_netdevice->hard_header(send_skb, kgdb_netdevice, ptype,
290 -                                      kgdb_remotemac, kgdb_localmac,
291 -                                      send_skb->len) < 0) {
292 -               kfree_skb(send_skb);
293 -               return 0;
294 -       }
295 -
296 -       /*
297 -        * Fill out the arp protocol part.
298 -        *
299 -        * we only support ethernet device type,
300 -        * which (according to RFC 1390) should always equal 1 (Ethernet).
301 -        */
302 -
303 -       arp->ar_hrd = htons(kgdb_netdevice->type);
304 -       arp->ar_pro = htons(ETH_P_IP);
305 -
306 -       arp->ar_hln = kgdb_netdevice->addr_len;
307 -       arp->ar_pln = 4;
308 -       arp->ar_op = htons(type);
309 -
310 -       arp_ptr=(unsigned char *)(arp + 1);
311 -
312 -       memcpy(arp_ptr, kgdb_netdevice->dev_addr, kgdb_netdevice->addr_len);
313 -       arp_ptr += kgdb_netdevice->addr_len;
314 -       memcpy(arp_ptr, &tip, 4);
315 -       arp_ptr += 4;
316 -       memcpy(arp_ptr, kgdb_localmac, kgdb_netdevice->addr_len);
317 -       arp_ptr += kgdb_netdevice->addr_len;
318 -       memcpy(arp_ptr, &sip, 4);
319 -       return 0;
320 -}
321 -
322 -
323 -/*
324   * Accept an skbuff from net_device layer and add the payload onto
325   * kgdb buffer
326 - *
327 - * When the kgdb stub routine getDebugChar() is called it draws characters
328 - * out of the buffer until it is empty and then reads directly from the
329 - * serial port.
330 - *
331 - * We do not attempt to write chars from the interrupt routine since
332 - * the stubs do all of that via putDebugChar() which writes one byte
333 - * after waiting for the interface to become ready.
334 - *
335 - * The debug stubs like to run with interrupts disabled since, after all,
336 - * they run as a consequence of a breakpoint in the kernel.
337 - *
338 - * NOTE: Return value of 1 means it was for us and is an indication to
339 - * the calling driver to destroy the sk_buff and not send it up the stack.
340   */
341 -int
342 -kgdb_net_interrupt(struct sk_buff *skb)
343 +static void rx_hook(struct netpoll *np, int port, char *msg, int len)
344  {
345 -       unsigned char   chr;
346 -       struct iphdr    *iph = (struct iphdr*)skb->data;
347 -       struct udphdr   *udph= (struct udphdr*)(skb->data+(iph->ihl<<2));
348 -       unsigned char   *data = (unsigned char *) udph + sizeof(struct udphdr);
349 -       int             len;
350 -       int             i;
351 -
352 -       if ((kgdb_eth != -1) && (!kgdb_netdevice) &&
353 -           (iph->protocol == IPPROTO_UDP) &&
354 -           (be16_to_cpu(udph->dest) == kgdb_listenport)) {
355 -               kgdb_sendport = be16_to_cpu(udph->source);
356 -
357 -               while (kgdb_eth_is_initializing)
358 -                       ;
359 -               if (!kgdb_netdevice)
360 -                       kgdb_eth_hook();
361 -               if (!kgdb_netdevice) {
362 -                       /* Lets not even try again. */
363 -                       kgdb_eth = -1;
364 -                       return 0;
365 -               }
366 -       }
367 -       if (!kgdb_netdevice) {
368 -               return 0;
369 -       }
370 -       if (skb->protocol == __constant_htons(ETH_P_ARP) && !send_skb) {
371 -               make_arp_request(skb);
372 -               return 0;
373 -       }
374 -       if (iph->protocol != IPPROTO_UDP) {
375 -               return 0;
376 -       }
377 +       int i, chr;
378  
379 -       if (be16_to_cpu(udph->dest) != kgdb_listenport) {
380 -               return 0;
381 -       }
382 +       np->remote_port = port;
383  
384 -       len = (be16_to_cpu(iph->tot_len) -
385 -              (sizeof(struct udphdr) + sizeof(struct iphdr)));
386 +       /* Is this gdb trying to attach? */
387 +       if (!netpoll_trap() && len == 8 && !strncmp(msg, "$Hc-1#09", 8))
388 +               kgdb_schedule_breakpoint();
389  
390         for (i = 0; i < len; i++) {
391 -               chr = data[i];
392 -               if (chr == 3) {
393 -                       kgdb_eth_need_breakpoint[smp_processor_id()] = 1;
394 -                       continue;
395 -               }
396 +               chr = msg[i];
397 +               if (chr == 3)
398 +                       kgdb_schedule_breakpoint();
399 +
400                 if (atomic_read(&kgdb_buf_in_cnt) >= GDB_BUF_SIZE) {
401                         /* buffer overflow, clear it */
402                         kgdb_buf_in_inx = 0;
403 @@ -371,112 +108,54 @@
404                 kgdb_buf_in_inx &= (GDB_BUF_SIZE - 1);
405                 atomic_inc(&kgdb_buf_in_cnt);
406         }
407 -
408 -       if (!kgdb_netdevice->kgdb_is_trapped) {
409 -               /*
410 -                * If a new gdb instance is trying to attach, we need to
411 -                * break here.
412 -                */
413 -               if (!strncmp(data, "$Hc-1#09", 8))
414 -                       kgdb_eth_need_breakpoint[smp_processor_id()] = 1;
415 -       }
416 -       return 1;
417  }
418 -EXPORT_SYMBOL(kgdb_net_interrupt);
419  
420 -int
421 -kgdb_eth_hook(void)
422 +static int option_setup(char *opt)
423  {
424 -       char kgdb_netdev[16];
425 -       extern void kgdb_respond_ok(void);
426 -
427 -       if (kgdb_remotemac[0] == 0xff) {
428 -               panic("ERROR! 'gdbeth_remotemac' option not set!\n");
429 -       }
430 -       if (kgdb_localmac[0] == 0xff) {
431 -               panic("ERROR! 'gdbeth_localmac' option not set!\n");
432 -       }
433 -       if (kgdb_remoteip == 0) {
434 -               panic("ERROR! 'gdbeth_remoteip' option not set!\n");
435 -       }
436 +       return netpoll_parse_options(&np, opt);
437 +}
438  
439 -       sprintf(kgdb_netdev,"eth%d",kgdb_eth);
440 +__setup("kgdboe=", option_setup);
441  
442 +static int init_kgdboe(void)
443 +{
444  #ifdef CONFIG_SMP
445         if (num_online_cpus() > CONFIG_NO_KGDB_CPUS) {
446                 printk("kgdb: too manu cpus. Cannot enable debugger with more than %d cpus\n", CONFIG_NO_KGDB_CPUS);
447                 return -1;
448         }
449  #endif
450 -       for (kgdb_netdevice = dev_base;
451 -               kgdb_netdevice != NULL;
452 -               kgdb_netdevice = kgdb_netdevice->next) {
453 -               if (strncmp(kgdb_netdevice->name, kgdb_netdev, IFNAMSIZ) == 0) {
454 -                       break;
455 -               }
456 -       }
457 -       if (!kgdb_netdevice) {
458 -               printk("KGDB NET : Unable to find interface %s\n",kgdb_netdev);
459 -               return -ENODEV;
460 -       }
461  
462 -       /*
463 -        * Call GDB routine to setup the exception vectors for the debugger
464 -        */
465         set_debug_traps();
466  
467 -       /*
468 -        * Call the breakpoint() routine in GDB to start the debugging
469 -        * session.
470 -        */
471 -       kgdb_eth_is_initializing = 1;
472 -       kgdb_eth_need_breakpoint[smp_processor_id()] = 1;
473 +       if(!np.remote_ip || netpoll_setup(&np))
474 +               return 1;
475 +
476 +       kgdboe = 1;
477 +
478 +       printk(KERN_INFO "kgdb: debugging over ethernet enabled\n");
479 +
480         return 0;
481  }
482  
483 -/*
484 - * getDebugChar
485 - *
486 - * This is a GDB stub routine.  It waits for a character from the
487 - * serial interface and then returns it.  If there is no serial
488 - * interface connection then it returns a bogus value which will
489 - * almost certainly cause the system to hang.
490 - */
491 -int
492 -eth_getDebugChar(void)
493 +int eth_getDebugChar(void)
494  {
495 -       volatile int    chr;
496 +       int chr;
497  
498 -       while ((chr = read_char()) < 0) {
499 -               if (send_skb) {
500 -                       kgdb_eth_reply_arp();
501 -               }
502 -               if (kgdb_netdevice->poll_controller) {
503 -                       kgdb_netdevice->poll_controller(kgdb_netdevice);
504 -               } else {
505 -                       printk("KGDB NET: Error - Device %s is not supported!\n", kgdb_netdevice->name);
506 -                       panic("Please add support for kgdb net to this driver");
507 -               }
508 -       }
509 +       while ((chr = read_char()) < 0)
510 +               netpoll_poll(&np);
511         return chr;
512  }
513  
514 -#define ETH_QUEUE_SIZE 256
515 -static char eth_queue[ETH_QUEUE_SIZE];
516 -static int outgoing_queue;
517 -
518 -void
519 -eth_flushDebugChar(void)
520 +void eth_flushDebugChar(void)
521  {
522         if(outgoing_queue) {
523                 write_buffer(eth_queue, outgoing_queue);
524 -
525                 outgoing_queue = 0;
526         }
527  }
528  
529 -static void
530 -put_char_on_queue(int chr)
531 +static void put_char_on_queue(int chr)
532  {
533         eth_queue[outgoing_queue++] = chr;
534         if(outgoing_queue == ETH_QUEUE_SIZE)
535 @@ -485,33 +164,26 @@
536         }
537  }
538  
539 -/*
540 - * eth_putDebugChar
541 - *
542 - * This is a GDB stub routine.  It waits until the interface is ready
543 - * to transmit a char and then sends it.
544 - */
545 -void
546 -eth_putDebugChar(int chr)
547 +void eth_putDebugChar(int chr)
548  {
549         put_char_on_queue(chr); /* this routine will wait */
550  }
551  
552 -void
553 -kgdb_eth_set_trapmode(int mode)
554 +void kgdb_schedule_breakpoint(void)
555  {
556 -       if (!kgdb_netdevice) {
557 -               return;
558 -       }
559 -       kgdb_netdevice->kgdb_is_trapped = mode;
560 +       kgdb_eth_need_breakpoint[smp_processor_id()] = 1;
561  }
562  
563 -int
564 -kgdb_eth_is_trapped()
565 +void kgdb_process_breakpoint(void)
566  {
567 -       if (!kgdb_netdevice) {
568 -               return 0;
569 +       /*
570 +        * Handle a breakpoint queued from inside network driver code
571 +         * to avoid reentrancy issues
572 +        */
573 +       if (kgdb_eth_need_breakpoint[smp_processor_id()]) {
574 +               kgdb_eth_need_breakpoint[smp_processor_id()] = 0;
575 +               BREAKPOINT;
576         }
577 -       return kgdb_netdevice->kgdb_is_trapped;
578  }
579 -EXPORT_SYMBOL(kgdb_eth_is_trapped);
580 +
581 +module_init(init_kgdboe);
582 Index: linux-2.6.0-test6/arch/i386/kernel/kgdb_stub.c
583 ===================================================================
584 --- linux-2.6.0-test6.orig/arch/i386/kernel/kgdb_stub.c 2003-10-12 13:12:22.000000000 +0800
585 +++ linux-2.6.0-test6/arch/i386/kernel/kgdb_stub.c      2003-10-12 18:57:21.625083056 +0800
586 @@ -120,6 +120,7 @@
587  #include <asm/desc.h>
588  #include <linux/inet.h>
589  #include <linux/kallsyms.h>
590 +#include <linux/netpoll.h>
591  
592  /************************************************************************
593   *
594 @@ -136,10 +137,6 @@
595  extern int eth_putDebugChar(int);     /* write a single character      */
596  extern int eth_getDebugChar(void);    /* read and return a single char */
597  extern void eth_flushDebugChar(void); /* flush pending characters      */
598 -extern void kgdb_eth_set_trapmode(int);
599 -extern void kgdb_eth_reply_arp(void);   /*send arp request */
600 -extern volatile int kgdb_eth_is_initializing;
601 -
602  
603  /************************************************************************/
604  /* BUFMAX defines the maximum number of characters in inbound/outbound buffers*/
605 @@ -281,13 +278,13 @@
606  
607  /*
608   * I/O dispatch functions...
609 - * Based upon kgdb_eth, either call the ethernet
610 + * Based upon kgdboe, either call the ethernet
611   * handler or the serial one..
612   */
613  void
614  putDebugChar(int c)
615  {
616 -       if (kgdb_eth == -1) {
617 +       if (!kgdboe) {
618                 tty_putDebugChar(c);
619         } else {
620                 eth_putDebugChar(c);
621 @@ -297,7 +294,7 @@
622  int
623  getDebugChar(void)
624  {
625 -       if (kgdb_eth == -1) {
626 +       if (!kgdboe) {
627                 return tty_getDebugChar();
628         } else {
629                 return eth_getDebugChar();
630 @@ -307,7 +304,7 @@
631  void
632  flushDebugChar(void)
633  {
634 -       if (kgdb_eth == -1) {
635 +       if (!kgdboe) {
636                 tty_flushDebugChar();
637         } else {
638                 eth_flushDebugChar();
639 @@ -494,66 +491,24 @@
640  
641         /*  $<packet info>#<checksum>. */
642  
643 -       if (kgdb_eth == -1) {
644 -               do {
645 -                       if (remote_debug)
646 -                               printk("T:%s\n", buffer);
647 -                       putDebugChar('$');
648 -                       checksum = 0;
649 -                       count = 0;
650 -
651 -                       while ((ch = buffer[count])) {
652 -                               putDebugChar(ch);
653 -                               checksum += ch;
654 -                               count += 1;
655 -                       }
656 -
657 -                       putDebugChar('#');
658 -                       putDebugChar(hexchars[checksum >> 4]);
659 -                       putDebugChar(hexchars[checksum % 16]);
660 -                       flushDebugChar();
661 -
662 -               } while ((getDebugChar() & 0x7f) != '+');
663 -       } else {
664 -               /*
665 -                * For udp, we can not transfer too much bytes once.
666 -                * We only transfer MAX_SEND_COUNT size bytes each time
667 -                */
668 -
669 -#define MAX_SEND_COUNT 30
670 -
671 -               int send_count = 0, i = 0;
672 -               char send_buf[MAX_SEND_COUNT];
673 +       do {
674 +               if (remote_debug)
675 +                       printk("T:%s\n", buffer);
676 +               putDebugChar('$');
677 +               checksum = 0;
678 +               count = 0;
679 +               while ((ch = buffer[count])) {
680 +                       putDebugChar(ch);
681 +                       checksum += ch;
682 +                       count += 1;
683 +               }
684 +               
685 +               putDebugChar('#');
686 +               putDebugChar(hexchars[checksum >> 4]);
687 +               putDebugChar(hexchars[checksum % 16]);
688 +               flushDebugChar();
689  
690 -               do {
691 -                       if (remote_debug)
692 -                               printk("T:%s\n", buffer);
693 -                       putDebugChar('$');
694 -                       checksum = 0;
695 -                       count = 0;
696 -                       send_count = 0;
697 -                       while ((ch = buffer[count])) {
698 -                               if (send_count >= MAX_SEND_COUNT) {
699 -                                       for(i = 0; i < MAX_SEND_COUNT; i++) {
700 -                                               putDebugChar(send_buf[i]);
701 -                                       }
702 -                                       flushDebugChar();
703 -                                       send_count = 0;
704 -                               } else {
705 -                                       send_buf[send_count] = ch;
706 -                                       checksum += ch;
707 -                                       count ++;
708 -                                       send_count++;
709 -                               }
710 -                       }
711 -                       for(i = 0; i < send_count; i++)
712 -                               putDebugChar(send_buf[i]);
713 -                       putDebugChar('#');
714 -                       putDebugChar(hexchars[checksum >> 4]);
715 -                       putDebugChar(hexchars[checksum % 16]);
716 -                       flushDebugChar();
717 -               } while ((getDebugChar() & 0x7f) != '+');
718 -       }
719 +       } while ((getDebugChar() & 0x7f) != '+');
720  }
721  
722  static char remcomInBuffer[BUFMAX];
723 @@ -1142,9 +1097,9 @@
724          */
725         in_kgdb_entry_log[cpu]++;
726         in_kgdb_here_log[cpu] = regs;
727 -       if (cpu == spinlock_cpu || waiting_cpus[cpu].task) {
728 +       if (cpu == spinlock_cpu || waiting_cpus[cpu].task)
729                 goto exit_in_kgdb;
730 -       }
731 +
732         /*
733          * For protection of the initilization of the spin locks by kgdb
734          * it locks the kgdb spinlock before it gets the wait locks set
735 @@ -1153,16 +1108,18 @@
736          * sequence where the wait lock is removed prior to the kgdb lock
737          * so if kgdb gets unlocked, we just exit.
738          */
739 +
740         while (spin_is_locked(&kgdb_spinlock) &&
741                !spin_is_locked(waitlocks + cpu)) ;
742 -       if (!spin_is_locked(&kgdb_spinlock)) {
743 +       if (!spin_is_locked(&kgdb_spinlock))
744                 goto exit_in_kgdb;
745 -       }
746 +
747         waiting_cpus[cpu].task = current;
748         waiting_cpus[cpu].pid = (current->pid) ? : (PID_MAX + cpu);
749         waiting_cpus[cpu].regs = regs;
750  
751         spin_unlock_wait(waitlocks + cpu);
752 +
753         /*
754          * log departure of this cpu
755          */
756 @@ -1281,9 +1238,8 @@
757  
758         __asm__("movl %%cr2,%0":"=r" (address));
759  
760 -       if (kgdb_eth != -1) {
761 -               kgdb_eth_set_trapmode(1);
762 -       }
763 +       if (kgdboe)
764 +               netpoll_set_trap(1);
765  
766         kgdb_local_irq_save(flags);
767  
768 @@ -1338,10 +1294,12 @@
769                 if (num_online_cpus() > 1) {
770                         int me_in_kgdb = in_kgdb_entry_log[smp_processor_id()];
771                         smp_send_nmi_allbutself();
772 +
773                         while (i < num_online_cpus() && time != end_time) {
774                                 int j;
775                                 for (j = 0; j < MAX_NO_CPUS; j++) {
776                                         if (waiting_cpus[j].task &&
777 +                                           waiting_cpus[j].task != NOCPU &&
778                                             !cpu_logged_in[j]) {
779                                                 i++;
780                                                 cpu_logged_in[j] = 1;
781 @@ -1526,13 +1484,8 @@
782         remcomOutBuffer[2] = hexchars[signo % 16];
783         remcomOutBuffer[3] = 0;
784  
785 -       if (kgdb_eth_is_initializing) {
786 -               kgdb_eth_is_initializing = 0;
787 -       } else {
788 -               putpacket(remcomOutBuffer);
789 -       }
790 +       putpacket(remcomOutBuffer);
791  
792 -       kgdb_eth_reply_arp();
793         while (1 == 1) {
794                 error = 0;
795                 remcomOutBuffer[0] = 0;
796 @@ -1689,10 +1642,6 @@
797  
798                         newPC = regs.eip;
799  
800 -                       if (kgdb_eth != -1) {
801 -                               kgdb_eth_set_trapmode(0);
802 -                       }
803 -
804                         /* clear the trace bit */
805                         regs.eflags &= 0xfffffeff;
806  
807 @@ -1724,6 +1673,10 @@
808                                         }
809                                 }
810                         }
811 +
812 +                       if (kgdboe)
813 +                               netpoll_set_trap(0);
814 +
815                         correct_hw_break();
816                         asm volatile ("movl %0, %%db6\n"::"r" (0));
817                         goto exit_kgdb;
818 @@ -2430,63 +2383,3 @@
819                            int signo, int err_code, struct pt_regs *linux_regs);
820  gdb_debug_hook *linux_debug_hook = &kgdb_handle_exception;     /* histerical reasons... */
821  
822 -static int __init kgdb_opt_kgdbeth(char *str)
823 -{
824 -       kgdb_eth = simple_strtoul(str, NULL, 10);
825 -       return 1;
826 -}
827 -
828 -static int __init kgdb_opt_kgdbeth_remoteip(char *str)
829 -{
830 -       kgdb_remoteip = in_aton(str);
831 -       return 1;
832 -}
833 -
834 -static int __init kgdb_opt_kgdbeth_listenport(char *str)
835 -{
836 -       kgdb_listenport = simple_strtoul(str, NULL, 10);
837 -       kgdb_sendport = kgdb_listenport - 1;
838 -       return 1;
839 -}
840 -
841 -static int __init parse_hw_addr(char *str, unsigned char *addr)
842 -{
843 -       int  i;
844 -       char *p;
845 -
846 -       p = str;
847 -       i = 0;
848 -       while(1)
849 -       {
850 -               unsigned int c;
851 -
852 -               sscanf(p, "%x:", &c);
853 -               addr[i++] = c;
854 -               while((*p != 0) && (*p != ':')) {
855 -                       p++;
856 -               }
857 -               if (*p == 0) {
858 -                       break;
859 -               }
860 -               p++;
861 -       }
862 -
863 -       return 1;
864 -}
865 -
866 -static int __init kgdb_opt_kgdbeth_remotemac(char *str)
867 -{
868 -       return parse_hw_addr(str, kgdb_remotemac);
869 -}
870 -static int __init kgdb_opt_kgdbeth_localmac(char *str)
871 -{
872 -       return parse_hw_addr(str, kgdb_localmac);
873 -}
874 -
875 -
876 -__setup("gdbeth=", kgdb_opt_kgdbeth);
877 -__setup("gdbeth_remoteip=", kgdb_opt_kgdbeth_remoteip);
878 -__setup("gdbeth_listenport=", kgdb_opt_kgdbeth_listenport);
879 -__setup("gdbeth_remotemac=", kgdb_opt_kgdbeth_remotemac);
880 -__setup("gdbeth_localmac=", kgdb_opt_kgdbeth_localmac);
881 -
882 Index: linux-2.6.0-test6/arch/i386/lib/kgdb_serial.c
883 ===================================================================
884 --- linux-2.6.0-test6.orig/arch/i386/lib/kgdb_serial.c  2003-10-12 13:12:22.000000000 +0800
885 +++ linux-2.6.0-test6/arch/i386/lib/kgdb_serial.c       2003-10-12 13:12:25.000000000 +0800
886 @@ -386,7 +386,7 @@
887  static int __init
888  kgdb_enable_ints(void)
889  {
890 -       if (kgdb_eth != -1) {
891 +       if (kgdboe) {
892                 return 0;
893         }
894         if (gdb_async_info == NULL) {
895 Index: linux-2.6.0-test6/drivers/net/Makefile
896 ===================================================================
897 --- linux-2.6.0-test6.orig/drivers/net/Makefile 2003-10-12 13:12:22.000000000 +0800
898 +++ linux-2.6.0-test6/drivers/net/Makefile      2003-10-12 13:12:25.000000000 +0800
899 @@ -32,8 +32,6 @@
900  
901  obj-$(CONFIG_OAKNET) += oaknet.o 8390.o
902  
903 -obj-$(CONFIG_KGDB) += kgdb_eth.o
904 -
905  obj-$(CONFIG_DGRS) += dgrs.o
906  obj-$(CONFIG_RCPCI) += rcpci.o
907  obj-$(CONFIG_VORTEX) += 3c59x.o
908 @@ -109,6 +107,8 @@
909  ifeq ($(CONFIG_SLIP_COMPRESSED),y)
910    obj-$(CONFIG_SLIP) += slhc.o
911  endif
912 +# Must come after all NICs it might use
913 +obj-$(CONFIG_KGDB) += kgdb_eth.o
914  
915  obj-$(CONFIG_DUMMY) += dummy.o
916  obj-$(CONFIG_DE600) += de600.o
917 Index: linux-2.6.0-test6/include/asm-i386/kgdb.h
918 ===================================================================
919 --- linux-2.6.0-test6.orig/include/asm-i386/kgdb.h      2003-10-12 13:12:23.000000000 +0800
920 +++ linux-2.6.0-test6/include/asm-i386/kgdb.h   2003-10-12 13:12:25.000000000 +0800
921 @@ -21,17 +21,13 @@
922  
923  struct sk_buff;
924  
925 -extern int kgdb_eth;
926 -extern unsigned kgdb_remoteip;
927 -extern unsigned short kgdb_listenport;
928 -extern unsigned short kgdb_sendport;
929 -extern unsigned char kgdb_remotemac[6];
930 -extern unsigned char kgdb_localmac[6];
931  extern int kgdb_eth_need_breakpoint[];
932 +extern int kgdboe;
933 +extern void kgdb_schedule_breakpoint(void);
934 +extern void kgdb_process_breakpoint(void);
935  
936  extern int kgdb_tty_hook(void);
937  extern int kgdb_eth_hook(void);
938 -extern int gdb_net_interrupt(struct sk_buff *skb);
939  
940  /*
941   * GDB debug stub (or any debug stub) can point the 'linux_debug_hook'
942 Index: linux-2.6.0-test6/Documentation/i386/kgdb/kgdbeth.txt
943 ===================================================================
944 --- linux-2.6.0-test6.orig/Documentation/i386/kgdb/kgdbeth.txt  2003-10-12 13:12:22.000000000 +0800
945 +++ linux-2.6.0-test6/Documentation/i386/kgdb/kgdbeth.txt       2003-10-12 13:12:25.000000000 +0800
946 @@ -6,16 +6,20 @@
947  
948  Robert Walsh <rjwalsh@durables.org>  (2.6 port)
949  wangdi <wangdi@clusterfs.com>        (2.6 port)
950 +Matt Mackall <mpm@selenic.com>       (netpoll api)
951  San Mehat                            (original 2.4 code)
952  
953  
954  Introduction
955  ------------
956  
957 -KGDB supports debugging over ethernet.  Only a limited set of ethernet
958 -devices are supported right now, but adding support for new devices
959 -should not be too complicated.  See "New Devices" below for details.
960 -
961 +KGDB supports debugging over ethernet (kgdboe) via polling of a given
962 +network interface. Most cards should be supported automatically.
963 +Debugging facilities are available as soon as the network driver and
964 +kgdboe have initialized. Unfortunately, this is too late in the boot
965 +process for debugging some issues, but works quite well for many
966 +others. This should not interfere with normal network usage and
967 +doesn't require a dedicated NIC.
968  
969  Terminology
970  -----------
971 @@ -29,33 +33,25 @@
972  Usage
973  -----
974  
975 -You need to use the following command-line options on the TARGET kernel:
976 -
977 -  gdbeth=DEVICENUM
978 -  gdbeth_remoteip=HOSTIPADDR
979 -  gdbeth_remotemac=REMOTEMAC
980 -  gdbeth_localmac=LOCALMAC
981 -
982 -kgdbeth=DEVICENUM sets the ethernet device number to listen on for
983 -debugging packets.  e.g. kgdbeth=0 listens on eth0.
984 -
985 -kgdbeth_remoteip=HOSTIPADDR sets the IP address of the HOST machine.
986 -Only packets originating from this IP address will be accepted by the
987 -debugger.  e.g. kgdbeth_remoteip=192.168.2.2
988 +You need to use the following command-line option on the TARGET kernel:
989  
990 -kgdbeth_remotemac=REMOTEMAC sets the ethernet address of the HOST machine.
991 -e.g. kgdbeth_remotemac=00:07:70:12:4E:F5
992 +  kgdboe=[tgt-port]@<tgt-ip>/[dev],[host-port]@<host-ip>/[host-macaddr]
993  
994 -kgdbeth_localmac=LOCALMAC sets the ethernet address of the TARGET machine.
995 -e.g. kgdbeth_localmac=00:10:9F:18:21:3C
996 +    where
997 +        tgt-port      source for UDP packets (defaults to 6443)
998 +        tgt-ip        source IP to use (interface address)
999 +        dev           network interface (eth0)
1000 +        host-port     HOST UDP port (6442) (not really used)
1001 +        host-ip       IP address for HOST machine
1002 +        host-macaddr  ethernet MAC address for HOST (ff:ff:ff:ff:ff:ff)
1003  
1004 -You can also set the following command-line option on the TARGET kernel:
1005 +  examples:
1006  
1007 -  kgdbeth_listenport=PORT
1008 +    kgdboe=7000@192.168.0.1/wlan0,7001@192.168.0.2/00:05:3C:04:47:5D
1009 +    kgdboe=@192.168.0.1/,@192.168.0.2/
1010  
1011 -kgdbeth_listenport sets the UDP port to listen on for gdb debugging
1012 -packets.  The default value is "6443".  e.g. kgdbeth_listenport=7654
1013 -causes the kernel to listen on UDP port 7654 for debugging packets.
1014 +Only packets originating from the configured HOST IP address will be
1015 +accepted by the debugger.
1016  
1017  On the HOST side, run gdb as normal and use a remote UDP host as the
1018  target:
1019 @@ -72,47 +68,16 @@
1020  
1021  You can now continue as if you were debugging over a serial line.
1022  
1023 -Observations
1024 -------------
1025 -
1026 -I've used this with NFS and various other network applications (ssh,
1027 -etc.) and it's doesn't appear to interfere with their operation in
1028 -any way.  It doesn't seem to effect the NIC it uses - i.e. you don't
1029 -need a dedicated NIC for this.
1030 -
1031  Limitations
1032  -----------
1033  
1034 -In the inital release of this code you _must_ break into the system with the
1035 -debugger by hand, early after boot, as described above.
1036 -
1037 -Otherwise, the first time the kernel tries to enter the debugger (say, via an
1038 -oops or a BUG), the kgdb stub will doublefault and die because things aren't
1039 -fully set up yet.
1040 -
1041 -Supported devices
1042 ------------------
1043 -
1044 -Right now, the following drivers are supported:
1045 -
1046 -  e100 driver (drivers/net/e100/*)
1047 -  3c59x driver (drivers/net/3c59x.c)
1048 -
1049 -
1050 -New devices
1051 ------------
1052 -
1053 -Supporting a new device is straightforward.  Just add a "poll" routine to
1054 -the driver and hook it into the poll_controller field in the netdevice
1055 -structure.  For an example, look in drivers/net/3c59x.c and search
1056 -for CONFIG_KGDB (two places.)
1057 -
1058 -The poll routine is usually quite simple - it's usually enough to just
1059 -disable interrupts, call the device's interrupt routine and re-enable
1060 -interrupts again.
1061 -
1062 +The current release of this code is exclusive of using kgdb on a
1063 +serial interface, so you must boot without the kgdboe option to use
1064 +serial debugging. Trying to debug the network driver while using it
1065 +will prove interesting.
1066  
1067  Bug reports
1068  -----------
1069  
1070 -Send bug reports to Robert Walsh <rjwalsh@durables.org>.
1071 +Send bug reports to Robert Walsh <rjwalsh@durables.org> Matt
1072 +Mackall <mpm@selenic.com> and wangdi <wangdi@clusterfs.com>.