Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/scsipi Merge the geometry and cache handling code fo...



details:   https://anonhg.NetBSD.org/src/rev/ea215007ee79
branches:  trunk
changeset: 552074:ea215007ee79
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Thu Sep 18 00:06:31 2003 +0000

description:
Merge the geometry and cache handling code for all direct access and optical
devices, as it's general to all SCSI MMC devices.  In the process, remove
PQUIRK_NO_FLEX_PAGE.

diffstat:

 sys/dev/scsipi/atapiconf.c  |   13 +-
 sys/dev/scsipi/cd.c         |    6 +-
 sys/dev/scsipi/files.scsipi |    9 +-
 sys/dev/scsipi/scsipiconf.h |    4 +-
 sys/dev/scsipi/sd.c         |  615 ++++++++++++++++++++++++++++++++++++++--
 sys/dev/scsipi/sd_atapi.c   |  203 -------------
 sys/dev/scsipi/sd_scsi.c    |  667 --------------------------------------------
 sys/dev/scsipi/sdvar.h      |   17 +-
 8 files changed, 595 insertions(+), 939 deletions(-)

diffs (truncated from 1748 to 300 lines):

diff -r b16cdec8a6a2 -r ea215007ee79 sys/dev/scsipi/atapiconf.c
--- a/sys/dev/scsipi/atapiconf.c        Wed Sep 17 23:33:43 2003 +0000
+++ b/sys/dev/scsipi/atapiconf.c        Thu Sep 18 00:06:31 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atapiconf.c,v 1.60 2003/09/17 19:14:57 mycroft Exp $   */
+/*     $NetBSD: atapiconf.c,v 1.61 2003/09/18 00:06:31 mycroft Exp $   */
 
 /*
  * Copyright (c) 1996, 2001 Manuel Bouyer.  All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.60 2003/09/17 19:14:57 mycroft Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.61 2003/09/18 00:06:31 mycroft Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -103,15 +103,8 @@
         "CD-ROM  CDR-S1", "", "1.70"},         PQUIRK_NOCAPACITY}, /* Sanyo */
        {{T_CDROM, T_REMOV,
         "CD-ROM  CDR-N16", "", "1.25"},        PQUIRK_NOCAPACITY}, /* Sanyo */
-       {{T_DIRECT, T_REMOV,            /* Panasonic MultiMediaCard */
-         "04DA", "1B00", "0010"},              PQUIRK_NO_FLEX_PAGE },
-       {{T_DIRECT, T_REMOV,            /* ZiO! MultiMediaCard */
-         "eUSB", "MultiMediaCard", ""},        PQUIRK_NO_FLEX_PAGE },
        {{T_DIRECT, T_REMOV,
-         "FUJIFILM", "USB-DRIVEUNIT", "1.00"}, PQUIRK_NO_FLEX_PAGE |
-                                               PQUIRK_NOSENSE },
-       {{T_OPTICAL, T_REMOV,
-         "FUJITSU MCJ3230AP", "", ""},         PQUIRK_NO_FLEX_PAGE },
+         "FUJIFILM", "USB-DRIVEUNIT", "1.00"}, PQUIRK_NOSENSE },
 };
 
 int
diff -r b16cdec8a6a2 -r ea215007ee79 sys/dev/scsipi/cd.c
--- a/sys/dev/scsipi/cd.c       Wed Sep 17 23:33:43 2003 +0000
+++ b/sys/dev/scsipi/cd.c       Thu Sep 18 00:06:31 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cd.c,v 1.196 2003/09/13 15:49:04 mycroft Exp $ */
+/*     $NetBSD: cd.c,v 1.197 2003/09/18 00:06:32 mycroft Exp $ */
 
 /*-
  * Copyright (c) 1998, 2001, 2003 The NetBSD Foundation, Inc.
@@ -54,7 +54,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.196 2003/09/13 15:49:04 mycroft Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.197 2003/09/18 00:06:32 mycroft Exp $");
 
 #include "rnd.h"
 
@@ -1520,7 +1520,7 @@
         * We could probe the mode pages to figure out what kind of disc it is.
         * Is this worthwhile?
         */
-       strncpy(lp->d_typename, "generic CD/DVD", 16);
+       strncpy(lp->d_typename, "mydisc", 16);
        strncpy(lp->d_packname, "fictitious", 16);
        lp->d_secperunit = cd->params.disksize;
        lp->d_rpm = 300;
diff -r b16cdec8a6a2 -r ea215007ee79 sys/dev/scsipi/files.scsipi
--- a/sys/dev/scsipi/files.scsipi       Wed Sep 17 23:33:43 2003 +0000
+++ b/sys/dev/scsipi/files.scsipi       Thu Sep 18 00:06:31 2003 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.scsipi,v 1.35 2003/09/08 01:56:34 mycroft Exp $
+#      $NetBSD: files.scsipi,v 1.36 2003/09/18 00:06:34 mycroft Exp $
 #
 # Config file and device description for machine-independent SCSI code.
 # Included by ports that need it.  Ports that use it must provide
@@ -43,11 +43,8 @@
 file   dev/scsipi/if_se.c              se                      needs-flag
 
 device sd: disk
-attach sd at scsibus with sd_scsibus
-attach sd at atapibus with sd_atapibus
-file   dev/scsipi/sd_scsi.c            sd_scsibus
-file   dev/scsipi/sd_atapi.c           sd_atapibus
-file   dev/scsipi/sd.c                 sd | sd_scsibus | sd_atapibus needs-flag
+attach sd at scsibus, atapibus
+file   dev/scsipi/sd.c                 sd                      needs-flag
 
 device st: tape
 attach st at scsibus with st_scsibus
diff -r b16cdec8a6a2 -r ea215007ee79 sys/dev/scsipi/scsipiconf.h
--- a/sys/dev/scsipi/scsipiconf.h       Wed Sep 17 23:33:43 2003 +0000
+++ b/sys/dev/scsipi/scsipiconf.h       Thu Sep 18 00:06:31 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsipiconf.h,v 1.79 2003/09/17 19:14:58 mycroft Exp $  */
+/*     $NetBSD: scsipiconf.h,v 1.80 2003/09/18 00:06:34 mycroft Exp $  */
 
 /*-
  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@@ -452,8 +452,6 @@
 #define        PQUIRK_NOTUR            0x00001000      /* no TEST UNIT READY */
 #define        PQUIRK_NOSENSE          0x00004000      /* can't REQUEST SENSE */
 #define PQUIRK_ONLYBIG         0x00008000      /* only use SCSI_{R,W}_BIG */
-#define PQUIRK_NO_FLEX_PAGE    0x00020000      /* does not support flex geom
-                                                  page */
 #define PQUIRK_NOBIGMODESENSE  0x00040000      /* has no big mode-sense op */
 #define PQUIRK_CAP_SYNC                0x00080000      /* SCSI device with ST sync op*/
 #define PQUIRK_CAP_WIDE16      0x00100000      /* SCSI device with ST wide op*/
diff -r b16cdec8a6a2 -r ea215007ee79 sys/dev/scsipi/sd.c
--- a/sys/dev/scsipi/sd.c       Wed Sep 17 23:33:43 2003 +0000
+++ b/sys/dev/scsipi/sd.c       Thu Sep 18 00:06:31 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sd.c,v 1.208 2003/09/13 15:49:05 mycroft Exp $ */
+/*     $NetBSD: sd.c,v 1.209 2003/09/18 00:06:36 mycroft Exp $ */
 
 /*-
  * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
@@ -54,7 +54,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.208 2003/09/13 15:49:05 mycroft Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.209 2003/09/18 00:06:36 mycroft Exp $");
 
 #include "opt_scsi.h"
 #include "opt_bufq.h"
@@ -108,8 +108,43 @@
 int    sd_reassign_blocks __P((struct sd_softc *, u_long));
 int    sd_interpret_sense __P((struct scsipi_xfer *));
 
+int    sd_mode_sense __P((struct sd_softc *, u_int8_t, void *, size_t, int,
+           int, int *));
+int    sd_mode_select __P((struct sd_softc *, u_int8_t, void *, size_t, int,
+           int));
+int    sd_get_simplifiedparms __P((struct sd_softc *, struct disk_parms *,
+           int));
+int    sd_get_capacity __P((struct sd_softc *, struct disk_parms *, int));
+int    sd_get_parms __P((struct sd_softc *, struct disk_parms *, int));
+int    sd_flush __P((struct sd_softc *, int));
+int    sd_getcache __P((struct sd_softc *, int *));
+int    sd_setcache __P((struct sd_softc *, int));
+
+int    sdmatch __P((struct device *, struct cfdata *, void *));
+void   sdattach __P((struct device *, struct device *, void *));
+int    sdactivate __P((struct device *, enum devact));
+int    sddetach __P((struct device *, int));
+
+CFATTACH_DECL(sd, sizeof(struct sd_softc), sdmatch, sdattach, sddetach,
+    sdactivate);
+
 extern struct cfdriver sd_cd;
 
+const struct scsipi_inquiry_pattern sd_patterns[] = {
+       {T_DIRECT, T_FIXED,
+        "",         "",                 ""},
+       {T_DIRECT, T_REMOV,
+        "",         "",                 ""},
+       {T_OPTICAL, T_FIXED,
+        "",         "",                 ""},
+       {T_OPTICAL, T_REMOV,
+        "",         "",                 ""},
+       {T_SIMPLE_DIRECT, T_FIXED,
+        "",         "",                 ""},
+       {T_SIMPLE_DIRECT, T_REMOV,
+        "",         "",                 ""},
+};
+
 dev_type_open(sdopen);
 dev_type_close(sdclose);
 dev_type_read(sdread);
@@ -137,22 +172,65 @@
        sddone,                 /* deal with stats at interrupt time */
 };
 
+struct sd_mode_sense_data {
+       /*
+        * XXX
+        * We are not going to parse this as-is -- it just has to be large
+        * enough.
+        */
+       union {
+               struct scsipi_mode_header small;
+               struct scsipi_mode_header_big big;
+       } header;
+       struct scsi_blk_desc blk_desc;
+       union scsi_disk_pages pages;
+};
+
+/*
+ * The routine called by the low level scsi routine when it discovers
+ * A device suitable for this driver
+ */
+int
+sdmatch(parent, match, aux)
+       struct device *parent;
+       struct cfdata *match;
+       void *aux;
+{
+       struct scsipibus_attach_args *sa = aux;
+       int priority;
+
+       (void)scsipi_inqmatch(&sa->sa_inqbuf,
+           (caddr_t)sd_patterns, sizeof(sd_patterns) / sizeof(sd_patterns[0]),
+           sizeof(sd_patterns[0]), &priority);
+
+       return (priority);
+}
+
 /*
  * Attach routine common to atapi & scsi.
  */
 void
-sdattach(parent, sd, periph, ops)
-       struct device *parent;
-       struct sd_softc *sd;
-       struct scsipi_periph *periph;
-       const struct sd_ops *ops;
+sdattach(parent, self, aux)
+       struct device *parent, *self;
+       void *aux;
 {
+       struct sd_softc *sd = (void *)self;
+       struct scsipibus_attach_args *sa = aux;
+       struct scsipi_periph *periph = sa->sa_periph;
        int error, result;
        struct disk_parms *dp = &sd->params;
        char pbuf[9];
 
        SC_DEBUG(periph, SCSIPI_DB2, ("sdattach: "));
 
+       sd->type = (sa->sa_inqbuf.type & SID_TYPE);
+       if (sd->type == T_SIMPLE_DIRECT)
+               periph->periph_quirks |= PQUIRK_ONLYBIG | PQUIRK_NOBIGMODESENSE;
+
+       if (scsipi_periph_bustype(sa->sa_periph) == SCSIPI_BUSTYPE_SCSI &&
+           periph->periph_version == 0)
+               sd->flags |= SDF_ANCIENT;
+
 #ifdef NEW_BUFQ_STRATEGY
        bufq_alloc(&sd->buf_queue, BUFQ_READ_PRIO|BUFQ_SORT_RAWBLOCK);
 #else
@@ -163,7 +241,6 @@
         * Store information needed to contact our base driver
         */
        sd->sc_periph = periph;
-       sd->sc_ops = ops;
 
        periph->periph_dev = &sd->sc_dev;
        periph->periph_switch = &sd_switch;
@@ -197,8 +274,7 @@
        if (error)
                result = SDGP_RESULT_OFFLINE;
        else
-               result = (*sd->sc_ops->sdo_get_parms)(sd, &sd->params,
-                   XS_CTL_DISCOVERY);
+               result = sd_get_parms(sd, &sd->params, XS_CTL_DISCOVERY);
        aprint_normal("%s: ", sd->sc_dev.dv_xname);
        switch (result) {
        case SDGP_RESULT_OK:
@@ -472,7 +548,7 @@
                         * The drive should refuse real I/O, if the media is
                         * unformatted.
                         */
-                       if ((*sd->sc_ops->sdo_get_parms)(sd, &sd->params,
+                       if (sd_get_parms(sd, &sd->params,
                            0) == SDGP_RESULT_OFFLINE) {
                                error = ENXIO;
                                goto bad2;
@@ -564,9 +640,8 @@
                 * If the disk cache needs flushing, and the disk supports
                 * it, do it now.
                 */
-               if ((sd->flags & SDF_DIRTY) != 0 &&
-                   sd->sc_ops->sdo_flush != NULL) {
-                       if ((*sd->sc_ops->sdo_flush)(sd, 0)) {
+               if ((sd->flags & SDF_DIRTY) != 0) {
+                       if (sd_flush(sd, 0)) {
                                printf("%s: cache synchronization failed\n",
                                    sd->sc_dev.dv_xname);
                                sd->flags &= ~SDF_FLUSHING;
@@ -1106,21 +1181,12 @@
 #endif
 
        case DIOCGCACHE:
-               if (sd->sc_ops->sdo_getcache != NULL)
-                       return ((*sd->sc_ops->sdo_getcache)(sd, (int *) addr));
-
-               /* Not supported on this device. */
-               *(int *) addr = 0;
-               return (0);
+               return (sd_getcache(sd, (int *) addr));
 
        case DIOCSCACHE:
                if ((flag & FWRITE) == 0)
                        return (EBADF);
-               if (sd->sc_ops->sdo_setcache != NULL)
-                       return ((*sd->sc_ops->sdo_setcache)(sd, *(int *) addr));
-
-               /* Not supported on this device. */
-               return (EOPNOTSUPP);
+               return (sd_setcache(sd, *(int *) addr));
 
        case DIOCCACHESYNC:
                /*
@@ -1129,9 +1195,8 @@



Home | Main Index | Thread Index | Old Index