Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/compat/linux/common Add linux scsi-generic to work for s...
details: https://anonhg.NetBSD.org/src/rev/240ff5f4819c
branches: trunk
changeset: 573611:240ff5f4819c
user: christos <christos%NetBSD.org@localhost>
date: Thu Feb 03 00:09:09 2005 +0000
description:
Add linux scsi-generic to work for simple cases. Allows gendalia's change
to limp along. From soren with fixes from me.
diffstat:
sys/compat/linux/common/linux_ioctl.c | 7 +-
sys/compat/linux/common/linux_ioctl.h | 4 +-
sys/compat/linux/common/linux_sg.c | 297 ++++++++++++++++++++++++++++++++++
sys/compat/linux/common/linux_sg.h | 132 +++++++++++++++
4 files changed, 437 insertions(+), 3 deletions(-)
diffs (truncated from 483 to 300 lines):
diff -r 5028d997933a -r 240ff5f4819c sys/compat/linux/common/linux_ioctl.c
--- a/sys/compat/linux/common/linux_ioctl.c Thu Feb 03 00:03:02 2005 +0000
+++ b/sys/compat/linux/common/linux_ioctl.c Thu Feb 03 00:09:09 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_ioctl.c,v 1.39 2004/06/03 01:53:28 yamt Exp $ */
+/* $NetBSD: linux_ioctl.c,v 1.40 2005/02/03 00:09:09 christos Exp $ */
/*-
* Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_ioctl.c,v 1.39 2004/06/03 01:53:28 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_ioctl.c,v 1.40 2005/02/03 00:09:09 christos Exp $");
#if defined(_KERNEL_OPT)
#include "sequencer.h"
@@ -147,6 +147,9 @@
#endif
}
break;
+ case '"':
+ error = linux_ioctl_sg(p, uap, retval);
+ break;
case 0x89:
error = linux_ioctl_socket(p, uap, retval);
break;
diff -r 5028d997933a -r 240ff5f4819c sys/compat/linux/common/linux_ioctl.h
--- a/sys/compat/linux/common/linux_ioctl.h Thu Feb 03 00:03:02 2005 +0000
+++ b/sys/compat/linux/common/linux_ioctl.h Thu Feb 03 00:09:09 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_ioctl.h,v 1.18 2003/06/29 22:29:30 fvdl Exp $ */
+/* $NetBSD: linux_ioctl.h,v 1.19 2005/02/03 00:09:09 christos Exp $ */
/*-
* Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
@@ -56,6 +56,8 @@
register_t *retval));
int linux_ioctl_blkio __P((struct proc *p, struct linux_sys_ioctl_args *uap,
register_t *retval));
+int linux_ioctl_sg __P((struct proc *p, struct linux_sys_ioctl_args *uap,
+ register_t *retval));
__END_DECLS
#endif /* !_KERNEL */
diff -r 5028d997933a -r 240ff5f4819c sys/compat/linux/common/linux_sg.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/linux/common/linux_sg.c Thu Feb 03 00:09:09 2005 +0000
@@ -0,0 +1,297 @@
+/* $NetBSD: linux_sg.c,v 1.1 2005/02/03 00:09:09 christos Exp $ */
+
+/*
+ * Copyright (c) 2004 Soren S. Jorvang. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: linux_sg.c,v 1.1 2005/02/03 00:09:09 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/mount.h>
+#include <sys/proc.h>
+
+#include <sys/scsiio.h>
+#include <dev/scsipi/scsipi_all.h>
+#include <dev/scsipi/scsiconf.h>
+
+#include <sys/sa.h>
+#include <sys/syscallargs.h>
+
+#include <compat/linux/common/linux_types.h>
+#include <compat/linux/common/linux_ioctl.h>
+#include <compat/linux/common/linux_signal.h>
+#include <compat/linux/common/linux_sg.h>
+
+#include <compat/linux/linux_syscallargs.h>
+
+#ifdef LINUX_SG_DEBUG
+#define DPRINTF(a) printf a
+#else
+#define DPRINTF(a)
+#endif
+
+#ifdef LINUX_SG_DEBUG
+static void dump_sg_io(struct linux_sg_io_hdr *);
+static void dump_scsireq(struct scsireq *);
+#endif
+
+static int bsd_to_linux_host_status(int);
+static int bsd_to_linux_driver_status(int);
+
+int
+linux_ioctl_sg(struct proc *p, struct linux_sys_ioctl_args *uap,
+ register_t *retval)
+{
+ struct file *fp;
+ struct filedesc *fdp;
+ u_long com = SCARG(uap, com);
+ int error = 0;
+ int (*ioctlf)(struct file *, u_long, void *, struct proc *);
+ struct linux_sg_io_hdr lreq;
+ struct scsireq req;
+
+ fdp = p->p_fd;
+ if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
+ return EBADF;
+
+ FILE_USE(fp);
+ ioctlf = fp->f_ops->fo_ioctl;
+
+ *retval = 0;
+ DPRINTF(("Command = %lx\n", com));
+ switch (com) {
+ case LINUX_SG_GET_VERSION_NUM: {
+ short version = 30124;
+ error = copyout(&version, SCARG(uap, data), sizeof(version));
+ break;
+ }
+ case LINUX_SG_IO:
+ error = copyin(SCARG(uap, data), &lreq, sizeof(lreq));
+ if (error) {
+ DPRINTF(("failed to copy in request data %d\n", error));
+ break;
+ }
+
+#ifdef LINUX_SG_DEBUG
+ dump_sg_io(&lreq);
+#endif
+ (void)memset(&req, 0, sizeof(req));
+ switch (lreq.dxfer_direction) {
+ case SG_DXFER_TO_DEV:
+ req.flags = SCCMD_WRITE;
+ break;
+ case SG_DXFER_FROM_DEV:
+ req.flags = SCCMD_READ;
+ break;
+ default:
+ DPRINTF(("unknown direction %d\n",
+ lreq.dxfer_direction));
+ error = EINVAL;
+ goto done;
+ }
+ if (lreq.iovec_count != 0) {
+ /* XXX: Not yet */
+ error = EOPNOTSUPP;
+ DPRINTF(("scatter/gather not supported\n"));
+ break;
+ }
+
+ if (lreq.cmd_len > sizeof(req.cmd)) {
+ DPRINTF(("invalid command length %d\n", lreq.cmd_len));
+ error = EINVAL;
+ break;
+ }
+
+ error = copyin(lreq.cmdp, req.cmd, lreq.cmd_len);
+ if (error) {
+ DPRINTF(("failed to copy in cmd data %d\n", error));
+ break;
+ }
+
+ req.timeout = lreq.timeout;
+ req.cmdlen = lreq.cmd_len;
+ req.datalen = lreq.dxfer_len;
+ req.databuf = lreq.dxferp;
+
+ error = ioctlf(fp, SCIOCCOMMAND, (caddr_t)&req, p);
+ if (error) {
+ DPRINTF(("SCIOCCOMMAND failed %d\n", error));
+ break;
+ }
+#ifdef LINUX_SG_DEBUG
+ dump_scsireq(&req);
+#endif
+ (void)memset(&req, 0, sizeof(req));
+
+ if (req.senselen_used) {
+ lreq.sb_len_wr = req.senselen;
+ error = copyout(req.sense, lreq.sbp, req.senselen);
+ if (error) {
+ DPRINTF(("sense copyout failed %d\n", error));
+ break;
+ }
+ } else {
+ lreq.sb_len_wr = 0;
+ }
+
+ lreq.status = req.status;
+ lreq.masked_status = 0; /* XXX */
+ lreq.host_status = bsd_to_linux_host_status(req.retsts);
+ lreq.sb_len_wr = req.datalen_used;
+ lreq.driver_status = bsd_to_linux_driver_status(req.error);
+ lreq.resid = req.datalen - req.datalen_used;
+ lreq.duration = req.timeout; /* XXX */
+ lreq.info = 0; /* XXX */
+ error = copyout(&lreq, SCARG(uap, data), sizeof(lreq));
+ if (error)
+ DPRINTF(("failed to copy out req data %d\n", error));
+ break;
+ case LINUX_SG_EMULATED_HOST:
+ case LINUX_SG_SET_TRANSFORM:
+ case LINUX_SG_GET_TRANSFORM:
+ case LINUX_SG_GET_NUM_WAITING:
+ case LINUX_SG_SCSI_RESET:
+ case LINUX_SG_GET_REQUEST_TABLE:
+ case LINUX_SG_SET_KEEP_ORPHAN:
+ case LINUX_SG_GET_KEEP_ORPHAN:
+ case LINUX_SG_GET_ACCESS_COUNT:
+ case LINUX_SG_SET_FORCE_LOW_DMA:
+ case LINUX_SG_GET_LOW_DMA:
+ case LINUX_SG_GET_SG_TABLESIZE:
+ case LINUX_SG_GET_SCSI_ID:
+ case LINUX_SG_SET_FORCE_PACK_ID:
+ case LINUX_SG_GET_PACK_ID:
+ case LINUX_SG_SET_RESERVED_SIZE:
+ case LINUX_SG_GET_RESERVED_SIZE:
+ error = ENODEV;
+ break;
+
+ /* version 2 interfaces */
+ case LINUX_SG_SET_TIMEOUT:
+ break;
+ case LINUX_SG_GET_TIMEOUT:
+ /* ioctl returns value..., grr. */
+ *retval = 60;
+ break;
+ case LINUX_SG_GET_COMMAND_Q:
+ case LINUX_SG_SET_COMMAND_Q:
+ case LINUX_SG_SET_DEBUG:
+ case LINUX_SG_NEXT_CMD_LEN:
+ error = ENODEV;
+ break;
+ }
+
+done:
+ FILE_UNUSE(fp, p);
+
+ DPRINTF(("Return=%d\n", error));
+ return error;
+}
+
+static int
+bsd_to_linux_driver_status(int bs)
+{
+ switch (bs) {
+ default:
+ case XS_NOERROR:
+ return 0;
+ case XS_SENSE:
+ case XS_SHORTSENSE:
+ return LINUX_DRIVER_SENSE;
+ case XS_RESOURCE_SHORTAGE:
+ return LINUX_DRIVER_SOFT;
+ case XS_DRIVER_STUFFUP:
+ return LINUX_DRIVER_ERROR;
+ case XS_SELTIMEOUT:
+ case XS_TIMEOUT:
+ return LINUX_DRIVER_TIMEOUT;
+ case XS_BUSY:
+ return LINUX_DRIVER_BUSY;
+ case XS_RESET:
+ return LINUX_SUGGEST_ABORT;
+ case XS_REQUEUE:
+ return LINUX_SUGGEST_RETRY;
+ }
+}
+
+static int
+bsd_to_linux_host_status(int bs)
+{
+ switch (bs) {
+ case SCCMD_OK:
+ case SCCMD_SENSE:
+ return LINUX_DID_OK;
+ case SCCMD_TIMEOUT:
Home |
Main Index |
Thread Index |
Old Index