diff options
author | Hans de Goede <j.w.r.degoede@hhs.nl> | 2006-08-25 04:24:20 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-08-26 16:05:19 -0400 |
commit | faf9b616325430422fa13fead88ca7843eb249d6 (patch) | |
tree | 7272b6ac857c5ec400ea61a65f141927de3712af /drivers/hwmon/abituguru.c | |
parent | 4801bc25f37a969ea773c24d12fd4738541848a1 (diff) |
[PATCH] hwmon: abituguru timeout fixes
This patch contains 2 sets of fixes for the abituguru:
1) Much improved timeout handling, drasticly reducing the amount of
timeout errors on some motherboards
2) Fix the exit paths in the bank1 sensor type detect code to always
restore the original settings even on an error. Without this our
special test settings could remain seriously confusing the system
BIOS's setup menu.
Both are very much related and are must haves, to avoid messing up the
uguru CMOS settings.
Detailed changes:
- Much improved timeout / wait for status handling. Many thanks to Sunil
Kumar, for all his testing, ideas and patches! The code now first busy
waits, polling the uguru for the expected status as this usually
succeeds pretty quickly (within 90 reads). To avoid unnecessary CPU burn
in timeout conditions, the amount of busy waiting has been halved from
previous versions (120 tries instead of 250). This is not a problem,
because this version goes to sleep after 120 attemps for 1 jiffy and
then tries again, it does this sleep and try again 5 times before
finally giving up. This (almost?) completly removes the timeout errors
some people have seen regulary. Apparently some older uguru versions
sometimes are distracted for a (relatively) long time. This solves this.
- These timeout errors not only occur in the sending address part of
reading the uguru but also in the wait for read state, so errors in
this state are now handled as retryable just like send address state
errors and are only logged and reported to userspace if 3 executive
tries fail.
- Fix a very nasty bug in the bank1 sensor type detection code, where it
would not restore the original settings in any of the error paths!
- Since not successfully restoring the original settings can seriously
confuse the system BIOS (hang when entering the relevant setup menu),
we now try restoring them 3 times before giving up.
Signed-off-by: Hans de Goede <j.w.r.degoede@hhs.nl>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/hwmon/abituguru.c')
-rw-r--r-- | drivers/hwmon/abituguru.c | 99 |
1 files changed, 61 insertions, 38 deletions
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c index cc15c4f2e9ec..35ad1b032726 100644 --- a/drivers/hwmon/abituguru.c +++ b/drivers/hwmon/abituguru.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/jiffies.h> | 26 | #include <linux/jiffies.h> |
27 | #include <linux/mutex.h> | 27 | #include <linux/mutex.h> |
28 | #include <linux/err.h> | 28 | #include <linux/err.h> |
29 | #include <linux/delay.h> | ||
29 | #include <linux/platform_device.h> | 30 | #include <linux/platform_device.h> |
30 | #include <linux/hwmon.h> | 31 | #include <linux/hwmon.h> |
31 | #include <linux/hwmon-sysfs.h> | 32 | #include <linux/hwmon-sysfs.h> |
@@ -64,17 +65,17 @@ | |||
64 | #define ABIT_UGURU_IN_SENSOR 0 | 65 | #define ABIT_UGURU_IN_SENSOR 0 |
65 | #define ABIT_UGURU_TEMP_SENSOR 1 | 66 | #define ABIT_UGURU_TEMP_SENSOR 1 |
66 | #define ABIT_UGURU_NC 2 | 67 | #define ABIT_UGURU_NC 2 |
67 | /* Timeouts / Retries, if these turn out to need a lot of fiddling we could | 68 | /* In many cases we need to wait for the uGuru to reach a certain status, most |
68 | convert them to params. */ | 69 | of the time it will reach this status within 30 - 90 ISA reads, and thus we |
69 | /* 250 was determined by trial and error, 200 works most of the time, but not | 70 | can best busy wait. This define gives the total amount of reads to try. */ |
70 | always. I assume this is cpu-speed independent, since the ISA-bus and not | 71 | #define ABIT_UGURU_WAIT_TIMEOUT 125 |
71 | the CPU should be the bottleneck. Note that 250 sometimes is still not | 72 | /* However sometimes older versions of the uGuru seem to be distracted and they |
72 | enough (only reported on AN7 mb) this is handled by a higher layer. */ | 73 | do not respond for a long time. To handle this we sleep before each of the |
73 | #define ABIT_UGURU_WAIT_TIMEOUT 250 | 74 | last ABIT_UGURU_WAIT_TIMEOUT_SLEEP tries. */ |
75 | #define ABIT_UGURU_WAIT_TIMEOUT_SLEEP 5 | ||
74 | /* Normally all expected status in abituguru_ready, are reported after the | 76 | /* Normally all expected status in abituguru_ready, are reported after the |
75 | first read, but sometimes not and we need to poll, 5 polls was not enough | 77 | first read, but sometimes not and we need to poll. */ |
76 | 50 sofar is. */ | 78 | #define ABIT_UGURU_READY_TIMEOUT 5 |
77 | #define ABIT_UGURU_READY_TIMEOUT 50 | ||
78 | /* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */ | 79 | /* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */ |
79 | #define ABIT_UGURU_MAX_RETRIES 3 | 80 | #define ABIT_UGURU_MAX_RETRIES 3 |
80 | #define ABIT_UGURU_RETRY_DELAY (HZ/5) | 81 | #define ABIT_UGURU_RETRY_DELAY (HZ/5) |
@@ -226,6 +227,10 @@ static int abituguru_wait(struct abituguru_data *data, u8 state) | |||
226 | timeout--; | 227 | timeout--; |
227 | if (timeout == 0) | 228 | if (timeout == 0) |
228 | return -EBUSY; | 229 | return -EBUSY; |
230 | /* sleep a bit before our last few tries, see the comment on | ||
231 | this where ABIT_UGURU_WAIT_TIMEOUT_SLEEP is defined. */ | ||
232 | if (timeout <= ABIT_UGURU_WAIT_TIMEOUT_SLEEP) | ||
233 | msleep(0); | ||
229 | } | 234 | } |
230 | return 0; | 235 | return 0; |
231 | } | 236 | } |
@@ -256,6 +261,7 @@ static int abituguru_ready(struct abituguru_data *data) | |||
256 | "CMD reg does not hold 0xAC after ready command\n"); | 261 | "CMD reg does not hold 0xAC after ready command\n"); |
257 | return -EIO; | 262 | return -EIO; |
258 | } | 263 | } |
264 | msleep(0); | ||
259 | } | 265 | } |
260 | 266 | ||
261 | /* After this the ABIT_UGURU_DATA port should contain | 267 | /* After this the ABIT_UGURU_DATA port should contain |
@@ -268,6 +274,7 @@ static int abituguru_ready(struct abituguru_data *data) | |||
268 | "state != more input after ready command\n"); | 274 | "state != more input after ready command\n"); |
269 | return -EIO; | 275 | return -EIO; |
270 | } | 276 | } |
277 | msleep(0); | ||
271 | } | 278 | } |
272 | 279 | ||
273 | data->uguru_ready = 1; | 280 | data->uguru_ready = 1; |
@@ -331,7 +338,8 @@ static int abituguru_read(struct abituguru_data *data, | |||
331 | /* And read the data */ | 338 | /* And read the data */ |
332 | for (i = 0; i < count; i++) { | 339 | for (i = 0; i < count; i++) { |
333 | if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { | 340 | if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { |
334 | ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for " | 341 | ABIT_UGURU_DEBUG(retries ? 1 : 3, |
342 | "timeout exceeded waiting for " | ||
335 | "read state (bank: %d, sensor: %d)\n", | 343 | "read state (bank: %d, sensor: %d)\n", |
336 | (int)bank_addr, (int)sensor_addr); | 344 | (int)bank_addr, (int)sensor_addr); |
337 | break; | 345 | break; |
@@ -350,7 +358,9 @@ static int abituguru_read(struct abituguru_data *data, | |||
350 | static int abituguru_write(struct abituguru_data *data, | 358 | static int abituguru_write(struct abituguru_data *data, |
351 | u8 bank_addr, u8 sensor_addr, u8 *buf, int count) | 359 | u8 bank_addr, u8 sensor_addr, u8 *buf, int count) |
352 | { | 360 | { |
353 | int i; | 361 | /* We use the ready timeout as we have to wait for 0xAC just like the |
362 | ready function */ | ||
363 | int i, timeout = ABIT_UGURU_READY_TIMEOUT; | ||
354 | 364 | ||
355 | /* Send the address */ | 365 | /* Send the address */ |
356 | i = abituguru_send_address(data, bank_addr, sensor_addr, | 366 | i = abituguru_send_address(data, bank_addr, sensor_addr, |
@@ -370,7 +380,8 @@ static int abituguru_write(struct abituguru_data *data, | |||
370 | } | 380 | } |
371 | 381 | ||
372 | /* Now we need to wait till the chip is ready to be read again, | 382 | /* Now we need to wait till the chip is ready to be read again, |
373 | don't ask why */ | 383 | so that we can read 0xAC as confirmation that our write has |
384 | succeeded. */ | ||
374 | if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { | 385 | if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) { |
375 | ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state " | 386 | ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state " |
376 | "after write (bank: %d, sensor: %d)\n", (int)bank_addr, | 387 | "after write (bank: %d, sensor: %d)\n", (int)bank_addr, |
@@ -379,11 +390,15 @@ static int abituguru_write(struct abituguru_data *data, | |||
379 | } | 390 | } |
380 | 391 | ||
381 | /* Cmd port MUST be read now and should contain 0xAC */ | 392 | /* Cmd port MUST be read now and should contain 0xAC */ |
382 | if (inb_p(data->addr + ABIT_UGURU_CMD) != 0xAC) { | 393 | while (inb_p(data->addr + ABIT_UGURU_CMD) != 0xAC) { |
383 | ABIT_UGURU_DEBUG(1, "CMD reg does not hold 0xAC after write " | 394 | timeout--; |
384 | "(bank: %d, sensor: %d)\n", (int)bank_addr, | 395 | if (timeout == 0) { |
385 | (int)sensor_addr); | 396 | ABIT_UGURU_DEBUG(1, "CMD reg does not hold 0xAC after " |
386 | return -EIO; | 397 | "write (bank: %d, sensor: %d)\n", |
398 | (int)bank_addr, (int)sensor_addr); | ||
399 | return -EIO; | ||
400 | } | ||
401 | msleep(0); | ||
387 | } | 402 | } |
388 | 403 | ||
389 | /* Last put the chip back in ready state */ | 404 | /* Last put the chip back in ready state */ |
@@ -403,7 +418,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
403 | u8 sensor_addr) | 418 | u8 sensor_addr) |
404 | { | 419 | { |
405 | u8 val, buf[3]; | 420 | u8 val, buf[3]; |
406 | int ret = ABIT_UGURU_NC; | 421 | int i, ret = -ENODEV; /* error is the most common used retval :| */ |
407 | 422 | ||
408 | /* If overriden by the user return the user selected type */ | 423 | /* If overriden by the user return the user selected type */ |
409 | if (bank1_types[sensor_addr] >= ABIT_UGURU_IN_SENSOR && | 424 | if (bank1_types[sensor_addr] >= ABIT_UGURU_IN_SENSOR && |
@@ -439,7 +454,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
439 | buf[2] = 250; | 454 | buf[2] = 250; |
440 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, | 455 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, |
441 | buf, 3) != 3) | 456 | buf, 3) != 3) |
442 | return -ENODEV; | 457 | goto abituguru_detect_bank1_sensor_type_exit; |
443 | /* Now we need 20 ms to give the uguru time to read the sensors | 458 | /* Now we need 20 ms to give the uguru time to read the sensors |
444 | and raise a voltage alarm */ | 459 | and raise a voltage alarm */ |
445 | set_current_state(TASK_UNINTERRUPTIBLE); | 460 | set_current_state(TASK_UNINTERRUPTIBLE); |
@@ -447,21 +462,16 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
447 | /* Check for alarm and check the alarm is a volt low alarm. */ | 462 | /* Check for alarm and check the alarm is a volt low alarm. */ |
448 | if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3, | 463 | if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3, |
449 | ABIT_UGURU_MAX_RETRIES) != 3) | 464 | ABIT_UGURU_MAX_RETRIES) != 3) |
450 | return -ENODEV; | 465 | goto abituguru_detect_bank1_sensor_type_exit; |
451 | if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) { | 466 | if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) { |
452 | if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, | 467 | if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, |
453 | sensor_addr, buf, 3, | 468 | sensor_addr, buf, 3, |
454 | ABIT_UGURU_MAX_RETRIES) != 3) | 469 | ABIT_UGURU_MAX_RETRIES) != 3) |
455 | return -ENODEV; | 470 | goto abituguru_detect_bank1_sensor_type_exit; |
456 | if (buf[0] & ABIT_UGURU_VOLT_LOW_ALARM_FLAG) { | 471 | if (buf[0] & ABIT_UGURU_VOLT_LOW_ALARM_FLAG) { |
457 | /* Restore original settings */ | ||
458 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, | ||
459 | sensor_addr, | ||
460 | data->bank1_settings[sensor_addr], | ||
461 | 3) != 3) | ||
462 | return -ENODEV; | ||
463 | ABIT_UGURU_DEBUG(2, " found volt sensor\n"); | 472 | ABIT_UGURU_DEBUG(2, " found volt sensor\n"); |
464 | return ABIT_UGURU_IN_SENSOR; | 473 | ret = ABIT_UGURU_IN_SENSOR; |
474 | goto abituguru_detect_bank1_sensor_type_exit; | ||
465 | } else | 475 | } else |
466 | ABIT_UGURU_DEBUG(2, " alarm raised during volt " | 476 | ABIT_UGURU_DEBUG(2, " alarm raised during volt " |
467 | "sensor test, but volt low flag not set\n"); | 477 | "sensor test, but volt low flag not set\n"); |
@@ -477,7 +487,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
477 | buf[2] = 10; | 487 | buf[2] = 10; |
478 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, | 488 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, |
479 | buf, 3) != 3) | 489 | buf, 3) != 3) |
480 | return -ENODEV; | 490 | goto abituguru_detect_bank1_sensor_type_exit; |
481 | /* Now we need 50 ms to give the uguru time to read the sensors | 491 | /* Now we need 50 ms to give the uguru time to read the sensors |
482 | and raise a temp alarm */ | 492 | and raise a temp alarm */ |
483 | set_current_state(TASK_UNINTERRUPTIBLE); | 493 | set_current_state(TASK_UNINTERRUPTIBLE); |
@@ -485,15 +495,16 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
485 | /* Check for alarm and check the alarm is a temp high alarm. */ | 495 | /* Check for alarm and check the alarm is a temp high alarm. */ |
486 | if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3, | 496 | if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3, |
487 | ABIT_UGURU_MAX_RETRIES) != 3) | 497 | ABIT_UGURU_MAX_RETRIES) != 3) |
488 | return -ENODEV; | 498 | goto abituguru_detect_bank1_sensor_type_exit; |
489 | if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) { | 499 | if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) { |
490 | if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, | 500 | if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, |
491 | sensor_addr, buf, 3, | 501 | sensor_addr, buf, 3, |
492 | ABIT_UGURU_MAX_RETRIES) != 3) | 502 | ABIT_UGURU_MAX_RETRIES) != 3) |
493 | return -ENODEV; | 503 | goto abituguru_detect_bank1_sensor_type_exit; |
494 | if (buf[0] & ABIT_UGURU_TEMP_HIGH_ALARM_FLAG) { | 504 | if (buf[0] & ABIT_UGURU_TEMP_HIGH_ALARM_FLAG) { |
495 | ret = ABIT_UGURU_TEMP_SENSOR; | ||
496 | ABIT_UGURU_DEBUG(2, " found temp sensor\n"); | 505 | ABIT_UGURU_DEBUG(2, " found temp sensor\n"); |
506 | ret = ABIT_UGURU_TEMP_SENSOR; | ||
507 | goto abituguru_detect_bank1_sensor_type_exit; | ||
497 | } else | 508 | } else |
498 | ABIT_UGURU_DEBUG(2, " alarm raised during temp " | 509 | ABIT_UGURU_DEBUG(2, " alarm raised during temp " |
499 | "sensor test, but temp high flag not set\n"); | 510 | "sensor test, but temp high flag not set\n"); |
@@ -501,11 +512,23 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
501 | ABIT_UGURU_DEBUG(2, " alarm not raised during temp sensor " | 512 | ABIT_UGURU_DEBUG(2, " alarm not raised during temp sensor " |
502 | "test\n"); | 513 | "test\n"); |
503 | 514 | ||
504 | /* Restore original settings */ | 515 | ret = ABIT_UGURU_NC; |
505 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, | 516 | abituguru_detect_bank1_sensor_type_exit: |
506 | data->bank1_settings[sensor_addr], 3) != 3) | 517 | /* Restore original settings, failing here is really BAD, it has been |
518 | reported that some BIOS-es hang when entering the uGuru menu with | ||
519 | invalid settings present in the uGuru, so we try this 3 times. */ | ||
520 | for (i = 0; i < 3; i++) | ||
521 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, | ||
522 | sensor_addr, data->bank1_settings[sensor_addr], | ||
523 | 3) == 3) | ||
524 | break; | ||
525 | if (i == 3) { | ||
526 | printk(KERN_ERR ABIT_UGURU_NAME | ||
527 | ": Fatal error could not restore original settings. " | ||
528 | "This should never happen please report this to the " | ||
529 | "abituguru maintainer (see MAINTAINERS)\n"); | ||
507 | return -ENODEV; | 530 | return -ENODEV; |
508 | 531 | } | |
509 | return ret; | 532 | return ret; |
510 | } | 533 | } |
511 | 534 | ||
@@ -1305,7 +1328,7 @@ static struct abituguru_data *abituguru_update_device(struct device *dev) | |||
1305 | data->update_timeouts = 0; | 1328 | data->update_timeouts = 0; |
1306 | LEAVE_UPDATE: | 1329 | LEAVE_UPDATE: |
1307 | /* handle timeout condition */ | 1330 | /* handle timeout condition */ |
1308 | if (err == -EBUSY) { | 1331 | if (!success && (err == -EBUSY || err >= 0)) { |
1309 | /* No overflow please */ | 1332 | /* No overflow please */ |
1310 | if (data->update_timeouts < 255u) | 1333 | if (data->update_timeouts < 255u) |
1311 | data->update_timeouts++; | 1334 | data->update_timeouts++; |