Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 May 1999 11:17:46 -0400 (EDT)
From:      Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To:        "John W. DeBoskey" <jwd@unx.sas.com>
Cc:        freebsd-current@FreeBSD.ORG
Subject:   Re: cvs commit: src/sys/i386/isa ida.c
Message-ID:  <199905271517.LAA19291@khavrinen.lcs.mit.edu>
In-Reply-To: <199905270323.XAA66917@bb01f39.unx.sas.com>
References:  <199905270323.XAA66917@bb01f39.unx.sas.com>

next in thread | previous in thread | raw e-mail | index | archive | help
<<On Wed, 26 May 1999 23:23:27 -0400 (EDT), "John W. DeBoskey" <jwd@unx.sas.com> said:

>    I have/use Dell enclosures. These show-up at boot-time as:

> pass6 at ahc0 bus 0 target 6 lun 0
> pass6: <DELL 8UWS BACKPLANE 5> Fixed Processor SCSI-2 device 
> pass6: 3.300MB/s transfers

If they implement the SAF-TE standard, then they will return 50 bytes
of inquire data; after the usual SCSI standard data comes the string
`SAF-TE'.  Here is an example, using the old `libscsi' interface and
some appropriate structure definitions:

static int
is_safte(int fd, struct hsbp *hs)
{
        int i;
        char *cp;
        struct scsireq req;
        struct inquire_response resp;
        struct encl_config encl;
        struct hsbp_info *info = &hs->info;

        scsireq_reset(&req);
        scsireq_build(&req, sizeof resp, (char *)&resp, SCCMD_READ,
                            "12 v:b3 0:b5 0 0 v 0", (int)info->hi_sc_lun,
                      (int)sizeof resp);
        scsireq_enter(fd, &req);
        /*
         * If we had an error this early, we can't possibly work with this
         * device.  Also return false if we didn't get enough data back
         * to be a valid SAF-TE response.
         */
        if (SCSIREQ_ERROR((&req)) || req.datalen_used < sizeof resp)
                return 0;
        if (strncmp(resp.safte_id, "SAF-TE", 6) != 0)
                return 0;
        if (strncmp(resp.safte_rev, "1.0", 3) != 0)
                return 0;
        info->hi_type = HSBP_TYPE_SAFTE_1;

        /*
         * Format the enclosure ID as something human-readable.
         */
        for (i = 0, cp = info->hi_serial; i < sizeof(resp.encl_id); 
             i++, cp += 2) {
                snprintf(cp, 2, "%02x", (u_int)resp.encl_id[i] & 0xff);
        }

        /*
         * Copy the other INQUIRE information into the standard
         * format.
         */
#define TRIM(field) \
        do { cp = &field[(sizeof field) - 1]; \
                while (cp > field && *cp == ' ') { \
                        *cp-- = '\0'; \
                } \
        } while(0)
        TRIM(resp.vendor);
        TRIM(resp.product);
        TRIM(resp.firmware);
#undef TRIM
        info->hi_vendor[0] = info->hi_model[0] = info->hi_swrev[0] = '\0';
        strncat(info->hi_vendor, resp.vendor, sizeof resp.vendor);
        strncat(info->hi_model, resp.product, sizeof resp.product);
        strncat(info->hi_swrev, resp.firmware, sizeof resp.firmware);

        if (safte_read_buffer(fd, info->hi_sc_lun, SAFTE_BUF_ENCL_CONFIG,
                              sizeof encl, &encl) < sizeof encl) {
                warnx("/dev/pt%d did not accept Read Enclosure Configuration",
                     info->hi_pt_unit);
                return 0;
        }
        info->hi_nslots = encl.nslots;
        info->hi_nfans = encl.nfans;
        info->hi_nps = encl.npower;
        info->hi_ntemps = encl.ntemps;
        info->hi_haslock = encl.haslock;
        info->hi_hasspkr = encl.hasspkr;

        hs->u.safte.statuslen = encl.nfans + encl.npower + encl.nslots + 2
                + encl.ntemps + 2;
        hs->u.safte.status = malloc(hs->u.safte.statuslen);
        if (hs->u.safte.status == 0)
                err(EX_OSERR, "malloc(%lu)", (u_long)hs->u.safte.statuslen);
        hs->u.safte.slotstatus = malloc(4 * encl.nslots);
        if (hs->u.safte.slotstatus == 0)
                err(EX_OSERR, "malloc(%d)", 4 * encl.nslots);
        hs->u.safte.oslotstatus = malloc(4 * encl.nslots);
        if (hs->u.safte.oslotstatus == 0)
                err(EX_OSERR, "malloc(%d)", 4 * encl.nslots);

        hs->u.safte.psstatus = hs->u.safte.status + encl.nfans;
        hs->u.safte.slotids = hs->u.safte.psstatus + encl.npower;
        hs->u.safte.lockstatus = hs->u.safte.slotids + encl.nslots;
        hs->u.safte.spkrstatus = hs->u.safte.lockstatus + 1;
        hs->u.safte.temps = hs->u.safte.spkrstatus + 1;
        hs->u.safte.tempalarms = hs->u.safte.temps + encl.ntemps;

        if (safte_read_buffer(fd, info->hi_sc_lun, SAFTE_BUF_ENCL_STATUS,
                              hs->u.safte.statuslen, hs->u.safte.status)
            < (int)hs->u.safte.statuslen) {
                warnx("/dev/pt%d did not accept Read Enclosure Status",
                     info->hi_pt_unit);
                free(hs->u.safte.status);
                free(hs->u.safte.slotstatus);
                hs->u.safte.status = 0;
                hs->u.safte.statuslen = 0;
                return 0;
        }
        /*
         * Build the SCSI unit number map.
         * The specification has the bug that, when no device is installed,
         * the unit might be specified as 255 (meaning ``none'').
         */
        for (i = 0; i < 16; i++)
                info->hi_slotunit[i] = -1;
        for (cp = hs->u.safte.slotids, i = 0; i < encl.nslots; i++) {
                if (cp[i] < 16)
                        info->hi_slotunit[(u_char)cp[i]] = i;
        }

        if (safte_read_buffer(fd, info->hi_sc_lun, SAFTE_BUF_SLOT_STATUS,
                              4 * encl.nslots, hs->u.safte.slotstatus)
            < 4 * encl.nslots) {
                warnx("/dev/pt%d did not accept Read Device Slot Status",
                      info->hi_pt_unit);
                free(hs->u.safte.status);
                free(hs->u.safte.slotstatus);
                return 0;
        }
        memcpy(hs->u.safte.oslotstatus, hs->u.safte.slotstatus,
              4 * encl.nslots);
        memset(hs->u.safte.cmdbytes, 0, sizeof hs->u.safte.cmdbytes);
        hs->u.safte.cmdbytes[0] = SAFTE_WRT_GLOBAL_CMD;

        return 1;
}

-GAWollman

--
Garrett A. Wollman   | O Siem / We are all family / O Siem / We're all the same
wollman@lcs.mit.edu  | O Siem / The fires of freedom 
Opinions not those of| Dance in the burning flame
MIT, LCS, CRS, or NSA|                     - Susan Aglukark and Chad Irschick


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199905271517.LAA19291>