aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-scsi.c
diff options
context:
space:
mode:
authorAlbert Lee <albertcc@tw.ibm.com>2005-10-04 08:47:43 -0400
committerJeff Garzik <jgarzik@pobox.com>2005-10-04 08:47:43 -0400
commit3aef52311bcb1f88aa5c786302f1ae14a787f61e (patch)
tree12e62f0736c6678e0819543722b66f6813080190 /drivers/scsi/libata-scsi.c
parentc187c4b58a9caff660a4c8ae39d0def88cc449af (diff)
[libata scsi] tidy up SCSI lba and xfer len calculations
move the redundant SCSI lba and transfer length calculation code from ata_scsi_verify_xlat() and ata_scsi_rw_xlat() to common functions.
Diffstat (limited to 'drivers/scsi/libata-scsi.c')
-rw-r--r--drivers/scsi/libata-scsi.c179
1 files changed, 115 insertions, 64 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index d67c3fc98f7b..22434e0d4e75 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -488,6 +488,99 @@ static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
488} 488}
489 489
490/** 490/**
491 * scsi_6_lba_len - Get LBA and transfer length
492 * @scsicmd: SCSI command to translate
493 *
494 * Calculate LBA and transfer length for 6-byte commands.
495 *
496 * RETURNS:
497 * @plba: the LBA
498 * @plen: the transfer length
499 */
500
501static void scsi_6_lba_len(u8 *scsicmd, u64 *plba, u32 *plen)
502{
503 u64 lba = 0;
504 u32 len = 0;
505
506 VPRINTK("six-byte command\n");
507
508 lba |= ((u64)scsicmd[2]) << 8;
509 lba |= ((u64)scsicmd[3]);
510
511 len |= ((u32)scsicmd[4]);
512
513 *plba = lba;
514 *plen = len;
515}
516
517/**
518 * scsi_10_lba_len - Get LBA and transfer length
519 * @scsicmd: SCSI command to translate
520 *
521 * Calculate LBA and transfer length for 10-byte commands.
522 *
523 * RETURNS:
524 * @plba: the LBA
525 * @plen: the transfer length
526 */
527
528static void scsi_10_lba_len(u8 *scsicmd, u64 *plba, u32 *plen)
529{
530 u64 lba = 0;
531 u32 len = 0;
532
533 VPRINTK("ten-byte command\n");
534
535 lba |= ((u64)scsicmd[2]) << 24;
536 lba |= ((u64)scsicmd[3]) << 16;
537 lba |= ((u64)scsicmd[4]) << 8;
538 lba |= ((u64)scsicmd[5]);
539
540 len |= ((u32)scsicmd[7]) << 8;
541 len |= ((u32)scsicmd[8]);
542
543 *plba = lba;
544 *plen = len;
545}
546
547/**
548 * scsi_16_lba_len - Get LBA and transfer length
549 * @scsicmd: SCSI command to translate
550 *
551 * Calculate LBA and transfer length for 16-byte commands.
552 *
553 * RETURNS:
554 * @plba: the LBA
555 * @plen: the transfer length
556 */
557
558static void scsi_16_lba_len(u8 *scsicmd, u64 *plba, u32 *plen)
559{
560 u64 lba = 0;
561 u32 len = 0;
562
563 VPRINTK("sixteen-byte command\n");
564
565 lba |= ((u64)scsicmd[2]) << 56;
566 lba |= ((u64)scsicmd[3]) << 48;
567 lba |= ((u64)scsicmd[4]) << 40;
568 lba |= ((u64)scsicmd[5]) << 32;
569 lba |= ((u64)scsicmd[6]) << 24;
570 lba |= ((u64)scsicmd[7]) << 16;
571 lba |= ((u64)scsicmd[8]) << 8;
572 lba |= ((u64)scsicmd[9]);
573
574 len |= ((u32)scsicmd[10]) << 24;
575 len |= ((u32)scsicmd[11]) << 16;
576 len |= ((u32)scsicmd[12]) << 8;
577 len |= ((u32)scsicmd[13]);
578
579 *plba = lba;
580 *plen = len;
581}
582
583/**
491 * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one 584 * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one
492 * @qc: Storage for translated ATA taskfile 585 * @qc: Storage for translated ATA taskfile
493 * @scsicmd: SCSI command to translate 586 * @scsicmd: SCSI command to translate
@@ -508,38 +601,16 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
508 unsigned int lba = tf->flags & ATA_TFLAG_LBA; 601 unsigned int lba = tf->flags & ATA_TFLAG_LBA;
509 unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48; 602 unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48;
510 u64 dev_sectors = qc->dev->n_sectors; 603 u64 dev_sectors = qc->dev->n_sectors;
511 u64 block = 0; 604 u64 block;
512 u32 n_block = 0; 605 u32 n_block;
513 606
514 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 607 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
515 tf->protocol = ATA_PROT_NODATA; 608 tf->protocol = ATA_PROT_NODATA;
516 609
517 if (scsicmd[0] == VERIFY) { 610 if (scsicmd[0] == VERIFY)
518 block |= ((u64)scsicmd[2]) << 24; 611 scsi_10_lba_len(scsicmd, &block, &n_block);
519 block |= ((u64)scsicmd[3]) << 16; 612 else if (scsicmd[0] == VERIFY_16)
520 block |= ((u64)scsicmd[4]) << 8; 613 scsi_16_lba_len(scsicmd, &block, &n_block);
521 block |= ((u64)scsicmd[5]);
522
523 n_block |= ((u32)scsicmd[7]) << 8;
524 n_block |= ((u32)scsicmd[8]);
525 }
526
527 else if (scsicmd[0] == VERIFY_16) {
528 block |= ((u64)scsicmd[2]) << 56;
529 block |= ((u64)scsicmd[3]) << 48;
530 block |= ((u64)scsicmd[4]) << 40;
531 block |= ((u64)scsicmd[5]) << 32;
532 block |= ((u64)scsicmd[6]) << 24;
533 block |= ((u64)scsicmd[7]) << 16;
534 block |= ((u64)scsicmd[8]) << 8;
535 block |= ((u64)scsicmd[9]);
536
537 n_block |= ((u32)scsicmd[10]) << 24;
538 n_block |= ((u32)scsicmd[11]) << 16;
539 n_block |= ((u32)scsicmd[12]) << 8;
540 n_block |= ((u32)scsicmd[13]);
541 }
542
543 else 614 else
544 return 1; 615 return 1;
545 616
@@ -636,8 +707,8 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
636 struct ata_device *dev = qc->dev; 707 struct ata_device *dev = qc->dev;
637 unsigned int lba = tf->flags & ATA_TFLAG_LBA; 708 unsigned int lba = tf->flags & ATA_TFLAG_LBA;
638 unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48; 709 unsigned int lba48 = tf->flags & ATA_TFLAG_LBA48;
639 u64 block = 0; 710 u64 block;
640 u32 n_block = 0; 711 u32 n_block;
641 712
642 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 713 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
643 tf->protocol = qc->dev->xfer_protocol; 714 tf->protocol = qc->dev->xfer_protocol;
@@ -651,46 +722,26 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, u8 *scsicmd)
651 } 722 }
652 723
653 /* Calculate the SCSI LBA and transfer length. */ 724 /* Calculate the SCSI LBA and transfer length. */
654 if (scsicmd[0] == READ_10 || scsicmd[0] == WRITE_10) { 725 switch (scsicmd[0]) {
655 block |= ((u64)scsicmd[2]) << 24; 726 case READ_10:
656 block |= ((u64)scsicmd[3]) << 16; 727 case WRITE_10:
657 block |= ((u64)scsicmd[4]) << 8; 728 scsi_10_lba_len(scsicmd, &block, &n_block);
658 block |= ((u64)scsicmd[5]); 729 break;
659 730 case READ_6:
660 n_block |= ((u32)scsicmd[7]) << 8; 731 case WRITE_6:
661 n_block |= ((u32)scsicmd[8]); 732 scsi_6_lba_len(scsicmd, &block, &n_block);
662
663 VPRINTK("ten-byte command\n");
664 } else if (scsicmd[0] == READ_6 || scsicmd[0] == WRITE_6) {
665 block |= ((u64)scsicmd[2]) << 8;
666 block |= ((u64)scsicmd[3]);
667
668 n_block |= ((u32)scsicmd[4]);
669 733
670 /* for 6-byte r/w commands, transfer length 0 734 /* for 6-byte r/w commands, transfer length 0
671 * means 256 blocks of data, not 0 block. 735 * means 256 blocks of data, not 0 block.
672 */ 736 */
673 if (!n_block) 737 if (!n_block)
674 n_block = 256; 738 n_block = 256;
675 739 break;
676 VPRINTK("six-byte command\n"); 740 case READ_16:
677 } else if (scsicmd[0] == READ_16 || scsicmd[0] == WRITE_16) { 741 case WRITE_16:
678 block |= ((u64)scsicmd[2]) << 56; 742 scsi_16_lba_len(scsicmd, &block, &n_block);
679 block |= ((u64)scsicmd[3]) << 48; 743 break;
680 block |= ((u64)scsicmd[4]) << 40; 744 default:
681 block |= ((u64)scsicmd[5]) << 32;
682 block |= ((u64)scsicmd[6]) << 24;
683 block |= ((u64)scsicmd[7]) << 16;
684 block |= ((u64)scsicmd[8]) << 8;
685 block |= ((u64)scsicmd[9]);
686
687 n_block |= ((u32)scsicmd[10]) << 24;
688 n_block |= ((u32)scsicmd[11]) << 16;
689 n_block |= ((u32)scsicmd[12]) << 8;
690 n_block |= ((u32)scsicmd[13]);
691
692 VPRINTK("sixteen-byte command\n");
693 } else {
694 DPRINTK("no-byte command\n"); 745 DPRINTK("no-byte command\n");
695 return 1; 746 return 1;
696 } 747 }