diff --git a/sys/dev/scsipi/scsi_all.h b/sys/dev/scsipi/scsi_all.h index d92d370befd7..82e47067fe9e 100644 --- a/sys/dev/scsipi/scsi_all.h +++ b/sys/dev/scsipi/scsi_all.h @@ -1,4 +1,4 @@ -/* $NetBSD: scsi_all.h,v 1.8 1996/07/10 22:48:56 explorer Exp $ */ +/* $NetBSD: scsi_all.h,v 1.9 1996/09/03 18:20:31 thorpej Exp $ */ /* * SCSI general interface description @@ -34,8 +34,14 @@ #define SCSI_CTL_LINK 0x01 #define SCSI_CTL_FLAG 0x02 #define SCSI_CTL_VENDOR 0xC0 -#define SCSI_CMD_LUN 0xA0 /* these two should not be needed */ -#define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */ + + +/* + * Some old SCSI devices need the LUN to be set in the top 3 bits of the + * second byte of the CDB. + */ +#define SCSI_CMD_LUN_MASK 0xe0 +#define SCSI_CMD_LUN_SHIFT 5 struct scsi_generic { diff --git a/sys/dev/scsipi/scsi_base.c b/sys/dev/scsipi/scsi_base.c index f2d49a7c0643..fedffbd2bba0 100644 --- a/sys/dev/scsipi/scsi_base.c +++ b/sys/dev/scsipi/scsi_base.c @@ -1,4 +1,4 @@ -/* $NetBSD: scsi_base.c,v 1.37 1996/07/05 16:19:02 christos Exp $ */ +/* $NetBSD: scsi_base.c,v 1.38 1996/09/03 18:20:33 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Charles Hannum. All rights reserved. @@ -180,6 +180,14 @@ scsi_make_xs(sc_link, scsi_cmd, cmdlen, data_addr, datalen, xs->timeout = timeout; xs->bp = bp; + /* + * Set the LUN in the CDB if we have an older device. We also + * set it for more modern SCSI-II devices "just in case". + */ + if ((sc_link->scsi_version & SID_ANSII) <= 2) + xs->cmd->bytes[0] |= + ((sc_link->lun << SCSI_CMD_LUN_SHIFT) & SCSI_CMD_LUN_MASK); + return xs; } diff --git a/sys/dev/scsipi/scsiconf.c b/sys/dev/scsipi/scsiconf.c index 5413c0c59ed0..60d579a86c06 100644 --- a/sys/dev/scsipi/scsiconf.c +++ b/sys/dev/scsipi/scsiconf.c @@ -1,4 +1,4 @@ -/* $NetBSD: scsiconf.c,v 1.62 1996/08/28 18:47:51 cgd Exp $ */ +/* $NetBSD: scsiconf.c,v 1.63 1996/09/03 18:20:35 thorpej Exp $ */ /* * Copyright (c) 1994 Charles Hannum. All rights reserved. @@ -586,6 +586,7 @@ scsi_probedev(scsi, target, lun) if ((inqbuf.version & SID_ANSII) == 0 && (sc_link->quirks & SDEV_FORCELUNS) == 0) sc_link->quirks |= SDEV_NOLUNS; + sc_link->scsi_version = inqbuf.version; if ((sc_link->quirks & SDEV_NOLUNS) == 0) scsi->moreluns |= (1 << target); diff --git a/sys/dev/scsipi/scsiconf.h b/sys/dev/scsipi/scsiconf.h index 724a3293b79e..72fbc4b51d4c 100644 --- a/sys/dev/scsipi/scsiconf.h +++ b/sys/dev/scsipi/scsiconf.h @@ -1,4 +1,4 @@ -/* $NetBSD: scsiconf.h,v 1.31 1996/08/28 18:47:55 cgd Exp $ */ +/* $NetBSD: scsiconf.h,v 1.32 1996/09/03 18:20:36 thorpej Exp $ */ /* * Copyright (c) 1993, 1994, 1995 Charles Hannum. All rights reserved. @@ -139,6 +139,7 @@ struct scsi_device { struct scsi_link { int channel; /* channel, i.e. bus # on controller */ + u_int8_t scsi_version; /* SCSI-I, SCSI-II, etc. */ u_int8_t scsibus; /* the Nth scsibus */ u_int8_t target; /* targ of this dev */ u_int8_t lun; /* lun of this dev */ diff --git a/sys/scsi/scsi_all.h b/sys/scsi/scsi_all.h index d92d370befd7..82e47067fe9e 100644 --- a/sys/scsi/scsi_all.h +++ b/sys/scsi/scsi_all.h @@ -1,4 +1,4 @@ -/* $NetBSD: scsi_all.h,v 1.8 1996/07/10 22:48:56 explorer Exp $ */ +/* $NetBSD: scsi_all.h,v 1.9 1996/09/03 18:20:31 thorpej Exp $ */ /* * SCSI general interface description @@ -34,8 +34,14 @@ #define SCSI_CTL_LINK 0x01 #define SCSI_CTL_FLAG 0x02 #define SCSI_CTL_VENDOR 0xC0 -#define SCSI_CMD_LUN 0xA0 /* these two should not be needed */ -#define SCSI_CMD_LUN_SHIFT 5 /* LUN in the cmd is no longer SCSI */ + + +/* + * Some old SCSI devices need the LUN to be set in the top 3 bits of the + * second byte of the CDB. + */ +#define SCSI_CMD_LUN_MASK 0xe0 +#define SCSI_CMD_LUN_SHIFT 5 struct scsi_generic { diff --git a/sys/scsi/scsi_base.c b/sys/scsi/scsi_base.c index f2d49a7c0643..fedffbd2bba0 100644 --- a/sys/scsi/scsi_base.c +++ b/sys/scsi/scsi_base.c @@ -1,4 +1,4 @@ -/* $NetBSD: scsi_base.c,v 1.37 1996/07/05 16:19:02 christos Exp $ */ +/* $NetBSD: scsi_base.c,v 1.38 1996/09/03 18:20:33 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Charles Hannum. All rights reserved. @@ -180,6 +180,14 @@ scsi_make_xs(sc_link, scsi_cmd, cmdlen, data_addr, datalen, xs->timeout = timeout; xs->bp = bp; + /* + * Set the LUN in the CDB if we have an older device. We also + * set it for more modern SCSI-II devices "just in case". + */ + if ((sc_link->scsi_version & SID_ANSII) <= 2) + xs->cmd->bytes[0] |= + ((sc_link->lun << SCSI_CMD_LUN_SHIFT) & SCSI_CMD_LUN_MASK); + return xs; } diff --git a/sys/scsi/scsiconf.c b/sys/scsi/scsiconf.c index 5413c0c59ed0..60d579a86c06 100644 --- a/sys/scsi/scsiconf.c +++ b/sys/scsi/scsiconf.c @@ -1,4 +1,4 @@ -/* $NetBSD: scsiconf.c,v 1.62 1996/08/28 18:47:51 cgd Exp $ */ +/* $NetBSD: scsiconf.c,v 1.63 1996/09/03 18:20:35 thorpej Exp $ */ /* * Copyright (c) 1994 Charles Hannum. All rights reserved. @@ -586,6 +586,7 @@ scsi_probedev(scsi, target, lun) if ((inqbuf.version & SID_ANSII) == 0 && (sc_link->quirks & SDEV_FORCELUNS) == 0) sc_link->quirks |= SDEV_NOLUNS; + sc_link->scsi_version = inqbuf.version; if ((sc_link->quirks & SDEV_NOLUNS) == 0) scsi->moreluns |= (1 << target); diff --git a/sys/scsi/scsiconf.h b/sys/scsi/scsiconf.h index 724a3293b79e..72fbc4b51d4c 100644 --- a/sys/scsi/scsiconf.h +++ b/sys/scsi/scsiconf.h @@ -1,4 +1,4 @@ -/* $NetBSD: scsiconf.h,v 1.31 1996/08/28 18:47:55 cgd Exp $ */ +/* $NetBSD: scsiconf.h,v 1.32 1996/09/03 18:20:36 thorpej Exp $ */ /* * Copyright (c) 1993, 1994, 1995 Charles Hannum. All rights reserved. @@ -139,6 +139,7 @@ struct scsi_device { struct scsi_link { int channel; /* channel, i.e. bus # on controller */ + u_int8_t scsi_version; /* SCSI-I, SCSI-II, etc. */ u_int8_t scsibus; /* the Nth scsibus */ u_int8_t target; /* targ of this dev */ u_int8_t lun; /* lun of this dev */