]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/scsi/scsi_scan.c
Move code that is used both by initiator and target drivers
[karo-tx-linux.git] / drivers / scsi / scsi_scan.c
index 9c0a520d933c91eaaf793a259ba099d87c8d3176..f9f3f8203d42709d9957aa27b1be471acb612046 100644 (file)
@@ -280,7 +280,8 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
                                    sdev->host->cmd_per_lun, shost->bqt,
                                    shost->hostt->tag_alloc_policy);
        }
-       scsi_change_queue_depth(sdev, sdev->host->cmd_per_lun);
+       scsi_change_queue_depth(sdev, sdev->host->cmd_per_lun ?
+                                       sdev->host->cmd_per_lun : 1);
 
        scsi_sysfs_device_initialize(sdev);
 
@@ -897,6 +898,12 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
         */
        if (*bflags & BLIST_MAX_512)
                blk_queue_max_hw_sectors(sdev->request_queue, 512);
+       /*
+        * Max 1024 sector transfer length for targets that report incorrect
+        * max/optimal lengths and relied on the old block layer safe default
+        */
+       else if (*bflags & BLIST_MAX_1024)
+               blk_queue_max_hw_sectors(sdev->request_queue, 1024);
 
        /*
         * Some devices may not want to have a start command automatically
@@ -1262,68 +1269,6 @@ static void scsi_sequential_lun_scan(struct scsi_target *starget,
                        return;
 }
 
-/**
- * scsilun_to_int - convert a scsi_lun to an int
- * @scsilun:   struct scsi_lun to be converted.
- *
- * Description:
- *     Convert @scsilun from a struct scsi_lun to a four byte host byte-ordered
- *     integer, and return the result. The caller must check for
- *     truncation before using this function.
- *
- * Notes:
- *     For a description of the LUN format, post SCSI-3 see the SCSI
- *     Architecture Model, for SCSI-3 see the SCSI Controller Commands.
- *
- *     Given a struct scsi_lun of: d2 04 0b 03 00 00 00 00, this function
- *     returns the integer: 0x0b03d204
- *
- *     This encoding will return a standard integer LUN for LUNs smaller
- *     than 256, which typically use a single level LUN structure with
- *     addressing method 0.
- **/
-u64 scsilun_to_int(struct scsi_lun *scsilun)
-{
-       int i;
-       u64 lun;
-
-       lun = 0;
-       for (i = 0; i < sizeof(lun); i += 2)
-               lun = lun | (((u64)scsilun->scsi_lun[i] << ((i + 1) * 8)) |
-                            ((u64)scsilun->scsi_lun[i + 1] << (i * 8)));
-       return lun;
-}
-EXPORT_SYMBOL(scsilun_to_int);
-
-/**
- * int_to_scsilun - reverts an int into a scsi_lun
- * @lun:        integer to be reverted
- * @scsilun:   struct scsi_lun to be set.
- *
- * Description:
- *     Reverts the functionality of the scsilun_to_int, which packed
- *     an 8-byte lun value into an int. This routine unpacks the int
- *     back into the lun value.
- *
- * Notes:
- *     Given an integer : 0x0b03d204,  this function returns a
- *     struct scsi_lun of: d2 04 0b 03 00 00 00 00
- *
- **/
-void int_to_scsilun(u64 lun, struct scsi_lun *scsilun)
-{
-       int i;
-
-       memset(scsilun->scsi_lun, 0, sizeof(scsilun->scsi_lun));
-
-       for (i = 0; i < sizeof(lun); i += 2) {
-               scsilun->scsi_lun[i] = (lun >> 8) & 0xFF;
-               scsilun->scsi_lun[i+1] = lun & 0xFF;
-               lun = lun >> 16;
-       }
-}
-EXPORT_SYMBOL(int_to_scsilun);
-
 /**
  * scsi_report_lun_scan - Scan using SCSI REPORT LUN results
  * @starget: which target
@@ -1570,16 +1515,15 @@ EXPORT_SYMBOL(scsi_add_device);
 
 void scsi_rescan_device(struct device *dev)
 {
-       if (!dev->driver)
-               return;
-
-       if (try_module_get(dev->driver->owner)) {
+       device_lock(dev);
+       if (dev->driver && try_module_get(dev->driver->owner)) {
                struct scsi_driver *drv = to_scsi_driver(dev->driver);
 
                if (drv->rescan)
                        drv->rescan(dev);
                module_put(dev->driver->owner);
        }
+       device_unlock(dev);
 }
 EXPORT_SYMBOL(scsi_rescan_device);