summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2007-02-19 11:44:25 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2007-02-19 11:44:25 +0000
commita959e788b769c459811ae5a3a05c73d8e2fb2901 (patch)
tree3b800ab633159861d32f98aa6f94ce5b25237547
parent798300be85f1053c70f183a2ac9e71458c7c1dae (diff)
pull in atascsi, a scsi to ata translation layer, so i can work on it in
tree. ive lost two large changes today thanks to my own stupidity which could have been avoided if they were in the tree. discussed with deraadt@ ok jsg@ grange@ an older version was ok marco@
-rw-r--r--sys/conf/files3
-rw-r--r--sys/dev/ata/atascsi.c134
-rw-r--r--sys/dev/ata/atascsi.h60
-rw-r--r--sys/dev/ata/files.ata4
4 files changed, 199 insertions, 2 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 20cc159acbc..4521cbc43df 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -1,4 +1,4 @@
-# $OpenBSD: files,v 1.392 2006/12/06 20:07:52 martin Exp $
+# $OpenBSD: files,v 1.393 2007/02/19 11:44:24 dlg Exp $
# $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@@ -11,6 +11,7 @@ define ifnet
define tty
define audio {}
define scsi {}
+define atascsi {}
define ifmedia
define mii {[phy = -1]}
define midibus {}
diff --git a/sys/dev/ata/atascsi.c b/sys/dev/ata/atascsi.c
new file mode 100644
index 00000000000..9ec35e2ff9d
--- /dev/null
+++ b/sys/dev/ata/atascsi.c
@@ -0,0 +1,134 @@
+/* $OpenBSD: atascsi.c,v 1.1 2007/02/19 11:44:24 dlg Exp $ */
+
+/*
+ * Copyright (c) 2007 David Gwynne <dlg@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/buf.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/device.h>
+#include <sys/proc.h>
+#include <sys/queue.h>
+
+#include <scsi/scsi_all.h>
+#include <scsi/scsiconf.h>
+
+#include <dev/ata/atascsi.h>
+
+struct atascsi {
+ struct device *ab_dev;
+ void *ab_cookie;
+
+ int *ab_ports;
+
+ struct atascsi_methods *ab_methods;
+ struct scsi_adapter ab_switch;
+ struct scsi_link ab_link;
+ struct scsibus_softc *ab_scsibus;
+};
+
+int atascsi_probe(struct atascsi *, int);
+
+int atascsi_cmd(struct scsi_xfer *);
+
+/* template */
+struct scsi_adapter atascsi_switch = {
+ atascsi_cmd, /* scsi_cmd */
+ minphys, /* scsi_minphys */
+ NULL,
+ NULL,
+ NULL /* ioctl */
+};
+
+struct scsi_device atascsi_device = {
+ NULL, NULL, NULL, NULL
+};
+
+struct atascsi *
+atascsi_attach(struct device *self, struct atascsi_attach_args *aaa)
+{
+ struct scsibus_attach_args saa;
+ struct atascsi *ab;
+ int i;
+
+ ab = malloc(sizeof(struct atascsi), M_DEVBUF, M_WAITOK);
+ bzero(ab, sizeof(struct atascsi));
+
+ ab->ab_dev = self;
+ ab->ab_cookie = aaa->aaa_cookie;
+ ab->ab_methods = aaa->aaa_methods;
+
+ /* copy from template and modify for ourselves */
+ ab->ab_switch = atascsi_switch;
+ ab->ab_switch.scsi_minphys = aaa->aaa_minphys;
+
+ /* fill in our scsi_link */
+ ab->ab_link.device = &atascsi_device;
+ ab->ab_link.adapter = &ab->ab_switch;
+ ab->ab_link.adapter_softc = ab;
+ ab->ab_link.adapter_buswidth = aaa->aaa_nports;
+ ab->ab_link.luns = 1; /* XXX port multiplier as luns */
+ ab->ab_link.adapter_target = aaa->aaa_nports;
+ ab->ab_link.openings = aaa->aaa_ncmds;
+
+ ab->ab_ports = malloc(sizeof(int) * aaa->aaa_nports,
+ M_DEVBUF, M_WAITOK);
+ bzero(ab->ab_ports, sizeof(int) * aaa->aaa_nports);
+
+ /* fill in the port array with the type of devices there */
+ for (i = 0; i < ab->ab_link.adapter_buswidth; i++)
+ atascsi_probe(ab, i);
+
+ bzero(&saa, sizeof(saa));
+ saa.saa_sc_link = &ab->ab_link;
+
+ /* stash the scsibus so we can do hotplug on it */
+ ab->ab_scsibus = (struct scsibus_softc *)config_found(self, &saa,
+ scsiprint);
+
+ return (ab);
+}
+
+int
+atascsi_detach(struct atascsi *ab)
+{
+ return (0);
+}
+
+int
+atascsi_probe(struct atascsi *ab, int port)
+{
+ if (port > ab->ab_link.adapter_buswidth)
+ return (ENXIO);
+
+ ab->ab_ports[port] = ab->ab_methods->probe(ab->ab_cookie, port);
+
+ return (0);
+}
+
+int
+atascsi_cmd(struct scsi_xfer *xs)
+{
+ int s;
+
+ xs->error = XS_DRIVER_STUFFUP;
+ s = splbio();
+ scsi_done(xs);
+ splx(s);
+ return (COMPLETE);
+}
diff --git a/sys/dev/ata/atascsi.h b/sys/dev/ata/atascsi.h
new file mode 100644
index 00000000000..6f80cc4c547
--- /dev/null
+++ b/sys/dev/ata/atascsi.h
@@ -0,0 +1,60 @@
+/* $OpenBSD: atascsi.h,v 1.1 2007/02/19 11:44:24 dlg Exp $ */
+
+/*
+ * Copyright (c) 2007 David Gwynne <dlg@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+struct atascsi;
+struct ata_xfer;
+
+struct atascsi_methods {
+ int (*probe)(void *, int);
+ int (*ata_cmd)(void *, struct ata_xfer *);
+};
+
+struct atascsi_attach_args {
+ void *aaa_cookie;
+
+ struct atascsi_methods *aaa_methods;
+ void (*aaa_minphys)(struct buf *);
+ int aaa_nports;
+ int aaa_ncmds;
+};
+
+struct atascsi_port {
+ int ap_type;
+#define ATABUS_PORT_T_NONE 0
+#define ATABUS_PORT_T_DISK 1
+#define ATABUS_PORT_T_ATAPI 2
+};
+
+struct ata_xfer {
+ int port;
+
+ int flags;
+#define ATA_F_POLL (1<<0)
+#define ATA_F_NOSLEEP (1<<1)
+
+ u_int8_t *cmd;
+
+ u_int8_t *data;
+ size_t datalen;
+};
+
+struct atascsi *atascsi_attach(struct device *, struct atascsi_attach_args *);
+int atascsi_detach(struct atascsi *);
+
+int atascsi_probe_dev(struct atascsi *, int);
+int atascsi_detach_dev(struct atascsi *, int);
diff --git a/sys/dev/ata/files.ata b/sys/dev/ata/files.ata
index cf010e3131d..3adc4c4b8f9 100644
--- a/sys/dev/ata/files.ata
+++ b/sys/dev/ata/files.ata
@@ -1,4 +1,4 @@
-# $OpenBSD: files.ata,v 1.2 2002/12/23 02:37:38 grange Exp $
+# $OpenBSD: files.ata,v 1.3 2007/02/19 11:44:24 dlg Exp $
# $NetBSD: files.ata,v 1.3 1998/10/12 16:09:16 bouyer Exp $
#
# Config file and device description for machine-independent devices
@@ -13,3 +13,5 @@ file dev/ata/wd.c wd needs-flag
file dev/ata/ata_wdc.c wd & wdc_base
file dev/ata/ata.c (ata | atapi) & wdc_base
+
+file dev/ata/atascsi.c atascsi