diff options
author | Matthew Dharm <mdharm-usb@one-eyed-alien.net> | 2005-12-05 00:57:51 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-01-04 16:51:41 -0500 |
commit | f5b8cb9c91f2f7d54dc3f066db8d4e0f041de79b (patch) | |
tree | 87c0ffd6678cffdd5d9c9425d8f8432ceebc1c33 /drivers/usb/storage/sddr09.c | |
parent | 7931e1c6f8007d5fef8a0bb2dc71bd97315eeae9 (diff) |
[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>
Diffstat (limited to 'drivers/usb/storage/sddr09.c')
-rw-r--r-- | drivers/usb/storage/sddr09.c | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c index 0a6efae452fb..6c379b6b43d1 100644 --- a/drivers/usb/storage/sddr09.c +++ b/drivers/usb/storage/sddr09.c | |||
@@ -214,6 +214,20 @@ static void nand_store_ecc(unsigned char *data, unsigned char *ecc) { | |||
214 | * The actual driver starts here. | 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 | * On my 16MB card, control blocks have size 64 (16 real control bytes, | 232 | * On my 16MB card, control blocks have size 64 (16 real control bytes, |
219 | * and 48 junk bytes). In reality of course the card uses 16 control bytes, | 233 | * and 48 junk bytes). In reality of course the card uses 16 control bytes, |
@@ -1342,27 +1356,51 @@ sddr09_card_info_destructor(void *extra) { | |||
1342 | kfree(info->pba_to_lba); | 1356 | kfree(info->pba_to_lba); |
1343 | } | 1357 | } |
1344 | 1358 | ||
1345 | static void | 1359 | static int |
1346 | sddr09_init_card_info(struct us_data *us) { | 1360 | sddr09_common_init(struct us_data *us) { |
1347 | if (!us->extra) { | 1361 | int result; |
1348 | us->extra = kmalloc(sizeof(struct sddr09_card_info), GFP_NOIO); | 1362 | |
1349 | if (us->extra) { | 1363 | /* set the configuration -- STALL is an acceptable response here */ |
1350 | memset(us->extra, 0, sizeof(struct sddr09_card_info)); | 1364 | if (us->pusb_dev->actconfig->desc.bConfigurationValue != 1) { |
1351 | us->extra_destructor = sddr09_card_info_destructor; | 1365 | US_DEBUGP("active config #%d != 1 ??\n", us->pusb_dev |
1352 | } | 1366 | ->actconfig->desc.bConfigurationValue); |
1367 | return -EINVAL; | ||
1368 | } | ||
1369 | |||
1370 | result = usb_reset_configuration(us->pusb_dev); | ||
1371 | US_DEBUGP("Result of usb_reset_configuration is %d\n", result); | ||
1372 | if (result == -EPIPE) { | ||
1373 | US_DEBUGP("-- stall on control interface\n"); | ||
1374 | } else if (result != 0) { | ||
1375 | /* it's not a stall, but another error -- time to bail */ | ||
1376 | US_DEBUGP("-- Unknown error. Rejecting device\n"); | ||
1377 | return -EINVAL; | ||
1353 | } | 1378 | } |
1379 | |||
1380 | us->extra = kzalloc(sizeof(struct sddr09_card_info), GFP_NOIO); | ||
1381 | if (!us->extra) | ||
1382 | return -ENOMEM; | ||
1383 | us->extra_destructor = sddr09_card_info_destructor; | ||
1384 | |||
1385 | nand_init_ecc(); | ||
1386 | return 0; | ||
1354 | } | 1387 | } |
1355 | 1388 | ||
1389 | |||
1356 | /* | 1390 | /* |
1357 | * This is needed at a very early stage. If this is not listed in the | 1391 | * This is needed at a very early stage. If this is not listed in the |
1358 | * unusual devices list but called from here then LUN 0 of the combo reader | 1392 | * unusual devices list but called from here then LUN 0 of the combo reader |
1359 | * is not recognized. But I do not know what precisely these calls do. | 1393 | * is not recognized. But I do not know what precisely these calls do. |
1360 | */ | 1394 | */ |
1361 | int | 1395 | int |
1362 | sddr09_init(struct us_data *us) { | 1396 | usb_stor_sddr09_dpcm_init(struct us_data *us) { |
1363 | int result; | 1397 | int result; |
1364 | unsigned char *data = us->iobuf; | 1398 | unsigned char *data = us->iobuf; |
1365 | 1399 | ||
1400 | result = sddr09_common_init(us); | ||
1401 | if (result) | ||
1402 | return result; | ||
1403 | |||
1366 | result = sddr09_send_command(us, 0x01, USB_DIR_IN, data, 2); | 1404 | result = sddr09_send_command(us, 0x01, USB_DIR_IN, data, 2); |
1367 | if (result != USB_STOR_TRANSPORT_GOOD) { | 1405 | if (result != USB_STOR_TRANSPORT_GOOD) { |
1368 | US_DEBUGP("sddr09_init: send_command fails\n"); | 1406 | US_DEBUGP("sddr09_init: send_command fails\n"); |
@@ -1398,7 +1436,7 @@ sddr09_init(struct us_data *us) { | |||
1398 | 1436 | ||
1399 | // test unit ready | 1437 | // test unit ready |
1400 | 1438 | ||
1401 | return USB_STOR_TRANSPORT_GOOD; /* not result */ | 1439 | return 0; /* not result */ |
1402 | } | 1440 | } |
1403 | 1441 | ||
1404 | /* | 1442 | /* |
@@ -1427,13 +1465,6 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us) | |||
1427 | }; | 1465 | }; |
1428 | 1466 | ||
1429 | info = (struct sddr09_card_info *)us->extra; | 1467 | info = (struct sddr09_card_info *)us->extra; |
1430 | if (!info) { | ||
1431 | nand_init_ecc(); | ||
1432 | sddr09_init_card_info(us); | ||
1433 | info = (struct sddr09_card_info *)us->extra; | ||
1434 | if (!info) | ||
1435 | return USB_STOR_TRANSPORT_ERROR; | ||
1436 | } | ||
1437 | 1468 | ||
1438 | if (srb->cmnd[0] == REQUEST_SENSE && havefakesense) { | 1469 | if (srb->cmnd[0] == REQUEST_SENSE && havefakesense) { |
1439 | /* for a faked command, we have to follow with a faked sense */ | 1470 | /* for a faked command, we have to follow with a faked sense */ |
@@ -1606,3 +1637,10 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us) | |||
1606 | return USB_STOR_TRANSPORT_GOOD; | 1637 | return USB_STOR_TRANSPORT_GOOD; |
1607 | } | 1638 | } |
1608 | 1639 | ||
1640 | /* | ||
1641 | * Initialization routine for the sddr09 subdriver | ||
1642 | */ | ||
1643 | int | ||
1644 | usb_stor_sddr09_init(struct us_data *us) { | ||
1645 | return sddr09_common_init(us); | ||
1646 | } | ||