Home | History | Annotate | Download | only in ic
History log of /src/sys/dev/ic/wdcvar.h
RevisionDateAuthorComments
 1.100  13-Apr-2020  jdolecek fix use-after-free for ata xfer on bio submission found by KASAN

driver ata_bio hooks read parts of the xfer after ata_exec_xfer()
call in order to determine return value, change so that the hook
doesn't return any value - callers do not care already,
as all I/O requests are asynchronous

this problem was uncovered by recent change for wd(4) to not hold
wd mutex during ata_bio call, the interrupt for the xfer might
thus actually fire immediately

adjust also ata_exec_command driver hooks similarily - remove all
completion and waiting logic from drivers, upper layer ata code
using AT_WAIT/AT_POLL changed to call ata_wait_cmd() itself

PR kern/55169 by Nick Hudson
 1.99  14-Sep-2019  tsutsui branches: 1.99.6;
Restore interface to pass a MD reset function to MI wdcprobe().

Fixes silent hang on G1IDE on Dreamcast. PR kern/54538
Should be pulled up to netbsd-9 with the previous changes.
 1.98  07-Oct-2017  jdolecek branches: 1.98.4; 1.98.10;
Merge support for SATA NCQ (Native Command Queueing) from jdolecek-ncq branch

ATA subsystem was changed to support several outstanding commands, and use
NCQ xfers if supported by both the controller and the disk, including NCQ
error recovery. Set NCQ high priority for BPRIO_TIMECRITICAL xfers
if supported. Added FUA support.

Done some work towards MP-safe, all ATA code tsleep()/wakeup() replaced
by condvars, and switched most code from spl* to mutexes (separate
wd(4) and ata channel lock).

Introduced new option WD_CHAOS_MONKEY to facilitate testing of error
handling, fixed several uncovered issues. Also fixed several problems
with kernel dump to wd(4) disk.

Tested with ahcisata(4), mvsata(4), siisata(4), piixide(4) on amd64,
with and without port multiplier, both disk and ATAPI devices; other
drivers and archs mechanically adjusted and compile-tested. NCQ is
supported for ahcisata(4) and siisata(4) for any controller, for
mvsata(4) only Gen IIe ones for now. Also enabled ATAPI support in
mvsata(4).

Thanks to Matt Thomas for initial ATA infrastructure patch, and
Jonathan A.Kollasch for siisata(4) NCQ changes and general testing.

Also fixes PR kern/43169 (wd(4)); and PR kern/11811, PR kern/47041,
PR kern/51979 (kernel dump)
 1.97  03-Feb-2013  jakllsch branches: 1.97.26;
Add argument to wdccommandext() to allow the entire contents of the
device/head register to be specified. Needed for upcoming port multipler
support in mvsata(4).
 1.96  19-Nov-2012  rkujawa Introduce WDC_CAPABILITY_NO_AUXCTL flag. For lame controllers that don't
have aux control registers (driver coming soon).
 1.95  31-Jul-2012  bouyer branches: 1.95.2;
Apply back changes that were reverted on Jul 24 and Jul 26 (general ata/wdc
cleanup and SATA PMP support), now that I'm back to fix the fallouts.
 1.94  26-Jul-2012  jakllsch Revert, with intention of restoring in a less invasive way, the SATA Port
Multiplier code.

ok christos@
 1.93  02-Jul-2012  bouyer Add sata Port MultiPlier (PMP) support to the ata bus layer,
as described in
http://mail-index.netbsd.org/tech-kern/2012/06/23/msg013442.html
PMP support in integrated to the atabus layer.
struct ata_channel's ch_drive[] is not dynamically allocated, and ch_ndrive
(renamed to ch_ndrives) closely reflects the size of the ch_drive[] array.
Add helper functions atabus_alloc_drives() and atabus_free_drives()
to manage ch_drive[]/ch_ndrives.
Add wdc_maxdrives to struct wdc_softc so that bus front-end can specify
how much drive they really support (master/slave or single).
ata_reset_drive() callback gains a uint32_t *sigp argument which,
when not NULL, will contain the signature of the device being reset.
While there, some cosmetic changes:
- added a drive_type enum to ata_drive_datas, and stop encoding the
probed drive type in drive_flags (we were out of drive flags anyway).
- rename DRIVE_ATAPIST to DRIVE_ATAPIDSCW to better reflect what this
really is
- remove ata_channel->ata_drives, it's redundant with the pointer in
ata_drive_datas
- factor out the interpretation of SATA signatures in sata_interpet_sig()

propagate these changes to the ATA HBA drivers, and add support for PMP
to ahcisata(4) and siisata(4).

Thanks to:
- Protocase (http://www.protocase.com/) which provided a system
with lots of controllers, SATA PMP and drive slots
- Conservation Genomics Laboratory, Department of Biology, New Mexico State
University for hosting the above system
- Brook Milligan, who set up remote access and has been very responsive
when SATA cable move was needed
 1.92  09-Jan-2012  jakllsch Instead of assume that 'features' is 0 in wdccommandext(),
pass it as an argument, as is done for wdccommand().
 1.91  05-Nov-2010  jakllsch branches: 1.91.8; 1.91.12;
Pave the way for detachment of pciide(4)-family ATA controllers.
 1.90  01-Dec-2009  dyoung branches: 1.90.2; 1.90.4;
Delete wdcactivate() prototype, it's gone away for good.
 1.89  28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.88  10-Jan-2008  dyoung branches: 1.88.6; 1.88.8; 1.88.10;
Let us detach atabus* from wdc*, and wdc* from isa*.

Use device_t, device_private().
 1.87  25-Oct-2006  bouyer branches: 1.87.24; 1.87.30; 1.87.38;
Add sata registers to struct wdc_regs. Add wdc_sataprobe(), a function
probing drives using the standard SATA registers; taken from various
PCI sata drivers. Export wdc_drvprobe() too.
 1.86  30-Sep-2006  itohy A little effort against kernel bloat....
Exclude ATA DMA support if no ATA DMA capable drivers are compiled in.
 1.85  07-Sep-2006  itohy branches: 1.85.2; 1.85.4;
Add PIOBM (busmastering transfer using ATA PIO mode) support.
The PIOBM is used by only one driver (will be added later,
stay tuned) and intruduce an attribute "ata_piobm" so that
it will be conditionally compiled in.
The "ata_dma" (busmastering transfer using ATA DMA mode) and
"ata_udma" (busmastering transfer using ATA Ultra DMA mode)
attributes are also added for consistency, but unused for now.
 1.84  11-Dec-2005  christos branches: 1.84.4; 1.84.8;
merge ktrace-lwp.
 1.83  06-Aug-2005  bouyer Add an optionnal controller callback for channel reset. If the callback
is set to NULL, use the generic reset code.
Use this to work around a bug in some Acer IDE controllers (like the
one found in some sparc systems) where a controller disable/enable
is required after a reset to avoid data corruption when Ultra-DMA is
used. Workaround from opensolaris, thanks to Hiroki Sato for testing.
 1.82  02-Mar-2005  mycroft branches: 1.82.2; 1.82.4;
Copyright maintenance.
 1.81  27-Feb-2005  perry nuke trailing whitespace
 1.80  11-Feb-2005  rearnsha Add support for Artisea chips operating in DPA mode, which has a
16-bit view of the ATA command registers for extended commands.

Approved by briggs.
 1.79  21-Aug-2004  thorpej branches: 1.79.4; 1.79.6;
Make some functions referenced only in wdc.c private to that file.
 1.78  20-Aug-2004  thorpej Move atabusconfig() to ata.c.
 1.77  20-Aug-2004  thorpej Move most of wdc_softc into a new atac_softc structure that contains
info common to all types of ATA controllers.
 1.76  19-Aug-2004  thorpej - Add and use a CHAN_TO_WDC() macro to get the wdc_softc from an
ata_channel.
- Add and use a CHAN_TO_WDC_REGS() macro to get the wdc_regs from an
ata_channel.
- Add and use a CHAN_TO_PCIIDE() macro to get the pciide_softc from an
ata_channel.
- Add and use a CHAN_TO_PCHAN() macro to get the pciide_channel from an
ata_channel. (This one just hides a cast, and is really just for
consistency with the others.)
 1.75  14-Aug-2004  thorpej - Split the register handles out of struct wdc_channel into a separate
wdc_regs structure, and array of which (indexed per channel) is pointed
to by struct wdc_softc.
- Move the resulting wdc_channel structure to atavar.h and rename it to
ata_channel. Rename the corresponding flags.
- Add a "ch_ndrive" member to struct ata_channel, which indicates the
maximum number of drives that can be present on the channel. For now,
this is always 2. Add an ATA_MAXDRIVES constant that places an upper
limit on this value, also currently 2.
 1.74  13-Aug-2004  thorpej Don't bother with bits that tell of the presence of optional callbacks;
just check the function pointers for NULL.
 1.73  13-Aug-2004  thorpej Move wdcstart() to ata.c and rename it to atastart().
 1.72  13-Aug-2004  thorpej Move wdc_exec_xfer() to ata.c and rename it ata_exec_xfer().
 1.71  12-Aug-2004  thorpej Move wdc_addref() and wdc_delref() to ata.c and rename them to
ata_*.
 1.70  12-Aug-2004  thorpej Move wdc_kill_pending() to ata.c and rename it ata_kill_pending().
 1.69  12-Aug-2004  thorpej - Move wdc_xfer_pool, wdc_get_xfer(), wdc_free_xfer() to ata.c, and rename
to ata_*.
- Use a static initializer for the ata_xfer_pool.
 1.68  12-Aug-2004  thorpej Move wdc_probe_caps() to ata.c and rename it ata_probe_caps().
 1.67  12-Aug-2004  thorpej Move wdc_print_modes() into ata.c and rename it ata_print_modes().
 1.66  12-Aug-2004  thorpej Rename some constants:
WDC_COMPLETE -> ATACMD_COMPLETE
WDC_QUEUED -> ATACMD_QUEUED
WDC_TRY_AGAIN -> ATACMD_TRY_AGAIN
 1.65  12-Aug-2004  thorpej Rename "struct wdc_command" to "struct ata_command".
 1.64  11-Aug-2004  mycroft Make datain_pio and dataout_pio function pointers in wdc_softc, which can
be overridden by the backend if desired. Add experimental code to wdc_pcmcia
to use this in memory-mapped mode, disabled by default.
 1.63  11-Aug-2004  mycroft Add two helper functions -- wdc_datain_pio() and wdc_dataout_pio() -- which
encapsulate the logic for the various methods of transferring data. Use these
throughout.
 1.62  04-Aug-2004  bouyer Change wdc_kill_pending() to take a struct ata_drive_datas * as argument,
and kill only pending requests for this drive.
Implement a DRIVE_WAITDRAIN flag, which will cause the active command to
be killed once complete.
Other minor fixes.
Now it's possible to detach a ATA or ATAPI device from ioctl even when
a dd on the raw char partition is running.
 1.61  04-Aug-2004  bouyer Add
struct ata_xfer *active_xfer
to ata_queue. Now the active xfer isn't the head of the queue any more,
this makes a few things easier (this will also help for tagged queuing
support).
Remove the WDCF_ACTIVE flag, test active_xfer != NULL instead.
clean up wdc_free_xfer() and kill_xfer().
Clean up wdc_reset_channel(), and make it issue a ATAPI_SOFT_RESET if the
active command is ATAPI.
In wdc_atapi_get_params(), use AT_WAIT | AT_POLL for ATAPI_SOFT_RESET,
so that we'll use tsleep() instead of delay().
In wdc_atapi_start(), call wdc_dmawait() at the right place.
 1.60  02-Aug-2004  bouyer Make it possible for (*dma_finish)() to abort quietly a DMA op. Use this
in wdc_reset_channel().
 1.59  02-Aug-2004  bouyer Clean up interraction between wdc_reset_channel and the kernel thread.
Move kill_xfer() after the reset, and stop the DMA engine if needed
(this will unload the DMA maps).
 1.58  01-Aug-2004  bouyer Implement an atabus control device, and define some ATA bus control
IOCTLS. Implement ATABUSIORESET, which will reset the given ATA bus.
 1.57  25-May-2004  thorpej Add the notion of "shadow registers" to the wdc driver. These shadow
registers are registers that overlap with others on many controllers, but
which may actually be distinct on some controllers. Right now, the two
shadows are:

- wd_status (usually overlaps wd_command)
- wd_features (usually overlaps wd_error)

Add a new helper function, wdc_init_shadow_regs(), used to initialize
the shadow register handles on controllers where they do actually overlap.

Partially from Jordan Rhody @ Wasabi Systems, Inc.
 1.56  13-Apr-2004  bouyer Make wdc_channel->ch_flags volatile, and cast it to (void *) when used
in tsleep()/wakeup() to appease gcc. Otherwise, the ch_flags value may
be cached in a register in atabus_thread(), and when it sets the WDCF_TH_RUN
bit after tsleep() it may loose loose the changes made by an interrupt handler
or another thread.
Problem analysed by Jukka Andberg on tech-kern.
 1.55  03-Jan-2004  thorpej branches: 1.55.2;
More structure member namespace cleanup: thread -> ch_thread
 1.54  03-Jan-2004  thorpej More wdc_channel structure member namespace cleanup:
- channel -> ch_channel
- wdc -> ch_wdc
 1.53  03-Jan-2004  thorpej More comment/whitespace tidy-up.
 1.52  03-Jan-2004  thorpej Rename "struct channel_softc" to "struct wdc_channel".
 1.51  01-Jan-2004  thorpej Prepend "wdc_" to wait_for_drq, wait_for_unbusy, and wait_for_ready.
 1.50  01-Jan-2004  thorpej Tidy up this file somewhat.
 1.49  01-Jan-2004  thorpej Rename:
- wdc_xfer to ata_xfer
- channel_queue to ata_queue
and move them to <dev/ata/atavar.h> so they can be used by non-wdc ATA
controllers. Clean up the member names of these structures while at it.
 1.48  30-Dec-2003  thorpej Move the drive probing code out of atabusconfig() and into a new
wdc_drvprobe() function. wdc_drvprobe() is used if the controller
does not specify a custom one prior to calling wdcattach(). The
WDC_CAPABILITY_DRVPROBE bit is gone.
 1.47  30-Dec-2003  thorpej Move most of the atabus layer into ata.c.
 1.46  15-Dec-2003  thorpej Add a (*drv_probe)() optional callback into the driver to probe for
drives on a channel. Drivers should provide this if they have some
sort of intelligent probing mechanism.
 1.45  03-Dec-2003  bouyer Move WDC_NREG from wdcreg.h to wdcvar.h. First part of fix for
port-macppc/23604.
 1.44  27-Nov-2003  fvdl There are some cards that map the ATA control and IDE DMA registers
in a different fashion. Individually, they have the same functionality,
but their layout is different. An example of such a chipset is
the Promise 203xx.

To be able to deal with this, transform the cmd and dma bus_space handles
into an array of handles, each seperately created with bus_space_subregion.
The code generated by using the extra indirection shouldn't change much,
since the extra indirection is negated by having the offset calculation
already done in bus_space_subregion. E.g.

bus_space_write_4(tag, handle, offset, value)

becomes

bus_space_write_4(tag, handles[offset], 0, value)

Reviewed by Manuel Bouyer. Tested on wdc_isa, wdc_pcmcia, viaide, piixide (i386)
and on cmdide (sparc64).
 1.43  02-Nov-2003  wiz Fix some typos. From Tom Cosgrove via jmc@openbsd.
 1.42  29-Oct-2003  bouyer freese->freeze, as pointed out by Frederick Bruck.
 1.41  08-Oct-2003  bouyer Make the ATA mid-layer appears as atabus, as proposed in
http://mail-index.netbsd.org/tech-kern/2003/09/25/0006.html
This adds a device (atabus) between IDE controllers and wd or atapibus, to
have each ATA channel show up in the device tree. Later there will be atabus
devices in /dev, so that we can do IOCTL on them.
Each atabus has its own kernel thread, to handle operations that needs polling,
e.g. reset and others.

Device probing on each bus it defered to the atabus thread creation.
This allows to do the reset and basic device probes in parallel, which reduce
boot time on systems with several pciide controllers.
 1.40  25-Sep-2003  mycroft Hide the use of config_interrupts() in one place.
 1.39  23-Sep-2003  mycroft Fix more probe delay and/or failure problems:
1) Don't wait for DRQ on an IDENTIFY command -- if it's not set when we see
BSY clear, abort the command and ignore the drive. (Do this by testing
for DRQ in the read/write cases in __wdccommand_intr().)
2) Don't wait for DRQ to deassert when we finish an IDENTIFY (or any other
non-block command that reads data) -- we don't do this for block I/O, and
empirically it doesn't clear on my CF cards at all, causing a pointless 1s
delay.
3) Add comments to some of the delay()s, and add missing ones in wdcreset()
and the WDCC_RECAL in the so-called "pre-ATA" probe.
4) Slightly simplify the reset sequence -- we were doing an extra I/O.
5) Modify the register writability test to make sure that registers are not
overlapped -- this can happen in some weird cases with a missing device 1.
6) Check the error register value after the reset -- if it's not 01h or 81h,
as appropriate (see ATA spec), punt.
Tested with a number of ATA-only, ATAPI-only, mixed ATA-ATAPI, CF, and IDE
disk configurations.

Also remove the SINGLE_DRIVE nonsense again.
 1.38  21-Sep-2003  bouyer Since we can't detect ghost drives in the wdc back-end, resurect
WDC_CAPABILITY_SINGLE_DRIVE.
 1.37  19-Sep-2003  mycroft 1) Use config_interrupts() to attach IDE and ATAPI drives. This eliminates
most polling.
2) Clean up some goofiness in pciide -- get rid of the whole "candisable" path
(it's gratuitous) and simplify the code by calling pciide_map_compat_intr(),
*_set_modes() and wdc_print_modes() from central locations.
3) Add a register writability and register ghost test to eliminate phantom
drives more quickly.
 1.36  28-Apr-2003  nakayama branches: 1.36.2;
Make DMA mode works on Promise Ultra66/100 with 48-bit LBA drives.
Ok'ed by bouyer in tech-kern@netbsd.org.
 1.35  27-Jan-2003  thorpej Experimental support for RAID volumes configured by ATA "RAID" controllers.
Such RAID controllers are actually just IDE controllers with a BIOS that
can create RAID volumes and write the configuration info to config blocks
on the disks. The BIOS can do I/O to these volumes, and the OS must
understand the config blocks and implement RAID in software in order to be
able to use these volumes.

Only SPAN (simple concatenation) and RAID0 are supported at this time,
and writing back config blocks is also not supported at this time. Currently,
only the Promise configuration scheme is supported, although supporting
the Highpoint scheme should not be too difficult.

In any case, this is sufficient to use the Promise RAID0 volume (thus
preserving the win2k AS installation) on this new Intel server I have.

Thanks to Soren Schmidt for doing the work in FreeBSD; it made this
task much easier. The config block parsing code is adapted from his
work.
 1.34  13-Jan-2002  christos branches: 1.34.10;
Add LBA48 support based on patches from Keisuke YOSHIDA. KNF a bit while
I am there.
 1.33  07-Jan-2002  dbj Changes to the wdc(4) mi driver that add the WDC_CAPABILITY_SELECT
flag and a callback function which gets called whenever a target is
selected on a channel.

The macppc wdc driver needs to reprogram its timing register
differently for each target on a channel each time that target is
selected. I also changed the ATA4_TIME_TO_TICK to use a divisor of
15, which brings our timing calculations consistent with darwin.

These patches fix problems on my dual usb ibook with combo dvd/cdrw
drive because the hard drive supports udma and the combo drive does
not. Without turning off the udma timings in the configuration
register, I cannot access the non-udma combo drive.
 1.32  03-Dec-2001  bouyer Allow wd to attach to something else than wdc/pciide (like USB<->ATA bridges):
- move some functions from ata.c to ata_wdc.c or wdc.c.
- add callbacks to struct ata_bustype so that wd.c doesn't call directly
functions from the lower level driver.
 1.31  01-Dec-2001  bouyer For ATAPI tape drives, poll for DSC (using a callout), to get the real
status of the command, and make sure the drive is ready for the next one.
 1.30  13-Jun-2001  bjh21 branches: 1.30.2;
Add explicit support for IDE and SCSI adaptors which don't support interrupts.
On such adaptors, all transfers are done in polling mode.

OK'ed by Manuel on tech-kern.
 1.29  25-Apr-2001  bouyer Pull up the thorpej_scsipi branch to main branch.
This is a completely rewritten scsipi_xfer execution engine, and the
associated changes to HBA drivers. Overview of changes & features:
- All xfers are queued in the mid-layer, rather than doing so in an
ad-hoc fashion in individual adapter drivers.
- Adapter/channel resource management in the mid-layer, avoids even trying
to start running an xfer if the adapter/channel doesn't have the resources.
- Better communication between the mid-layer and the adapters.
- Asynchronous event notification mechanism from adapter to mid-layer and
peripherals.
- Better peripheral queue management: freeze/thaw, sorted requeueing during
recovery, etc.
- Clean separation of peripherals, adapters, and adapter channels (no more
scsipi_link).
- Kernel thread for each scsipi_channel makes error recovery much easier
(no more dealing with interrupt context when recovering from an error).
- Mid-layer support for tagged queueing: commands can have the tag type
set explicitly, tag IDs are allocated in the mid-layer (thus eliminating
the need to use buggy tag ID allocation schemes in many adapter drivers).
- support for QUEUE FULL and CHECK CONDITION status in mid-layer; the command
will be requeued, or a REQUEST SENSE will be sent as appropriate.

Just before the merge syssrc has been tagged with thorpej_scsipi_beforemerge
 1.28  22-Jan-2001  mycroft branches: 1.28.2;
Force certain commands (i.e. DVD authentication) to PIO mode. They are
explicitly not supported in DMA mode, and generally return an `illegal field
in CDB' error.
This should have been done ages ago.
 1.27  06-Jan-2001  takemura Add WDC_CAPABILITY_SINGLE_DRIVE to ignore secound drive. Wdc on pcmcia will
be attached with this flag.
Some CF Card (for ex. IBM MicroDrive and SanDisk) doesn't seem to implement
drive select command. In this case, you can't eliminate ghost drive properly.
So you should use this flag to ignore the ghost by force.
 1.26  08-Nov-2000  wrstuden Move guts of pciide_print_modes() to wdc_print_modes() so that non-pciide
wdc drivers (like macppc's obio IDE interface) can use it. Also add
support to both wd attach line and to wdc_print_modes() to print
Ultra/{33,66,100} for respective UDMA modes (From Manuel Bouyer).
 1.25  12-Jun-2000  bouyer branches: 1.25.2;
Add a callback (*irqack), for controllers that need special action to ack
the interrupt once it has been ack'd on the drive.
 1.24  01-Apr-2000  bouyer branches: 1.24.2;
- 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).
 1.23  23-Mar-2000  enami Fix a typo in comment in previous commit.
 1.22  23-Mar-2000  thorpej 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.
 1.21  20-Mar-2000  enami - Test the generic device active flag instead of home grown one.
- Test also it in wdcintr.
 1.20  20-Oct-1999  enami Cancel active transfers on aic/wdc detach.
Also makes LS-120 drive works for me again.
 1.19  23-Sep-1999  enami branches: 1.19.2; 1.19.4; 1.19.6;
Allow to detach wdc, atapibus, wd and cd.
 1.18  09-Aug-1999  bouyer Garbage-collect C_INUSE and C_NEEDDONE.
 1.17  11-Apr-1999  bouyer 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).
 1.16  01-Apr-1999  bouyer branches: 1.16.2;
- 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.
 1.15  08-Feb-1999  bouyer 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.
 1.14  16-Dec-1998  bouyer Add a callback to re-compute the modes used on a channel.
 1.13  03-Dec-1998  bouyer Rename pio_mode, etc ... to PIO_cap, etc ... for consistency with the
ata_drive_datas struct. Suggested by Soren S. Jorvan.
 1.12  03-Dec-1998  bouyer 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 ...
 1.11  02-Dec-1998  bouyer 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.
 1.10  21-Nov-1998  drochner 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.
 1.9  20-Nov-1998  thorpej Implement reference counting for ATA adapters.
 1.8  19-Nov-1998  thorpej Adapt to the new scsipi_adapter interface.
 1.7  17-Nov-1998  bouyer New IDE xfer flag: C_SENSE, set by the ATAPI back-end sense info needs to
be retrieved.
 1.6  12-Oct-1998  bouyer Merge bouyer-ide
 1.5  22-Sep-1998  mark Add data32iot and data32ioh members to the wdc_attachment_data structure.
This bus space tag and handle is used for 32 bit data transfers i.e.
when WDC_CAPABILITY_DATA32 is enabled as the 32 bit data register may
not be part of the standard drive registers.
 1.4  10-Sep-1998  kenh Add support for passing device quirks from the attachment routine,
and add support for a NO_EXTRA_RESETS quirk (required by the TEAC
IDE Card/II, which the Vaio uses).
 1.3  15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.2  07-Apr-1998  leo branches: 1.2.2;
Add hooks to make exclusive hardware locking possible. This is necessary
to make the driver suitable for the atari falcon.
 1.1  14-Jan-1998  cgd Various cleanups and bug fixes to the wdc/wd code:
* Fix bug in wdc that would overflow ATAPI transfer length.
* Improve wdc probe code so that 'wdc' is probed in if present
even if there are no drives attached, and so that it works
properly even if the only device is an ATAPI slave.
* bus_space-ify.
* split the ISA attachment from the wdc driver, and remove
ISA dependencies from non-ISA files.
* claim that wd and wdc are now machine-independent (probably not
completely true, but mostly so; they at least work on arm32 and
i386).
* Various other minor fixups and cleanups, some of which were pointed
out by Kazuki Sakamoto.
 1.2.2.13  05-Oct-1998  bouyer Rename WDC_CAPABILITY_PIO to WDC_CAPABILITY_MODE, as it's used to tell wether
the controller's driver can tell which timing mode it uses. Check this
before setting DMA modes too.
This allow the generic DMA code to work again.
 1.2.2.12  04-Oct-1998  bouyer New flag for wdc_xfer: C_DMA, set when a cmd will use DMA. This reduce some
if() in ata_wdc.c and atapi_wdc.c from 3 tests to one.
 1.2.2.11  02-Oct-1998  bouyer Cleanup a few error message, remove some dead code. Re-add a reset at end of
attach, unless we have WDC_NO_EXTRA_RESETS.
Add support for data32iot/data32ioh from -current: each controller pass
WDC_CAPABILITY_DATA32 if they can do 32bit, and WDC_CAPABILITY_DATA16 if they
can do 16bit. For controller that support both, the usual autodetect
mechanism is still used.
 1.2.2.10  20-Sep-1998  bouyer Kill the 'old drive' flag. The probe for IDE controllers now looks
like this :
- if status = 0xff for both master and slave, no drive at all -> exit.
- issue a reset (timeout = 31s).
- test signatures: if ATAPI signature, flag a (possible) ATAPI devices here
else test register writability, then wait for the drive to become
ready, issue a diagnostic command and wait for the drive to become ready
if ok, flag a real ATA device.
This looks more like the old probe.
For ATA devices, if IDENTIFY fails, then it's an old drive and use
a fake disklabel/geometry.
 1.2.2.9  20-Sep-1998  bouyer - always call config_found() from wdcattach(), instead of printing our own
the "not configured" message ourselve. When no atapibus is configured,
use a fake ata_atapi_attach, else call wdc_atapibus_attach(). This way we
don't have to include the whole atapi support in an ata-only config.
- the dma_* function pointers take a 'int flags' as last argument, instead
of an 'int read'. The 2 valid flags are: WDC_DMA_READ (to select read/write)
and WDC_DMA_POLL, to signal interrupt-less mode (for core dumps).
- Reworked wdcprobe() so look more like the old one. A status of 0xff is
interpreted as "no drive" (freebsd does this); this this speed up
the probe for non-IDE machines (a reset timeout has been bumped to 31s,
to match the specs). The probe set ups the drive flags to either ATA or
ATAPI (depend on register signature) or OLD (if register signature don't
match, but a working drive appears to be there). Later the ATA code
will look at the OLD flag to decide wether there is no drive, or an old
(ST506) one if WDC_IDENTIFY fails.
- For known PCI chips, don't use the wdcprobe() heuristic to find wether
a channel is enabled/disabled; use the chip's specific registers for this.
- Clear the command queue when we have a polled command. This allows dumps to
work even if a command was being handled by the controller at panic time.
- Increase the number of available DMA segments by one, as user requests may
not be aligned on a page boundary.
 1.2.2.8  11-Sep-1998  bouyer Sync with HEAD.
 1.2.2.7  21-Aug-1998  bouyer Sync with -current
 1.2.2.6  13-Aug-1998  bouyer - sync with HEAD
- better error detection and report for wd drives
- better wddump() support
- wdcwait() now takes a timout argument, so that we can honnor the
timeout argument of scsipi cmds.
 1.2.2.5  23-Jun-1998  leo Add necessary cruft to handle swapped byte-lanes on the data-register. It
basically boils down to the fact that there are 2 new options:
WDC_CAPABILITY_{ATA,ATAPI}_NOSTREAM with which you are able to control
the usage bus_space_read_multi_X() vs. bus_space_read_multi_stream_X().
 1.2.2.4  19-Jun-1998  leo Kill typo
 1.2.2.3  05-Jun-1998  bouyer A few bux fixes (untested):
- If the PIO mode of the controller is unknown, put the drive in the
hightest mode it supports. A drive in a faster mode than the controller
should work.
- Create DMA maps even for unknown controllers in pciide.
 1.2.2.2  05-Jun-1998  bouyer Patches from Leo Weppelman for IDE on atari, with minor fixes by me
(needed the addition of a void wdcrestart __P((void*)) function).
Quoting his words:
These diffs are preliminary because it looks like the free_hw() function
does not get called. This is only a problem on the atari falcon. I have not
yet been able to track this down.
Also, KNF wdc.c.
 1.2.2.1  04-Jun-1998  bouyer Commit changes to the IDE system in a branch. This allows a better separation
between higth-level and low-level (i.e. registers read/write) and generalize
the queue for all commands. This also add supports for IDE DMA.
 1.16.2.2  07-Jul-2000  he Apply patch (requested by bouyer):
Add support for the following PCIIDE controllers:
o AMD 756
o CMD PCI0648 and PCI0649
o Hightpoint HPT366
o OPTi 82c621 (and a few of its derivatives)
o Promise Ultra/33 and Ultra/66
o Intel 82801 (ICH/ICH0)
Also fix PR#10437 (detect more ATAPI devices).
 1.16.2.1  12-Apr-1999  bouyer branches: 1.16.2.1.2;
Sync with ic/wdc.c 1.67, ic/wdcvar.h 1.17, isa/wdc_isa.c 1.14:
Revert to a more conservative probe: it controller responded and we don't find
ATAPI signature, assume it and ATA or OLD drive (OLD is only set if the
wdc front end passed WDC_CAPABILITIES_OLD, only used for ISA front-end).
At attach time, issue an IDENTIFY to detect drives and eliminates ghosts.
If IDENTIFY failed and OLD is set, issue a RECAL to check for the presence
of old drives.
Should fix the 'disk dissapeared' problems reported by some users, including
port-arm32/7324.
 1.16.2.1.2.1  21-Jun-1999  thorpej Sync w/ -current.
 1.19.6.1  27-Dec-1999  wrstuden Pull up to last week's -current.
 1.19.4.1  15-Nov-1999  fvdl Sync with -current
 1.19.2.6  11-Feb-2001  bouyer Sync with HEAD.
 1.19.2.5  18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.19.2.4  22-Nov-2000  bouyer Sync with HEAD.
 1.19.2.3  20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.19.2.2  20-Oct-1999  thorpej Sync w/ trunk.
 1.19.2.1  19-Oct-1999  thorpej Adapt to scsipi API changes.
 1.24.2.1  22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.25.2.2  16-Jan-2002  he Pull up revision 1.33 (via patch, requested by dbj):
Add UDMA support and allow separate DMA timings to be programmed
for two different devices on the same wdc channel on the macppc.
The machine-independent driver is updated to optionally use the
WDC_CAPABILITY_SELECT callback whenever a target is selected on
a channel.
 1.25.2.1  27-Dec-2001  he Pull up revision 1.28 (requested by mycroft):
Make DVD commands work on drives configured for DMA.
 1.28.2.5  28-Feb-2002  nathanw Catch up to -current.
 1.28.2.4  23-Feb-2002  gmcgarry Merge up from -current.
 1.28.2.3  11-Jan-2002  nathanw More catchup.
 1.28.2.2  08-Jan-2002  nathanw Catch up to -current.
 1.28.2.1  21-Jun-2001  nathanw Catch up to -current.
 1.30.2.2  11-Feb-2002  jdolecek Sync w/ -current.
 1.30.2.1  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.34.10.1  28-Apr-2003  tron Pull up revision 1.36 (requested by nakayama in ticket #1275):
Make DMA mode works on Promise Ultra66/100 with 48-bit LBA drives.
Ok'ed by bouyer in tech-kern@netbsd.org.
 1.36.2.8  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.36.2.7  04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.36.2.6  15-Feb-2005  skrll Sync with HEAD.
 1.36.2.5  21-Sep-2004  skrll Fix the sync with head I botched.
 1.36.2.4  18-Sep-2004  skrll Sync with HEAD.
 1.36.2.3  25-Aug-2004  skrll Sync with HEAD.
 1.36.2.2  12-Aug-2004  skrll Sync with HEAD.
 1.36.2.1  03-Aug-2004  skrll Sync with HEAD
 1.55.2.1  18-Apr-2004  jmc branches: 1.55.2.1.2;
Pullup rev 1.56 (requested by bouyer in ticket #149)

Make wdc_channel->ch_flags volatile, and cast it to (void *) when used
in tsleep()/wakeup() to appease gcc. Otherwise, the ch_flags value may
be cached in a register in atabus_thread(), and when it sets the WDCF_TH_RUN
bit after tsleep() it may loose loose the changes made by an interrupt handler
or another thread.
 1.55.2.1.2.1  07-Aug-2005  riz Pull up revision 1.83 via patch (requested by bouyer in ticket #5555):
Add an optionnal controller callback for channel reset. If the callback
is set to NULL, use the generic reset code.
Use this to work around a bug in some Acer IDE controllers (like the
one found in some sparc systems) where a controller disable/enable
is required after a reset to avoid data corruption when Ultra-DMA is
used. Workaround from opensolaris, thanks to Hiroki Sato for testing.
 1.79.6.2  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.79.6.1  12-Feb-2005  yamt sync with head.
 1.79.4.1  29-Apr-2005  kent sync with -current
 1.82.4.3  21-Jan-2008  yamt sync with head
 1.82.4.2  30-Dec-2006  yamt sync with head.
 1.82.4.1  21-Jun-2006  yamt sync with head.
 1.82.2.1  18-Aug-2005  tron Pull up revision 1.83 (requested by bouyer in ticket #653):
Add an optionnal controller callback for channel reset. If the callback
is set to NULL, use the generic reset code.
Use this to work around a bug in some Acer IDE controllers (like the
one found in some sparc systems) where a controller disable/enable
is required after a reset to avoid data corruption when Ultra-DMA is
used. Workaround from opensolaris, thanks to Hiroki Sato for testing.
 1.84.8.1  14-Sep-2006  yamt sync with head.
 1.84.4.1  09-Sep-2006  rpaulo sync with head
 1.85.4.2  10-Dec-2006  yamt sync with head.
 1.85.4.1  22-Oct-2006  yamt sync with head
 1.85.2.1  18-Nov-2006  ad Sync with head.
 1.87.38.1  10-Jan-2008  bouyer Sync with HEAD
 1.87.30.1  18-Feb-2008  mjf Sync with HEAD.
 1.87.24.1  23-Mar-2008  matt sync with HEAD
 1.88.10.2  11-Mar-2010  yamt sync with head
 1.88.10.1  16-May-2008  yamt sync with head.
 1.88.8.1  18-May-2008  yamt sync with head.
 1.88.6.1  02-Jun-2008  mjf Sync with HEAD.
 1.90.4.1  05-Mar-2011  rmind sync with head
 1.90.2.1  06-Nov-2010  uebayasi Sync with HEAD.
 1.91.12.1  18-Feb-2012  mrg merge to -current.
 1.91.8.4  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.91.8.3  16-Jan-2013  yamt sync with (a bit old) head
 1.91.8.2  30-Oct-2012  yamt sync with head
 1.91.8.1  17-Apr-2012  yamt sync with head
 1.95.2.2  03-Dec-2017  jdolecek update from HEAD
 1.95.2.1  25-Feb-2013  tls resync with head
 1.97.26.3  27-Sep-2017  jdolecek change wdc_init_shadow_regs() to accept only struct wdc_regs, it doesn't
touch anything else

factor out the probe-only struct ata_channel initialization to wdcprobe(), to
reduce duplication of logic in individual drivers, and to actually work now
that more init is needed beyond the memset()
 1.97.26.2  12-Aug-2017  jdolecek remove all logic around ATACH_IRQ_WAIT and channel-global ch_error/ch_status,
so that there is less hidden state shared by commands; primary intent is
to make the NCQ and non-NCQ paths more similar, and remove possibility
of incorrect handling for the NCQ commands

tested both disk and ATAPI - piixide(4) on QEMU, and siisata(4),
ahcisata(4), mvsata(4) on real hw
 1.97.26.1  15-Apr-2017  jdolecek pass also ata_command via ata_xfer, callers of ata_exec_command() is now
responsible for allocation/disposal of the structure

change code to allocate ata_xfer for commands on stack same way as previously
the ata_command were, using c_slot 0; adjust asserts so that it would allow
several xfers with same c_slot, as long as only one such transfer is active
at a time
 1.98.10.2  30-Dec-2022  martin Pull up following revision(s) (requested by tsutsui in ticket #1557):

sys/dev/ic/ahcisata_core.c: revision 1.83
sys/dev/ic/ahcisata_core.c: revision 1.102
sys/dev/ata/ata.c: revision 1.164
sys/dev/ata/ata_wdc.c: revision 1.115
sys/dev/ata/ata_recovery.c: revision 1.4
sys/dev/ic/siisata.c: revision 1.42
sys/dev/ic/wdc.c: revision 1.308
sys/dev/ic/mvsata.c: revision 1.56
sys/dev/scsipi/atapi_wdc.c: revision 1.138
sys/dev/ic/siisata.c: revision 1.49
sys/dev/ata/atavar.h: revision 1.105
sys/dev/ata/wd.c: revision 1.460
sys/dev/ata/ata.c: revision 1.155
sys/dev/ata/wd.c: revision 1.462
sys/dev/ata/atavar.h: revision 1.109
sys/dev/ata/satapmp_subr.c: revision 1.16
sys/dev/ic/wdc.c: revision 1.299
sys/dev/ic/ahcisata_core.c: revision 1.93
sys/dev/ata/ata_wdc.c: revision 1.120
sys/dev/ic/wdcvar.h: revision 1.100
sys/dev/scsipi/atapi_wdc.c: revision 1.141
sys/dev/ic/mvsata.c: revision 1.61
sys/dev/usb/umass_isdata.c (apply patch)

drop wd lock in wdstart1() before calling the ata_bio hook; when called
from ata thread context, that can still need to sleep for wdc attachments
in wdcwait()

fix use-after-free for ata xfer on bio submission found by KASAN
driver ata_bio hooks read parts of the xfer after ata_exec_xfer()
call in order to determine return value, change so that the hook
doesn't return any value - callers do not care already,
as all I/O requests are asynchronous

this problem was uncovered by recent change for wd(4) to not hold
wd mutex during ata_bio call, the interrupt for the xfer might
thus actually fire immediately

adjust also ata_exec_command driver hooks similarily - remove all
completion and waiting logic from drivers, upper layer ata code
using AT_WAIT/AT_POLL changed to call ata_wait_cmd() itself
PR kern/55169 by Nick Hudson

Function declaration formating whitespace consistency. NFCI.

PR kern/56403
Fix kernel freeze for wdc(4) variants with ATAC_CAP_NOIRQ:

(1) Change ata_xfer_ops:c_poll from void to int function. When it returns
ATAPOLL_AGAIN, let ata_xfer_start() iterate itself again.
(2) Let wdc_ata_bio_poll() return ATAPOLL_AGAIN until ATA_ITSDONE is
achieved.

A similar change has been made for mvsata(4) (see mvsata_bio_poll()),
and no functional changes for other devices.

This is how the drivers worked before jdolecek-ncq branch was merged.
Note that this changes are less likely to cause infinite recursion:

(1) wdc_ata_bio_intr() called from wdc_ata_bio_poll() asserts ATA_ITSDONE
in its error handling paths via wdc_ata_bio_done().
(2) Return value from c_start (= wdc_ata_bio_start()) is checked in
ata_xfer_start().

Therefore, errors encountered in ata_xfer_ops:c_poll and c_start routines
terminate the recursion for wdc(4). The situation is similar for mvsata(4).

Still, there is a possibility where ata_xfer_start() takes long time to
finish a normal operation. This can result in a delayed response for lower
priority interrupts. But, I've never observed such a situation, even when
heavy thrashing takes place for swap partition in wd(4).
"Go ahead" by jdolecek@.
 1.98.10.1  23-Sep-2019  martin Pull up following revision(s) (requested by tsutsui in ticket #232):

sys/arch/evbppc/mpc85xx/wdc_obio.c: revision 1.7
sys/arch/dreamcast/dev/g1/wdc_g1.c: revision 1.4
sys/arch/dreamcast/dev/g1/wdc_g1.c: revision 1.5
sys/arch/mmeye/dev/wdc_mainbus.c: revision 1.7
sys/dev/ic/wdcvar.h: revision 1.99
sys/dev/ic/wdc.c: revision 1.292
sys/arch/mips/adm5120/dev/wdc_extio.c: revision 1.11

adjust several missed drivers for wdcprobe() changes of ATA NCQ branch
for dreamcast g1 just drop the custom reset function, it doesn't seem to do
anything useful over the generic variant

PR kern/54538 by Izumi Tsutsui

Restore interface to pass a MD reset function to MI wdcprobe().

Fixes silent hang on G1IDE on Dreamcast. PR kern/54538
Should be pulled up to netbsd-9 with the previous changes.
 1.98.4.2  21-Apr-2020  martin Sync with HEAD
 1.98.4.1  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.99.6.1  20-Apr-2020  bouyer Sync with HEAD

RSS XML Feed