aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sr.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/sr.c')
-rw-r--r--drivers/scsi/sr.c75
1 files changed, 13 insertions, 62 deletions
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 2f259f249522..ce63fc8312dc 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -50,10 +50,10 @@
50#include <scsi/scsi_dbg.h> 50#include <scsi/scsi_dbg.h>
51#include <scsi/scsi_device.h> 51#include <scsi/scsi_device.h>
52#include <scsi/scsi_driver.h> 52#include <scsi/scsi_driver.h>
53#include <scsi/scsi_cmnd.h>
53#include <scsi/scsi_eh.h> 54#include <scsi/scsi_eh.h>
54#include <scsi/scsi_host.h> 55#include <scsi/scsi_host.h>
55#include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */ 56#include <scsi/scsi_ioctl.h> /* For the door lock/unlock commands */
56#include <scsi/scsi_request.h>
57 57
58#include "scsi_logging.h" 58#include "scsi_logging.h"
59#include "sr.h" 59#include "sr.h"
@@ -199,15 +199,7 @@ int sr_media_change(struct cdrom_device_info *cdi, int slot)
199 /* check multisession offset etc */ 199 /* check multisession offset etc */
200 sr_cd_check(cdi); 200 sr_cd_check(cdi);
201 201
202 /* 202 get_sectorsize(cd);
203 * If the disk changed, the capacity will now be different,
204 * so we force a re-read of this information
205 * Force 2048 for the sector size so that filesystems won't
206 * be trying to use something that is too small if the disc
207 * has changed.
208 */
209 cd->needs_sector_size = 1;
210 cd->device->sector_size = 2048;
211 } 203 }
212 return retval; 204 return retval;
213} 205}
@@ -538,13 +530,6 @@ static int sr_open(struct cdrom_device_info *cdi, int purpose)
538 if (!scsi_block_when_processing_errors(sdev)) 530 if (!scsi_block_when_processing_errors(sdev))
539 goto error_out; 531 goto error_out;
540 532
541 /*
542 * If this device did not have media in the drive at boot time, then
543 * we would have been unable to get the sector size. Check to see if
544 * this is the case, and try again.
545 */
546 if (cd->needs_sector_size)
547 get_sectorsize(cd);
548 return 0; 533 return 0;
549 534
550error_out: 535error_out:
@@ -604,7 +589,6 @@ static int sr_probe(struct device *dev)
604 cd->driver = &sr_template; 589 cd->driver = &sr_template;
605 cd->disk = disk; 590 cd->disk = disk;
606 cd->capacity = 0x1fffff; 591 cd->capacity = 0x1fffff;
607 cd->needs_sector_size = 1;
608 cd->device->changed = 1; /* force recheck CD type */ 592 cd->device->changed = 1; /* force recheck CD type */
609 cd->use = 1; 593 cd->use = 1;
610 cd->readcd_known = 0; 594 cd->readcd_known = 0;
@@ -658,43 +642,30 @@ static void get_sectorsize(struct scsi_cd *cd)
658 unsigned char *buffer; 642 unsigned char *buffer;
659 int the_result, retries = 3; 643 int the_result, retries = 3;
660 int sector_size; 644 int sector_size;
661 struct scsi_request *SRpnt = NULL;
662 request_queue_t *queue; 645 request_queue_t *queue;
663 646
664 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA); 647 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
665 if (!buffer) 648 if (!buffer)
666 goto Enomem; 649 goto Enomem;
667 SRpnt = scsi_allocate_request(cd->device, GFP_KERNEL);
668 if (!SRpnt)
669 goto Enomem;
670 650
671 do { 651 do {
672 cmd[0] = READ_CAPACITY; 652 cmd[0] = READ_CAPACITY;
673 memset((void *) &cmd[1], 0, 9); 653 memset((void *) &cmd[1], 0, 9);
674 /* Mark as really busy */
675 SRpnt->sr_request->rq_status = RQ_SCSI_BUSY;
676 SRpnt->sr_cmd_len = 0;
677
678 memset(buffer, 0, 8); 654 memset(buffer, 0, 8);
679 655
680 /* Do the command and wait.. */ 656 /* Do the command and wait.. */
681 SRpnt->sr_data_direction = DMA_FROM_DEVICE; 657 the_result = scsi_execute_req(cd->device, cmd, DMA_FROM_DEVICE,
682 scsi_wait_req(SRpnt, (void *) cmd, (void *) buffer, 658 buffer, 8, NULL, SR_TIMEOUT,
683 8, SR_TIMEOUT, MAX_RETRIES); 659 MAX_RETRIES);
684 660
685 the_result = SRpnt->sr_result;
686 retries--; 661 retries--;
687 662
688 } while (the_result && retries); 663 } while (the_result && retries);
689 664
690 665
691 scsi_release_request(SRpnt);
692 SRpnt = NULL;
693
694 if (the_result) { 666 if (the_result) {
695 cd->capacity = 0x1fffff; 667 cd->capacity = 0x1fffff;
696 sector_size = 2048; /* A guess, just in case */ 668 sector_size = 2048; /* A guess, just in case */
697 cd->needs_sector_size = 1;
698 } else { 669 } else {
699#if 0 670#if 0
700 if (cdrom_get_last_written(&cd->cdi, 671 if (cdrom_get_last_written(&cd->cdi,
@@ -727,7 +698,6 @@ static void get_sectorsize(struct scsi_cd *cd)
727 printk("%s: unsupported sector size %d.\n", 698 printk("%s: unsupported sector size %d.\n",
728 cd->cdi.name, sector_size); 699 cd->cdi.name, sector_size);
729 cd->capacity = 0; 700 cd->capacity = 0;
730 cd->needs_sector_size = 1;
731 } 701 }
732 702
733 cd->device->sector_size = sector_size; 703 cd->device->sector_size = sector_size;
@@ -736,7 +706,6 @@ static void get_sectorsize(struct scsi_cd *cd)
736 * Add this so that we have the ability to correctly gauge 706 * Add this so that we have the ability to correctly gauge
737 * what the device is capable of. 707 * what the device is capable of.
738 */ 708 */
739 cd->needs_sector_size = 0;
740 set_capacity(cd->disk, cd->capacity); 709 set_capacity(cd->disk, cd->capacity);
741 } 710 }
742 711
@@ -748,10 +717,7 @@ out:
748 717
749Enomem: 718Enomem:
750 cd->capacity = 0x1fffff; 719 cd->capacity = 0x1fffff;
751 sector_size = 2048; /* A guess, just in case */ 720 cd->device->sector_size = 2048; /* A guess, just in case */
752 cd->needs_sector_size = 1;
753 if (SRpnt)
754 scsi_release_request(SRpnt);
755 goto out; 721 goto out;
756} 722}
757 723
@@ -759,8 +725,8 @@ static void get_capabilities(struct scsi_cd *cd)
759{ 725{
760 unsigned char *buffer; 726 unsigned char *buffer;
761 struct scsi_mode_data data; 727 struct scsi_mode_data data;
762 struct scsi_request *SRpnt;
763 unsigned char cmd[MAX_COMMAND_SIZE]; 728 unsigned char cmd[MAX_COMMAND_SIZE];
729 struct scsi_sense_hdr sshdr;
764 unsigned int the_result; 730 unsigned int the_result;
765 int retries, rc, n; 731 int retries, rc, n;
766 732
@@ -776,19 +742,11 @@ static void get_capabilities(struct scsi_cd *cd)
776 "" 742 ""
777 }; 743 };
778 744
779 /* allocate a request for the TEST_UNIT_READY */
780 SRpnt = scsi_allocate_request(cd->device, GFP_KERNEL);
781 if (!SRpnt) {
782 printk(KERN_WARNING "(get_capabilities:) Request allocation "
783 "failure.\n");
784 return;
785 }
786 745
787 /* allocate transfer buffer */ 746 /* allocate transfer buffer */
788 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA); 747 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
789 if (!buffer) { 748 if (!buffer) {
790 printk(KERN_ERR "sr: out of memory.\n"); 749 printk(KERN_ERR "sr: out of memory.\n");
791 scsi_release_request(SRpnt);
792 return; 750 return;
793 } 751 }
794 752
@@ -800,24 +758,19 @@ static void get_capabilities(struct scsi_cd *cd)
800 memset((void *)cmd, 0, MAX_COMMAND_SIZE); 758 memset((void *)cmd, 0, MAX_COMMAND_SIZE);
801 cmd[0] = TEST_UNIT_READY; 759 cmd[0] = TEST_UNIT_READY;
802 760
803 SRpnt->sr_cmd_len = 0; 761 the_result = scsi_execute_req (cd->device, cmd, DMA_NONE, NULL,
804 SRpnt->sr_sense_buffer[0] = 0; 762 0, &sshdr, SR_TIMEOUT,
805 SRpnt->sr_sense_buffer[2] = 0; 763 MAX_RETRIES);
806 SRpnt->sr_data_direction = DMA_NONE;
807
808 scsi_wait_req (SRpnt, (void *) cmd, buffer,
809 0, SR_TIMEOUT, MAX_RETRIES);
810 764
811 the_result = SRpnt->sr_result;
812 retries++; 765 retries++;
813 } while (retries < 5 && 766 } while (retries < 5 &&
814 (!scsi_status_is_good(the_result) || 767 (!scsi_status_is_good(the_result) ||
815 ((driver_byte(the_result) & DRIVER_SENSE) && 768 (scsi_sense_valid(&sshdr) &&
816 SRpnt->sr_sense_buffer[2] == UNIT_ATTENTION))); 769 sshdr.sense_key == UNIT_ATTENTION)));
817 770
818 /* ask for mode page 0x2a */ 771 /* ask for mode page 0x2a */
819 rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128, 772 rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128,
820 SR_TIMEOUT, 3, &data); 773 SR_TIMEOUT, 3, &data, NULL);
821 774
822 if (!scsi_status_is_good(rc)) { 775 if (!scsi_status_is_good(rc)) {
823 /* failed, drive doesn't have capabilities mode page */ 776 /* failed, drive doesn't have capabilities mode page */
@@ -825,7 +778,6 @@ static void get_capabilities(struct scsi_cd *cd)
825 cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R | 778 cd->cdi.mask |= (CDC_CD_R | CDC_CD_RW | CDC_DVD_R |
826 CDC_DVD | CDC_DVD_RAM | 779 CDC_DVD | CDC_DVD_RAM |
827 CDC_SELECT_DISC | CDC_SELECT_SPEED); 780 CDC_SELECT_DISC | CDC_SELECT_SPEED);
828 scsi_release_request(SRpnt);
829 kfree(buffer); 781 kfree(buffer);
830 printk("%s: scsi-1 drive\n", cd->cdi.name); 782 printk("%s: scsi-1 drive\n", cd->cdi.name);
831 return; 783 return;
@@ -885,7 +837,6 @@ static void get_capabilities(struct scsi_cd *cd)
885 cd->device->writeable = 1; 837 cd->device->writeable = 1;
886 } 838 }
887 839
888 scsi_release_request(SRpnt);
889 kfree(buffer); 840 kfree(buffer);
890} 841}
891 842