aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/storage
diff options
context:
space:
mode:
authorMatthew Dharm <mdharm-usb@one-eyed-alien.net>2005-12-05 00:58:52 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-01-04 16:51:41 -0500
commit0dc08a357538de3d93305fbf99348663abdbf2cd (patch)
treed794f54e4ba52ef19e9817562f284736de216b14 /drivers/usb/storage
parentf5b8cb9c91f2f7d54dc3f066db8d4e0f041de79b (diff)
[PATCH] USB Storage: sddr09 cleanups
This is the second of three patches to prepare the sddr09 subdriver for conversion to the Sim-SCSI framework. This patch (as595) updates the code to use standard error values for return codes instead of our special-purpose USB_STOR_TRANSPORT_... codes. The reverse update is then needed in the transport routine, but with the Sim-SCSI framework that routine will go away. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Acked-by: Andries Brouwer <Andries.Brouwer@cwi.nl> Signed-off-by: Matthew Dharm <mdharm-usb@one-eyed-alien.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/storage')
-rw-r--r--drivers/usb/storage/sddr09.c103
1 files changed, 50 insertions, 53 deletions
diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c
index 6c379b6b43d1..760fe9362b6d 100644
--- a/drivers/usb/storage/sddr09.c
+++ b/drivers/usb/storage/sddr09.c
@@ -274,8 +274,11 @@ sddr09_send_command(struct us_data *us,
274 274
275 rc = usb_stor_ctrl_transfer(us, pipe, request, requesttype, 275 rc = usb_stor_ctrl_transfer(us, pipe, request, requesttype,
276 0, 0, xfer_data, xfer_len); 276 0, 0, xfer_data, xfer_len);
277 return (rc == USB_STOR_XFER_GOOD ? USB_STOR_TRANSPORT_GOOD : 277 switch (rc) {
278 USB_STOR_TRANSPORT_ERROR); 278 case USB_STOR_XFER_GOOD: return 0;
279 case USB_STOR_XFER_STALLED: return -EPIPE;
280 default: return -EIO;
281 }
279} 282}
280 283
281static int 284static int
@@ -322,20 +325,12 @@ sddr09_request_sense(struct us_data *us, unsigned char *sensebuf, int buflen) {
322 command[4] = buflen; 325 command[4] = buflen;
323 326
324 result = sddr09_send_scsi_command(us, command, 12); 327 result = sddr09_send_scsi_command(us, command, 12);
325 if (result != USB_STOR_TRANSPORT_GOOD) { 328 if (result)
326 US_DEBUGP("request sense failed\n");
327 return result; 329 return result;
328 }
329 330
330 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 331 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
331 sensebuf, buflen, NULL); 332 sensebuf, buflen, NULL);
332 if (result != USB_STOR_XFER_GOOD) { 333 return (result == USB_STOR_XFER_GOOD ? 0 : -EIO);
333 US_DEBUGP("request sense bulk in failed\n");
334 return USB_STOR_TRANSPORT_ERROR;
335 } else {
336 US_DEBUGP("request sense worked\n");
337 return USB_STOR_TRANSPORT_GOOD;
338 }
339} 334}
340 335
341/* 336/*
@@ -383,7 +378,7 @@ sddr09_readX(struct us_data *us, int x, unsigned long fromaddress,
383 378
384 result = sddr09_send_scsi_command(us, command, 12); 379 result = sddr09_send_scsi_command(us, command, 12);
385 380
386 if (result != USB_STOR_TRANSPORT_GOOD) { 381 if (result) {
387 US_DEBUGP("Result for send_control in sddr09_read2%d %d\n", 382 US_DEBUGP("Result for send_control in sddr09_read2%d %d\n",
388 x, result); 383 x, result);
389 return result; 384 return result;
@@ -395,9 +390,9 @@ sddr09_readX(struct us_data *us, int x, unsigned long fromaddress,
395 if (result != USB_STOR_XFER_GOOD) { 390 if (result != USB_STOR_XFER_GOOD) {
396 US_DEBUGP("Result for bulk_transfer in sddr09_read2%d %d\n", 391 US_DEBUGP("Result for bulk_transfer in sddr09_read2%d %d\n",
397 x, result); 392 x, result);
398 return USB_STOR_TRANSPORT_ERROR; 393 return -EIO;
399 } 394 }
400 return USB_STOR_TRANSPORT_GOOD; 395 return 0;
401} 396}
402 397
403/* 398/*
@@ -511,7 +506,7 @@ sddr09_erase(struct us_data *us, unsigned long Eaddress) {
511 506
512 result = sddr09_send_scsi_command(us, command, 12); 507 result = sddr09_send_scsi_command(us, command, 12);
513 508
514 if (result != USB_STOR_TRANSPORT_GOOD) 509 if (result)
515 US_DEBUGP("Result for send_control in sddr09_erase %d\n", 510 US_DEBUGP("Result for send_control in sddr09_erase %d\n",
516 result); 511 result);
517 512
@@ -569,7 +564,7 @@ sddr09_writeX(struct us_data *us,
569 564
570 result = sddr09_send_scsi_command(us, command, 12); 565 result = sddr09_send_scsi_command(us, command, 12);
571 566
572 if (result != USB_STOR_TRANSPORT_GOOD) { 567 if (result) {
573 US_DEBUGP("Result for send_control in sddr09_writeX %d\n", 568 US_DEBUGP("Result for send_control in sddr09_writeX %d\n",
574 result); 569 result);
575 return result; 570 return result;
@@ -581,9 +576,9 @@ sddr09_writeX(struct us_data *us,
581 if (result != USB_STOR_XFER_GOOD) { 576 if (result != USB_STOR_XFER_GOOD) {
582 US_DEBUGP("Result for bulk_transfer in sddr09_writeX %d\n", 577 US_DEBUGP("Result for bulk_transfer in sddr09_writeX %d\n",
583 result); 578 result);
584 return USB_STOR_TRANSPORT_ERROR; 579 return -EIO;
585 } 580 }
586 return USB_STOR_TRANSPORT_GOOD; 581 return 0;
587} 582}
588 583
589/* erase address, write same address */ 584/* erase address, write same address */
@@ -647,7 +642,7 @@ sddr09_read_sg_test_only(struct us_data *us) {
647 642
648 result = sddr09_send_scsi_command(us, command, 4*nsg+3); 643 result = sddr09_send_scsi_command(us, command, 4*nsg+3);
649 644
650 if (result != USB_STOR_TRANSPORT_GOOD) { 645 if (result) {
651 US_DEBUGP("Result for send_control in sddr09_read_sg %d\n", 646 US_DEBUGP("Result for send_control in sddr09_read_sg %d\n",
652 result); 647 result);
653 return result; 648 return result;
@@ -655,7 +650,7 @@ sddr09_read_sg_test_only(struct us_data *us) {
655 650
656 buf = (unsigned char *) kmalloc(bulklen, GFP_NOIO); 651 buf = (unsigned char *) kmalloc(bulklen, GFP_NOIO);
657 if (!buf) 652 if (!buf)
658 return USB_STOR_TRANSPORT_ERROR; 653 return -ENOMEM;
659 654
660 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 655 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
661 buf, bulklen, NULL); 656 buf, bulklen, NULL);
@@ -663,10 +658,10 @@ sddr09_read_sg_test_only(struct us_data *us) {
663 if (result != USB_STOR_XFER_GOOD) { 658 if (result != USB_STOR_XFER_GOOD) {
664 US_DEBUGP("Result for bulk_transfer in sddr09_read_sg %d\n", 659 US_DEBUGP("Result for bulk_transfer in sddr09_read_sg %d\n",
665 result); 660 result);
666 return USB_STOR_TRANSPORT_ERROR; 661 return -EIO;
667 } 662 }
668 663
669 return USB_STOR_TRANSPORT_GOOD; 664 return 0;
670} 665}
671#endif 666#endif
672 667
@@ -695,14 +690,13 @@ sddr09_read_status(struct us_data *us, unsigned char *status) {
695 command[1] = LUNBITS; 690 command[1] = LUNBITS;
696 691
697 result = sddr09_send_scsi_command(us, command, 12); 692 result = sddr09_send_scsi_command(us, command, 12);
698 if (result != USB_STOR_TRANSPORT_GOOD) 693 if (result)
699 return result; 694 return result;
700 695
701 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 696 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
702 data, 64, NULL); 697 data, 64, NULL);
703 *status = data[0]; 698 *status = data[0];
704 return (result == USB_STOR_XFER_GOOD ? 699 return (result == USB_STOR_XFER_GOOD ? 0 : -EIO);
705 USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR);
706} 700}
707 701
708static int 702static int
@@ -725,7 +719,7 @@ sddr09_read_data(struct us_data *us,
725 buffer = kmalloc(len, GFP_NOIO); 719 buffer = kmalloc(len, GFP_NOIO);
726 if (buffer == NULL) { 720 if (buffer == NULL) {
727 printk("sddr09_read_data: Out of memory\n"); 721 printk("sddr09_read_data: Out of memory\n");
728 return USB_STOR_TRANSPORT_ERROR; 722 return -ENOMEM;
729 } 723 }
730 724
731 // Figure out the initial LBA and page 725 // Figure out the initial LBA and page
@@ -736,7 +730,7 @@ sddr09_read_data(struct us_data *us,
736 // This could be made much more efficient by checking for 730 // This could be made much more efficient by checking for
737 // contiguous LBA's. Another exercise left to the student. 731 // contiguous LBA's. Another exercise left to the student.
738 732
739 result = USB_STOR_TRANSPORT_GOOD; 733 result = 0;
740 index = offset = 0; 734 index = offset = 0;
741 735
742 while (sectors > 0) { 736 while (sectors > 0) {
@@ -749,7 +743,7 @@ sddr09_read_data(struct us_data *us,
749 if (lba >= maxlba) { 743 if (lba >= maxlba) {
750 US_DEBUGP("Error: Requested lba %u exceeds " 744 US_DEBUGP("Error: Requested lba %u exceeds "
751 "maximum %u\n", lba, maxlba); 745 "maximum %u\n", lba, maxlba);
752 result = USB_STOR_TRANSPORT_ERROR; 746 result = -EIO;
753 break; 747 break;
754 } 748 }
755 749
@@ -763,7 +757,7 @@ sddr09_read_data(struct us_data *us,
763 757
764 /* This is not really an error. It just means 758 /* This is not really an error. It just means
765 that the block has never been written. 759 that the block has never been written.
766 Instead of returning USB_STOR_TRANSPORT_ERROR 760 Instead of returning an error
767 it is better to return all zero data. */ 761 it is better to return all zero data. */
768 762
769 memset(buffer, 0, len); 763 memset(buffer, 0, len);
@@ -778,7 +772,7 @@ sddr09_read_data(struct us_data *us,
778 772
779 result = sddr09_read20(us, address>>1, 773 result = sddr09_read20(us, address>>1,
780 pages, info->pageshift, buffer, 0); 774 pages, info->pageshift, buffer, 0);
781 if (result != USB_STOR_TRANSPORT_GOOD) 775 if (result)
782 break; 776 break;
783 } 777 }
784 778
@@ -844,7 +838,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba,
844 pba = sddr09_find_unused_pba(info, lba); 838 pba = sddr09_find_unused_pba(info, lba);
845 if (!pba) { 839 if (!pba) {
846 printk("sddr09_write_lba: Out of unused blocks\n"); 840 printk("sddr09_write_lba: Out of unused blocks\n");
847 return USB_STOR_TRANSPORT_ERROR; 841 return -ENOSPC;
848 } 842 }
849 info->pba_to_lba[pba] = lba; 843 info->pba_to_lba[pba] = lba;
850 info->lba_to_pba[lba] = pba; 844 info->lba_to_pba[lba] = pba;
@@ -855,7 +849,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba,
855 /* Maybe it is impossible to write to PBA 1. 849 /* Maybe it is impossible to write to PBA 1.
856 Fake success, but don't do anything. */ 850 Fake success, but don't do anything. */
857 printk("sddr09: avoid writing to pba 1\n"); 851 printk("sddr09: avoid writing to pba 1\n");
858 return USB_STOR_TRANSPORT_GOOD; 852 return 0;
859 } 853 }
860 854
861 pagelen = (1 << info->pageshift) + (1 << CONTROL_SHIFT); 855 pagelen = (1 << info->pageshift) + (1 << CONTROL_SHIFT);
@@ -864,7 +858,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba,
864 address = (pba << (info->pageshift + info->blockshift)); 858 address = (pba << (info->pageshift + info->blockshift));
865 result = sddr09_read22(us, address>>1, info->blocksize, 859 result = sddr09_read22(us, address>>1, info->blocksize,
866 info->pageshift, blockbuffer, 0); 860 info->pageshift, blockbuffer, 0);
867 if (result != USB_STOR_TRANSPORT_GOOD) 861 if (result)
868 return result; 862 return result;
869 863
870 /* check old contents and fill lba */ 864 /* check old contents and fill lba */
@@ -911,7 +905,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba,
911 { 905 {
912 unsigned char status = 0; 906 unsigned char status = 0;
913 int result2 = sddr09_read_status(us, &status); 907 int result2 = sddr09_read_status(us, &status);
914 if (result2 != USB_STOR_TRANSPORT_GOOD) 908 if (result2)
915 US_DEBUGP("sddr09_write_inplace: cannot read status\n"); 909 US_DEBUGP("sddr09_write_inplace: cannot read status\n");
916 else if (status != 0xc0) 910 else if (status != 0xc0)
917 US_DEBUGP("sddr09_write_inplace: status after write: 0x%x\n", 911 US_DEBUGP("sddr09_write_inplace: status after write: 0x%x\n",
@@ -952,7 +946,7 @@ sddr09_write_data(struct us_data *us,
952 blockbuffer = kmalloc(blocklen, GFP_NOIO); 946 blockbuffer = kmalloc(blocklen, GFP_NOIO);
953 if (!blockbuffer) { 947 if (!blockbuffer) {
954 printk("sddr09_write_data: Out of memory\n"); 948 printk("sddr09_write_data: Out of memory\n");
955 return USB_STOR_TRANSPORT_ERROR; 949 return -ENOMEM;
956 } 950 }
957 951
958 // Since we don't write the user data directly to the device, 952 // Since we don't write the user data directly to the device,
@@ -964,14 +958,14 @@ sddr09_write_data(struct us_data *us,
964 if (buffer == NULL) { 958 if (buffer == NULL) {
965 printk("sddr09_write_data: Out of memory\n"); 959 printk("sddr09_write_data: Out of memory\n");
966 kfree(blockbuffer); 960 kfree(blockbuffer);
967 return USB_STOR_TRANSPORT_ERROR; 961 return -ENOMEM;
968 } 962 }
969 963
970 // Figure out the initial LBA and page 964 // Figure out the initial LBA and page
971 lba = address >> info->blockshift; 965 lba = address >> info->blockshift;
972 page = (address & info->blockmask); 966 page = (address & info->blockmask);
973 967
974 result = USB_STOR_TRANSPORT_GOOD; 968 result = 0;
975 index = offset = 0; 969 index = offset = 0;
976 970
977 while (sectors > 0) { 971 while (sectors > 0) {
@@ -987,7 +981,7 @@ sddr09_write_data(struct us_data *us,
987 981
988 result = sddr09_write_lba(us, lba, page, pages, 982 result = sddr09_write_lba(us, lba, page, pages,
989 buffer, blockbuffer); 983 buffer, blockbuffer);
990 if (result != USB_STOR_TRANSPORT_GOOD) 984 if (result)
991 break; 985 break;
992 986
993 page = 0; 987 page = 0;
@@ -1036,7 +1030,7 @@ sddr09_read_deviceID(struct us_data *us, unsigned char *deviceID) {
1036 command[1] = LUNBITS; 1030 command[1] = LUNBITS;
1037 1031
1038 result = sddr09_send_scsi_command(us, command, 12); 1032 result = sddr09_send_scsi_command(us, command, 12);
1039 if (result != USB_STOR_TRANSPORT_GOOD) 1033 if (result)
1040 return result; 1034 return result;
1041 1035
1042 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 1036 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
@@ -1045,8 +1039,7 @@ sddr09_read_deviceID(struct us_data *us, unsigned char *deviceID) {
1045 for (i = 0; i < 4; i++) 1039 for (i = 0; i < 4; i++)
1046 deviceID[i] = content[i]; 1040 deviceID[i] = content[i];
1047 1041
1048 return (result == USB_STOR_XFER_GOOD ? 1042 return (result == USB_STOR_XFER_GOOD ? 0 : -EIO);
1049 USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR);
1050} 1043}
1051 1044
1052static int 1045static int
@@ -1055,7 +1048,7 @@ sddr09_get_wp(struct us_data *us, struct sddr09_card_info *info) {
1055 unsigned char status; 1048 unsigned char status;
1056 1049
1057 result = sddr09_read_status(us, &status); 1050 result = sddr09_read_status(us, &status);
1058 if (result != USB_STOR_TRANSPORT_GOOD) { 1051 if (result) {
1059 US_DEBUGP("sddr09_get_wp: read_status fails\n"); 1052 US_DEBUGP("sddr09_get_wp: read_status fails\n");
1060 return result; 1053 return result;
1061 } 1054 }
@@ -1071,7 +1064,7 @@ sddr09_get_wp(struct us_data *us, struct sddr09_card_info *info) {
1071 if (status & 0x1) 1064 if (status & 0x1)
1072 US_DEBUGP(" Error"); 1065 US_DEBUGP(" Error");
1073 US_DEBUGP("\n"); 1066 US_DEBUGP("\n");
1074 return USB_STOR_TRANSPORT_GOOD; 1067 return 0;
1075} 1068}
1076 1069
1077#if 0 1070#if 0
@@ -1103,7 +1096,7 @@ sddr09_get_cardinfo(struct us_data *us, unsigned char flags) {
1103 1096
1104 result = sddr09_read_deviceID(us, deviceID); 1097 result = sddr09_read_deviceID(us, deviceID);
1105 1098
1106 if (result != USB_STOR_TRANSPORT_GOOD) { 1099 if (result) {
1107 US_DEBUGP("Result of read_deviceID is %d\n", result); 1100 US_DEBUGP("Result of read_deviceID is %d\n", result);
1108 printk("sddr09: could not read card info\n"); 1101 printk("sddr09: could not read card info\n");
1109 return NULL; 1102 return NULL;
@@ -1214,7 +1207,7 @@ sddr09_read_map(struct us_data *us) {
1214 us, address>>1, 1207 us, address>>1,
1215 min(alloc_blocks, numblocks - i), 1208 min(alloc_blocks, numblocks - i),
1216 buffer, 0); 1209 buffer, 0);
1217 if (result != USB_STOR_TRANSPORT_GOOD) { 1210 if (result) {
1218 result = -1; 1211 result = -1;
1219 goto done; 1212 goto done;
1220 } 1213 }
@@ -1402,7 +1395,7 @@ usb_stor_sddr09_dpcm_init(struct us_data *us) {
1402 return result; 1395 return result;
1403 1396
1404 result = sddr09_send_command(us, 0x01, USB_DIR_IN, data, 2); 1397 result = sddr09_send_command(us, 0x01, USB_DIR_IN, data, 2);
1405 if (result != USB_STOR_TRANSPORT_GOOD) { 1398 if (result) {
1406 US_DEBUGP("sddr09_init: send_command fails\n"); 1399 US_DEBUGP("sddr09_init: send_command fails\n");
1407 return result; 1400 return result;
1408 } 1401 }
@@ -1411,7 +1404,7 @@ usb_stor_sddr09_dpcm_init(struct us_data *us) {
1411 // get 07 02 1404 // get 07 02
1412 1405
1413 result = sddr09_send_command(us, 0x08, USB_DIR_IN, data, 2); 1406 result = sddr09_send_command(us, 0x08, USB_DIR_IN, data, 2);
1414 if (result != USB_STOR_TRANSPORT_GOOD) { 1407 if (result) {
1415 US_DEBUGP("sddr09_init: 2nd send_command fails\n"); 1408 US_DEBUGP("sddr09_init: 2nd send_command fails\n");
1416 return result; 1409 return result;
1417 } 1410 }
@@ -1420,7 +1413,7 @@ usb_stor_sddr09_dpcm_init(struct us_data *us) {
1420 // get 07 00 1413 // get 07 00
1421 1414
1422 result = sddr09_request_sense(us, data, 18); 1415 result = sddr09_request_sense(us, data, 18);
1423 if (result == USB_STOR_TRANSPORT_GOOD && data[2] != 0) { 1416 if (result == 0 && data[2] != 0) {
1424 int j; 1417 int j;
1425 for (j=0; j<18; j++) 1418 for (j=0; j<18; j++)
1426 printk(" %02X", data[j]); 1419 printk(" %02X", data[j]);
@@ -1567,7 +1560,9 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
1567 US_DEBUGP("READ_10: read page %d pagect %d\n", 1560 US_DEBUGP("READ_10: read page %d pagect %d\n",
1568 page, pages); 1561 page, pages);
1569 1562
1570 return sddr09_read_data(us, page, pages); 1563 result = sddr09_read_data(us, page, pages);
1564 return (result == 0 ? USB_STOR_TRANSPORT_GOOD :
1565 USB_STOR_TRANSPORT_ERROR);
1571 } 1566 }
1572 1567
1573 if (srb->cmnd[0] == WRITE_10) { 1568 if (srb->cmnd[0] == WRITE_10) {
@@ -1580,7 +1575,9 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
1580 US_DEBUGP("WRITE_10: write page %d pagect %d\n", 1575 US_DEBUGP("WRITE_10: write page %d pagect %d\n",
1581 page, pages); 1576 page, pages);
1582 1577
1583 return sddr09_write_data(us, page, pages); 1578 result = sddr09_write_data(us, page, pages);
1579 return (result == 0 ? USB_STOR_TRANSPORT_GOOD :
1580 USB_STOR_TRANSPORT_ERROR);
1584 } 1581 }
1585 1582
1586 /* catch-all for all other commands, except 1583 /* catch-all for all other commands, except
@@ -1606,10 +1603,10 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
1606 US_DEBUGP("SDDR09: Send control for command %s\n", ptr); 1603 US_DEBUGP("SDDR09: Send control for command %s\n", ptr);
1607 1604
1608 result = sddr09_send_scsi_command(us, srb->cmnd, 12); 1605 result = sddr09_send_scsi_command(us, srb->cmnd, 12);
1609 if (result != USB_STOR_TRANSPORT_GOOD) { 1606 if (result) {
1610 US_DEBUGP("sddr09_transport: sddr09_send_scsi_command " 1607 US_DEBUGP("sddr09_transport: sddr09_send_scsi_command "
1611 "returns %d\n", result); 1608 "returns %d\n", result);
1612 return result; 1609 return USB_STOR_TRANSPORT_ERROR;
1613 } 1610 }
1614 1611
1615 if (srb->request_bufflen == 0) 1612 if (srb->request_bufflen == 0)