linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] make psaux reconnect adjustable
@ 2001-08-02 16:02 Andries.Brouwer
  2001-08-02 16:18 ` Kurt Garloff
  0 siblings, 1 reply; 19+ messages in thread
From: Andries.Brouwer @ 2001-08-02 16:02 UTC (permalink / raw)
  To: Andries.Brouwer, alan
  Cc: brent, garloff, linux-kernel, mantel, rubini, torvalds

From: Alan Cox <alan@lxorguk.ukuu.org.uk>:

> 2.2 has had the sysctl for ages, and it defaults to off

Not precisely - it is a boot parameter "psaux-reconnect".
That is better than a sysctl.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
  2001-08-02 16:02 [PATCH] make psaux reconnect adjustable Andries.Brouwer
@ 2001-08-02 16:18 ` Kurt Garloff
  0 siblings, 0 replies; 19+ messages in thread
From: Kurt Garloff @ 2001-08-02 16:18 UTC (permalink / raw)
  To: Andries.Brouwer; +Cc: alan, brent, linux-kernel, mantel, rubini, torvalds

[-- Attachment #1: Type: text/plain, Size: 929 bytes --]

On Thu, Aug 02, 2001 at 04:02:38PM +0000, Andries Brouwer wrote:
> From: Alan Cox <alan@lxorguk.ukuu.org.uk>:
> 
> > 2.2 has had the sysctl for ages, and it defaults to off

I would definitely not object to defaulting to off.

> Not precisely - it is a boot parameter "psaux-reconnect".
> That is better than a sysctl.

Why should that be better than a sysctl? Boot parameters are ugly. You 
need to reboot in order to change them ...

Your other mail implies that we can fix the problem without manual
intervention by parsing AA 00 instead of just AA. If it's true, I'd 
consider that the best solution. 
Otherwise, I'd like my patch to be applied maybe with a changed default.

Regards,
-- 
Kurt Garloff  <garloff@suse.de>                          Eindhoven, NL
GPG key: See mail header, key servers         Linux kernel development
SuSE GmbH, Nuernberg, DE                                SCSI, Security

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
  2001-08-14 21:29       ` Kurt Garloff
@ 2001-08-15 15:50         ` Gunther Mayer
  0 siblings, 0 replies; 19+ messages in thread
From: Gunther Mayer @ 2001-08-15 15:50 UTC (permalink / raw)
  To: Kurt Garloff; +Cc: linux-kernel

Kurt Garloff wrote:
> 
> On Tue, Aug 14, 2001 at 09:58:55AM -0700, Linus Torvalds wrote:
> >  - do we actually need the config switch AT ALL, whether at bootup or not?
> >    What exactly breaks if we just always pass the AA 00 values through?
> >    Apparently nothing ever breaks, which makes me suspect that people are
> >    just being unnecessarily defensive.
> >
> > In short, I'd prefer a patch that just unconditionally removes the code,
> > unless somebody KNOWS that it could break something. That failing, a
> > simple kernel command line option sounds better than more files in /proc.

Linus, no more boot options (and no more files in /proc), please.

Don't push policy on users when there is a perfect, simple and _user-friendly_ solution.

> 
> OK, here come two patches. The first one removes the special PSAUX reconnect
> handling completely. So userspace should handle it. (Which is possible; just
> not implemented in gpm/X11 at this time AFAIK.)
> 
> Second patch reintroduces the special handling again, but does
> * react on AA 00 instead of just AA, thus much less likely breaking other
>   drivers (such as synps2). All PS/2 mouses I could access (about 5
>   different models) produced AA 00, so this seems OK.
> * is disabled by default, and needs to be enabled by the psaux-reconnect
>   boot parameter, like in 2.2.19.

Your patch for "AA 00" is preferable over current state "AA" (<=2.4.8)

ioctl is preferable over sysctl. Aware drivers do "ioctl("/dev/psaux", PS2_TRANSPARENT)".

run-time configuration is preferable over a boot parameter (see above about user-friendliness).

Not breaking current behaviour ("reconnecting 3-byte protocol mice works perfectly") is preferable.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
  2001-08-14 17:10 ` Gunther Mayer
@ 2001-08-14 21:56   ` Kurt Garloff
  0 siblings, 0 replies; 19+ messages in thread
From: Kurt Garloff @ 2001-08-14 21:56 UTC (permalink / raw)
  To: Gunther Mayer; +Cc: linux-kernel, Andries Brouwer

[-- Attachment #1: Type: text/plain, Size: 993 bytes --]

On Tue, Aug 14, 2001 at 07:10:26PM +0200, Gunther Mayer wrote:
> Andries.Brouwer@cwi.nl wrote:
> Add an "ioctl(PS2_TRANSPARENT)", to disable the current kernel policy.
> So new drivers which understand about "aa 00" sequences can act properly.
> Don't break existing apps.

Well, coneptually, an ioctl is the same as a sysctl. You allow the user /
sysadmin to toggle the behaviour. Given Linus' love for ioctls, I opted for
the sysctl.

But in principle, Andries is right: There's no reason why userspace can't
handle it, so removing the thing (maybe with a boot param for some time to
allow a smooth transition until all drivers are fixed) is the right thiing
to do.

Regards,
-- 
Kurt Garloff                   <kurt@garloff.de>         [Eindhoven, NL]
Physics: Plasma simulations  <K.Garloff@Phys.TUE.NL>  [TU Eindhoven, NL]
Linux: SCSI, Security          <garloff@suse.de>    [SuSE Nuernberg, DE]
 (See mail header or public key servers for PGP2 and GPG public keys.)

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
  2001-08-14 16:58     ` Linus Torvalds
  2001-08-14 17:35       ` Kurt Garloff
@ 2001-08-14 21:29       ` Kurt Garloff
  2001-08-15 15:50         ` Gunther Mayer
  1 sibling, 1 reply; 19+ messages in thread
From: Kurt Garloff @ 2001-08-14 21:29 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Andries.Brouwer, alan, linux-kernel, mantel, rubini


[-- Attachment #1.1: Type: text/plain, Size: 1676 bytes --]

On Tue, Aug 14, 2001 at 09:58:55AM -0700, Linus Torvalds wrote:
>  - do we actually need the config switch AT ALL, whether at bootup or not?
>    What exactly breaks if we just always pass the AA 00 values through?
>    Apparently nothing ever breaks, which makes me suspect that people are
>    just being unnecessarily defensive.
> 
> In short, I'd prefer a patch that just unconditionally removes the code,
> unless somebody KNOWS that it could break something. That failing, a
> simple kernel command line option sounds better than more files in /proc.

OK, here come two patches. The first one removes the special PSAUX reconnect
handling completely. So userspace should handle it. (Which is possible; just
not implemented in gpm/X11 at this time AFAIK.)

Second patch reintroduces the special handling again, but does
* react on AA 00 instead of just AA, thus much less likely breaking other
  drivers (such as synps2). All PS/2 mouses I could access (about 5
  different models) produced AA 00, so this seems OK.
* is disabled by default, and needs to be enabled by the psaux-reconnect
  boot parameter, like in 2.2.19.

Second patch depends on first. Please apply just the first or both.

(Current failure of gpm/X11 would make me choose for both, but then I'm 
 more the one thinking of customers of a distro than the one trying to keep
 the kernel clean. On the long term, I'd drop the second in any case.)

Regards,
-- 
Kurt Garloff  <garloff@suse.de>                          Eindhoven, NL
GPG key: See mail header, key servers         Linux kernel development
SuSE GmbH, Nuernberg, DE                                SCSI, Security

[-- Attachment #1.2: 247-noreconnect.diff --]
[-- Type: text/plain, Size: 853 bytes --]

diff -uNr linux-2.4.7.kurt-1/drivers/char/pc_keyb.c linux-2.4.7.kurt-1-noreconnect/drivers/char/pc_keyb.c
--- linux-2.4.7.kurt-1/drivers/char/pc_keyb.c	Tue Jul 24 18:42:36 2001
+++ linux-2.4.7.kurt-1-noreconnect/drivers/char/pc_keyb.c	Tue Aug 14 22:47:38 2001
@@ -81,8 +81,6 @@
 
 static int __init psaux_init(void);
 
-#define AUX_RECONNECT 170 /* scancode when ps2 device is plugged (back) in */
- 
 static struct aux_queue *queue;	/* Mouse data buffer. */
 static int aux_count;
 /* used when we send commands to the mouse that expect an ACK. */
@@ -406,11 +404,6 @@
 			return;
 		}
 		mouse_reply_expected = 0;
-	}
-	else if(scancode == AUX_RECONNECT){
-		queue->head = queue->tail = 0;  /* Flush input queue */
-		__aux_write_ack(AUX_ENABLE_DEV);  /* ping the mouse :) */
-		return;
 	}
 
 	add_mouse_randomness(scancode);

[-- Attachment #1.3: 247-reconnect_bootpar.diff --]
[-- Type: text/plain, Size: 1868 bytes --]

diff -uNr linux-2.4.7.kurt-1-noreconnect/drivers/char/pc_keyb.c linux-2.4.7.kurt-1-recon_bootpar/drivers/char/pc_keyb.c
--- linux-2.4.7.kurt-1-noreconnect/drivers/char/pc_keyb.c	Tue Aug 14 22:47:38 2001
+++ linux-2.4.7.kurt-1-recon_bootpar/drivers/char/pc_keyb.c	Tue Aug 14 23:13:49 2001
@@ -63,6 +63,7 @@
 #ifdef CONFIG_PSMOUSE
 static void aux_write_ack(int val);
 static void __aux_write_ack(int val);
+static int aux_reconnect = 0;
 #endif
 
 static spinlock_t kbd_controller_lock = SPIN_LOCK_UNLOCKED;
@@ -81,6 +82,9 @@
 
 static int __init psaux_init(void);
 
+#define AUX_RECONNECT1 0xaa	/* scancode1 when ps2 device is plugged (back) in */
+#define AUX_RECONNECT2 0x00	/* scancode2 when ps2 device is plugged (back) in */
+ 
 static struct aux_queue *queue;	/* Mouse data buffer. */
 static int aux_count;
 /* used when we send commands to the mouse that expect an ACK. */
@@ -398,6 +402,7 @@
 static inline void handle_mouse_event(unsigned char scancode)
 {
 #ifdef CONFIG_PSMOUSE
+	static unsigned char prev_code;
 	if (mouse_reply_expected) {
 		if (scancode == AUX_ACK) {
 			mouse_reply_expected--;
@@ -405,7 +410,15 @@
 		}
 		mouse_reply_expected = 0;
 	}
+	else if(scancode == AUX_RECONNECT2 && prev_code == AUX_RECONNECT1
+		&& aux_reconnect) {
+		printk (KERN_INFO "PS/2 mouse reconnect detected\n");
+		queue->head = queue->tail = 0;	/* Flush input queue */
+		__aux_write_ack(AUX_ENABLE_DEV);  /* ping the mouse :) */
+		return;
+	}
 
+	prev_code = scancode;
 	add_mouse_randomness(scancode);
 	if (aux_count) {
 		int head = queue->head;
@@ -751,6 +764,14 @@
 }
 
 #if defined CONFIG_PSMOUSE
+
+static int __init aux_reconnect_setup (char *str)
+{
+	aux_reconnect = 1;
+	return 1;
+}
+
+__setup("psaux-reconnect", aux_reconnect_setup);
 
 /*
  * Check if this is a dual port controller.

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
@ 2001-08-14 21:26 Andries.Brouwer
  0 siblings, 0 replies; 19+ messages in thread
From: Andries.Brouwer @ 2001-08-14 21:26 UTC (permalink / raw)
  To: Andries.Brouwer, Gunther.Mayer; +Cc: linux-kernel


> PS/2 mouse protocol was designed to easily re-synchronize

Not very easily. The Microsoft protocol synchronizes after
a single packet, but the PS/2 protocol has packets of three
bytes, two of which have completely arbitrary contents,
while the first byte has arbitrary contents except that
bit 3 is always set. No doubt it takes only a few packets
to resynchronize in practice, but in theory one could have
arbitrarily long strings of ..., 8, 8, 8, 8, 8, 12, 8, 8, 8, ...
and nobody knows whether the 12 was a mouse button.

> _This_ shows, user-mode must be notified of the re-connect!

Yes, we agree completely: this AUX_RECONNECT stuff should
be ripped out of the kernel, no sysctl, no ioctl, no boot param,
just out. Now gpm can handle the sequence AA 00 as it sees fit,
possibly by reinitializing the mouse, and if X gets its mouse
events via gpm it doesnt need the same code itself.

Andries

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
  2001-08-14 18:29 Andries.Brouwer
@ 2001-08-14 19:35 ` Gunther Mayer
  0 siblings, 0 replies; 19+ messages in thread
From: Gunther Mayer @ 2001-08-14 19:35 UTC (permalink / raw)
  To: Andries.Brouwer; +Cc: linux-kernel

Andries.Brouwer@cwi.nl wrote:
> 
>     From Gunther.Mayer@t-online.de Tue Aug 14 19:10:40 2001
> 
>     >     I can confirm what you suggest:
>     >         My mouse (Logitech wheel USB/PS2) sends indeed AA 00.
>     >     So, I extended my patch:
>     >     psmouse_reconnect = 0: Do nothing (just pass all to userspace)
>     >     psmouse_reconnect = 1: Flush Q & ping mouse on AA 00 (default)
>     >     psmouse_reconnect = 2: Flush Q & ping mouse on AA (old behaviour)
>     >
>     >     With reconnect 1 or 2: After reconnecting, mouse behaves strange
>     >         (jumping around the screen)
> 
>     This is a serious bug in many user-space drivers. PS/2 mouse protocol
>     was designed to easily re-synchronize (think about transmission errors/
>     lost bytes).
> 
> The fragment of text you reply to is not about the 3-byte PS/2
> protocol, but about the 4-byte wheelmouse protocol.

No, it applies even to 4-byte protocol (see 1).

1) Re-synchronize on transmission errors (e.g. lost bytes)
The 4-byte protocol shares bytes 1-3 with the 3-byte protocol.
So it can synchronize just as easy.

2) Re-connecting the mouse
The 4-byte wheelmouse protocol must be re-enabled by sending proper
magic bytes by user-level driver (else it stays in 3-byte mode).

_This_ shows, user-mode must be notified of the re-connect! So letting
the driver choose PS2_TRANSPARENT, it can easily handle this situation.

3) Re-connecting a different animal
The user-level driver should autodetect common mouse protocols
(legacy proprietary protocols will vanish and should not hinder progress).

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
@ 2001-08-14 18:29 Andries.Brouwer
  2001-08-14 19:35 ` Gunther Mayer
  0 siblings, 1 reply; 19+ messages in thread
From: Andries.Brouwer @ 2001-08-14 18:29 UTC (permalink / raw)
  To: Gunther.Mayer, linux-kernel; +Cc: Andries.Brouwer

    From Gunther.Mayer@t-online.de Tue Aug 14 19:10:40 2001

    >     I can confirm what you suggest:
    >         My mouse (Logitech wheel USB/PS2) sends indeed AA 00.
    >     So, I extended my patch:
    >     psmouse_reconnect = 0: Do nothing (just pass all to userspace)
    >     psmouse_reconnect = 1: Flush Q & ping mouse on AA 00 (default)
    >     psmouse_reconnect = 2: Flush Q & ping mouse on AA (old behaviour)
    > 
    >     With reconnect 1 or 2: After reconnecting, mouse behaves strange
    >         (jumping around the screen)

    This is a serious bug in many user-space drivers. PS/2 mouse protocol
    was designed to easily re-synchronize (think about transmission errors/
    lost bytes).

The fragment of text you reply to is not about the 3-byte PS/2
protocol, but about the 4-byte wheelmouse protocol.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
  2001-08-14 16:58     ` Linus Torvalds
@ 2001-08-14 17:35       ` Kurt Garloff
  2001-08-14 21:29       ` Kurt Garloff
  1 sibling, 0 replies; 19+ messages in thread
From: Kurt Garloff @ 2001-08-14 17:35 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Kurt Garloff, Andries.Brouwer, alan, linux-kernel, mantel, rubini

[-- Attachment #1: Type: text/plain, Size: 2193 bytes --]

Hi Linus,

thanks for your comments.

On Tue, Aug 14, 2001 at 09:58:55AM -0700, Linus Torvalds wrote:
> I really have two comments, but I haven't followed the whole discussion,
> so feel free to just say that it's been hashed out already:
> 
>  - sysconf entries are suspicious for stuff like this. If some code really
>    requires this to work correctly, that's exactly the kind of code that
>    would run automatically at bootup. A sysconf doesn't really help people
>    in that case - we'd be much better off with just a bootup switch.

Maybe that's the difference of whether you define the kernel behaviour by
deciding what goes in and the one that tries to avoid a breakage without
changing the default behaviour ...
Of course the sysctl is less intrusive (from a user's point of view).

>  - do we actually need the config switch AT ALL, whether at bootup or not?
>    What exactly breaks if we just always pass the AA 00 values through?
>    Apparently nothing ever breaks, which makes me suspect that people are
>    just being unnecessarily defensive.

PS2 mouses need this ping thing to be operational after being plugged.
But, there's no reason it needs to be done in the kernel.
* It works for plain PS2 only (not: imps2, synps2, ...)
* The userspace driver (gpm, X11) can do it as well, AFAICS

I guess the thing has been introduced because it was more convenient than
fixing userspace.
Maybe the kernel does it a bit more efficient by throwing away the queue ...

> In short, I'd prefer a patch that just unconditionally removes the code,
> unless somebody KNOWS that it could break something. That failing, a
> simple kernel command line option sounds better than more files in /proc.

I'd be happy with removing it.
Patch will follow!

> Remember: the biggest mistake to do is to overdesign. The road to hell is
> paved with good intentions.

A few sysctls don't qualify as overdesign yet, I hope.

Regards,
-- 
Kurt Garloff  <garloff@suse.de>                          Eindhoven, NL
GPG key: See mail header, key servers         Linux kernel development
SuSE GmbH, Nuernberg, DE                                SCSI, Security

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
  2001-08-14 11:12 Andries.Brouwer
@ 2001-08-14 17:10 ` Gunther Mayer
  2001-08-14 21:56   ` Kurt Garloff
  0 siblings, 1 reply; 19+ messages in thread
From: Gunther Mayer @ 2001-08-14 17:10 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andries.Brouwer

Andries.Brouwer@cwi.nl wrote:
> 
>     From garloff@garloff.de Tue Aug 14 11:57:23 2001
> 
>     I can confirm what you suggest:
>         My mouse (Logitech wheel USB/PS2) sends indeed AA 00.
>     So, I extended my patch:
>     psmouse_reconnect = 0: Do nothing (just pass all to userspace)
>     psmouse_reconnect = 1: Flush Q & ping mouse on AA 00 (default)
>     psmouse_reconnect = 2: Flush Q & ping mouse on AA (old behaviour)
> 
>     With reconnect 1 or 2: After reconnecting, mouse behaves strange
>         (jumping around the screen)

This is a serious bug in many user-space drivers. PS/2 mouse protocol
was designed to easily re-synchronize (think about transmission errors/
lost bytes).

>     With reconnect 0:      Mouse is dead

This is a bug in all user-space drivers (understandable as the
kernel tried to be too clever). They must send the proper ps2-enabling
sequence after they see "aa 00".

> 
>     In both cases restarting gpm gets the mouse back to work again.
>     It seems the imps2 driver does some initialization to the mouse.
> 
>     If I use the plain ps2 driver, then finally, I see the benefit of the
>     reconnect code in the kernel:
>     With reconnect = 1 or 2: It works after replugging
>     With reconnect = 0:      Mouse is dead after replugging
> 
>     In the latter case restarting gpm helps.
...

Add an "ioctl(PS2_TRANSPARENT)", to disable the current kernel policy.
So new drivers which understand about "aa 00" sequences can act properly.
Don't break existing apps.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
  2001-08-14 15:03   ` Kurt Garloff
@ 2001-08-14 16:58     ` Linus Torvalds
  2001-08-14 17:35       ` Kurt Garloff
  2001-08-14 21:29       ` Kurt Garloff
  0 siblings, 2 replies; 19+ messages in thread
From: Linus Torvalds @ 2001-08-14 16:58 UTC (permalink / raw)
  To: Kurt Garloff; +Cc: Andries.Brouwer, alan, linux-kernel, mantel, rubini


> Well, probably not, as it contains a typo which lets machines without kbd
> hang. Fixed version attached. Sorry!

Hmm..

I really have two comments, but I haven't followed the whole discussion,
so feel free to just say that it's been hashed out already:

 - sysconf entries are suspicious for stuff like this. If some code really
   requires this to work correctly, that's exactly the kind of code that
   would run automatically at bootup. A sysconf doesn't really help people
   in that case - we'd be much better off with just a bootup switch.

 - do we actually need the config switch AT ALL, whether at bootup or not?
   What exactly breaks if we just always pass the AA 00 values through?
   Apparently nothing ever breaks, which makes me suspect that people are
   just being unnecessarily defensive.

In short, I'd prefer a patch that just unconditionally removes the code,
unless somebody KNOWS that it could break something. That failing, a
simple kernel command line option sounds better than more files in /proc.

Remember: the biggest mistake to do is to overdesign. The road to hell is
paved with good intentions.

		Linus


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
  2001-08-14  9:57 ` Kurt Garloff
@ 2001-08-14 15:03   ` Kurt Garloff
  2001-08-14 16:58     ` Linus Torvalds
  0 siblings, 1 reply; 19+ messages in thread
From: Kurt Garloff @ 2001-08-14 15:03 UTC (permalink / raw)
  To: Andries.Brouwer, alan, linux-kernel, mantel, rubini, torvalds


[-- Attachment #1.1: Type: text/plain, Size: 493 bytes --]

On Tue, Aug 14, 2001 at 11:57:01AM +0200, Kurt Garloff wrote:
> Linus, Alan, I'd like to have your input:
> 
> Do you like the patch as is? 

Well, probably not, as it contains a typo which lets machines without kbd
hang. Fixed version attached. Sorry!

Regards,
-- 
Kurt Garloff  <garloff@suse.de>                          Eindhoven, NL
GPG key: See mail header, key servers         Linux kernel development
SuSE GmbH, Nuernberg, DE                                SCSI, Security

[-- Attachment #1.2: 247-psaux-reconnect-sysctl3.diff --]
[-- Type: text/plain, Size: 6934 bytes --]

diff -uNr linux-2.4.7.kurt-1/drivers/char/pc_keyb.c linux-2.4.7.kurt-1-psaux/drivers/char/pc_keyb.c
--- linux-2.4.7.kurt-1/drivers/char/pc_keyb.c	Tue Jul 24 18:42:36 2001
+++ linux-2.4.7.kurt-1-psaux/drivers/char/pc_keyb.c	Tue Aug 14 16:56:58 2001
@@ -81,8 +81,9 @@
 
 static int __init psaux_init(void);
 
-#define AUX_RECONNECT 170 /* scancode when ps2 device is plugged (back) in */
- 
+#define AUX_RECONNECT1 170 /* scancode when ps2 device is plugged (back) in */
+#define AUX_RECONNECT2 0   /* scancode when ps2 device is plugged (back) in */
+
 static struct aux_queue *queue;	/* Mouse data buffer. */
 static int aux_count;
 /* used when we send commands to the mouse that expect an ACK. */
@@ -92,8 +93,83 @@
 #define AUX_INTS_ON  (KBD_MODE_KCC | KBD_MODE_SYS | KBD_MODE_MOUSE_INT | KBD_MODE_KBD_INT)
 
 #define MAX_RETRIES	60		/* some aux operations take long time*/
+
 #endif /* CONFIG_PSMOUSE */
 
+/* We want to be able to handle the psmouse reconnect token; unfortunately the
+ * Synaptics touchpads (and probably others too) use it for their extented
+ * functionality and produce them in extended mode (as set by gpm -t synps2).
+ * So we make this adjustable via a sysctl.  garloff@suse.de, 2001-08-01 */
+
+#ifdef CONFIG_SYSCTL
+#include <linux/sysctl.h>
+#ifdef CONFIG_PSMOUSE
+int sysctl_psmouse_reconnect = 1;
+#endif
+int sysctl_kbd_report_unkn = 1;
+int sysctl_kbd_report_to = 1;
+
+static int psaux_sysctl_handler (ctl_table *ctl, int write, struct file *filp,
+				 void *buffer, size_t *lenp)
+{
+	int *valp = ctl->data;
+	int ret = proc_dointvec(ctl, write, filp, buffer, lenp); 
+	if (write) {
+		if (*valp > 2)
+			*valp = 2;
+	}
+	return ret;
+}
+			
+
+ctl_table psaux_table[] = {
+#ifdef CONFIG_PSMOUSE   
+        {DEV_PSMOUSE_RECONNECT, "psmouse_reconnect", &sysctl_psmouse_reconnect,
+                sizeof(int), 0644, NULL, &psaux_sysctl_handler},
+#endif   
+	{DEV_KBD_REPORT_UNKN, "kbd_report_unknown", &sysctl_kbd_report_unkn,
+                sizeof(int), 0644, NULL, &psaux_sysctl_handler},
+        {DEV_KBD_REPORT_TO, "kbd_report_timeout", &sysctl_kbd_report_to,
+                sizeof(int), 0644, NULL, &psaux_sysctl_handler},
+	{0}
+};
+
+ctl_table psaux_psaux_table[] = {
+        {DEV_CDROM, "ps2", NULL, 0, 0555, psaux_table},
+        {0}
+        };
+
+ctl_table psaux_root_table[] = {
+#ifdef CONFIG_PROC_FS
+        {CTL_DEV, "dev", NULL, 0, 0555, psaux_psaux_table},
+#endif /* CONFIG_PROC_FS */
+        {0}
+        };
+static struct ctl_table_header *psaux_sysctl_header;
+
+static void psaux_sysctl_register (void)
+{
+	static int initialized;
+	if (initialized) return;
+	
+	psaux_sysctl_header = register_sysctl_table (psaux_root_table, 1);
+	/*psaux_root_table->child->de->owner = THIS_MODULE;*/
+	initialized++;
+}
+
+/*
+static void psaux_sysctl_unregister (void)
+{
+	if (psaux_sysctl_header)
+		unregister_sysctl_table (psaux_sysctl_header);
+}
+ */
+#else /* CONFIG_SYSCTL */
+#define sysctl_psmouse_reconnect 1
+#define sysctl_kbd_report_unkn 1
+#define sysctl_kbd_report_to 1
+#endif /* CONFIG_SYSCTL */
+
 /*
  * Wait for keyboard controller input buffer to drain.
  *
@@ -123,9 +199,8 @@
 		mdelay(1);
 		timeout--;
 	} while (timeout);
-#ifdef KBD_REPORT_TIMEOUTS
-	printk(KERN_WARNING "Keyboard timed out[1]\n");
-#endif
+	if (sysctl_kbd_report_to)
+		printk(KERN_WARNING "Keyboard timed out[1]\n");
 }
 
 /*
@@ -324,10 +399,8 @@
 		  *keycode = E1_PAUSE;
 		  prev_scancode = 0;
 	      } else {
-#ifdef KBD_REPORT_UNKN
-		  if (!raw_mode)
+		  if (!raw_mode && sysctl_kbd_report_unkn)
 		    printk(KERN_INFO "keyboard: unknown e1 escape sequence\n");
-#endif
 		  prev_scancode = 0;
 		  return 0;
 	      }
@@ -352,11 +425,9 @@
 	      if (e0_keys[scancode])
 		*keycode = e0_keys[scancode];
 	      else {
-#ifdef KBD_REPORT_UNKN
-		  if (!raw_mode)
+		  if (!raw_mode && sysctl_kbd_report_unkn)
 		    printk(KERN_INFO "keyboard: unknown scancode e0 %02x\n",
 			   scancode);
-#endif
 		  return 0;
 	      }
 	  }
@@ -374,11 +445,9 @@
 	  *keycode = high_keys[scancode - SC_LIM];
 
 	  if (!*keycode) {
-	      if (!raw_mode) {
-#ifdef KBD_REPORT_UNKN
+	      if (!raw_mode && sysctl_kbd_report_unkn) {
 		  printk(KERN_INFO "keyboard: unrecognized scancode (%02x)"
 			 " - ignored\n", scancode);
-#endif
 	      }
 	      return 0;
 	  }
@@ -397,6 +466,7 @@
 	    return 0200;
 }
 
+static unsigned char psaux_prev;
 static inline void handle_mouse_event(unsigned char scancode)
 {
 #ifdef CONFIG_PSMOUSE
@@ -407,13 +477,24 @@
 		}
 		mouse_reply_expected = 0;
 	}
-	else if(scancode == AUX_RECONNECT){
+	else if(scancode == AUX_RECONNECT1 
+		&& sysctl_psmouse_reconnect == 2) {
+		printk (KERN_DEBUG "PS2 mouse reconnect detected.\n");
+		queue->head = queue->tail = 0;  /* Flush input queue */
+		__aux_write_ack(AUX_ENABLE_DEV);  /* ping the mouse :) */
+		return;
+	}
+	else if (scancode == AUX_RECONNECT2 && psaux_prev == AUX_RECONNECT1
+		 && sysctl_psmouse_reconnect == 1 ) {
+		printk (KERN_DEBUG "PS2 mouse reconnect detected.\n");
 		queue->head = queue->tail = 0;  /* Flush input queue */
 		__aux_write_ack(AUX_ENABLE_DEV);  /* ping the mouse :) */
 		return;
 	}
 
 	add_mouse_randomness(scancode);
+	psaux_prev = scancode;
+
 	if (aux_count) {
 		int head = queue->head;
 
@@ -516,16 +597,14 @@
 				break;
 			mdelay(1);
 			if (!--timeout) {
-#ifdef KBD_REPORT_TIMEOUTS
-				printk(KERN_WARNING "keyboard: Timeout - AT keyboard not present?\n");
-#endif
+				if (sysctl_kbd_report_to)
+					printk(KERN_WARNING "keyboard: Timeout - AT keyboard not present?\n");
 				return 0;
 			}
 		}
 	} while (retries-- > 0);
-#ifdef KBD_REPORT_TIMEOUTS
-	printk(KERN_WARNING "keyboard: Too many NACKs -- noisy kbd cable?\n");
-#endif
+	if (sysctl_kbd_report_to)
+		printk(KERN_WARNING "keyboard: Too many NACKs -- noisy kbd cable?\n");
 	return 0;
 }
 
@@ -755,6 +834,7 @@
 
 	/* Ok, finally allocate the IRQ, and off we go.. */
 	kbd_request_irq(keyboard_interrupt);
+	psaux_sysctl_register ();
 }
 
 #if defined CONFIG_PSMOUSE
diff -uNr linux-2.4.7.kurt-1/include/linux/sysctl.h linux-2.4.7.kurt-1-psaux/include/linux/sysctl.h
--- linux-2.4.7.kurt-1/include/linux/sysctl.h	Tue Jul 24 18:48:05 2001
+++ linux-2.4.7.kurt-1-psaux/include/linux/sysctl.h	Tue Aug 14 10:37:54 2001
@@ -594,7 +594,8 @@
 	DEV_HWMON=2,
 	DEV_PARPORT=3,
 	DEV_RAID=4,
-	DEV_MAC_HID=5
+	DEV_MAC_HID=5,
+	DEV_PSAUX=6,
 };
 
 /* /proc/sys/dev/cdrom */
@@ -653,6 +654,13 @@
 	DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE=4,
 	DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE=5,
 	DEV_MAC_HID_ADB_MOUSE_SENDS_KEYCODES=6
+};
+
+/* /proc/sys/dev/psaux */
+enum {
+	DEV_PSMOUSE_RECONNECT=1,
+	DEV_KBD_REPORT_UNKN=2,
+	DEV_KBD_REPORT_TO=3,
 };
 
 #ifdef __KERNEL__

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
@ 2001-08-14 11:12 Andries.Brouwer
  2001-08-14 17:10 ` Gunther Mayer
  0 siblings, 1 reply; 19+ messages in thread
From: Andries.Brouwer @ 2001-08-14 11:12 UTC (permalink / raw)
  To: Andries.Brouwer, garloff; +Cc: alan, linux-kernel, mantel, rubini, torvalds

    From garloff@garloff.de Tue Aug 14 11:57:23 2001

    I can confirm what you suggest:
	My mouse (Logitech wheel USB/PS2) sends indeed AA 00.
    So, I extended my patch:
    psmouse_reconnect = 0: Do nothing (just pass all to userspace)
    psmouse_reconnect = 1: Flush Q & ping mouse on AA 00 (default)
    psmouse_reconnect = 2: Flush Q & ping mouse on AA (old behaviour)

    With reconnect 1 or 2: After reconnecting, mouse behaves strange
	(jumping around the screen)
    With reconnect 0:      Mouse is dead

    In both cases restarting gpm gets the mouse back to work again.
    It seems the imps2 driver does some initialization to the mouse.

    If I use the plain ps2 driver, then finally, I see the benefit of the
    reconnect code in the kernel:
    With reconnect = 1 or 2: It works after replugging
    With reconnect = 0:      Mouse is dead after replugging

    In the latter case restarting gpm helps.

Before having an opinion about what would be appropriate,
let me make sure that I understand the facts that you report.

You talk about reconnect, but what is your definition of reconnect?
Is it that the mouse sends AA or AA 00, or is it that you unplug
and replug the mouse?

Andries

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
  2001-08-02 17:27 Andries.Brouwer
@ 2001-08-14  9:57 ` Kurt Garloff
  2001-08-14 15:03   ` Kurt Garloff
  0 siblings, 1 reply; 19+ messages in thread
From: Kurt Garloff @ 2001-08-14  9:57 UTC (permalink / raw)
  To: Andries.Brouwer; +Cc: alan, linux-kernel, mantel, rubini, torvalds


[-- Attachment #1.1: Type: text/plain, Size: 2510 bytes --]

Hi Andries,

On Thu, Aug 02, 2001 at 05:27:07PM +0000, Andries Brouwer wrote:
>     Your other mail implies that we can fix the problem without manual
>     intervention by parsing AA 00 instead of just AA. If it's true, I'd=20
>     consider that the best solution.=20
> 
> Maybe precisely one person reported this, and his address
> now bounces. If there exist people who need this "psaux-reconnect"
> they can report on the codes they see. Note that just like AA is
> a perfectly normal code, also the sequence AA 00 is perfectly
> normal. Testing for that only diminishes the probability of
> getting it by accident.

I can confirm what you suggest: My mouse (Logitech wheel USB/PS2) sends
indeed AA 00. 
So, I extended my patch (which you will dislike even more, I know, as you're
against sysctls unlike me):
psmouse_reconnect = 0: Do nothing (just pass all to userspace)
psmouse_reconnect = 1: Flush Q & ping mouse on AA 00 (default)
psmouse_reconnect = 2: Flush Q & ping mouse on AA (old behaviour)

> Instead of adding boot parameters or sysctls or heuristics,
> probably we should just transfer the codes seen to user space,
> e.g. to gpm.  Then it is up to gpm to recognize an AA 00 sequence
> and decide whether that is something special.

With reconnect 1 or 2: After reconnecting, mouse behaves strange (jumping
			around the screen)
With reconnect 0:      Mouse is dead

In both cases restarting gpm gets the mouse back to work again.
It seems the imps2 driver does some initialization to the mouse.

If I use the plain ps2 driver, then finally, I see the benefit of the
reconnect code in the kernel:
With reconnect = 1 or 2: It works after replugging
With reconnect = 0:      Mouse is dead after replugging

In the latter case restarting gpm helps.

Patch is attached.
It adds the sysctls as the last patch did, but now the psmouse_reconnect has
3 possible values. Also, I added a printk, so the kernel logs detected mouse
reconnect events.

Linus, Alan, I'd like to have your input:

Do you like the patch as is? Should I remove the sysctls and just look for
AA 00 (as Andries may prefer)? Shouldn't the AA 00 be passed to userspace
as well in any case (to allow e.g. the imps2 driver to do reinitialization)?

Regards,
-- 
Kurt Garloff  <garloff@suse.de>                          Eindhoven, NL
GPG key: See mail header, key servers         Linux kernel development
SuSE GmbH, Nuernberg, DE                                SCSI, Security

[-- Attachment #1.2: 247-psaux-reconnect-sysctl2.diff --]
[-- Type: text/plain, Size: 6888 bytes --]

diff -uNr linux-2.4.7.kurt-1/drivers/char/pc_keyb.c linux-2.4.7.kurt-1-psaux/drivers/char/pc_keyb.c
--- linux-2.4.7.kurt-1/drivers/char/pc_keyb.c	Tue Jul 24 18:42:36 2001
+++ linux-2.4.7.kurt-1-psaux/drivers/char/pc_keyb.c	Tue Aug 14 10:44:50 2001
@@ -81,8 +81,9 @@
 
 static int __init psaux_init(void);
 
-#define AUX_RECONNECT 170 /* scancode when ps2 device is plugged (back) in */
- 
+#define AUX_RECONNECT1 170 /* scancode when ps2 device is plugged (back) in */
+#define AUX_RECONNECT2 0   /* scancode when ps2 device is plugged (back) in */
+
 static struct aux_queue *queue;	/* Mouse data buffer. */
 static int aux_count;
 /* used when we send commands to the mouse that expect an ACK. */
@@ -92,8 +93,83 @@
 #define AUX_INTS_ON  (KBD_MODE_KCC | KBD_MODE_SYS | KBD_MODE_MOUSE_INT | KBD_MODE_KBD_INT)
 
 #define MAX_RETRIES	60		/* some aux operations take long time*/
+
 #endif /* CONFIG_PSMOUSE */
 
+/* We want to be able to handle the psmouse reconnect token; unfortunately the
+ * Synaptics touchpads (and probably others too) use it for their extented
+ * functionality and produce them in extended mode (as set by gpm -t synps2).
+ * So we make this adjustable via a sysctl.  garloff@suse.de, 2001-08-01 */
+
+#ifdef CONFIG_SYSCTL
+#include <linux/sysctl.h>
+#ifdef CONFIG_PSMOUSE
+int sysctl_psmouse_reconnect = 1;
+#endif
+int sysctl_kbd_report_unkn = 0;
+int sysctl_kbd_report_to = 0;
+
+static int psaux_sysctl_handler (ctl_table *ctl, int write, struct file *filp,
+				 void *buffer, size_t *lenp)
+{
+	int *valp = ctl->data;
+	int ret = proc_dointvec(ctl, write, filp, buffer, lenp); 
+	if (write) {
+		if (*valp > 2)
+			*valp = 2;
+	}
+	return ret;
+}
+			
+
+ctl_table psaux_table[] = {
+#ifdef CONFIG_PSMOUSE   
+        {DEV_PSMOUSE_RECONNECT, "psmouse_reconnect", &sysctl_psmouse_reconnect,
+                sizeof(int), 0644, NULL, &psaux_sysctl_handler},
+#endif   
+	{DEV_KBD_REPORT_UNKN, "kbd_report_unknown", &sysctl_kbd_report_unkn,
+                sizeof(int), 0644, NULL, &psaux_sysctl_handler},
+        {DEV_KBD_REPORT_TO, "kbd_report_timeout", &sysctl_kbd_report_to,
+                sizeof(int), 0644, NULL, &psaux_sysctl_handler},
+	{0}
+};
+
+ctl_table psaux_psaux_table[] = {
+        {DEV_CDROM, "ps2", NULL, 0, 0555, psaux_table},
+        {0}
+        };
+
+ctl_table psaux_root_table[] = {
+#ifdef CONFIG_PROC_FS
+        {CTL_DEV, "dev", NULL, 0, 0555, psaux_psaux_table},
+#endif /* CONFIG_PROC_FS */
+        {0}
+        };
+static struct ctl_table_header *psaux_sysctl_header;
+
+static void psaux_sysctl_register (void)
+{
+	static int initialized;
+	if (initialized) return;
+	
+	psaux_sysctl_header = register_sysctl_table (psaux_root_table, 1);
+	/*psaux_root_table->child->de->owner = THIS_MODULE;*/
+	initialized++;
+}
+
+/*
+static void psaux_sysctl_unregister (void)
+{
+	if (psaux_sysctl_header)
+		unregister_sysctl_table (psaux_sysctl_header);
+}
+ */
+#else /* CONFIG_SYSCTL */
+#define sysctl_psmouse_reconnect 1
+#define sysctl_kbd_report_unkn 0
+#define sysctl_kbd_report_to 0
+#endif /* CONFIG_SYSCTL */
+
 /*
  * Wait for keyboard controller input buffer to drain.
  *
@@ -123,9 +199,8 @@
 		mdelay(1);
 		timeout--;
 	} while (timeout);
-#ifdef KBD_REPORT_TIMEOUTS
-	printk(KERN_WARNING "Keyboard timed out[1]\n");
-#endif
+	if (sysctl_kbd_report_to)
+		printk(KERN_WARNING "Keyboard timed out[1]\n");
 }
 
 /*
@@ -324,10 +399,8 @@
 		  *keycode = E1_PAUSE;
 		  prev_scancode = 0;
 	      } else {
-#ifdef KBD_REPORT_UNKN
-		  if (!raw_mode)
+		  if (!raw_mode && sysctl_kbd_report_unkn)
 		    printk(KERN_INFO "keyboard: unknown e1 escape sequence\n");
-#endif
 		  prev_scancode = 0;
 		  return 0;
 	      }
@@ -352,11 +425,9 @@
 	      if (e0_keys[scancode])
 		*keycode = e0_keys[scancode];
 	      else {
-#ifdef KBD_REPORT_UNKN
-		  if (!raw_mode)
+		  if (!raw_mode && sysctl_kbd_report_unkn)
 		    printk(KERN_INFO "keyboard: unknown scancode e0 %02x\n",
 			   scancode);
-#endif
 		  return 0;
 	      }
 	  }
@@ -374,11 +445,9 @@
 	  *keycode = high_keys[scancode - SC_LIM];
 
 	  if (!*keycode) {
-	      if (!raw_mode) {
-#ifdef KBD_REPORT_UNKN
+	      if (!raw_mode && sysctl_kbd_report_unkn) {
 		  printk(KERN_INFO "keyboard: unrecognized scancode (%02x)"
 			 " - ignored\n", scancode);
-#endif
 	      }
 	      return 0;
 	  }
@@ -397,6 +466,7 @@
 	    return 0200;
 }
 
+static unsigned char psaux_prev;
 static inline void handle_mouse_event(unsigned char scancode)
 {
 #ifdef CONFIG_PSMOUSE
@@ -407,13 +477,24 @@
 		}
 		mouse_reply_expected = 0;
 	}
-	else if(scancode == AUX_RECONNECT){
+	else if(scancode == AUX_RECONNECT1 
+		&& sysctl_psmouse_reconnect == 2) {
+		printk (KERN_DEBUG "PS2 mouse reconnect detected.\n");
+		queue->head = queue->tail = 0;  /* Flush input queue */
+		__aux_write_ack(AUX_ENABLE_DEV);  /* ping the mouse :) */
+		return;
+	}
+	else if (scancode == AUX_RECONNECT2 && psaux_prev == AUX_RECONNECT1
+		 && sysctl_psmouse_reconnect == 1 ) {
+		printk (KERN_DEBUG "PS2 mouse reconnect detected.\n");
 		queue->head = queue->tail = 0;  /* Flush input queue */
 		__aux_write_ack(AUX_ENABLE_DEV);  /* ping the mouse :) */
 		return;
 	}
 
 	add_mouse_randomness(scancode);
+	psaux_prev = scancode;
+
 	if (aux_count) {
 		int head = queue->head;
 
@@ -515,17 +596,14 @@
 			if (resend)
 				break;
 			mdelay(1);
-			if (!--timeout) {
-#ifdef KBD_REPORT_TIMEOUTS
+			if (!--timeout && sysctl_kbd_report_to) {
 				printk(KERN_WARNING "keyboard: Timeout - AT keyboard not present?\n");
-#endif
 				return 0;
 			}
 		}
 	} while (retries-- > 0);
-#ifdef KBD_REPORT_TIMEOUTS
-	printk(KERN_WARNING "keyboard: Too many NACKs -- noisy kbd cable?\n");
-#endif
+	if (sysctl_kbd_report_to)
+		printk(KERN_WARNING "keyboard: Too many NACKs -- noisy kbd cable?\n");
 	return 0;
 }
 
@@ -755,6 +833,7 @@
 
 	/* Ok, finally allocate the IRQ, and off we go.. */
 	kbd_request_irq(keyboard_interrupt);
+	psaux_sysctl_register ();
 }
 
 #if defined CONFIG_PSMOUSE
diff -uNr linux-2.4.7.kurt-1/include/linux/sysctl.h linux-2.4.7.kurt-1-psaux/include/linux/sysctl.h
--- linux-2.4.7.kurt-1/include/linux/sysctl.h	Tue Jul 24 18:48:05 2001
+++ linux-2.4.7.kurt-1-psaux/include/linux/sysctl.h	Tue Aug 14 10:37:54 2001
@@ -594,7 +594,8 @@
 	DEV_HWMON=2,
 	DEV_PARPORT=3,
 	DEV_RAID=4,
-	DEV_MAC_HID=5
+	DEV_MAC_HID=5,
+	DEV_PSAUX=6,
 };
 
 /* /proc/sys/dev/cdrom */
@@ -653,6 +654,13 @@
 	DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE=4,
 	DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE=5,
 	DEV_MAC_HID_ADB_MOUSE_SENDS_KEYCODES=6
+};
+
+/* /proc/sys/dev/psaux */
+enum {
+	DEV_PSMOUSE_RECONNECT=1,
+	DEV_KBD_REPORT_UNKN=2,
+	DEV_KBD_REPORT_TO=3,
 };
 
 #ifdef __KERNEL__

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
       [not found] <no.id>
  2001-08-02 15:03 ` Alan Cox
@ 2001-08-02 17:34 ` Alan Cox
  1 sibling, 0 replies; 19+ messages in thread
From: Alan Cox @ 2001-08-02 17:34 UTC (permalink / raw)
  To: Andries.Brouwer; +Cc: garloff, alan, linux-kernel, mantel, rubini, torvalds

> Of course I hope that we'll handle this correctly at some point,
> without any options or parameters. In my eyes a sysctl is heavier
> infrastructure than a boot parameter, so I prefer the latter
> when a temporary fix is needed.

The input device infrastructure pending for 2.5 already handles all of
these issues

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
@ 2001-08-02 17:27 Andries.Brouwer
  2001-08-14  9:57 ` Kurt Garloff
  0 siblings, 1 reply; 19+ messages in thread
From: Andries.Brouwer @ 2001-08-02 17:27 UTC (permalink / raw)
  To: Andries.Brouwer, garloff; +Cc: alan, linux-kernel, mantel, rubini, torvalds

    From: Kurt Garloff <garloff@suse.de>

    > Not precisely - it is a boot parameter "psaux-reconnect".
    > That is better than a sysctl.

    Why should that be better than a sysctl? Boot parameters are ugly. You
    need to reboot in order to change them ...

Of course I hope that we'll handle this correctly at some point,
without any options or parameters. In my eyes a sysctl is heavier
infrastructure than a boot parameter, so I prefer the latter
when a temporary fix is needed.

    Your other mail implies that we can fix the problem without manual
    intervention by parsing AA 00 instead of just AA. If it's true, I'd=20
    consider that the best solution.=20

Maybe precisely one person reported this, and his address
now bounces. If there exist people who need this "psaux-reconnect"
they can report on the codes they see. Note that just like AA is
a perfectly normal code, also the sequence AA 00 is perfectly
normal. Testing for that only diminishes the probability of
getting it by accident.

Instead of adding boot parameters or sysctls or heuristics,
probably we should just transfer the codes seen to user space,
e.g. to gpm.  Then it is up to gpm to recognize an AA 00 sequence
and decide whether that is something special.

Andries



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
       [not found] <no.id>
@ 2001-08-02 15:03 ` Alan Cox
  2001-08-02 17:34 ` Alan Cox
  1 sibling, 0 replies; 19+ messages in thread
From: Alan Cox @ 2001-08-02 15:03 UTC (permalink / raw)
  To: Andries.Brouwer
  Cc: alan, garloff, torvalds, brent, linux-kernel, mantel, rubini

> who asked for this code): if what I say is correct you should
> always see 00 following the AA. So, there may exist a more cautious
> patch that will bite fewer people and does not react to AA but to
> the sequence AA 00.

2.2 has had the sysctl for ages, and it defaults to off

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] make psaux reconnect adjustable
@ 2001-08-02 11:55 Andries.Brouwer
  0 siblings, 0 replies; 19+ messages in thread
From: Andries.Brouwer @ 2001-08-02 11:55 UTC (permalink / raw)
  To: alan, garloff, torvalds; +Cc: brent, linux-kernel, mantel, rubini

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2749 bytes --]

    From: Kurt Garloff <garloff@suse.de>

    working on notebooks I got used to the touchpads.
    Now, a lot of notebooks have a Synaptics touchpad.
    It offers a few additional features, such as tossing or the third mouse
    button (by a short click in the corner) ...

    Unfortunately, the synps2 generates nonstandard codes when in
    extended mode, amongst which the reconnect (170) token.
    The kernel (since 2.2.15) does interpret it as such and empties the queue.

    This seems to appropriate for a real plug event. For a synps2, it's not,
    but makes your mouse dead for a second. Instead the data should just
    be passed to userspace (gpm).

    So I made the behaviour switchable via a sysctl.=20

Hmm. I don't think there exists a "reconnect token" AA.
At power up or after a reset (FF) the mouse sends AA
(self test passed) followed by 00 (the ID: I am a PS/2 mouse).
During operation the value AA is entirely legal and has no special
significance.

Moreover, it seems that the specs say that the host should not react
to the AA but wait for the 00. The expected protocol at power up is:
Mouse: AA 00. Host: F4 (enable). Mouse: FA (ack).
Afterwards the host will send F3 to set the sample rate
(or to initialize a wheelmouse).

A quote [1]:
"At power-on, the PS/2 device performs a self-test and calibration,
then transmits the completion code $AA and ID code $00.  If the
device fails its self-test, it transmits error code $FC and ID code $00.
This processing also occurs when a software Reset ($FF) command is received.
The host should not attempt to send commands to the device until
the calibration/self-test is complete.
Power-on self-test and calibration takes 300­1000ms."

The reaction to FF (reset) from the host is an immediate FA (ack)
followed half a second later by AA 00.

Therefore, I think the kernel mouse handling was broken when this
strange AUX_RECONNECT stuff was introduced. It caused a tiny trickle
of complaints.
Bug 1: AA is not necessarily anything special
Bug 2: the sequence AA 00 from the mouse should not be interrupted

I don't think that it is a good idea to start building infrastructure
around it. By default this AUX_RECONNECT should be disabled, since
it is just plain wrong. Then the Synaptics touchpad will work.
In other words, no sysctl but #if 0 ... #endif.

For people who unplug and replug their PS/2 mouse with running
machine, or who use a KVM switch (I think it was only Brent Verner
who asked for this code): if what I say is correct you should
always see 00 following the AA. So, there may exist a more cautious
patch that will bite fewer people and does not react to AA but to
the sequence AA 00.

Andries

[1] See http://www.synaptics.com/decaf/utilities/tp-intf2-4.PDF

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] make psaux reconnect adjustable
@ 2001-08-02  2:21 Kurt Garloff
  0 siblings, 0 replies; 19+ messages in thread
From: Kurt Garloff @ 2001-08-02  2:21 UTC (permalink / raw)
  To: Linus Torvalds, Alan Cox
  Cc: Alessandro Rubini, Hubert Mantel, Linux kernel list


[-- Attachment #1.1: Type: text/plain, Size: 1453 bytes --]

Hi Linus Alan,

working on notebooks I got used to the touchpads.
Now, a lot of notebooks have a Synaptics touchpad.
It offers a few additional features, such as tossing or the third mouse
button (by a short click in the corner) ...

gpm -t synps2 does support those additional features and via the -R epeater
mode you also get it under X11.

Unfortunately, the synps2 generates nonstandard codes when in extended mode,
amongst which the reconnect (170) token.
The kernel (since 2.2.15) does interpret it as such and empties the queue.

This seems to appropriate for a real plug event. For a synps2, it's not, but
makes your mouse dead for a second. Instead the data should just be passed
to userspace (gpm).

So I made the behaviour switchable via a sysctl. 
/proc/sys/dev/ps2/psmouse_reconnect (defaults to 1 = the interpret behaviour)
Being at it, I also made the kbd error and unknown scancode reporting
switchable. (It used to be ifdefs.)

Please apply attached patch (against 2.4.7).

Allesandro, should I submit a patch for gpm to automatically handle this for
synps2 in case the kernel patch gets accepted?

Regards,
-- 
Kurt Garloff                   <kurt@garloff.de>         [Eindhoven, NL]
Physics: Plasma simulations  <K.Garloff@Phys.TUE.NL>  [TU Eindhoven, NL]
Linux: SCSI, Security          <garloff@suse.de>    [SuSE Nuernberg, DE]
 (See mail header or public key servers for PGP2 and GPG public keys.)

[-- Attachment #1.2: 247-psaux-reconnect-sysctl.diff --]
[-- Type: text/plain, Size: 5729 bytes --]

--- linux/include/linux/sysctl.h.orig	Tue Jul 31 23:49:42 2001
+++ linux/include/linux/sysctl.h	Thu Aug  2 03:41:34 2001
@@ -594,7 +594,8 @@
 	DEV_HWMON=2,
 	DEV_PARPORT=3,
 	DEV_RAID=4,
-	DEV_MAC_HID=5
+	DEV_MAC_HID=5,
+	DEV_PSAUX=6,
 };
 
 /* /proc/sys/dev/cdrom */
@@ -653,6 +654,13 @@
 	DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE=4,
 	DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE=5,
 	DEV_MAC_HID_ADB_MOUSE_SENDS_KEYCODES=6
+};
+
+/* /proc/sys/dev/psaux */
+enum {
+	DEV_PSMOUSE_RECONNECT=1,
+	DEV_KBD_REPORT_UNKN=2,
+	DEV_KBD_REPORT_TO=3,
 };
 
 #ifdef __KERNEL__
--- linux/drivers/char/pc_keyb.c.orig	Fri Apr  6 19:42:55 2001
+++ linux/drivers/char/pc_keyb.c	Thu Aug  2 04:01:15 2001
@@ -92,8 +92,83 @@
 #define AUX_INTS_ON  (KBD_MODE_KCC | KBD_MODE_SYS | KBD_MODE_MOUSE_INT | KBD_MODE_KBD_INT)
 
 #define MAX_RETRIES	60		/* some aux operations take long time*/
+
 #endif /* CONFIG_PSMOUSE */
 
+/* We want to be able to handle the psmouse reconnect token; unfortunately the
+ * Synaptics touchpads (and probably others too) use it for their extented
+ * functionality and produce them in extended mode (as set by gpm -t synps2).
+ * So we make this adjustable via a sysctl.  garloff@suse.de, 2001-08-01 */
+
+#ifdef CONFIG_SYSCTL
+#include <linux/sysctl.h>
+#ifdef CONFIG_PSMOUSE
+int sysctl_psmouse_reconnect = 1;
+#endif
+int sysctl_kbd_report_unkn = 0;
+int sysctl_kbd_report_to = 0;
+
+static int psaux_sysctl_handler (ctl_table *ctl, int write, struct file *filp,
+				 void *buffer, size_t *lenp)
+{
+	int *valp = ctl->data;
+	int ret = proc_dointvec(ctl, write, filp, buffer, lenp); 
+	if (write) {
+		if (*valp)
+			*valp = 1;
+	}
+	return ret;
+}
+			
+
+ctl_table psaux_table[] = {
+#ifdef CONFIG_PSMOUSE   
+        {DEV_PSMOUSE_RECONNECT, "psmouse_reconnect", &sysctl_psmouse_reconnect,
+                sizeof(int), 0644, NULL, &psaux_sysctl_handler},
+#endif   
+	{DEV_KBD_REPORT_UNKN, "kbd_report_unknown", &sysctl_kbd_report_unkn,
+                sizeof(int), 0644, NULL, &psaux_sysctl_handler},
+        {DEV_KBD_REPORT_TO, "kbd_report_timeout", &sysctl_kbd_report_to,
+                sizeof(int), 0644, NULL, &psaux_sysctl_handler},
+	{0}
+};
+
+ctl_table psaux_psaux_table[] = {
+        {DEV_CDROM, "ps2", NULL, 0, 0555, psaux_table},
+        {0}
+        };
+
+ctl_table psaux_root_table[] = {
+#ifdef CONFIG_PROC_FS
+        {CTL_DEV, "dev", NULL, 0, 0555, psaux_psaux_table},
+#endif /* CONFIG_PROC_FS */
+        {0}
+        };
+static struct ctl_table_header *psaux_sysctl_header;
+
+static void psaux_sysctl_register (void)
+{
+	static int initialized;
+	if (initialized) return;
+	
+	psaux_sysctl_header = register_sysctl_table (psaux_root_table, 1);
+	/*psaux_root_table->child->de->owner = THIS_MODULE;*/
+	initialized++;
+}
+
+/*
+static void psaux_sysctl_unregister (void)
+{
+	if (psaux_sysctl_header)
+		unregister_sysctl_table (psaux_sysctl_header);
+}
+ */
+#else /* CONFIG_SYSCTL */
+#define sysctl_psmouse_reconnect 1
+#define sysctl_kbd_report_unkn 0
+#define sysctl_kbd_report_to 0
+#endif /* CONFIG_SYSCTL */
+
 /*
  * Wait for keyboard controller input buffer to drain.
  *
@@ -123,9 +198,8 @@
 		mdelay(1);
 		timeout--;
 	} while (timeout);
-#ifdef KBD_REPORT_TIMEOUTS
-	printk(KERN_WARNING "Keyboard timed out[1]\n");
-#endif
+	if (sysctl_kbd_report_to)
+		printk(KERN_WARNING "Keyboard timed out[1]\n");
 }
 
 /*
@@ -320,10 +394,8 @@
 		  *keycode = E1_PAUSE;
 		  prev_scancode = 0;
 	      } else {
-#ifdef KBD_REPORT_UNKN
-		  if (!raw_mode)
+		  if (!raw_mode && sysctl_kbd_report_unkn)
 		    printk(KERN_INFO "keyboard: unknown e1 escape sequence\n");
-#endif
 		  prev_scancode = 0;
 		  return 0;
 	      }
@@ -348,11 +420,9 @@
 	      if (e0_keys[scancode])
 		*keycode = e0_keys[scancode];
 	      else {
-#ifdef KBD_REPORT_UNKN
-		  if (!raw_mode)
+		  if (!raw_mode && sysctl_kbd_report_unkn)
 		    printk(KERN_INFO "keyboard: unknown scancode e0 %02x\n",
 			   scancode);
-#endif
 		  return 0;
 	      }
 	  }
@@ -370,11 +440,9 @@
 	  *keycode = high_keys[scancode - SC_LIM];
 
 	  if (!*keycode) {
-	      if (!raw_mode) {
-#ifdef KBD_REPORT_UNKN
+	      if (!raw_mode && sysctl_kbd_report_unkn) {
 		  printk(KERN_INFO "keyboard: unrecognized scancode (%02x)"
 			 " - ignored\n", scancode);
-#endif
 	      }
 	      return 0;
 	  }
@@ -404,12 +472,15 @@
 		mouse_reply_expected = 0;
 	}
 	else if(scancode == AUX_RECONNECT){
-		queue->head = queue->tail = 0;  /* Flush input queue */
-		__aux_write_ack(AUX_ENABLE_DEV);  /* ping the mouse :) */
-		return;
+		if (sysctl_psmouse_reconnect) {
+			queue->head = queue->tail = 0;  /* Flush input queue */
+			__aux_write_ack(AUX_ENABLE_DEV);  /* ping the mouse :) */
+			return;
+		}
 	}
+	else
+		add_mouse_randomness(scancode);
 
-	add_mouse_randomness(scancode);
 	if (aux_count) {
 		int head = queue->head;
 
@@ -511,17 +582,14 @@
 			if (resend)
 				break;
 			mdelay(1);
-			if (!--timeout) {
-#ifdef KBD_REPORT_TIMEOUTS
+			if (!--timeout && sysctl_kbd_report_to) {
 				printk(KERN_WARNING "keyboard: Timeout - AT keyboard not present?\n");
-#endif
 				return 0;
 			}
 		}
 	} while (retries-- > 0);
-#ifdef KBD_REPORT_TIMEOUTS
-	printk(KERN_WARNING "keyboard: Too many NACKs -- noisy kbd cable?\n");
-#endif
+	if (sysctl_kbd_report_to)
+		printk(KERN_WARNING "keyboard: Too many NACKs -- noisy kbd cable?\n");
 	return 0;
 }
 
@@ -751,6 +819,7 @@
 
 	/* Ok, finally allocate the IRQ, and off we go.. */
 	kbd_request_irq(keyboard_interrupt);
+	psaux_sysctl_register ();
 }
 
 #if defined CONFIG_PSMOUSE

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2001-08-15 15:49 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-02 16:02 [PATCH] make psaux reconnect adjustable Andries.Brouwer
2001-08-02 16:18 ` Kurt Garloff
  -- strict thread matches above, loose matches on Subject: below --
2001-08-14 21:26 Andries.Brouwer
2001-08-14 18:29 Andries.Brouwer
2001-08-14 19:35 ` Gunther Mayer
2001-08-14 11:12 Andries.Brouwer
2001-08-14 17:10 ` Gunther Mayer
2001-08-14 21:56   ` Kurt Garloff
2001-08-02 17:27 Andries.Brouwer
2001-08-14  9:57 ` Kurt Garloff
2001-08-14 15:03   ` Kurt Garloff
2001-08-14 16:58     ` Linus Torvalds
2001-08-14 17:35       ` Kurt Garloff
2001-08-14 21:29       ` Kurt Garloff
2001-08-15 15:50         ` Gunther Mayer
     [not found] <no.id>
2001-08-02 15:03 ` Alan Cox
2001-08-02 17:34 ` Alan Cox
2001-08-02 11:55 Andries.Brouwer
2001-08-02  2:21 Kurt Garloff

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).