From tbuswell@tbuswell.ne.mediaone.net  Tue Sep 22 11:27:33 1998
Received: from tbuswell.ne.mediaone.net (tbuswell.ne.mediaone.net [24.128.24.62])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA27181
          for <FreeBSD-gnats-submit@freebsd.org>; Tue, 22 Sep 1998 11:27:32 -0700 (PDT)
          (envelope-from tbuswell@tbuswell.ne.mediaone.net)
Received: (from tbuswell@localhost)
	by tbuswell.ne.mediaone.net (8.9.1/8.8.8) id OAA00789;
	Tue, 22 Sep 1998 14:26:14 -0400 (EDT)
	(envelope-from tbuswell)
Message-Id: <199809221826.OAA00789@tbuswell.ne.mediaone.net>
Date: Tue, 22 Sep 1998 14:26:14 -0400 (EDT)
From: tbuswell@mediaone.net
Reply-To: tbuswell@mediaone.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: PS/2 intellimouse and "psmintr: out of sync" messages
X-Send-Pr-Version: 3.2

>Number:         8027
>Category:       misc
>Synopsis:       PS/2 intellimouse and "psmintr: out of sync" messages
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    yokota
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 22 11:30:01 PDT 1998
>Closed-Date:    Wed Sep 23 09:31:30 PDT 1998
>Last-Modified:  Wed Sep 23 09:32:59 PDT 1998
>Originator:     Ted Buswell
>Release:        FreeBSD 3.0-BETA i386
>Organization:
>Environment:

	PS/2 "MS Intellimouse" and i386/isa/psm.c 1.54

>Description:

	No recovery is attempted when the psm driver detects
	that it is "out of sync" with the device.  Once this condition is
	reached, all subsequent activity with the mouse will generate a
	message such as:
		/kernel: psmintr: out of sync (00c8 != 0008).
	A reboot is required to regain error-free use of the mouse.

>How-To-Repeat:

	1) disconnect the mouse from the host
	2) reconnect the mouse
	3) move the mouse to generate "out of sync" messages.

>Fix:

	In my opinion, when the "out of sync" condition is detected,
	an effort should be made to resync, possibly through
	reinitialization of the device.
	
	The attached diff fixes the problem, at least for my
	"Intellimouse"-type device, by reinitializing the device.
	[is the spltty() needed?]

Index: psm.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/isa/psm.c,v
retrieving revision 1.54
diff -c -r1.54 psm.c
*** psm.c	1998/07/06 16:10:06	1.54
--- psm.c	1998/09/22 18:12:15
***************
*** 1696,1703 ****
  	 */
  	if ((sc->inputbytes == 0) 
  		&& ((c & sc->mode.syncmask[0]) != sc->mode.syncmask[1])) {
              log(LOG_DEBUG, "psmintr: out of sync (%04x != %04x).\n", 
! 		c & sc->mode.syncmask[0], sc->mode.syncmask[1]);
              continue;
  	}
  
--- 1696,1711 ----
  	 */
  	if ((sc->inputbytes == 0) 
  		&& ((c & sc->mode.syncmask[0]) != sc->mode.syncmask[1])) {
+             int s;
              log(LOG_DEBUG, "psmintr: out of sync (%04x != %04x).\n", 
!                 c & sc->mode.syncmask[0], sc->mode.syncmask[1]);
!             s = spltty();
!             if( kbdc_lock(sc->kbdc, TRUE) ) {
!               if (!reinitialize(unit, &sc->mode) || !enable_aux_dev(sc->kbdc))
!                 recover_from_error(sc->kbdc);
!               kbdc_lock(sc->kbdc, FALSE);
!             }
!             splx(s);
              continue;
  	}
  
>Release-Note:
>Audit-Trail:

From: Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
To: tbuswell@mediaone.net
Cc: FreeBSD-gnats-submit@freebsd.org, yokota@zodiac.mech.utsunomiya-u.ac.jp
Subject: Re: misc/8027: PS/2 intellimouse and "psmintr: out of sync" messages 
Date: Wed, 23 Sep 1998 12:37:33 +0900

 >>Number:         8027
 >>Category:       misc
 >>Synopsis:       PS/2 intellimouse and "psmintr: out of sync" messages
 [...]
 >>Release:        FreeBSD 3.0-BETA i386
 >>Environment:
 >
 >	PS/2 "MS Intellimouse" and i386/isa/psm.c 1.54
 >
 >>Description:
 >
 >	No recovery is attempted when the psm driver detects
 >	that it is "out of sync" with the device.  Once this condition is
 >	reached, all subsequent activity with the mouse will generate a
 >	message such as:
 >		/kernel: psmintr: out of sync (00c8 != 0008).
 >	A reboot is required to regain error-free use of the mouse.
 
 The psm driver DOES try to resync with the data stream by skipping
 incoming bytes up to the next valid header byte.
 
 The reason why this fails and reinitialization of the the mouse is
 required in your case is described below.
 
 >>How-To-Repeat:
 >
 >	1) disconnect the mouse from the host
 >	2) reconnect the mouse
 >	3) move the mouse to generate "out of sync" messages.
 
 MS IntelliMouse uses the four-byte data packet to report wheel
 movement rather than the three-byte packet as used by the standard PS/2
 mouse.  However, in order to maintain compatibility with the standard
 PS/2 mouse, it initially uses the three-byte packet and switches to the
 four-byte packet after a specific device initialization procedure is
 carried out by the host computer. The psm driver does this
 initialization when the driver is attached in the boot sequence.
 
 This means, if you disconnect the IntelliMouse from your PC and
 reconnect it while FreeBSD is running, the mouse is put into the
 three-byte mode, but the psm driver has no way of knowing that the
 mouse is disconnected and reconnected and continue to think the mouse
 is sending four-byte packets.  Therefore, it won't be able to resync
 with the mouse; the data format expected by the driver and the packet
 sent by the mouse do not agree.
 
 I do not recommend that you unplug and re-plug PS/2 mice.  The PS/2
 mouse interface circuit is connected to the keyboard controller and is
 very susceptible to electric noise. I know a couple of friends who
 "FRIED" the keyboard controller by accidentally disconnected and
 reconnected the PS/2 mouse.  Unless the manual of your motherboard (or
 laptop computer) clearly states that you can do "hot
 plugging/unplugging" of the PS/2 mouse, you shouldn't do that while
 the power is on.
 
 Laptop computer MAY allow the user to plug/unplug the PS/2 mouse while
 the system is in the sleep/suspend/hibernation state.  In that case,
 you may want to try the kernel options: PSM_HOOKAPM and
 PSM_RESETAFTERSUSPEND.  See the man page for psm(4).
 
 Kazu
 
State-Changed-From-To: open->analyzed 
State-Changed-By: yokota 
State-Changed-When: Tue Sep 22 22:23:25 PDT 1998 
State-Changed-Why:  
The psm driver DOES try to regain sync with data stream. 


Responsible-Changed-From-To: freebsd-bugs->yokota 
Responsible-Changed-By: yokota 
Responsible-Changed-When: Tue Sep 22 22:23:25 PDT 1998 
Responsible-Changed-Why:  
The psm driver is my area. 
State-Changed-From-To: analyzed->closed 
State-Changed-By: yokota 
State-Changed-When: Wed Sep 23 09:31:30 PDT 1998 
State-Changed-Why:  
The PR originator finds the workaround using APM is acceptable. 
>Unformatted:
