Hi,

In my machine, sometimes an odd 5 byte packet is received by pms
in the 6 byte elantech v4 touchpad protocol as documented in [1].
The packet in question in hex notation is 80 80 36 00 00, which
corresponds with a zero movement trackpoint packet missing its first
byte which normally carries the trackpoint button states.

As pms assumes 6 bytes per packet with this protocol, receiving a
5 byte packet causes a desynchronisation between the software and
hardware state.  It is triggered by simultaneous use of any trackpoint
button and multi touch input, especially but not necessarily in
conjunction with trackpoint movement.

The attached patch tests for the specific byte sequence and prepends
a null byte such that it is interpreted as a trackpoint button
release [2].  Running this patch, the desynchronisation issue no
longer occurs, and it seems that no 5 byte packets other then the
kind described above are received.  Since in the protocol as
documented the first byte is never 0x80, I believe that this
workaround has no further side effects.

As to how and why sometimes this odd packet is received I do not
know.  It could be that there is a bug in the touchpad firmware,
that under some circumstances drops the first byte in a packet
if it is null, or perhaps a bug in pms/pckbd that does the same.

Perhaps this information is useful.

Alexander

1.  https://www.kernel.org/doc/html/v4.16/input/devices/elantech.html
2.  When just discarding these 5 byte packets I have occasionally
    observed trackpoint buttons seemingly getting stuck until a new
    mouse button press.

Index: sys/dev/pckbc/pms.c
===================================================================
RCS file: /cvs/src/sys/dev/pckbc/pms.c,v
retrieving revision 1.90
diff -u -p -r1.90 pms.c
--- sys/dev/pckbc/pms.c 20 Sep 2019 21:21:47 -0000      1.90
+++ sys/dev/pckbc/pms.c 19 Jan 2020 12:14:12 -0000
@@ -2382,8 +2382,34 @@ elantech_packet_type(struct elantech_sof
 int
 pms_sync_elantech_v4(struct pms_softc *sc, int data)
 {
+       int i;
+
        if (sc->inputstate == 0)
                return ((data & 0x08) == 0 ? 0 : -1);
+               
+       /*
+        * XXX Sometimes an empty trackpoint packet (80 80 36 00 00)
+        * with missing first byte is received, interpret as trackpoint
+        * button release.
+        */
+       if (sc->inputstate >= 3
+           && (sc->elantech->flags & ELANTECH_F_TRACKPOINT)
+           && sc->packet[0] == 0x80
+           && sc->packet[1] == 0x80
+           && sc->packet[2] == 0x36
+           && sc->packet[3] == 0x00) {
+               if (sc->inputstate == 3)
+                       return (0);
+               else if (sc->packet[4] != 0x00)
+                       return (-1);
+               else {
+                       for (i = 5; i > 0; i--)
+                               sc->packet[i] = sc->packet[i-1];
+                       sc->packet[0] = 0x00;
+                       sc->inputstate++;
+                       return (0);
+               }
+       }
 
        if (sc->inputstate == 3) {
                switch (elantech_packet_type(sc->elantech, data)) {

Packet data sample from a pms patched to print each validated packet:
 44 | 0b 3a 32 0c 32
 44 | 00 2b 32 fc 27
 01 | 80 80 36 00 00
 44 | f6 19 32 f3 1c
 44 | e6 0b 32 e8 16
pms0: not in sync yet, discard input (state = 3, 80 80 36 00 | e8 16)
pms0: not in sync yet, discard input (state = 3, 00 44 b6 fe | e8 16)
pms0: not in sync yet, discard input (state = 3, 32 a8 0e 44 | e8 16)
pms0: not in sync yet, discard input (state = 0, d8 | a8 0e 44 e8 16)
pms0: not in sync yet, discard input (state = 3, f1 32 cb f9 | e8 16)
 44 | 94 b6 32 92 ca
 44 | c9 d8 32 ce de
 44 | cf d1 32 c9 d7
 44 | c2 b4 32 b6 b8
 44 | cc b5 32 cc bd
 44 | da bc 32 e4 cc
 01 | 80 80 36 00 00
 44 | ef cb 32 f1 cf
 44 | fa d2 32 fb d1

dmesg:
OpenBSD 6.6-current (GENERIC.MP) #6: Sat Jan 18 11:56:49 CET 2020
     XXXXXX@XXXXXXX:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 16908791808 (16125MB)
avail mem = 16383868928 (15624MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 3.0 @ 0x7f0d6000 (63 entries)
bios0: vendor LENOVO version "R0SET49W (1.33 )" date 12/27/2019
bios0: LENOVO 20LHCTO1WW
acpi0 at bios0: ACPI 5.0
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP SSDT SSDT TPM2 UEFI SSDT SSDT HPET APIC MCFG ECDT SSDT 
SSDT BOOT BATB SSDT SSDT SSDT LPIT WSMT SSDT SSDT SSI
acpi0: wakeup devices GLAN(S4) XHC_(S3) XDCI(S4) RP01(S4) PXSX(S4) RP02(S4) 
PXSX(S4) PXSX(S4) RP04(S4) PXSX(S4) RP05(S4) PXSX(S4) R]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpihpet0 at acpi0: 23999999 Hz
acpimadt0 at acpi0 addr 0xfee00000: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz, 1587.85 MHz, 06-8e-0a
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PN
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 24MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz, 1439.83 MHz, 06-8e-0a
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PN
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 0, core 1, package 0
cpu2 at mainbus0: apid 4 (application processor)
cpu2: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz, 1252.62 MHz, 06-8e-0a
cpu2: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PN
cpu2: 256KB 64b/line 8-way L2 cache
cpu2: smt 0, core 2, package 0
cpu3 at mainbus0: apid 6 (application processor)
cpu3: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz, 1141.82 MHz, 06-8e-0a
cpu3: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PN
cpu3: 256KB 64b/line 8-way L2 cache
cpu3: smt 0, core 3, package 0
ioapic0 at mainbus0: apid 2 pa 0xfec00000, version 20, 120 pins
acpimcfg0 at acpi0
acpimcfg0: addr 0xf8000000, bus 0-63
acpiec0 at acpi0
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus 2 (RP01)
acpiprt2 at acpi0: bus -1 (RP02)
acpiprt3 at acpi0: bus 4 (RP03)
acpiprt4 at acpi0: bus -1 (RP04)
acpiprt5 at acpi0: bus 5 (RP05)
acpiprt6 at acpi0: bus -1 (RP06)
acpiprt7 at acpi0: bus -1 (RP07)
acpiprt8 at acpi0: bus -1 (RP08)
acpiprt9 at acpi0: bus 6 (RP09)
acpiprt10 at acpi0: bus -1 (RP10)
acpiprt11 at acpi0: bus -1 (RP11)
acpiprt12 at acpi0: bus -1 (RP12)
acpiprt13 at acpi0: bus -1 (RP13)
acpiprt14 at acpi0: bus -1 (RP14)
acpiprt15 at acpi0: bus -1 (RP15)
acpiprt16 at acpi0: bus -1 (RP16)
acpiprt17 at acpi0: bus -1 (RP17)
acpiprt18 at acpi0: bus -1 (RP18)
acpiprt19 at acpi0: bus -1 (RP19)
acpiprt20 at acpi0: bus -1 (RP20)
acpiprt21 at acpi0: bus -1 (RP21)
acpiprt22 at acpi0: bus -1 (RP22)
acpiprt23 at acpi0: bus -1 (RP23)
acpiprt24 at acpi0: bus -1 (RP24)
acpicpu0 at acpi0: C3(200@1034 mwait.1@0x60), C2(200@151 mwait.1@0x33), 
C1(1000@1 mwait.1), PSS
acpicpu1 at acpi0: C3(200@1034 mwait.1@0x60), C2(200@151 mwait.1@0x33), 
C1(1000@1 mwait.1), PSS
acpicpu2 at acpi0: C3(200@1034 mwait.1@0x60), C2(200@151 mwait.1@0x33), 
C1(1000@1 mwait.1), PSS
acpicpu3 at acpi0: C3(200@1034 mwait.1@0x60), C2(200@151 mwait.1@0x33), 
C1(1000@1 mwait.1), PSS
acpipwrres0 at acpi0: PUBS, resource for XHC_
acpipci0 at acpi0 PCI0: 0x00000010 0x00000011 0x00000000
acpithinkpad0 at acpi0: version 2.0
acpiac0 at acpi0: AC unit offline
acpibat0 at acpi0: BAT0 model "01AV433" serial  XXXX type LiP oem "SMP"
"PNP0C60" at acpi0 not configured
"LEN0100" at acpi0 not configured
"INT3403" at acpi0 not configured
"INT3403" at acpi0 not configured
"INT3403" at acpi0 not configured
acpicmos0 at acpi0
"INT0E0C" at acpi0 not configured
acpibtn0 at acpi0: SLPB
acpibtn1 at acpi0: PWRB
"PNP0C14" at acpi0 not configured
"INT33A1" at acpi0 not configured
acpibtn2 at acpi0: LID_
"PNP0C14" at acpi0 not configured
"PNP0C14" at acpi0 not configured
"PNP0C14" at acpi0 not configured
"PNP0C14" at acpi0 not configured
"INT3400" at acpi0 not configured
"STM7304" at acpi0 not configured
"USBC000" at acpi0 not configured
acpivideo0 at acpi0: GFX0
acpivout0 at acpivideo0: DD1F
cpu0: using VERW MDS workaround (except on vmm entry)
cpu0: Enhanced SpeedStep 1587 MHz: speeds: 2001, 2000, 1900, 1800, 1700, 1500, 
1400, 1300, 1200, 1100, 1000, 800, 700, 600, 500, 40z
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 "Intel Core 8G Host" rev 0x08
inteldrm0 at pci0 dev 2 function 0 "Intel UHD Graphics 620" rev 0x07
drm0 at inteldrm0
inteldrm0: msi
"Intel Core 6G Thermal" rev 0x08 at pci0 dev 4 function 0 not configured
"Intel Core GMM" rev 0x00 at pci0 dev 8 function 0 not configured
"Intel 100 Series ISH" rev 0x21 at pci0 dev 19 function 0 not configured
xhci0 at pci0 dev 20 function 0 "Intel 100 Series xHCI" rev 0x21: msi, xHCI 1.0
usb0 at xhci0: USB revision 3.0
uhub0 at usb0 configuration 1 interface 0 "Intel xHCI root hub" rev 3.00/1.00 
addr 1
pchtemp0 at pci0 dev 20 function 2 "Intel 100 Series Thermal" rev 0x21
"Intel 100 Series MEI" rev 0x21 at pci0 dev 22 function 0 not configured
ppb0 at pci0 dev 28 function 0 "Intel 100 Series PCIE" rev 0xf1: msi
pci1 at ppb0 bus 2
rtsx0 at pci1 dev 0 function 0 "Realtek RTS522A Card Reader" rev 0x01: msi
sdmmc0 at rtsx0: 4-bit, dma
ppb1 at pci0 dev 28 function 2 "Intel 100 Series PCIE" rev 0xf1: msi
pci2 at ppb1 bus 4
iwm0 at pci2 dev 0 function 0 "Intel Dual Band Wireless-AC 8265" rev 0x78, msi
ppb2 at pci0 dev 28 function 4 "Intel 100 Series PCIE" rev 0xf1: msi
pci3 at ppb2 bus 5
nvme0 at pci3 dev 0 function 0 "Samsung SM981/PM981 NVMe" rev 0x00: msix, NVMe 
1.2
nvme0: SAMSUNG MZVLB1T0HALR-000L7, firmware 5L2QEXA7, serial XXXXXXXXXXXXXX
scsibus1 at nvme0: 2 targets, initiator 0
sd0 at scsibus1 targ 1 lun 0: <NVMe, SAMSUNG MZVLB1T0, 5L2Q>
sd0: 976762MB, 512 bytes/sector, 2000409264 sectors
ppb3 at pci0 dev 29 function 0 "Intel 100 Series PCIE" rev 0xf1: msi
pci4 at ppb3 bus 6
pcib0 at pci0 dev 31 function 0 "Intel 200 Series LPC" rev 0x21
"Intel 100 Series PMC" rev 0x21 at pci0 dev 31 function 2 not configured
azalia0 at pci0 dev 31 function 3 "Intel 200 Series HD Audio" rev 0x21: msi
azalia0: codecs: Conexant/0x2008, Intel/0x280b, using Conexant/0x2008
audio0 at azalia0
ichiic0 at pci0 dev 31 function 4 "Intel 100 Series SMBus" rev 0x21: apic 2 int 
16
iic0 at ichiic0
em0 at pci0 dev 31 function 6 "Intel I219-V" rev 0x21: msi, address 
9c:5a:44:1f:b7:65
isa0 at pcib0
isadma0 at isa0
pckbc0 at isa0 port 0x60/5 irq 1 irq 12
pckbd0 at pckbc0 (kbd slot)
wskbd0 at pckbd0: console keyboard
pms0 at pckbc0 (aux slot)
wsmouse0 at pms0 mux 0
pms0: Elantech Clickpad, version 4, firmware 0x4d1f00
wsmouse1 at pms0 mux 0
pcppi0 at isa0 port 0x61
spkr0 at pcppi0
vmm0 at mainbus0: VMX/EPT
efifb at mainbus0 not configured
uvideo0 at uhub0 port 8 configuration 1 interface 0 "SunplusIT Inc Integrated 
Camera" rev 2.01/17.91 addr 2
video0 at uvideo0
uhidev0 at uhub0 port 10 configuration 1 interface 0 "Wacom Co.,Ltd. Pen and 
multitouch sensor" rev 2.00/0.02 addr 3
uhidev0: iclass 3/0, 14 report ids
uhid0 at uhidev0 reportid 2: input=0, output=0, feature=1
uhid1 at uhidev0 reportid 3: input=39, output=0, feature=63
uhid2 at uhidev0 reportid 4: input=0, output=0, feature=15
uhid3 at uhidev0 reportid 7: input=0, output=0, feature=255
uhid4 at uhidev0 reportid 8: input=0, output=0, feature=135
uhid5 at uhidev0 reportid 9: input=0, output=0, feature=63
ums0 at uhidev0 reportid 10
ums0: mouse has no X report
ums1 at uhidev0 reportid 12: 1 button, tip
wsmouse2 at ums1 mux 0
uhid6 at uhidev0 reportid 13: input=0, output=0, feature=7
uhid7 at uhidev0 reportid 14: input=0, output=0, feature=2
uhidev1 at uhub0 port 10 configuration 1 interface 1 "Wacom Co.,Ltd. Pen and 
multitouch sensor" rev 2.00/0.02 addr 3
uhidev1: iclass 3/0, 19 report ids
ums2 at uhidev1 reportid 1: 2 buttons
wsmouse3 at ums2 mux 0
uhid8 at uhidev1 reportid 5: input=23, output=0, feature=8
ums3 at uhidev1 reportid 6: 3 buttons, tip, barrel, eraser
wsmouse4 at ums3 mux 0
uhid9 at uhidev1 reportid 11: input=15, output=0, feature=63
uhid10 at uhidev1 reportid 15: input=39, output=0, feature=7
uhid11 at uhidev1 reportid 16: input=20, output=0, feature=63
uhid12 at uhidev1 reportid 17: input=0, output=0, feature=9
uhid13 at uhidev1 reportid 18: input=0, output=0, feature=255
ums4 at uhidev1 reportid 19
ums4: mouse has no X report
vscsi0 at root
scsibus2 at vscsi0: 256 targets
softraid0 at root
scsibus3 at softraid0: 256 targets
sd1 at scsibus3 targ 1 lun 0: <OPENBSD, SR CRYPTO, 006>
sd1: 831837MB, 512 bytes/sector, 1703603696 sectors
root on sd1a (XXXXXXXXXXXXXXXX.a) swap on sd1b dump on sd1b
inteldrm0: 1920x1080, 32bpp
wsdisplay0 at inteldrm0 mux 1: console (std, vt100 emulation), using wskbd0
wsdisplay0: screen 1-5 added (std, vt100 emulation)
iwm0: hw rev 0x230, fw ver 34.0.1, address a0:51:0b:e9:bb:6e

Reply via email to