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()
322 usb_stor_dbg(us, "Media status %02X %02X\n", data[0], data[1]); in alauda_get_media_status()
331 static int alauda_ack_media(struct us_data *us) in alauda_ack_media() argument
335 if (MEDIA_PORT(us) == ALAUDA_PORT_XD) in alauda_ack_media()
340 return usb_stor_ctrl_transfer(us, us->send_ctrl_pipe, in alauda_ack_media()
348 static int alauda_get_media_signature(struct us_data *us, unsigned char *data) in alauda_get_media_signature() argument
352 if (MEDIA_PORT(us) == ALAUDA_PORT_XD) in alauda_get_media_signature()
357 return usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe, in alauda_get_media_signature()
364 static int alauda_reset_media(struct us_data *us) in alauda_reset_media() argument
366 unsigned char *command = us->iobuf; in alauda_reset_media()
371 command[8] = MEDIA_PORT(us); in alauda_reset_media()
373 return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_reset_media()
380 static int alauda_init_media(struct us_data *us) in alauda_init_media() argument
382 unsigned char *data = us->iobuf; in alauda_init_media()
390 if (alauda_get_media_status(us, data) != USB_STOR_XFER_GOOD) in alauda_init_media()
397 usb_stor_dbg(us, "We are ready for action!\n"); in alauda_init_media()
399 if (alauda_ack_media(us) != USB_STOR_XFER_GOOD) in alauda_init_media()
404 if (alauda_get_media_status(us, data) != USB_STOR_XFER_GOOD) in alauda_init_media()
408 usb_stor_dbg(us, "Media not ready after ack\n"); in alauda_init_media()
412 if (alauda_get_media_signature(us, data) != USB_STOR_XFER_GOOD) in alauda_init_media()
415 usb_stor_dbg(us, "Media signature: %4ph\n", data); in alauda_init_media()
423 MEDIA_INFO(us).capacity = 1 << media_info->chipshift; in alauda_init_media()
424 usb_stor_dbg(us, "Found media with capacity: %ldMB\n", in alauda_init_media()
425 MEDIA_INFO(us).capacity >> 20); in alauda_init_media()
427 MEDIA_INFO(us).pageshift = media_info->pageshift; in alauda_init_media()
428 MEDIA_INFO(us).blockshift = media_info->blockshift; in alauda_init_media()
429 MEDIA_INFO(us).zoneshift = media_info->zoneshift; in alauda_init_media()
431 MEDIA_INFO(us).pagesize = 1 << media_info->pageshift; in alauda_init_media()
432 MEDIA_INFO(us).blocksize = 1 << media_info->blockshift; in alauda_init_media()
433 MEDIA_INFO(us).zonesize = 1 << media_info->zoneshift; in alauda_init_media()
435 MEDIA_INFO(us).uzonesize = ((1 << media_info->zoneshift) / 128) * 125; in alauda_init_media()
436 MEDIA_INFO(us).blockmask = MEDIA_INFO(us).blocksize - 1; in alauda_init_media()
438 num_zones = MEDIA_INFO(us).capacity >> (MEDIA_INFO(us).zoneshift in alauda_init_media()
439 + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift); in alauda_init_media()
440 MEDIA_INFO(us).pba_to_lba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO); in alauda_init_media()
441 MEDIA_INFO(us).lba_to_pba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO); in alauda_init_media()
442 if (MEDIA_INFO(us).pba_to_lba == NULL || MEDIA_INFO(us).lba_to_pba == NULL) in alauda_init_media()
445 if (alauda_reset_media(us) != USB_STOR_XFER_GOOD) in alauda_init_media()
455 static int alauda_check_media(struct us_data *us) in alauda_check_media() argument
457 struct alauda_info *info = (struct alauda_info *) us->extra; in alauda_check_media()
458 unsigned char *status = us->iobuf; in alauda_check_media()
461 rc = alauda_get_media_status(us, status); in alauda_check_media()
470 usb_stor_dbg(us, "No media, or door open\n"); in alauda_check_media()
471 alauda_free_maps(&MEDIA_INFO(us)); in alauda_check_media()
480 usb_stor_dbg(us, "Media change detected\n"); in alauda_check_media()
481 alauda_free_maps(&MEDIA_INFO(us)); in alauda_check_media()
482 alauda_init_media(us); in alauda_check_media()
497 static int alauda_check_status2(struct us_data *us) in alauda_check_status2() argument
502 0, 0, 0, 0, 3, 0, MEDIA_PORT(us) in alauda_check_status2()
506 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_check_status2()
511 rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_check_status2()
516 usb_stor_dbg(us, "%3ph\n", data); in alauda_check_status2()
527 static int alauda_get_redu_data(struct us_data *us, u16 pba, unsigned char *data) in alauda_get_redu_data() argument
532 PBA_HI(pba), PBA_ZONE(pba), 0, PBA_LO(pba), 0, 0, MEDIA_PORT(us) in alauda_get_redu_data()
535 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_get_redu_data()
540 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_get_redu_data()
565 static int alauda_read_map(struct us_data *us, unsigned int zone) in alauda_read_map() argument
567 unsigned char *data = us->iobuf; in alauda_read_map()
570 unsigned int zonesize = MEDIA_INFO(us).zonesize; in alauda_read_map()
571 unsigned int uzonesize = MEDIA_INFO(us).uzonesize; in alauda_read_map()
582 usb_stor_dbg(us, "Mapping blocks for zone %d\n", zone); in alauda_read_map()
591 result = alauda_get_redu_data(us, blocknum, data); in alauda_read_map()
602 usb_stor_dbg(us, "PBA %d has no logical mapping\n", blocknum); in alauda_read_map()
615 …usb_stor_dbg(us, "PBA %d has no logical mapping: reserved area = %02X%02X%02X%02X data status %02X… in alauda_read_map()
624 usb_stor_dbg(us, "PBA %d has invalid address field %02X%02X/%02X%02X\n", in alauda_read_map()
673 MEDIA_INFO(us).lba_to_pba[zone] = lba_to_pba; in alauda_read_map()
674 MEDIA_INFO(us).pba_to_lba[zone] = pba_to_lba; in alauda_read_map()
689 static void alauda_ensure_map_for_zone(struct us_data *us, unsigned int zone) in alauda_ensure_map_for_zone() argument
691 if (MEDIA_INFO(us).lba_to_pba[zone] == NULL in alauda_ensure_map_for_zone()
692 || MEDIA_INFO(us).pba_to_lba[zone] == NULL) in alauda_ensure_map_for_zone()
693 alauda_read_map(us, zone); in alauda_ensure_map_for_zone()
699 static int alauda_erase_block(struct us_data *us, u16 pba) in alauda_erase_block() argument
704 PBA_ZONE(pba), 0, PBA_LO(pba), 0x02, 0, MEDIA_PORT(us) in alauda_erase_block()
708 usb_stor_dbg(us, "Erasing PBA %d\n", pba); in alauda_erase_block()
710 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_erase_block()
715 rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_erase_block()
720 usb_stor_dbg(us, "Erase result: %02X %02X\n", buf[0], buf[1]); in alauda_erase_block()
728 static int alauda_read_block_raw(struct us_data *us, u16 pba, in alauda_read_block_raw() argument
734 PBA_ZONE(pba), 0, PBA_LO(pba) + page, pages, 0, MEDIA_PORT(us) in alauda_read_block_raw()
737 usb_stor_dbg(us, "pba %d page %d count %d\n", pba, page, pages); in alauda_read_block_raw()
739 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_read_block_raw()
744 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_read_block_raw()
745 data, (MEDIA_INFO(us).pagesize + 64) * pages, NULL); in alauda_read_block_raw()
754 static int alauda_read_block(struct us_data *us, u16 pba, in alauda_read_block() argument
758 unsigned int pagesize = MEDIA_INFO(us).pagesize; in alauda_read_block()
760 rc = alauda_read_block_raw(us, pba, page, pages, data); in alauda_read_block()
779 static int alauda_write_block(struct us_data *us, u16 pba, unsigned char *data) in alauda_write_block() argument
782 struct alauda_info *info = (struct alauda_info *) us->extra; in alauda_write_block()
785 PBA_ZONE(pba), 0, PBA_LO(pba), 32, 0, MEDIA_PORT(us) in alauda_write_block()
788 usb_stor_dbg(us, "pba %d\n", pba); in alauda_write_block()
790 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_write_block()
795 rc = usb_stor_bulk_transfer_buf(us, info->wr_ep, data, in alauda_write_block()
796 (MEDIA_INFO(us).pagesize + 64) * MEDIA_INFO(us).blocksize, in alauda_write_block()
801 return alauda_check_status2(us); in alauda_write_block()
807 static int alauda_write_lba(struct us_data *us, u16 lba, in alauda_write_lba() argument
815 unsigned int uzonesize = MEDIA_INFO(us).uzonesize; in alauda_write_lba()
816 unsigned int zonesize = MEDIA_INFO(us).zonesize; in alauda_write_lba()
817 unsigned int pagesize = MEDIA_INFO(us).pagesize; in alauda_write_lba()
818 unsigned int blocksize = MEDIA_INFO(us).blocksize; in alauda_write_lba()
823 alauda_ensure_map_for_zone(us, zone); in alauda_write_lba()
825 pba = MEDIA_INFO(us).lba_to_pba[zone][lba_offset]; in alauda_write_lba()
836 new_pba = alauda_find_unused_pba(&MEDIA_INFO(us), zone); in alauda_write_lba()
845 result = alauda_read_block_raw(us, pba, 0, in alauda_write_lba()
863 usb_stor_dbg(us, "Warning: bad ecc in page %d- of pba %d\n", in alauda_write_lba()
869 usb_stor_dbg(us, "Warning: bad ecc in page %d+ of pba %d\n", in alauda_write_lba()
890 result = alauda_write_block(us, new_pba, blockbuffer); in alauda_write_lba()
895 MEDIA_INFO(us).pba_to_lba[zone][new_pba_offset] = lba; in alauda_write_lba()
896 MEDIA_INFO(us).lba_to_pba[zone][lba_offset] = new_pba; in alauda_write_lba()
897 usb_stor_dbg(us, "Remapped LBA %d to PBA %d\n", lba, new_pba); in alauda_write_lba()
901 result = alauda_erase_block(us, pba); in alauda_write_lba()
904 MEDIA_INFO(us).pba_to_lba[zone][pba_offset] = UNDEF; in alauda_write_lba()
913 static int alauda_read_data(struct us_data *us, unsigned long address, in alauda_read_data() argument
919 unsigned int blockshift = MEDIA_INFO(us).blockshift; in alauda_read_data()
920 unsigned int pageshift = MEDIA_INFO(us).pageshift; in alauda_read_data()
921 unsigned int blocksize = MEDIA_INFO(us).blocksize; in alauda_read_data()
922 unsigned int pagesize = MEDIA_INFO(us).pagesize; in alauda_read_data()
923 unsigned int uzonesize = MEDIA_INFO(us).uzonesize; in alauda_read_data()
942 page = (address & MEDIA_INFO(us).blockmask); in alauda_read_data()
943 max_lba = MEDIA_INFO(us).capacity >> (blockshift + pageshift); in alauda_read_data()
954 alauda_ensure_map_for_zone(us, zone); in alauda_read_data()
958 usb_stor_dbg(us, "Error: Requested lba %u exceeds maximum %u\n", in alauda_read_data()
969 pba = MEDIA_INFO(us).lba_to_pba[zone][lba_offset]; in alauda_read_data()
972 usb_stor_dbg(us, "Read %d zero pages (LBA %d) page %d\n", in alauda_read_data()
984 usb_stor_dbg(us, "Read %d pages, from PBA %d (LBA %d) page %d\n", in alauda_read_data()
987 result = alauda_read_block(us, pba, page, pages, buffer); in alauda_read_data()
993 usb_stor_access_xfer_buf(buffer, len, us->srb, in alauda_read_data()
1008 static int alauda_write_data(struct us_data *us, unsigned long address, in alauda_write_data() argument
1013 unsigned int blockshift = MEDIA_INFO(us).blockshift; in alauda_write_data()
1014 unsigned int pageshift = MEDIA_INFO(us).pageshift; in alauda_write_data()
1015 unsigned int blocksize = MEDIA_INFO(us).blocksize; in alauda_write_data()
1016 unsigned int pagesize = MEDIA_INFO(us).pagesize; in alauda_write_data()
1044 page = (address & MEDIA_INFO(us).blockmask); in alauda_write_data()
1045 max_lba = MEDIA_INFO(us).capacity >> (pageshift + blockshift); in alauda_write_data()
1058 usb_stor_dbg(us, "Requested lba %u exceeds maximum %u\n", in alauda_write_data()
1065 usb_stor_access_xfer_buf(buffer, len, us->srb, in alauda_write_data()
1068 result = alauda_write_lba(us, lba, page, pages, buffer, in alauda_write_data()
1107 static int init_alauda(struct us_data *us) in init_alauda() argument
1110 struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting; in init_alauda()
1113 us->extra = kzalloc(sizeof(struct alauda_info), GFP_NOIO); in init_alauda()
1114 if (!us->extra) in init_alauda()
1117 info = (struct alauda_info *) us->extra; in init_alauda()
1118 us->extra_destructor = alauda_info_destructor; in init_alauda()
1120 info->wr_ep = usb_sndbulkpipe(us->pusb_dev, in init_alauda()
1127 static int alauda_transport(struct scsi_cmnd *srb, struct us_data *us) in alauda_transport() argument
1130 struct alauda_info *info = (struct alauda_info *) us->extra; in alauda_transport()
1131 unsigned char *ptr = us->iobuf; in alauda_transport()
1137 usb_stor_dbg(us, "INQUIRY - Returning bogus response\n"); in alauda_transport()
1139 fill_inquiry_response(us, ptr, 36); in alauda_transport()
1144 usb_stor_dbg(us, "TEST_UNIT_READY\n"); in alauda_transport()
1145 return alauda_check_media(us); in alauda_transport()
1152 rc = alauda_check_media(us); in alauda_transport()
1156 num_zones = MEDIA_INFO(us).capacity >> (MEDIA_INFO(us).zoneshift in alauda_transport()
1157 + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift); in alauda_transport()
1159 capacity = num_zones * MEDIA_INFO(us).uzonesize in alauda_transport()
1160 * MEDIA_INFO(us).blocksize; in alauda_transport()
1173 rc = alauda_check_media(us); in alauda_transport()
1182 usb_stor_dbg(us, "READ_10: page %d pagect %d\n", page, pages); in alauda_transport()
1184 return alauda_read_data(us, page, pages); in alauda_transport()
1190 rc = alauda_check_media(us); in alauda_transport()
1199 usb_stor_dbg(us, "WRITE_10: page %d pagect %d\n", page, pages); in alauda_transport()
1201 return alauda_write_data(us, page, pages); in alauda_transport()
1205 usb_stor_dbg(us, "REQUEST_SENSE\n"); in alauda_transport()
1226 usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n", in alauda_transport()
1239 struct us_data *us; in alauda_probe() local
1242 result = usb_stor_probe1(&us, intf, id, in alauda_probe()
1248 us->transport_name = "Alauda Control/Bulk"; in alauda_probe()
1249 us->transport = alauda_transport; in alauda_probe()
1250 us->transport_reset = usb_stor_Bulk_reset; in alauda_probe()
1251 us->max_lun = 1; in alauda_probe()
1253 result = usb_stor_probe2(us); in alauda_probe()