Author: mav
Date: Wed Feb  6 22:07:38 2013
New Revision: 246437
URL: http://svnweb.freebsd.org/changeset/base/246437

Log:
  MFC r235911, r235980, r238739, r238740, r238894, r239213, r241488, r241952,
  r242173, r242621, r242634, r242638, r242647, r242720, r244418, r244508,
  r245891:
  Revamp the CAM enclosure services driver.
  This updated driver uses an in-kernel daemon to track state changes and
  publishes physical path location information for disk elements into the
  CAM device database.
  
  Sponsored by:   Spectra Logic Corporation
  Sponsored by:   iXsystems, Inc.

Added:
  stable/9/sys/cam/scsi/scsi_enc.c
     - copied, changed from r235911, head/sys/cam/scsi/scsi_enc.c
  stable/9/sys/cam/scsi/scsi_enc.h
     - copied unchanged from r235911, head/sys/cam/scsi/scsi_enc.h
  stable/9/sys/cam/scsi/scsi_enc_internal.h
     - copied unchanged from r235911, head/sys/cam/scsi/scsi_enc_internal.h
  stable/9/sys/cam/scsi/scsi_enc_safte.c
     - copied, changed from r235911, head/sys/cam/scsi/scsi_enc_safte.c
  stable/9/sys/cam/scsi/scsi_enc_ses.c
     - copied, changed from r235911, head/sys/cam/scsi/scsi_enc_ses.c
Deleted:
  stable/9/sys/cam/scsi/scsi_ses.c
Modified:
  stable/9/share/examples/ses/Makefile.inc
  stable/9/share/examples/ses/sesd/sesd.0
  stable/9/share/examples/ses/srcs/eltsub.c
  stable/9/share/examples/ses/srcs/getencstat.c
  stable/9/share/examples/ses/srcs/getnobj.c
  stable/9/share/examples/ses/srcs/getobjmap.c
  stable/9/share/examples/ses/srcs/getobjstat.c
  stable/9/share/examples/ses/srcs/inienc.c
  stable/9/share/examples/ses/srcs/sesd.c
  stable/9/share/examples/ses/srcs/setencstat.c
  stable/9/share/examples/ses/srcs/setobjstat.c
  stable/9/sys/cam/scsi/scsi_pt.c
  stable/9/sys/cam/scsi/scsi_ses.h
  stable/9/sys/conf/files
  stable/9/sys/fs/devfs/devfs_vnops.c
  stable/9/sys/modules/cam/Makefile
  stable/9/usr.bin/kdump/mkioctls
Directory Properties:
  stable/9/share/examples/ses/   (props changed)
  stable/9/sys/   (props changed)
  stable/9/sys/conf/   (props changed)
  stable/9/sys/fs/   (props changed)
  stable/9/sys/modules/   (props changed)
  stable/9/usr.bin/kdump/   (props changed)

Modified: stable/9/share/examples/ses/Makefile.inc
==============================================================================
--- stable/9/share/examples/ses/Makefile.inc    Wed Feb  6 19:16:25 2013        
(r246436)
+++ stable/9/share/examples/ses/Makefile.inc    Wed Feb  6 22:07:38 2013        
(r246437)
@@ -32,7 +32,6 @@
 # mja...@feral.com
 #
 
-CFLAGS+= -I/usr/include/cam/scsi -DSESINC="<scsi_ses.h>"
 BINDIR?= /usr/sbin
 
 CLEANFILES+= ${MAN}

Modified: stable/9/share/examples/ses/sesd/sesd.0
==============================================================================
--- stable/9/share/examples/ses/sesd/sesd.0     Wed Feb  6 19:16:25 2013        
(r246436)
+++ stable/9/share/examples/ses/sesd/sesd.0     Wed Feb  6 22:07:38 2013        
(r246437)
@@ -31,7 +31,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd February 21, 2000
+.Dd November 5, 2012
 .Dt SESD 8
 .Os
 .Sh NAME
@@ -39,6 +39,7 @@
 .Nd monitor SCSI Environmental Services Devices
 .Sh SYNOPSIS
 .Nm
+.Op Fl c
 .Op Fl d
 .Op Fl t Ar poll-interval
 .Ar device
@@ -57,7 +58,9 @@ poll each device for a change in state.
 .Pp
 The following options may be used:
 .Bl -tag -width Ds
-.It Fl p Ar poll-interval
+.It Fl c
+Try to clear enclosure status after read.
+.It Fl t Ar poll-interval
 Change the interval of polling from the default 30 seconds to the number
 of seconds specified.
 .It Fl d

Modified: stable/9/share/examples/ses/srcs/eltsub.c
==============================================================================
--- stable/9/share/examples/ses/srcs/eltsub.c   Wed Feb  6 19:16:25 2013        
(r246436)
+++ stable/9/share/examples/ses/srcs/eltsub.c   Wed Feb  6 22:07:38 2013        
(r246437)
@@ -33,10 +33,13 @@
  */
 
 #include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_enc.h>
 
 #include "eltsub.h"
 
@@ -46,79 +49,82 @@ geteltnm(int type)
        static char rbuf[132];
 
        switch (type) {
-       case SESTYP_UNSPECIFIED:
+       case ELMTYP_UNSPECIFIED:
                sprintf(rbuf, "Unspecified");
                break;
-       case SESTYP_DEVICE:
-               sprintf(rbuf, "Device");
+       case ELMTYP_DEVICE:
+               sprintf(rbuf, "Device Slot");
                break;
-       case SESTYP_POWER:
-               sprintf(rbuf, "Power supply");
+       case ELMTYP_POWER:
+               sprintf(rbuf, "Power Supply");
                break;
-       case SESTYP_FAN:
-               sprintf(rbuf, "Cooling element");
+       case ELMTYP_FAN:
+               sprintf(rbuf, "Cooling");
                break;
-       case SESTYP_THERM:
-               sprintf(rbuf, "Temperature sensors");
+       case ELMTYP_THERM:
+               sprintf(rbuf, "Temperature Sensors");
                break;
-       case SESTYP_DOORLOCK:
+       case ELMTYP_DOORLOCK:
                sprintf(rbuf, "Door Lock");
                break;
-       case SESTYP_ALARM:
+       case ELMTYP_ALARM:
                sprintf(rbuf, "Audible alarm");
                break;
-       case SESTYP_ESCC:
-               sprintf(rbuf, "Enclosure services controller electronics");
+       case ELMTYP_ESCC:
+               sprintf(rbuf, "Enclosure Services Controller Electronics");
                break;
-       case SESTYP_SCC:
-               sprintf(rbuf, "SCC controller electronics");
+       case ELMTYP_SCC:
+               sprintf(rbuf, "SCC Controller Electronics");
                break;
-       case SESTYP_NVRAM:
-               sprintf(rbuf, "Nonvolatile cache");
+       case ELMTYP_NVRAM:
+               sprintf(rbuf, "Nonvolatile Cache");
                break;
-       case SESTYP_UPS:
-               sprintf(rbuf, "Uninterruptible power supply");
+       case ELMTYP_INV_OP_REASON:
+               sprintf(rbuf, "Invalid Operation Reason");
                break;
-       case SESTYP_DISPLAY:
+       case ELMTYP_UPS:
+               sprintf(rbuf, "Uninterruptible Power Supply");
+               break;
+       case ELMTYP_DISPLAY:
                sprintf(rbuf, "Display");
                break;
-       case SESTYP_KEYPAD:
-               sprintf(rbuf, "Key pad entry device");
+       case ELMTYP_KEYPAD:
+               sprintf(rbuf, "Key Pad Entry");
                break;
-       case SESTYP_ENCLOSURE:
+       case ELMTYP_ENCLOSURE:
                sprintf(rbuf, "Enclosure");
                break;
-       case SESTYP_SCSIXVR:
-               sprintf(rbuf, "SCSI port/transceiver");
+       case ELMTYP_SCSIXVR:
+               sprintf(rbuf, "SCSI Port/Transceiver");
                break;
-       case SESTYP_LANGUAGE:
+       case ELMTYP_LANGUAGE:
                sprintf(rbuf, "Language");
                break;
-       case SESTYP_COMPORT:
+       case ELMTYP_COMPORT:
                sprintf(rbuf, "Communication Port");
                break;
-       case SESTYP_VOM:
+       case ELMTYP_VOM:
                sprintf(rbuf, "Voltage Sensor");
                break;
-       case SESTYP_AMMETER:
+       case ELMTYP_AMMETER:
                sprintf(rbuf, "Current Sensor");
                break;
-       case SESTYP_SCSI_TGT:
-               sprintf(rbuf, "SCSI target port");
+       case ELMTYP_SCSI_TGT:
+               sprintf(rbuf, "SCSI Target Port");
                break;
-       case SESTYP_SCSI_INI:
-               sprintf(rbuf, "SCSI initiator port");
+       case ELMTYP_SCSI_INI:
+               sprintf(rbuf, "SCSI Initiator Port");
                break;
-       case SESTYP_SUBENC:
-               sprintf(rbuf, "Simple sub-enclosure");
+       case ELMTYP_SUBENC:
+               sprintf(rbuf, "Simple Subenclosure");
                break;
-       case SESTYP_ARRAY:
-               sprintf(rbuf, "Array device");
+       case ELMTYP_ARRAY_DEV:
+               sprintf(rbuf, "Array Device Slot");
                break;
-       case SESTYP_SASEXPANDER:
+       case ELMTYP_SAS_EXP:
                sprintf(rbuf, "SAS Expander");
                break;
-       case SESTYP_SASCONNECTOR:
+       case ELMTYP_SAS_CONN:
                sprintf(rbuf, "SAS Connector");
                break;
        default:
@@ -134,31 +140,34 @@ scode2ascii(u_char code)
        static char rbuf[32];
        switch (code & 0xf) {
        case SES_OBJSTAT_UNSUPPORTED:
-               sprintf(rbuf, "status not supported");
+               sprintf(rbuf, "Unsupported");
                break;
        case SES_OBJSTAT_OK:
-               sprintf(rbuf, "ok");
+               sprintf(rbuf, "OK");
                break;
        case SES_OBJSTAT_CRIT:
-               sprintf(rbuf, "critical");
+               sprintf(rbuf, "Critical");
                break;
        case SES_OBJSTAT_NONCRIT:
-               sprintf(rbuf, "non-critical");
+               sprintf(rbuf, "Noncritical");
                break;
        case SES_OBJSTAT_UNRECOV:
-               sprintf(rbuf, "unrecoverable");
+               sprintf(rbuf, "Unrecoverable");
                break;
        case SES_OBJSTAT_NOTINSTALLED:
-               sprintf(rbuf, "not installed");
+               sprintf(rbuf, "Not Installed");
                break;
        case SES_OBJSTAT_UNKNOWN:
-               sprintf(rbuf, "unknown status");
+               sprintf(rbuf, "Unknown");
                break;
        case SES_OBJSTAT_NOTAVAIL:
-               sprintf(rbuf, "status not available");
+               sprintf(rbuf, "Not Available");
+               break;
+       case SES_OBJSTAT_NOACCESS:
+               sprintf(rbuf, "No Access Allowed");
                break;
        default:
-               sprintf(rbuf, "unknown status code %x", code & 0xf);
+               sprintf(rbuf, "<Status 0x%x>", code & 0xf);
                break;
        }
        return (rbuf);
@@ -171,7 +180,11 @@ stat2ascii(int eletype __unused, u_char 
        static char ebuf[256], *scode;
 
        scode = scode2ascii(cstat[0]);
-       sprintf(ebuf, "Status=%s (bytes=0x%02x 0x%02x 0x%02x 0x%02x)",
-           scode, cstat[0], cstat[1], cstat[2], cstat[3]);
+       sprintf(ebuf, "status: %s%s%s%s (0x%02x 0x%02x 0x%02x 0x%02x)",
+           scode,
+           (cstat[0] & 0x40) ? ", Prd.Fail" : "",
+           (cstat[0] & 0x20) ? ", Disabled" : "",
+           (cstat[0] & 0x10) ? ", Swapped" : "",
+           cstat[0], cstat[1], cstat[2], cstat[3]);
        return (ebuf);
 }

Modified: stable/9/share/examples/ses/srcs/getencstat.c
==============================================================================
--- stable/9/share/examples/ses/srcs/getencstat.c       Wed Feb  6 19:16:25 
2013        (r246436)
+++ stable/9/share/examples/ses/srcs/getencstat.c       Wed Feb  6 22:07:38 
2013        (r246437)
@@ -33,20 +33,25 @@
  */
 
 #include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_enc.h>
 
 #include "eltsub.h"
 
 int
 main(int a, char **v)
 {
-       ses_object *objp;
-       ses_objstat ob;
+       encioc_element_t *objp;
+       encioc_elm_status_t ob;
+       encioc_elm_desc_t objd;
+       encioc_elm_devnames_t objdn;
        int fd, nobj, f, i, verbose, quiet, errors;
        u_char estat;
 
@@ -73,13 +78,13 @@ main(int a, char **v)
                        perror(*v);
                        continue;
                }
-               if (ioctl(fd, SESIOC_GETNOBJ, (caddr_t) &nobj) < 0) {
-                       perror("SESIOC_GETNOBJ");
+               if (ioctl(fd, ENCIOC_GETNELM, (caddr_t) &nobj) < 0) {
+                       perror("ENCIOC_GETNELM");
                        (void) close(fd);
                        continue;
                }
-               if (ioctl(fd, SESIOC_GETENCSTAT, (caddr_t) &estat) < 0) {
-                       perror("SESIOC_GETENCSTAT");
+               if (ioctl(fd, ENCIOC_GETENCSTAT, (caddr_t) &estat) < 0) {
+                       perror("ENCIOC_GETENCSTAT");
                        (void) close(fd);
                        continue;
                }
@@ -113,38 +118,64 @@ main(int a, char **v)
                        }
                }
                fprintf(stdout, ">\n");
-               objp = calloc(nobj, sizeof (ses_object));
+               objp = calloc(nobj, sizeof (encioc_element_t));
                if (objp == NULL) {
                        perror("calloc");
                        (void) close(fd);
                        continue;
                }
-                if (ioctl(fd, SESIOC_GETOBJMAP, (caddr_t) objp) < 0) {
-                        perror("SESIOC_GETOBJMAP");
+                if (ioctl(fd, ENCIOC_GETELMMAP, (caddr_t) objp) < 0) {
+                        perror("ENCIOC_GETELMMAP");
                         (void) close(fd);
                         continue;
                 }
                for (i = 0; i < nobj; i++) {
-                       ob.obj_id = objp[i].obj_id;
-                       if (ioctl(fd, SESIOC_GETOBJSTAT, (caddr_t) &ob) < 0) {
-                               perror("SESIOC_GETOBJSTAT");
+                       ob.elm_idx = objp[i].elm_idx;
+                       if (ioctl(fd, ENCIOC_GETELMSTAT, (caddr_t) &ob) < 0) {
+                               perror("ENCIOC_GETELMSTAT");
                                (void) close(fd);
                                break;
                        }
-                       if ((ob.cstat[0] & 0xf) == SES_OBJSTAT_OK) {
-                               if (verbose) {
-                                       fprintf(stdout,
-                                           "Element 0x%x: %s OK (%s)\n",
-                                           ob.obj_id,
-                                           geteltnm(objp[i].object_type),
-                                           stat2ascii(objp[i].object_type,
-                                           ob.cstat));
-                               }
+                       bzero(&objd, sizeof(objd));
+                       objd.elm_idx = objp[i].elm_idx;
+                       objd.elm_desc_len = UINT16_MAX;
+                       objd.elm_desc_str = calloc(UINT16_MAX, sizeof(char));
+                       if (objd.elm_desc_str == NULL) {
+                               perror("calloc");
+                               (void) close(fd);
                                continue;
                        }
-                       fprintf(stdout, "Element 0x%x: %s, %s\n",
-                           ob.obj_id, geteltnm(objp[i].object_type),
-                           stat2ascii(objp[i].object_type, ob.cstat));
+                       if (ioctl(fd, ENCIOC_GETELMDESC, (caddr_t)&objd) < 0) {
+                               perror("ENCIOC_GETELMDESC");
+                               (void) close(fd);
+                               break;
+                       }
+                       bzero(&objdn, sizeof(objdn));
+                       objdn.elm_idx = objp[i].elm_idx;
+                       objdn.elm_names_size = 128;
+                       objdn.elm_devnames = calloc(128, sizeof(char));
+                       if (objdn.elm_devnames == NULL) {
+                               perror("calloc");
+                               (void) close(fd);
+                               break;
+                       }
+                       /*
+                        * This ioctl isn't critical and has a good chance
+                        * of returning -1.
+                        */
+                       (void)ioctl(fd, ENCIOC_GETELMDEVNAMES, (caddr_t)&objdn);
+                       fprintf(stdout, "Element 0x%x: %s", ob.elm_idx,
+                           geteltnm(objp[i].elm_type));
+                       fprintf(stdout, ", %s",
+                           stat2ascii(objp[i].elm_type, ob.cstat));
+                       if (objd.elm_desc_len > 0)
+                               fprintf(stdout, ", descriptor: '%s'",
+                                   objd.elm_desc_str);
+                       if (objdn.elm_names_len > 0)
+                               fprintf(stdout, ", dev: '%s'",
+                                   objdn.elm_devnames);
+                       fprintf(stdout, "\n");
+                       free(objdn.elm_devnames);
                }
                free(objp);
                (void) close(fd);

Modified: stable/9/share/examples/ses/srcs/getnobj.c
==============================================================================
--- stable/9/share/examples/ses/srcs/getnobj.c  Wed Feb  6 19:16:25 2013        
(r246436)
+++ stable/9/share/examples/ses/srcs/getnobj.c  Wed Feb  6 22:07:38 2013        
(r246437)
@@ -33,12 +33,15 @@
  */
 
 #include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_ses.h>
 
 int
 main(int argc, char **argv)

Modified: stable/9/share/examples/ses/srcs/getobjmap.c
==============================================================================
--- stable/9/share/examples/ses/srcs/getobjmap.c        Wed Feb  6 19:16:25 
2013        (r246436)
+++ stable/9/share/examples/ses/srcs/getobjmap.c        Wed Feb  6 22:07:38 
2013        (r246437)
@@ -33,11 +33,14 @@
  */
 
 #include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_ses.h>
 
 #include "eltsub.h"
 

Modified: stable/9/share/examples/ses/srcs/getobjstat.c
==============================================================================
--- stable/9/share/examples/ses/srcs/getobjstat.c       Wed Feb  6 19:16:25 
2013        (r246436)
+++ stable/9/share/examples/ses/srcs/getobjstat.c       Wed Feb  6 22:07:38 
2013        (r246437)
@@ -32,11 +32,14 @@
  * mja...@feral.com
  */
 #include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_ses.h>
 
 int
 main(int a, char **v)

Modified: stable/9/share/examples/ses/srcs/inienc.c
==============================================================================
--- stable/9/share/examples/ses/srcs/inienc.c   Wed Feb  6 19:16:25 2013        
(r246436)
+++ stable/9/share/examples/ses/srcs/inienc.c   Wed Feb  6 22:07:38 2013        
(r246437)
@@ -33,11 +33,14 @@
  */
 
 #include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_ses.h>
 
 int
 main(int a, char **v)

Modified: stable/9/share/examples/ses/srcs/sesd.c
==============================================================================
--- stable/9/share/examples/ses/srcs/sesd.c     Wed Feb  6 19:16:25 2013        
(r246436)
+++ stable/9/share/examples/ses/srcs/sesd.c     Wed Feb  6 22:07:38 2013        
(r246437)
@@ -32,14 +32,18 @@
  * mja...@feral.com
  */
 #include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <string.h>
 #include <syslog.h>
+#include <unistd.h>
 #include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_enc.h>
 
 #define        ALLSTAT (SES_ENCSTAT_UNRECOV | SES_ENCSTAT_CRITICAL | \
        SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
@@ -52,29 +56,33 @@ int
 main(int a, char **v)
 {
        static const char *usage =
-           "usage: %s [ -d ] [ -t pollinterval ] device [ device ]\n";
-       int fd, polltime, dev, devbase, nodaemon;
-       ses_encstat stat, *carray;
+           "usage: %s [ -c ] [ -d ] [ -t pollinterval ] device [ device ]\n";
+       int fd, polltime, dev, nodaemon, clear, c;
+       encioc_enc_status_t stat, nstat, *carray;
 
        if (a < 2) {
                fprintf(stderr, usage, *v);
                return (1);
        }
 
-       devbase = 1;
-
-       if (strcmp(v[1], "-d") == 0) {
-               nodaemon = 1;
-               devbase++;
-       } else {
-               nodaemon = 0;
-       }
-
-       if (a > 2 && strcmp(v[2], "-t") == 0) {
-               devbase += 2;
-               polltime = atoi(v[3]);
-       } else {
-               polltime = 30;
+       nodaemon = 0;
+       polltime = 30;
+       clear = 0;
+       while ((c = getopt(a, v, "cdt:")) != -1) {
+               switch (c) {
+               case 'c':
+                       clear = 1;
+                       break;
+               case 'd':
+                       nodaemon = 1;
+                       break;
+               case 't':
+                       polltime = atoi(optarg);
+                       break;
+               default:
+                       fprintf(stderr, usage, *v);
+                       return (1);
+               }
        }
 
        carray = malloc(a);
@@ -82,20 +90,20 @@ main(int a, char **v)
                perror("malloc");
                return (1);
        }
-       for (dev = devbase; dev < a; dev++)
-               carray[dev] = (ses_encstat) -1;
+       for (dev = optind; dev < a; dev++)
+               carray[dev] = (encioc_enc_status_t) -1;
 
        /*
         * Check to make sure we can open all devices
         */
-       for (dev = devbase; dev < a; dev++) {
+       for (dev = optind; dev < a; dev++) {
                fd = open(v[dev], O_RDWR);
                if (fd < 0) {
                        perror(v[dev]);
                        return (1);
                }
-               if (ioctl(fd, SESIOC_INIT, NULL) < 0) {
-                       fprintf(stderr, "%s: SESIOC_INIT fails- %s\n",
+               if (ioctl(fd, ENCIOC_INIT, NULL) < 0) {
+                       fprintf(stderr, "%s: ENCIOC_INIT fails- %s\n",
                            v[dev], strerror(errno));
                        return (1);
                }
@@ -112,7 +120,7 @@ main(int a, char **v)
        }
 
        for (;;) {
-               for (dev = devbase; dev < a; dev++) {
+               for (dev = optind; dev < a; dev++) {
                        fd = open(v[dev], O_RDWR);
                        if (fd < 0) {
                                syslog(LOG_ERR, "%s: %m", v[dev]);
@@ -122,12 +130,20 @@ main(int a, char **v)
                        /*
                         * Get the actual current enclosure status.
                         */
-                       if (ioctl(fd, SESIOC_GETENCSTAT, (caddr_t) &stat) < 0) {
+                       if (ioctl(fd, ENCIOC_GETENCSTAT, (caddr_t) &stat) < 0) {
                                syslog(LOG_ERR,
-                                   "%s: SESIOC_GETENCSTAT- %m", v[dev]);
+                                   "%s: ENCIOC_GETENCSTAT- %m", v[dev]);
                                (void) close(fd);
                                continue;
                        }
+                       if (stat != 0 && clear) {
+                               nstat = 0;
+                               if (ioctl(fd, ENCIOC_SETENCSTAT,
+                                   (caddr_t) &nstat) < 0) {
+                                       syslog(LOG_ERR,
+                                           "%s: ENCIOC_SETENCSTAT- %m", 
v[dev]);
+                               }
+                       }
                        (void) close(fd);
 
                        if (stat == carray[dev])
@@ -139,9 +155,8 @@ main(int a, char **v)
                                    "%s: Enclosure Status OK", v[dev]);
                        }
                        if (stat & SES_ENCSTAT_INFO) {
-                               syslog(LOG_INFO,
-                                   "%s: Enclosure Status Has Information",
-                                   v[dev]);
+                               syslog(LOG_NOTICE,
+                                   "%s: Enclosure Has Information", v[dev]);
                        }
                        if (stat & SES_ENCSTAT_NONCRITICAL) {
                                syslog(LOG_WARNING,

Modified: stable/9/share/examples/ses/srcs/setencstat.c
==============================================================================
--- stable/9/share/examples/ses/srcs/setencstat.c       Wed Feb  6 19:16:25 
2013        (r246436)
+++ stable/9/share/examples/ses/srcs/setencstat.c       Wed Feb  6 22:07:38 
2013        (r246437)
@@ -33,18 +33,21 @@
  */
 
 #include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_enc.h>
 
 int
 main(int a, char **v)
 {
        int fd;
        long val;
-       ses_encstat stat;
+       encioc_enc_status_t stat;
 
        if (a != 3) {
                fprintf(stderr, "usage: %s device enclosure_status\n", *v);
@@ -57,9 +60,9 @@ main(int a, char **v)
        }
        
        val =  strtol(v[2], NULL, 0);
-       stat = (ses_encstat) val;
-       if (ioctl(fd, SESIOC_SETENCSTAT, (caddr_t) &stat) < 0) {
-               perror("SESIOC_SETENCSTAT");
+       stat = (encioc_enc_status_t)val;
+       if (ioctl(fd, ENCIOC_SETENCSTAT, (caddr_t) &stat) < 0) {
+               perror("ENCIOC_SETENCSTAT");
        }
        (void) close(fd);
        return (0);

Modified: stable/9/share/examples/ses/srcs/setobjstat.c
==============================================================================
--- stable/9/share/examples/ses/srcs/setobjstat.c       Wed Feb  6 19:16:25 
2013        (r246436)
+++ stable/9/share/examples/ses/srcs/setobjstat.c       Wed Feb  6 22:07:38 
2013        (r246437)
@@ -33,18 +33,21 @@
  */
 
 #include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_enc.h>
 
 int
 main(int a, char **v)
 {
        int fd;
        int i;
-       ses_objstat obj;
+       encioc_elm_status_t obj;
        long cvt;
        char *x;
 
@@ -64,7 +67,7 @@ usage:
        if (x == v[2]) {
                goto usage;
        }
-       obj.obj_id = cvt;
+       obj.elm_idx = cvt;
        for (i = 0; i < 4; i++) {
                x = v[3 + i];
                cvt = strtol(v[3 + i],  &x, 0);
@@ -73,8 +76,8 @@ usage:
                }
                obj.cstat[i] = cvt;
        }
-       if (ioctl(fd, SESIOC_SETOBJSTAT, (caddr_t) &obj) < 0) {
-               perror("SESIOC_SETOBJSTAT");
+       if (ioctl(fd, ENCIOC_SETELMSTAT, (caddr_t) &obj) < 0) {
+               perror("ENCIOC_SETELMSTAT");
        }
        (void) close(fd);
        return (0);

Copied and modified: stable/9/sys/cam/scsi/scsi_enc.c (from r235911, 
head/sys/cam/scsi/scsi_enc.c)
==============================================================================
--- head/sys/cam/scsi/scsi_enc.c        Thu May 24 14:07:44 2012        
(r235911, copy source)
+++ stable/9/sys/cam/scsi/scsi_enc.c    Wed Feb  6 22:07:38 2013        
(r246437)
@@ -56,15 +56,10 @@ __FBSDID("$FreeBSD$");
 #include <cam/scsi/scsi_enc.h>
 #include <cam/scsi/scsi_enc_internal.h>
 
-#include <opt_enc.h>
-
 MALLOC_DEFINE(M_SCSIENC, "SCSI ENC", "SCSI ENC buffers");
 
 /* Enclosure type independent driver */
 
-#define        SEN_ID          "UNISYS           SUN_SEN"
-#define        SEN_ID_LEN      24
-
 static d_open_t        enc_open;
 static d_close_t       enc_close;
 static d_ioctl_t       enc_ioctl;
@@ -136,15 +131,8 @@ enc_oninvalidate(struct cam_periph *peri
         */
        enc->enc_flags |= ENC_FLAG_SHUTDOWN;
        if (enc->enc_daemon != NULL) {
-               /* Signal and wait for the ses daemon to terminate. */
+               /* Signal the ses daemon to terminate. */
                wakeup(enc->enc_daemon);
-               /*
-                * We're called with the SIM mutex held, but we're dropping
-                * the update mutex here on sleep.  So we have to manually
-                * drop the SIM mutex.
-                */
-               cam_periph_sleep(enc->periph, enc->enc_daemon,
-                                PUSER, "thtrm", 0);
        }
        callout_drain(&enc->status_updater);
 
@@ -567,7 +555,7 @@ enc_runcmd(struct enc_softc *enc, char *
                cdbl = IOCDBLEN;
        }
 
-       ccb = cam_periph_getccb(enc->periph, 1);
+       ccb = cam_periph_getccb(enc->periph, CAM_PRIORITY_NORMAL);
        if (enc->enc_type == ENC_SEMB_SES || enc->enc_type == ENC_SEMB_SAFT) {
                tdlen = min(dlen, 1020);
                tdlen = (tdlen + 3) & ~3;
@@ -635,9 +623,8 @@ enc_log(struct enc_softc *enc, const cha
 /*
  * Is this a device that supports enclosure services?
  *
- * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
- * an ENC device. If it happens to be an old UNISYS SEN device, we can
- * handle that too.
+ * It's a a pretty simple ruleset- if it is device type
+ * 0x0D (13), it's an ENCLOSURE device.
  */
 
 #define        SAFTE_START     44
@@ -664,13 +651,9 @@ enc_type(struct ccb_getdev *cgd)
        iqd = (unsigned char *)&cgd->inq_data;
        buflen = min(sizeof(cgd->inq_data),
            SID_ADDITIONAL_LENGTH(&cgd->inq_data));
-       if (buflen < 8+SEN_ID_LEN)
-               return (ENC_NONE);
 
        if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
-               if (STRNCMP(&iqd[8], SEN_ID, SEN_ID_LEN) == 0) {
-                       return (ENC_SEN);
-               } else if ((iqd[2] & 0x7) > 2) {
+               if ((iqd[2] & 0x7) > 2) {
                        return (ENC_SES);
                } else {
                        return (ENC_SES_SCSI2);
@@ -839,6 +822,7 @@ enc_daemon(void *arg)
        }
        enc->enc_daemon = NULL;
        cam_periph_unlock(enc->periph);
+       cam_periph_release(enc->periph);
        kproc_exit(0);
 }
 
@@ -849,6 +833,9 @@ enc_kproc_init(enc_softc_t *enc)
 
        callout_init_mtx(&enc->status_updater, enc->periph->sim->mtx, 0);
 
+       if (cam_periph_acquire(enc->periph) != CAM_REQ_CMP)
+               return (ENXIO);
+
        result = kproc_create(enc_daemon, enc, &enc->enc_daemon, /*flags*/0,
                              /*stackpgs*/0, "enc_daemon%d",
                              enc->periph->unit_number);
@@ -857,7 +844,8 @@ enc_kproc_init(enc_softc_t *enc)
                cam_periph_lock(enc->periph);
                enc->enc_vec.poll_status(enc);
                cam_periph_unlock(enc->periph);
-       }
+       } else
+               cam_periph_release(enc->periph);
        return (result);
 }
  
@@ -887,11 +875,6 @@ enc_ctor(struct cam_periph *periph, void
        char *tname;
 
        cgd = (struct ccb_getdev *)arg;
-       if (periph == NULL) {
-               printf("enc_ctor: periph was NULL!!\n");
-               goto out;
-       }
-
        if (cgd == NULL) {
                printf("enc_ctor: no getdev CCB, can't register device\n");
                goto out;
@@ -920,7 +903,6 @@ enc_ctor(struct cam_periph *periph, void
        case ENC_SEMB_SAFT:
                err = safte_softc_init(enc);
                break;
-       case ENC_SEN:
        case ENC_NONE:
        default:
                ENC_FREE(enc);
@@ -955,7 +937,7 @@ enc_ctor(struct cam_periph *periph, void
                err = enc_kproc_init(enc);
                if (err) {
                        xpt_print(periph->path,
-                                 "error %d string enc_daemon\n", err);
+                                 "error %d starting enc_daemon\n", err);
                        goto out;
                }
        }
@@ -987,9 +969,6 @@ enc_ctor(struct cam_periph *periph, void
         case ENC_SES_PASSTHROUGH:
                tname = "ENC Passthrough Device";
                break;
-        case ENC_SEN:
-               tname = "UNISYS SEN Device (NOT HANDLED YET)";
-               break;
         case ENC_SAFT:
                tname = "SAF-TE Compliant Device";
                break;

Copied: stable/9/sys/cam/scsi/scsi_enc.h (from r235911, 
head/sys/cam/scsi/scsi_enc.h)
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/9/sys/cam/scsi/scsi_enc.h    Wed Feb  6 22:07:38 2013        
(r246437, copy of r235911, head/sys/cam/scsi/scsi_enc.h)
@@ -0,0 +1,219 @@
+/* $FreeBSD$ */
+/*-
+ * Copyright (c) 2000 by Matthew Jacob
+ * 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,
+ *    without modification, immediately at the beginning of the file.
+ * 2. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * the GNU Public License ("GPL").
+ *
+ * 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.
+ *
+ */
+#ifndef        _SCSI_ENC_H_
+#define        _SCSI_ENC_H_
+
+#include <cam/scsi/scsi_ses.h>
+
+#define        ENCIOC                  ('s' - 040)
+#define        ENCIOC_GETNELM          _IO(ENCIOC, 1)
+#define        ENCIOC_GETELMMAP        _IO(ENCIOC, 2)
+#define        ENCIOC_GETENCSTAT       _IO(ENCIOC, 3)
+#define        ENCIOC_SETENCSTAT       _IO(ENCIOC, 4)
+#define        ENCIOC_GETELMSTAT       _IO(ENCIOC, 5)
+#define        ENCIOC_SETELMSTAT       _IO(ENCIOC, 6)
+#define        ENCIOC_GETTEXT          _IO(ENCIOC, 7)
+#define        ENCIOC_INIT             _IO(ENCIOC, 8)
+#define        ENCIOC_GETELMDESC       _IO(ENCIOC, 9)
+#define        ENCIOC_GETELMDEVNAMES   _IO(ENCIOC, 10)
+#define        ENCIOC_GETSTRING        _IO(ENCIOC, 11)
+#define        ENCIOC_SETSTRING        _IO(ENCIOC, 12)
+
+/*
+ * Platform Independent Definitions for enclosure devices.
+ */
+/*
+ * SCSI Based Environmental Services Application Defines
+ *
+ * Based almost entirely on SCSI-3 ENC Revision 8A specification,
+ * but slightly abstracted as the underlying device may in fact
+ * be a SAF-TE or vendor unique device.
+ */
+/*
+ * ENC Driver Operations:
+ * (The defines themselves are platform and access method specific)
+ *
+ * ENCIOC_GETNELM
+ * ENCIOC_GETELMMAP
+ * ENCIOC_GETENCSTAT
+ * ENCIOC_SETENCSTAT
+ * ENCIOC_GETELMSTAT
+ * ENCIOC_SETELMSTAT
+ * ENCIOC_INIT
+ *
+ *
+ * An application finds out how many elements an enclosure instance
+ * is managing by performing a ENCIOC_GETNELM operation. It then
+ * performs a ENCIOC_GETELMMAP to get the map that contains the
+ * elment identifiers for all elements (see encioc_element_t below).
+ * This information is static.
+ * 
+ * The application may perform ENCIOC_GETELMSTAT operations to retrieve
+ * status on an element (see the enc_elm_status_t structure below),
+ * ENCIOC_SETELMSTAT operations to set status for an element.
+ *
+ * Similarly, overall enclosure status me be fetched or set via
+ * ENCIOC_GETENCSTAT or  ENCIOC_SETENCSTAT operations (see encioc_enc_status_t
+ * below).
+ *
+ * Readers should note that there is nothing that requires either a set
+ * or a clear operation to actually latch and do anything in the target.
+ *
+ * A ENCIOC_INIT operation causes the enclosure to be initialized.
+ */
+
+/* Element Types */
+typedef enum {
+       ELMTYP_UNSPECIFIED      = 0x00,
+       ELMTYP_DEVICE           = 0x01,
+       ELMTYP_POWER            = 0x02,
+       ELMTYP_FAN              = 0x03,
+       ELMTYP_THERM            = 0x04,
+       ELMTYP_DOORLOCK         = 0x05,
+       ELMTYP_ALARM            = 0x06,
+       ELMTYP_ESCC             = 0x07, /* Enclosure SCC */
+       ELMTYP_SCC              = 0x08, /* SCC */
+       ELMTYP_NVRAM            = 0x09,
+       ELMTYP_INV_OP_REASON    = 0x0a,
+       ELMTYP_UPS              = 0x0b,
+       ELMTYP_DISPLAY          = 0x0c,
+       ELMTYP_KEYPAD           = 0x0d,
+       ELMTYP_ENCLOSURE        = 0x0e,
+       ELMTYP_SCSIXVR          = 0x0f,
+       ELMTYP_LANGUAGE         = 0x10,
+       ELMTYP_COMPORT          = 0x11,
+       ELMTYP_VOM              = 0x12,
+       ELMTYP_AMMETER          = 0x13,
+       ELMTYP_SCSI_TGT         = 0x14,
+       ELMTYP_SCSI_INI         = 0x15,
+       ELMTYP_SUBENC           = 0x16,
+       ELMTYP_ARRAY_DEV        = 0x17,
+       ELMTYP_SAS_EXP          = 0x18, /* SAS expander */
+       ELMTYP_SAS_CONN         = 0x19  /* SAS connector */
+} elm_type_t;
+
+typedef struct encioc_element {
+       /* Element Index */
+       unsigned int    elm_idx;        
+
+       /* ID of SubEnclosure containing Element*/
+       unsigned int    elm_subenc_id;
+
+       /* Element Type */
+       elm_type_t      elm_type;
+} encioc_element_t;
+
+/*
+ * Overall Enclosure Status
+ */
+typedef unsigned char encioc_enc_status_t;
+
+/*
+ * Element Status
+ */
+typedef struct encioc_elm_status {
+       unsigned int    elm_idx;
+       unsigned char   cstat[4];
+} encioc_elm_status_t;
+
+/*
+ * ENC String structure, for StringIn and StringOut commands; use this with
+ * the ENCIOC_GETSTRING and ENCIOC_SETSTRING ioctls.
+ */
+typedef struct encioc_string {
+       size_t bufsiz;          /* IN/OUT: length of string provided/returned */
+#define        ENC_STRING_MAX  0xffff
+       uint8_t *buf;           /* IN/OUT: string */
+} encioc_string_t;
+
+/*============================================================================*/
+
+/* 
+ * SES v2 r20 6.1.10 (pg 39) - Element Descriptor diagnostic page
+ * Tables 21, 22, and 23
+ */
+typedef struct encioc_elm_desc {
+       unsigned int     elm_idx;       /* IN: elment requested */
+       uint16_t         elm_desc_len; /* IN: buffer size; OUT: bytes written */
+       char            *elm_desc_str; /* IN/OUT: buffer for descriptor data */
+} encioc_elm_desc_t;
+
+/*
+ * ENCIOC_GETELMDEVNAMES:
+ * ioctl structure to get an element's device names, if available
+ */
+typedef struct  encioc_elm_devnames {
+       unsigned int     elm_idx;       /* IN: element index */
+       size_t           elm_names_size;/* IN: size of elm_devnames */
+       size_t           elm_names_len; /* OUT: actual size returned */
+       /*
+        * IN/OUT: comma separated list of peripheral driver
+        * instances servicing this element.
+        */
+       char            *elm_devnames;
+} encioc_elm_devnames_t;
+
+/* ioctl structure for requesting FC info for a port */
+typedef struct encioc_elm_fc_port {
+       unsigned int            elm_idx;
+       unsigned int            port_idx;
+       struct ses_elm_fc_port  port_data;
+} encioc_elm_fc_port_t;

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to