Lines Matching full:us

114 #define MEDIA_PORT(us) us->srb->device->lun  argument
115 #define MEDIA_INFO(us) ((struct alauda_info *)us->extra)->port[MEDIA_PORT(us)] argument
121 static int init_alauda(struct us_data *us);
308 static int alauda_get_media_status(struct us_data *us, unsigned char *data) in alauda_get_media_status() argument
313 if (MEDIA_PORT(us) == ALAUDA_PORT_XD) in alauda_get_media_status()
318 rc = usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe, in alauda_get_media_status()
321 usb_stor_dbg(us, "Media status %02X %02X\n", data[0], data[1]); in alauda_get_media_status()
330 static int alauda_ack_media(struct us_data *us) in alauda_ack_media() argument
334 if (MEDIA_PORT(us) == ALAUDA_PORT_XD) in alauda_ack_media()
339 return usb_stor_ctrl_transfer(us, us->send_ctrl_pipe, in alauda_ack_media()
347 static int alauda_get_media_signature(struct us_data *us, unsigned char *data) in alauda_get_media_signature() argument
351 if (MEDIA_PORT(us) == ALAUDA_PORT_XD) in alauda_get_media_signature()
356 return usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe, in alauda_get_media_signature()
363 static int alauda_reset_media(struct us_data *us) in alauda_reset_media() argument
365 unsigned char *command = us->iobuf; in alauda_reset_media()
370 command[8] = MEDIA_PORT(us); in alauda_reset_media()
372 return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_reset_media()
379 static int alauda_init_media(struct us_data *us) in alauda_init_media() argument
381 unsigned char *data = us->iobuf; in alauda_init_media()
389 if (alauda_get_media_status(us, data) != USB_STOR_XFER_GOOD) in alauda_init_media()
396 usb_stor_dbg(us, "We are ready for action!\n"); in alauda_init_media()
398 if (alauda_ack_media(us) != USB_STOR_XFER_GOOD) in alauda_init_media()
403 if (alauda_get_media_status(us, data) != USB_STOR_XFER_GOOD) in alauda_init_media()
407 usb_stor_dbg(us, "Media not ready after ack\n"); in alauda_init_media()
411 if (alauda_get_media_signature(us, data) != USB_STOR_XFER_GOOD) in alauda_init_media()
414 usb_stor_dbg(us, "Media signature: %4ph\n", data); in alauda_init_media()
422 MEDIA_INFO(us).capacity = 1 << media_info->chipshift; in alauda_init_media()
423 usb_stor_dbg(us, "Found media with capacity: %ldMB\n", in alauda_init_media()
424 MEDIA_INFO(us).capacity >> 20); in alauda_init_media()
426 MEDIA_INFO(us).pageshift = media_info->pageshift; in alauda_init_media()
427 MEDIA_INFO(us).blockshift = media_info->blockshift; in alauda_init_media()
428 MEDIA_INFO(us).zoneshift = media_info->zoneshift; in alauda_init_media()
430 MEDIA_INFO(us).pagesize = 1 << media_info->pageshift; in alauda_init_media()
431 MEDIA_INFO(us).blocksize = 1 << media_info->blockshift; in alauda_init_media()
432 MEDIA_INFO(us).zonesize = 1 << media_info->zoneshift; in alauda_init_media()
434 MEDIA_INFO(us).uzonesize = ((1 << media_info->zoneshift) / 128) * 125; in alauda_init_media()
435 MEDIA_INFO(us).blockmask = MEDIA_INFO(us).blocksize - 1; in alauda_init_media()
437 num_zones = MEDIA_INFO(us).capacity >> (MEDIA_INFO(us).zoneshift in alauda_init_media()
438 + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift); in alauda_init_media()
439 MEDIA_INFO(us).pba_to_lba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO); in alauda_init_media()
440 MEDIA_INFO(us).lba_to_pba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO); in alauda_init_media()
442 if (alauda_reset_media(us) != USB_STOR_XFER_GOOD) in alauda_init_media()
452 static int alauda_check_media(struct us_data *us) in alauda_check_media() argument
454 struct alauda_info *info = (struct alauda_info *) us->extra; in alauda_check_media()
457 alauda_get_media_status(us, status); in alauda_check_media()
462 usb_stor_dbg(us, "No media, or door open\n"); in alauda_check_media()
463 alauda_free_maps(&MEDIA_INFO(us)); in alauda_check_media()
472 usb_stor_dbg(us, "Media change detected\n"); in alauda_check_media()
473 alauda_free_maps(&MEDIA_INFO(us)); in alauda_check_media()
474 alauda_init_media(us); in alauda_check_media()
489 static int alauda_check_status2(struct us_data *us) in alauda_check_status2() argument
494 0, 0, 0, 0, 3, 0, MEDIA_PORT(us) in alauda_check_status2()
498 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_check_status2()
503 rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_check_status2()
508 usb_stor_dbg(us, "%3ph\n", data); in alauda_check_status2()
519 static int alauda_get_redu_data(struct us_data *us, u16 pba, unsigned char *data) in alauda_get_redu_data() argument
524 PBA_HI(pba), PBA_ZONE(pba), 0, PBA_LO(pba), 0, 0, MEDIA_PORT(us) in alauda_get_redu_data()
527 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_get_redu_data()
532 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_get_redu_data()
557 static int alauda_read_map(struct us_data *us, unsigned int zone) in alauda_read_map() argument
559 unsigned char *data = us->iobuf; in alauda_read_map()
562 unsigned int zonesize = MEDIA_INFO(us).zonesize; in alauda_read_map()
563 unsigned int uzonesize = MEDIA_INFO(us).uzonesize; in alauda_read_map()
574 usb_stor_dbg(us, "Mapping blocks for zone %d\n", zone); in alauda_read_map()
583 result = alauda_get_redu_data(us, blocknum, data); in alauda_read_map()
594 usb_stor_dbg(us, "PBA %d has no logical mapping\n", blocknum); in alauda_read_map()
607 …usb_stor_dbg(us, "PBA %d has no logical mapping: reserved area = %02X%02X%02X%02X data status %02X… in alauda_read_map()
616 usb_stor_dbg(us, "PBA %d has invalid address field %02X%02X/%02X%02X\n", in alauda_read_map()
665 MEDIA_INFO(us).lba_to_pba[zone] = lba_to_pba; in alauda_read_map()
666 MEDIA_INFO(us).pba_to_lba[zone] = pba_to_lba; in alauda_read_map()
681 static void alauda_ensure_map_for_zone(struct us_data *us, unsigned int zone) in alauda_ensure_map_for_zone() argument
683 if (MEDIA_INFO(us).lba_to_pba[zone] == NULL in alauda_ensure_map_for_zone()
684 || MEDIA_INFO(us).pba_to_lba[zone] == NULL) in alauda_ensure_map_for_zone()
685 alauda_read_map(us, zone); in alauda_ensure_map_for_zone()
691 static int alauda_erase_block(struct us_data *us, u16 pba) in alauda_erase_block() argument
696 PBA_ZONE(pba), 0, PBA_LO(pba), 0x02, 0, MEDIA_PORT(us) in alauda_erase_block()
700 usb_stor_dbg(us, "Erasing PBA %d\n", pba); in alauda_erase_block()
702 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_erase_block()
707 rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_erase_block()
712 usb_stor_dbg(us, "Erase result: %02X %02X\n", buf[0], buf[1]); in alauda_erase_block()
720 static int alauda_read_block_raw(struct us_data *us, u16 pba, in alauda_read_block_raw() argument
726 PBA_ZONE(pba), 0, PBA_LO(pba) + page, pages, 0, MEDIA_PORT(us) in alauda_read_block_raw()
729 usb_stor_dbg(us, "pba %d page %d count %d\n", pba, page, pages); in alauda_read_block_raw()
731 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_read_block_raw()
736 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_read_block_raw()
737 data, (MEDIA_INFO(us).pagesize + 64) * pages, NULL); in alauda_read_block_raw()
746 static int alauda_read_block(struct us_data *us, u16 pba, in alauda_read_block() argument
750 unsigned int pagesize = MEDIA_INFO(us).pagesize; in alauda_read_block()
752 rc = alauda_read_block_raw(us, pba, page, pages, data); in alauda_read_block()
771 static int alauda_write_block(struct us_data *us, u16 pba, unsigned char *data) in alauda_write_block() argument
774 struct alauda_info *info = (struct alauda_info *) us->extra; in alauda_write_block()
777 PBA_ZONE(pba), 0, PBA_LO(pba), 32, 0, MEDIA_PORT(us) in alauda_write_block()
780 usb_stor_dbg(us, "pba %d\n", pba); in alauda_write_block()
782 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_write_block()
787 rc = usb_stor_bulk_transfer_buf(us, info->wr_ep, data, in alauda_write_block()
788 (MEDIA_INFO(us).pagesize + 64) * MEDIA_INFO(us).blocksize, in alauda_write_block()
793 return alauda_check_status2(us); in alauda_write_block()
799 static int alauda_write_lba(struct us_data *us, u16 lba, in alauda_write_lba() argument
807 unsigned int uzonesize = MEDIA_INFO(us).uzonesize; in alauda_write_lba()
808 unsigned int zonesize = MEDIA_INFO(us).zonesize; in alauda_write_lba()
809 unsigned int pagesize = MEDIA_INFO(us).pagesize; in alauda_write_lba()
810 unsigned int blocksize = MEDIA_INFO(us).blocksize; in alauda_write_lba()
815 alauda_ensure_map_for_zone(us, zone); in alauda_write_lba()
817 pba = MEDIA_INFO(us).lba_to_pba[zone][lba_offset]; in alauda_write_lba()
828 new_pba = alauda_find_unused_pba(&MEDIA_INFO(us), zone); in alauda_write_lba()
837 result = alauda_read_block_raw(us, pba, 0, in alauda_write_lba()
855 usb_stor_dbg(us, "Warning: bad ecc in page %d- of pba %d\n", in alauda_write_lba()
861 usb_stor_dbg(us, "Warning: bad ecc in page %d+ of pba %d\n", in alauda_write_lba()
882 result = alauda_write_block(us, new_pba, blockbuffer); in alauda_write_lba()
887 MEDIA_INFO(us).pba_to_lba[zone][new_pba_offset] = lba; in alauda_write_lba()
888 MEDIA_INFO(us).lba_to_pba[zone][lba_offset] = new_pba; in alauda_write_lba()
889 usb_stor_dbg(us, "Remapped LBA %d to PBA %d\n", lba, new_pba); in alauda_write_lba()
893 result = alauda_erase_block(us, pba); in alauda_write_lba()
896 MEDIA_INFO(us).pba_to_lba[zone][pba_offset] = UNDEF; in alauda_write_lba()
905 static int alauda_read_data(struct us_data *us, unsigned long address, in alauda_read_data() argument
911 unsigned int blockshift = MEDIA_INFO(us).blockshift; in alauda_read_data()
912 unsigned int pageshift = MEDIA_INFO(us).pageshift; in alauda_read_data()
913 unsigned int blocksize = MEDIA_INFO(us).blocksize; in alauda_read_data()
914 unsigned int pagesize = MEDIA_INFO(us).pagesize; in alauda_read_data()
915 unsigned int uzonesize = MEDIA_INFO(us).uzonesize; in alauda_read_data()
934 page = (address & MEDIA_INFO(us).blockmask); in alauda_read_data()
935 max_lba = MEDIA_INFO(us).capacity >> (blockshift + pageshift); in alauda_read_data()
946 alauda_ensure_map_for_zone(us, zone); in alauda_read_data()
950 usb_stor_dbg(us, "Error: Requested lba %u exceeds maximum %u\n", in alauda_read_data()
961 pba = MEDIA_INFO(us).lba_to_pba[zone][lba_offset]; in alauda_read_data()
964 usb_stor_dbg(us, "Read %d zero pages (LBA %d) page %d\n", in alauda_read_data()
976 usb_stor_dbg(us, "Read %d pages, from PBA %d (LBA %d) page %d\n", in alauda_read_data()
979 result = alauda_read_block(us, pba, page, pages, buffer); in alauda_read_data()
985 usb_stor_access_xfer_buf(buffer, len, us->srb, in alauda_read_data()
1000 static int alauda_write_data(struct us_data *us, unsigned long address, in alauda_write_data() argument
1005 unsigned int blockshift = MEDIA_INFO(us).blockshift; in alauda_write_data()
1006 unsigned int pageshift = MEDIA_INFO(us).pageshift; in alauda_write_data()
1007 unsigned int blocksize = MEDIA_INFO(us).blocksize; in alauda_write_data()
1008 unsigned int pagesize = MEDIA_INFO(us).pagesize; in alauda_write_data()
1036 page = (address & MEDIA_INFO(us).blockmask); in alauda_write_data()
1037 max_lba = MEDIA_INFO(us).capacity >> (pageshift + blockshift); in alauda_write_data()
1050 usb_stor_dbg(us, "Requested lba %u exceeds maximum %u\n", in alauda_write_data()
1057 usb_stor_access_xfer_buf(buffer, len, us->srb, in alauda_write_data()
1060 result = alauda_write_lba(us, lba, page, pages, buffer, in alauda_write_data()
1099 static int init_alauda(struct us_data *us) in init_alauda() argument
1102 struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting; in init_alauda()
1105 us->extra = kzalloc(sizeof(struct alauda_info), GFP_NOIO); in init_alauda()
1106 if (!us->extra) in init_alauda()
1109 info = (struct alauda_info *) us->extra; in init_alauda()
1110 us->extra_destructor = alauda_info_destructor; in init_alauda()
1112 info->wr_ep = usb_sndbulkpipe(us->pusb_dev, in init_alauda()
1119 static int alauda_transport(struct scsi_cmnd *srb, struct us_data *us) in alauda_transport() argument
1122 struct alauda_info *info = (struct alauda_info *) us->extra; in alauda_transport()
1123 unsigned char *ptr = us->iobuf; in alauda_transport()
1129 usb_stor_dbg(us, "INQUIRY - Returning bogus response\n"); in alauda_transport()
1131 fill_inquiry_response(us, ptr, 36); in alauda_transport()
1136 usb_stor_dbg(us, "TEST_UNIT_READY\n"); in alauda_transport()
1137 return alauda_check_media(us); in alauda_transport()
1144 rc = alauda_check_media(us); in alauda_transport()
1148 num_zones = MEDIA_INFO(us).capacity >> (MEDIA_INFO(us).zoneshift in alauda_transport()
1149 + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift); in alauda_transport()
1151 capacity = num_zones * MEDIA_INFO(us).uzonesize in alauda_transport()
1152 * MEDIA_INFO(us).blocksize; in alauda_transport()
1165 rc = alauda_check_media(us); in alauda_transport()
1174 usb_stor_dbg(us, "READ_10: page %d pagect %d\n", page, pages); in alauda_transport()
1176 return alauda_read_data(us, page, pages); in alauda_transport()
1182 rc = alauda_check_media(us); in alauda_transport()
1191 usb_stor_dbg(us, "WRITE_10: page %d pagect %d\n", page, pages); in alauda_transport()
1193 return alauda_write_data(us, page, pages); in alauda_transport()
1197 usb_stor_dbg(us, "REQUEST_SENSE\n"); in alauda_transport()
1218 usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n", in alauda_transport()
1231 struct us_data *us; in alauda_probe() local
1234 result = usb_stor_probe1(&us, intf, id, in alauda_probe()
1240 us->transport_name = "Alauda Control/Bulk"; in alauda_probe()
1241 us->transport = alauda_transport; in alauda_probe()
1242 us->transport_reset = usb_stor_Bulk_reset; in alauda_probe()
1243 us->max_lun = 1; in alauda_probe()
1245 result = usb_stor_probe2(us); in alauda_probe()