i8042 access timings
Hi,
Recently there was a patch from Alan regarding access timing violations in i8042. It made me curious as we only wait between accesses to status register but not data register. I peeked into FreeBSD code and they use delays to access both registers and I wonder if that's the piece that makes i8042 mysteriously fail on some boards.
Anyway, regardless of whether access to data register should be done with delay as well there seem to be another timing access violation - in i8042_command we do i8042_wait_read which reads STR and then immediately do i8042_read_status to check AUXDATA bit.
Does the patch below makes any sense?
Signature · 107 lines
Dmitry
===== drivers/input/serio/i8042.c 1.79 vs edited =====
--- 1.79/drivers/input/serio/i8042.c 2005-01-25 00:54:50 -05:00
+++ edited/drivers/input/serio/i8042.c 2005-01-25 02:04:56 -05:00
@@ -137,8 +137,8 @@
static int i8042_wait_read(void)
{
int i = 0;
- while ((~i8042_read_status() & I8042_STR_OBF) && (i < I8042_CTL_TIMEOUT)) {
- udelay(50);
+ while ((~i8042_read_status() & I8042_STR_OBF) && i < I8042_CTL_TIMEOUT) {
+ udelay(I8042_STR_DELAY);
i++;
}
return -(i == I8042_CTL_TIMEOUT);
@@ -147,8 +147,8 @@
static int i8042_wait_write(void)
{
int i = 0;
- while ((i8042_read_status() & I8042_STR_IBF) && (i < I8042_CTL_TIMEOUT)) {
- udelay(50);
+ while ((i8042_read_status() & I8042_STR_IBF) && i < I8042_CTL_TIMEOUT) {
+ udelay(I8042_STR_DELAY);
i++;
}
return -(i == I8042_CTL_TIMEOUT);
@@ -162,17 +162,20 @@
static int i8042_flush(void)
{
unsigned long flags;
- unsigned char data;
+ unsigned char str, data;
int i = 0;
spin_lock_irqsave(&i8042_lock, flags);
- while ((i8042_read_status() & I8042_STR_OBF) && (i++ < I8042_BUFFER_SIZE)) {
- udelay(50);
+ do {
+ str = i8042_read_status();
+ if (~str & I8042_STR_OBF)
+ break;
+ udelay(I8042_DATA_DELAY);
data = i8042_read_data();
- dbg("%02x <- i8042 (flush, %s)", data,
- i8042_read_status() & I8042_STR_AUXDATA ? "aux" : "kbd");
- }
+ dbg("%02x <- i8042 (flush, %s)", data, str & I8042_STR_AUXDATA ? "aux" : "kbd");
+ udelay(I8042_STR_DELAY);
+ } while (i++ < I8042_BUFFER_SIZE);
spin_unlock_irqrestore(&i8042_lock, flags);
@@ -190,6 +193,7 @@
static int i8042_command(unsigned char *param, int command)
{
unsigned long flags;
+ unsigned char str;
int retval = 0, i = 0;
if (i8042_noloop && command == I8042_CMD_AUX_LOOP)
@@ -213,7 +217,10 @@
if (!retval)
for (i = 0; i < ((command >> 8) & 0xf); i++) {
if ((retval = i8042_wait_read())) break;
- if (i8042_read_status() & I8042_STR_AUXDATA)
+ udelay(I8042_STR_DELAY);
+ str = i8042_read_status();
+ udelay(I8042_DATA_DELAY);
+ if (str & I8042_STR_AUXDATA)
param[i] = ~i8042_read_data();
else
param[i] = i8042_read_data();
@@ -424,6 +431,7 @@
ret = 0;
goto out;
}
+ udelay(I8042_DATA_DELAY);
data = i8042_read_data();
spin_unlock_irqrestore(&i8042_lock, flags);
===== drivers/input/serio/i8042.h 1.12 vs edited =====
--- 1.12/drivers/input/serio/i8042.h 2005-01-22 02:22:51 -05:00
+++ edited/drivers/input/serio/i8042.h 2005-01-25 01:44:36 -05:00
@@ -30,12 +30,19 @@
#endif
/*
- * This is in 50us units, the time we wait for the i8042 to react. This
+ * i8042 I/O recovery times
+ */
+#define I8042_STR_DELAY 20
+#define I8042_DATA_DELAY 7
+
+
+/*
+ * This is in 20us units, the time we wait for the i8042 to react. This
* has to be long enough for the i8042 itself to timeout on sending a byte
* to a non-existent mouse.
*/
-#define I8042_CTL_TIMEOUT 10000
+#define I8042_CTL_TIMEOUT 25000
/*
* When the device isn't opened and it's interrupts aren't used, we poll it atQuoted 5 lines · Dmitry Torokhov
Recently there was a patch from Alan regarding access timing violations in i8042. It made me curious as we only wait between accesses to status register but not data register. I peeked into FreeBSD code and they use delays to access both registers and I wonder if that's the piece that makes i8042 mysteriously fail on some boards.
You are following this much more closely than I do, but isn't the usual complaint "2.4 works, 2.6 fails"?
Quoted 4 lines · Dmitry Torokhov
in i8042. It made me curious as we only wait between accesses to status register but not data register. I peeked into FreeBSD code and they use delays to access both registers and I wonder if that's the piece that makes i8042 mysteriously fail on some boards.
Maybe - my own experience is that the last boards I've seen that actually require the delays are the Digital Hinote laptops, so its only stuff only
as far as I can tell
Quoted 7 lines · Dmitry Torokhov
Hi,
Anyway, regardless of whether access to data register should be done with delay as well there seem to be another timing access violation - ini8042_commandwe doi8042_wait_readwhich reads STR and then immediately doi8042_read_statusto check AUXDATA bit.Does the patch below makes any sense?
It looks right to me
Dmitry Torokhov
maintainerQuoted 11 lines · Andries Brouwer
Quoted 5 lines · Dmitry Torokhov
Recently there was a patch from Alan regarding access timing violations in i8042. It made me curious as we only wait between accesses to status register but not data register. I peeked into FreeBSD code and they use delays to access both registers and I wonder if that's the piece that makes i8042 mysteriously fail on some boards.
You are following this much more closely than I do, but isn't the usual complaint "2.4 works, 2.6 fails"?
Quite often it is but too much has changed in input layer to pinpoing exact cause of the failure and I am open to any suggestions. Common problems I see:
1. ACPI sometimes interferes with i8042, especially battery status polling. I am concerned about embedded controller access as well, it looks like it takes sweet time to read/write data to it and ec.c does it with interrupts disabled. I have a patch that enables interrupts but nobody seems to be interested in testing. ACPI interference ranges from losing bytes and bytes arriving with > 0.5 sec delay to "Can't read/write CTR" type of errors. And on the other hand I see some boxces need ACPI or they will not talk to i8042 (although I suspect cold boot will also fix that).
How many 2.4 boxes have ACPI on? I honestly do not know.
2. USB legacy emulation - we used to have PS/2 initialization in GPM/Xfree which means that USB modules (if any) are already loaded and requested handoff so results were very consistent. Now it all depends on who's first. There were couple of PCI quirk patches doing early USB handoff but they have not been applied out of fear breaking some boxes. I wonder if there are concrete examples of such patches breaking boxes, how many and whether DMI decode/workaround will be beneficial for these.
Also, In 2.4 if BIOS detected PS/2 mouse we trusted it and did not do any additional checks, now that i8042 is not x86 specific we do everything by hand and it looks like some hardware is not expecting it...
Still, I wonder if implementing these delays will give IO controller better chances to react to our queries and will get rid of some failures.
Signature · 1 line
Dmitry
Quoted 13 lines · Dmitry Torokhov
Quoted 11 lines · Andries Brouwer
Quoted 5 lines · Dmitry Torokhov
Recently there was a patch from Alan regarding access timing violations in i8042. It made me curious as we only wait between accesses to status register but not data register. I peeked into FreeBSD code and they use delays to access both registers and I wonder if that's the piece that makes i8042 mysteriously fail on some boards.
You are following this much more closely than I do, but isn't the usual complaint "2.4 works, 2.6 fails"?
Quoted 8 lines
Quite often it is but too much has changed in input layer to pinpoing exact cause of the failure and I am open to any suggestions. Common problems I see:
1. ACPI sometimes interferes with i8042, especially battery status polling. I am concerned about embedded controller access as well, it looks like it takes sweet time to read/write data to it and
ec.cdoes it with interrupts disabled.
Furthermore, the EC and the i8042 are often the same chip, resulting in the i8042 not answering when EC is busy. Enabling interrupts won't help.
Quoted 8 lines
2. USB legacy emulation - we used to have PS/2 initialization in GPM/Xfree which means that USB modules (if any) are already loaded and requested handoff so results were very consistent. Now it all depends on who's first. There were couple of PCI quirk patches doing early USB handoff but they have not been applied out of fear breaking some boxes. I wonder if there are concrete examples of such patches breaking boxes, how many and whether DMI decode/workaround will be beneficial for these.
I still hope we could get those in after the handoff code is ironed out. It kept (keeps?) crashing some machines and not using USB is an easy way out of this if you don't have the handoff in the early init code.
Quoted 4 lines
Also, In 2.4 if BIOS detected PS/2 mouse we trusted it and did not do any additional checks, now that i8042 is not x86 specific we do everything by hand and it looks like some hardware is not expecting it...
We may be able to loosen the checks again now that 98% of machines do have the PS/2 mouse port if they have the AT keyboard port.
Quoted 3 lines
Still, I wonder if implementing these delays will give IO controller better chances to react to our queries and will get rid of some failures.
Agreed. I'll check them tomorrow in detail and if I find them OK (I expect to), I'll merge the patch to my tree. Unfortunately I don't expect the delays themselves will fix much.
Signature · 2 lines
Vojtech Pavlik SuSE Labs, SuSE CR
Dmitry Torokhov
maintainerQuoted 18 lines · Vojtech Pavlik
Quoted 17 lines · Dmitry Torokhov
Quoted 11 lines · Andries Brouwer
Quoted 5 lines · Dmitry Torokhov
Recently there was a patch from Alan regarding access timing violations in i8042. It made me curious as we only wait between accesses to status register but not data register. I peeked into FreeBSD code and they use delays to access both registers and I wonder if that's the piece that makes i8042 mysteriously fail on some boards.
You are following this much more closely than I do, but isn't the usual complaint "2.4 works, 2.6 fails"?
Quite often it is but too much has changed in input layer to pinpoing exact cause of the failure and I am open to any suggestions. Common problems I see:
Quoted 7 lines
Quoted 4 lines
1. ACPI sometimes interferes with i8042, especially battery status polling. I am concerned about embedded controller access as well, it looks like it takes sweet time to read/write data to it and
ec.cdoes it with interrupts disabled.Furthermore, the EC and the i8042 are often the same chip, resulting in the i8042 not answering when EC is busy. Enabling interrupts won't help.
It might or it might not, I think it really depends on firmware implementation.
Quoted 8 lines
Quoted 4 lines
Also, In 2.4 if BIOS detected PS/2 mouse we trusted it and did not do any additional checks, now that i8042 is not x86 specific we do everything by hand and it looks like some hardware is not expecting it...
We may be able to loosen the checks again now that 98% of machines do have the PS/2 mouse port if they have the AT keyboard port.
Maybe only for specific machines - the report was about a Toshiba and it looks like they have quite a few problems with their KBCs - bouncing keys, not being able to sustain full Synaptics 480 bytes/s rate...
Signature · 1 line
Dmitry
Quoted 3 lines · Dmitry Torokhov
Still, I wonder if implementing these delays will give IO controller better chances to react to our queries and will get rid of some failures.
My objection is this: by doing this you create myths that may be difficult to dispel later. I recall other situations where there were superfluous restrictions and I had a hard time convincing others of the fact that the tests weren't there for any good reason, that there was no single instance of hardware on earth known to work better with the added restrictions.
So, I would prefer to only insert delays if at least one person reports that things improve if you do so. Or if you can point at data sheets that state that such delays are needed.
Or perhaps if you can show that there were delays in 2.4 absent in 2.6.
Apart from the "not creating myths" reason, there is another:
as we know, the keyboard/mouse system is in a bad state in 2.6. It often happens that 2.6.x works and 2.6.y fails, and we ask a user to try intermediate stages to see what change made a difference. Applying random meaningless patches to the keyboard system creates additional noise and uncertainty.
Andries
Quoted 6 lines · Andries Brouwer
Quoted 3 lines · Dmitry Torokhov
Still, I wonder if implementing these delays will give IO controller better chances to react to our queries and will get rid of some failures.
Quoted 6 lines
My objection is this: by doing this you create myths that may be difficult to dispel later. I recall other situations where there were superfluous restrictions and I had a hard time convincing others of the fact that the tests weren't there for any good reason, that there was no single instance of hardware on earth known to work better with the added restrictions.
Seems like a comment along the lines of "foo hardware doesn't work right unless we delay a bit here" is the obvious solution. Then someone can easily disprove it later.
Lee
Quoted 13 lines · Dmitry Torokhov
Recently there was a patch from Alan regarding access timing violations in i8042. It made me curious as we only wait between accesses to status register but not data register. I peeked into FreeBSD code and they use delays to access both registers and I wonder if that's the piece that makes i8042 mysteriously fail on some boards.
Anyway, regardless of whether access to data register should be done with delay as well there seem to be another timing access violation - in
i8042_commandwe doi8042_wait_readwhich reads STR and then immediately doi8042_read_statusto check AUXDATA bit.Does the patch below makes any sense?
Review
Quoted 6 lines
(quoted diff) +5
-0+ do { + str = i8042_read_status(); + if (~str & I8042_STR_OBF) + break; + udelay(I8042_DATA_DELAY); data = i8042_read_data();
In my opinion, there is no requirement to wait after status read returned success and the actual reading of data. This way we'd have to have the delay in the interrupt routine as well.
Review
Quoted 6 lines
(quoted diff) +3
-3- dbg("%02x <- i8042 (flush, %s)", data, - i8042_read_status() & I8042_STR_AUXDATA ? "aux" : "kbd"); - } + dbg("%02x <- i8042 (flush, %s)", data, str & I8042_STR_AUXDATA ? "aux" : "kbd"); + udelay(I8042_STR_DELAY); + } while (i++ < I8042_BUFFER_SIZE);
So the only problem in the flush routine is the debugging print.
Quoted 11 lines
(quoted diff) +1
-0spin_unlock_irqrestore(&i8042_lock, flags);@@ -190,6 +193,7 @@ static int i8042_command(unsigned char *param, int command) { unsigned long flags; + unsigned char str; int retval = 0, i = 0; if (i8042_noloop && command == I8042_CMD_AUX_LOOP)
Review line 221
Quoted 6 lines
(quoted diff) +2
-1@@ -213,7 +217,10 @@ if (!retval) for (i = 0; i < ((command >> 8) & 0xf); i++) { if ((retval = i8042_wait_read())) break; - if (i8042_read_status() & I8042_STR_AUXDATA) + udelay(I8042_STR_DELAY); + str = i8042_read_status();
[]
Review line 226
Quoted 5 lines
(quoted diff) +2
-0+ udelay(I8042_DATA_DELAY); + if (str & I8042_STR_AUXDATA) param[i] = ~i8042_read_data(); else param[i] = i8042_read_data();
We may as well drop the negation. It's a bad way to signal the data came from the AUX port. Then we don't need the extra status read and can just proceed to read the data, since IMO we don't need to wait inbetween, even according to the IBM spec.
Signature · 2 lines
Vojtech Pavlik SuSE Labs, SuSE CR
Dmitry Torokhov
maintainerQuoted 15 lines · Vojtech Pavlik
Review line 221
Quoted 7 lines · Dmitry Torokhov
(quoted diff) +2
-1@@ -213,7 +217,10 @@ if (!retval) for (i = 0; i < ((command >> 8) & 0xf); i++) { if ((retval = i8042_wait_read())) break; - if (i8042_read_status() & I8042_STR_AUXDATA) + udelay(I8042_STR_DELAY); + str = i8042_read_status();[]
Review line 226
Quoted 5 lines
(quoted diff) +2
-0+ udelay(I8042_DATA_DELAY); + if (str & I8042_STR_AUXDATA) param[i] = ~i8042_read_data(); else param[i] = i8042_read_data();
Quoted 4 lines
We may as well drop the negation. It's a bad way to signal the data came from the AUX port. Then we don't need the extra status read and can just proceed to read the data, since IMO we don't need to wait inbetween, even according to the IBM spec.
Do you remember why it has been done to begin with?
Signature · 1 line
Dmitry
Quoted 16 lines · Dmitry Torokhov
Quoted 15 lines · Vojtech Pavlik
Review line 221
Quoted 7 lines · Dmitry Torokhov
(quoted diff) +2
-1@@ -213,7 +217,10 @@ if (!retval) for (i = 0; i < ((command >> 8) & 0xf); i++) { if ((retval = i8042_wait_read())) break; - if (i8042_read_status() & I8042_STR_AUXDATA) + udelay(I8042_STR_DELAY); + str = i8042_read_status();[]
Quoted 5 lines
(quoted diff) +2
-0+ udelay(I8042_DATA_DELAY); + if (str & I8042_STR_AUXDATA) param[i] = ~i8042_read_data(); else param[i] = i8042_read_data();
Quoted 9 lines
Quoted 4 lines
We may as well drop the negation. It's a bad way to signal the data came from the AUX port. Then we don't need the extra status read and can just proceed to read the data, since IMO we don't need to wait inbetween, even according to the IBM spec.
Do you remember why it has been done to begin with?
Signature · 1 line
Dmitry
The only time you need any delay at all is after you have send the chip a reset command (0xff). Of course if you expect the device to turn ON/OFF something like the old A20 bit, then you need to wait for it to (1) get the command, (2) interpret it (it contains a uP), then read/modify write the appropriate bit. That takes time. However, if you get an interrupt that says "data are available", you read the data with no waiting. It's there and has been for a long time. The status bits will have always been set before the internal status event. There is never any need to wait after that.
Most of the newer emulations are inside Super-IO chips. They don't suffer the port I/O glitches that the old ISA-mapped devices did. You done' even need the "_p" in the port read/writes but we need to maintain compatibility with some old machines so I wouldn't change that.
Cheers,
Dick Johnson
Penguin : Linux version 2.6.10 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.
Dmitry Torokhov
maintainerQuoted 23 lines · linux-os
Quoted 21 lines · Dmitry Torokhov
Quoted 19 lines · Vojtech Pavlik
Review line 221
Quoted 7 lines · Dmitry Torokhov
(quoted diff) +2
-1@@ -213,7 +217,10 @@ if (!retval) for (i = 0; i < ((command >> 8) & 0xf); i++) { if ((retval = i8042_wait_read())) break; - if (i8042_read_status() & I8042_STR_AUXDATA) + udelay(I8042_STR_DELAY); + str = i8042_read_status();[]
Review line 226
Quoted 5 lines
(quoted diff) +2
-0+ udelay(I8042_DATA_DELAY); + if (str & I8042_STR_AUXDATA) param[i] = ~i8042_read_data(); else param[i] = i8042_read_data();We may as well drop the negation. It's a bad way to signal the data came from the AUX port. Then we don't need the extra status read and can just proceed to read the data, since IMO we don't need to wait inbetween, even according to the IBM spec.
Quoted 7 lines
Quoted 4 lines
Do you remember why it has been done to begin with?
--
DmitryThe only time you need any delay at all is after you have send
...
Thank you Richard for this thorough explanation of IO access but I was actually asking why we wanted to invert AUX data.
Signature · 1 line
Dmitry
Quoted 16 lines · Dmitry Torokhov
Quoted 15 lines · Vojtech Pavlik
Review line 221
Quoted 7 lines · Dmitry Torokhov
(quoted diff) +2
-1@@ -213,7 +217,10 @@ if (!retval) for (i = 0; i < ((command >> 8) & 0xf); i++) { if ((retval = i8042_wait_read())) break; - if (i8042_read_status() & I8042_STR_AUXDATA) + udelay(I8042_STR_DELAY); + str = i8042_read_status();[]
Quoted 5 lines
(quoted diff) +2
-0+ udelay(I8042_DATA_DELAY); + if (str & I8042_STR_AUXDATA) param[i] = ~i8042_read_data(); else param[i] = i8042_read_data();
Quoted 6 lines
Quoted 4 lines
We may as well drop the negation. It's a bad way to signal the data came from the AUX port. Then we don't need the extra status read and can just proceed to read the data, since IMO we don't need to wait inbetween, even according to the IBM spec.
Do you remember why it has been done to begin with?
Yes. It's only for the detection of the AUX port. I wanted to know whether the byte we receive in the AUX_LOOP command really comes back through the AUX interface and not through the KBD interface. Since there isn't any other information path for signalling which interface i8042_command() received the byte through, I just negated the value there.
Signature · 2 lines
Vojtech Pavlik SuSE Labs, SuSE CR
Quoted 3 lines · Lee Revell
Seems like a comment along the lines of "foo hardware doesn't work right unless we delay a bit here" is the obvious solution. Then someone can easily disprove it later.
Myths are not really involved here. The IBM PC hardware specifications are fairly well defined and the various bits of "we glued a 2Mhz part onto the bus" stuff is all well documented. Nowdays its more complex because most kbc's aren't standalone low end microcontrollers but are chipset integrated cells or even software SMM emulations.
The real test is to fish out something like an old Digital Hi-note laptop or an early 486 board with seperate kbc and try it.
Alan
Quoted 5 lines · Alan Cox
Quoted 3 lines · Lee Revell
Seems like a comment along the lines of "foo hardware doesn't work right unless we delay a bit here" is the obvious solution. Then someone can easily disprove it later.
Quoted 8 lines
Myths are not really involved here. The IBM PC hardware specifications are fairly well defined and the various bits of "we glued a 2Mhz part onto the bus" stuff is all well documented. Nowdays its more complex because most kbc's aren't standalone low end microcontrollers but are chipset integrated cells or even software SMM emulations.
The real test is to fish out something like an old Digital Hi-note laptop or an early 486 board with seperate kbc and try it.
I'm testing it on an NexGen Nx586 VL-BUS board that has a separate i8042 controller. ;) Remember NexGen?
Signature · 2 lines
Vojtech Pavlik SuSE Labs, SuSE CR
Quoted 8 lines · Alan Cox
Myths are not really involved here. The IBM PC hardware specifications are fairly well defined and the various bits of "we glued a 2Mhz part onto the bus" stuff is all well documented. Nowdays its more complex because most kbc's aren't standalone low end microcontrollers but are chipset integrated cells or even software SMM emulations.
The real test is to fish out something like an old Digital Hi-note laptop or an early 486 board with seperate kbc and try it.
I have a Digital HiNote collecting dust which had this keyboard problem with the RH 6.x 2.2.x boot disk kernels, IIRC. I can test if you like, but I won't be able to get to it until the weekend.
Bill Rugolsky
Quoted 7 lines · Bill Rugolsky Jr.
Quoted 6 lines · Alan Cox
Myths are not really involved here. The IBM PC hardware specifications are fairly well defined and the various bits of "we glued a 2Mhz part onto the bus" stuff is all well documented. Nowdays its more complex because most kbc's aren't standalone low end microcontrollers but are chipset integrated cells or even software SMM emulations.
Quoted 6 lines
Quoted 2 lines
The real test is to fish out something like an old Digital Hi-note laptop or an early 486 board with seperate kbc and try it.
I have a Digital HiNote collecting dust which had this keyboard problem with the RH 6.x 2.2.x boot disk kernels, IIRC. I can test if you like, but I won't be able to get to it until the weekend.
That'd be very nice indeed.
Signature · 2 lines
Vojtech Pavlik SuSE Labs, SuSE CR
Discussion:
Dmitry:
Here are patches with some delays. One never knows - maybe they help someone.
Andries:
Only insert delays in the kernel source when either we know about at least one person who reports that it helps, or about data sheets that specify that the delay is required. Otherwise one creates myths and superstition.
Lee Revell:
Quoted 3 lines
Quoted 3 lines
Seems like a comment along the lines of "foo hardware doesn't work right unless we delay a bit here" is the obvious solution. Then someone can easily disprove it later.
At present the comment would be
"Here is a delay - nobody knows why we are adding it".
Alan:
Quoted 2 lines
Myths are not really involved here. The IBM PC hardware specifications are fairly well defined
If there is a data sheet that requires the delay I am of course happy. If there are test results that show that it helps, I am happy as well. But the given motivation was "you never know - it might help". Bad.
The present situation is that often 2.4 works and 2.6 fails. Not because of some delay that is also absent in 2.4. Often because of all those keyboard commands we send to the hardware. Sometimes also because of ACPI.
Andries
Quoted 20 lines · Andries Brouwer
Discussion:
Dmitry:
Here are patches with some delays. One never knows - maybe they help someone.Andries:
Only insert delays in the kernel source when either we know about at least one person who reports that it helps, or about data sheets that specify that the delay is required. Otherwise one creates myths and superstition.Lee Revell:
Quoted 3 lines
Quoted 3 lines
Seems like a comment along the lines of "foo hardware doesn't work right unless we delay a bit here" is the obvious solution. Then someone can easily disprove it later.
At present the comment would be
"Here is a delay - nobody knows why we are adding it".
Quoted 7 lines
Alan:
Quoted 2 lines
Myths are not really involved here. The IBM PC hardware specifications are fairly well defined
If there is a data sheet that requires the delay I am of course happy. If there are test results that show that it helps, I am happy as well. But the given motivation was "you never know - it might help". Bad.
I fully agree. And I won't merge the delay patch in the current state. It may be useful for testing with systems that are failing, though. On the other hand, I don't believe any of todays systems need any delays, and that most of the problems are caused by the kernel pushing the limits of what SMM emulation can do, where the real hardware wouldn't have problems with it.
Quoted 1 line
The present situation is that often 2.4 works and 2.6 fails.
And the most common case is the SMM code messing up 2.6 detection. 2.4 is lucky by doing the mouse initalization after the USB modules have loaded, not doing any MUX detection at all, etc. It still has problems on systems where there is no AUX yet BIOS reports it and a user opens /dev/psaux.
Quoted 3 lines
Not because of some delay that is also absent in 2.4. Often because of all those keyboard commands we send to the hardware. Sometimes also because of ACPI.
Intel, VIA, nVidia and ALi embedded i8042 cells handle the commands with ease. Extended notebooks i8042's usually handle multiplexing, and as such don't have problems with the commands either. SiS seems not to implement a few commands in some of their chipsets, but issuing the not implemented commands has no adverse effects.
Where computer makers cut corners a LOT is the BIOS. And doing SMM mouse emulation when you have both a real PS/2 mouse and an USB mouse is really tricky, not only because of the data mixing intricacies, but also because of the wide variety of PS/2 and USB hardware. Some USB mice ignore the SetIdle call and this causes the SMM to send an endless stream of simulated PS/2 mouse data for example.
A way to save us most of the headaches in 2.6 would be to always do the usb handoff, unless disabled by a kernel option, by reversing the logic of the "usb-handoff" kernel option.
That way, the playing field for i8042.c would be level with 2.4. Without it, the driver has to avoid much more obstacles.
[Hmm, a thought. Since MUX and SMM emulation are mutually exclusive, maybe the i8042 driver should disable MUX detection unless usb-handoff has been specified ... unfortunately most people will not notice and have problems with their Synaptics touchpads.]
Signature · 2 lines
Vojtech Pavlik SuSE Labs, SuSE CR
Quoted 6 lines · Vojtech Pavlik
Quoted 3 lines · Bill Rugolsky Jr.
I have a Digital HiNote collecting dust which had this keyboard problem with the RH 6.x 2.2.x boot disk kernels, IIRC. I can test if you like, but I won't be able to get to it until the weekend.
That'd be very nice indeed.
Sorry for the long delay in replying; the HiNote needed some effort to get the thing up and running again. [Various bits of hardware are broken; the power switch, floppy, and CD-ROM are busted/flakey.] I've now got Fedora Core 3 running on it. I was pleasantly surprised that the 2.6.9 i83265 PCMCIA module loads, and the internal Xircom CEM56 network/modem works. [Broken with 2.6.10+ though; the fix is probably trivial.]
I wasn't sure exactly what to test. I applied the following patch to 2.6.11-rc3-bk9, and booted with i8042_debug=1. So far, it works as expected, and there is nothing of interest in the kernel log. [Also worked with the FC3 2.6.9 kernel and this patch+DEBUG.]
Now that things are up and running, I will apply any patches that you would like tested.
Bill Rugolsky
drivers/input/serio/i8042.c renamed from drivers/input/serio/i8042.c.udelay-backout +4 -3
@@ -131,9 +131,10 @@ {int i =0 ;while ((~i8042_read_status () &I8042_STR_OBF ) && (i <I8042_CTL_TIMEOUT )) { -udelay (50 ); +udelay (I8042_STR_DELAY ); i++; } +if (i >0 )dbg ("i8042_wait_read: looped %d times" ,i);return -(i ==I8042_CTL_TIMEOUT ); }
@@ -141,9 +142,10 @@ {int i =0 ;while ((i8042_read_status () &I8042_STR_IBF ) && (i <I8042_CTL_TIMEOUT )) { -udelay (50 ); +udelay (I8042_STR_DELAY ); i++; } +if (i >0 )dbg ("i8042_wait_write: looped %d times" ,i);return -(i ==I8042_CTL_TIMEOUT ); }
@@ -161,7 +163,6 @@spin_lock_irqsave (&i8042_lock, flags);while ((i8042_read_status () &I8042_STR_OBF ) && (i++ <I8042_BUFFER_SIZE )) { -udelay (50 ); data =i8042_read_data ();dbg ("%02x <- i8042 (flush, %s)" , data,i8042_read_status () &I8042_STR_AUXDATA ?"aux" :"kbd" );
drivers/input/serio/i8042.h renamed from drivers/input/serio/i8042.h.udelay-backout +8 -2
@@ -30,12 +30,18 @@#endif /* -* This is in 50us units, the time we wait for the i8042 to react. This +* The time (in us) that we wait for the i8042 to react. +*/ + +#define I8042_STR_DELAY 20 + +/* +* This is in units of the time we wait for the i8042 to react. This * has to be long enough for the i8042 itself to timeout on sending a byte * to a non-existent mouse. */ -#define I8042_CTL_TIMEOUT 10000 +#define I8042_CTL_TIMEOUT 25000/* * When the device isn't opened and it's interrupts aren't used, we poll it at
Quoted 7 lines · Bill Rugolsky Jr.
Sorry for the long delay in replying; the HiNote needed some effort to get the thing up and running again. [Various bits of hardware are broken; the power switch, floppy, and CD-ROM are busted/flakey.] I've now got Fedora Core 3 running on it. I was pleasantly surprised that the 2.6.9 i83265 PCMCIA module loads, and the internal Xircom CEM56 network/modem works. [Broken with 2.6.10+ though; the fix is probably trivial.]
Quoted 7 lines
I wasn't sure exactly what to test. I applied the following patch to 2.6.11-rc3-bk9, and booted with i8042_debug=1. So far, it works as expected, and there is nothing of interest in the kernel log. [Also worked with the FC3 2.6.9 kernel and this patch+DEBUG.]
Now that things are up and running, I will apply any patches that you would like tested.
And I suppose it was running just fine without the patch as well?
The question was whether the patch helps, or whether it is not needed.
Signature · 2 lines
Vojtech Pavlik SuSE Labs, SuSE CR
Quoted 1 line · Vojtech Pavlik
And I suppose it was running just fine without the patch as well?
Correct.
Quoted 1 line
The question was whether the patch helps, or whether it is not needed.
If you look again at the patch I posted, it only borrowed a few lines of the patch from Dmitry that started this thread; I eliminated Alan's recent udelay(50) addition, reduced the loop delay, and added debug printks to the *_wait routines to determine whether the loop is ever taken.
At least so far, those debugging statements have produced no output. I'll use the machine a bit and report back if I trigger anything.
Regards,
Bill Rugolsky