aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/sd.c5
-rw-r--r--drivers/scsi/sd.h2
-rw-r--r--drivers/scsi/sd_dif.c25
3 files changed, 9 insertions, 23 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 4df73e52a4f9..9f7fc39891b8 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -804,9 +804,8 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
804 SCpnt->cmnd[0] = WRITE_6; 804 SCpnt->cmnd[0] = WRITE_6;
805 SCpnt->sc_data_direction = DMA_TO_DEVICE; 805 SCpnt->sc_data_direction = DMA_TO_DEVICE;
806 806
807 if (blk_integrity_rq(rq) && 807 if (blk_integrity_rq(rq))
808 sd_dif_prepare(rq, block, sdp->sector_size) == -EIO) 808 sd_dif_prepare(rq, block, sdp->sector_size);
809 goto out;
810 809
811 } else if (rq_data_dir(rq) == READ) { 810 } else if (rq_data_dir(rq) == READ) {
812 SCpnt->cmnd[0] = READ_6; 811 SCpnt->cmnd[0] = READ_6;
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index f703f4827b6f..47c52a6d733c 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -156,7 +156,7 @@ struct sd_dif_tuple {
156#ifdef CONFIG_BLK_DEV_INTEGRITY 156#ifdef CONFIG_BLK_DEV_INTEGRITY
157 157
158extern void sd_dif_config_host(struct scsi_disk *); 158extern void sd_dif_config_host(struct scsi_disk *);
159extern int sd_dif_prepare(struct request *rq, sector_t, unsigned int); 159extern void sd_dif_prepare(struct request *rq, sector_t, unsigned int);
160extern void sd_dif_complete(struct scsi_cmnd *, unsigned int); 160extern void sd_dif_complete(struct scsi_cmnd *, unsigned int);
161 161
162#else /* CONFIG_BLK_DEV_INTEGRITY */ 162#else /* CONFIG_BLK_DEV_INTEGRITY */
diff --git a/drivers/scsi/sd_dif.c b/drivers/scsi/sd_dif.c
index e52d5bc42bc4..04998f36e507 100644
--- a/drivers/scsi/sd_dif.c
+++ b/drivers/scsi/sd_dif.c
@@ -366,7 +366,8 @@ void sd_dif_config_host(struct scsi_disk *sdkp)
366 * 366 *
367 * Type 3 does not have a reference tag so no remapping is required. 367 * Type 3 does not have a reference tag so no remapping is required.
368 */ 368 */
369int sd_dif_prepare(struct request *rq, sector_t hw_sector, unsigned int sector_sz) 369void sd_dif_prepare(struct request *rq, sector_t hw_sector,
370 unsigned int sector_sz)
370{ 371{
371 const int tuple_sz = sizeof(struct sd_dif_tuple); 372 const int tuple_sz = sizeof(struct sd_dif_tuple);
372 struct bio *bio; 373 struct bio *bio;
@@ -378,7 +379,7 @@ int sd_dif_prepare(struct request *rq, sector_t hw_sector, unsigned int sector_s
378 sdkp = rq->bio->bi_bdev->bd_disk->private_data; 379 sdkp = rq->bio->bi_bdev->bd_disk->private_data;
379 380
380 if (sdkp->protection_type == SD_DIF_TYPE3_PROTECTION) 381 if (sdkp->protection_type == SD_DIF_TYPE3_PROTECTION)
381 return 0; 382 return;
382 383
383 phys = hw_sector & 0xffffffff; 384 phys = hw_sector & 0xffffffff;
384 385
@@ -397,10 +398,9 @@ int sd_dif_prepare(struct request *rq, sector_t hw_sector, unsigned int sector_s
397 398
398 for (j = 0 ; j < iv->bv_len ; j += tuple_sz, sdt++) { 399 for (j = 0 ; j < iv->bv_len ; j += tuple_sz, sdt++) {
399 400
400 if (be32_to_cpu(sdt->ref_tag) != virt) 401 if (be32_to_cpu(sdt->ref_tag) == virt)
401 goto error; 402 sdt->ref_tag = cpu_to_be32(phys);
402 403
403 sdt->ref_tag = cpu_to_be32(phys);
404 virt++; 404 virt++;
405 phys++; 405 phys++;
406 } 406 }
@@ -410,16 +410,6 @@ int sd_dif_prepare(struct request *rq, sector_t hw_sector, unsigned int sector_s
410 410
411 bio->bi_flags |= (1 << BIO_MAPPED_INTEGRITY); 411 bio->bi_flags |= (1 << BIO_MAPPED_INTEGRITY);
412 } 412 }
413
414 return 0;
415
416error:
417 kunmap_atomic(sdt);
418 sd_printk(KERN_ERR, sdkp, "%s: virt %u, phys %u, ref %u, app %4x\n",
419 __func__, virt, phys, be32_to_cpu(sdt->ref_tag),
420 be16_to_cpu(sdt->app_tag));
421
422 return -EILSEQ;
423} 413}
424 414
425/* 415/*
@@ -463,10 +453,7 @@ void sd_dif_complete(struct scsi_cmnd *scmd, unsigned int good_bytes)
463 return; 453 return;
464 } 454 }
465 455
466 if (be32_to_cpu(sdt->ref_tag) != phys && 456 if (be32_to_cpu(sdt->ref_tag) == phys)
467 sdt->app_tag != 0xffff)
468 sdt->ref_tag = 0xffffffff; /* Bad ref */
469 else
470 sdt->ref_tag = cpu_to_be32(virt); 457 sdt->ref_tag = cpu_to_be32(virt);
471 458
472 virt++; 459 virt++;