Merge tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[platform/kernel/linux-starfive.git] / drivers / scsi / sd.c
index 73e6f5f..a390679 100644 (file)
@@ -122,7 +122,6 @@ static void scsi_disk_release(struct device *cdev);
 static DEFINE_IDA(sd_index_ida);
 
 static struct kmem_cache *sd_cdb_cache;
-static mempool_t *sd_cdb_pool;
 static mempool_t *sd_page_pool;
 static struct lock_class_key sd_bio_compl_lkclass;
 
@@ -1002,13 +1001,13 @@ static void sd_config_write_same(struct scsi_disk *sdkp)
                 * Reporting a maximum number of blocks that is not aligned
                 * on the device physical size would cause a large write same
                 * request to be split into physically unaligned chunks by
-                * __blkdev_issue_write_zeroes() and __blkdev_issue_write_same()
-                * even if the caller of these functions took care to align the
-                * large request. So make sure the maximum reported is aligned
-                * to the device physical block size. This is only an optional
-                * optimization for regular disks, but this is mandatory to
-                * avoid failure of large write same requests directed at
-                * sequential write required zones of host-managed ZBC disks.
+                * __blkdev_issue_write_zeroes() even if the caller of this
+                * functions took care to align the large request. So make sure
+                * the maximum reported is aligned to the device physical block
+                * size. This is only an optional optimization for regular
+                * disks, but this is mandatory to avoid failure of large write
+                * same requests directed at sequential write required zones of
+                * host-managed ZBC disks.
                 */
                sdkp->max_ws_blocks =
                        round_down(sdkp->max_ws_blocks,
@@ -1017,68 +1016,10 @@ static void sd_config_write_same(struct scsi_disk *sdkp)
        }
 
 out:
-       blk_queue_max_write_same_sectors(q, sdkp->max_ws_blocks *
-                                        (logical_block_size >> 9));
        blk_queue_max_write_zeroes_sectors(q, sdkp->max_ws_blocks *
                                         (logical_block_size >> 9));
 }
 
-/**
- * sd_setup_write_same_cmnd - write the same data to multiple blocks
- * @cmd: command to prepare
- *
- * Will set up either WRITE SAME(10) or WRITE SAME(16) depending on
- * the preference indicated by the target device.
- **/
-static blk_status_t sd_setup_write_same_cmnd(struct scsi_cmnd *cmd)
-{
-       struct request *rq = scsi_cmd_to_rq(cmd);
-       struct scsi_device *sdp = cmd->device;
-       struct scsi_disk *sdkp = scsi_disk(rq->q->disk);
-       struct bio *bio = rq->bio;
-       u64 lba = sectors_to_logical(sdp, blk_rq_pos(rq));
-       u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq));
-       blk_status_t ret;
-
-       if (sdkp->device->no_write_same)
-               return BLK_STS_TARGET;
-
-       BUG_ON(bio_offset(bio) || bio_iovec(bio).bv_len != sdp->sector_size);
-
-       rq->timeout = SD_WRITE_SAME_TIMEOUT;
-
-       if (sdkp->ws16 || lba > 0xffffffff || nr_blocks > 0xffff) {
-               cmd->cmd_len = 16;
-               cmd->cmnd[0] = WRITE_SAME_16;
-               put_unaligned_be64(lba, &cmd->cmnd[2]);
-               put_unaligned_be32(nr_blocks, &cmd->cmnd[10]);
-       } else {
-               cmd->cmd_len = 10;
-               cmd->cmnd[0] = WRITE_SAME;
-               put_unaligned_be32(lba, &cmd->cmnd[2]);
-               put_unaligned_be16(nr_blocks, &cmd->cmnd[7]);
-       }
-
-       cmd->transfersize = sdp->sector_size;
-       cmd->allowed = sdkp->max_retries;
-
-       /*
-        * For WRITE SAME the data transferred via the DATA OUT buffer is
-        * different from the amount of data actually written to the target.
-        *
-        * We set up __data_len to the amount of data transferred via the
-        * DATA OUT buffer so that blk_rq_map_sg sets up the proper S/G list
-        * to transfer a single sector of data first, but then reset it to
-        * the amount of data to be written right after so that the I/O path
-        * knows how much to actually write.
-        */
-       rq->__data_len = sdp->sector_size;
-       ret = scsi_alloc_sgtables(cmd);
-       rq->__data_len = blk_rq_bytes(rq);
-
-       return ret;
-}
-
 static blk_status_t sd_setup_flush_cmnd(struct scsi_cmnd *cmd)
 {
        struct request *rq = scsi_cmd_to_rq(cmd);
@@ -1100,13 +1041,7 @@ static blk_status_t sd_setup_rw32_cmnd(struct scsi_cmnd *cmd, bool write,
                                       sector_t lba, unsigned int nr_blocks,
                                       unsigned char flags)
 {
-       cmd->cmnd = mempool_alloc(sd_cdb_pool, GFP_ATOMIC);
-       if (unlikely(cmd->cmnd == NULL))
-               return BLK_STS_RESOURCE;
-
        cmd->cmd_len = SD_EXT_CDB_SIZE;
-       memset(cmd->cmnd, 0, cmd->cmd_len);
-
        cmd->cmnd[0]  = VARIABLE_LENGTH_CMD;
        cmd->cmnd[7]  = 0x18; /* Additional CDB len */
        cmd->cmnd[9]  = write ? WRITE_32 : READ_32;
@@ -1311,8 +1246,6 @@ static blk_status_t sd_init_command(struct scsi_cmnd *cmd)
                }
        case REQ_OP_WRITE_ZEROES:
                return sd_setup_write_zeroes_cmnd(cmd);
-       case REQ_OP_WRITE_SAME:
-               return sd_setup_write_same_cmnd(cmd);
        case REQ_OP_FLUSH:
                return sd_setup_flush_cmnd(cmd);
        case REQ_OP_READ:
@@ -1340,17 +1273,9 @@ static blk_status_t sd_init_command(struct scsi_cmnd *cmd)
 static void sd_uninit_command(struct scsi_cmnd *SCpnt)
 {
        struct request *rq = scsi_cmd_to_rq(SCpnt);
-       u8 *cmnd;
 
        if (rq->rq_flags & RQF_SPECIAL_PAYLOAD)
                mempool_free(rq->special_vec.bv_page, sd_page_pool);
-
-       if (SCpnt->cmnd != scsi_req(rq)->cmd) {
-               cmnd = SCpnt->cmnd;
-               SCpnt->cmnd = NULL;
-               SCpnt->cmd_len = 0;
-               mempool_free(cmnd, sd_cdb_pool);
-       }
 }
 
 static bool sd_need_revalidate(struct block_device *bdev,
@@ -2012,7 +1937,6 @@ static int sd_done(struct scsi_cmnd *SCpnt)
        switch (req_op(req)) {
        case REQ_OP_DISCARD:
        case REQ_OP_WRITE_ZEROES:
-       case REQ_OP_WRITE_SAME:
        case REQ_OP_ZONE_RESET:
        case REQ_OP_ZONE_RESET_ALL:
        case REQ_OP_ZONE_OPEN:
@@ -3691,7 +3615,8 @@ static int sd_suspend_common(struct device *dev, bool ignore_stop_errors)
                return 0;
 
        if (sdkp->WCE && sdkp->media_present) {
-               sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n");
+               if (!sdkp->device->silence_suspend)
+                       sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n");
                ret = sd_sync_cache(sdkp, &sshdr);
 
                if (ret) {
@@ -3713,7 +3638,8 @@ static int sd_suspend_common(struct device *dev, bool ignore_stop_errors)
        }
 
        if (sdkp->device->manage_start_stop) {
-               sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
+               if (!sdkp->device->silence_suspend)
+                       sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
                /* an error is not worth aborting a system sleep */
                ret = sd_start_stop_device(sdkp, 0);
                if (ignore_stop_errors)
@@ -3819,18 +3745,11 @@ static int __init init_sd(void)
                goto err_out_class;
        }
 
-       sd_cdb_pool = mempool_create_slab_pool(SD_MEMPOOL_SIZE, sd_cdb_cache);
-       if (!sd_cdb_pool) {
-               printk(KERN_ERR "sd: can't init extended cdb pool\n");
-               err = -ENOMEM;
-               goto err_out_cache;
-       }
-
        sd_page_pool = mempool_create_page_pool(SD_MEMPOOL_SIZE, 0);
        if (!sd_page_pool) {
                printk(KERN_ERR "sd: can't init discard page pool\n");
                err = -ENOMEM;
-               goto err_out_ppool;
+               goto err_out_cache;
        }
 
        err = scsi_register_driver(&sd_template.gendrv);
@@ -3842,9 +3761,6 @@ static int __init init_sd(void)
 err_out_driver:
        mempool_destroy(sd_page_pool);
 
-err_out_ppool:
-       mempool_destroy(sd_cdb_pool);
-
 err_out_cache:
        kmem_cache_destroy(sd_cdb_cache);
 
@@ -3868,7 +3784,6 @@ static void __exit exit_sd(void)
        SCSI_LOG_HLQUEUE(3, printk("exit_sd: exiting sd driver\n"));
 
        scsi_unregister_driver(&sd_template.gendrv);
-       mempool_destroy(sd_cdb_pool);
        mempool_destroy(sd_page_pool);
        kmem_cache_destroy(sd_cdb_cache);