alauda.c (cf9ce948f47640797bd19980e1d99c6d17d0bdc3) alauda.c (191648d03d20229523d9a75b8abef56421298d28)
1/*
2 * Driver for Alauda-based card readers
3 *
4 * Current development and maintenance by:
5 * (c) 2005 Daniel Drake <dsd@gentoo.org>
6 *
7 * The 'Alauda' is a chip manufacturered by RATOC for OEM use.
8 *

--- 312 unchanged lines hidden (view full) ---

321 if (MEDIA_PORT(us) == ALAUDA_PORT_XD)
322 command = ALAUDA_GET_XD_MEDIA_STATUS;
323 else
324 command = ALAUDA_GET_SM_MEDIA_STATUS;
325
326 rc = usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe,
327 command, 0xc0, 0, 1, data, 2);
328
1/*
2 * Driver for Alauda-based card readers
3 *
4 * Current development and maintenance by:
5 * (c) 2005 Daniel Drake <dsd@gentoo.org>
6 *
7 * The 'Alauda' is a chip manufacturered by RATOC for OEM use.
8 *

--- 312 unchanged lines hidden (view full) ---

321 if (MEDIA_PORT(us) == ALAUDA_PORT_XD)
322 command = ALAUDA_GET_XD_MEDIA_STATUS;
323 else
324 command = ALAUDA_GET_SM_MEDIA_STATUS;
325
326 rc = usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe,
327 command, 0xc0, 0, 1, data, 2);
328
329 US_DEBUGP("alauda_get_media_status: Media status %02X %02X\n",
330 data[0], data[1]);
329 usb_stor_dbg(us, "Media status %02X %02X\n", data[0], data[1]);
331
332 return rc;
333}
334
335/*
336 * Clears the "media was changed" bit so that we know when it changes again
337 * in the future.
338 */

--- 58 unchanged lines hidden (view full) ---

397
398 if (alauda_get_media_status(us, data) != USB_STOR_XFER_GOOD)
399 return USB_STOR_TRANSPORT_ERROR;
400
401 if (data[0] & 0x10)
402 ready = 1;
403 }
404
330
331 return rc;
332}
333
334/*
335 * Clears the "media was changed" bit so that we know when it changes again
336 * in the future.
337 */

--- 58 unchanged lines hidden (view full) ---

396
397 if (alauda_get_media_status(us, data) != USB_STOR_XFER_GOOD)
398 return USB_STOR_TRANSPORT_ERROR;
399
400 if (data[0] & 0x10)
401 ready = 1;
402 }
403
405 US_DEBUGP("alauda_init_media: We are ready for action!\n");
404 usb_stor_dbg(us, "We are ready for action!\n");
406
407 if (alauda_ack_media(us) != USB_STOR_XFER_GOOD)
408 return USB_STOR_TRANSPORT_ERROR;
409
410 msleep(10);
411
412 if (alauda_get_media_status(us, data) != USB_STOR_XFER_GOOD)
413 return USB_STOR_TRANSPORT_ERROR;
414
415 if (data[0] != 0x14) {
405
406 if (alauda_ack_media(us) != USB_STOR_XFER_GOOD)
407 return USB_STOR_TRANSPORT_ERROR;
408
409 msleep(10);
410
411 if (alauda_get_media_status(us, data) != USB_STOR_XFER_GOOD)
412 return USB_STOR_TRANSPORT_ERROR;
413
414 if (data[0] != 0x14) {
416 US_DEBUGP("alauda_init_media: Media not ready after ack\n");
415 usb_stor_dbg(us, "Media not ready after ack\n");
417 return USB_STOR_TRANSPORT_ERROR;
418 }
419
420 if (alauda_get_media_signature(us, data) != USB_STOR_XFER_GOOD)
421 return USB_STOR_TRANSPORT_ERROR;
422
416 return USB_STOR_TRANSPORT_ERROR;
417 }
418
419 if (alauda_get_media_signature(us, data) != USB_STOR_XFER_GOOD)
420 return USB_STOR_TRANSPORT_ERROR;
421
423 US_DEBUGP("alauda_init_media: Media signature: %02X %02X %02X %02X\n",
424 data[0], data[1], data[2], data[3]);
422 usb_stor_dbg(us, "Media signature: %02X %02X %02X %02X\n",
423 data[0], data[1], data[2], data[3]);
425 media_info = alauda_card_find_id(data[1]);
426 if (media_info == NULL) {
427 printk(KERN_WARNING
428 "alauda_init_media: Unrecognised media signature: "
429 "%02X %02X %02X %02X\n",
430 data[0], data[1], data[2], data[3]);
431 return USB_STOR_TRANSPORT_ERROR;
432 }
433
434 MEDIA_INFO(us).capacity = 1 << media_info->chipshift;
424 media_info = alauda_card_find_id(data[1]);
425 if (media_info == NULL) {
426 printk(KERN_WARNING
427 "alauda_init_media: Unrecognised media signature: "
428 "%02X %02X %02X %02X\n",
429 data[0], data[1], data[2], data[3]);
430 return USB_STOR_TRANSPORT_ERROR;
431 }
432
433 MEDIA_INFO(us).capacity = 1 << media_info->chipshift;
435 US_DEBUGP("Found media with capacity: %ldMB\n",
436 MEDIA_INFO(us).capacity >> 20);
434 usb_stor_dbg(us, "Found media with capacity: %ldMB\n",
435 MEDIA_INFO(us).capacity >> 20);
437
438 MEDIA_INFO(us).pageshift = media_info->pageshift;
439 MEDIA_INFO(us).blockshift = media_info->blockshift;
440 MEDIA_INFO(us).zoneshift = media_info->zoneshift;
441
442 MEDIA_INFO(us).pagesize = 1 << media_info->pageshift;
443 MEDIA_INFO(us).blocksize = 1 << media_info->blockshift;
444 MEDIA_INFO(us).zonesize = 1 << media_info->zoneshift;

--- 22 unchanged lines hidden (view full) ---

467 unsigned char status[2];
468 int rc;
469
470 rc = alauda_get_media_status(us, status);
471
472 /* Check for no media or door open */
473 if ((status[0] & 0x80) || ((status[0] & 0x1F) == 0x10)
474 || ((status[1] & 0x01) == 0)) {
436
437 MEDIA_INFO(us).pageshift = media_info->pageshift;
438 MEDIA_INFO(us).blockshift = media_info->blockshift;
439 MEDIA_INFO(us).zoneshift = media_info->zoneshift;
440
441 MEDIA_INFO(us).pagesize = 1 << media_info->pageshift;
442 MEDIA_INFO(us).blocksize = 1 << media_info->blockshift;
443 MEDIA_INFO(us).zonesize = 1 << media_info->zoneshift;

--- 22 unchanged lines hidden (view full) ---

466 unsigned char status[2];
467 int rc;
468
469 rc = alauda_get_media_status(us, status);
470
471 /* Check for no media or door open */
472 if ((status[0] & 0x80) || ((status[0] & 0x1F) == 0x10)
473 || ((status[1] & 0x01) == 0)) {
475 US_DEBUGP("alauda_check_media: No media, or door open\n");
474 usb_stor_dbg(us, "No media, or door open\n");
476 alauda_free_maps(&MEDIA_INFO(us));
477 info->sense_key = 0x02;
478 info->sense_asc = 0x3A;
479 info->sense_ascq = 0x00;
480 return USB_STOR_TRANSPORT_FAILED;
481 }
482
483 /* Check for media change */
484 if (status[0] & 0x08) {
475 alauda_free_maps(&MEDIA_INFO(us));
476 info->sense_key = 0x02;
477 info->sense_asc = 0x3A;
478 info->sense_ascq = 0x00;
479 return USB_STOR_TRANSPORT_FAILED;
480 }
481
482 /* Check for media change */
483 if (status[0] & 0x08) {
485 US_DEBUGP("alauda_check_media: Media change detected\n");
484 usb_stor_dbg(us, "Media change detected\n");
486 alauda_free_maps(&MEDIA_INFO(us));
487 alauda_init_media(us);
488
489 info->sense_key = UNIT_ATTENTION;
490 info->sense_asc = 0x28;
491 info->sense_ascq = 0x00;
492 return USB_STOR_TRANSPORT_FAILED;
493 }

--- 19 unchanged lines hidden (view full) ---

513 if (rc != USB_STOR_XFER_GOOD)
514 return rc;
515
516 rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
517 data, 3, NULL);
518 if (rc != USB_STOR_XFER_GOOD)
519 return rc;
520
485 alauda_free_maps(&MEDIA_INFO(us));
486 alauda_init_media(us);
487
488 info->sense_key = UNIT_ATTENTION;
489 info->sense_asc = 0x28;
490 info->sense_ascq = 0x00;
491 return USB_STOR_TRANSPORT_FAILED;
492 }

--- 19 unchanged lines hidden (view full) ---

512 if (rc != USB_STOR_XFER_GOOD)
513 return rc;
514
515 rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
516 data, 3, NULL);
517 if (rc != USB_STOR_XFER_GOOD)
518 return rc;
519
521 US_DEBUGP("alauda_check_status2: %02X %02X %02X\n", data[0], data[1], data[2]);
520 usb_stor_dbg(us, "%02X %02X %02X\n", data[0], data[1], data[2]);
522 if (data[0] & ALAUDA_STATUS_ERROR)
523 return USB_STOR_XFER_ERROR;
524
525 return USB_STOR_XFER_GOOD;
526}
527
528/*
529 * Gets the redundancy data for the first page of a PBA

--- 49 unchanged lines hidden (view full) ---

579 unsigned int zone_base_pba = zone * zonesize;
580 u16 *lba_to_pba = kcalloc(zonesize, sizeof(u16), GFP_NOIO);
581 u16 *pba_to_lba = kcalloc(zonesize, sizeof(u16), GFP_NOIO);
582 if (lba_to_pba == NULL || pba_to_lba == NULL) {
583 result = USB_STOR_TRANSPORT_ERROR;
584 goto error;
585 }
586
521 if (data[0] & ALAUDA_STATUS_ERROR)
522 return USB_STOR_XFER_ERROR;
523
524 return USB_STOR_XFER_GOOD;
525}
526
527/*
528 * Gets the redundancy data for the first page of a PBA

--- 49 unchanged lines hidden (view full) ---

578 unsigned int zone_base_pba = zone * zonesize;
579 u16 *lba_to_pba = kcalloc(zonesize, sizeof(u16), GFP_NOIO);
580 u16 *pba_to_lba = kcalloc(zonesize, sizeof(u16), GFP_NOIO);
581 if (lba_to_pba == NULL || pba_to_lba == NULL) {
582 result = USB_STOR_TRANSPORT_ERROR;
583 goto error;
584 }
585
587 US_DEBUGP("alauda_read_map: Mapping blocks for zone %d\n", zone);
586 usb_stor_dbg(us, "Mapping blocks for zone %d\n", zone);
588
589 /* 1024 PBA's per zone */
590 for (i = 0; i < zonesize; i++)
591 lba_to_pba[i] = pba_to_lba[i] = UNDEF;
592
593 for (i = 0; i < zonesize; i++) {
594 blocknum = zone_base_pba + i;
595
596 result = alauda_get_redu_data(us, blocknum, data);
597 if (result != USB_STOR_XFER_GOOD) {
598 result = USB_STOR_TRANSPORT_ERROR;
599 goto error;
600 }
601
602 /* special PBAs have control field 0^16 */
603 for (j = 0; j < 16; j++)
604 if (data[j] != 0)
605 goto nonz;
606 pba_to_lba[i] = UNUSABLE;
587
588 /* 1024 PBA's per zone */
589 for (i = 0; i < zonesize; i++)
590 lba_to_pba[i] = pba_to_lba[i] = UNDEF;
591
592 for (i = 0; i < zonesize; i++) {
593 blocknum = zone_base_pba + i;
594
595 result = alauda_get_redu_data(us, blocknum, data);
596 if (result != USB_STOR_XFER_GOOD) {
597 result = USB_STOR_TRANSPORT_ERROR;
598 goto error;
599 }
600
601 /* special PBAs have control field 0^16 */
602 for (j = 0; j < 16; j++)
603 if (data[j] != 0)
604 goto nonz;
605 pba_to_lba[i] = UNUSABLE;
607 US_DEBUGP("alauda_read_map: PBA %d has no logical mapping\n", blocknum);
606 usb_stor_dbg(us, "PBA %d has no logical mapping\n", blocknum);
608 continue;
609
610 nonz:
611 /* unwritten PBAs have control field FF^16 */
612 for (j = 0; j < 16; j++)
613 if (data[j] != 0xff)
614 goto nonff;
615 continue;
616
617 nonff:
618 /* normal PBAs start with six FFs */
619 if (j < 6) {
607 continue;
608
609 nonz:
610 /* unwritten PBAs have control field FF^16 */
611 for (j = 0; j < 16; j++)
612 if (data[j] != 0xff)
613 goto nonff;
614 continue;
615
616 nonff:
617 /* normal PBAs start with six FFs */
618 if (j < 6) {
620 US_DEBUGP("alauda_read_map: PBA %d has no logical mapping: "
621 "reserved area = %02X%02X%02X%02X "
622 "data status %02X block status %02X\n",
623 blocknum, data[0], data[1], data[2], data[3],
624 data[4], data[5]);
619 usb_stor_dbg(us, "PBA %d has no logical mapping: reserved area = %02X%02X%02X%02X data status %02X block status %02X\n",
620 blocknum,
621 data[0], data[1], data[2], data[3],
622 data[4], data[5]);
625 pba_to_lba[i] = UNUSABLE;
626 continue;
627 }
628
629 if ((data[6] >> 4) != 0x01) {
623 pba_to_lba[i] = UNUSABLE;
624 continue;
625 }
626
627 if ((data[6] >> 4) != 0x01) {
630 US_DEBUGP("alauda_read_map: PBA %d has invalid address "
631 "field %02X%02X/%02X%02X\n",
632 blocknum, data[6], data[7], data[11], data[12]);
628 usb_stor_dbg(us, "PBA %d has invalid address field %02X%02X/%02X%02X\n",
629 blocknum, data[6], data[7],
630 data[11], data[12]);
633 pba_to_lba[i] = UNUSABLE;
634 continue;
635 }
636
637 /* check even parity */
638 if (parity[data[6] ^ data[7]]) {
639 printk(KERN_WARNING
640 "alauda_read_map: Bad parity in LBA for block %d"

--- 65 unchanged lines hidden (view full) ---

706{
707 int rc;
708 unsigned char command[] = {
709 ALAUDA_BULK_CMD, ALAUDA_BULK_ERASE_BLOCK, PBA_HI(pba),
710 PBA_ZONE(pba), 0, PBA_LO(pba), 0x02, 0, MEDIA_PORT(us)
711 };
712 unsigned char buf[2];
713
631 pba_to_lba[i] = UNUSABLE;
632 continue;
633 }
634
635 /* check even parity */
636 if (parity[data[6] ^ data[7]]) {
637 printk(KERN_WARNING
638 "alauda_read_map: Bad parity in LBA for block %d"

--- 65 unchanged lines hidden (view full) ---

704{
705 int rc;
706 unsigned char command[] = {
707 ALAUDA_BULK_CMD, ALAUDA_BULK_ERASE_BLOCK, PBA_HI(pba),
708 PBA_ZONE(pba), 0, PBA_LO(pba), 0x02, 0, MEDIA_PORT(us)
709 };
710 unsigned char buf[2];
711
714 US_DEBUGP("alauda_erase_block: Erasing PBA %d\n", pba);
712 usb_stor_dbg(us, "Erasing PBA %d\n", pba);
715
716 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
717 command, 9, NULL);
718 if (rc != USB_STOR_XFER_GOOD)
719 return rc;
720
721 rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
722 buf, 2, NULL);
723 if (rc != USB_STOR_XFER_GOOD)
724 return rc;
725
713
714 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
715 command, 9, NULL);
716 if (rc != USB_STOR_XFER_GOOD)
717 return rc;
718
719 rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
720 buf, 2, NULL);
721 if (rc != USB_STOR_XFER_GOOD)
722 return rc;
723
726 US_DEBUGP("alauda_erase_block: Erase result: %02X %02X\n",
727 buf[0], buf[1]);
724 usb_stor_dbg(us, "Erase result: %02X %02X\n", buf[0], buf[1]);
728 return rc;
729}
730
731/*
732 * Reads data from a certain offset page inside a PBA, including interleaved
733 * redundancy data. Returns (pagesize+64)*pages bytes in data.
734 */
735static int alauda_read_block_raw(struct us_data *us, u16 pba,
736 unsigned int page, unsigned int pages, unsigned char *data)
737{
738 int rc;
739 unsigned char command[] = {
740 ALAUDA_BULK_CMD, ALAUDA_BULK_READ_BLOCK, PBA_HI(pba),
741 PBA_ZONE(pba), 0, PBA_LO(pba) + page, pages, 0, MEDIA_PORT(us)
742 };
743
725 return rc;
726}
727
728/*
729 * Reads data from a certain offset page inside a PBA, including interleaved
730 * redundancy data. Returns (pagesize+64)*pages bytes in data.
731 */
732static int alauda_read_block_raw(struct us_data *us, u16 pba,
733 unsigned int page, unsigned int pages, unsigned char *data)
734{
735 int rc;
736 unsigned char command[] = {
737 ALAUDA_BULK_CMD, ALAUDA_BULK_READ_BLOCK, PBA_HI(pba),
738 PBA_ZONE(pba), 0, PBA_LO(pba) + page, pages, 0, MEDIA_PORT(us)
739 };
740
744 US_DEBUGP("alauda_read_block: pba %d page %d count %d\n",
745 pba, page, pages);
741 usb_stor_dbg(us, "pba %d page %d count %d\n", pba, page, pages);
746
747 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
748 command, 9, NULL);
749 if (rc != USB_STOR_XFER_GOOD)
750 return rc;
751
752 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
753 data, (MEDIA_INFO(us).pagesize + 64) * pages, NULL);

--- 34 unchanged lines hidden (view full) ---

788{
789 int rc;
790 struct alauda_info *info = (struct alauda_info *) us->extra;
791 unsigned char command[] = {
792 ALAUDA_BULK_CMD, ALAUDA_BULK_WRITE_BLOCK, PBA_HI(pba),
793 PBA_ZONE(pba), 0, PBA_LO(pba), 32, 0, MEDIA_PORT(us)
794 };
795
742
743 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
744 command, 9, NULL);
745 if (rc != USB_STOR_XFER_GOOD)
746 return rc;
747
748 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
749 data, (MEDIA_INFO(us).pagesize + 64) * pages, NULL);

--- 34 unchanged lines hidden (view full) ---

784{
785 int rc;
786 struct alauda_info *info = (struct alauda_info *) us->extra;
787 unsigned char command[] = {
788 ALAUDA_BULK_CMD, ALAUDA_BULK_WRITE_BLOCK, PBA_HI(pba),
789 PBA_ZONE(pba), 0, PBA_LO(pba), 32, 0, MEDIA_PORT(us)
790 };
791
796 US_DEBUGP("alauda_write_block: pba %d\n", pba);
792 usb_stor_dbg(us, "pba %d\n", pba);
797
798 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
799 command, 9, NULL);
800 if (rc != USB_STOR_XFER_GOOD)
801 return rc;
802
803 rc = usb_stor_bulk_transfer_buf(us, info->wr_ep, data,
804 (MEDIA_INFO(us).pagesize + 64) * MEDIA_INFO(us).blocksize,

--- 56 unchanged lines hidden (view full) ---

861 lbap ^= 1;
862
863 /* check old contents and fill lba */
864 for (i = 0; i < blocksize; i++) {
865 bptr = blockbuffer + (i * (pagesize + 64));
866 cptr = bptr + pagesize;
867 nand_compute_ecc(bptr, ecc);
868 if (!nand_compare_ecc(cptr+13, ecc)) {
793
794 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
795 command, 9, NULL);
796 if (rc != USB_STOR_XFER_GOOD)
797 return rc;
798
799 rc = usb_stor_bulk_transfer_buf(us, info->wr_ep, data,
800 (MEDIA_INFO(us).pagesize + 64) * MEDIA_INFO(us).blocksize,

--- 56 unchanged lines hidden (view full) ---

857 lbap ^= 1;
858
859 /* check old contents and fill lba */
860 for (i = 0; i < blocksize; i++) {
861 bptr = blockbuffer + (i * (pagesize + 64));
862 cptr = bptr + pagesize;
863 nand_compute_ecc(bptr, ecc);
864 if (!nand_compare_ecc(cptr+13, ecc)) {
869 US_DEBUGP("Warning: bad ecc in page %d- of pba %d\n",
870 i, pba);
865 usb_stor_dbg(us, "Warning: bad ecc in page %d- of pba %d\n",
866 i, pba);
871 nand_store_ecc(cptr+13, ecc);
872 }
873 nand_compute_ecc(bptr + (pagesize / 2), ecc);
874 if (!nand_compare_ecc(cptr+8, ecc)) {
867 nand_store_ecc(cptr+13, ecc);
868 }
869 nand_compute_ecc(bptr + (pagesize / 2), ecc);
870 if (!nand_compare_ecc(cptr+8, ecc)) {
875 US_DEBUGP("Warning: bad ecc in page %d+ of pba %d\n",
876 i, pba);
871 usb_stor_dbg(us, "Warning: bad ecc in page %d+ of pba %d\n",
872 i, pba);
877 nand_store_ecc(cptr+8, ecc);
878 }
879 cptr[6] = cptr[11] = MSB_of(lbap);
880 cptr[7] = cptr[12] = LSB_of(lbap);
881 }
882
883 /* copy in new stuff and compute ECC */
884 xptr = ptr;

--- 10 unchanged lines hidden (view full) ---

895
896 result = alauda_write_block(us, new_pba, blockbuffer);
897 if (result != USB_STOR_XFER_GOOD)
898 return result;
899
900 new_pba_offset = new_pba - (zone * zonesize);
901 MEDIA_INFO(us).pba_to_lba[zone][new_pba_offset] = lba;
902 MEDIA_INFO(us).lba_to_pba[zone][lba_offset] = new_pba;
873 nand_store_ecc(cptr+8, ecc);
874 }
875 cptr[6] = cptr[11] = MSB_of(lbap);
876 cptr[7] = cptr[12] = LSB_of(lbap);
877 }
878
879 /* copy in new stuff and compute ECC */
880 xptr = ptr;

--- 10 unchanged lines hidden (view full) ---

891
892 result = alauda_write_block(us, new_pba, blockbuffer);
893 if (result != USB_STOR_XFER_GOOD)
894 return result;
895
896 new_pba_offset = new_pba - (zone * zonesize);
897 MEDIA_INFO(us).pba_to_lba[zone][new_pba_offset] = lba;
898 MEDIA_INFO(us).lba_to_pba[zone][lba_offset] = new_pba;
903 US_DEBUGP("alauda_write_lba: Remapped LBA %d to PBA %d\n",
904 lba, new_pba);
899 usb_stor_dbg(us, "Remapped LBA %d to PBA %d\n", lba, new_pba);
905
906 if (pba != UNDEF) {
907 unsigned int pba_offset = pba - (zone * zonesize);
908 result = alauda_erase_block(us, pba);
909 if (result != USB_STOR_XFER_GOOD)
910 return result;
911 MEDIA_INFO(us).pba_to_lba[zone][pba_offset] = UNDEF;
912 }

--- 46 unchanged lines hidden (view full) ---

959 unsigned int zone = lba / uzonesize; /* integer division */
960 unsigned int lba_offset = lba - (zone * uzonesize);
961 unsigned int pages;
962 u16 pba;
963 alauda_ensure_map_for_zone(us, zone);
964
965 /* Not overflowing capacity? */
966 if (lba >= max_lba) {
900
901 if (pba != UNDEF) {
902 unsigned int pba_offset = pba - (zone * zonesize);
903 result = alauda_erase_block(us, pba);
904 if (result != USB_STOR_XFER_GOOD)
905 return result;
906 MEDIA_INFO(us).pba_to_lba[zone][pba_offset] = UNDEF;
907 }

--- 46 unchanged lines hidden (view full) ---

954 unsigned int zone = lba / uzonesize; /* integer division */
955 unsigned int lba_offset = lba - (zone * uzonesize);
956 unsigned int pages;
957 u16 pba;
958 alauda_ensure_map_for_zone(us, zone);
959
960 /* Not overflowing capacity? */
961 if (lba >= max_lba) {
967 US_DEBUGP("Error: Requested lba %u exceeds "
968 "maximum %u\n", lba, max_lba);
962 usb_stor_dbg(us, "Error: Requested lba %u exceeds maximum %u\n",
963 lba, max_lba);
969 result = USB_STOR_TRANSPORT_ERROR;
970 break;
971 }
972
973 /* Find number of pages we can read in this block */
974 pages = min(sectors, blocksize - page);
975 len = pages << pageshift;
976
977 /* Find where this lba lives on disk */
978 pba = MEDIA_INFO(us).lba_to_pba[zone][lba_offset];
979
980 if (pba == UNDEF) { /* this lba was never written */
964 result = USB_STOR_TRANSPORT_ERROR;
965 break;
966 }
967
968 /* Find number of pages we can read in this block */
969 pages = min(sectors, blocksize - page);
970 len = pages << pageshift;
971
972 /* Find where this lba lives on disk */
973 pba = MEDIA_INFO(us).lba_to_pba[zone][lba_offset];
974
975 if (pba == UNDEF) { /* this lba was never written */
981 US_DEBUGP("Read %d zero pages (LBA %d) page %d\n",
982 pages, lba, page);
976 usb_stor_dbg(us, "Read %d zero pages (LBA %d) page %d\n",
977 pages, lba, page);
983
984 /* This is not really an error. It just means
985 that the block has never been written.
986 Instead of returning USB_STOR_TRANSPORT_ERROR
987 it is better to return all zero data. */
988
989 memset(buffer, 0, len);
990 } else {
978
979 /* This is not really an error. It just means
980 that the block has never been written.
981 Instead of returning USB_STOR_TRANSPORT_ERROR
982 it is better to return all zero data. */
983
984 memset(buffer, 0, len);
985 } else {
991 US_DEBUGP("Read %d pages, from PBA %d"
992 " (LBA %d) page %d\n",
993 pages, pba, lba, page);
986 usb_stor_dbg(us, "Read %d pages, from PBA %d (LBA %d) page %d\n",
987 pages, pba, lba, page);
994
995 result = alauda_read_block(us, pba, page, pages, buffer);
996 if (result != USB_STOR_TRANSPORT_GOOD)
997 break;
998 }
999
1000 /* Store the data in the transfer buffer */
1001 usb_stor_access_xfer_buf(buffer, len, us->srb,

--- 59 unchanged lines hidden (view full) ---

1061
1062 while (sectors > 0) {
1063 /* Write as many sectors as possible in this block */
1064 unsigned int pages = min(sectors, blocksize - page);
1065 len = pages << pageshift;
1066
1067 /* Not overflowing capacity? */
1068 if (lba >= max_lba) {
988
989 result = alauda_read_block(us, pba, page, pages, buffer);
990 if (result != USB_STOR_TRANSPORT_GOOD)
991 break;
992 }
993
994 /* Store the data in the transfer buffer */
995 usb_stor_access_xfer_buf(buffer, len, us->srb,

--- 59 unchanged lines hidden (view full) ---

1055
1056 while (sectors > 0) {
1057 /* Write as many sectors as possible in this block */
1058 unsigned int pages = min(sectors, blocksize - page);
1059 len = pages << pageshift;
1060
1061 /* Not overflowing capacity? */
1062 if (lba >= max_lba) {
1069 US_DEBUGP("alauda_write_data: Requested lba %u exceeds "
1070 "maximum %u\n", lba, max_lba);
1063 usb_stor_dbg(us, "Requested lba %u exceeds maximum %u\n",
1064 lba, max_lba);
1071 result = USB_STOR_TRANSPORT_ERROR;
1072 break;
1073 }
1074
1075 /* Get the data from the transfer buffer */
1076 usb_stor_access_xfer_buf(buffer, len, us->srb,
1077 &sg, &offset, FROM_XFER_BUF);
1078

--- 38 unchanged lines hidden (view full) ---

1117 */
1118static int init_alauda(struct us_data *us)
1119{
1120 struct alauda_info *info;
1121 struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting;
1122 nand_init_ecc();
1123
1124 us->extra = kzalloc(sizeof(struct alauda_info), GFP_NOIO);
1065 result = USB_STOR_TRANSPORT_ERROR;
1066 break;
1067 }
1068
1069 /* Get the data from the transfer buffer */
1070 usb_stor_access_xfer_buf(buffer, len, us->srb,
1071 &sg, &offset, FROM_XFER_BUF);
1072

--- 38 unchanged lines hidden (view full) ---

1111 */
1112static int init_alauda(struct us_data *us)
1113{
1114 struct alauda_info *info;
1115 struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting;
1116 nand_init_ecc();
1117
1118 us->extra = kzalloc(sizeof(struct alauda_info), GFP_NOIO);
1125 if (!us->extra) {
1126 US_DEBUGP("init_alauda: Gah! Can't allocate storage for"
1127 "alauda info struct!\n");
1119 if (!us->extra)
1128 return USB_STOR_TRANSPORT_ERROR;
1120 return USB_STOR_TRANSPORT_ERROR;
1129 }
1121
1130 info = (struct alauda_info *) us->extra;
1131 us->extra_destructor = alauda_info_destructor;
1132
1133 info->wr_ep = usb_sndbulkpipe(us->pusb_dev,
1134 altsetting->endpoint[0].desc.bEndpointAddress
1135 & USB_ENDPOINT_NUMBER_MASK);
1136
1137 return USB_STOR_TRANSPORT_GOOD;

--- 4 unchanged lines hidden (view full) ---

1142 int rc;
1143 struct alauda_info *info = (struct alauda_info *) us->extra;
1144 unsigned char *ptr = us->iobuf;
1145 static unsigned char inquiry_response[36] = {
1146 0x00, 0x80, 0x00, 0x01, 0x1F, 0x00, 0x00, 0x00
1147 };
1148
1149 if (srb->cmnd[0] == INQUIRY) {
1122 info = (struct alauda_info *) us->extra;
1123 us->extra_destructor = alauda_info_destructor;
1124
1125 info->wr_ep = usb_sndbulkpipe(us->pusb_dev,
1126 altsetting->endpoint[0].desc.bEndpointAddress
1127 & USB_ENDPOINT_NUMBER_MASK);
1128
1129 return USB_STOR_TRANSPORT_GOOD;

--- 4 unchanged lines hidden (view full) ---

1134 int rc;
1135 struct alauda_info *info = (struct alauda_info *) us->extra;
1136 unsigned char *ptr = us->iobuf;
1137 static unsigned char inquiry_response[36] = {
1138 0x00, 0x80, 0x00, 0x01, 0x1F, 0x00, 0x00, 0x00
1139 };
1140
1141 if (srb->cmnd[0] == INQUIRY) {
1150 US_DEBUGP("alauda_transport: INQUIRY. "
1151 "Returning bogus response.\n");
1142 usb_stor_dbg(us, "INQUIRY - Returning bogus response\n");
1152 memcpy(ptr, inquiry_response, sizeof(inquiry_response));
1153 fill_inquiry_response(us, ptr, 36);
1154 return USB_STOR_TRANSPORT_GOOD;
1155 }
1156
1157 if (srb->cmnd[0] == TEST_UNIT_READY) {
1143 memcpy(ptr, inquiry_response, sizeof(inquiry_response));
1144 fill_inquiry_response(us, ptr, 36);
1145 return USB_STOR_TRANSPORT_GOOD;
1146 }
1147
1148 if (srb->cmnd[0] == TEST_UNIT_READY) {
1158 US_DEBUGP("alauda_transport: TEST_UNIT_READY.\n");
1149 usb_stor_dbg(us, "TEST_UNIT_READY\n");
1159 return alauda_check_media(us);
1160 }
1161
1162 if (srb->cmnd[0] == READ_CAPACITY) {
1163 unsigned int num_zones;
1164 unsigned long capacity;
1165
1166 rc = alauda_check_media(us);

--- 21 unchanged lines hidden (view full) ---

1188 if (rc != USB_STOR_TRANSPORT_GOOD)
1189 return rc;
1190
1191 page = short_pack(srb->cmnd[3], srb->cmnd[2]);
1192 page <<= 16;
1193 page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
1194 pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
1195
1150 return alauda_check_media(us);
1151 }
1152
1153 if (srb->cmnd[0] == READ_CAPACITY) {
1154 unsigned int num_zones;
1155 unsigned long capacity;
1156
1157 rc = alauda_check_media(us);

--- 21 unchanged lines hidden (view full) ---

1179 if (rc != USB_STOR_TRANSPORT_GOOD)
1180 return rc;
1181
1182 page = short_pack(srb->cmnd[3], srb->cmnd[2]);
1183 page <<= 16;
1184 page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
1185 pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
1186
1196 US_DEBUGP("alauda_transport: READ_10: page %d pagect %d\n",
1197 page, pages);
1187 usb_stor_dbg(us, "READ_10: page %d pagect %d\n", page, pages);
1198
1199 return alauda_read_data(us, page, pages);
1200 }
1201
1202 if (srb->cmnd[0] == WRITE_10) {
1203 unsigned int page, pages;
1204
1205 rc = alauda_check_media(us);
1206 if (rc != USB_STOR_TRANSPORT_GOOD)
1207 return rc;
1208
1209 page = short_pack(srb->cmnd[3], srb->cmnd[2]);
1210 page <<= 16;
1211 page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
1212 pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
1213
1188
1189 return alauda_read_data(us, page, pages);
1190 }
1191
1192 if (srb->cmnd[0] == WRITE_10) {
1193 unsigned int page, pages;
1194
1195 rc = alauda_check_media(us);
1196 if (rc != USB_STOR_TRANSPORT_GOOD)
1197 return rc;
1198
1199 page = short_pack(srb->cmnd[3], srb->cmnd[2]);
1200 page <<= 16;
1201 page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
1202 pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
1203
1214 US_DEBUGP("alauda_transport: WRITE_10: page %d pagect %d\n",
1215 page, pages);
1204 usb_stor_dbg(us, "WRITE_10: page %d pagect %d\n", page, pages);
1216
1217 return alauda_write_data(us, page, pages);
1218 }
1219
1220 if (srb->cmnd[0] == REQUEST_SENSE) {
1205
1206 return alauda_write_data(us, page, pages);
1207 }
1208
1209 if (srb->cmnd[0] == REQUEST_SENSE) {
1221 US_DEBUGP("alauda_transport: REQUEST_SENSE.\n");
1210 usb_stor_dbg(us, "REQUEST_SENSE\n");
1222
1223 memset(ptr, 0, 18);
1224 ptr[0] = 0xF0;
1225 ptr[2] = info->sense_key;
1226 ptr[7] = 11;
1227 ptr[12] = info->sense_asc;
1228 ptr[13] = info->sense_ascq;
1229 usb_stor_set_xfer_buf(ptr, 18, srb);
1230
1231 return USB_STOR_TRANSPORT_GOOD;
1232 }
1233
1234 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
1235 /* sure. whatever. not like we can stop the user from popping
1236 the media out of the device (no locking doors, etc) */
1237 return USB_STOR_TRANSPORT_GOOD;
1238 }
1239
1211
1212 memset(ptr, 0, 18);
1213 ptr[0] = 0xF0;
1214 ptr[2] = info->sense_key;
1215 ptr[7] = 11;
1216 ptr[12] = info->sense_asc;
1217 ptr[13] = info->sense_ascq;
1218 usb_stor_set_xfer_buf(ptr, 18, srb);
1219
1220 return USB_STOR_TRANSPORT_GOOD;
1221 }
1222
1223 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
1224 /* sure. whatever. not like we can stop the user from popping
1225 the media out of the device (no locking doors, etc) */
1226 return USB_STOR_TRANSPORT_GOOD;
1227 }
1228
1240 US_DEBUGP("alauda_transport: Gah! Unknown command: %d (0x%x)\n",
1241 srb->cmnd[0], srb->cmnd[0]);
1229 usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n",
1230 srb->cmnd[0], srb->cmnd[0]);
1242 info->sense_key = 0x05;
1243 info->sense_asc = 0x20;
1244 info->sense_ascq = 0x00;
1245 return USB_STOR_TRANSPORT_FAILED;
1246}
1247
1248static int alauda_probe(struct usb_interface *intf,
1249 const struct usb_device_id *id)

--- 33 unchanged lines hidden ---
1231 info->sense_key = 0x05;
1232 info->sense_asc = 0x20;
1233 info->sense_ascq = 0x00;
1234 return USB_STOR_TRANSPORT_FAILED;
1235}
1236
1237static int alauda_probe(struct usb_interface *intf,
1238 const struct usb_device_id *id)

--- 33 unchanged lines hidden ---