Add REPORT LUNS basic infrastructure.
authorPeter Avalos <pavalos@dragonflybsd.org>
Sat, 24 Nov 2007 03:48:31 +0000 (03:48 +0000)
committerPeter Avalos <pavalos@dragonflybsd.org>
Sat, 24 Nov 2007 03:48:31 +0000 (03:48 +0000)
Obtained-from: FreeBSD

sys/bus/cam/scsi/scsi_all.c
sys/bus/cam/scsi/scsi_all.h

index 2720eaa..3314e80 100644 (file)
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_all.c,v 1.14.2.11 2003/10/30 15:06:35 thomas Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_all.c,v 1.18 2007/11/24 03:09:57 pavalos Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_all.c,v 1.19 2007/11/24 03:48:31 pavalos Exp $
  */
 
 #include <sys/param.h>
@@ -2584,6 +2584,34 @@ scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
               reladr |= SRC16_RELADR;
 }
 
+/*
+ * Prevent or allow the user to remove the media
+ */
+void
+scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
+            void (*cbfcnp)(struct cam_periph *, union ccb *),
+            u_int8_t tag_action, u_int8_t action,
+            u_int8_t sense_len, u_int32_t timeout)
+{
+       struct scsi_prevent *scsi_cmd;
+
+       cam_fill_csio(csio,
+                     retries,
+                     cbfcnp,
+                     /*flags*/CAM_DIR_NONE,
+                     tag_action,
+                     /*data_ptr*/NULL,
+                     /*dxfer_len*/0,
+                     sense_len,
+                     sizeof(*scsi_cmd),
+                     timeout);
+
+       scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
+       bzero(scsi_cmd, sizeof(*scsi_cmd));
+       scsi_cmd->opcode = PREVENT_ALLOW;
+       scsi_cmd->how = action;
+}
+
 /* XXX allow specification of address and PMI bit and LBA */
 void
 scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
@@ -2610,32 +2638,28 @@ scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
        scsi_cmd->opcode = READ_CAPACITY;
 }
 
-/*
- * Prevent or allow the user to remove the media
- */
 void
-scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
-            void (*cbfcnp)(struct cam_periph *, union ccb *),
-            u_int8_t tag_action, u_int8_t action,
-            u_int8_t sense_len, u_int32_t timeout)
+scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
+                void (*cbfcnp)(struct cam_periph *, union ccb *),
+                u_int8_t tag_action, struct scsi_report_luns_data *rpl_buf,
+                u_int32_t alloc_len, u_int8_t sense_len, u_int32_t timeout)
 {
-       struct scsi_prevent *scsi_cmd;
+       struct scsi_report_luns *scsi_cmd;
 
        cam_fill_csio(csio,
                      retries,
                      cbfcnp,
-                     /*flags*/CAM_DIR_NONE,
+                     /*flags*/CAM_DIR_IN,
                      tag_action,
-                     /*data_ptr*/NULL,
-                     /*dxfer_len*/0,
+                     /*data_ptr*/(u_int8_t *)rpl_buf,
+                     /*dxfer_len*/alloc_len,
                      sense_len,
                      sizeof(*scsi_cmd),
                      timeout);
-
-       scsi_cmd = (struct scsi_prevent *)&csio->cdb_io.cdb_bytes;
+       scsi_cmd = (struct scsi_report_luns *)&csio->cdb_io.cdb_bytes;
        bzero(scsi_cmd, sizeof(*scsi_cmd));
-       scsi_cmd->opcode = PREVENT_ALLOW;
-       scsi_cmd->how = action;
+       scsi_cmd->opcode = REPORT_LUNS;
+       scsi_ulto4b(alloc_len, scsi_cmd->addr);
 }
 
 /*
index b33b04f..2779250 100644 (file)
@@ -15,7 +15,7 @@
  * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_all.h,v 1.14.2.5 2003/08/24 03:26:37 ken Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_all.h,v 1.9 2007/11/22 16:34:25 pavalos Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_all.h,v 1.10 2007/11/24 03:48:31 pavalos Exp $
  */
 
 /*
@@ -530,6 +530,7 @@ struct scsi_start_stop_unit
 #define READ_16                        0x88
 #define WRITE_16               0x8a
 #define SERVICE_ACTION_IN      0x9e
+#define REPORT_LUNS            0xa0
 #define MOVE_MEDIUM            0xa5
 #define READ_12                        0xa8
 #define WRITE_12               0xaa
@@ -718,6 +719,29 @@ struct scsi_read_capacity_data_long
        uint8_t length[4];
 };
 
+struct scsi_report_luns
+{
+       u_int8_t opcode;
+       u_int8_t byte2;
+       u_int8_t unused[3];
+       u_int8_t addr[4];
+       u_int8_t control;
+};
+
+struct scsi_report_luns_data {
+       u_int8_t length[4];     /* length of LUN inventory, in bytes */
+       u_int8_t reserved[4];   /* unused */
+       /*
+        * LUN inventory- we only support the type zero form for now.
+        */
+       struct {
+               u_int8_t lundata[8];
+       } luns[1];
+};
+#define        RPL_LUNDATA_ATYP_MASK   0xc0    /* MBZ for type 0 lun */
+#define        RPL_LUNDATA_T0LUN       1       /* @ lundata[1] */
+
+
 struct scsi_sense_data
 {
        u_int8_t error_code;
@@ -796,6 +820,8 @@ struct scsi_mode_blk_desc
 
 #define        SCSI_DEFAULT_DENSITY    0x00    /* use 'default' density */
 #define        SCSI_SAME_DENSITY       0x7f    /* use 'same' density- >= SCSI-2 only */
+
+
 /*
  * Status Byte
  */
@@ -1002,10 +1028,15 @@ void            scsi_log_select(struct ccb_scsiio *csio, u_int32_t retries,
                                u_int32_t param_len, u_int8_t sense_len,
                                u_int32_t timeout);
 
+void           scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
+                            void (*cbfcnp)(struct cam_periph *, union ccb *),
+                            u_int8_t tag_action, u_int8_t action,
+                            u_int8_t sense_len, u_int32_t timeout);
+
 void           scsi_read_capacity(struct ccb_scsiio *csio, u_int32_t retries,
                                   void (*cbfcnp)(struct cam_periph *, 
                                   union ccb *), u_int8_t tag_action, 
-                                  struct scsi_read_capacity_data *rcap_buf,
+                                  struct scsi_read_capacity_data *,
                                   u_int8_t sense_len, u_int32_t timeout);
 void           scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
                                    void (*cbfcnp)(struct cam_periph *,
@@ -1015,10 +1046,12 @@ void            scsi_read_capacity_16(struct ccb_scsiio *csio, uint32_t retries,
                                    *rcap_buf, uint8_t sense_len,
                                    uint32_t timeout);
 
-void           scsi_prevent(struct ccb_scsiio *csio, u_int32_t retries,
-                            void (*cbfcnp)(struct cam_periph *, union ccb *),
-                            u_int8_t tag_action, u_int8_t action,
-                            u_int8_t sense_len, u_int32_t timeout);
+void           scsi_report_luns(struct ccb_scsiio *csio, u_int32_t retries,
+                                  void (*cbfcnp)(struct cam_periph *, 
+                                  union ccb *), u_int8_t tag_action, 
+                                  struct scsi_report_luns_data *,
+                                  u_int32_t alloc_len, u_int8_t sense_len,
+                                  u_int32_t timeout);
 
 void           scsi_synchronize_cache(struct ccb_scsiio *csio, 
                                       u_int32_t retries,