Commit Graph

88 Commits

Author SHA1 Message Date
bouyer 9b45dfba17 Accept any 'sc' value when probing atapi drives: with some drives, or
controllers, or combination of both, the value can be different from the
expected one after a reset.
2000-05-12 15:00:33 +00:00
mrg 952f1cf1d0 avoid using uninitalised variables inside WDCDEBUG. 2000-04-05 06:27:36 +00:00
bouyer 77f1e5eb02 Add checks to detect busy-waits, conditionnal on new debug flag
DEBUG_DELAY (0x40). This will print how much time we did loop in wdcwait(),
if we had to read registers more than one time.
2000-04-04 12:43:13 +00:00
bouyer fcb3e9ddac Better fix to previous: delay(100) before the IDENTIFY, and if it fails
delay(1000000) and retry. The 1s delay is needed for some special case only,
no need to hang the machine for that long everytime (especially for PCMCIA).
2000-04-04 09:25:51 +00:00
bouyer b2cd1f029a Bump delay() from 100 to 1000000 before attempting a IDENTIFY just after a
reset - solves a problem reported by cpg@aladdin.de.
2000-04-01 14:50:32 +00:00
bouyer 26f6c9a9cf - DMA code cleanup: pciide_dma_finish() doesn't stop/unload the current DMA op
if an IRQ was not detected, unless the force flag was given. Use this to
  detect if the IRQ was for us (closer to shared IRQ for controllers which
  don't have their own IRQ handler in pciide.c) and to poll for DMA xfer.
  Also makes the timeout recovery code simpler.
- ATAPI cleanup: don't call controller-specific functions from atapiconf.c
  (wdc_*), so that it's possible to attach an atapibus to something else
  than a wdc/pciide (Hi Lennart :).
  Overload struct scsi_adapter with struct atapi_adapter, defined
  as struct scsi_adapter + atapi-specific callbacks. scsipi_link still points
  to an scsi_adapter, atapi code casts it to atapi_adapter if needed.
  Move atapi_softc to atapiconf.h so that it can be used by the underlying
  controller code (e.g. atapi_wdc.c).
  Add an atapi-specific callback *atapi_probedev(), which probe a drive
  in a controller-specific way, allocate the sc_link and fills in the
  ataparams if needed. It then calls atapi_probedev() (from atapiconf.c)
  to do the generic initialisations and attach the device.
- While I'm there merge and centralise the state definitions in atavar.h.
  It should now be possible to use a common ata/atapi routine to set the
  drive's modes (will do later).
2000-04-01 14:32:22 +00:00
simonb 8a447f3757 Remove reduncdant decl of wdc_kill_pending - it's in <dev/ic/wdcvar.h>. 2000-03-29 03:56:53 +00:00
soren 2c88f0bb92 s/32-bits/32-bit/ (Hi Al!) 2000-03-23 15:04:49 +00:00
thorpej fc96443d15 New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
  resource allocation.
- Insertion and removal of callouts is constant time, important as
  this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
2000-03-23 07:01:25 +00:00
enami 83446dedc1 - Test the generic device active flag instead of home grown one.
- Test also it in wdcintr.
2000-03-20 22:53:36 +00:00
bouyer 085f44145c - Be more strict in status check before sending a command (make sure
DRQ is not asserted). Closes kern/9346.
- Change the "fake identify before the real one" by a delay(). The real cause
  of the problem is that the drive is unresponsive just after a reset.
  The real problem (and the solution) showed up after the first change.
2000-02-14 12:37:35 +00:00
bouyer 638e1a6958 Improve the downgrade logic:
- If UDMA 2 is failing try UDMA 1 first, it helps in some cases
- downgrade if we get an error in the first 4000 xfers, or if we get
  4 errors in 4000 xfers if the first 4000 went without troubles.

While I'm there commit a local change I have since some time to get my CD
probed: issue a "blanck" IDENTIFY before the one used to detect slave ghosts,
with my drive the first IDENTIFY following a controller reset fails with an
aborted command ...
2000-01-17 00:01:00 +00:00
bouyer 7bd006b847 Improve a few debug messages. 1999-11-28 20:04:22 +00:00
bouyer 9d3c1407f7 If IRQ was not for us, add back WDCF_IRQ_WAIT to the flags, so that
the next IRQ (real or timeout) will be handled.
Fixes the 'missing untimeout' problem reported by a few peoples, and
kern/8639.
1999-10-21 14:37:58 +00:00
enami a2369d8e97 Cancel active transfers on aic/wdc detach.
Also makes LS-120 drive works for me again.
1999-10-20 15:22:24 +00:00
enami 67e874d814 Allow to detach wdc, atapibus, wd and cd. 1999-09-23 11:04:29 +00:00
bouyer 7c1c212662 If we are using UDMA mode > 2 and get a DMA error, downgrade to UDMA mode 2
first: maybe we incorrectly guessed the cable type.
1999-08-30 12:58:58 +00:00
bouyer d6c3ef56b4 Guard pool_get()/pool_put() with splbio()/splx(). Fix kern/8245. 1999-08-25 17:08:20 +00:00
bouyer 5885dbb878 - use pool(9) for wdc_xfer, instead of managing a free list.
- fix printing of Ultra-DMA modes (shows up when the drive supports highther
  modes than the controller).
- Don't use C_NEEDDONE anymore. We were setting this flag in a possibly
  freed wdc_xfer (this didn't create problems, as it was free'd in the POLL
  case only, while IRQs are blocked, but it's not good practice anyway
  and pool(9) complains about it ;)
1999-08-09 09:55:18 +00:00
bouyer fae9929734 - Add some debug printf (WDCPROBE) in _wdcreset_wait(), I've needed these
2 times in the past
- Set up timeout per xfer instead of per interrupt. This helps with
  PIO transfer (we would call timeout()/untimout() several times for a
  transfer).
- If we missed an interrupt for a PIO transfer, reset and restart it
  immedialy, don't try to recover and continue. If we missed an interrupt we
  may have lost a read/write cycle on the IDE bus. If this happens 1) we
  corrupt data and 2) we enter an interrupt loop at the end of the xfer, as
  the drive has some more data to read/write, but the host thinks the xfer is
  done.
This last change fix the (or at last some of the) 'lookup after lost interrupt'
some peoples have been experiencing.
1999-08-06 12:00:23 +00:00
bouyer 2917356cae Guard tsleep() with a while (!(wdc_c->flags & AT_DONE)) {}, as suggested by
Constantine Sapuntzakis confirmed by Bill Sommerfeld. Although nothing is
supposed to call wakeup on this without setting AT_DONE, it's good practice to
do it this way (the process may be waken up by a setrunnable() call).
1999-07-30 14:59:10 +00:00
bouyer 4fd8325ec6 Resurect the old register read/write test for non-ATA/ATAPI drives, to avoid
false matches on controllers which properly respond to a WDCC_RECAL command.
Should close PR port-i386/7702 (the author tested this patch, and said it
solves his problem).
1999-06-23 19:00:17 +00:00
bouyer 503de51fdd Fix probe code for IDE devices:
- Don't rely on ATA signature: some ide controllers seems to not transmit it
  properly (SIMIDE on arm32 machines). Instead, when we guess a drive is here
  after reset, just mark it as ATA and OLD is it's not ATAPI.
- at attach time, use IDENTIFY to eliminate ghost from the probe. If the
  drive had the old flag and IDENTIFY failed, issue a WDCC_RECAL command
  to detect a pre-ATA disk. If IDENTIFY succeded, remove the OLD flag,
  it's obviously not a pre-ATA disk.
- add a new controller flag, WDC_CAPABILITY_PREATA, used to shorcut parts
  of the probe (not necessary, but makes the probe/attach faster). This is
  only set by the ISA front-end, all other controllers supported can't have
  pre-ATA drives attached.
The mechanism used are more or less the same as before, they have just been
reordered. Should solve port-arm32/7324 (waiting for feedback).
1999-04-11 20:50:28 +00:00
bouyer b43b844f6f - change the interrupt routines to take a 3rd arguments, set to 1 if we
are called from the interrupt or timeout handler, 0 otherwise.
- use this to know if we can busy-wait for wait_for_unbusy or wait_for_ready
This fixes a bug where CDs withot the DRQ_INTR capability would not busy-wait
for the CMDOUT phase.
While I'm there change 2 delay() to DELAY() for consistency, and
garbage-collect some old code from wdcintr() which has been ifdef'd out
for some time now.
1999-04-01 21:46:28 +00:00
bouyer bb47e5aecf Increase some DELAY(), this seems required on some hardware (I'm not sure if
the hardware is at fault, or if DELAY(1) waits for less than 1us).
Improve debuging messages for wdcreset_wait().
1999-03-31 11:18:31 +00:00
bouyer ad69d389ab Remove the hack to attach devices responding with ATA signatures as atapi if
IDENTIFY said so: it doesn't help for the drive this was supposed helping,
and seems to break another device.
In interrupt routine, don't return 0 if we are polling: this should fix the
"panic: wdc_exec_command: polled command not done" some people reported
(kern/7269).
1999-03-29 08:32:02 +00:00
bouyer 1ff88ee466 Avoid busy-waiting when possible if we are not polling (real IRQ or timeout
callback). Shared PCI IRQ should now work (but still untested).
1999-03-25 16:17:36 +00:00
bouyer a6365676fa Add a new disk flag: DRIVE_OLD for pre-ATA disks. probe routine will now set
DRIVE_OLD, DRIVE_ATA or DRIVE_ATAPI based on register signatures.
The attach routine will issue a IDENTIFY command for ATA/ATAPI disk,
to detect flase matches by the probe routine.
probe/attach should now be fully compliant with ata-4/ata-5. As a side
effect, ATAPI drives which improperly use ATA register signatures should now
be attached as ATAPI.
1999-03-10 13:11:43 +00:00
bouyer ba74f49e60 Keep track of CRC errors in Ultra-DMA mode. If we noticed a CRC error and we
need to downgrade, downgrade to PIO, as it has been shown if we got CRC errors
in Ultra-DMA mode, we will have silent data corruption in multiword DMA mode
(isn't IDE wonderfull ? :).
Set timeout to 1s for "normal" ata I/O, to minimise the effects of missed
interrupts.
1999-03-07 14:02:53 +00:00
abs b86f85e1cc wdcwait is called initially without any device on my thinkpad.
This breaks the first WDCDEBUG_PRINT. Handle this case.
1999-02-21 02:07:52 +00:00
hubertf 99626f33a3 Only #define WDCDEBUG if it isn't already defined (e.g. by some options
in the kernel config file).
1999-02-20 23:47:52 +00:00
bouyer 7e5acb7709 Don't print an extra newline if the controller doesn't support 32 bits access.
Pointed out by Dave Huang.
1999-02-18 14:45:31 +00:00
bouyer d683e62685 Be less strict on ATAPI signature, at last one CD puts 0x00 in sc instead
of 0x01.
1999-02-15 18:47:59 +00:00
bouyer 1e0e78854a There's no ATA draft where it is required for the drive to set DRDY | DSC when
the disk is ready to transfer data, and in ATA-5 the DSC has been obsoleted.
So only wait for DRQ to transfer data. This can be made conditional on the
ATA version if it's proven to break with some drives (worked with all the
drives I have access to).
While I'm there correct a few typos.
1999-02-08 15:22:28 +00:00
bouyer a1471db64a move wd.c:print_wderror() to ata.c:ata_perror().
In wdc_probe_caps() add code to guess the ATA revision supported (if
ATA4 if Ultra-DMA, ATA2 if PIO mode > 2). We can't rely on param.atap_ata_major
here, at last one Ultra-DMA drive claims to support only ATA-3.
Use the ATA version in ata_perror(), and to try a flush cache command
in a shutdown hook for IDE drives.
1999-01-18 20:06:24 +00:00
bouyer c37bf0ccb4 Keep track of DMA errors, and downgrade the transert mode (UDMA ->DMA,
DMA->PIO) in case of 2 consecutive errors. Don't downgrade if the
PIO/DMA/UDMA modes were forced by a config flag.
1998-12-16 13:02:03 +00:00
bouyer 997074f17c Add a missing 'return' in an error path; noticed by Matthias Drochner. 1998-12-08 13:29:31 +00:00
bouyer 47ab212504 Rename pio_mode, etc ... to PIO_cap, etc ... for consistency with the
ata_drive_datas struct. Suggested by Soren S. Jorvan.
1998-12-03 18:24:30 +00:00
bouyer 71f33dbfa5 UDMA->Ultra-DMA in a printf 1998-12-03 17:30:32 +00:00
bouyer 2b28c858d8 add a udma_mode field to wdc_softc, and use it the same way dma_mode is used
(higthest ultra-dma mode supported). There may be a higther ultra-dma mode
defined ...
1998-12-03 15:38:59 +00:00
bouyer 1d5d5ab40a In struct wdc_xfer, change 'channel' to a pointer to a channel_softc, to avoid
a double-pointer dereference at run-time. Suggested by Matthias Drochner.
1998-12-02 15:53:34 +00:00
bouyer 45675ab14b - change drive_flags from u_int8_t to u_int16_t
- keep the modes supported by the drive in struct ata_drive_datas (will be
  later used for downgrading the DMA/PIO mode on error)
- use config flags to force/disable PIO/DMA/UDMA modes
- For the CMD PCI0643/6 setup DMA mode to DMA Read multiple.
1998-12-02 10:52:24 +00:00
bouyer 5f088e0243 wdcstart(): Re-add support of shared xfer queue across multiple channels
(was lost between 1.44 and 1.45).
1998-11-29 17:34:49 +00:00
kenh 1f676cda09 Implement the AT_READREG flag. This is needed for the CHECK POWER MODE
ATA command (among others).
1998-11-23 23:02:11 +00:00
drochner 3e38051bc5 in wdc_softc: access the per-channel data via a pointer array instead of
an array of fixed-sized channel_softc elements. This way IDE controllers
which more than 1 channel (pciide) can extend the channel data easily
for private needs.
To avoid the double dereference at runtime, change the argument of
wdcstart() to the channel data pointer instead of the array index.
1998-11-21 15:41:41 +00:00
thorpej 4ba3417429 Implement reference counting for ATA adapters. 1998-11-20 01:22:37 +00:00
kenh 396aa17f77 Sigh, my bad. Check for chp->wdc being NULL before trying to deference it.
(I didn't realize the ISA wdc front-end doesn't fill in chp->wdc).
1998-11-19 22:50:21 +00:00
thorpej afc84158d1 Back out revision 1.40. That change couldn't have POSSIBLY worked, since
when wdcprobe() is called, the wdc_softc pointer in the channel_softc
hasn't even been intialized!
1998-11-19 19:52:42 +00:00
kenh 1461c4fb20 __wdccommand_done() needs to call wdcstart(), otherwise you can run
into deadlocks when using wdc_exec_command().
1998-11-19 04:07:54 +00:00
kenh 58932a8415 Quirk out the first test in the beginning of wdcprobe(); the Vaio
CD-ROM drive doesn't like it for some reason.
1998-11-18 19:12:08 +00:00