From 5ade3960bb517317af52da2da61a013a084233ac Mon Sep 17 00:00:00 2001 From: Jeroen Ruigrok/asmodai Date: Sat, 22 Nov 2003 09:50:36 +0000 Subject: [PATCH] Remove the archaic wd(4) driver and its dependencies. Tested with: LINT --- share/man/man4/man4.i386/Makefile | 4 +- share/man/man4/man4.i386/wd.4 | 88 -- share/man/man4/man4.i386/wfd.4 | 234 --- sys/bus/isa/i386/isa_compat.h | 7 +- sys/conf/files.i386 | 14 +- sys/config/LINT | 75 +- sys/dev/disk/wcd/wd_cd.c | 1482 ------------------- sys/dev/disk/wcd/wd_cd.h | 350 ----- sys/dev/disk/wd/wd.c | 2209 ----------------------------- sys/dev/disk/wd/wdreg.h | 321 ----- sys/dev/disk/wfd/wfd.c | 729 ---------- sys/dev/disk/wst/wst.c | 778 ---------- sys/i386/conf/LINT | 75 +- 13 files changed, 6 insertions(+), 6360 deletions(-) delete mode 100644 share/man/man4/man4.i386/wd.4 delete mode 100644 share/man/man4/man4.i386/wfd.4 delete mode 100644 sys/dev/disk/wcd/wd_cd.c delete mode 100644 sys/dev/disk/wcd/wd_cd.h delete mode 100644 sys/dev/disk/wd/wd.c delete mode 100644 sys/dev/disk/wd/wdreg.h delete mode 100644 sys/dev/disk/wfd/wfd.c delete mode 100644 sys/dev/disk/wst/wst.c diff --git a/share/man/man4/man4.i386/Makefile b/share/man/man4/man4.i386/Makefile index 6f3fe49bdd..c3dc213491 100644 --- a/share/man/man4/man4.i386/Makefile +++ b/share/man/man4/man4.i386/Makefile @@ -1,5 +1,5 @@ # $FreeBSD: src/share/man/man4/man4.i386/Makefile,v 1.122.2.12 2003/04/15 17:23:32 fjoe Exp $ -# $DragonFly: src/share/man/man4/man4.i386/Makefile,v 1.2 2003/06/17 04:36:59 dillon Exp $ +# $DragonFly: src/share/man/man4/man4.i386/Makefile,v 1.3 2003/11/22 09:50:35 asmodai Exp $ MAN= aic.4 alpm.4 amdpm.4 apm.4 ar.4 asc.4 asr.4 \ cs.4 cx.4 cy.4 \ @@ -10,7 +10,7 @@ MAN= aic.4 alpm.4 amdpm.4 apm.4 ar.4 asc.4 asr.4 \ ray.4 rdp.4 sb.4 sbni.4 scd.4 \ spkr.4 sr.4 tw.4 \ tx.4 viapm.4 vx.4 \ - wd.4 wfd.4 wl.4 wt.4 + wl.4 wt.4 MLINKS= spkr.4 speaker.4 diff --git a/share/man/man4/man4.i386/wd.4 b/share/man/man4/man4.i386/wd.4 deleted file mode 100644 index b88ae0a2bd..0000000000 --- a/share/man/man4/man4.i386/wd.4 +++ /dev/null @@ -1,88 +0,0 @@ -.\" -.\" Copyright (c) 1994 Wilko Bulte -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software withough specific prior written permission -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD: src/share/man/man4/man4.i386/wd.4,v 1.19.2.3 2001/08/17 13:08:46 ru Exp $ -.\" $DragonFly: src/share/man/man4/man4.i386/Attic/wd.4,v 1.2 2003/06/17 04:37:00 dillon Exp $ -.\" -.Dd August 31, 1994 -.Dt WD 4 i386 -.Os -.Sh NAME -.Nm wd -.Nd generic WD100x/IDE disk controller driver -.Sh SYNOPSIS -.Cd "device wdc0 at isa? port IO_WD1 irq 14" Op flags Ar flags -.Cd device wd0 at wdc0 drive 0 -.Cd "device wd1 at wdc0 drive 1" Op flags Ar flags -.Sh DESCRIPTION -This driver provides access to disks connected to controllers that emulate -the Western Digital WD100x series. -This range of controllers includes WD1003 -type ST412 controllers, WD1007 ESDI controllers and also the generic IDE -controllers found on most motherboards. -.Pp -Your controller documentation is usually quick to point out any WD100x -compatibility. -.Pp -You can convey a number of hints and instructions to the driver using -the -.Ar flags -parameter. -.Pp -For each drive there are six bit-fields encoded in a 16 bit integer: -.Bl -tag -width 0x0000 -.It 0x8000 -Test and use the 32bit transfer capability of the drive. -.It 0x4000 -If drive looks like it's coming out of sleep mode, assume it's -confused and reinitialize it. -.It 0x2000 -Probe for and use the bus-mastering DMA capabilities of modern -PCI chipsets. -.It 0x1000 -Use LBA addressing instead of the default CHS addressing. -.It 0x0f00 -Force number of heads to ((flags & 0xf00)>>8), recalculate number -of cylinders to match. -.It 0x00ff -Test and use multi-sector transfer mode of this drive, max number of -sectors attempted is (flags & 0x00ff). -.El -.Pp -The flags can be specified on the line for the drive as a 16 bit int, -or on the controller line as a 32 bit int, where the top 16 bit is -relevant to the highest numbered drive. -.Sh FILES -.Bl -tag -width Pa -compact -.It Pa /dev/wd* -wd device nodes -.It Pa /sys/i386/conf/GENERIC -sample generic kernel config file for (a.o.) wd based systems -.It Pa /sys/i386/isa/wd.c -driver source -.El -.Sh NOTES -This driver will soon be completely replaced by the ata and ad drivers. diff --git a/share/man/man4/man4.i386/wfd.4 b/share/man/man4/man4.i386/wfd.4 deleted file mode 100644 index 048b36ba64..0000000000 --- a/share/man/man4/man4.i386/wfd.4 +++ /dev/null @@ -1,234 +0,0 @@ -.\" Copyright (c) 1997 Junichi Satoh -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the author nor the names of any co-contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY FreeBSD, Inc. AND CONTRIBUTORS ``AS IS'' -.\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL FreeBSD, Inc. OR CONTRIBUTORS BE -.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD: src/share/man/man4/man4.i386/wfd.4,v 1.12.2.3 2001/12/21 10:07:09 ru Exp $ -.\" $DragonFly: src/share/man/man4/man4.i386/Attic/wfd.4,v 1.2 2003/06/17 04:37:00 dillon Exp $ -.\" -.Dd January 16, 1998 -.Dt WFD 4 i386 -.Os -.Sh NAME -.Nm wfd -.Nd ATAPI floppy driver (LS-120 floppy driver) -.Sh SYNOPSIS -.Cd options ATAPI -.Cd options ATAPI_STATIC -.Cd device wfd -.Pp -.Sh DESCRIPTION -The -.Nm -driver provides support for -.Em ATAPI -floppy disks, typically LS-120 style 120mb/1.4mb floppy drives. -In general the interfaces are similar to those described by -.Xr wd 4 . -.Pp -As the IDE controllers are probed during boot, the -.Em IDE -buses are scanned for devices. -Any devices found which answered as -.Sq Em Floppy -and -.Sq Em removable -type device will be attached to the -.Nm -driver. -The first device found will be attached as -.Em wfd0 -and the next, -.Em wfd1 , -and so on. -.Pp -When used with a LS-120 drive, this driver will read/write the following -types of floppy disk: -.Bl -tag -width 1.25MB -compact -.It 120mb -.It 1.44mb -.It 1.25mb (PC-9801 series format) -.It 1.2mb -.It 720kb -.El -.Sh PARTITIONING -The -.Nm -driver allows the disk to have two levels of partitioning. -One layer, called the -.Dq slice layer , -is used to separate the -.Fx -areas of the disk from areas used by other operating systems. -The second layer is the native -.Bx 4.4 -partitioning scheme, -.Xr disklabel 5 , -which is used to subdivide the -.Fx -slices into areas for individual filesystems. -For more information, see -.Xr fdisk 8 -and -.Xr disklabel 8 , -respectively. -.Pp -If an uninitialized disk is opened, the slice table will be -initialized with a fictitious -.Fx -slice spanning the entire disk. Similarly, if an uninitialized -(or -.No non- Ns Fx ) -slice is opened, its disklabel will be initialized with parameters -returned by the drive and a single -.Sq Li c -partition encompassing the entire slice. -.Sh EXAMPLES -Making LS-120/ZIP disks can be a bit more complicated than usual depending -upon whether or not you chose to use the slice code or not. -LS-120 floppies are typically considered floppy devices and do not carry -a slice table. On the other hand, Zip disks, which use the same driver, -are considered hard disks by the vendor, so for compatibility, you should -use a slice table. -.Pp -The driver will handle either type of disk with or without a slice -table, but for compatibility, you should generally create disks -that follow the vendor's behavior. -.Pp -To create a UFS LS-120 disk (no slice table), -First, make sure there is no slice table on the disk): -.Dl # dd if=/dev/zero of=/dev/wfd0 count=16 -.Pp -Next, disklabel the disk: -.Dl # disklabel -rw wfd0 fd120m -.Pp -Then newfs as usual: -.Dl # newfs /dev/rwfd0a -.Pp -To create a standard 1.44mb floppy in a LS-120 drive, do the same -procedure, but use -.Ar fd1440 -as the disk layout when using the -.Nm disklabel -command. -.Sh KERNEL CONFIGURATION -Only one -.Nm -device is necessary in the config file; data structures are dynamically -allocated as disks are found on the -.Tn IDE -buses. -.Sh NOTES -This driver is attached to the -.Xr wdc 4 -IDE/ATAPI disk controller driver. It will not work unless -IDE controllers have been configured and enabled in the kernel. -.Sh BUGS -Floppy formatting is not yet supported. -.Pp -This driver is still a beta version. -If you have problems, please report them to -.Aq bugs@FreeBSD.org -and the author. -.Sh FILES -.Bl -tag -width /dev/rwfdXXXXX -compact -.It Pa /dev/rwfd Ns Ar u -raw mode -.Tn ATAPI -floppy -.Ar u , -accessed as an unpartitioned device -.Sm off -.It Pa /dev/wfd Ar u Pa s Ar n -.Sm on -block mode -.Tn ATAPI -floppy disk unit -.Ar u , -slice -.Ar n , -accessed as an unpartitioned device -.Sm off -.It Pa /dev/rwfd Ar u Pa s Ar n -.Sm on -raw mode -.Tn ATAPI -floppy disk unit -.Ar u , -slice -.Ar n , -accessed as an unpartitioned device -.It Pa /dev/wfd Ns Ar u Ns Ar p -block mode -.Tn ATAPI -floppy disk unit -.Ar u , -first -.Fx -slice, partition -.Ar p -.It Pa /dev/rwfd Ns Ar u Ns Ar p -raw mode -.Tn ATAPI -floppy disk unit -.Ar u , -first -.Fx -slice, partition -.Ar p -.Sm off -.It Pa /dev/wfd Ar u Pa s Ar n Ar p -.Sm on -block mode -.Tn ATAPI -floppy disk unit -.Ar u , -.Ar n Ns th -slice, partition -.Ar p -.Sm off -.It Pa /dev/rwfd Ar u Pa s Ar n Ar p -.Sm on -raw mode -.Tn ATAPI -floppy disk unit -.Ar u , -.Ar n Ns th -slice, partition -.Ar p -.El -.Sh SEE ALSO -.Xr wcd 4 , -.Xr wd 4 , -.Xr disklabel 5 , -.Xr disklabel 8 , -.Xr fdisk 8 -.Sh AUTHORS -.An "Junichi Satoh" Aq junichi@jp.FreeBSD.org -.Sh HISTORY -The -.Nm -driver first appeared in -.Fx 2.2.6 . diff --git a/sys/bus/isa/i386/isa_compat.h b/sys/bus/isa/i386/isa_compat.h index 33e11a20db..b1726dd758 100644 --- a/sys/bus/isa/i386/isa_compat.h +++ b/sys/bus/isa/i386/isa_compat.h @@ -24,11 +24,10 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/isa/isa_compat.h,v 1.27.2.11 2002/10/05 18:31:48 scottl Exp $ - * $DragonFly: src/sys/bus/isa/i386/isa_compat.h,v 1.3 2003/08/07 21:16:46 dillon Exp $ + * $DragonFly: src/sys/bus/isa/i386/isa_compat.h,v 1.4 2003/11/22 09:50:35 asmodai Exp $ */ #include "use_vt.h" -#include "use_wdc.h" #include "use_cx.h" #include "use_el.h" #include "use_le.h" @@ -73,7 +72,6 @@ struct old_isa_driver { }; extern struct isa_driver vtdriver; -extern struct isa_driver wdcdriver; extern struct isa_driver cxdriver; extern struct isa_driver eldriver; extern struct isa_driver ledriver; @@ -170,9 +168,6 @@ static struct old_isa_driver old_drivers[] = { /* BIO */ -#if NWDC > 0 - { INTR_TYPE_BIO, &wdcdriver }, -#endif #if NMCD > 0 { INTR_TYPE_BIO, &mcddriver }, #endif diff --git a/sys/conf/files.i386 b/sys/conf/files.i386 index 5f39c43561..a0df22c419 100644 --- a/sys/conf/files.i386 +++ b/sys/conf/files.i386 @@ -2,7 +2,7 @@ # files marked standard are always included. # # $FreeBSD: src/sys/conf/files.i386,v 1.307.2.38 2003/01/02 20:41:33 kan Exp $ -# $DragonFly: src/sys/conf/Attic/files.i386,v 1.7 2003/10/01 18:21:44 dillon Exp $ +# $DragonFly: src/sys/conf/Attic/files.i386,v 1.8 2003/11/22 09:50:35 asmodai Exp $ # # The long compile-with and dependency lines are required because of # limitations in config: backslash-newline doesn't work in strings, and @@ -244,8 +244,6 @@ emulation/ibcs2/i386/ibcs2_xenix.c optional ibcs2 emulation/ibcs2/i386/ibcs2_xenix_sysent.c optional ibcs2 emulation/ibcs2/coff/imgact_coff.c optional ibcs2 i386/isa/asc.c optional asc -i386/isa/atapi.c optional wdc \ - warning "The wdc driver is obsolete. Please use the ata driver!" i386/isa/clock.c standard dev/serial/cronyx/cronyx.c optional cx dev/video/ctx/ctx.c optional ctx @@ -358,15 +356,6 @@ dev/sound/isa/i386/spkr/spkr.c optional speaker dev/serial/stl/stallion.c optional stl dev/misc/tw/tw.c optional tw dev/video/i386/vesa/vesa.c optional vga vesa -dev/disk/wd/wd.c optional wd \ - warning "The wd driver is obsolete. Please use the atadisk driver!" -dev/disk/wd/wd.c optional wdc -dev/disk/wcd/wd_cd.c optional wcd wdc \ - warning "The wcd driver is obsolete. Please use the atapicd driver!" -dev/disk/wfd/wfd.c optional wfd wdc \ - warning "The wfd driver is obsolete. Please use the atapifd driver!" -dev/disk/wst/wst.c optional wst wdc \ - warning "The wst driver is obsolete. Please use the atapist driver!" dev/disk/wt/wt.c optional wt emulation/linux/i386/imgact_linux.c optional compat_linux emulation/linux/i386/linux_dummy.c optional compat_linux @@ -506,4 +495,3 @@ netproto/smb/smb_smb.c optional netsmb netproto/smb/smb_subr.c optional netsmb netproto/smb/smb_trantcp.c optional netsmb netproto/smb/smb_usr.c optional netsmb -bus/pci/ide_pci.c optional wdc pci diff --git a/sys/config/LINT b/sys/config/LINT index 0f5796d73c..f36460f12a 100644 --- a/sys/config/LINT +++ b/sys/config/LINT @@ -3,7 +3,7 @@ # as much of the source tree as it can. # # $FreeBSD: src/sys/i386/conf/LINT,v 1.749.2.144 2003/06/04 17:56:59 sam Exp $ -# $DragonFly: src/sys/config/LINT,v 1.10 2003/11/09 19:04:35 drhodus Exp $ +# $DragonFly: src/sys/config/LINT,v 1.11 2003/11/22 09:50:36 asmodai Exp $ # # NB: You probably don't want to try running a kernel built from this # file. Instead, you should start from GENERIC, and add options from @@ -1288,79 +1288,6 @@ options ATA_STATIC_ID #device ata0 at isa? port IO_WD1 irq 14 #device ata1 at isa? port IO_WD2 irq 15 -# -# ST-506, ESDI, and IDE hard disks: `wdc' and `wd' -# -# The flags fields are used to enable the multi-sector I/O and -# the 32BIT I/O modes. The flags may be used in either the controller -# definition or in the individual disk definitions. The controller -# definition is supported for the boot configuration stuff. -# -# Each drive has a 16 bit flags value defined: -# The low 8 bits are the maximum value for the multi-sector I/O, -# where 0xff defaults to the maximum that the drive can handle. -# The high bit of the 16 bit flags (0x8000) allows probing for -# 32 bit transfers. Bit 14 (0x4000) enables a hack to wake -# up powered-down laptop drives. Bit 13 (0x2000) allows -# probing for PCI IDE DMA controllers, such as Intel's PIIX -# south bridges. Bit 12 (0x1000) sets LBA mode instead of the -# default CHS mode for accessing the drive. See the wd.4 man page. -# -# The flags field for the drives can be specified in the controller -# specification with the low 16 bits for drive 0, and the high 16 bits -# for drive 1. -# e.g.: -#device wdc0 at isa? port IO_WD1 irq 14 flags 0x00ff8004 -# -# specifies that drive 0 will be allowed to probe for 32 bit transfers and -# a maximum multi-sector transfer of 4 sectors, and drive 1 will not be -# allowed to probe for 32 bit transfers, but will allow multi-sector -# transfers up to the maximum that the drive supports. -# -# If you are using a PCI controller that is not running in compatibility -# mode (for example, it is a 2nd IDE PCI interface), then use config line(s) -# such as: -# -#device wdc2 at isa? port 0 flags 0xa0ffa0ff -#device wd4 at wdc2 drive 0 -#device wd5 at wdc2 drive 1 -# -#device wdc3 at isa? port 0 flags 0xa0ffa0ff -#device wd6 at wdc3 drive 0 -#device wd7 at wdc3 drive 1 -# -# Note that the above config would be useful for a Promise card, when used -# on a MB that already has a PIIX controller. Note the bogus irq and port -# entries. These are automatically filled in by the IDE/PCI support. -# -# This driver must be commented out because it is mutually exclusive with -# the ata(4) driver. -# -device wdc0 at isa? port IO_WD1 irq 14 -device wd0 at wdc0 drive 0 -device wd1 at wdc0 drive 1 -device wdc1 at isa? port IO_WD2 irq 15 -device wd2 at wdc1 drive 0 -device wd3 at wdc1 drive 1 - -# -# This option allow you to override the default probe time for IDE -# devices, to get a faster probe. Setting this below 10000 violate -# the IDE specs, but may still work for you (it will work for most -# people). -# -options IDE_DELAY=8000 # Be optimistic about Joe IDE device - -# IDE CD-ROM & CD-R/RW driver - requires wdc controller -device wcd - -# IDE floppy driver - requires wdc controller -device wfd - -# IDE tape driver - requires wdc controller -device wst - - # # Standard floppy disk controllers: `fdc' and `fd' # diff --git a/sys/dev/disk/wcd/wd_cd.c b/sys/dev/disk/wcd/wd_cd.c deleted file mode 100644 index bd8ec9952d..0000000000 --- a/sys/dev/disk/wcd/wd_cd.c +++ /dev/null @@ -1,1482 +0,0 @@ -/*- - * Copyright (c) 1998, 1999 Søren Schmidt - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * without modification, immediately at the beginning of the file. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: src/sys/i386/isa/wd_cd.c,v 1.29 2000/01/29 16:00:33 peter Exp $ - * $DragonFly: src/sys/dev/disk/wcd/Attic/wd_cd.c,v 1.8 2003/08/07 21:16:54 dillon Exp $ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "wd_cd.h" - -static d_open_t acdopen; -static d_close_t acdclose; -static d_ioctl_t acdioctl; -static d_strategy_t acdstrategy; - -#define CDEV_MAJOR 69 -static struct cdevsw acd_cdevsw = { - /* name */ "wcd", - /* maj */ CDEV_MAJOR, - /* flags */ D_DISK, - /* port */ NULL, - /* autoq */ 0, - - /* open */ acdopen, - /* close */ acdclose, - /* read */ physread, - /* write */ physwrite, - /* ioctl */ acdioctl, - /* poll */ nopoll, - /* mmap */ nommap, - /* strategy */ acdstrategy, - /* dump */ nodump, - /* psize */ nopsize -}; - -#define NUNIT 16 /* Max # of devices */ - -#define F_BOPEN 0x0001 /* The block device is opened */ -#define F_MEDIA_CHANGED 0x0002 /* The media have changed since open */ -#define F_DEBUG 0x0004 /* Print debug info */ -#define F_LOCKED 0x0008 /* This unit is locked (or should be) */ -#define F_TRACK_PREP 0x0010 /* Track should be prep'ed */ -#define F_TRACK_PREPED 0x0020 /* Track has been prep'ed */ -#define F_DISK_PREPED 0x0040 /* Disk has been prep'ed */ -#define F_WRITTEN 0x0080 /* The medium has been written to */ - -static struct acd *acdtab[NUNIT]; -static int acdnlun = 0; /* Number of configured drives */ - -int acdattach(struct atapi *, int, struct atapi_params *, int); -static struct acd *acd_init_lun(struct atapi *, int, struct atapi_params *, int, -struct devstat *); -static void acd_start(struct acd *); -static void acd_done(struct acd *, struct buf *, int, struct atapires); -static int acd_read_toc(struct acd *); -static int acd_request_wait(struct acd *, u_char, u_char, u_char, u_char, u_char, u_char, u_char, u_char, u_char, u_char, char *, int); -static void acd_describe(struct acd *); -static int acd_setchan(struct acd *, u_char, u_char, u_char, u_char); -static int acd_eject(struct acd *, int); -static void acd_select_slot(struct acd *); -static int acd_open_disk(struct acd *, int); -static int acd_open_track(struct acd *, struct wormio_prepare_track *); -static int acd_close_track(struct acd *); -static int acd_close_disk(struct acd *); -static int acd_read_track_info(struct acd *cdp, int lba, struct acd_track_info *info); -static int acd_blank_disk(struct acd *); -static void atapi_dump(int ctrlr, int lun, char *label, void *data, int len); -static void atapi_error(struct atapi *ata, int unit, struct atapires result); - -struct acd * -acd_init_lun(struct atapi *ata, int unit, struct atapi_params *ap, int lun, - struct devstat *device_stats) -{ - struct acd *ptr; - - if (!(ptr = malloc(sizeof(struct acd), M_TEMP, M_NOWAIT))) - return NULL; - bzero(ptr, sizeof(struct acd)); - bufq_init(&ptr->buf_queue); - ptr->ata = ata; - ptr->unit = unit; - ptr->lun = lun; - ptr->param = ap; - ptr->flags = F_MEDIA_CHANGED; - ptr->flags &= ~(F_WRITTEN|F_TRACK_PREP|F_TRACK_PREPED); - ptr->block_size = 2048; - ptr->refcnt = 0; - ptr->slot = -1; - ptr->changer_info = NULL; - if (device_stats == NULL) { - if (!(ptr->device_stats = malloc(sizeof(struct devstat), - M_TEMP, M_NOWAIT))) - return NULL; - bzero(ptr->device_stats, sizeof(struct devstat)); - } - else - ptr->device_stats = device_stats; - make_dev(&acd_cdevsw, dkmakeminor(lun, 0, 0), - UID_ROOT, GID_OPERATOR, 0640, "rwcd%da", lun); - make_dev(&acd_cdevsw, dkmakeminor(lun, 0, RAW_PART), - UID_ROOT, GID_OPERATOR, 0640, "rwcd%dc", lun); - make_dev(&acd_cdevsw, dkmakeminor(lun, 0, 0), - UID_ROOT, GID_OPERATOR, 0640, "wcd%da", lun); - make_dev(&acd_cdevsw, dkmakeminor(lun, 0, RAW_PART), - UID_ROOT, GID_OPERATOR, 0640, "wcd%dc", lun); - return ptr; -} - -int -acdattach(struct atapi *ata, int unit, struct atapi_params *ap, int debug) -{ - struct acd *cdp; - struct atapires result; - struct changer *chp; - int i, count; - - if (acdnlun >= NUNIT) { - printf("wcd: too many units\n"); - return 0; - } - if (!atapi_request_immediate) { - printf("wcd: configuration error, ATAPI code not present!\n"); - return 0; - } - if ((cdp = acd_init_lun(ata, unit, ap, acdnlun, NULL)) == NULL) { - printf("wcd: out of memory\n"); - return 0; - } - acdtab[acdnlun] = cdp; - - if (debug) { - cdp->flags |= F_DEBUG; - atapi_dump(cdp->ata->ctrlr, cdp->lun, "info", ap, sizeof(*ap)); - } - - /* Get drive capabilities, some drives needs this repeated */ - for (count = 0 ; count < 5 ; count++) { - result = atapi_request_immediate(ata, unit, - ATAPI_MODE_SENSE, - 0, ATAPI_CDROM_CAP_PAGE, - 0, 0, 0, 0, - sizeof(cdp->cap)>>8, sizeof(cdp->cap), - 0, 0, 0, 0, 0, 0, 0, - (char *)&cdp->cap, sizeof(cdp->cap)); - if (result.code == 0 || result.code == RES_UNDERRUN) - break; - } - - /* Some drives have shorter capabilities page. */ - if (result.code == RES_UNDERRUN) - result.code = 0; - - if (result.code == 0) { - cdp->cap.max_speed = ntohs(cdp->cap.max_speed); - cdp->cap.max_vol_levels = ntohs(cdp->cap.max_vol_levels); - cdp->cap.buf_size = ntohs(cdp->cap.buf_size); - cdp->cap.cur_speed = ntohs(cdp->cap.cur_speed); - acd_describe(cdp); - if (cdp->flags & F_DEBUG) - atapi_dump(cdp->ata->ctrlr, cdp->lun, "cap", &cdp->cap, - sizeof(cdp->cap)); - } - /* If this is a changer device, allocate the neeeded lun's */ - if (cdp->cap.mech == MST_MECH_CHANGER) { - char string[16]; - struct acd *tmpcdp = cdp; - - chp = malloc(sizeof(struct changer), M_TEMP, M_NOWAIT); - if (chp == NULL) { - printf("wcd: out of memory\n"); - return 0; - } - bzero(chp, sizeof(struct changer)); - result = atapi_request_immediate(ata, unit, ATAPI_MECH_STATUS, - 0, 0, 0, 0, 0, 0, 0, - sizeof(struct changer)>>8, - sizeof(struct changer), - 0, 0, 0, 0, 0, 0, - (char *)chp, sizeof(struct changer)); - if (cdp->flags & F_DEBUG) { - printf("result.code=%d curr=%02x slots=%d len=%d\n", - result.code, chp->current_slot, chp->slots, - htons(chp->table_length)); - } - if (result.code == RES_UNDERRUN) - result.code = 0; - - if (result.code == 0) { - chp->table_length = htons(chp->table_length); - for (i = 0; i < chp->slots && acdnlun < NUNIT; i++) { - if (i > 0) { - tmpcdp = acd_init_lun(ata, unit, ap, acdnlun, - cdp->device_stats); - if (!tmpcdp) { - printf("wcd: out of memory\n"); - return 0; - } - } - tmpcdp->slot = i; - tmpcdp->changer_info = chp; - printf("wcd%d: changer slot %d %s\n", acdnlun, i, - (chp->slot[i].present ? "disk present" : "no disk")); - acdtab[acdnlun++] = tmpcdp; - } - if (acdnlun >= NUNIT) { - printf("wcd: too many units\n"); - return 0; - } - } - sprintf(string, "wcd%d-", cdp->lun); - devstat_add_entry(cdp->device_stats, string, tmpcdp->lun, DEV_BSIZE, - DEVSTAT_NO_ORDERED_TAGS, - DEVSTAT_TYPE_CDROM | DEVSTAT_TYPE_IF_IDE, - DEVSTAT_PRIORITY_CD); - } - else { - acdnlun++; - devstat_add_entry(cdp->device_stats, "wcd", cdp->lun, DEV_BSIZE, - DEVSTAT_NO_ORDERED_TAGS, - DEVSTAT_TYPE_CDROM | DEVSTAT_TYPE_IF_IDE, - DEVSTAT_PRIORITY_CD); - } - return 1; -} - -void -acd_describe(struct acd *cdp) -{ - int comma; - char *mechanism; - - printf("wcd%d: drive speed ", cdp->lun); - if (cdp->cap.cur_speed != cdp->cap.max_speed) - printf("%d - ", cdp->cap.cur_speed * 1000 / 1024); - printf("%dKB/sec", cdp->cap.max_speed * 1000 / 1024); - if (cdp->cap.buf_size) - printf(", %dKB cache\n", cdp->cap.buf_size); - - printf("wcd%d: supported read types:", cdp->lun); - comma = 0; - if (cdp->cap.read_cdr) { - printf(" CD-R"); comma = 1; - } - if (cdp->cap.read_cdrw) { - printf("%s CD-RW", comma ? "," : ""); comma = 1; - } - if (cdp->cap.cd_da) { - printf("%s CD-DA", comma ? "," : ""); comma = 1; - } - if (cdp->cap.method2) - printf("%s packet track", comma ? "," : ""); - if (cdp->cap.write_cdr || cdp->cap.write_cdrw) { - printf("\nwcd%d: supported write types:", cdp->lun); - comma = 0; - if (cdp->cap.write_cdr) { - printf(" CD-R" ); comma = 1; - } - if (cdp->cap.write_cdrw) { - printf("%s CD-RW", comma ? "," : ""); comma = 1; - } - if (cdp->cap.test_write) { - printf("%s test write", comma ? "," : ""); comma = 1; - } - } - if (cdp->cap.audio_play) { - printf("\nwcd%d: Audio: ", cdp->lun); - if (cdp->cap.audio_play) - printf("play"); - if (cdp->cap.max_vol_levels) - printf(", %d volume levels", cdp->cap.max_vol_levels); - } - printf("\nwcd%d: Mechanism: ", cdp->lun); - switch (cdp->cap.mech) { - case MST_MECH_CADDY: - mechanism = "caddy"; break; - case MST_MECH_TRAY: - mechanism = "tray"; break; - case MST_MECH_POPUP: - mechanism = "popup"; break; - case MST_MECH_CHANGER: - mechanism = "changer"; break; - case MST_MECH_CARTRIDGE: - mechanism = "cartridge"; break; - default: - mechanism = 0; break; - } - if (mechanism) - printf("%s%s", cdp->cap.eject ? "ejectable " : "", mechanism); - else if (cdp->cap.eject) - printf("ejectable"); - - if (cdp->cap.mech != MST_MECH_CHANGER) { - printf("\nwcd%d: Medium: ", cdp->lun); - switch (cdp->cap.medium_type & MST_TYPE_MASK_HIGH) { - case MST_CDROM: - printf("CD-ROM "); break; - case MST_CDR: - printf("CD-R "); break; - case MST_CDRW: - printf("CD-RW "); break; - case MST_DOOR_OPEN: - printf("door open"); break; - case MST_NO_DISC: - printf("no/blank disc inside"); break; - case MST_FMT_ERROR: - printf("medium format error"); break; - } - if ((cdp->cap.medium_type & MST_TYPE_MASK_HIGH) < MST_TYPE_MASK_HIGH) { - switch (cdp->cap.medium_type & MST_TYPE_MASK_LOW) { - case MST_DATA_120: - printf("120mm data disc loaded"); break; - case MST_AUDIO_120: - printf("120mm audio disc loaded"); break; - case MST_COMB_120: - printf("120mm data/audio disc loaded"); break; - case MST_PHOTO_120: - printf("120mm photo disc loaded"); break; - case MST_DATA_80: - printf("80mm data disc loaded"); break; - case MST_AUDIO_80: - printf("80mm audio disc loaded"); break; - case MST_COMB_80: - printf("80mm data/audio disc loaded"); break; - case MST_PHOTO_80: - printf("80mm photo disc loaded"); break; - case MST_FMT_NONE: - switch (cdp->cap.medium_type & MST_TYPE_MASK_HIGH) { - case MST_CDROM: - printf("unknown medium"); break; - case MST_CDR: - case MST_CDRW: - printf("blank medium"); break; - } - break; - default: - printf("unknown type=0x%x", cdp->cap.medium_type); break; - } - } - } - if (cdp->cap.lock) - printf(cdp->cap.locked ? ", locked" : ", unlocked"); - if (cdp->cap.prevent) - printf(", lock protected"); - printf("\n"); -} - -static int -acdopen(dev_t dev, int flags, int fmt, struct thread *td) -{ - int lun = dkunit(dev); - struct acd *cdp; - - if (lun >= acdnlun || !atapi_request_immediate) - return ENXIO; - cdp = acdtab[lun]; - - if (!(cdp->flags & F_BOPEN) && !cdp->refcnt) { - /* Prevent user eject */ - acd_request_wait(cdp, ATAPI_PREVENT_ALLOW, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0); - cdp->flags |= F_LOCKED; - } - if (fmt == S_IFBLK) - cdp->flags |= F_BOPEN; - else - ++cdp->refcnt; - dev->si_bsize_phys = cdp->block_size; - if (!(flags & O_NONBLOCK) && acd_read_toc(cdp) && !(flags & FWRITE)) - printf("acd%d: read_toc failed\n", lun); - return 0; -} - -int -acdclose(dev_t dev, int flags, int fmt, struct thread *td) -{ - struct acd *cdp = acdtab[dkunit(dev)]; - - if (fmt == S_IFBLK) - cdp->flags &= ~F_BOPEN; - else - --cdp->refcnt; - - /* Are we the last open ?? */ - if (!(cdp->flags & F_BOPEN) && !cdp->refcnt) { - /* Yup, do we need to close any written tracks */ - if ((flags & FWRITE) != 0) { - if ((cdp->flags & F_TRACK_PREPED) != 0) { - acd_close_track(cdp); - cdp->flags &= ~(F_TRACK_PREPED | F_TRACK_PREP); - } - } - /* Allow the user eject */ - acd_request_wait(cdp, ATAPI_PREVENT_ALLOW, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - } - cdp->flags &= ~F_LOCKED; - return 0; -} - -void -acdstrategy(struct buf *bp) -{ - int lun = dkunit(bp->b_dev); - struct acd *cdp = acdtab[lun]; - int x; - -#ifdef NOTYET - /* allow write only on CD-R/RW media */ /* all for now SOS */ - if (!(bp->b_flags & B_READ) && !(writeable_media)) { - bp->b_error = EROFS; - bp->b_flags |= B_ERROR; - biodone(bp); - return; - } -#endif - - if (bp->b_bcount == 0) { - bp->b_resid = 0; - biodone(bp); - return; - } - - bp->b_pblkno = bp->b_blkno; - bp->b_resid = bp->b_bcount; - - x = splbio(); - bufqdisksort(&cdp->buf_queue, bp); - acd_start(cdp); - splx(x); -} - -static void -acd_start(struct acd *cdp) -{ - struct buf *bp = bufq_first(&cdp->buf_queue); - u_long lba, blocks; - int cmd; - int count; - - if (!bp) - return; - - bufq_remove(&cdp->buf_queue, bp); - - /* Should reject all queued entries if media have changed. */ - if (cdp->flags & F_MEDIA_CHANGED) { - bp->b_error = EIO; - bp->b_flags |= B_ERROR; - biodone(bp); - return; - } - - acd_select_slot(cdp); - - if ((bp->b_flags & B_READ) == B_WRITE) { - if ((cdp->flags & F_TRACK_PREPED) == 0) { - if ((cdp->flags & F_TRACK_PREP) == 0) { - printf("wcd%d: sequence error\n", cdp->lun); - bp->b_error = EIO; - bp->b_flags |= B_ERROR; - biodone(bp); - return; - } else { - if (acd_open_track(cdp, &cdp->preptrack) != 0) { - biodone(bp); - return; - } - cdp->flags |= F_TRACK_PREPED; - } - } - } - - if (bp->b_flags & B_READ) -#ifdef NOTYET - lba = bp->b_offset / cdp->block_size; -#else - lba = bp->b_blkno / (cdp->block_size / DEV_BSIZE); -#endif - else - lba = cdp->next_writeable_lba + (bp->b_offset / cdp->block_size); - blocks = (bp->b_bcount + (cdp->block_size - 1)) / cdp->block_size; - - if ((bp->b_flags & B_READ) == B_WRITE) { - cmd = ATAPI_WRITE_BIG; - count = -bp->b_bcount; - } else { - cmd = ATAPI_READ_BIG; - count = bp->b_bcount; - } - - devstat_start_transaction(cdp->device_stats); - - atapi_request_callback(cdp->ata, cdp->unit, cmd, 0, - lba>>24, lba>>16, lba>>8, lba, 0, - blocks>>8, blocks, 0, 0, 0, 0, 0, 0, 0, - (u_char *)bp->b_data, count, - (atapi_callback_t *)acd_done, cdp, bp); -} - -static void -acd_done(struct acd *cdp, struct buf *bp, int resid, struct atapires result) -{ - - if (result.code) { - atapi_error(cdp->ata, cdp->unit, result); - bp->b_error = EIO; - bp->b_flags |= B_ERROR; - } else { - bp->b_resid = resid; - if ((bp->b_flags & B_READ) == B_WRITE) - cdp->flags |= F_WRITTEN; - } - devstat_end_transaction_buf(cdp->device_stats, bp); - biodone(bp); - acd_start(cdp); -} - -static int -acd_request_wait(struct acd *cdp, u_char cmd, u_char a1, u_char a2, - u_char a3, u_char a4, u_char a5, u_char a6, u_char a7, u_char a8, - u_char a9, char *addr, int count) -{ - struct atapires result; - - result = atapi_request_wait(cdp->ata, cdp->unit, cmd, a1, a2, a3, a4, a5, - a6, a7, a8, a9, 0, 0, 0, 0, 0, 0, addr, count); - if (result.code) { - atapi_error(cdp->ata, cdp->unit, result); - return EIO; - } - return 0; -} - -static __inline void -lba2msf(int lba, u_char *m, u_char *s, u_char *f) -{ - lba += 150; - lba &= 0xffffff; - *m = lba / (60 * 75); - lba %= (60 * 75); - *s = lba / 75; - *f = lba % 75; -} - -static __inline int -msf2lba(u_char m, u_char s, u_char f) -{ - return (m * 60 + s) * 75 + f - 150; -} - -int -acdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td) -{ - int lun = dkunit(dev); - struct acd *cdp = acdtab[lun]; - int error = 0; - - if (cdp->flags & F_MEDIA_CHANGED) - switch (cmd) { - case CDIOCRESET: - break; - default: - acd_read_toc(cdp); - acd_request_wait(cdp, ATAPI_PREVENT_ALLOW, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0); - cdp->flags |= F_LOCKED; - break; - } - switch (cmd) { -/* - case CDIOCRESUME: - bzero(cdb); - cdb->cmd = ATAPI_PAUSE; - cdb->b8 = 0x01; - return atapi_cmd_wait(cdp->ata, cdp->unit, cdb, 0, 0, timout, 0); -*/ - case CDIOCRESUME: - return acd_request_wait(cdp, ATAPI_PAUSE, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0); - - case CDIOCPAUSE: - return acd_request_wait(cdp, ATAPI_PAUSE, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - - case CDIOCSTART: - return acd_request_wait(cdp, ATAPI_START_STOP, - 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0); - - case CDIOCSTOP: - return acd_request_wait(cdp, ATAPI_START_STOP, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - - case CDIOCALLOW: - acd_select_slot(cdp); - cdp->flags &= ~F_LOCKED; - return acd_request_wait(cdp, ATAPI_PREVENT_ALLOW, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - - case CDIOCPREVENT: - acd_select_slot(cdp); - cdp->flags |= F_LOCKED; - return acd_request_wait(cdp, ATAPI_PREVENT_ALLOW, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0); - - case CDIOCRESET: - error = suser(td); - if (error) - return (error); - return acd_request_wait(cdp, ATAPI_TEST_UNIT_READY, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - - case CDIOCEJECT: - if ((cdp->flags & F_BOPEN) && cdp->refcnt) - return EBUSY; - return acd_eject(cdp, 0); - - case CDIOCCLOSE: - if ((cdp->flags & F_BOPEN) && cdp->refcnt) - return 0; - return acd_eject(cdp, 1); - - case CDIOREADTOCHEADER: - if (!cdp->toc.hdr.ending_track) - return EIO; - bcopy(&cdp->toc.hdr, addr, sizeof(cdp->toc.hdr)); - break; - - case CDIOREADTOCENTRYS: - { - struct ioc_read_toc_entry *te = (struct ioc_read_toc_entry *)addr; - struct toc *toc = &cdp->toc; - struct toc buf; - u_long len; - u_char starting_track = te->starting_track; - - if (!cdp->toc.hdr.ending_track) - return EIO; - - if (te->data_len < sizeof(toc->tab[0]) || - (te->data_len % sizeof(toc->tab[0])) != 0 || - (te->address_format != CD_MSF_FORMAT && - te->address_format != CD_LBA_FORMAT)) - return EINVAL; - - if (!starting_track) - starting_track = toc->hdr.starting_track; - else if (starting_track == 170) - starting_track = toc->hdr.ending_track + 1; - else if (starting_track < toc->hdr.starting_track || - starting_track > toc->hdr.ending_track + 1) - return EINVAL; - - len = ((toc->hdr.ending_track + 1 - starting_track) + 1) * - sizeof(toc->tab[0]); - if (te->data_len < len) - len = te->data_len; - if (len > sizeof(toc->tab)) - return EINVAL; - - if (te->address_format == CD_MSF_FORMAT) { - struct cd_toc_entry *entry; - - buf = cdp->toc; - toc = &buf; - entry = toc->tab + (toc->hdr.ending_track + 1 - - toc->hdr.starting_track) + 1; - while (--entry >= toc->tab) - lba2msf(ntohl(entry->addr.lba), &entry->addr.msf.minute, - &entry->addr.msf.second, &entry->addr.msf.frame); - } - return copyout(toc->tab + starting_track - toc->hdr.starting_track, - te->data, len); - } - - case CDIOREADTOCENTRY: - { - struct ioc_read_toc_single_entry *te = - (struct ioc_read_toc_single_entry *)addr; - struct toc *toc = &cdp->toc; - struct toc buf; - u_char track = te->track; - - if (!cdp->toc.hdr.ending_track) - return EIO; - - if (te->address_format != CD_MSF_FORMAT && - te->address_format != CD_LBA_FORMAT) - return EINVAL; - - if (!track) - track = toc->hdr.starting_track; - else if (track == 170) - track = toc->hdr.ending_track + 1; - else if (track < toc->hdr.starting_track || - track > toc->hdr.ending_track + 1) - return EINVAL; - - if (te->address_format == CD_MSF_FORMAT) { - struct cd_toc_entry *entry; - - buf = cdp->toc; - toc = &buf; - entry = toc->tab + (track - toc->hdr.starting_track); - lba2msf(ntohl(entry->addr.lba), &entry->addr.msf.minute, - &entry->addr.msf.second, &entry->addr.msf.frame); - } - bcopy(toc->tab + track - toc->hdr.starting_track, - &te->entry, sizeof(struct cd_toc_entry)); - } - break; - - case CDIOCREADSUBCHANNEL: - { - struct ioc_read_subchannel *args = - (struct ioc_read_subchannel *)addr; - struct cd_sub_channel_info data; - u_long len = args->data_len; - int abslba, rellba; - - if (len > sizeof(data) || - len < sizeof(struct cd_sub_channel_header)) - return EINVAL; - - if (acd_request_wait(cdp, ATAPI_READ_SUBCHANNEL, - 0, 0x40, 1, 0, 0, 0, - sizeof(cdp->subchan)>>8, sizeof(cdp->subchan), - 0, - (char *)&cdp->subchan, - sizeof(cdp->subchan)) != 0) - return EIO; - if (cdp->flags & F_DEBUG) - atapi_dump(cdp->ata->ctrlr, cdp->lun, "subchan", &cdp->subchan, - sizeof(cdp->subchan)); - - abslba = cdp->subchan.abslba; - rellba = cdp->subchan.rellba; - if (args->address_format == CD_MSF_FORMAT) { - lba2msf(ntohl(abslba), - &data.what.position.absaddr.msf.minute, - &data.what.position.absaddr.msf.second, - &data.what.position.absaddr.msf.frame); - lba2msf(ntohl(rellba), - &data.what.position.reladdr.msf.minute, - &data.what.position.reladdr.msf.second, - &data.what.position.reladdr.msf.frame); - } else { - data.what.position.absaddr.lba = abslba; - data.what.position.reladdr.lba = rellba; - } - data.header.audio_status = cdp->subchan.audio_status; - data.what.position.control = cdp->subchan.control & 0xf; - data.what.position.addr_type = cdp->subchan.control >> 4; - data.what.position.track_number = cdp->subchan.track; - data.what.position.index_number = cdp->subchan.indx; - return copyout(&data, args->data, len); - } - - case CDIOCPLAYMSF: - { - struct ioc_play_msf *args = (struct ioc_play_msf *)addr; - - return acd_request_wait(cdp, ATAPI_PLAY_MSF, 0, 0, - args->start_m, args->start_s, args->start_f, - args->end_m, args->end_s, args->end_f, - 0, 0, 0); - } - - case CDIOCPLAYBLOCKS: - { - struct ioc_play_blocks *args = (struct ioc_play_blocks *)addr; - - return acd_request_wait(cdp, ATAPI_PLAY_BIG, 0, - args->blk>>24 & 0xff, args->blk>>16 & 0xff, - args->blk>>8 & 0xff, args->blk & 0xff, - args->len>>24 & 0xff, args->len>>16 & 0xff, - args->len>>8 & 0xff, args->len & 0xff, - 0, 0); - } - - case CDIOCPLAYTRACKS: - { - struct ioc_play_track *args = (struct ioc_play_track *)addr; - u_long start, len; - int t1, t2; - - if (!cdp->toc.hdr.ending_track) - return EIO; - - if (args->end_track < cdp->toc.hdr.ending_track + 1) - ++args->end_track; - if (args->end_track > cdp->toc.hdr.ending_track + 1) - args->end_track = cdp->toc.hdr.ending_track + 1; - t1 = args->start_track - cdp->toc.hdr.starting_track; - t2 = args->end_track - cdp->toc.hdr.starting_track; - if (t1 < 0 || t2 < 0) - return EINVAL; - start = ntohl(cdp->toc.tab[t1].addr.lba); - len = ntohl(cdp->toc.tab[t2].addr.lba) - start; - - return acd_request_wait(cdp, ATAPI_PLAY_BIG, 0, - start>>24 & 0xff, start>>16 & 0xff, - start>>8 & 0xff, start & 0xff, - len>>24 & 0xff, len>>16 & 0xff, - len>>8 & 0xff, len & 0xff, 0, 0); - } - - case CDIOCREADAUDIO: - { - struct ioc_read_audio* args = (struct ioc_read_audio*) addr; - int lba, frames, result = 0; - u_char *buffer, *ubuf = args->buffer; - - if (!cdp->toc.hdr.ending_track) - return EIO; - - if ((frames = args->nframes) < 0) - return EINVAL; - - if (args->address_format == CD_LBA_FORMAT) - lba = args->address.lba; - else if (args->address_format == CD_MSF_FORMAT) - lba = msf2lba(args->address.msf.minute, - args->address.msf.second, - args->address.msf.frame); - else - return EINVAL; -#ifndef CD_BUFFER_BLOCKS -#define CD_BUFFER_BLOCKS 8 -#endif - if (!(buffer = malloc(CD_BUFFER_BLOCKS * 2352, M_TEMP, M_NOWAIT))) - return ENOMEM; - - while (frames > 0) { - u_char blocks; - int size; - - blocks = (frames>CD_BUFFER_BLOCKS) ? CD_BUFFER_BLOCKS : frames; - size = blocks * 2352; - - result = acd_request_wait(cdp, ATAPI_READ_CD, 4, - lba>>24, (lba>>16)&0xff, - (lba>>8)&0xff, lba&0xff, 0, 0, - blocks, 0xf0, buffer, size); - if (result != 0) - break; - - result = copyout(buffer, ubuf, size); - if (result != 0) - break; - - ubuf += size; - frames -= blocks; - lba += blocks; - } - - free(buffer, M_TEMP); - return result; - } - - case CDIOCGETVOL: - { - struct ioc_vol *arg = (struct ioc_vol *)addr; - - error = acd_request_wait(cdp, ATAPI_MODE_SENSE, 0, CDROM_AUDIO_PAGE, - 0, 0, 0, 0, - sizeof(cdp->au)>>8, sizeof(cdp->au), 0, - (char *)&cdp->au, sizeof(cdp->au)); - if (error) - return error; - if (cdp->flags & F_DEBUG) - atapi_dump(cdp->ata->ctrlr, cdp->lun, "au", &cdp->au, - sizeof(cdp->au)); - if (cdp->au.page_code != CDROM_AUDIO_PAGE) - return EIO; - arg->vol[0] = cdp->au.port[0].volume; - arg->vol[1] = cdp->au.port[1].volume; - arg->vol[2] = cdp->au.port[2].volume; - arg->vol[3] = cdp->au.port[3].volume; - } - break; - - case CDIOCSETVOL: - { - struct ioc_vol *arg = (struct ioc_vol *)addr; - - error = acd_request_wait(cdp, ATAPI_MODE_SENSE, 0, CDROM_AUDIO_PAGE, - 0, 0, 0, 0, - sizeof(cdp->au)>>8, sizeof(cdp->au), 0, - (char *)&cdp->au, sizeof(cdp->au)); - if (error) - return error; - if (cdp->flags & F_DEBUG) - atapi_dump(cdp->ata->ctrlr, cdp->lun, "au", &cdp->au, - sizeof(cdp->au)); - if (cdp->au.page_code != CDROM_AUDIO_PAGE) - return EIO; - - error = acd_request_wait(cdp, ATAPI_MODE_SENSE, 0, - CDROM_AUDIO_PAGE_MASK, 0, 0, 0, 0, - sizeof(cdp->aumask)>>8,sizeof(cdp->aumask), - 0, - (char *)&cdp->aumask, sizeof(cdp->aumask)); - if (error) - return error; - if (cdp->flags & F_DEBUG) - atapi_dump(cdp->ata->ctrlr, cdp->lun, "mask", &cdp->aumask, - sizeof(cdp->aumask)); - - cdp->au.data_length = 0; - cdp->au.port[0].channels = CHANNEL_0; - cdp->au.port[1].channels = CHANNEL_1; - cdp->au.port[0].volume = arg->vol[0] & cdp->aumask.port[0].volume; - cdp->au.port[1].volume = arg->vol[1] & cdp->aumask.port[1].volume; - cdp->au.port[2].volume = arg->vol[2] & cdp->aumask.port[2].volume; - cdp->au.port[3].volume = arg->vol[3] & cdp->aumask.port[3].volume; - return acd_request_wait(cdp, ATAPI_MODE_SELECT, 0x10, - 0, 0, 0, 0, 0, - sizeof(cdp->au)>>8, sizeof(cdp->au), - 0, (char *)&cdp->au, -sizeof(cdp->au)); - } - - case CDIOCSETPATCH: - { - struct ioc_patch *arg = (struct ioc_patch *)addr; - - return acd_setchan(cdp, arg->patch[0], arg->patch[1], - arg->patch[2], arg->patch[3]); - } - - case CDIOCSETMONO: - return acd_setchan(cdp, CHANNEL_0|CHANNEL_1, CHANNEL_0|CHANNEL_1, 0, 0); - - case CDIOCSETSTEREO: - return acd_setchan(cdp, CHANNEL_0, CHANNEL_1, 0, 0); - - case CDIOCSETMUTE: - return acd_setchan(cdp, 0, 0, 0, 0); - - case CDIOCSETLEFT: - return acd_setchan(cdp, CHANNEL_0, CHANNEL_0, 0, 0); - - case CDIOCSETRIGHT: - return acd_setchan(cdp, CHANNEL_1, CHANNEL_1, 0, 0); - - case CDRIOCNEXTWRITEABLEADDR: - { - struct acd_track_info track_info; - - if ((error = acd_read_track_info(cdp, 0xff, &track_info))) - break; - if (!track_info.nwa_valid) - return EINVAL; - cdp->next_writeable_lba = track_info.next_writeable_addr; - *(int*)addr = track_info.next_writeable_addr; - } - break; - - case WORMIOCPREPDISK: - { - struct wormio_prepare_disk *w = (struct wormio_prepare_disk *)addr; - - if (w->dummy != 0 && w->dummy != 1) - error = EINVAL; - else { - error = acd_open_disk(cdp, w->dummy); - if (error == 0) { - cdp->flags |= F_DISK_PREPED; - cdp->dummy = w->dummy; - cdp->speed = w->speed; - } - } - } - break; - - case WORMIOCPREPTRACK: - { - struct wormio_prepare_track *w =(struct wormio_prepare_track *)addr; - - if (w->audio != 0 && w->audio != 1) - error = EINVAL; - else if (w->audio == 0 && w->preemp) - error = EINVAL; - else if ((cdp->flags & F_DISK_PREPED) == 0) { - error = EINVAL; - printf("wcd%d: sequence error (PREP_TRACK)\n", cdp->lun); - } else { - cdp->flags |= F_TRACK_PREP; - cdp->preptrack = *w; - } - } - break; - - case WORMIOCFINISHTRACK: - if ((cdp->flags & F_TRACK_PREPED) != 0) - error = acd_close_track(cdp); - cdp->flags &= ~(F_TRACK_PREPED | F_TRACK_PREP); - break; - - case WORMIOCFIXATION: - { - struct wormio_fixation *w = - (struct wormio_fixation *)addr; - - if ((cdp->flags & F_WRITTEN) == 0) - error = EINVAL; - else if (w->toc_type < 0 /* WORM_TOC_TYPE_AUDIO */ || - w->toc_type > 4 /* WORM_TOC_TYPE_CDI */ ) - error = EINVAL; - else if (w->onp != 0 && w->onp != 1) - error = EINVAL; - else { - /* no fixation needed if dummy write */ - if (cdp->dummy == 0) - error = acd_close_disk(cdp); - cdp->flags &= - ~(F_WRITTEN|F_DISK_PREPED|F_TRACK_PREP|F_TRACK_PREPED); - } - } - break; - - case CDRIOCBLANK: - return acd_blank_disk(cdp); - - default: - return ENOTTY; - } - return error; -} - -static int -acd_read_toc(struct acd *cdp) -{ - int ntracks, len; - struct atapires result; - - bzero(&cdp->toc, sizeof(cdp->toc)); - bzero(&cdp->info, sizeof(cdp->info)); - - acd_select_slot(cdp); - - result = atapi_request_wait(cdp->ata, cdp->unit, ATAPI_TEST_UNIT_READY, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0); - - if (result.code == RES_ERR && - (result.error & AER_SKEY) == AER_SK_UNIT_ATTENTION) { - cdp->flags |= F_MEDIA_CHANGED; - cdp->flags &= ~(F_WRITTEN|F_TRACK_PREP|F_TRACK_PREPED); - result = atapi_request_wait(cdp->ata, cdp->unit, ATAPI_TEST_UNIT_READY, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0); - } - - if (result.code) { - atapi_error(cdp->ata, cdp->unit, result); - return EIO; - } - - cdp->flags &= ~F_MEDIA_CHANGED; - - len = sizeof(struct ioc_toc_header) + sizeof(struct cd_toc_entry); - if (acd_request_wait(cdp, ATAPI_READ_TOC, 0, 0, 0, 0, 0, 0, - len>>8, len & 0xff, 0, (char *)&cdp->toc, len) != 0) { - bzero(&cdp->toc, sizeof(cdp->toc)); - return 0; - } - ntracks = cdp->toc.hdr.ending_track - cdp->toc.hdr.starting_track + 1; - if (ntracks <= 0 || ntracks > MAXTRK) { - bzero(&cdp->toc, sizeof(cdp->toc)); - return 0; - } - - len = sizeof(struct ioc_toc_header) + ntracks * sizeof(struct cd_toc_entry); - if (acd_request_wait(cdp, ATAPI_READ_TOC, 0, 0, 0, 0, 0, 0, - len>>8, len & 0xff, 0, (char *)&cdp->toc, len) & 0xff){ - bzero(&cdp->toc, sizeof(cdp->toc)); - return 0; - } - - cdp->toc.hdr.len = ntohs(cdp->toc.hdr.len); - - if (acd_request_wait(cdp, ATAPI_READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0, - (char *)&cdp->info, sizeof(cdp->info)) != 0) - bzero(&cdp->info, sizeof(cdp->info)); - - cdp->toc.tab[ntracks].control = cdp->toc.tab[ntracks - 1].control; - cdp->toc.tab[ntracks].addr_type = cdp->toc.tab[ntracks - 1].addr_type; - cdp->toc.tab[ntracks].track = 170; - cdp->toc.tab[ntracks].addr.lba = cdp->info.volsize; - - cdp->info.volsize = ntohl(cdp->info.volsize); - cdp->info.blksize = ntohl(cdp->info.blksize); - - if (cdp->info.volsize && cdp->toc.hdr.ending_track - && (cdp->flags & F_DEBUG)) { - printf("wcd%d: ", cdp->lun); - if (cdp->toc.tab[0].control & 4) - printf("%ldMB ", cdp->info.volsize / 512); - else - printf("%ld:%ld audio ", cdp->info.volsize / 75 / 60, - cdp->info.volsize / 75 % 60); - printf("(%ld sectors (%ld bytes)), %d tracks\n", - cdp->info.volsize, cdp->info.blksize, - cdp->toc.hdr.ending_track - cdp->toc.hdr.starting_track + 1); - } - return 0; -} - -/* - * Set up the audio channel masks. - */ -static int -acd_setchan(struct acd *cdp, u_char c0, u_char c1, u_char c2, u_char c3) -{ - int error; - - error = acd_request_wait(cdp, ATAPI_MODE_SENSE, 0, CDROM_AUDIO_PAGE, - 0, 0, 0, 0, - sizeof(cdp->au)>>8, sizeof(cdp->au), 0, - (char *)&cdp->au, sizeof(cdp->au)); - if (error) - return error; - if (cdp->flags & F_DEBUG) - atapi_dump(cdp->ata->ctrlr, cdp->lun, "au", &cdp->au, sizeof(cdp->au)); - if (cdp->au.page_code != CDROM_AUDIO_PAGE) - return EIO; - - cdp->au.data_length = 0; - cdp->au.port[0].channels = c0; - cdp->au.port[1].channels = c1; - cdp->au.port[2].channels = c2; - cdp->au.port[3].channels = c3; - return acd_request_wait(cdp, ATAPI_MODE_SELECT, 0x10, - 0, 0, 0, 0, 0, - sizeof(cdp->au)>>8, sizeof(cdp->au), 0, - (char *)&cdp->au, -sizeof(cdp->au)); -} - -static int -acd_eject(struct acd *cdp, int close) -{ - struct atapires result; - - acd_select_slot(cdp); - - result = atapi_request_wait(cdp->ata, cdp->unit, ATAPI_START_STOP, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - - if (result.code == RES_ERR && - ((result.error & AER_SKEY) == AER_SK_NOT_READY || - (result.error & AER_SKEY) == AER_SK_UNIT_ATTENTION)) { - int err; - - if (!close) - return 0; - err = acd_request_wait(cdp, ATAPI_START_STOP, 0, 0, 0, 3, - 0, 0, 0, 0, 0, 0, 0); - if (err) - return err; - - acd_read_toc(cdp); - - acd_request_wait(cdp, ATAPI_PREVENT_ALLOW, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0); - cdp->flags |= F_LOCKED; - return 0; - } - if (result.code) { - atapi_error(cdp->ata, cdp->unit, result); - return EIO; - } - if (close) - return 0; - - tsleep((caddr_t) &lbolt, 0, "wcdej1", 0); - tsleep((caddr_t) &lbolt, 0, "wcdej2", 0); - - acd_request_wait(cdp, ATAPI_PREVENT_ALLOW, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - cdp->flags &= ~F_LOCKED; - - cdp->flags |= F_MEDIA_CHANGED; - cdp->flags &= ~(F_WRITTEN|F_TRACK_PREP|F_TRACK_PREPED); - return acd_request_wait(cdp, ATAPI_START_STOP, 0, 0, 0, 2, - 0, 0, 0, 0, 0, 0, 0); -} - -static void -acd_select_slot(struct acd *cdp) -{ - if (cdp->slot < 0 || cdp->changer_info->current_slot == cdp->slot) - return; - - /* Unlock (might not be needed but its cheaper than asking) */ - acd_request_wait(cdp, ATAPI_PREVENT_ALLOW, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - - /* Unload the current media from player */ - acd_request_wait(cdp, ATAPI_LOAD_UNLOAD, 0, 0, 0, 2, - 0, 0, 0, cdp->changer_info->current_slot, 0, 0, 0); - - /* load the wanted slot */ - acd_request_wait(cdp, ATAPI_LOAD_UNLOAD, 0, 0, 0, 3, - 0, 0, 0, cdp->slot, 0, 0, 0); - - cdp->changer_info->current_slot = cdp->slot; - - /* Lock the media if needed */ - if (cdp->flags & F_LOCKED) { - acd_request_wait(cdp, ATAPI_PREVENT_ALLOW, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0); - } -} - -static int -acd_open_disk(struct acd *cdp, int test) -{ - cdp->next_writeable_lba = 0; - return 0; -} - -static int -acd_close_disk(struct acd *cdp) -{ - return acd_request_wait(cdp, ATAPI_CLOSE_TRACK, 0x00, - 0x02, 0, 0, 0/*track*/, 0, 0, 0, 0, 0, 0); -} - -static int -acd_open_track(struct acd *cdp, struct wormio_prepare_track *ptp) -{ - struct write_param param; - struct atapires result; - - result = atapi_request_wait(cdp->ata, cdp->unit, ATAPI_MODE_SENSE, - 0, 0x05, 0, 0, 0, 0, - sizeof(param)>>8, sizeof(param), - 0, 0, 0, 0, 0, 0, 0, - (char *)¶m, sizeof(param)); - - if (cdp->flags & F_DEBUG) - atapi_dump(cdp->ata->ctrlr, cdp->lun, "0x05", ¶m, sizeof(param)); - - if (result.code == RES_UNDERRUN) - result.code = 0; - - if (result.code) { - atapi_error(cdp->ata, cdp->unit, result); - return EIO; - } - param.page_code = 0x05; - param.page_length = 0x32; - param.test_write = cdp->dummy ? 1 : 0; - param.write_type = CDR_WTYPE_TRACK; - - switch (ptp->audio) { -/* switch (data_type) { */ - - case 0: -/* case CDR_DATA: */ - cdp->block_size = 2048; - param.track_mode = CDR_TMODE_DATA; - param.data_block_type = CDR_DB_ROM_MODE1; - param.session_format = CDR_SESS_CDROM; - break; - - default: -/* case CDR_AUDIO: */ - cdp->block_size = 2352; - if (ptp->preemp) - param.track_mode = CDR_TMODE_AUDIO; - else - param.track_mode = 0; - param.data_block_type = CDR_DB_RAW; - param.session_format = CDR_SESS_CDROM; - break; - -/* - case CDR_MODE2: - param.track_mode = CDR_TMODE_DATA; - param.data_block_type = CDR_DB_ROM_MODE2; - param.session_format = CDR_SESS_CDROM; - break; - - case CDR_XA1: - param.track_mode = CDR_TMODE_DATA; - param.data_block_type = CDR_DB_XA_MODE1; - param.session_format = CDR_SESS_CDROM_XA; - break; - - case CDR_XA2: - param.track_mode = CDR_TMODE_DATA; - param.data_block_type = CDR_DB_XA_MODE2_F1; - param.session_format = CDR_SESS_CDROM_XA; - break; - - case CDR_CDI: - param.track_mode = CDR_TMODE_DATA; - param.data_block_type = CDR_DB_XA_MODE2_F1; - param.session_format = CDR_SESS_CDI; - break; -*/ - } - - param.multi_session = CDR_MSES_NONE; - param.fp = 0; - param.packet_size = 0; - - if (cdp->flags & F_DEBUG) - atapi_dump(cdp->ata->ctrlr, cdp->lun, "0x05", ¶m, sizeof(param)); - - result = atapi_request_wait(cdp->ata, cdp->unit, ATAPI_MODE_SELECT, - 0x10, 0, 0, 0, 0, 0, - sizeof(param)>>8, sizeof(param), - 0, 0, 0, 0, 0, 0, 0, - (char *)¶m, -sizeof(param)); - - if (result.code == RES_UNDERRUN) - result.code = 0; - - if (result.code) { - atapi_error(cdp->ata, cdp->unit, result); - return EIO; - } - return 0; -} - -static int -acd_close_track(struct acd *cdp) -{ - return acd_request_wait(cdp, ATAPI_SYNCHRONIZE_CACHE, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); -} - -static int -acd_read_track_info(struct acd *cdp, int lba, struct acd_track_info *info) -{ - int error; - - error = acd_request_wait(cdp, ATAPI_READ_TRACK_INFO, 0x01, - lba>>24, (lba>>16)&0xff, - (lba>>8)&0xff, lba&0xff, - 0, - sizeof(*info)>>8, sizeof(*info), 0, - (char *)info, sizeof(*info)); - if (error) - return error; - info->track_start_addr = ntohl(info->track_start_addr); - info->next_writeable_addr = ntohl(info->next_writeable_addr); - info->free_blocks = ntohl(info->free_blocks); - info->fixed_packet_size = ntohl(info->fixed_packet_size); - info->track_length = ntohl(info->track_length); - return 0; -} - -static int -acd_blank_disk(struct acd *cdp) -{ - int error; - - error = acd_request_wait(cdp, 0xa1, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - cdp->flags |= F_MEDIA_CHANGED; - cdp->flags &= ~(F_WRITTEN|F_TRACK_PREP|F_TRACK_PREPED); - return error; -} - -static void -atapi_error(struct atapi *ata, int unit, struct atapires result) -{ - if (result.code != RES_ERR) { - printf("atapi%d:%d: ERROR %d, status=%b, error=%b\n", - ata->ctrlr, unit, result.code, result.status, - ARS_BITS, result.error, AER_BITS); - return; - } - switch (result.error & AER_SKEY) { - case AER_SK_NOT_READY: - if (ata->debug) - printf("atapi%d:%d: not ready\n", ata->ctrlr, unit); - break; - - case AER_SK_BLANK_CHECK: - if (ata->debug) - printf("atapi%d:%d: blank check\n", ata->ctrlr, unit); - break; - - case AER_SK_MEDIUM_ERROR: - if (ata->debug) - printf("atapi%d:%d: medium error\n", ata->ctrlr, unit); - break; - - case AER_SK_HARDWARE_ERROR: - if (ata->debug) - printf("atapi%d:%d: hardware error\n", ata->ctrlr, unit); - break; - - case AER_SK_ILLEGAL_REQUEST: - if (ata->debug) - printf("atapi%d:%d: illegal request\n", ata->ctrlr, unit); - break; - - case AER_SK_UNIT_ATTENTION: - if (ata->debug) - printf("atapi%d:%d: unit attention\n", ata->ctrlr, unit); - break; - - case AER_SK_DATA_PROTECT: - if (ata->debug) - printf("atapi%d:%d: reading protected data\n", ata->ctrlr, unit); - break; - - case AER_SK_ABORTED_COMMAND: - if (ata->debug) - printf("atapi%d:%d: command aborted\n", ata->ctrlr, unit); - break; - - case AER_SK_MISCOMPARE: - if (ata->debug) - printf("atapi%d:%d: data don't match medium\n", ata->ctrlr, unit); - break; - - default: - if (ata->debug) - printf("atapi%d:%d: unknown error, status=%b, error=%b\n", - ata->ctrlr, unit, result.status, ARS_BITS, - result.error, AER_BITS); - } -} - -static void -atapi_dump(int ctrlr, int lun, char *label, void *data, int len) -{ - u_char *p = data; - - printf ("atapi%d%d: %s %x", ctrlr, lun, label, *p++); - while (--len > 0) printf ("-%x", *p++); - printf ("\n"); -} - -static void -acd_drvinit(void *unused) -{ - cdevsw_add(&acd_cdevsw); -} - -SYSINIT(acddev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE + CDEV_MAJOR, acd_drvinit, NULL) diff --git a/sys/dev/disk/wcd/wd_cd.h b/sys/dev/disk/wcd/wd_cd.h deleted file mode 100644 index f3eaf02d3b..0000000000 --- a/sys/dev/disk/wcd/wd_cd.h +++ /dev/null @@ -1,350 +0,0 @@ -/*- - * Copyright (c) 1998, 1999 Søren Schmidt - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * without modification, immediately at the beginning of the file. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: src/sys/i386/isa/wd_cd.h,v 1.6 1999/10/03 04:12:07 bde Exp $ - * $DragonFly: src/sys/dev/disk/wcd/Attic/wd_cd.h,v 1.2 2003/06/17 04:28:37 dillon Exp $ - */ - -/* - * CDROM Table Of Contents - */ -#define MAXTRK 99 -struct toc { - struct ioc_toc_header hdr; - struct cd_toc_entry tab[MAXTRK + 1]; -}; - -/* - * CDROM Audio Control Parameters Page - */ -struct audiopage { - /* Mode Page data header */ - u_short data_length; - u_char medium_type; - u_char dev_spec; - u_char unused[2]; - u_short blk_desc_len; - - /* Audio control page */ - u_char page_code; -#define CDROM_AUDIO_PAGE 0x0e -#define CDROM_AUDIO_PAGE_MASK 0x4e - - u_char param_len; - u_char flags; -#define CD_PA_SOTC 0x02 -#define CD_PA_IMMED 0x04 - - u_char reserved3; - u_char reserved4; - u_char reserved5; - u_short lb_per_sec; - struct port_control { - u_char channels:4; -#define CHANNEL_0 1 -#define CHANNEL_1 2 -#define CHANNEL_2 4 -#define CHANNEL_3 8 - u_char volume; - } port[4]; -}; - -/* - * CDROM Capabilities and Mechanical Status Page - */ -struct cappage { - /* Mode data header */ - u_short data_length; - u_char medium_type; /* Present media type */ -#define MST_TYPE_MASK_LOW 0x0f -#define MST_FMT_NONE 0x00 -#define MST_DATA_120 0x01 -#define MST_AUDIO_120 0x02 -#define MST_COMB_120 0x03 -#define MST_PHOTO_120 0x04 -#define MST_DATA_80 0x05 -#define MST_AUDIO_80 0x06 -#define MST_COMB_80 0x07 -#define MST_PHOTO_80 0x08 - -#define MST_TYPE_MASK_HIGH 0x70 -#define MST_CDROM 0x00 -#define MST_CDR 0x10 -#define MST_CDRW 0x20 - -#define MST_NO_DISC 0x70 -#define MST_DOOR_OPEN 0x71 -#define MST_FMT_ERROR 0x72 - - u_char dev_spec; - u_char unused[2]; - u_short blk_desc_len; - - /* Capabilities page */ - u_char page_code; -#define ATAPI_CDROM_CAP_PAGE 0x2a - - u_char param_len; - u_char read_cdr:1; /* Supports CD-R read */ - u_char read_cdrw:1; /* Supports CD-RW read */ - u_char method2:1; /* Supports reading packet tracks */ - u_char byte2_37:5; - u_char write_cdr:1; /* Supports CD-R write */ - u_char write_cdrw:1; /* Supports CD-RW write */ - u_char test_write:1; /* Supports test writing */ - u_char byte3_37:5; - u_char audio_play:1; /* Audio play supported */ - u_char composite:1; /* Composite audio/video supported */ - u_char dport1:1; /* Digital audio on port 1 */ - u_char dport2:1; /* Digital audio on port 2 */ - u_char mode2_form1:1; /* Mode 2 form 1 (XA) read */ - u_char mode2_form2:1; /* Mode 2 form 2 format */ - u_char multisession:1; /* Multi-session photo-CD */ - u_char:1; - u_char cd_da:1; /* Audio-CD read supported */ - u_char cd_da_stream:1; /* CD-DA streaming */ - u_char rw:1; /* Combined R-W subchannels */ - u_char rw_corr:1; /* R-W subchannel data corrected */ - u_char c2:1; /* C2 error pointers supported */ - u_char isrc:1; /* Can return the ISRC info */ - u_char upc:1; /* Can return the catalog number UPC */ - u_char:1; - u_char lock:1; /* Can be locked */ - u_char locked:1; /* Current lock state */ - u_char prevent:1; /* Prevent jumper installed */ - u_char eject:1; /* Can eject */ - u_char:1; - u_char mech:3; /* Loading mechanism type */ -#define MST_MECH_CADDY 0 -#define MST_MECH_TRAY 1 -#define MST_MECH_POPUP 2 -#define MST_MECH_CHANGER 4 -#define MST_MECH_CARTRIDGE 5 - - u_char sep_vol:1; /* Independent volume of channels */ - u_char sep_mute:1; /* Independent mute of channels */ - u_char:6; - - u_short max_speed; /* Max raw data rate in bytes/1000 */ - u_short max_vol_levels; /* Number of discrete volume levels */ - u_short buf_size; /* Internal buffer size in bytes/1024 */ - u_short cur_speed; /* Current data rate in bytes/1000 */ - - u_char reserved3; - u_char bckf:1; /* Data valid on failing edge of BCK */ - u_char rch:1; /* High LRCK indicates left channel */ - u_char lsbf:1; /* Set if LSB first */ - u_char dlen:2; -#define MST_DLEN_32 0 -#define MST_DLEN_16 1 -#define MST_DLEN_24 2 -#define MST_DLEN_24_I2S 3 - - u_char:3; - u_char reserved4[2]; -}; - -/* - * CDROM Changer mechanism status structure - */ -struct changer { - u_char current_slot:5; /* Active changer slot */ - u_char mech_state:2; /* Current changer state */ -#define CH_READY 0 -#define CH_LOADING 1 -#define CH_UNLOADING 2 -#define CH_INITIALIZING 3 - - u_char fault:1; /* Fault in last operation */ - u_char reserved0:5; - u_char cd_state:3; /* Current mechanism state */ -#define CD_IDLE 0 -#define CD_AUDIO_ACTIVE 1 -#define CD_AUDIO_SCAN 2 -#define CD_HOST_ACTIVE 3 -#define CD_NO_STATE 7 - - u_char current_lba[3]; /* Current LBA */ - u_char slots; /* Number of available slots */ - u_short table_length; /* Slot table length */ - struct { - u_char changed:1; /* Media has changed in this slot */ - u_char unused:6; - u_char present:1; /* Slot has a CD present */ - u_char reserved0; - u_char reserved1; - u_char reserved2; - } slot[32]; -}; - -/* - * CDROM Write Parameters Mode Page (Burners ONLY) - */ -struct write_param { - /* Mode Page data header */ - u_short data_length; - u_char medium_type; - u_char dev_spec; - u_char unused[2]; - u_short blk_desc_len; - - /* Write Parameters mode page */ - u_char page_code; /* 0x05 */ - u_char page_length; /* 0x32 */ - u_char write_type:4; /* Write stream type */ -#define CDR_WTYPE_PACKET 0x00 -#define CDR_WTYPE_TRACK 0x01 -#define CDR_WTYPE_SESSION 0x02 -#define CDR_WTYPE_RAW 0x03 - - u_char test_write:1; /* Test write enable */ - u_char reserved2_567:3; - u_char track_mode:4; /* Track mode */ -#define CDR_TMODE_AUDIO 0x01 -#define CDR_TMODE_INCR_DATA 0x01 -#define CDR_TMODE_ALLOW_COPY 0x02 -#define CDR_TMODE_DATA 0x04 -#define CDR_TMODE_QUAD_AUDIO 0x08 - - u_char copy:1; /* Generation stamp */ - u_char fp:1; /* Fixed packet type */ - u_char multi_session:2; /* Multi-session type */ -#define CDR_MSES_NONE 0x00 -#define CDR_MSES_FINAL 0x01 -#define CDR_MSES_RESERVED 0x02 -#define CDR_MSES_NULTI 0x03 - - u_char data_block_type:4; /* Data block type code */ -#define CDR_DB_RAW 0x0 /* 2352 bytes of raw data */ -#define CDR_DB_RAW_PQ 0x1 /* 2368 bytes raw data + P/Q subchan */ -#define CDR_DB_RAW_PW 0x2 /* 2448 bytes raw data + P-W subchan */ -#define CDR_DB_RAW_PW_R 0x3 /* 2448 bytes raw data + P-W raw sub */ -#define CDR_DB_RES_4 0x4 /* Reserved */ -#define CDR_DB_RES_5 0x5 /* Reserved */ -#define CDR_DB_RES_6 0x6 /* Reserved */ -#define CDR_DB_VS_7 0x7 /* Vendor specific */ -#define CDR_DB_ROM_MODE1 0x8 /* 2048 bytes Mode 1 (ISO/IEC 10149) */ -#define CDR_DB_ROM_MODE2 0x9 /* 2336 bytes Mode 2 (ISO/IEC 10149) */ -#define CDR_DB_XA_MODE1 0x10 /* 2048 bytes Mode 1 (CD-ROM XA 1) */ -#define CDR_DB_XA_MODE2_F1 0x11 /* 2056 bytes Mode 2 (CD-ROM XA 1) */ -#define CDR_DB_XA_MODE2_F2 0x12 /* 2324 bytes Mode 2 (CD-ROM XA 2) */ -#define CDR_DB_XA_MODE2_MIX 0x13 /* 2332 bytes Mode 2 (CD-ROM XA 1/2) */ -#define CDR_DB_RES_14 0x14 /* Reserved */ -#define CDR_DB_VS_15 0x15 /* Vendor specific */ - - u_char reserved4_4567:4; - u_char reserved5; - u_char reserved6; - u_char host_app_code:6; /* Host application code */ - u_char reserved7_67:2; - u_char session_format; /* Session format */ -#define CDR_SESS_CDROM 0x00 -#define CDR_SESS_CDI 0x10 -#define CDR_SESS_CDROM_XA 0x20 - - u_char reserved9; - u_int packet_size; /* Packet size in bytes */ - u_short audio_pause_length; /* Audio pause length in secs */ - u_char media_catalog_number[16]; - u_char isr_code[16]; - u_char sub_hdr_byte0; - u_char sub_hdr_byte1; - u_char sub_hdr_byte2; - u_char sub_hdr_byte3; -/* - u_char vendor_specific_byte0; - u_char vendor_specific_byte1; - u_char vendor_specific_byte2; - u_char vendor_specific_byte3; -*/ - -} __attribute__((packed)); -/* - * CDROM Read Track Information structure - */ -struct acd_track_info { - u_short data_length; - u_char track_number; /* Current track number */ - u_char session_number; /* Current session number */ - u_char reserved4; - u_char track_mode:4; /* Mode of this track */ - u_char copy:1; /* Generation stamp */ - u_char damage:1; /* Damaged track */ - u_char reserved5_67:2; - u_char data_mode:4; /* Data mode of this disc */ - u_char fp:1; /* Fixed packet */ - u_char packet:1; /* Packet track */ - u_char blank:1; /* Blank (empty) track */ - u_char rt:1; /* Reserved track */ - u_char nwa_valid:1; /* next_writeable_addr field valid */ - u_char reserved7_17:7; - u_int track_start_addr; /* Start of this track */ - u_int next_writeable_addr; /* Next writeable addr on this disc */ - u_int free_blocks; /* Free block on this disc */ - u_int fixed_packet_size; /* Size of packets on this track */ - u_int track_length; /* Length of this track */ -}; - -/* - * Structure describing an ATAPI CDROM device - */ -struct acd { - int unit; /* IDE bus drive unit */ - int lun; /* Logical device unit */ - int flags; /* Device state flags */ - int refcnt; /* The number of raw opens */ - struct atapi *ata; /* Controller structure */ - struct buf_queue_head buf_queue; /* Queue of i/o requests */ - struct atapi_params *param; /* Drive parameters table */ - struct toc toc; /* Table of disc contents */ - struct { - u_long volsize; /* Volume size in blocks */ - u_long blksize; /* Block size in bytes */ - } info; - struct audiopage au; /* Audio page info */ - struct cappage cap; /* Capabilities page info */ - struct audiopage aumask; /* Audio page mask */ - struct { /* Subchannel info */ - u_char void0; - u_char audio_status; - u_short data_length; - u_char data_format; - u_char control; - u_char track; - u_char indx; - u_long abslba; - u_long rellba; - } subchan; - struct changer *changer_info; /* Changer info */ - int slot; /* This lun's slot number */ - struct devstat *device_stats; /* Devstat parameters */ - u_int block_size; /* Blocksize currently used */ - u_char dummy; /* Use dummy writes */ - u_char speed; /* Select drive speed */ - u_int next_writeable_lba; /* Next writable position */ - struct wormio_prepare_track preptrack; /* Scratch region */ -}; diff --git a/sys/dev/disk/wd/wd.c b/sys/dev/disk/wd/wd.c deleted file mode 100644 index c421cd7be3..0000000000 --- a/sys/dev/disk/wd/wd.c +++ /dev/null @@ -1,2209 +0,0 @@ -/*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)wd.c 7.2 (Berkeley) 5/9/91 - * $FreeBSD: src/sys/i386/isa/wd.c,v 1.219.2.2 2000/08/04 22:31:07 peter Exp $ - * $DragonFly: src/sys/dev/disk/wd/Attic/wd.c,v 1.8 2003/08/07 21:16:54 dillon Exp $ - */ - -/* TODO: - * o Bump error count after timeout. - * o Satisfy ATA timing in all cases. - * o Finish merging berry/sos timeout code (bump error count...). - * o Don't use polling except for initialization. Need to - * reorganize the state machine. Then "extra" interrupts - * shouldn't happen (except maybe one for initialization). - * o Support extended DOS partitions. - * o Support swapping to DOS partitions. - * o Handle clustering, disklabelling, DOS - * partitions and swapping driver-independently. - * Swapping will need new - * driver entries for polled reinit and polled write). - */ - -#include "use_wd.h" -#ifdef NWDC -#undef NWDC -#endif - -#include "use_wdc.h" - -#if NWDC > 0 - -#include "opt_hw_wdog.h" -#include "opt_ide_delay.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "wdreg.h" -#include -#include -#include -#include - -#include - -extern void wdstart(int ctrlr); - -#ifdef IDE_DELAY -#define TIMEOUT IDE_DELAY -#else -#define TIMEOUT 10000 -#endif -#define RETRIES 5 /* number of retries before giving up */ -#define RECOVERYTIME 500000 /* usec for controller to recover after err */ -#define MAXTRANSFER 255 /* max size of transfer in sectors */ - /* correct max is 256 but some controllers */ - /* can't handle that in all cases */ -#define WDOPT_32BIT 0x8000 -#define WDOPT_SLEEPHACK 0x4000 -#define WDOPT_DMA 0x2000 -#define WDOPT_LBA 0x1000 -#define WDOPT_FORCEHD(x) (((x)&0x0f00)>>8) -#define WDOPT_MULTIMASK 0x00ff - -/* - * Drive states. Used to initialize drive. - */ - -#define CLOSED 0 /* disk is closed. */ -#define WANTOPEN 1 /* open requested, not started */ -#define RECAL 2 /* doing restore */ -#define OPEN 3 /* done with open */ - -#define PRIMARY 0 - -/* - * Disk geometry. A small part of struct disklabel. - * XXX disklabel.5 contains an old clone of disklabel.h. - */ -struct diskgeom { - u_long d_secsize; /* # of bytes per sector */ - u_long d_nsectors; /* # of data sectors per track */ - u_long d_ntracks; /* # of tracks per cylinder */ - u_long d_ncylinders; /* # of data cylinders per unit */ - u_long d_secpercyl; /* # of data sectors per cylinder */ - u_long d_secperunit; /* # of data sectors per unit */ - u_long d_precompcyl; /* XXX always 0 */ -}; - -/* - * The structure of a disk drive. - */ -struct disk { - u_int dk_bc; /* byte count left */ - short dk_skip; /* blocks already transferred */ - int dk_ctrlr; /* physical controller number */ - int dk_ctrlr_cmd640;/* controller number for CMD640 quirk */ - u_int32_t dk_unit; /* physical unit number */ - u_int32_t dk_lunit; /* logical unit number */ - u_int32_t dk_interface; /* interface (two ctrlrs per interface) */ - char dk_state; /* control state */ - u_char dk_status; /* copy of status reg. */ - u_char dk_error; /* copy of error reg. */ - u_char dk_timeout; /* countdown to next timeout */ - u_int32_t dk_port; /* i/o port base */ - u_int32_t dk_altport; /* altstatus port base */ - u_long cfg_flags; /* configured characteristics */ - short dk_flags; /* drive characteristics found */ -#define DKFL_SINGLE 0x00004 /* sector at a time mode */ -#define DKFL_ERROR 0x00008 /* processing a disk error */ -#define DKFL_LABELLING 0x00080 /* readdisklabel() in progress */ -#define DKFL_32BIT 0x00100 /* use 32-bit i/o mode */ -#define DKFL_MULTI 0x00200 /* use multi-i/o mode */ -#define DKFL_USEDMA 0x00800 /* use DMA for data transfers */ -#define DKFL_DMA 0x01000 /* using DMA on this transfer-- DKFL_SINGLE - * overrides this - */ -#define DKFL_LBA 0x02000 /* use LBA for data transfers */ - struct wdparams dk_params; /* ESDI/IDE drive/controller parameters */ - unsigned int dk_multi; /* multi transfers */ - int dk_currentiosize; /* current io size */ - struct diskgeom dk_dd; /* device configuration data */ - struct diskslices *dk_slices; /* virtual drives */ - void *dk_dmacookie; /* handle for DMA services */ - - struct devstat dk_stats; /* devstat entry */ -}; - -#define WD_COUNT_RETRIES -static int wdtest = 0; - -static struct disk *wddrives[NWD]; /* table of units */ -static struct buf_queue_head drive_queue[NWD]; /* head of queue per drive */ -static struct { - int b_active; -} wdutab[NWD]; -/* -static struct buf wdtab[NWDC]; -*/ -static struct { - struct buf_queue_head controller_queue; - int b_errcnt; - int b_active; -} wdtab[NWDC]; - -struct wddma wddma[NWDC]; - -#ifdef notyet -static struct buf rwdbuf[NWD]; /* buffers for raw IO */ -#endif - -static int wdprobe(struct isa_device *dvp); -static int wdattach(struct isa_device *dvp); -static void wdustart(struct disk *du); -static int wdcontrol(struct buf *bp); -static int wdcommand(struct disk *du, u_int cylinder, u_int head, - u_int sector, u_int count, u_int command); -static int wdsetctlr(struct disk *du); -#if 0 -static int wdwsetctlr(struct disk *du); -#endif -static int wdsetmode(int mode, void *wdinfo); -static int wdgetctlr(struct disk *du); -static void wderror(struct buf *bp, struct disk *du, char *mesg); -static void wdflushirq(struct disk *du, int old_ipl); -static int wdreset(struct disk *du); -static void wdsleep(int ctrlr, char *wmesg); -static timeout_t wdtimeout; -static int wdunwedge(struct disk *du); -static int wdwait(struct disk *du, u_char bits_wanted, int timeout); - -struct isa_driver wdcdriver = { - wdprobe, wdattach, "wdc", -}; - - - -static d_open_t wdopen; -static d_close_t wdclose; -static d_strategy_t wdstrategy; -static d_ioctl_t wdioctl; -static d_dump_t wddump; -static d_psize_t wdsize; - -static struct cdevsw wd_cdevsw = { - /* name */ "wd", - /* maj */ WD_CDEV_MAJOR, - /* flags */ D_DISK, - /* port */ NULL, - /* autoq */ 0, - - /* open */ wdopen, - /* close */ wdclose, - /* read */ physread, - /* write */ physwrite, - /* ioctl */ wdioctl, - /* poll */ nopoll, - /* mmap */ nommap, - /* strategy */ wdstrategy, - /* dump */ wddump, - /* psize */ wdsize -}; - - -static int atapictrlr; -static int eide_quirks; - - -/* - * Here we use the pci-subsystem to find out, whether there is - * a cmd640b-chip attached on this pci-bus. This public routine - * will be called by ide_pci.c - */ - -void -wdc_pci(int quirks) -{ - eide_quirks = quirks; -} - -/* - * Probe for controller. - */ -static int -wdprobe(struct isa_device *dvp) -{ - int unit = dvp->id_unit; - int interface; - struct disk *du; - - if (unit >= NWDC) - return (0); - - du = malloc(sizeof *du, M_TEMP, M_NOWAIT); - if (du == NULL) - return (0); - bzero(du, sizeof *du); - du->dk_ctrlr = dvp->id_unit; - interface = du->dk_ctrlr / 2; - du->dk_interface = interface; - du->dk_port = dvp->id_iobase; - if (wddma[interface].wdd_candma != NULL) { - du->dk_dmacookie = - wddma[interface].wdd_candma(dvp->id_iobase, du->dk_ctrlr, - du->dk_unit); - du->dk_altport = - wddma[interface].wdd_altiobase(du->dk_dmacookie); - } - if (du->dk_altport == 0) - du->dk_altport = du->dk_port + wd_ctlr; - - /* check if we have registers that work */ - outb(du->dk_port + wd_sdh, WDSD_IBM); /* set unit 0 */ - outb(du->dk_port + wd_cyl_lo, 0xa5); /* wd_cyl_lo is read/write */ - if (inb(du->dk_port + wd_cyl_lo) == 0xff) { /* XXX too weak */ - /* There is no master, try the ATAPI slave. */ - du->dk_unit = 1; - outb(du->dk_port + wd_sdh, WDSD_IBM | 0x10); - outb(du->dk_port + wd_cyl_lo, 0xa5); - if (inb(du->dk_port + wd_cyl_lo) == 0xff) - goto nodevice; - } - - if (wdreset(du) == 0) - goto reset_ok; - /* test for ATAPI signature */ - outb(du->dk_port + wd_sdh, WDSD_IBM); /* master */ - if (inb(du->dk_port + wd_cyl_lo) == 0x14 && - inb(du->dk_port + wd_cyl_hi) == 0xeb) - goto reset_ok; - du->dk_unit = 1; - outb(du->dk_port + wd_sdh, WDSD_IBM | 0x10); /* slave */ - if (inb(du->dk_port + wd_cyl_lo) == 0x14 && - inb(du->dk_port + wd_cyl_hi) == 0xeb) - goto reset_ok; - DELAY(RECOVERYTIME); - if (wdreset(du) != 0) { - goto nodevice; - } -reset_ok: - - /* execute a controller only command */ - if (wdcommand(du, 0, 0, 0, 0, WDCC_DIAGNOSE) != 0 - || wdwait(du, 0, TIMEOUT) < 0) { - goto nodevice; - } - - /* - * drive(s) did not time out during diagnostic : - * Get error status and check that both drives are OK. - * Table 9-2 of ATA specs suggests that we must check for - * a value of 0x01 - * - * Strangely, some controllers will return a status of - * 0x81 (drive 0 OK, drive 1 failure), and then when - * the DRV bit is set, return status of 0x01 (OK) for - * drive 2. (This seems to contradict the ATA spec.) - */ - du->dk_error = inb(du->dk_port + wd_error); - if(du->dk_error != 0x01 && du->dk_error != 0) { - if(du->dk_error & 0x80) { /* drive 1 failure */ - - /* first set the DRV bit */ - u_int sdh; - sdh = inb(du->dk_port+ wd_sdh); - sdh = sdh | 0x10; - outb(du->dk_port+ wd_sdh, sdh); - - /* Wait, to make sure drv 1 has completed diags */ - if ( wdwait(du, 0, TIMEOUT) < 0) - goto nodevice; - - /* Get status for drive 1 */ - du->dk_error = inb(du->dk_port + wd_error); - /* printf("Error (drv 1) : %x\n", du->dk_error); */ - /* - * Sometimes (apparently mostly with ATAPI - * drives involved) 0x81 really means 0x81 - * (drive 0 OK, drive 1 failed). - */ - if(du->dk_error != 0x01 && du->dk_error != 0x81) - goto nodevice; - } else /* drive 0 fail */ - goto nodevice; - } - - - free(du, M_TEMP); - return (IO_WDCSIZE); - -nodevice: - free(du, M_TEMP); - return (0); -} - -/* - * Attach each drive if possible. - */ -static int -wdattach(struct isa_device *dvp) -{ - int unit, lunit, flags, i; - struct disk *du; - struct wdparams *wp; - static char buf[] = "wdcXXX"; - static int once; - - dvp->id_intr = wdintr; - - if (dvp->id_unit >= NWDC) - return (0); - - if (!once) { - cdevsw_add(&wd_cdevsw); - once++; - } - - if (eide_quirks & Q_CMD640B) { - if (dvp->id_unit == PRIMARY) { - printf("wdc0: CMD640B workaround enabled\n"); - bufq_init(&wdtab[PRIMARY].controller_queue); - } - } else - bufq_init(&wdtab[dvp->id_unit].controller_queue); - - sprintf(buf, "wdc%d", dvp->id_unit); - for (i = resource_query_string(-1, "at", buf); - i != -1; - i = resource_query_string(i, "at", buf)) { - if (strcmp(resource_query_name(i), "wd")) - /* Avoid a bit of foot shooting. */ - continue; - - lunit = resource_query_unit(i); - if (lunit >= NWD) - continue; - - if (resource_int_value("wd", lunit, "drive", &unit) != 0) - continue; - if (resource_int_value("wd", lunit, "flags", &flags) != 0) - flags = 0; - - du = malloc(sizeof *du, M_TEMP, M_NOWAIT); - if (du == NULL) - continue; - if (wddrives[lunit] != NULL) - panic("drive attached twice"); - wddrives[lunit] = du; - bufq_init(&drive_queue[lunit]); - bzero(du, sizeof *du); - du->dk_ctrlr = dvp->id_unit; - if (eide_quirks & Q_CMD640B) { - du->dk_ctrlr_cmd640 = PRIMARY; - } else { - du->dk_ctrlr_cmd640 = du->dk_ctrlr; - } - du->dk_unit = unit; - du->dk_lunit = lunit; - du->dk_port = dvp->id_iobase; - - du->dk_altport = du->dk_port + wd_ctlr; - /* - * Use the individual device flags or the controller - * flags. - */ - du->cfg_flags = flags | - ((dvp->id_flags) >> (16 * unit)); - - if (wdgetctlr(du) == 0) { - /* - * Print out description of drive. - * wdp_model may not be null terminated. - */ - printf("wdc%d: unit %d (wd%d): <%.*s>", - dvp->id_unit, unit, lunit, - (int)sizeof(du->dk_params.wdp_model), - du->dk_params.wdp_model); - if (du->dk_flags & DKFL_LBA) - printf(", LBA"); - if (du->dk_flags & DKFL_USEDMA) - printf(", DMA"); - if (du->dk_flags & DKFL_32BIT) - printf(", 32-bit"); - if (du->dk_multi > 1) - printf(", multi-block-%d", du->dk_multi); - if (du->cfg_flags & WDOPT_SLEEPHACK) - printf(", sleep-hack"); - printf("\n"); - if (du->dk_params.wdp_heads == 0) - printf("wd%d: size unknown, using %s values\n", - lunit, du->dk_dd.d_secperunit > 17 - ? "BIOS" : "fake"); - printf( "wd%d: %luMB (%lu sectors), " - "%lu cyls, %lu heads, %lu S/T, %lu B/S\n", - lunit, - du->dk_dd.d_secperunit - / ((1024L * 1024L) / du->dk_dd.d_secsize), - du->dk_dd.d_secperunit, - du->dk_dd.d_ncylinders, - du->dk_dd.d_ntracks, - du->dk_dd.d_nsectors, - du->dk_dd.d_secsize); - - if (bootverbose) { - wp = &du->dk_params; - printf( "wd%d: ATA INQUIRE valid = %04x, " - "dmamword = %04x, apio = %04x, " - "udma = %04x\n", - du->dk_lunit, - wp->wdp_atavalid, - wp->wdp_dmamword, - wp->wdp_eidepiomodes, - wp->wdp_udmamode); - } - - /* - * Start timeout routine for this drive. - * XXX timeout should be per controller. - */ - wdtimeout(du); - - make_dev(&wd_cdevsw, - dkmakeminor(lunit, WHOLE_DISK_SLICE, RAW_PART), - UID_ROOT, GID_OPERATOR, 0640, "rwd%d", lunit); - - /* - * Export the drive to the devstat interface. - */ - devstat_add_entry(&du->dk_stats, "wd", - lunit, du->dk_dd.d_secsize, - DEVSTAT_NO_ORDERED_TAGS, - DEVSTAT_TYPE_DIRECT | - DEVSTAT_TYPE_IF_IDE, - DEVSTAT_PRIORITY_DISK); - - } else { - free(du, M_TEMP); - wddrives[lunit] = NULL; - } - } - /* - * Probe all free IDE units, searching for ATAPI drives. - */ - for (unit=0; unit<2; ++unit) { - for (lunit=0; lunitdk_ctrlr == dvp->id_unit && - wddrives[lunit]->dk_unit == unit) - goto next; - if (atapi_attach (dvp->id_unit, unit, dvp->id_iobase)) - atapictrlr = dvp->id_unit; -next: ; - } - /* - * Discard any interrupts generated by wdgetctlr(). wdflushirq() - * doesn't work now because the ambient ipl is too high. - */ - if (eide_quirks & Q_CMD640B) { - wdtab[PRIMARY].b_active = 2; - } else { - wdtab[dvp->id_unit].b_active = 2; - } - - return (1); -} - -/* Read/write routine for a buffer. Finds the proper unit, range checks - * arguments, and schedules the transfer. Does not wait for the transfer - * to complete. Multi-page transfers are supported. All I/O requests must - * be a multiple of a sector in length. - */ -void -wdstrategy(struct buf *bp) -{ - struct disk *du; - int lunit = dkunit(bp->b_dev); - int s; - - /* valid unit, controller, and request? */ - if (lunit >= NWD || bp->b_blkno < 0 || (du = wddrives[lunit]) == NULL - || bp->b_bcount % DEV_BSIZE != 0) { - - bp->b_error = EINVAL; - bp->b_flags |= B_ERROR; - goto done; - } - - /* - * Do bounds checking, adjust transfer, and set b_pblkno. - */ - if (dscheck(bp, du->dk_slices) <= 0) - goto done; - - /* queue transfer on drive, activate drive and controller if idle */ - s = splbio(); - - /* Pick up changes made by readdisklabel(). */ - if (du->dk_flags & DKFL_LABELLING && du->dk_state > RECAL) { - wdsleep(du->dk_ctrlr, "wdlab"); - du->dk_state = WANTOPEN; - } - - bufqdisksort(&drive_queue[lunit], bp); - - if (wdutab[lunit].b_active == 0) - wdustart(du); /* start drive */ - - if (wdtab[du->dk_ctrlr_cmd640].b_active == 0) - wdstart(du->dk_ctrlr); /* start controller */ - - /* Tell devstat that we have started a transaction on this drive */ - devstat_start_transaction(&du->dk_stats); - - splx(s); - return; - -done: - /* toss transfer, we're done early */ - biodone(bp); -} - -/* - * Routine to queue a command to the controller. The unit's - * request is linked into the active list for the controller. - * If the controller is idle, the transfer is started. - */ -static void -wdustart(struct disk *du) -{ - struct buf *bp; - int ctrlr = du->dk_ctrlr_cmd640; - - /* unit already active? */ - if (wdutab[du->dk_lunit].b_active) - return; - - - bp = bufq_first(&drive_queue[du->dk_lunit]); - if (bp == NULL) { /* yes, an assign */ - return; - } - /* - * store away which device we came from. - */ - bp->b_driver1 = du; - - bufq_remove(&drive_queue[du->dk_lunit], bp); - - /* link onto controller queue */ - bufq_insert_tail(&wdtab[ctrlr].controller_queue, bp); - - /* mark the drive unit as busy */ - wdutab[du->dk_lunit].b_active = 1; - -} - -/* - * Controller startup routine. This does the calculation, and starts - * a single-sector read or write operation. Called to start a transfer, - * or from the interrupt routine to continue a multi-sector transfer. - * RESTRICTIONS: - * 1. The transfer length must be an exact multiple of the sector size. - */ - -void -wdstart(int ctrlr) -{ - struct disk *du; - struct buf *bp; - struct diskgeom *lp; /* XXX sic */ - long blknum; - long secpertrk, secpercyl; - u_int lunit; - u_int count; - int ctrlr_atapi; - - if (eide_quirks & Q_CMD640B) { - ctrlr = PRIMARY; - ctrlr_atapi = atapictrlr; - } else { - ctrlr_atapi = ctrlr; - } - - if (wdtab[ctrlr].b_active == 2) - wdtab[ctrlr].b_active = 0; - if (wdtab[ctrlr].b_active) - return; - /* is there a drive for the controller to do a transfer with? */ - bp = bufq_first(&wdtab[ctrlr].controller_queue); - if (bp == NULL) { - if (atapi_strt && atapi_strt (ctrlr_atapi)) - /* mark controller active in ATAPI mode */ - wdtab[ctrlr].b_active = 3; - return; - } - - /* obtain controller and drive information */ - lunit = dkunit(bp->b_dev); - du = wddrives[lunit]; - - /* if not really a transfer, do control operations specially */ - if (du->dk_state < OPEN) { - if (du->dk_state != WANTOPEN) - printf("wd%d: wdstart: weird dk_state %d\n", - du->dk_lunit, du->dk_state); - if (wdcontrol(bp) != 0) - printf("wd%d: wdstart: wdcontrol returned nonzero, state = %d\n", - du->dk_lunit, du->dk_state); - return; - } - - /* calculate transfer details */ - blknum = bp->b_pblkno + du->dk_skip; -#ifdef WDDEBUG - if (du->dk_skip == 0) - printf("wd%d: wdstart: %s %d@%d; map ", lunit, - (bp->b_flags & B_READ) ? "read" : "write", - bp->b_bcount, blknum); - else - printf(" %d)%x", du->dk_skip, inb(du->dk_altport)); -#endif - - lp = &du->dk_dd; - secpertrk = lp->d_nsectors; - secpercyl = lp->d_secpercyl; - - if (du->dk_skip == 0) - du->dk_bc = bp->b_bcount; - - wdtab[ctrlr].b_active = 1; /* mark controller active */ - - /* if starting a multisector transfer, or doing single transfers */ - if (du->dk_skip == 0 || (du->dk_flags & DKFL_SINGLE)) { - u_int command; - u_int count1; - long cylin, head, sector; - - if (du->dk_flags & DKFL_LBA) { - sector = (blknum >> 0) & 0xff; - cylin = (blknum >> 8) & 0xffff; - head = ((blknum >> 24) & 0xf) | WDSD_LBA; - } else { - cylin = blknum / secpercyl; - head = (blknum % secpercyl) / secpertrk; - sector = blknum % secpertrk; - } - /* - * XXX this looks like an attempt to skip bad sectors - * on write. - */ - if (wdtab[ctrlr].b_errcnt && (bp->b_flags & B_READ) == 0) - du->dk_bc += DEV_BSIZE; - - count1 = howmany( du->dk_bc, DEV_BSIZE); - - du->dk_flags &= ~DKFL_MULTI; - - if (du->dk_flags & DKFL_SINGLE) { - command = (bp->b_flags & B_READ) - ? WDCC_READ : WDCC_WRITE; - count1 = 1; - du->dk_currentiosize = 1; - } else { - if((du->dk_flags & DKFL_USEDMA) && - wddma[du->dk_interface].wdd_dmaverify(du->dk_dmacookie, - (void *)((int)bp->b_data + - du->dk_skip * DEV_BSIZE), - du->dk_bc, - bp->b_flags & B_READ)) { - du->dk_flags |= DKFL_DMA; - if( bp->b_flags & B_READ) - command = WDCC_READ_DMA; - else - command = WDCC_WRITE_DMA; - du->dk_currentiosize = count1; - } else if( (count1 > 1) && (du->dk_multi > 1)) { - du->dk_flags |= DKFL_MULTI; - if( bp->b_flags & B_READ) { - command = WDCC_READ_MULTI; - } else { - command = WDCC_WRITE_MULTI; - } - du->dk_currentiosize = du->dk_multi; - if( du->dk_currentiosize > count1) - du->dk_currentiosize = count1; - } else { - if( bp->b_flags & B_READ) { - command = WDCC_READ; - } else { - command = WDCC_WRITE; - } - du->dk_currentiosize = 1; - } - } - - /* - * XXX this loop may never terminate. The code to handle - * counting down of retries and eventually failing the i/o - * is in wdintr() and we can't get there from here. - */ - if (wdtest != 0) { - if (--wdtest == 0) { - wdtest = 100; - printf("dummy wdunwedge\n"); - wdunwedge(du); - } - } - - if ((du->dk_flags & (DKFL_DMA|DKFL_SINGLE)) == DKFL_DMA) { - wddma[du->dk_interface].wdd_dmaprep(du->dk_dmacookie, - (void *)((int)bp->b_data + - du->dk_skip * DEV_BSIZE), - du->dk_bc, - bp->b_flags & B_READ); - } - while (wdcommand(du, cylin, head, sector, count1, command) - != 0) { - wderror(bp, du, - "wdstart: timeout waiting to give command"); - wdunwedge(du); - } -#ifdef WDDEBUG - printf("cylin %ld head %ld sector %ld addr %x sts %x\n", - cylin, head, sector, - (int)bp->b_data + du->dk_skip * DEV_BSIZE, - inb(du->dk_altport)); -#endif - } - - /* - * Schedule wdtimeout() to wake up after a few seconds. Retrying - * unmarked bad blocks can take 3 seconds! Then it is not good that - * we retry 5 times. - * - * On the first try, we give it 10 seconds, for drives that may need - * to spin up. - * - * XXX wdtimeout() doesn't increment the error count so we may loop - * forever. More seriously, the loop isn't forever but causes a - * crash. - * - * TODO fix b_resid bug elsewhere (fd.c....). Fix short but positive - * counts being discarded after there is an error (in physio I - * think). Discarding them would be OK if the (special) file offset - * was not advanced. - */ - if (wdtab[ctrlr].b_errcnt == 0) - du->dk_timeout = 1 + 10; - else - du->dk_timeout = 1 + 3; - - /* if this is a DMA op, start DMA and go away until it's done. */ - if ((du->dk_flags & (DKFL_DMA|DKFL_SINGLE)) == DKFL_DMA) { - wddma[du->dk_interface].wdd_dmastart(du->dk_dmacookie); - return; - } - - /* If this is a read operation, just go away until it's done. */ - if (bp->b_flags & B_READ) - return; - - /* Ready to send data? */ - if (wdwait(du, WDCS_READY | WDCS_SEEKCMPLT | WDCS_DRQ, TIMEOUT) < 0) { - wderror(bp, du, "wdstart: timeout waiting for DRQ"); - /* - * XXX what do we do now? If we've just issued the command, - * then we can treat this failure the same as a command - * failure. But if we are continuing a multi-sector write, - * the command was issued ages ago, so we can't simply - * restart it. - * - * XXX we waste a lot of time unnecessarily translating block - * numbers to cylin/head/sector for continued i/o's. - */ - } - - count = 1; - if( du->dk_flags & DKFL_MULTI) { - count = howmany(du->dk_bc, DEV_BSIZE); - if( count > du->dk_multi) - count = du->dk_multi; - if( du->dk_currentiosize > count) - du->dk_currentiosize = count; - } - - if (du->dk_flags & DKFL_32BIT) - outsl(du->dk_port + wd_data, - (void *)((int)bp->b_data + du->dk_skip * DEV_BSIZE), - (count * DEV_BSIZE) / sizeof(long)); - else - outsw(du->dk_port + wd_data, - (void *)((int)bp->b_data + du->dk_skip * DEV_BSIZE), - (count * DEV_BSIZE) / sizeof(short)); - du->dk_bc -= DEV_BSIZE * count; -} - -/* Interrupt routine for the controller. Acknowledge the interrupt, check for - * errors on the current operation, mark it done if necessary, and start - * the next request. Also check for a partially done transfer, and - * continue with the next chunk if so. - */ - -void -wdintr(void *unitnum) -{ - struct disk *du; - struct buf *bp; - int dmastat = 0; /* Shut up GCC */ - int unit = (int)unitnum; - - int ctrlr_atapi; - - if (eide_quirks & Q_CMD640B) { - unit = PRIMARY; - ctrlr_atapi = atapictrlr; - } else { - ctrlr_atapi = unit; - } - - if (wdtab[unit].b_active == 2) - return; /* intr in wdflushirq() */ - if (!wdtab[unit].b_active) { -#ifdef WDDEBUG - /* - * These happen mostly because the power-mgt part of the - * bios shuts us down, and we just manage to see the - * interrupt from the "SLEEP" command. - */ - printf("wdc%d: extra interrupt\n", unit); -#endif - return; - } - if (wdtab[unit].b_active == 3) { - /* process an ATAPI interrupt */ - if (atapi_intr && atapi_intr (ctrlr_atapi)) - /* ATAPI op continues */ - return; - /* controller is free, start new op */ - wdtab[unit].b_active = 0; - wdstart (unit); - return; - } - bp = bufq_first(&wdtab[unit].controller_queue); - du = wddrives[dkunit(bp->b_dev)]; - - /* finish off DMA */ - if ((du->dk_flags & (DKFL_DMA|DKFL_SINGLE)) == DKFL_DMA) { - /* XXX SMP boxes sometimes generate an early intr. Why? */ - if ((wddma[du->dk_interface].wdd_dmastatus(du->dk_dmacookie) & - WDDS_INTERRUPT) == 0) - return; - dmastat = wddma[du->dk_interface].wdd_dmadone(du->dk_dmacookie); - } - - du->dk_timeout = 0; - - /* check drive status/failure */ - if (wdwait(du, 0, TIMEOUT) < 0) { - wderror(bp, du, "wdintr: timeout waiting for status"); - du->dk_status |= WDCS_ERR; /* XXX */ - } - - /* is it not a transfer, but a control operation? */ - if (du->dk_state < OPEN) { - wdtab[unit].b_active = 0; - switch (wdcontrol(bp)) { - case 0: - return; - case 1: - wdstart(unit); - return; - case 2: - goto done; - } - } - - /* have we an error? */ - if ((du->dk_status & (WDCS_ERR | WDCS_ECCCOR)) - || (((du->dk_flags & (DKFL_DMA|DKFL_SINGLE)) == DKFL_DMA) - && dmastat != WDDS_INTERRUPT)) { - - unsigned int errstat; -oops: - /* - * XXX bogus inb() here - */ - errstat = inb(du->dk_port + wd_error); - - if(((du->dk_flags & (DKFL_DMA|DKFL_SINGLE)) == DKFL_DMA) && - (errstat & WDERR_ABORT)) { - wderror(bp, du, "reverting to PIO mode"); - du->dk_flags &= ~DKFL_USEDMA; - } else if((du->dk_flags & DKFL_MULTI) && - (errstat & WDERR_ABORT)) { - wderror(bp, du, "reverting to non-multi sector mode"); - du->dk_multi = 1; - } - - if (!(du->dk_status & (WDCS_ERR | WDCS_ECCCOR)) && - (((du->dk_flags & (DKFL_DMA|DKFL_SINGLE)) == DKFL_DMA) && - (dmastat != WDDS_INTERRUPT))) - printf("wd%d: DMA failure, DMA status %b\n", - du->dk_lunit, dmastat, WDDS_BITS); -#ifdef WDDEBUG - wderror(bp, du, "wdintr"); -#endif - if ((du->dk_flags & DKFL_SINGLE) == 0) { - du->dk_flags |= DKFL_ERROR; - goto outt; - } - - if (du->dk_status & WDCS_ERR) { - if (++wdtab[unit].b_errcnt < RETRIES) { - wdtab[unit].b_active = 0; - } else { - wderror(bp, du, "hard error"); - bp->b_error = EIO; - bp->b_flags |= B_ERROR; /* flag the error */ - } - } else if (du->dk_status & WDCS_ECCCOR) - wderror(bp, du, "soft ecc"); - } - - /* - * If this was a successful read operation, fetch the data. - */ - if (((bp->b_flags & (B_READ | B_ERROR)) == B_READ) - && !((du->dk_flags & (DKFL_DMA|DKFL_SINGLE)) == DKFL_DMA) - && wdtab[unit].b_active) { - u_int chk, dummy, multisize; - multisize = chk = du->dk_currentiosize * DEV_BSIZE; - if( du->dk_bc < chk) { - chk = du->dk_bc; - if( ((chk + DEV_BSIZE - 1) / DEV_BSIZE) < du->dk_currentiosize) { - du->dk_currentiosize = (chk + DEV_BSIZE - 1) / DEV_BSIZE; - multisize = du->dk_currentiosize * DEV_BSIZE; - } - } - - /* ready to receive data? */ - if ((du->dk_status & (WDCS_READY | WDCS_SEEKCMPLT | WDCS_DRQ)) - != (WDCS_READY | WDCS_SEEKCMPLT | WDCS_DRQ)) - wderror(bp, du, "wdintr: read intr arrived early"); - if (wdwait(du, WDCS_READY | WDCS_SEEKCMPLT | WDCS_DRQ, TIMEOUT) != 0) { - wderror(bp, du, "wdintr: read error detected late"); - goto oops; - } - - /* suck in data */ - if( du->dk_flags & DKFL_32BIT) - insl(du->dk_port + wd_data, - (void *)((int)bp->b_data + du->dk_skip * DEV_BSIZE), - chk / sizeof(long)); - else - insw(du->dk_port + wd_data, - (void *)((int)bp->b_data + du->dk_skip * DEV_BSIZE), - chk / sizeof(short)); - du->dk_bc -= chk; - - /* XXX for obsolete fractional sector reads. */ - while (chk < multisize) { - insw(du->dk_port + wd_data, &dummy, 1); - chk += sizeof(short); - } - - } - - /* final cleanup on DMA */ - if (((bp->b_flags & B_ERROR) == 0) - && ((du->dk_flags & (DKFL_DMA|DKFL_SINGLE)) == DKFL_DMA) - && wdtab[unit].b_active) { - int iosize; - - iosize = du->dk_currentiosize * DEV_BSIZE; - - du->dk_bc -= iosize; - - } - -outt: - if (wdtab[unit].b_active) { - if ((bp->b_flags & B_ERROR) == 0) { - du->dk_skip += du->dk_currentiosize;/* add to successful sectors */ - if (wdtab[unit].b_errcnt) - wderror(bp, du, "soft error"); - wdtab[unit].b_errcnt = 0; - - /* see if more to transfer */ - if (du->dk_bc > 0 && (du->dk_flags & DKFL_ERROR) == 0) { - if( (du->dk_flags & DKFL_SINGLE) || - ((bp->b_flags & B_READ) == 0)) { - wdtab[unit].b_active = 0; - wdstart(unit); - } else { - du->dk_timeout = 1 + 3; - } - return; /* next chunk is started */ - } else if ((du->dk_flags & (DKFL_SINGLE | DKFL_ERROR)) - == DKFL_ERROR) { - du->dk_skip = 0; - du->dk_flags &= ~DKFL_ERROR; - du->dk_flags |= DKFL_SINGLE; - wdtab[unit].b_active = 0; - wdstart(unit); - return; /* redo xfer sector by sector */ - } - } - -done: ; - /* done with this transfer, with or without error */ - du->dk_flags &= ~(DKFL_SINGLE|DKFL_DMA); - bufq_remove( &wdtab[unit].controller_queue, bp); - wdtab[unit].b_errcnt = 0; - bp->b_resid = bp->b_bcount - du->dk_skip * DEV_BSIZE; - wdutab[du->dk_lunit].b_active = 0; - du->dk_skip = 0; - devstat_end_transaction_buf(&du->dk_stats, bp); - biodone(bp); - } - - /* controller idle */ - wdtab[unit].b_active = 0; - - /* anything more on drive queue? */ - wdustart(du); - /* anything more for controller to do? */ - wdstart(unit); -} - -/* - * Initialize a drive. - */ -int -wdopen(dev_t dev, int flags, int fmt, struct thread *td) -{ - unsigned int lunit; - struct disk *du; - int error; - - lunit = dkunit(dev); - if (lunit >= NWD || dktype(dev) != 0) - return (ENXIO); - du = wddrives[lunit]; - if (du == NULL) - return (ENXIO); - - dev->si_iosize_max = 248 * 512; - /* Finish flushing IRQs left over from wdattach(). */ - if (wdtab[du->dk_ctrlr_cmd640].b_active == 2) - wdtab[du->dk_ctrlr_cmd640].b_active = 0; - - /* spin waiting for anybody else reading the disk label */ - while (du->dk_flags & DKFL_LABELLING) - tsleep((caddr_t)&du->dk_flags, 0, "wdopen", 1); -#if 1 - wdsleep(du->dk_ctrlr, "wdopn1"); - du->dk_flags |= DKFL_LABELLING; - du->dk_state = WANTOPEN; - { - struct disklabel label; - - bzero(&label, sizeof label); - label.d_secsize = du->dk_dd.d_secsize; - label.d_nsectors = du->dk_dd.d_nsectors; - label.d_ntracks = du->dk_dd.d_ntracks; - label.d_ncylinders = du->dk_dd.d_ncylinders; - label.d_secpercyl = du->dk_dd.d_secpercyl; - label.d_secperunit = du->dk_dd.d_secperunit; - error = dsopen(dev, fmt, 0, &du->dk_slices, &label); - } - du->dk_flags &= ~DKFL_LABELLING; - wdsleep(du->dk_ctrlr, "wdopn2"); - return (error); -#else - if ((du->dk_flags & DKFL_BSDLABEL) == 0) { - /* - * wdtab[ctrlr].b_active != 0 implies XXX applicable now ?? - * drive_queue[lunit].b_act == NULL (?) XXX applicable now ?? - * so the following guards most things (until the next i/o). - * It doesn't guard against a new i/o starting and being - * affected by the label being changed. Sigh. - */ - wdsleep(du->dk_ctrlr, "wdopn1"); - - du->dk_flags |= DKFL_LABELLING; - du->dk_state = WANTOPEN; - - error = dsinit(dkmodpart(dev, RAW_PART), - &du->dk_dd, &du->dk_slices); - if (error != 0) { - du->dk_flags &= ~DKFL_LABELLING; - return (error); - } - /* XXX check value returned by wdwsetctlr(). */ - wdwsetctlr(du); - if (dkslice(dev) == WHOLE_DISK_SLICE) { - dsopen(dev, fmt, du->dk_slices); - return (0); - } - - /* - * Read label using RAW_PART partition. - * - * If the drive has an MBR, then the current geometry (from - * wdgetctlr()) is used to read it; then the BIOS/DOS - * geometry is inferred and used to read the label off the - * 'c' partition. Otherwise the label is read using the - * current geometry. The label gives the final geometry. - * If bad sector handling is enabled, then this geometry - * is used to read the bad sector table. The geometry - * changes occur inside readdisklabel() and are propagated - * to the driver by resetting the state machine. - * - * XXX can now handle changes directly since dsinit() doesn't - * do too much. - */ - msg = correct_readdisklabel(dkmodpart(dev, RAW_PART), - &du->dk_dd); - /* XXX check value returned by wdwsetctlr(). */ - wdwsetctlr(du); - du->dk_flags &= ~DKFL_LABELLING; - if (msg != NULL) { - log(LOG_WARNING, "wd%d: cannot find label (%s)\n", - lunit, msg); - if (part != RAW_PART) - return (EINVAL); /* XXX needs translation */ - /* - * Soon return. This is how slices without labels - * are allowed. They only work on the raw partition. - */ - } else { - unsigned long newsize, offset, size; -#if 0 - /* - * Force RAW_PART partition to be the whole disk. - */ - offset = du->dk_dd.d_partitions[RAW_PART].p_offset; - if (offset != 0) { - printf( - "wd%d: changing offset of '%c' partition from %lu to 0\n", - du->dk_lunit, 'a' + RAW_PART, offset); - du->dk_dd.d_partitions[RAW_PART].p_offset = 0; - } - size = du->dk_dd.d_partitions[RAW_PART].p_size; - newsize = du->dk_dd.d_secperunit; /* XXX */ - if (size != newsize) { - printf( - "wd%d: changing size of '%c' partition from %lu to %lu\n", - du->dk_lunit, 'a' + RAW_PART, size, - newsize); - du->dk_dd.d_partitions[RAW_PART].p_size - = newsize; - } -#endif - } - - /* Pick up changes made by readdisklabel(). */ - wdsleep(du->dk_ctrlr, "wdopn2"); - du->dk_state = WANTOPEN; - } - - /* - * Warn if a partion is opened that overlaps another partition which - * is open unless one is the "raw" partition (whole disk). - */ - if ((du->dk_openpart & mask) == 0 && part != RAW_PART) { - int start, end; - - pp = &du->dk_dd.d_partitions[part]; - start = pp->p_offset; - end = pp->p_offset + pp->p_size; - for (pp = du->dk_dd.d_partitions; - pp < &du->dk_dd.d_partitions[du->dk_dd.d_npartitions]; - pp++) { - if (pp->p_offset + pp->p_size <= start || - pp->p_offset >= end) - continue; - if (pp - du->dk_dd.d_partitions == RAW_PART) - continue; - if (du->dk_openpart - & (1 << (pp - du->dk_dd.d_partitions))) - log(LOG_WARNING, - "wd%d%c: overlaps open partition (%c)\n", - lunit, part + 'a', - pp - du->dk_dd.d_partitions + 'a'); - } - } - if (part >= du->dk_dd.d_npartitions && part != RAW_PART) - return (ENXIO); - - dsopen(dev, fmt, du->dk_slices); - - return (0); -#endif -} - -/* - * Implement operations other than read/write. - * Called from wdstart or wdintr during opens. - * Uses finite-state-machine to track progress of operation in progress. - * Returns 0 if operation still in progress, 1 if completed, 2 if error. - */ -static int -wdcontrol(struct buf *bp) -{ - struct disk *du; - int ctrlr; - - du = wddrives[dkunit(bp->b_dev)]; - ctrlr = du->dk_ctrlr_cmd640; - - switch (du->dk_state) { - case WANTOPEN: -tryagainrecal: - wdtab[ctrlr].b_active = 1; - if (wdcommand(du, 0, 0, 0, 0, WDCC_RESTORE | WD_STEP) != 0) { - wderror(bp, du, "wdcontrol: wdcommand failed"); - goto maybe_retry; - } - du->dk_state = RECAL; - return (0); - case RECAL: - if (du->dk_status & WDCS_ERR || wdsetctlr(du) != 0) { - wderror(bp, du, "wdcontrol: recal failed"); -maybe_retry: - if (du->dk_status & WDCS_ERR) - wdunwedge(du); - du->dk_state = WANTOPEN; - if (++wdtab[ctrlr].b_errcnt < RETRIES) - goto tryagainrecal; - bp->b_error = ENXIO; /* XXX needs translation */ - bp->b_flags |= B_ERROR; - return (2); - } - wdtab[ctrlr].b_errcnt = 0; - du->dk_state = OPEN; - /* - * The rest of the initialization can be done by normal - * means. - */ - return (1); - } - panic("wdcontrol"); - return (2); -} - -/* - * Wait uninterruptibly until controller is not busy, then send it a command. - * The wait usually terminates immediately because we waited for the previous - * command to terminate. - */ -static int -wdcommand(struct disk *du, u_int cylinder, u_int head, u_int sector, - u_int count, u_int command) -{ - u_int wdc; - - wdc = du->dk_port; - if (du->cfg_flags & WDOPT_SLEEPHACK) { - /* OK, so the APM bios has put the disk into SLEEP mode, - * how can we tell ? Uhm, we can't. There is no - * standardized way of finding out, and the only way to - * wake it up is to reset it. Bummer. - * - * All the many and varied versions of the IDE/ATA standard - * explicitly tells us not to look at these registers if - * the disk is in SLEEP mode. Well, too bad really, we - * have to find out if it's in sleep mode before we can - * avoid reading the registers. - * - * I have reason to belive that most disks will return - * either 0xff or 0x00 in all but the status register - * when in SLEEP mode, but I have yet to see one return - * 0x00, so we don't check for that yet. - * - * The check for WDCS_BUSY is for the case where the - * bios spins up the disk for us, but doesn't initialize - * it correctly /phk - */ - if(inb(wdc + wd_precomp) + inb(wdc + wd_cyl_lo) + - inb(wdc + wd_cyl_hi) + inb(wdc + wd_sdh) + - inb(wdc + wd_sector) + inb(wdc + wd_seccnt) == 6 * 0xff) { - if (bootverbose) - printf("wd(%d,%d): disk aSLEEP\n", - du->dk_ctrlr, du->dk_unit); - wdunwedge(du); - } else if(inb(wdc + wd_status) == WDCS_BUSY) { - if (bootverbose) - printf("wd(%d,%d): disk is BUSY\n", - du->dk_ctrlr, du->dk_unit); - wdunwedge(du); - } - } - - if (wdwait(du, 0, TIMEOUT) < 0) - return (1); - if( command == WDCC_FEATURES) { - outb(wdc + wd_sdh, WDSD_IBM | (du->dk_unit << 4) | head); - outb(wdc + wd_features, count); - if ( count == WDFEA_SETXFER ) - outb(wdc + wd_seccnt, sector); - } else { - outb(wdc + wd_precomp, du->dk_dd.d_precompcyl / 4); - outb(wdc + wd_cyl_lo, cylinder); - outb(wdc + wd_cyl_hi, cylinder >> 8); - outb(wdc + wd_sdh, WDSD_IBM | (du->dk_unit << 4) | head); - if (head & WDSD_LBA) - outb(wdc + wd_sector, sector); - else - outb(wdc + wd_sector, sector + 1); - outb(wdc + wd_seccnt, count); - } - if (wdwait(du, (command == WDCC_DIAGNOSE || command == WDCC_IDC) - ? 0 : WDCS_READY, TIMEOUT) < 0) - return (1); - outb(wdc + wd_command, command); - return (0); -} - -static void -wdsetmulti(struct disk *du) -{ - /* - * The config option flags low 8 bits define the maximum multi-block - * transfer size. If the user wants the maximum that the drive - * is capable of, just set the low bits of the config option to - * 0x00ff. - */ - if ((du->cfg_flags & WDOPT_MULTIMASK) != 0 && (du->dk_multi > 1)) { - int configval = du->cfg_flags & WDOPT_MULTIMASK; - du->dk_multi = min(du->dk_multi, configval); - if (wdcommand(du, 0, 0, 0, du->dk_multi, WDCC_SET_MULTI)) { - du->dk_multi = 1; - } else { - if (wdwait(du, WDCS_READY, TIMEOUT) < 0) { - du->dk_multi = 1; - } - } - } else { - du->dk_multi = 1; - } -} - -/* - * issue IDC to drive to tell it just what geometry it is to be. - */ -static int -wdsetctlr(struct disk *du) -{ - int error = 0; -#ifdef WDDEBUG - printf("wd(%d,%d): wdsetctlr: C %lu H %lu S %lu\n", - du->dk_ctrlr, du->dk_unit, - du->dk_dd.d_ncylinders, du->dk_dd.d_ntracks, - du->dk_dd.d_nsectors); -#endif - if (!(du->dk_flags & DKFL_LBA)) { - if (du->dk_dd.d_ntracks == 0 || du->dk_dd.d_ntracks > 16) { - struct wdparams *wp; - - printf("wd%d: can't handle %lu heads from partition table ", - du->dk_lunit, du->dk_dd.d_ntracks); - /* obtain parameters */ - wp = &du->dk_params; - if (wp->wdp_heads > 0 && wp->wdp_heads <= 16) { - printf("(controller value %u restored)\n", - wp->wdp_heads); - du->dk_dd.d_ntracks = wp->wdp_heads; - } - else { - printf("(truncating to 16)\n"); - du->dk_dd.d_ntracks = 16; - } - } - - if (du->dk_dd.d_nsectors == 0 || du->dk_dd.d_nsectors > 255) { - printf("wd%d: cannot handle %lu sectors (max 255)\n", - du->dk_lunit, du->dk_dd.d_nsectors); - error = 1; - } - if (error) { - wdtab[du->dk_ctrlr_cmd640].b_errcnt += RETRIES; - return (1); - } - if (wdcommand(du, du->dk_dd.d_ncylinders, du->dk_dd.d_ntracks - 1, 0, - du->dk_dd.d_nsectors, WDCC_IDC) != 0 - || wdwait(du, WDCS_READY, TIMEOUT) < 0) { - wderror((struct buf *)NULL, du, "wdsetctlr failed"); - return (1); - } - } - - wdsetmulti(du); - -#ifdef NOTYET -/* set read caching and write caching */ - wdcommand(du, 0, 0, 0, WDFEA_RCACHE, WDCC_FEATURES); - wdwait(du, WDCS_READY, TIMEOUT); - - wdcommand(du, 0, 0, 0, WDFEA_WCACHE, WDCC_FEATURES); - wdwait(du, WDCS_READY, TIMEOUT); -#endif - - return (0); -} - -#if 0 -/* - * Wait until driver is inactive, then set up controller. - */ -static int -wdwsetctlr(struct disk *du) -{ - int stat; - int x; - - wdsleep(du->dk_ctrlr, "wdwset"); - x = splbio(); - stat = wdsetctlr(du); - wdflushirq(du, x); - splx(x); - return (stat); -} -#endif - -/* - * gross little callback function for wdddma interface. returns 1 for - * success, 0 for failure. - */ -static int -wdsetmode(int mode, void *wdinfo) -{ - int i; - struct disk *du; - - du = wdinfo; - if (bootverbose) - printf("wd%d: wdsetmode() setting transfer mode to %02x\n", - du->dk_lunit, mode); - i = wdcommand(du, 0, 0, mode, WDFEA_SETXFER, - WDCC_FEATURES) == 0 && - wdwait(du, WDCS_READY, TIMEOUT) == 0; - return i; -} - -/* - * issue READP to drive to ask it what it is. - */ -static int -wdgetctlr(struct disk *du) -{ - int i; - char tb[DEV_BSIZE], tb2[DEV_BSIZE]; - struct wdparams *wp = NULL; - u_long flags = du->cfg_flags; -again: - if (wdcommand(du, 0, 0, 0, 0, WDCC_READP) != 0 - || wdwait(du, WDCS_READY | WDCS_SEEKCMPLT | WDCS_DRQ, TIMEOUT) != 0) { - - /* - * if we failed on the second try, assume non-32bit - */ - if( du->dk_flags & DKFL_32BIT) - goto failed; - - /* XXX need to check error status after final transfer. */ - /* - * Old drives don't support WDCC_READP. Try a seek to 0. - * Some IDE controllers return trash if there is no drive - * attached, so first test that the drive can be selected. - * This also avoids long waits for nonexistent drives. - */ - if (wdwait(du, 0, TIMEOUT) < 0) - return (1); - outb(du->dk_port + wd_sdh, WDSD_IBM | (du->dk_unit << 4)); - DELAY(5000); /* usually unnecessary; drive select is fast */ - /* - * Do this twice: may get a false WDCS_READY the first time. - */ - inb(du->dk_port + wd_status); - if ((inb(du->dk_port + wd_status) & (WDCS_BUSY | WDCS_READY)) - != WDCS_READY - || wdcommand(du, 0, 0, 0, 0, WDCC_RESTORE | WD_STEP) != 0 - || wdwait(du, WDCS_READY | WDCS_SEEKCMPLT, TIMEOUT) != 0) - return (1); - - if (du->dk_unit == bootinfo.bi_n_bios_used) { - du->dk_dd.d_secsize = DEV_BSIZE; - du->dk_dd.d_nsectors = - bootinfo.bi_bios_geom[du->dk_unit] & 0xff; - du->dk_dd.d_ntracks = - ((bootinfo.bi_bios_geom[du->dk_unit] >> 8) & 0xff) - + 1; - /* XXX Why 2 ? */ - du->dk_dd.d_ncylinders = - (bootinfo.bi_bios_geom[du->dk_unit] >> 16) + 2; - du->dk_dd.d_secpercyl = - du->dk_dd.d_ntracks * du->dk_dd.d_nsectors; - du->dk_dd.d_secperunit = - du->dk_dd.d_secpercyl * du->dk_dd.d_ncylinders; -#if 0 - du->dk_dd.d_partitions[WDRAW].p_size = - du->dk_dd.d_secperunit; - du->dk_dd.d_type = DTYPE_ST506; - du->dk_dd.d_subtype |= DSTYPE_GEOMETRY; - strncpy(du->dk_dd.d_typename, "Bios geometry", - sizeof du->dk_dd.d_typename); - strncpy(du->dk_params.wdp_model, "ST506", - sizeof du->dk_params.wdp_model); -#endif - bootinfo.bi_n_bios_used ++; - return 0; - } - /* - * Fake minimal drive geometry for reading the MBR. - * readdisklabel() may enlarge it to read the label. - */ - du->dk_dd.d_secsize = DEV_BSIZE; - du->dk_dd.d_nsectors = 17; - du->dk_dd.d_ntracks = 1; - du->dk_dd.d_ncylinders = 1; - du->dk_dd.d_secpercyl = 17; - du->dk_dd.d_secperunit = 17; - -#if 0 - /* - * Fake maximal drive size for writing the label. - */ - du->dk_dd.d_partitions[RAW_PART].p_size = 64 * 16 * 1024; - - /* - * Fake some more of the label for printing by disklabel(1) - * in case there is no real label. - */ - du->dk_dd.d_type = DTYPE_ST506; - du->dk_dd.d_subtype |= DSTYPE_GEOMETRY; - strncpy(du->dk_dd.d_typename, "Fake geometry", - sizeof du->dk_dd.d_typename); -#endif - - /* Fake the model name for printing by wdattach(). */ - strncpy(du->dk_params.wdp_model, "unknown", - sizeof du->dk_params.wdp_model); - - return (0); - } - - /* obtain parameters */ - wp = &du->dk_params; - if (du->dk_flags & DKFL_32BIT) - insl(du->dk_port + wd_data, tb, sizeof(tb) / sizeof(long)); - else - insw(du->dk_port + wd_data, tb, sizeof(tb) / sizeof(short)); - - /* try 32-bit data path (VLB IDE controller) */ - if (flags & WDOPT_32BIT) { - if (! (du->dk_flags & DKFL_32BIT)) { - bcopy(tb, tb2, sizeof(struct wdparams)); - du->dk_flags |= DKFL_32BIT; - goto again; - } - - /* check that we really have 32-bit controller */ - if (bcmp (tb, tb2, sizeof(struct wdparams)) != 0) { -failed: - /* test failed, use 16-bit i/o mode */ - bcopy(tb2, tb, sizeof(struct wdparams)); - du->dk_flags &= ~DKFL_32BIT; - } - } - - bcopy(tb, wp, sizeof(struct wdparams)); - - /* shuffle string byte order */ - for (i = 0; (unsigned)i < sizeof(wp->wdp_model); i += 2) { - u_short *p; - - p = (u_short *) (wp->wdp_model + i); - *p = ntohs(*p); - } - /* - * Clean up the wdp_model by converting nulls to spaces, and - * then removing the trailing spaces. - */ - for (i = 0; (unsigned)i < sizeof(wp->wdp_model); i++) { - if (wp->wdp_model[i] == '\0') { - wp->wdp_model[i] = ' '; - } - } - for (i = sizeof(wp->wdp_model) - 1; - (i >= 0 && wp->wdp_model[i] == ' '); i--) { - wp->wdp_model[i] = '\0'; - } - - /* - * find out the drives maximum multi-block transfer capability - */ - du->dk_multi = wp->wdp_nsecperint & 0xff; - wdsetmulti(du); - - /* - * check drive's DMA capability - */ - if (wddma[du->dk_interface].wdd_candma) { - du->dk_dmacookie = wddma[du->dk_interface].wdd_candma( - du->dk_port, du->dk_ctrlr, du->dk_unit); - /* does user want this? */ - if ((du->cfg_flags & WDOPT_DMA) && - /* have we got a DMA controller? */ - du->dk_dmacookie && - /* can said drive do DMA? */ - wddma[du->dk_interface].wdd_dmainit(du->dk_dmacookie, wp, wdsetmode, du)) { - du->dk_flags |= DKFL_USEDMA; - } - } else { - du->dk_dmacookie = NULL; - } - -#ifdef WDDEBUG - printf( -"\nwd(%d,%d): wdgetctlr: gc %x cyl %d trk %d sec %d type %d sz %d model %s\n", - du->dk_ctrlr, du->dk_unit, wp->wdp_config, wp->wdp_cylinders, - wp->wdp_heads, wp->wdp_sectors, wp->wdp_buffertype, - wp->wdp_buffersize, wp->wdp_model); -#endif - - /* update disklabel given drive information */ - du->dk_dd.d_secsize = DEV_BSIZE; - if ((du->cfg_flags & WDOPT_LBA) && wp->wdp_lbasize) { - du->dk_dd.d_nsectors = 63; - if (wp->wdp_lbasize < 16*63*1024) { /* <=528.4 MB */ - du->dk_dd.d_ntracks = 16; - } - else if (wp->wdp_lbasize < 32*63*1024) { /* <=1.057 GB */ - du->dk_dd.d_ntracks = 32; - } - else if (wp->wdp_lbasize < 64*63*1024) { /* <=2.114 GB */ - du->dk_dd.d_ntracks = 64; - } - else if (wp->wdp_lbasize < 128*63*1024) { /* <=4.228 GB */ - du->dk_dd.d_ntracks = 128; - } - else if (wp->wdp_lbasize < 255*63*1024) { /* <=8.422 GB */ - du->dk_dd.d_ntracks = 255; - } - else { /* >8.422 GB */ - du->dk_dd.d_ntracks = 255; /* XXX */ - } - du->dk_dd.d_secpercyl= du->dk_dd.d_ntracks*du->dk_dd.d_nsectors; - du->dk_dd.d_ncylinders = wp->wdp_lbasize/du->dk_dd.d_secpercyl; - du->dk_dd.d_secperunit = wp->wdp_lbasize; - du->dk_flags |= DKFL_LBA; - } - else { - du->dk_dd.d_ncylinders = wp->wdp_cylinders; /* +- 1 */ - du->dk_dd.d_ntracks = wp->wdp_heads; - du->dk_dd.d_nsectors = wp->wdp_sectors; - du->dk_dd.d_secpercyl = - du->dk_dd.d_ntracks * du->dk_dd.d_nsectors; - du->dk_dd.d_secperunit = - du->dk_dd.d_secpercyl * du->dk_dd.d_ncylinders; - if (wp->wdp_cylinders == 16383 && - du->dk_dd.d_secperunit < wp->wdp_lbasize) { - du->dk_dd.d_secperunit = wp->wdp_lbasize; - du->dk_dd.d_ncylinders = - du->dk_dd.d_secperunit / du->dk_dd.d_secpercyl; - } - } - if (WDOPT_FORCEHD(du->cfg_flags)) { - du->dk_dd.d_ntracks = WDOPT_FORCEHD(du->cfg_flags); - du->dk_dd.d_secpercyl = - du->dk_dd.d_ntracks * du->dk_dd.d_nsectors; - du->dk_dd.d_ncylinders = - du->dk_dd.d_secperunit / du->dk_dd.d_secpercyl; - } - if (du->dk_dd.d_ncylinders > 0x10000 && !(du->cfg_flags & WDOPT_LBA)) { - du->dk_dd.d_ncylinders = 0x10000; - du->dk_dd.d_secperunit = du->dk_dd.d_secpercyl * - du->dk_dd.d_ncylinders; - printf( - "wd%d: cannot handle %d total sectors; truncating to %lu\n", - du->dk_lunit, wp->wdp_lbasize, du->dk_dd.d_secperunit); - } -#if 0 - du->dk_dd.d_partitions[RAW_PART].p_size = du->dk_dd.d_secperunit; - /* dubious ... */ - bcopy("ESDI/IDE", du->dk_dd.d_typename, 9); - bcopy(wp->wdp_model + 20, du->dk_dd.d_packname, 14 - 1); - /* better ... */ - du->dk_dd.d_type = DTYPE_ESDI; - du->dk_dd.d_subtype |= DSTYPE_GEOMETRY; -#endif - - return (0); -} - -int -wdclose(dev_t dev, int flags, int fmt, struct thread *td) -{ - dsclose(dev, fmt, wddrives[dkunit(dev)]->dk_slices); - return (0); -} - -int -wdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td) -{ - int lunit = dkunit(dev); - struct disk *du; - int error; - - du = wddrives[lunit]; - wdsleep(du->dk_ctrlr, "wdioct"); - error = dsioctl(dev, cmd, addr, flags, &du->dk_slices); - if (error != ENOIOCTL) - return (error); - return (ENOTTY); -} - -int -wdsize(dev_t dev) -{ - struct disk *du; - int lunit; - - lunit = dkunit(dev); - if (lunit >= NWD || dktype(dev) != 0) - return (-1); - du = wddrives[lunit]; - if (du == NULL) - return (-1); - return (dssize(dev, &du->dk_slices)); -} - -int -wddump(dev_t dev) -{ - struct disk *du; - struct disklabel *lp; - long num; /* number of sectors to write */ - int lunit, part; - long blkoff, blknum; - long blkcnt, blknext; - u_long ds_offset; - u_long nblocks; - static int wddoingadump = 0; - long cylin, head, sector; - long secpertrk, secpercyl; - char *addr; - - /* Toss any characters present prior to dump. */ - while (cncheckc() != -1) - ; - - /* Check for acceptable device. */ - /* XXX should reset to maybe allow du->dk_state < OPEN. */ - lunit = dkunit(dev); /* eventually support floppies? */ - part = dkpart(dev); - if (lunit >= NWD || (du = wddrives[lunit]) == NULL - || du->dk_state < OPEN - || (lp = dsgetlabel(dev, du->dk_slices)) == NULL) - return (ENXIO); - - /* Size of memory to dump, in disk sectors. */ - num = (u_long)Maxmem * PAGE_SIZE / du->dk_dd.d_secsize; - - - secpertrk = du->dk_dd.d_nsectors; - secpercyl = du->dk_dd.d_secpercyl; - nblocks = lp->d_partitions[part].p_size; - blkoff = lp->d_partitions[part].p_offset; - /* XXX */ - ds_offset = du->dk_slices->dss_slices[dkslice(dev)].ds_offset; - blkoff += ds_offset; - -#if 0 - printf("part %d, nblocks %lu, dumplo %ld num %ld\n", - part, nblocks, dumplo, num); -#endif - - /* Check transfer bounds against partition size. */ - if (dumplo < 0 || dumplo + num > nblocks) - return (EINVAL); - - /* Check if we are being called recursively. */ - if (wddoingadump) - return (EFAULT); - -#if 0 - /* Mark controller active for if we panic during the dump. */ - wdtab[du->dk_ctrlr].b_active = 1; -#endif - wddoingadump = 1; - - /* Recalibrate the drive. */ - DELAY(5); /* ATA spec XXX NOT */ - if (wdcommand(du, 0, 0, 0, 0, WDCC_RESTORE | WD_STEP) != 0 - || wdwait(du, WDCS_READY | WDCS_SEEKCMPLT, TIMEOUT) != 0 - || wdsetctlr(du) != 0) { - wderror((struct buf *)NULL, du, "wddump: recalibrate failed"); - return (EIO); - } - - du->dk_flags |= DKFL_SINGLE; - addr = (char *) 0; - blknum = dumplo + blkoff; - while (num > 0) { - blkcnt = num; - if (blkcnt > MAXTRANSFER) - blkcnt = MAXTRANSFER; - if ((du->dk_flags & DKFL_LBA) == 0) { - /* XXX keep transfer within current cylinder. */ - if ((blknum + blkcnt - 1) / secpercyl != - blknum / secpercyl) - blkcnt = secpercyl - (blknum % secpercyl); - } - blknext = blknum + blkcnt; - - /* Compute disk address. */ - if (du->dk_flags & DKFL_LBA) { - sector = (blknum >> 0) & 0xff; - cylin = (blknum >> 8) & 0xffff; - head = ((blknum >> 24) & 0xf) | WDSD_LBA; - } else { - cylin = blknum / secpercyl; - head = (blknum % secpercyl) / secpertrk; - sector = blknum % secpertrk; - } - -#if 0 - /* Let's just talk about this first... */ - printf("cylin %ld head %ld sector %ld addr %p count %ld\n", - cylin, head, sector, addr, blkcnt); - cngetc(); -#endif - - /* Do the write. */ - if (wdcommand(du, cylin, head, sector, blkcnt, WDCC_WRITE) - != 0) { - wderror((struct buf *)NULL, du, - "wddump: timeout waiting to to give command"); - return (EIO); - } - while (blkcnt != 0) { - if (is_physical_memory((vm_offset_t)addr)) - pmap_kenter((vm_offset_t)CADDR1, - trunc_page((vm_offset_t)addr)); - else - pmap_kenter((vm_offset_t)CADDR1, - trunc_page(0)); - - /* Ready to send data? */ - DELAY(5); /* ATA spec */ - if (wdwait(du, WDCS_READY | WDCS_SEEKCMPLT | WDCS_DRQ, TIMEOUT) - < 0) { - wderror((struct buf *)NULL, du, - "wddump: timeout waiting for DRQ"); - return (EIO); - } - if (du->dk_flags & DKFL_32BIT) - outsl(du->dk_port + wd_data, - CADDR1 + ((int)addr & PAGE_MASK), - DEV_BSIZE / sizeof(long)); - else - outsw(du->dk_port + wd_data, - CADDR1 + ((int)addr & PAGE_MASK), - DEV_BSIZE / sizeof(short)); - addr += DEV_BSIZE; - /* - * If we are dumping core, it may take a while. - * So reassure the user and hold off any watchdogs. - */ - if ((unsigned)addr % (1024 * 1024) == 0) { -#ifdef HW_WDOG - if (wdog_tickler) - (*wdog_tickler)(); -#endif /* HW_WDOG */ - printf("%ld ", num / (1024 * 1024 / DEV_BSIZE)); - } - num--; - blkcnt--; - } - - /* Wait for completion. */ - DELAY(5); /* ATA spec XXX NOT */ - if (wdwait(du, WDCS_READY | WDCS_SEEKCMPLT, TIMEOUT) < 0) { - wderror((struct buf *)NULL, du, - "wddump: timeout waiting for status"); - return (EIO); - } - - /* Check final status. */ - if ((du->dk_status - & (WDCS_READY | WDCS_SEEKCMPLT | WDCS_DRQ | WDCS_ERR)) - != (WDCS_READY | WDCS_SEEKCMPLT)) { - wderror((struct buf *)NULL, du, - "wddump: extra DRQ, or error"); - return (EIO); - } - - /* Update block count. */ - blknum = blknext; - - /* Operator aborting dump? */ - if (cncheckc() != -1) - return (EINTR); - } - return (0); -} - -static void -wderror(struct buf *bp, struct disk *du, char *mesg) -{ - if (bp == NULL) - printf("wd%d: %s", du->dk_lunit, mesg); - else - diskerr(bp, mesg, LOG_PRINTF, du->dk_skip, - dsgetlabel(bp->b_dev, du->dk_slices)); - printf(" (status %b error %b)\n", - du->dk_status, WDCS_BITS, du->dk_error, WDERR_BITS); -} - -/* - * Discard any interrupts that were latched by the interrupt system while - * we were doing polled i/o. - */ -static void -wdflushirq(struct disk *du, int old_ipl) -{ - wdtab[du->dk_ctrlr_cmd640].b_active = 2; - splx(old_ipl); - (void)splbio(); - wdtab[du->dk_ctrlr_cmd640].b_active = 0; -} - -/* - * Reset the controller. - */ -static int -wdreset(struct disk *du) -{ - int err = 0; - - if ((du->dk_flags & (DKFL_DMA|DKFL_SINGLE)) == DKFL_DMA) - wddma[du->dk_interface].wdd_dmadone(du->dk_dmacookie); - (void)wdwait(du, 0, TIMEOUT); - outb(du->dk_altport, WDCTL_IDS | WDCTL_RST); - DELAY(10 * 1000); - outb(du->dk_altport, WDCTL_IDS); - outb(du->dk_port + wd_sdh, WDSD_IBM | (du->dk_unit << 4)); - if (wdwait(du, 0, TIMEOUT) != 0) - err = 1; /* no IDE drive found */ - du->dk_error = inb(du->dk_port + wd_error); - if (du->dk_error != 0x01) - err = 1; /* the drive is incompatible */ - outb(du->dk_altport, WDCTL_4BIT); - return (err); -} - -/* - * Sleep until driver is inactive. - * This is used only for avoiding rare race conditions, so it is unimportant - * that the sleep may be far too short or too long. - */ -static void -wdsleep(int ctrlr, char *wmesg) -{ - int s = splbio(); - if (eide_quirks & Q_CMD640B) - ctrlr = PRIMARY; - while (wdtab[ctrlr].b_active) - tsleep((caddr_t)&wdtab[ctrlr].b_active, 0, wmesg, 1); - splx(s); -} - -static void -wdtimeout(void *cdu) -{ - struct disk *du; - int x; - static int timeouts; - - du = (struct disk *)cdu; - x = splbio(); - if (du->dk_timeout != 0 && --du->dk_timeout == 0) { - if(timeouts++ <= 5) { - char *msg; - - msg = (timeouts > 5) ? -"Last time I say: interrupt timeout. Probably a portable PC." : -"interrupt timeout"; - wderror((struct buf *)NULL, du, msg); - if (du->dk_dmacookie) - printf("wd%d: wdtimeout() DMA status %b\n", - du->dk_lunit, - wddma[du->dk_interface].wdd_dmastatus(du->dk_dmacookie), - WDDS_BITS); - } - wdunwedge(du); - wdflushirq(du, x); - du->dk_skip = 0; - du->dk_flags |= DKFL_SINGLE; - wdstart(du->dk_ctrlr); - } - timeout(wdtimeout, cdu, hz); - splx(x); -} - -/* - * Reset the controller after it has become wedged. This is different from - * wdreset() so that wdreset() can be used in the probe and so that this - * can restore the geometry . - */ -static int -wdunwedge(struct disk *du) -{ - struct disk *du1; - int lunit; - - /* Schedule other drives for recalibration. */ - for (lunit = 0; lunit < NWD; lunit++) - if ((du1 = wddrives[lunit]) != NULL && du1 != du - && du1->dk_ctrlr == du->dk_ctrlr - && du1->dk_state > WANTOPEN) - du1->dk_state = WANTOPEN; - - DELAY(RECOVERYTIME); - if (wdreset(du) == 0) { - /* - * XXX - recalibrate current drive now because some callers - * aren't prepared to have its state change. - */ - if (wdcommand(du, 0, 0, 0, 0, WDCC_RESTORE | WD_STEP) == 0 - && wdwait(du, WDCS_READY | WDCS_SEEKCMPLT, TIMEOUT) == 0 - && wdsetctlr(du) == 0) - return (0); - } - wderror((struct buf *)NULL, du, "wdunwedge failed"); - return (1); -} - -/* - * Wait uninterruptibly until controller is not busy and either certain - * status bits are set or an error has occurred. - * The wait is usually short unless it is for the controller to process - * an entire critical command. - * Return 1 for (possibly stale) controller errors, -1 for timeout errors, - * or 0 for no errors. - * Return controller status in du->dk_status and, if there was a controller - * error, return the error code in du->dk_error. - */ -#ifdef WD_COUNT_RETRIES -static int min_retries[NWDC]; -#endif - -static int -wdwait(struct disk *du, u_char bits_wanted, int timeout) -{ - int wdc; - u_char status; - -#define POLLING 1000 - - wdc = du->dk_port; - timeout += POLLING; - -/* - * This delay is really too long, but does not impact the performance - * as much when using the multi-sector option. Shorter delays have - * caused I/O errors on some drives and system configs. This should - * probably be fixed if we develop a better short term delay mechanism. - */ - DELAY(1); - - do { -#ifdef WD_COUNT_RETRIES - if (min_retries[du->dk_ctrlr] > timeout - || min_retries[du->dk_ctrlr] == 0) - min_retries[du->dk_ctrlr] = timeout; -#endif - du->dk_status = status = inb(wdc + wd_status); - /* - * Atapi drives have a very interesting feature, when attached - * as a slave on the IDE bus, and there is no master. - * They release the bus after getting the command. - * We should reselect the drive here to get the status. - */ - if (status == 0xff) { - outb(wdc + wd_sdh, WDSD_IBM | du->dk_unit << 4); - du->dk_status = status = inb(wdc + wd_status); - } - if (!(status & WDCS_BUSY)) { - if (status & WDCS_ERR) { - du->dk_error = inb(wdc + wd_error); - /* - * We once returned here. This is wrong - * because the error bit is apparently only - * valid after the controller has interrupted - * (e.g., the error bit is stale when we wait - * for DRQ for writes). So we can't depend - * on the error bit at all when polling for - * command completion. - */ - } - if ((status & bits_wanted) == bits_wanted) { - return (status & WDCS_ERR); - } - } - if (timeout < TIMEOUT) - /* - * Switch to a polling rate of about 1 KHz so that - * the timeout is almost machine-independent. The - * controller is taking a long time to respond, so - * an extra msec won't matter. - */ - DELAY(1000); - else - DELAY(1); - } while (--timeout != 0); - return (-1); -} - -#endif /* NWDC > 0 */ diff --git a/sys/dev/disk/wd/wdreg.h b/sys/dev/disk/wd/wdreg.h deleted file mode 100644 index 452db64217..0000000000 --- a/sys/dev/disk/wd/wdreg.h +++ /dev/null @@ -1,321 +0,0 @@ -/*- - * Copyright (c) 1991 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * William Jolitz. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * from: @(#)wdreg.h 7.1 (Berkeley) 5/9/91 - * $FreeBSD: src/sys/i386/isa/wdreg.h,v 1.30 1999/12/29 04:33:16 peter Exp $ - * $DragonFly: src/sys/dev/disk/wd/Attic/wdreg.h,v 1.3 2003/08/27 10:35:17 rob Exp $ - */ - -/* - * modified for PC9801 by F.Ukai - * Kyoto University Microcomputer Club (KMC) - */ - -/* - * Disk Controller register definitions. - */ -#ifdef PC98 -#define wd_data 0x0 /* data register (R/W - 16 bits) */ -#define wd_error 0x2 /* error register (R) */ -#define wd_precomp wd_error /* write precompensation (W) */ -#define wd_features wd_error /* features register (W) */ -#define wd_seccnt 0x4 /* sector count (R/W) */ -#define wd_sector 0x6 /* first sector number (R/W) */ -#define wd_cyl_lo 0x8 /* cylinder address, low byte (R/W) */ -#define wd_cyl_hi 0xa /* cylinder address, high byte (R/W)*/ -#define wd_sdh 0xc /* sector size/drive/head (R/W)*/ -#define wd_command 0xe /* command register (W) */ -#define wd_status wd_command /* immediate status (R) */ - -#define wd_altsts_nec 0x10c /*alternate fixed disk status(via 1015) (R)*/ -#define wd_ctlr_nec 0x10c /*fixed disk controller control(via 1015) (W)*/ -#define wd_altsts_epson 0x3 /*alternate fixed disk status(via 1015) (R)*/ -#define wd_ctlr_epson 0x3 /*fixed disk controller control(via 1015) (W)*/ -#define wd_altsts wd_altsts_nec - -#define WDCTL_4BIT 0x8 /* use four head bits (wd1003) */ -#define WDCTL_RST 0x4 /* reset the controller */ -#define WDCTL_IDS 0x2 /* disable controller interrupts */ -#define wd_digin 0x10e /* disk controller input(via 1015) (R)*/ -#else /* IBM-PC */ -#define wd_data 0x0 /* data register (R/W - 16 bits) */ -#define wd_error 0x1 /* error register (R) */ -#define wd_precomp wd_error /* write precompensation (W) */ -#define wd_features wd_error /* features register (W) */ -#define wd_seccnt 0x2 /* sector count (R/W) */ -#define wd_sector 0x3 /* first sector number (R/W) */ -#define wd_cyl_lo 0x4 /* cylinder address, low byte (R/W) */ -#define wd_cyl_hi 0x5 /* cylinder address, high byte (R/W)*/ -#define wd_sdh 0x6 /* sector size/drive/head (R/W)*/ -#define wd_command 0x7 /* command register (W) */ -#define wd_status wd_command /* immediate status (R) */ - -#define wd_altsts 0x206 /*alternate fixed disk status(via 1015) (R)*/ -#define wd_ctlr 0x206 /*fixed disk controller control(via 1015) (W)*/ -#define WDCTL_4BIT 0x8 /* use four head bits (wd1003) */ -#define WDCTL_RST 0x4 /* reset the controller */ -#define WDCTL_IDS 0x2 /* disable controller interrupts */ -#define wd_digin 0x207 /* disk controller input(via 1015) (R)*/ -#endif /* PC98 */ - -/* - * Status Bits. - */ -#define WDCS_BUSY 0x80 /* Controller busy bit. */ -#define WDCS_READY 0x40 /* Selected drive is ready */ -#define WDCS_WRTFLT 0x20 /* Write fault */ -#define WDCS_SEEKCMPLT 0x10 /* Seek complete */ -#define WDCS_DRQ 0x08 /* Data request bit. */ -#define WDCS_ECCCOR 0x04 /* ECC correction made in data */ -#define WDCS_INDEX 0x02 /* Index pulse from selected drive */ -#define WDCS_ERR 0x01 /* Error detect bit. */ - -#define WDCS_BITS "\020\010busy\007rdy\006wrtflt\005seekdone\004drq\003ecc_cor\002index\001err" -#define WDERR_ABORT 0x04 - -#define WDERR_BITS "\020\010badblk\007uncorr\006id_crc\005no_id\003abort\002tr000\001no_dam" - -/* - * Commands for Disk Controller. - */ -#define WDCC_RESTORE 0x10 /* disk restore code -- resets cntlr */ - -#define WDCC_READ 0x20 /* disk read code */ -#define WDCC_WRITE 0x30 /* disk write code */ -#define WDCC__LONG 0x02 /* modifier -- access ecc bytes */ -#define WDCC__NORETRY 0x01 /* modifier -- no retrys */ - -#define WDCC_FORMAT 0x50 /* disk format code */ -#define WDCC_DIAGNOSE 0x90 /* controller diagnostic */ -#define WDCC_IDC 0x91 /* initialize drive command */ -#define WDCC_READ_MULTI 0xC4 /* read multiple */ -#define WDCC_WRITE_MULTI 0xC5 /* write multiple */ -#define WDCC_SET_MULTI 0xC6 /* set multiple count */ -#define WDCC_READ_DMA 0xC8 /* read using DMA */ -#define WDCC_WRITE_DMA 0xCA /* write using DMA */ - - -#define WDCC_EXTDCMD 0xE0 /* send extended command */ -#define WDCC_READP 0xEC /* read parameters from controller */ -#define WDCC_FEATURES 0xEF /* features control */ - -#define WDCC_DEFECT 0xF0 /* read defect list */ - -#define WDFEA_NORCACHE 0x55 /* read cache disable */ -#define WDFEA_RCACHE 0xAA /* read cache enable */ -#define WDFEA_NOWCACHE 0x82 /* write cache disable */ -#define WDFEA_WCACHE 0x02 /* write cache enable */ -#define WDFEA_SETXFER 0x03 /* set transfer mode */ - -#define WD_STEP 0 /* winchester- default 35us step */ - -#define WDSD_IBM 0xa0 /* forced to 512 byte sector, ecc */ -#define WDSD_LBA 0x40 /* use Logical Block Adressing */ - -#ifdef _KERNEL -/* - * read parameters command returns this: - */ -struct wdparams { - /* - * XXX partly based on DRAFT X3T13/1153D rev 14. - * by the time you read this it will have changed. - * Offsets in words - * (as that's how they are usually presented in tables - * e.g. QUANTUM Product manuals) - */ - /* drive info */ - short wdp_config; /*0 general configuration bits */ - u_short wdp_cylinders; /*1 number of cylinders */ - short wdp_reserved2; /*2*/ - u_short wdp_heads; /*3 number of heads */ - short wdp_unfbytespertrk; /*4 number of unformatted bytes/track */ - short wdp_unfbytes; /*5 number of unformatted bytes/sec */ - u_short wdp_sectors; /*6 number of sectors per track */ - short wdp_vendorunique[3]; /*7,8,9*/ - /* controller info */ - char wdp_serial[20]; /*10-19 serial number */ - short wdp_buffertype; /*20 buffer type */ -#define WDTYPE_SINGLEPORTSECTOR 1 /* single port, single sector buffer */ -#define WDTYPE_DUALPORTMULTI 2 /* dual port, multiple sector buffer */ -#define WDTYPE_DUALPORTMULTICACHE 3 /* above plus track cache */ - short wdp_buffersize; /*21 buffer size, in 512-byte units */ - short wdp_necc; /*22 ecc bytes appended */ - char wdp_rev[8]; /*23-26 firmware revision */ - char wdp_model[40]; /*27-46 model name */ - char wdp_nsecperint; /*47L sectors per interrupt */ - char wdp_vendorunique1; /*47H*/ - short wdp_usedmovsd; /*48 can use double word read/write? */ - char wdp_vendorunique2; /*49L*/ - char wdp_capability; /*49H various capability bits */ - short wdp_cap_validate; /*50 validation for above */ - char wdp_vendorunique3; /*51L*/ - char wdp_opiomode; /*51H PIO modes 0-2 */ - char wdp_vendorunique4; /*52*/ - char wdp_odmamode; /*52 old DMA modes, not in ATA-3 */ - short wdp_atavalid; /*53 validation for newer fields */ - short wdp_currcyls; /*54 */ - short wdp_currheads; /*55 */ - short wdp_currsectors; /*56 */ - short wdp_currsize0; /*57 CHS size*/ - short wdp_currsize1; /*58 CHS size*/ - char wdp_currmultsect; /*59L */ - char wdp_multsectvalid; /*59H */ - int wdp_lbasize; /*60,61*/ - short wdp_dmasword; /*62 obsolete in ATA-3 */ - short wdp_dmamword; /*63 multiword DMA modes */ - short wdp_eidepiomodes; /*64 advanced PIO modes */ - short wdp_eidedmamin; /*65 fastest possible DMA timing */ - short wdp_eidedmanorm; /*66 recommended DMA timing */ - short wdp_eidepioblind; /*67 fastest possible blind PIO */ - short wdp_eidepioacked; /*68 fastest possible IORDY PIO */ - short wdp_reserved69; /*69*/ - short wdp_reserved70; /*70*/ - short wdp_reserved71; /*71*/ - short wdp_reserved72; /*72*/ - short wdp_reserved73; /*73*/ - short wdp_reserved74; /*74*/ - short wdp_queuelen; /*75*/ - short wdp_reserved76; /*76*/ - short wdp_reserved77; /*77*/ - short wdp_reserved78; /*78*/ - short wdp_reserved79; /*79*/ - short wdp_versmaj; /*80*/ - short wdp_versmin; /*81*/ - short wdp_featsupp1; /*82*/ - short wdp_featsupp2; /*83*/ - short wdp_featsupp3; /*84*/ - short wdp_featenab1; /*85*/ - short wdp_featenab2; /*86*/ - short wdp_featenab3; /*87*/ - short wdp_udmamode; /*88 UltraDMA modes */ - short wdp_erasetime; /*89*/ - short wdp_enherasetime; /*90*/ - short wdp_apmlevel; /*91*/ - short wdp_reserved92[34]; /*92*/ - short wdp_rmvcap; /*93*/ - short wdp_securelevel; /*94*/ -}; - -/* - * IDE DMA support. - * This is based on what is needed for the IDE DMA function of the Intel - * Triton chipset; hopefully it's general enough to be used for other - * chipsets as well. - * - * To use this: - * For each drive which you might want to do DMA on, call wdd_candma() - * to get a cookie. If it returns a null pointer, then the drive - * can't do DMA. Then call wdd_dmainit() to initialize the controller - * and drive. wdd_dmainit should leave PIO modes operational, though - * perhaps with suboptimal performance. - * - * Check the transfer by calling wdd_dmaverify(). The cookie is what - * you got before; vaddr is the virtual address of the buffer to be - * written; len is the length of the buffer; and direction is either - * B_READ or B_WRITE. This function verifies that the DMA hardware is - * capable of handling the request you've made. - * - * Setup the transfer by calling wdd_dmaprep(). This takes the same - * paramaters as wdd_dmaverify(). - * - * Send a read/write DMA command to the drive. - * - * Call wdd_dmastart(). - * - * Wait for an interrupt. Multi-sector transfers will only interrupt - * at the end of the transfer. - * - * Call wdd_dmadone(). It will return the status as defined by the - * WDDS_* constants below. - */ -struct wddma { - void *(*wdd_candma) /* returns a cookie if PCI */ - (int iobase_wd, int ctlr, int unit); - int (*wdd_dmaverify) /* verify that request is DMA-able */ - (void *cookie, char *vaddr, u_long len, int direction); - int (*wdd_dmaprep) /* prepare DMA hardware */ - (void *cookie, char *vaddr, u_long len, int direction); - void (*wdd_dmastart) /* begin DMA transfer */ - (void *cookie); - int (*wdd_dmadone) /* DMA transfer completed */ - (void *cookie); - int (*wdd_dmastatus) /* return status of DMA */ - (void *cookie); - int (*wdd_dmainit) /* initialize controller and drive */ - (void *cookie, - struct wdparams *wp, - int(wdcmd)(int mode, void *wdinfo), - void *wdinfo); - int (*wdd_iobase) /* returns iobase address */ - (void *cookie); - int (*wdd_altiobase) /* returns altiobase address */ - (void *cookie); -}; - -/* logical status bits returned by wdd_dmastatus */ -#define WDDS_ACTIVE 0x0001 -#define WDDS_ERROR 0x0002 -#define WDDS_INTERRUPT 0x0004 - -#define WDDS_BITS "\20\4interrupt\2error\1active" - -/* defines for ATA timing modes */ -#define WDDMA_GRPMASK 0xf8 -#define WDDMA_MODEMASK 0x07 -/* flow-controlled PIO modes */ -#define WDDMA_PIO 0x10 -#define WDDMA_PIO3 0x10 -#define WDDMA_PIO4 0x11 -/* multi-word DMA timing modes */ -#define WDDMA_MDMA 0x20 -#define WDDMA_MDMA0 0x20 -#define WDDMA_MDMA1 0x21 -#define WDDMA_MDMA2 0x22 - -/* Ultra DMA timing modes */ -#define WDDMA_UDMA 0x40 -#define WDDMA_UDMA0 0x40 -#define WDDMA_UDMA1 0x41 -#define WDDMA_UDMA2 0x42 - -#define Q_CMD640B 0x00000001 /* CMD640B quirk: serialize IDE channels */ -void wdc_pci(int quirks); - -extern struct wddma wddma[]; - -void wdintr (void *unit); - -#endif /* _KERNEL */ diff --git a/sys/dev/disk/wfd/wfd.c b/sys/dev/disk/wfd/wfd.c deleted file mode 100644 index 27c51e301f..0000000000 --- a/sys/dev/disk/wfd/wfd.c +++ /dev/null @@ -1,729 +0,0 @@ -/* - * Copyright (c) 1997,1998 Junichi Satoh - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer as - * the first lines of this file unmodified. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY Junichi Satoh ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL Junichi Satoh BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: src/sys/i386/isa/wfd.c,v 1.35 2000/01/29 16:00:33 peter Exp $ - * $DragonFly: src/sys/dev/disk/wfd/Attic/wfd.c,v 1.8 2003/08/07 21:16:54 dillon Exp $ - */ - -/* - * ATAPI Floppy, LS-120 driver - */ - -#include "use_wdc.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -static d_open_t wfdopen; -static d_close_t wfdclose; -static d_ioctl_t wfdioctl; -static d_strategy_t wfdstrategy; - -static struct cdevsw wfd_cdevsw = { - /* name */ "wfd", - /* maj */ WFD_CDEV_MAJOR, - /* flags */ D_DISK, - /* port */ NULL, - /* autoq */ 0, - - /* open */ wfdopen, - /* close */ wfdclose, - /* read */ physread, - /* write */ physwrite, - /* ioctl */ wfdioctl, - /* poll */ nopoll, - /* mmap */ nommap, - /* strategy */ wfdstrategy, - /* dump */ nodump, - /* psize */ nopsize, -}; - -int wfdattach(struct atapi*, int, struct atapi_params*, int); - -#define NUNIT (NWDC*2) /* Max. number of devices */ -#define UNIT(d) ((minor(d) >> 3) & 3) /* Unit part of minor device number */ - -#define F_BOPEN 0x0001 /* The block device is opened */ -#define F_MEDIA_CHANGED 0x0002 /* The media have changed since open */ -#define F_DEBUG 0x0004 /* Print debug info */ - -/* - * LS-120 Capabilities and Mechanical Status Page - */ -struct cappage { - /* Mode data header */ - u_short data_length; - u_char medium_type; -#define MDT_UNKNOWN 0x00 -#define MDT_NO_DISC 0x70 -#define MDT_DOOR_OPEN 0x71 -#define MDT_FMT_ERROR 0x72 - -#define MDT_2DD_UN 0x10 -#define MDT_2DD 0x11 -#define MDT_2HD_UN 0x20 -#define MDT_2HD_12_98 0x22 -#define MDT_2HD_12 0x23 -#define MDT_2HD_144 0x24 -#define MDT_LS120 0x31 - - unsigned reserved0 :7; - unsigned wp :1; /* Write protect */ - u_char reserved1[4]; - - /* Capabilities page */ - unsigned page_code :6; /* Page code - Should be 0x5 */ -#define CAP_PAGE 0x05 - unsigned reserved1_6 :1; /* Reserved */ - unsigned ps :1; /* The device is capable of saving the page */ - u_char page_length; /* Page Length - Should be 0x1e */ - u_short transfer_rate; /* In kilobits per second */ - u_char heads, sectors; /* Number of heads, Number of sectors per track */ - u_short sector_size; /* Byes per sector */ - u_short cyls; /* Number of cylinders */ - u_char reserved10[10]; - u_char motor_delay; /* Motor off delay */ - u_char reserved21[7]; - u_short rpm; /* Rotations per minute */ - u_char reserved30[2]; -}; - -struct wfd { - struct atapi *ata; /* Controller structure */ - int unit; /* IDE bus drive unit */ - int lun; /* Logical device unit */ - int flags; /* Device state flags */ - int refcnt; /* The number of raw opens */ - int maxblks; /* transfer size limit */ - struct buf_queue_head buf_queue; /* Queue of i/o requests */ - struct atapi_params *param; /* Drive parameters table */ - struct cappage cap; /* Capabilities page info */ - char description[80]; /* Device description */ - struct diskslices *dk_slices; /* virtual drives */ - - struct devstat device_stats; -}; - -static struct wfd *wfdtab[NUNIT]; /* Drive info by unit number */ -static int wfdnlun = 0; /* Number of configured drives */ - -static void wfd_start (struct wfd *t); -static void wfd_done (struct wfd *t, struct buf *bp, int resid, - struct atapires result); -static void wfd_error (struct wfd *t, struct atapires result); -static int wfd_request_wait (struct wfd *t, u_char cmd, u_char a1, u_char a2, - u_char a3, u_char a4, u_char a5, u_char a6, u_char a7, u_char a8, - u_char a9, char *addr, int count); -static void wfd_describe (struct wfd *t); -static int wfd_eject (struct wfd *t, int closeit); - -/* - * Dump the array in hexadecimal format for debugging purposes. - */ -static void wfd_dump (int lun, char *label, void *data, int len) -{ - u_char *p = data; - - printf ("wfd%d: %s %x", lun, label, *p++); - while (--len > 0) - printf ("-%x", *p++); - printf ("\n"); -} - -int -wfdattach (struct atapi *ata, int unit, struct atapi_params *ap, int debug) -{ - struct wfd *t; - struct atapires result; - int lun, i; - - if (wfdnlun >= NUNIT) { - printf ("wfd: too many units\n"); - return (0); - } - if (!atapi_request_immediate) { - printf("wfd: configuration error, ATAPI core code not present!\n"); - printf("wfd: check `options ATAPI_STATIC' in your kernel config file!\n"); - return (0); - } - t = malloc (sizeof (struct wfd), M_TEMP, M_NOWAIT); - if (! t) { - printf ("wfd: out of memory\n"); - return (0); - } - wfdtab[wfdnlun] = t; - bzero (t, sizeof (struct wfd)); - bufq_init(&t->buf_queue); - t->ata = ata; - t->unit = unit; - lun = t->lun = wfdnlun; - t->param = ap; - t->flags = F_MEDIA_CHANGED; - t->refcnt = 0; - if (debug) { - t->flags |= F_DEBUG; - /* Print params. */ - wfd_dump (t->lun, "info", ap, sizeof *ap); - } - - /* Get drive capabilities. */ - /* Do it twice to avoid the stale media changed state. */ - for (i = 0; i < 2; i++) { - result = atapi_request_immediate (ata, unit, ATAPI_MODE_SENSE, - 0, CAP_PAGE, 0, 0, 0, 0, - sizeof (t->cap) >> 8, sizeof (t->cap), - 0, 0, 0, 0, 0, 0, 0, (char*) &t->cap, sizeof (t->cap)); - } - - if (result.code == RES_ERR && - (result.error & AER_SKEY) == AER_SK_UNIT_ATTENTION) - result = atapi_request_immediate (ata, unit, ATAPI_MODE_SENSE, - 0, CAP_PAGE, 0, 0, 0, 0, sizeof (t->cap) >> 8, - sizeof (t->cap), 0, 0, 0, 0, 0, 0, 0, - (char*) &t->cap, sizeof (t->cap)); - - /* Some drives have shorter capabilities page. */ - if (result.code == RES_UNDERRUN) - result.code = 0; - - if (result.code == 0) { - wfd_describe (t); - if (t->flags & F_DEBUG) - wfd_dump (t->lun, "cap", &t->cap, sizeof t->cap); - } else - return -1; - - /* - * The IOMEGA ZIP 100, at firmware 21.* and 23.* at least - * is known to lock up if transfers > 64 blocks are - * requested. - */ - if (!strcmp(ap->model, "IOMEGA ZIP 100 ATAPI")) { - printf("wfd%d: buggy Zip drive, 64-block transfer limit set\n", - t->lun); - t->maxblks = 64; - } else { - t->maxblks = 0; /* no limit */ - } - - - - make_dev(&wfd_cdevsw, dkmakeminor(t->lun, WHOLE_DISK_SLICE, RAW_PART), - UID_ROOT, GID_OPERATOR, 0640, "rwfd%d", t->lun); - - /* - * Export the drive to the devstat interface. - */ - devstat_add_entry(&t->device_stats, "wfd", - t->lun, t->cap.sector_size, - DEVSTAT_NO_ORDERED_TAGS, - DEVSTAT_TYPE_FLOPPY | DEVSTAT_TYPE_IF_IDE, - DEVSTAT_PRIORITY_WFD); - wfdnlun++; - return (1); -} - -void wfd_describe (struct wfd *t) -{ - int no_print = 0; - - t->cap.cyls = ntohs (t->cap.cyls); - t->cap.sector_size = ntohs (t->cap.sector_size); - - printf ("wfd%d: ", t->lun); - switch (t->cap.medium_type) { - case MDT_UNKNOWN: - printf ("medium type unknown (no disk)"); - no_print = 1; - break; - case MDT_2DD_UN: - printf ("2DD(capacity unknown) floppy disk loaded"); - no_print = 1; - break; - case MDT_2DD: - printf ("720KB floppy disk loaded"); - break; - case MDT_2HD_UN: - printf ("2HD(capacity unknown) floppy disk loaded"); - no_print = 1; - break; - case MDT_2HD_12_98: - printf ("1.25MB(PC-9801 format) floppy disk loaded"); - break; - case MDT_2HD_12: - printf ("1.2MB floppy disk loaded"); - break; - case MDT_2HD_144: - printf ("1.44MB floppy disk loaded"); - break; - case MDT_LS120: - printf ("120MB floppy disk loaded"); - break; - case MDT_NO_DISC: - printf ("no disc inside"); - no_print = 1; - break; - case MDT_DOOR_OPEN: - printf ("door open"); - no_print = 1; - break; - case MDT_FMT_ERROR: - printf ("medium format error"); - no_print = 1; - break; - default: - printf ("medium type=0x%x", t->cap.medium_type); - break; - } - if (t->cap.wp) - printf(", write protected"); - printf ("\n"); - - if (!no_print) { - printf ("wfd%d: ", t->lun); - printf ("%u cyls", t->cap.cyls); - printf (", %u heads, %u S/T", t->cap.heads, t->cap.sectors); - printf (", %u B/S", t->cap.sector_size); - printf ("\n"); - } -} - -int wfdopen (dev_t dev, int flags, int fmt, struct thread *td) -{ - int lun = UNIT(dev); - struct wfd *t; - struct atapires result; - int errcode = 0; - struct disklabel label; - - /* Check that the device number is legal - * and the ATAPI driver is loaded. */ - if (lun >= wfdnlun || ! atapi_request_immediate) - return (ENXIO); - t = wfdtab[lun]; - - t->flags &= ~F_MEDIA_CHANGED; - /* Lock the media. */ - wfd_request_wait (t, ATAPI_PREVENT_ALLOW, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0); - - /* Sense the media type */ - result = atapi_request_wait (t->ata, t->unit, ATAPI_MODE_SENSE, - 0, CAP_PAGE, 0, 0, 0, 0, - sizeof (t->cap) >> 8, sizeof (t->cap), - 0, 0, 0, 0, 0, 0, 0, - (char*) &t->cap, sizeof (t->cap)); - if (result.code) - printf ("wfd%d: Sense the media type is failed.\n", t->lun); - else { - t->cap.cyls = ntohs (t->cap.cyls); - t->cap.sector_size = ntohs (t->cap.sector_size); - } - - /* Build label for whole disk. */ - bzero(&label, sizeof label); - label.d_secsize = t->cap.sector_size; - label.d_nsectors = t->cap.sectors; - label.d_ntracks = t->cap.heads; - label.d_ncylinders = t->cap.cyls; - label.d_secpercyl = t->cap.heads * t->cap.sectors; - label.d_rpm = 720; - label.d_secperunit = label.d_secpercyl * t->cap.cyls; - - /* Initialize slice tables. */ - errcode = dsopen(dev, fmt, 0, &t->dk_slices, &label); - if (errcode != 0) - return errcode; - - t->flags |= F_BOPEN; - return (0); -} - -/* - * Close the device. Only called if we are the LAST - * occurence of an open device. - */ -int wfdclose (dev_t dev, int flags, int fmt, struct thread *td) -{ - int lun = UNIT(dev); - struct wfd *t = wfdtab[lun]; - - dsclose(dev, fmt, t->dk_slices); - if(!dsisopen(t->dk_slices)) { - /* If we were the last open of the entire device, release it. */ - if (! t->refcnt) - wfd_request_wait (t, ATAPI_PREVENT_ALLOW, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - t->flags &= ~F_BOPEN; - } - return (0); -} - -/* - * Actually translate the requested transfer into one the physical driver can - * understand. The transfer is described by a buf and will include only one - * physical transfer. - */ -void wfdstrategy (struct buf *bp) -{ - int lun = UNIT(bp->b_dev); - struct wfd *t = wfdtab[lun]; - int x; - - /* If it's a null transfer, return immediatly. */ - if (bp->b_bcount == 0) { - bp->b_resid = 0; - biodone (bp); - return; - } - - /* - * Do bounds checking, adjust transfer, and set b_pblkno. - */ - if (dscheck(bp, t->dk_slices) <= 0) { - biodone(bp); - return; - } - - x = splbio(); - - /* Place it in the queue of disk activities for this disk. */ - bufqdisksort (&t->buf_queue, bp); - - /* Tell the device to get going on the transfer if it's - * not doing anything, otherwise just wait for completion. */ - wfd_start (t); - splx(x); -} - -/* - * Look to see if there is a buf waiting for the device - * and that the device is not already busy. If both are true, - * It dequeues the buf and creates an ATAPI command to perform the - * transfer in the buf. - * The bufs are queued by the strategy routine (wfdstrategy). - * Must be called at the correct (splbio) level. - */ -static void wfd_start (struct wfd *t) -{ - struct buf *bp = bufq_first(&t->buf_queue); - u_long blkno, nblk; - u_char op_code; - long count; - int pxcount, pxnblk; - u_char *pxdest; - - - /* See if there is a buf to do and we are not already doing one. */ - if (! bp) - return; - - /* Unqueue the request. */ - bufq_remove(&t->buf_queue, bp); - - /* Tell devstat we are starting on the transaction */ - devstat_start_transaction(&t->device_stats); - - /* We have a buf, now we should make a command - * First, translate the block to absolute and put it in terms of the - * logical blocksize of the device. */ - blkno = bp->b_pblkno / (t->cap.sector_size / 512); - nblk = (bp->b_bcount + (t->cap.sector_size - 1)) / t->cap.sector_size; - - if ((t->maxblks == 0) || (nblk <= t->maxblks)) { - - if(bp->b_flags & B_READ) { - op_code = ATAPI_READ_BIG; - count = bp->b_bcount; - } else { - op_code = ATAPI_WRITE_BIG; - count = -bp->b_bcount; - } - - /* only one transfer */ - (int)bp->b_driver1 = 0; - (int)bp->b_driver2 = 0; - atapi_request_callback (t->ata, t->unit, op_code, 0, - blkno>>24, blkno>>16, blkno>>8, blkno, - 0, nblk>>8, nblk, 0, 0, - 0, 0, 0, 0, 0, - (u_char*) bp->b_data, count, - (void*)wfd_done, t, bp); - } else { - - /* - * We can't handle this request in a single - * read/write operation. Instead, queue a set of - * transfers, and record the number of transfers - * and the running residual in the b_driver - * fields of the bp. - */ - - if(bp->b_flags & B_READ) { - op_code = ATAPI_READ_BIG; - } else { - op_code = ATAPI_WRITE_BIG; - } - - /* calculate number of transfers */ - (int)bp->b_driver1 = (nblk - 1) / t->maxblks; - (int)bp->b_driver2 = 0; - - pxdest = (u_char *)bp->b_data; - pxcount = bp->b_bcount; - - /* construct partial transfer requests */ - while (nblk > 0) { - pxnblk = min(nblk, t->maxblks); - count = min(pxcount, t->maxblks * t->cap.sector_size); - - atapi_request_callback(t->ata, t->unit, op_code, 0, - blkno>>24, blkno>>16, blkno>>8, - blkno, 0, pxnblk>>8, pxnblk, - 0, 0, 0, 0, 0, 0, 0, - pxdest, - (bp->b_flags & B_READ) ? - count : -count, - (void*)wfd_done, t, bp); - nblk -= pxnblk; - pxcount -= count; - pxdest += count; - blkno += pxnblk; - } - } -} - -static void wfd_done (struct wfd *t, struct buf *bp, int resid, - struct atapires result) -{ - - if (result.code) { - wfd_error (t, result); - bp->b_error = EIO; - bp->b_flags |= B_ERROR; - } else - (int)bp->b_driver2 += resid; - /* - * We can't call biodone until all outstanding - * transfer fragments are handled. If one hits - * an error, we will be returning an error, but - * only when all are complete. - */ - if (((int)bp->b_driver1)-- <= 0) { - bp->b_resid = (int)bp->b_driver2; - devstat_end_transaction_buf(&t->device_stats, bp); - biodone (bp); - } - - wfd_start (t); -} - -static void wfd_error (struct wfd *t, struct atapires result) -{ - if (result.code != RES_ERR) - return; - switch (result.error & AER_SKEY) { - case AER_SK_NOT_READY: - if (result.error & ~AER_SKEY) { - /* Not Ready */ - printf ("wfd%d: not ready\n", t->lun); - return; - } - /* Tray open. */ - if (! (t->flags & F_MEDIA_CHANGED)) - printf ("wfd%d: tray open\n", t->lun); - t->flags |= F_MEDIA_CHANGED; - return; - - case AER_SK_UNIT_ATTENTION: - /* Media changed. */ - if (! (t->flags & F_MEDIA_CHANGED)) - printf ("wfd%d: media changed\n", t->lun); - t->flags |= F_MEDIA_CHANGED; - return; - - case AER_SK_ILLEGAL_REQUEST: - /* Unknown command or invalid command arguments. */ - if (t->flags & F_DEBUG) - printf ("wfd%d: invalid command\n", t->lun); - return; - } - printf ("wfd%d: i/o error, status=%b, error=%b\n", t->lun, - result.status, ARS_BITS, result.error, AER_BITS); -} - -static int wfd_request_wait (struct wfd *t, u_char cmd, u_char a1, u_char a2, - u_char a3, u_char a4, u_char a5, u_char a6, u_char a7, u_char a8, - u_char a9, char *addr, int count) -{ - struct atapires result; - - result = atapi_request_wait (t->ata, t->unit, cmd, - a1, a2, a3, a4, a5, a6, a7, a8, a9, 0, 0, 0, 0, 0, 0, - addr, count); - if (result.code) { - wfd_error (t, result); - return (EIO); - } - return (0); -} - -/* - * Perform special action on behalf of the user. - * Knows about the internals of this device - */ -int wfdioctl (dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td) -{ - int lun = UNIT(dev); - struct wfd *t = wfdtab[lun]; - int error = 0; - - error = dsioctl(dev, cmd, addr, flag, &t->dk_slices); - if (error != ENOIOCTL) - return (error); - - if (t->flags & F_MEDIA_CHANGED) - switch (cmd) { - case CDIOCSETDEBUG: - case CDIOCCLRDEBUG: - case CDIOCRESET: - /* These ops are media change transparent. */ - break; - default: - /* Lock the media. */ - wfd_request_wait (t, ATAPI_PREVENT_ALLOW, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0); - break; - } - switch (cmd) { - case CDIOCSETDEBUG: - error = suser(td); - if (error) - return (error); - t->flags |= F_DEBUG; - atapi_debug (t->ata, 1); - return 0; - case CDIOCCLRDEBUG: - error = suser(td); - if (error) - return (error); - t->flags &= ~F_DEBUG; - atapi_debug (t->ata, 0); - return 0; - case CDIOCRESET: - error = suser(td); - if (error) - return (error); - return wfd_request_wait (t, ATAPI_TEST_UNIT_READY, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - case CDIOCEJECT: - /* Don't allow eject if the device is opened - * by somebody (not us) in block mode. */ - if ((t->flags & F_BOPEN) && t->refcnt) - return (EBUSY); - return wfd_eject (t, 0); - case CDIOCCLOSE: - if ((t->flags & F_BOPEN) && t->refcnt) - return (0); - return wfd_eject (t, 1); - default: - return (ENOTTY); - } - return (error); -} - -static int wfd_eject (struct wfd *t, int closeit) -{ - struct atapires result; - - /* Try to stop the disc. */ - result = atapi_request_wait (t->ata, t->unit, ATAPI_START_STOP, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - - if (result.code == RES_ERR && - ((result.error & AER_SKEY) == AER_SK_NOT_READY || - (result.error & AER_SKEY) == AER_SK_UNIT_ATTENTION)) { - int err; - - if (!closeit) - return (0); - /* - * The disc was unloaded. - * Load it (close tray). - * Read the table of contents. - */ - err = wfd_request_wait (t, ATAPI_START_STOP, - 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0); - if (err) - return (err); - - /* Lock the media. */ - wfd_request_wait (t, ATAPI_PREVENT_ALLOW, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0); - - return (0); - } - - if (result.code) { - wfd_error (t, result); - return (EIO); - } - - if (closeit) - return (0); - - /* Give it some time to stop spinning. */ - tsleep ((caddr_t)&lbolt, 0, "wfdej1", 0); - tsleep ((caddr_t)&lbolt, 0, "wfdej2", 0); - - /* Unlock. */ - wfd_request_wait (t, ATAPI_PREVENT_ALLOW, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - - /* Eject. */ - t->flags |= F_MEDIA_CHANGED; - return wfd_request_wait (t, ATAPI_START_STOP, - 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0); -} - -static void wfd_drvinit(void *unused) -{ - cdevsw_add(&wfd_cdevsw); -} - -SYSINIT(wfddev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+WFD_CDEV_MAJOR,wfd_drvinit,NULL) diff --git a/sys/dev/disk/wst/wst.c b/sys/dev/disk/wst/wst.c deleted file mode 100644 index 0bdaeb6265..0000000000 --- a/sys/dev/disk/wst/wst.c +++ /dev/null @@ -1,778 +0,0 @@ -/*- - * Copyright (c) 1998 Søren Schmidt - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * without modification, immediately at the beginning of the file. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: src/sys/i386/isa/wst.c,v 1.28 2000/01/29 16:00:34 peter Exp $ - * $DragonFly: src/sys/dev/disk/wst/Attic/wst.c,v 1.6 2003/08/07 21:16:55 dillon Exp $ - */ - -#include "use_wdc.h" -#include "opt_ddb.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static d_open_t wstopen; -static d_close_t wstclose; -static d_ioctl_t wstioctl; -static d_strategy_t wststrategy; - -#define CDEV_MAJOR 90 - -static struct cdevsw wst_cdevsw = { - /* name */ "wst", - /* maj */ CDEV_MAJOR, - /* flags */ 0, - /* port */ NULL, - /* autoq */ 0, - - /* open */ wstopen, - /* close */ wstclose, - /* read */ physread, - /* write */ physwrite, - /* ioctl */ wstioctl, - /* poll */ nopoll, - /* mmap */ nommap, - /* strategy */ wststrategy, - /* dump */ nodump, - /* psize */ nopsize -}; - -static unsigned int wst_total = 0; - -#define NUNIT (NWDC*2) -#define UNIT(d) ((minor(d) >> 3) & 3) - -#define WST_OPEN 0x0001 /* The device is opened */ -#define WST_MEDIA_CHANGED 0x0002 /* The media have changed */ -#define WST_DATA_WRITTEN 0x0004 /* Data has been written */ -#define WST_FM_WRITTEN 0x0008 /* Filemark has been written */ -#define WST_DEBUG 0x0010 /* Print debug info */ -#define WST_CTL_WARN 0x0020 /* Have we warned about CTL wrong? */ - -/* ATAPI tape commands not in std ATAPI command set */ -#define ATAPI_TAPE_REWIND 0x01 -#define ATAPI_TAPE_REQUEST_SENSE 0x03 -#define ATAPI_TAPE_READ_CMD 0x08 -#define ATAPI_TAPE_WRITE_CMD 0x0a -#define ATAPI_TAPE_WEOF 0x10 -#define WEOF_WRITE_MASK 0x01 -#define ATAPI_TAPE_SPACE_CMD 0x11 -#define SP_FM 0x01 -#define SP_EOD 0x03 -#define ATAPI_TAPE_ERASE 0x19 -#define ATAPI_TAPE_MODE_SENSE 0x1a -#define ATAPI_TAPE_LOAD_UNLOAD 0x1b -#define LU_LOAD_MASK 0x01 -#define LU_RETENSION_MASK 0x02 -#define LU_EOT_MASK 0x04 - -#define DSC_POLL_INTERVAL 10 - -/* - * MODE SENSE parameter header - */ -struct wst_header { - u_char data_length; /* Total length of data */ - u_char medium_type; /* Medium type (if any) */ - u_char dsp; /* Device specific parameter */ - u_char bdl; /* Block Descriptor Length */ -}; - -/* - * ATAPI tape drive Capabilities and Mechanical Status Page - */ -#define ATAPI_TAPE_CAP_PAGE 0x2a - -struct wst_cappage { - u_int page_code :6; /* Page code == 0x2a */ - u_int reserved1_67 :2; - u_char page_length; /* Page Length == 0x12 */ - u_char reserved2; - u_char reserved3; - u_int readonly :1; /* Read Only Mode */ - u_int reserved4_1234 :4; - u_int reverse :1; /* Supports reverse direction */ - u_int reserved4_67 :2; - u_int reserved5_012 :3; - u_int eformat :1; /* Supports ERASE formatting */ - u_int reserved5_4 :1; - u_int qfa :1; /* Supports QFA formats */ - u_int reserved5_67 :2; - u_int lock :1; /* Supports locking media */ - u_int locked :1; /* The media is locked */ - u_int prevent :1; /* Defaults to prevent state */ - u_int eject :1; /* Supports eject */ - u_int disconnect :1; /* Can break request > ctl */ - u_int reserved6_5 :1; - u_int ecc :1; /* Supports error correction */ - u_int compress :1; /* Supports data compression */ - u_int reserved7_0 :1; - u_int blk512 :1; /* Supports 512b block size */ - u_int blk1024 :1; /* Supports 1024b block size */ - u_int reserved7_3456 :4; - u_int slowb :1; /* Restricts byte count */ - u_short max_speed; /* Supported speed in KBps */ - u_short max_defects; /* Max stored defect entries */ - u_short ctl; /* Continuous Transfer Limit */ - u_short speed; /* Current Speed, in KBps */ - u_short buffer_size; /* Buffer Size, in 512 bytes */ - u_char reserved18; - u_char reserved19; -}; - -/* - * REQUEST SENSE structure - */ -struct wst_reqsense { - u_int error_code :7; /* Current or deferred errors */ - u_int valid :1; /* Follows QIC-157C */ - u_char reserved1; /* Segment Number - Reserved */ - u_int sense_key :4; /* Sense Key */ - u_int reserved2_4 :1; /* Reserved */ - u_int ili :1; /* Incorrect Length Indicator */ - u_int eom :1; /* End Of Medium */ - u_int filemark :1; /* Filemark */ - u_int info __attribute__((packed)); /* Cmd specific info */ - u_char asl; /* Additional sense length (n-7) */ - u_int command_specific; /* Additional cmd specific info */ - u_char asc; /* Additional Sense Code */ - u_char ascq; /* Additional Sense Code Qualifier */ - u_char replaceable_unit_code; /* Field Replaceable Unit Code */ - u_int sk_specific1 :7; /* Sense Key Specific */ - u_int sksv :1; /* Sense Key Specific info valid */ - u_char sk_specific2; /* Sense Key Specific */ - u_char sk_specific3; /* Sense Key Specific */ - u_char pad[2]; /* Padding */ -}; - -struct wst { - struct atapi *ata; /* Controller structure */ - int unit; /* IDE bus drive unit */ - int lun; /* Logical device unit */ - int flags; /* Device state flags */ - int blksize; /* Block size (512 | 1024) */ - struct buf_queue_head buf_queue; /* Queue of i/o requests */ - struct atapi_params *param; /* Drive parameters table */ - struct wst_header header; /* MODE SENSE param header */ - struct wst_cappage cap; /* Capabilities page info */ -}; - -static struct wst *wsttab[NUNIT]; /* Drive info by unit number */ -static int wstnlun = 0; /* Number of config'd drives */ - -int wstattach(struct atapi *ata, int unit, struct atapi_params *ap, int debug); -static int wst_sense(struct wst *t); -static void wst_describe(struct wst *t); -static void wst_poll_dsc(struct wst *t); -static void wst_start(struct wst *t); -static void wst_done(struct wst *t, struct buf *bp, int resid, struct atapires result); -static int wst_error(struct wst *t, struct atapires result); -static void wst_drvinit(void *unused); -static int wst_space_cmd(struct wst *t, u_char function, u_int count); -static int wst_write_filemark(struct wst *t, u_char function); -static int wst_erase(struct wst *t); -static int wst_load_unload(struct wst *t, u_char finction); -static int wst_rewind(struct wst *t); -static void wst_reset(struct wst *t); - -#ifdef DDB -void wst_dump(int lun, char *label, void *data, int len); - -void -wst_dump(int lun, char *label, void *data, int len) -{ - u_char *p = data; - - printf("wst%d: %s %x", lun, label, *p++); - while(--len > 0) - printf("-%x", *p++); - printf("\n"); -} -#endif - -int -wstattach(struct atapi *ata, int unit, struct atapi_params *ap, int debug) -{ - struct wst *t; - int lun; - - if (wstnlun >= NUNIT) { - printf("wst: too many units\n"); - return(-1); - } - if (!atapi_request_immediate) { - printf("wst: configuration error, ATAPI core code not present!\n"); - printf( - "wst: check `options ATAPI_STATIC' in your kernel config file!\n"); - return(-1); - } - t = malloc(sizeof(struct wst), M_TEMP, M_NOWAIT); - if (!t) { - printf("wst: out of memory\n"); - return(-1); - } - wsttab[wstnlun] = t; - bzero(t, sizeof(struct wst)); - bufq_init(&t->buf_queue); - t->ata = ata; - t->unit = unit; - t->ata->use_dsc = 1; - lun = t->lun = wstnlun; - t->param = ap; - t->flags = WST_MEDIA_CHANGED | WST_DEBUG; - - if (wst_sense(t)) - return -1; - - wst_describe(t); - wstnlun++; - - make_dev(&wst_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0640, "rwst%d", t->lun); - return(1); -} - -static int -wst_sense(struct wst *t) -{ - struct atapires result; - int count; - char buffer[255]; - - /* Get drive capabilities, some drives needs this repeated */ - for (count = 0 ; count < 5 ; count++) { - result = atapi_request_immediate(t->ata, t->unit, - ATAPI_TAPE_MODE_SENSE, - 8, /* DBD = 1 no block descr */ - ATAPI_TAPE_CAP_PAGE, - sizeof(buffer)>>8, sizeof(buffer), - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, buffer, sizeof(buffer)); - if (result.code == 0 || result.code == RES_UNDERRUN) - break; - } - - /* Some drives have shorter capabilities page. */ - if (result.code == RES_UNDERRUN) - result.code = 0; - - if (result.code == 0) { - bcopy(buffer, &t->header, sizeof(struct wst_header)); - bcopy(buffer+sizeof(struct wst_header), - &t->cap, sizeof(struct wst_cappage)); - if (t->cap.page_code != ATAPI_TAPE_CAP_PAGE) - return 1; - t->cap.max_speed = ntohs(t->cap.max_speed); - t->cap.max_defects = ntohs(t->cap.max_defects); - t->cap.ctl = ntohs(t->cap.ctl); - t->cap.speed = ntohs(t->cap.speed); - t->cap.buffer_size = ntohs(t->cap.buffer_size); - t->blksize = (t->cap.blk512 ? 512 : (t->cap.blk1024 ? 1024 : 0)); - return 0; - } - return 1; -} - -static void -wst_describe(struct wst *t) -{ - printf("wst%d: ", t->lun); - switch (t->header.medium_type) { - case 0x00: printf("Drive empty"); break; - case 0x17: printf("Travan 1 (400 Mbyte) media"); break; - case 0xb6: printf("Travan 4 (4 Gbyte) media"); break; - default: printf("Unknown media (0x%x)", t->header.medium_type); - } - if (t->cap.readonly) printf(", readonly"); - if (t->cap.reverse) printf(", reverse"); - if (t->cap.eformat) printf(", eformat"); - if (t->cap.qfa) printf(", qfa"); - if (t->cap.lock) printf(", lock"); - if (t->cap.locked) printf(", locked"); - if (t->cap.prevent) printf(", prevent"); - if (t->cap.eject) printf(", eject"); - if (t->cap.disconnect) printf(", disconnect"); - if (t->cap.ecc) printf(", ecc"); - if (t->cap.compress) printf(", compress"); - if (t->cap.blk512) printf(", 512b"); - if (t->cap.blk1024) printf(", 1024b"); - if (t->cap.slowb) printf(", slowb"); - printf("\nwst%d: ", t->lun); - printf("Max speed=%dKb/s, ", t->cap.max_speed); - printf("Transfer limit=%d blocks, ", t->cap.ctl); - printf("Buffer size=%d blocks", t->cap.buffer_size); - printf("\n"); -} - -int -wstopen(dev_t dev, int flags, int fmt, struct thread *td) -{ - int lun = UNIT(dev); - struct wst *t; - - /* Check that the device number and that the ATAPI driver is loaded. */ - if (lun >= wstnlun || !atapi_request_immediate) { - printf("ENXIO lun=%d, wstnlun=%d, im=%p\n", - lun, wstnlun, (void *)atapi_request_immediate); - return(ENXIO); - } - t = wsttab[lun]; - if (t->flags == WST_OPEN) - return EBUSY; - if (wst_sense(t)) - printf("wst%d: Sense media type failed\n", t->lun); - t->flags &= ~WST_MEDIA_CHANGED; - t->flags &= ~(WST_DATA_WRITTEN | WST_FM_WRITTEN); - t->flags |= WST_OPEN; - return(0); -} - -int -wstclose(dev_t dev, int flags, int fmt, struct thread *td) -{ - int lun = UNIT(dev); - struct wst *t = wsttab[lun]; - - /* Flush buffers, some drives fail here, but they should report ctl = 0 */ - if (t->cap.ctl && (t->flags & WST_DATA_WRITTEN)) - wst_write_filemark(t, 0); - - /* Write filemark if data written to tape */ - if ((t->flags & (WST_DATA_WRITTEN | WST_FM_WRITTEN)) == WST_DATA_WRITTEN) - wst_write_filemark(t, WEOF_WRITE_MASK); - - /* If minor is even rewind on close */ - if (!(minor(dev) & 0x01)) - wst_rewind(t); - - t->flags &= ~WST_OPEN; - if (t->flags & WST_DEBUG) - printf("wst%d: %ud total bytes transferred\n", t->lun, wst_total); - t->flags &= ~WST_CTL_WARN; - return(0); -} - -void -wststrategy(struct buf *bp) -{ - int lun = UNIT(bp->b_dev); - struct wst *t = wsttab[lun]; - int x; - - /* If it's a null transfer, return immediatly. */ - if (bp->b_bcount == 0) { - bp->b_resid = 0; - biodone(bp); - return; - } - - /* Check for != blocksize requests */ - if (bp->b_bcount % t->blksize) { - printf("wst%d: bad request, must be multiple of %d\n", lun, t->blksize); - bp->b_error = EIO; - bp->b_flags |= B_ERROR; - biodone(bp); - return; - } - - if (bp->b_bcount > t->blksize*t->cap.ctl) { - if ((t->flags & WST_CTL_WARN) == 0) { - printf("wst%d: WARNING: CTL exceeded %ld>%d\n", - lun, bp->b_bcount, t->blksize*t->cap.ctl); - t->flags |= WST_CTL_WARN; - } - } - - x = splbio(); - wst_total += bp->b_bcount; - bufq_insert_tail(&t->buf_queue, bp); - wst_start(t); - splx(x); -} - -static void -wst_poll_dsc(struct wst *t) -{ - /* We should use a final timeout here SOS XXX */ - if (!(inb(t->ata->port + AR_STATUS) & ARS_DSC)) { - timeout((timeout_t*)wst_poll_dsc, t, DSC_POLL_INTERVAL); - return; - } - t->ata->wait_for_dsc = 0; - wakeup((caddr_t)t); -} - -static void -wst_start(struct wst *t) -{ - struct buf *bp = bufq_first(&t->buf_queue); - u_long blk_count; - u_char op_code; - long byte_count; - - if (!bp) - return; - - if (t->ata->wait_for_dsc) - printf("wst%d: ERROR! allready waiting for DSC\n", t->lun); - - /* Sleep waiting for a ready drive (DSC) */ - if (t->ata->use_dsc && !(inb(t->ata->port + AR_STATUS) & ARS_DSC)) { - t->ata->wait_for_dsc = 1; - timeout((timeout_t*)wst_poll_dsc, t, DSC_POLL_INTERVAL); - tsleep((caddr_t) t, 0, "wstdsc", 0); - } - - bufq_remove(&t->buf_queue, bp); - blk_count = bp->b_bcount / t->blksize; - - if (bp->b_flags & B_READ) { - op_code = ATAPI_TAPE_READ_CMD; - byte_count = bp->b_bcount; - } else { - op_code = ATAPI_TAPE_WRITE_CMD; - t->flags |= WST_DATA_WRITTEN; - byte_count = -bp->b_bcount; - } - - atapi_request_callback(t->ata, t->unit, op_code, 1, - blk_count>>16, blk_count>>8, blk_count, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - (u_char*) bp->b_data, byte_count, - (void*)wst_done, t, bp); -} - -static void -wst_done(struct wst *t, struct buf *bp, int resid, - struct atapires result) -{ - if (result.code) { - printf("wst_done: "); - wst_error(t, result); - bp->b_error = EIO; - bp->b_flags |= B_ERROR; - } - else - bp->b_resid = resid; - - biodone(bp); - /*wst_start(t);*/ -} - -static int -wst_error(struct wst *t, struct atapires result) -{ - struct wst_reqsense sense; - - if (result.code != RES_ERR) { - printf("wst%d: ERROR code=%d, status=%b, error=%b\n", t->lun, - result.code, result.status, ARS_BITS, result.error, AER_BITS); - return 1; - } - - if ((result.error & AER_SKEY) && (result.status & ARS_CHECK)) { - atapi_request_immediate(t->ata, t->unit, - ATAPI_TAPE_REQUEST_SENSE, - 0, 0, 0, sizeof(sense), - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, (char*) &sense, sizeof(struct wst_reqsense)); - /*wst_dump(t->lun, "req_sense", &sense, sizeof(struct wst_reqsense));*/ - } - switch (result.error & AER_SKEY) { - case AER_SK_NOT_READY: - if (result.error & ~AER_SKEY) { - if (t->flags & WST_DEBUG) - printf("wst%d: not ready\n", t->lun); - break; - } - if (!(t->flags & WST_MEDIA_CHANGED)) - if (t->flags & WST_DEBUG) - printf("wst%d: no media\n", t->lun); - t->flags |= WST_MEDIA_CHANGED; - break; - - case AER_SK_BLANK_CHECK: - if (t->flags & WST_DEBUG) - printf("wst%d: EOD encountered\n", t->lun); - break; - - case AER_SK_MEDIUM_ERROR: - if (t->flags & WST_DEBUG) - printf("wst%d: nonrecovered data error\n", t->lun); - break; - - case AER_SK_HARDWARE_ERROR: - if (t->flags & WST_DEBUG) - printf("wst%d: nonrecovered hardware error\n", t->lun); - break; - - case AER_SK_ILLEGAL_REQUEST: - if (t->flags & WST_DEBUG) - printf("wst%d: invalid command\n", t->lun); - break; - - case AER_SK_UNIT_ATTENTION: - if (!(t->flags & WST_MEDIA_CHANGED)) - printf("wst%d: media changed\n", t->lun); - t->flags |= WST_MEDIA_CHANGED; - break; - - case AER_SK_DATA_PROTECT: - if (t->flags & WST_DEBUG) - printf("wst%d: reading read protected data\n", t->lun); - break; - - case AER_SK_ABORTED_COMMAND: - if (t->flags & WST_DEBUG) - printf("wst%d: command aborted\n", t->lun); - break; - - case AER_SK_MISCOMPARE: - if (t->flags & WST_DEBUG) - printf("wst%d: data don't match medium\n", t->lun); - break; - - default: - printf("wst%d: i/o error, status=%b, error=%b\n", t->lun, - result.status, ARS_BITS, result.error, AER_BITS); - } - printf("total=%u ERR=%x len=%ld ASC=%x ASCQ=%x\n", - wst_total, sense.error_code, (long)ntohl(sense.info), - sense.asc, sense.ascq); - return 1; -} - -int -wstioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td) -{ - int lun = UNIT(dev); - int error = 0; - struct wst *t = wsttab[lun]; - - switch (cmd) { - case MTIOCGET: - { - struct mtget *g = (struct mtget *) addr; - - bzero(g, sizeof(struct mtget)); - g->mt_type = 7; - g->mt_density = 1; - g->mt_blksiz = t->blksize; - g->mt_comp = t->cap.compress; - g->mt_density0 = 0; g->mt_density1 = 0; - g->mt_density2 = 0; g->mt_density3 = 0; - g->mt_blksiz0 = 0; g->mt_blksiz1 = 0; - g->mt_blksiz2 = 0; g->mt_blksiz3 = 0; - g->mt_comp0 = 0; g->mt_comp1 = 0; - g->mt_comp2 = 0; g->mt_comp3 = 0; - break; - } - case MTIOCTOP: - { - int i; - struct mtop *mt = (struct mtop *)addr; - - switch ((short) (mt->mt_op)) { - case MTWEOF: - for (i=0; i < mt->mt_count && !error; i++) - error = wst_write_filemark(t, WEOF_WRITE_MASK); - break; - case MTFSF: - if (mt->mt_count) - error = wst_space_cmd(t, SP_FM, mt->mt_count); - break; - case MTBSF: - if (mt->mt_count) - error = wst_space_cmd(t, SP_FM, -(mt->mt_count)); - break; - case MTFSR: - error = EINVAL; break; - case MTBSR: - error = EINVAL; break; - case MTREW: - error = wst_rewind(t); - break; - case MTOFFL: -#if 1 /* Misuse as a reset func for now */ - wst_reset(t); - wst_sense(t); - wst_describe(t); -#else - if (error = wst_rewind(t)) - break; - error = wst_load_unload(t, !LU_LOAD_MASK); -#endif - break; - case MTNOP: - error = wst_write_filemark(t, 0); - break; - case MTCACHE: - error = EINVAL; break; - case MTNOCACHE: - error = EINVAL; break; - case MTSETBSIZ: - error = EINVAL; break; - case MTSETDNSTY: - error = EINVAL; break; - case MTERASE: - error = wst_erase(t); - break; - case MTEOD: - error = wst_space_cmd(t, SP_EOD, 0); - break; - case MTCOMP: - error = EINVAL; break; - case MTRETENS: - error = wst_load_unload(t, LU_RETENSION_MASK|LU_LOAD_MASK); - break; - default: - error = EINVAL; - } - return error; - } - default: - return(ENOTTY); - } - return(error); -} - -static int -wst_space_cmd(struct wst *t, u_char function, u_int count) -{ - struct atapires result; - - result = atapi_request_wait(t->ata, t->unit, - ATAPI_TAPE_SPACE_CMD, function, - count>>16, count>>8, count, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, 0); - if (result.code) { - printf("wst_space_cmd: "); - wst_error(t, result); - return EIO; - } - return 0; -} - -static int -wst_write_filemark(struct wst *t, u_char function) -{ - struct atapires result; - - if (function) { - if (t->flags & WST_FM_WRITTEN) - t->flags &= ~WST_DATA_WRITTEN; - else - t->flags |= WST_FM_WRITTEN; - } - result = atapi_request_wait(t->ata, t->unit, - ATAPI_TAPE_WEOF, 0, 0, 0, function, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, 0); - if (result.code) { - printf("wst_write_filemark: "); - wst_error(t, result); - return EIO; - } - return 0; -} - -static int -wst_load_unload(struct wst *t, u_char function) -{ - struct atapires result; - - result = atapi_request_wait(t->ata, t->unit, - ATAPI_TAPE_LOAD_UNLOAD, 0, 0, 0, function, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, 0); - if (result.code) { - printf("wst_load_unload: "); - wst_error(t, result); - return EIO; - } - return 0; -} - -static int -wst_erase(struct wst *t) -{ - int error; - struct atapires result; - - error = wst_rewind(t); - if (error) - return error; - result = atapi_request_wait(t->ata, t->unit, - ATAPI_TAPE_ERASE, 3, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - NULL, 0); - if (result.code) { - printf("wst_erase: "); - wst_error(t, result); - return EIO; - } - return 0; -} - -static int -wst_rewind(struct wst *t) -{ - struct atapires result; - - result = atapi_request_wait(t->ata, t->unit, - ATAPI_TAPE_REWIND, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - NULL, 0); - if (result.code) { - printf("wst_rewind: "); - wst_error(t, result); - return EIO; - } - return 0; -} - -static void -wst_reset(struct wst *t) -{ - outb(t->ata->port + AR_DRIVE, ARD_DRIVE1); - DELAY(30); - outb(t->ata->port + AR_COMMAND, 0x08); - DELAY(30); -} - -static void -wst_drvinit(void *unused) -{ - cdevsw_add(&wst_cdevsw); -} - -SYSINIT(wstdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,wst_drvinit,NULL) diff --git a/sys/i386/conf/LINT b/sys/i386/conf/LINT index 39f8bb363c..b2e01c5657 100644 --- a/sys/i386/conf/LINT +++ b/sys/i386/conf/LINT @@ -3,7 +3,7 @@ # as much of the source tree as it can. # # $FreeBSD: src/sys/i386/conf/LINT,v 1.749.2.144 2003/06/04 17:56:59 sam Exp $ -# $DragonFly: src/sys/i386/conf/Attic/LINT,v 1.10 2003/11/09 19:04:35 drhodus Exp $ +# $DragonFly: src/sys/i386/conf/Attic/LINT,v 1.11 2003/11/22 09:50:36 asmodai Exp $ # # NB: You probably don't want to try running a kernel built from this # file. Instead, you should start from GENERIC, and add options from @@ -1288,79 +1288,6 @@ options ATA_STATIC_ID #device ata0 at isa? port IO_WD1 irq 14 #device ata1 at isa? port IO_WD2 irq 15 -# -# ST-506, ESDI, and IDE hard disks: `wdc' and `wd' -# -# The flags fields are used to enable the multi-sector I/O and -# the 32BIT I/O modes. The flags may be used in either the controller -# definition or in the individual disk definitions. The controller -# definition is supported for the boot configuration stuff. -# -# Each drive has a 16 bit flags value defined: -# The low 8 bits are the maximum value for the multi-sector I/O, -# where 0xff defaults to the maximum that the drive can handle. -# The high bit of the 16 bit flags (0x8000) allows probing for -# 32 bit transfers. Bit 14 (0x4000) enables a hack to wake -# up powered-down laptop drives. Bit 13 (0x2000) allows -# probing for PCI IDE DMA controllers, such as Intel's PIIX -# south bridges. Bit 12 (0x1000) sets LBA mode instead of the -# default CHS mode for accessing the drive. See the wd.4 man page. -# -# The flags field for the drives can be specified in the controller -# specification with the low 16 bits for drive 0, and the high 16 bits -# for drive 1. -# e.g.: -#device wdc0 at isa? port IO_WD1 irq 14 flags 0x00ff8004 -# -# specifies that drive 0 will be allowed to probe for 32 bit transfers and -# a maximum multi-sector transfer of 4 sectors, and drive 1 will not be -# allowed to probe for 32 bit transfers, but will allow multi-sector -# transfers up to the maximum that the drive supports. -# -# If you are using a PCI controller that is not running in compatibility -# mode (for example, it is a 2nd IDE PCI interface), then use config line(s) -# such as: -# -#device wdc2 at isa? port 0 flags 0xa0ffa0ff -#device wd4 at wdc2 drive 0 -#device wd5 at wdc2 drive 1 -# -#device wdc3 at isa? port 0 flags 0xa0ffa0ff -#device wd6 at wdc3 drive 0 -#device wd7 at wdc3 drive 1 -# -# Note that the above config would be useful for a Promise card, when used -# on a MB that already has a PIIX controller. Note the bogus irq and port -# entries. These are automatically filled in by the IDE/PCI support. -# -# This driver must be commented out because it is mutually exclusive with -# the ata(4) driver. -# -device wdc0 at isa? port IO_WD1 irq 14 -device wd0 at wdc0 drive 0 -device wd1 at wdc0 drive 1 -device wdc1 at isa? port IO_WD2 irq 15 -device wd2 at wdc1 drive 0 -device wd3 at wdc1 drive 1 - -# -# This option allow you to override the default probe time for IDE -# devices, to get a faster probe. Setting this below 10000 violate -# the IDE specs, but may still work for you (it will work for most -# people). -# -options IDE_DELAY=8000 # Be optimistic about Joe IDE device - -# IDE CD-ROM & CD-R/RW driver - requires wdc controller -device wcd - -# IDE floppy driver - requires wdc controller -device wfd - -# IDE tape driver - requires wdc controller -device wst - - # # Standard floppy disk controllers: `fdc' and `fd' # -- 2.41.0