Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] USB Storage: cleanups of sddr09

This is the first of three patches to prepare the sddr09 subdriver for
conversion to the Sim-SCSI framework. This patch (as594) straightens
out the initialization procedures and headers:

Some ugly code from usb.c was moved into sddr09.c.

Set-up of the private data structures was moved into the
initialization routine.

The connection between the "dpcm" version and the standalone
version was clarified.

A private declaration was moved from a header file into the
subdriver's .c file.

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>

authored by

Matthew Dharm and committed by
Greg Kroah-Hartman
f5b8cb9c 7931e1c6

+64 -63
-4
drivers/usb/storage/initializers.h
··· 45 45 * mode */ 46 46 int usb_stor_euscsi_init(struct us_data *us); 47 47 48 - #ifdef CONFIG_USB_STORAGE_SDDR09 49 - int sddr09_init(struct us_data *us); 50 - #endif 51 - 52 48 /* This function is required to activate all four slots on the UCR-61S2B 53 49 * flash reader */ 54 50 int usb_stor_ucr61s2b_init(struct us_data *us);
+55 -17
drivers/usb/storage/sddr09.c
··· 214 214 * The actual driver starts here. 215 215 */ 216 216 217 + struct sddr09_card_info { 218 + unsigned long capacity; /* Size of card in bytes */ 219 + int pagesize; /* Size of page in bytes */ 220 + int pageshift; /* log2 of pagesize */ 221 + int blocksize; /* Size of block in pages */ 222 + int blockshift; /* log2 of blocksize */ 223 + int blockmask; /* 2^blockshift - 1 */ 224 + int *lba_to_pba; /* logical to physical map */ 225 + int *pba_to_lba; /* physical to logical map */ 226 + int lbact; /* number of available pages */ 227 + int flags; 228 + #define SDDR09_WP 1 /* write protected */ 229 + }; 230 + 217 231 /* 218 232 * On my 16MB card, control blocks have size 64 (16 real control bytes, 219 233 * and 48 junk bytes). In reality of course the card uses 16 control bytes, ··· 1356 1342 kfree(info->pba_to_lba); 1357 1343 } 1358 1344 1359 - static void 1360 - sddr09_init_card_info(struct us_data *us) { 1361 - if (!us->extra) { 1362 - us->extra = kmalloc(sizeof(struct sddr09_card_info), GFP_NOIO); 1363 - if (us->extra) { 1364 - memset(us->extra, 0, sizeof(struct sddr09_card_info)); 1365 - us->extra_destructor = sddr09_card_info_destructor; 1366 - } 1345 + static int 1346 + sddr09_common_init(struct us_data *us) { 1347 + int result; 1348 + 1349 + /* set the configuration -- STALL is an acceptable response here */ 1350 + if (us->pusb_dev->actconfig->desc.bConfigurationValue != 1) { 1351 + US_DEBUGP("active config #%d != 1 ??\n", us->pusb_dev 1352 + ->actconfig->desc.bConfigurationValue); 1353 + return -EINVAL; 1367 1354 } 1355 + 1356 + result = usb_reset_configuration(us->pusb_dev); 1357 + US_DEBUGP("Result of usb_reset_configuration is %d\n", result); 1358 + if (result == -EPIPE) { 1359 + US_DEBUGP("-- stall on control interface\n"); 1360 + } else if (result != 0) { 1361 + /* it's not a stall, but another error -- time to bail */ 1362 + US_DEBUGP("-- Unknown error. Rejecting device\n"); 1363 + return -EINVAL; 1364 + } 1365 + 1366 + us->extra = kzalloc(sizeof(struct sddr09_card_info), GFP_NOIO); 1367 + if (!us->extra) 1368 + return -ENOMEM; 1369 + us->extra_destructor = sddr09_card_info_destructor; 1370 + 1371 + nand_init_ecc(); 1372 + return 0; 1368 1373 } 1374 + 1369 1375 1370 1376 /* 1371 1377 * This is needed at a very early stage. If this is not listed in the ··· 1393 1359 * is not recognized. But I do not know what precisely these calls do. 1394 1360 */ 1395 1361 int 1396 - sddr09_init(struct us_data *us) { 1362 + usb_stor_sddr09_dpcm_init(struct us_data *us) { 1397 1363 int result; 1398 1364 unsigned char *data = us->iobuf; 1365 + 1366 + result = sddr09_common_init(us); 1367 + if (result) 1368 + return result; 1399 1369 1400 1370 result = sddr09_send_command(us, 0x01, USB_DIR_IN, data, 2); 1401 1371 if (result != USB_STOR_TRANSPORT_GOOD) { ··· 1436 1398 1437 1399 // test unit ready 1438 1400 1439 - return USB_STOR_TRANSPORT_GOOD; /* not result */ 1401 + return 0; /* not result */ 1440 1402 } 1441 1403 1442 1404 /* ··· 1465 1427 }; 1466 1428 1467 1429 info = (struct sddr09_card_info *)us->extra; 1468 - if (!info) { 1469 - nand_init_ecc(); 1470 - sddr09_init_card_info(us); 1471 - info = (struct sddr09_card_info *)us->extra; 1472 - if (!info) 1473 - return USB_STOR_TRANSPORT_ERROR; 1474 - } 1475 1430 1476 1431 if (srb->cmnd[0] == REQUEST_SENSE && havefakesense) { 1477 1432 /* for a faked command, we have to follow with a faked sense */ ··· 1637 1606 return USB_STOR_TRANSPORT_GOOD; 1638 1607 } 1639 1608 1609 + /* 1610 + * Initialization routine for the sddr09 subdriver 1611 + */ 1612 + int 1613 + usb_stor_sddr09_init(struct us_data *us) { 1614 + return sddr09_common_init(us); 1615 + }
+2 -13
drivers/usb/storage/sddr09.h
··· 31 31 32 32 extern int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us); 33 33 34 - struct sddr09_card_info { 35 - unsigned long capacity; /* Size of card in bytes */ 36 - int pagesize; /* Size of page in bytes */ 37 - int pageshift; /* log2 of pagesize */ 38 - int blocksize; /* Size of block in pages */ 39 - int blockshift; /* log2 of blocksize */ 40 - int blockmask; /* 2^blockshift - 1 */ 41 - int *lba_to_pba; /* logical to physical map */ 42 - int *pba_to_lba; /* physical to logical map */ 43 - int lbact; /* number of available pages */ 44 - int flags; 45 - #define SDDR09_WP 1 /* write protected */ 46 - }; 34 + extern int usb_stor_sddr09_dpcm_init(struct us_data *us); 35 + extern int usb_stor_sddr09_init(struct us_data *us); 47 36 48 37 #endif
+7 -7
drivers/usb/storage/unusual_devs.h
··· 284 284 UNUSUAL_DEV( 0x04e6, 0x0003, 0x0000, 0x9999, 285 285 "Sandisk", 286 286 "ImageMate SDDR09", 287 - US_SC_SCSI, US_PR_EUSB_SDDR09, NULL, 288 - US_FL_SINGLE_LUN ), 287 + US_SC_SCSI, US_PR_EUSB_SDDR09, usb_stor_sddr09_init, 288 + 0), 289 289 290 290 /* This entry is from Andries.Brouwer@cwi.nl */ 291 291 UNUSUAL_DEV( 0x04e6, 0x0005, 0x0100, 0x0208, 292 292 "SCM Microsystems", 293 293 "eUSB SmartMedia / CompactFlash Adapter", 294 - US_SC_SCSI, US_PR_DPCM_USB, sddr09_init, 294 + US_SC_SCSI, US_PR_DPCM_USB, usb_stor_sddr09_dpcm_init, 295 295 0), 296 296 #endif 297 297 ··· 681 681 UNUSUAL_DEV( 0x066b, 0x0105, 0x0100, 0x0100, 682 682 "Olympus", 683 683 "Camedia MAUSB-2", 684 - US_SC_SCSI, US_PR_EUSB_SDDR09, NULL, 685 - US_FL_SINGLE_LUN ), 684 + US_SC_SCSI, US_PR_EUSB_SDDR09, usb_stor_sddr09_init, 685 + 0), 686 686 #endif 687 687 688 688 /* Reported by Darsen Lu <darsen@micro.ee.nthu.edu.tw> */ ··· 747 747 UNUSUAL_DEV( 0x0781, 0x0200, 0x0000, 0x9999, 748 748 "Sandisk", 749 749 "ImageMate SDDR-09", 750 - US_SC_SCSI, US_PR_EUSB_SDDR09, NULL, 751 - US_FL_SINGLE_LUN ), 750 + US_SC_SCSI, US_PR_EUSB_SDDR09, usb_stor_sddr09_init, 751 + 0), 752 752 #endif 753 753 754 754 #ifdef CONFIG_USB_STORAGE_FREECOM
-22
drivers/usb/storage/usb.c
··· 919 919 */ 920 920 get_device_info(us, id); 921 921 922 - #ifdef CONFIG_USB_STORAGE_SDDR09 923 - if (us->protocol == US_PR_EUSB_SDDR09 || 924 - us->protocol == US_PR_DPCM_USB) { 925 - /* set the configuration -- STALL is an acceptable response here */ 926 - if (us->pusb_dev->actconfig->desc.bConfigurationValue != 1) { 927 - US_DEBUGP("active config #%d != 1 ??\n", us->pusb_dev 928 - ->actconfig->desc.bConfigurationValue); 929 - goto BadDevice; 930 - } 931 - result = usb_reset_configuration(us->pusb_dev); 932 - 933 - US_DEBUGP("Result of usb_reset_configuration is %d\n", result); 934 - if (result == -EPIPE) { 935 - US_DEBUGP("-- stall on control interface\n"); 936 - } else if (result != 0) { 937 - /* it's not a stall, but another error -- time to bail */ 938 - US_DEBUGP("-- Unknown error. Rejecting device\n"); 939 - goto BadDevice; 940 - } 941 - } 942 - #endif 943 - 944 922 /* Get the transport, protocol, and pipe settings */ 945 923 result = get_transport(us); 946 924 if (result)