diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2011-06-15 01:10:06 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2011-06-15 01:10:06 +0000 |
commit | 345c2e919d8140aa32d9978a51dfb81d5f62a151 (patch) | |
tree | 83ae7ea234907e58faf9a51f530e30307ca585ba /sys/scsi | |
parent | 295fe234b22aea9894037c1519e7fd090eb126f0 (diff) |
factor the common bits out of code that builds scsi inquiry commands into
scsi_init_inquiry(). cut the compiled INQUIRY code over to it.
ok and tweaks from krw@
ok matthew@
Diffstat (limited to 'sys/scsi')
-rw-r--r-- | sys/scsi/safte.c | 11 | ||||
-rw-r--r-- | sys/scsi/scsi_base.c | 47 | ||||
-rw-r--r-- | sys/scsi/scsiconf.h | 4 |
3 files changed, 30 insertions, 32 deletions
diff --git a/sys/scsi/safte.c b/sys/scsi/safte.c index cd76518a9c2..4cc0586c8bc 100644 --- a/sys/scsi/safte.c +++ b/sys/scsi/safte.c @@ -1,4 +1,4 @@ -/* $OpenBSD: safte.c,v 1.47 2011/03/17 21:30:24 deraadt Exp $ */ +/* $OpenBSD: safte.c,v 1.48 2011/06/15 01:10:05 dlg Exp $ */ /* * Copyright (c) 2005 David Gwynne <dlg@openbsd.org> @@ -112,7 +112,6 @@ safte_match(struct device *parent, void *match, void *aux) struct scsi_inquiry_data *inqbuf; struct scsi_attach_args *sa = aux; struct scsi_inquiry_data *inq = sa->sa_inqbuf; - struct scsi_inquiry *cmd; struct scsi_xfer *xs; struct safte_inq *si; int error, flags = 0, length; @@ -147,15 +146,11 @@ safte_match(struct device *parent, void *match, void *aux) xs = scsi_xs_get(sa->sa_sc_link, flags | SCSI_DATA_IN); if (xs == NULL) goto fail; - xs->cmdlen = sizeof(*cmd); - xs->data = (void *)inqbuf; - xs->datalen = length; + xs->retries = 2; xs->timeout = 10000; - cmd = (struct scsi_inquiry *)xs->cmd; - cmd->opcode = INQUIRY; - _lto2b(length, cmd->length); + scsi_init_inquiry(xs, 0, 0, inqbuf, length); error = scsi_xs_sync(xs); scsi_xs_put(xs); diff --git a/sys/scsi/scsi_base.c b/sys/scsi/scsi_base.c index ab4d1bacd5c..8364b8dde86 100644 --- a/sys/scsi/scsi_base.c +++ b/sys/scsi/scsi_base.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scsi_base.c,v 1.199 2011/03/17 21:30:24 deraadt Exp $ */ +/* $OpenBSD: scsi_base.c,v 1.200 2011/06/15 01:10:05 dlg Exp $ */ /* $NetBSD: scsi_base.c,v 1.43 1997/04/02 02:29:36 mycroft Exp $ */ /* @@ -894,6 +894,25 @@ scsi_test_unit_ready(struct scsi_link *sc_link, int retries, int flags) return (error); } +void +scsi_init_inquiry(struct scsi_xfer *xs, u_int8_t flags, u_int8_t pagecode, + void *data, size_t len) +{ + struct scsi_inquiry *cmd; + + cmd = (struct scsi_inquiry *)xs->cmd; + cmd->opcode = INQUIRY; + cmd->flags = flags; + cmd->pagecode = pagecode; + _lto2b(len, cmd->length); + + xs->cmdlen = sizeof(*cmd); + + xs->flags |= SCSI_DATA_IN; + xs->data = data; + xs->datalen = len; +} + /* * Do a scsi operation asking a device what it is. * Use the scsi_cmd routine in the switch table. @@ -902,9 +921,7 @@ int scsi_inquire(struct scsi_link *link, struct scsi_inquiry_data *inqbuf, int flags) { - struct scsi_inquiry *cmd; struct scsi_xfer *xs; - size_t length; int error; xs = scsi_xs_get(link, flags); @@ -915,17 +932,7 @@ scsi_inquire(struct scsi_link *link, struct scsi_inquiry_data *inqbuf, * Ask for only the basic 36 bytes of SCSI2 inquiry information. This * avoids problems with devices that choke trying to supply more. */ - length = SID_INQUIRY_HDR + SID_SCSI2_ALEN; - - cmd = (struct scsi_inquiry *)xs->cmd; - cmd->opcode = INQUIRY; - _lto2b(length, cmd->length); - - xs->cmdlen = sizeof(*cmd); - - xs->flags |= SCSI_DATA_IN; - xs->data = (void *)inqbuf; - xs->datalen = length; + scsi_init_inquiry(xs, 0, 0, inqbuf, SID_INQUIRY_HDR + SID_SCSI2_ALEN); bzero(inqbuf, sizeof(*inqbuf)); memset(&inqbuf->vendor, ' ', sizeof inqbuf->vendor); @@ -947,7 +954,6 @@ int scsi_inquire_vpd(struct scsi_link *sc_link, void *buf, u_int buflen, u_int8_t page, int flags) { - struct scsi_inquiry *cmd; struct scsi_xfer *xs; int error; @@ -957,19 +963,14 @@ scsi_inquire_vpd(struct scsi_link *sc_link, void *buf, u_int buflen, xs = scsi_xs_get(sc_link, flags | SCSI_DATA_IN | SCSI_SILENT); if (xs == NULL) return (ENOMEM); - xs->cmdlen = sizeof(*cmd); - xs->data = buf; - xs->datalen = buflen; + xs->retries = 2; xs->timeout = 10000; - cmd = (struct scsi_inquiry *)xs->cmd; - cmd->opcode = INQUIRY; - cmd->flags = SI_EVPD; - cmd->pagecode = page; - _lto2b(buflen, cmd->length); + scsi_init_inquiry(xs, SI_EVPD, page, buf, buflen); error = scsi_xs_sync(xs); + scsi_xs_put(xs); return (error); diff --git a/sys/scsi/scsiconf.h b/sys/scsi/scsiconf.h index aebaffa35db..c7db4893d5e 100644 --- a/sys/scsi/scsiconf.h +++ b/sys/scsi/scsiconf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: scsiconf.h,v 1.144 2011/04/06 15:16:54 dlg Exp $ */ +/* $OpenBSD: scsiconf.h,v 1.145 2011/06/15 01:10:05 dlg Exp $ */ /* $NetBSD: scsiconf.h,v 1.35 1997/04/02 02:29:38 mycroft Exp $ */ /* @@ -538,6 +538,8 @@ daddr64_t scsi_size(struct scsi_link *, int, u_int32_t *); int scsi_test_unit_ready(struct scsi_link *, int, int); int scsi_inquire(struct scsi_link *, struct scsi_inquiry_data *, int); int scsi_inquire_vpd(struct scsi_link *, void *, u_int, u_int8_t, int); +void scsi_init_inquiry(struct scsi_xfer *, u_int8_t, u_int8_t, + void *, size_t); int scsi_prevent(struct scsi_link *, int, int); int scsi_start(struct scsi_link *, int, int); int scsi_mode_sense(struct scsi_link *, int, int, struct scsi_mode_header *, |