Author: nwhitehorn
Date: Tue Oct 29 15:36:58 2013
New Revision: 257345
URL: http://svnweb.freebsd.org/changeset/base/257345

Log:
  Implement extended LUN support. If PIM_EXTLUNS is set by a SIM, encode
  the upper 32-bits of the LUN, if possible, into the target_lun field as
  passed directly from the REPORT LUNs response. This allows extended LUN
  support to work for all LUNs with zeros in the lower 32-bits, which covers
  most addressing modes without breaking KBI. Behavior for drivers not
  setting PIM_EXTLUNS is unchanged. No user-facing interfaces are modified.
  
  Extended LUNs are stored with swizzled 16-bit word order so that, for
  devices implementing LUN addressing (like SCSI-2), the numerical
  representation of the LUN is identical with and without PIM_EXTLUNS. Thus
  setting PIM_EXTLUNS keeps most behavior, and user-facing LUN IDs, unchanged.
  This follows the strategy used in Solaris. A macro (CAM_EXTLUN_BYTE_SWIZZLE)
  is provided to transform a lun_id_t into a uint64_t ordered for the wire.
  
  This is the second part of work for full 64-bit extended LUN support and is
  designed to a bridge for stable/10 to the final 64-bit LUN code. The
  third and final part will involve widening lun_id_t to 64 bits and will
  not be MFCed. This third part will break the KBI but will keep the KPI
  unchanged so that all drivers that will care about this can be updated now
  and not require code changes between HEAD and stable/10.
  
  Reviewed by:  scottl
  MFC after:    2 weeks

Modified:
  head/sys/cam/cam.h
  head/sys/cam/scsi/scsi_xpt.c
  head/sys/powerpc/pseries/phyp_vscsi.c

Modified: head/sys/cam/cam.h
==============================================================================
--- head/sys/cam/cam.h  Tue Oct 29 15:07:54 2013        (r257344)
+++ head/sys/cam/cam.h  Tue Oct 29 15:36:58 2013        (r257345)
@@ -50,6 +50,12 @@ typedef union {
 #define        CAM_TARGET_WILDCARD ((target_id_t)~0)
 #define        CAM_LUN_WILDCARD ((lun_id_t)~0)
 
+#define CAM_EXTLUN_BYTE_SWIZZLE(lun) ( \
+       ((((u_int64_t)lun) & 0xffff000000000000L) >> 48) | \
+       ((((u_int64_t)lun) & 0x0000ffff00000000L) >> 16) | \
+       ((((u_int64_t)lun) & 0x00000000ffff0000L) << 16) | \
+       ((((u_int64_t)lun) & 0x000000000000ffffL) << 48))
+
 /*
  * Maximum length for a CAM CDB.  
  */

Modified: head/sys/cam/scsi/scsi_xpt.c
==============================================================================
--- head/sys/cam/scsi/scsi_xpt.c        Tue Oct 29 15:07:54 2013        
(r257344)
+++ head/sys/cam/scsi/scsi_xpt.c        Tue Oct 29 15:36:58 2013        
(r257345)
@@ -100,6 +100,12 @@ SYSCTL_PROC(_kern_cam, OID_AUTO, cam_src
                (lval) <<= 8;                                           \
                (lval) |=  (lp)->luns[(i)].lundata[1];                  \
        }
+#define        CAM_GET_LUN(lp, i, lval)                                        
\
+       (lval) = scsi_4btoul((lp)->luns[(i)].lundata);                  \
+       (lval) = ((lval) >> 16) | ((lval) << 16);
+#define CAM_LUN_ONLY_32BITS(lp, i)                             \
+       (scsi_4btoul(&((lp)->luns[(i)].lundata[4])) == 0)
+
 /*
  * If we're not quirked to search <= the first 8 luns
  * and we are either quirked to search above lun 8,
@@ -175,7 +181,8 @@ do {                                                        
                \
 typedef enum {
        PROBE_INQUIRY_CKSUM     = 0x01,
        PROBE_SERIAL_CKSUM      = 0x02,
-       PROBE_NO_ANNOUNCE       = 0x04
+       PROBE_NO_ANNOUNCE       = 0x04,
+       PROBE_EXTLUN            = 0x08
 } probe_flags;
 
 typedef struct {
@@ -561,10 +568,9 @@ static void         proberequestdefaultnegotiat
 static int       proberequestbackoff(struct cam_periph *periph,
                                     struct cam_ed *device);
 static void     probedone(struct cam_periph *periph, union ccb *done_ccb);
-static int      probe_strange_rpl_data(struct scsi_report_luns_data *rp,
-                                       uint32_t maxlun);
 static void     probe_purge_old(struct cam_path *path,
-                                struct scsi_report_luns_data *new);
+                                struct scsi_report_luns_data *new,
+                                probe_flags flags);
 static void     probecleanup(struct cam_periph *periph);
 static void     scsi_find_quirk(struct cam_ed *device);
 static void     scsi_scan_bus(struct cam_periph *periph, union ccb *ccb);
@@ -700,6 +706,11 @@ probeschedule(struct cam_periph *periph)
        else
                softc->flags &= ~PROBE_NO_ANNOUNCE;
 
+       if (cpi.hba_misc & PIM_EXTLUNS)
+               softc->flags |= PROBE_EXTLUN;
+       else
+               softc->flags &= ~PROBE_EXTLUN;
+
        xpt_schedule(periph, CAM_PRIORITY_XPT);
 }
 
@@ -1278,13 +1289,6 @@ out:
                         */
                        free(lp, M_CAMXPT);
                        lp = NULL;
-               } else if (probe_strange_rpl_data(lp, maxlun)) {
-                       /*
-                        * If we can't understand the lun format
-                        * of any entry, bail.
-                        */
-                       free(lp, M_CAMXPT);
-                       lp = NULL;
                } else {
                        lun_id_t lun;
                        int idx;
@@ -1292,14 +1296,14 @@ out:
                        CAM_DEBUG(path, CAM_DEBUG_PROBE,
                           ("Probe: %u lun(s) reported\n", nlun));
 
-                       CAM_GET_SIMPLE_LUN(lp, 0, lun);
+                       CAM_GET_LUN(lp, 0, lun);
                        /*
                         * If the first lun is not lun 0, then either there
                         * is no lun 0 in the list, or the list is unsorted.
                         */
                        if (lun != 0) {
                                for (idx = 0; idx < nlun; idx++) {
-                                       CAM_GET_SIMPLE_LUN(lp, idx, lun);
+                                       CAM_GET_LUN(lp, idx, lun);
                                        if (lun == 0) {
                                                break;
                                        }
@@ -1331,7 +1335,7 @@ out:
                         * This function will also install the new list
                         * in the target structure.
                         */
-                       probe_purge_old(path, lp);
+                       probe_purge_old(path, lp, softc->flags);
                        lp = NULL;
                }
                if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) {
@@ -1703,26 +1707,14 @@ probe_device_check:
        }
 }
 
-static int
-probe_strange_rpl_data(struct scsi_report_luns_data *rp, uint32_t maxlun)
-{
-       uint32_t idx;
-       uint32_t nlun = MIN(maxlun, (scsi_4btoul(rp->length) / 8));
-
-       for (idx = 0; idx < nlun; idx++) {
-               if (!CAM_CAN_GET_SIMPLE_LUN(rp, idx)) {
-                       return (-1);
-               }
-       }
-       return (0);
-}
-
 static void
-probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new)
+probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new,
+    probe_flags flags)
 {
        struct cam_path *tp;
        struct scsi_report_luns_data *old;
-       u_int idx1, idx2, nlun_old, nlun_new, this_lun;
+       u_int idx1, idx2, nlun_old, nlun_new;
+       lun_id_t this_lun;
        u_int8_t *ol, *nl;
 
        if (path->target == NULL) {
@@ -1757,17 +1749,26 @@ probe_purge_old(struct cam_path *path, s
                 * that would be what the probe state
                 * machine is currently working on,
                 * so we won't do that.
-                *
-                * We also cannot nuke it if it is
-                * not in a lun format we understand.
                 */
-               if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1)) {
-                       continue;
-               }
-               CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
+               CAM_GET_LUN(old, idx1, this_lun);
                if (this_lun == 0) {
                        continue;
                }
+
+               /*
+                * We also cannot nuke it if it is
+                * not in a lun format we understand
+                * and replace the LUN with a "simple" LUN
+                * if that is all the HBA supports.
+                */
+               if (!(flags & PROBE_EXTLUN)) {
+                       if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1))
+                               continue;
+                       CAM_GET_SIMPLE_LUN(old, idx1, this_lun);
+               }
+               if (!CAM_LUN_ONLY_32BITS(old, idx1))
+                       continue;
+
                if (xpt_create_path(&tp, NULL, xpt_path_path_id(path),
                    xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) {
                        xpt_async(AC_LOST_DEVICE, tp, NULL);
@@ -2013,7 +2014,7 @@ scsi_scan_bus(struct cam_periph *periph,
                mtx_lock(mtx);
                mtx_lock(&target->luns_mtx);
                if (target->luns) {
-                       uint32_t first;
+                       lun_id_t first;
                        u_int nluns = scsi_4btoul(target->luns->length) / 8;
 
                        /*
@@ -2021,20 +2022,45 @@ scsi_scan_bus(struct cam_periph *periph,
                         * of the list as we've actually just finished probing
                         * it.
                         */
-                       CAM_GET_SIMPLE_LUN(target->luns, 0, first);
+                       CAM_GET_LUN(target->luns, 0, first);
                        if (first == 0 && scan_info->lunindex[target_id] == 0) {
                                scan_info->lunindex[target_id]++;
                        } 
 
+                       /*
+                        * Skip any LUNs that the HBA can't deal with.
+                        */
+                       while (scan_info->lunindex[target_id] < nluns) {
+                               if (scan_info->cpi->hba_misc & PIM_EXTLUNS) {
+                                       CAM_GET_LUN(target->luns,
+                                           scan_info->lunindex[target_id],
+                                           lun_id);
+                                       break;
+                               }
+
+                               /* XXX print warning? */
+                               if (!CAM_LUN_ONLY_32BITS(target->luns,
+                                   scan_info->lunindex[target_id]))
+                                       continue;
+                               if (CAM_CAN_GET_SIMPLE_LUN(target->luns,
+                                   scan_info->lunindex[target_id])) {
+                                       CAM_GET_SIMPLE_LUN(target->luns,
+                                           scan_info->lunindex[target_id],
+                                           lun_id);
+                                       break;
+                               }
+                                       
+                               scan_info->lunindex[target_id]++;
+                       }
+
                        if (scan_info->lunindex[target_id] < nluns) {
-                               CAM_GET_SIMPLE_LUN(target->luns,
-                                   scan_info->lunindex[target_id], lun_id);
                                mtx_unlock(&target->luns_mtx);
                                next_target = 0;
                                CAM_DEBUG(request_ccb->ccb_h.path,
                                    CAM_DEBUG_PROBE,
-                                  ("next lun to try at index %u is %u\n",
-                                  scan_info->lunindex[target_id], lun_id));
+                                  ("next lun to try at index %u is %jx\n",
+                                  scan_info->lunindex[target_id],
+                                  (uintmax_t)lun_id));
                                scan_info->lunindex[target_id]++;
                        } else {
                                mtx_unlock(&target->luns_mtx);

Modified: head/sys/powerpc/pseries/phyp_vscsi.c
==============================================================================
--- head/sys/powerpc/pseries/phyp_vscsi.c       Tue Oct 29 15:07:54 2013        
(r257344)
+++ head/sys/powerpc/pseries/phyp_vscsi.c       Tue Oct 29 15:36:58 2013        
(r257345)
@@ -548,12 +548,6 @@ vscsi_task_management(struct vscsi_softc
        TAILQ_REMOVE(&sc->free_xferq, xp, queue);
        TAILQ_INSERT_TAIL(&sc->active_xferq, xp, queue);
 
-       if (!(ccb->ccb_h.xflags & CAM_EXTLUN_VALID)) {
-               ccb->ccb_h.xflags |= CAM_EXTLUN_VALID;
-               ccb->ccb_h.ext_lun.lun64 = (0x1UL << 62) |
-                   ((uint64_t)ccb->ccb_h.target_lun << 48);
-       }
-
        xp->srp_iu_size = crq.iu_length = sizeof(*cmd);
        err = vmem_alloc(xp->sc->srp_iu_arena, xp->srp_iu_size,
            M_BESTFIT | M_NOWAIT, &xp->srp_iu_offset);
@@ -565,7 +559,7 @@ vscsi_task_management(struct vscsi_softc
        bzero(cmd, xp->srp_iu_size);
        cmd->type = SRP_TSK_MGMT;
        cmd->tag = (uint64_t)xp;
-       cmd->lun = ccb->ccb_h.ext_lun.lun64;
+       cmd->lun = htobe64(CAM_EXTLUN_BYTE_SWIZZLE(ccb->ccb_h.target_lun));
 
        switch (ccb->ccb_h.func_code) {
        case XPT_RESET_DEV:
@@ -608,12 +602,6 @@ vscsi_scsi_command(void *xxp, bus_dma_se
        cdb = (ccb->ccb_h.flags & CAM_CDB_POINTER) ?
            ccb->csio.cdb_io.cdb_ptr : ccb->csio.cdb_io.cdb_bytes;
 
-       if (!(ccb->ccb_h.xflags & CAM_EXTLUN_VALID)) {
-               ccb->ccb_h.xflags |= CAM_EXTLUN_VALID;
-               ccb->ccb_h.ext_lun.lun64 = (0x1UL << 62) |
-                   ((uint64_t)ccb->ccb_h.target_lun << 48);
-       }
-
        /* Command format from Table 20, page 37 of SRP spec */
        crq.iu_length = 48 + ((nsegs > 1) ? 20 : 16) + 
            ((ccb->csio.cdb_len > 16) ? (ccb->csio.cdb_len - 16) : 0);
@@ -635,7 +623,7 @@ vscsi_scsi_command(void *xxp, bus_dma_se
        memcpy(cmd->cdb, cdb, ccb->csio.cdb_len);
 
        cmd->tag = (uint64_t)(xp); /* Let the responder find this again */
-       cmd->lun = ccb->ccb_h.ext_lun.lun64;
+       cmd->lun = htobe64(CAM_EXTLUN_BYTE_SWIZZLE(ccb->ccb_h.target_lun));
 
        if (nsegs > 1) {
                /* Use indirect descriptors */
_______________________________________________
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