Lines Matching refs:us
48 #define MEDIA_PORT(us) us->srb->device->lun argument
49 #define MEDIA_INFO(us) ((struct alauda_info *)us->extra)->port[MEDIA_PORT(us)] argument
199 static int alauda_get_media_status(struct us_data *us, unsigned char *data) in alauda_get_media_status() argument
204 if (MEDIA_PORT(us) == ALAUDA_PORT_XD) in alauda_get_media_status()
209 rc = usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe, in alauda_get_media_status()
222 static int alauda_ack_media(struct us_data *us) in alauda_ack_media() argument
226 if (MEDIA_PORT(us) == ALAUDA_PORT_XD) in alauda_ack_media()
231 return usb_stor_ctrl_transfer(us, us->send_ctrl_pipe, in alauda_ack_media()
239 static int alauda_get_media_signature(struct us_data *us, unsigned char *data) in alauda_get_media_signature() argument
243 if (MEDIA_PORT(us) == ALAUDA_PORT_XD) in alauda_get_media_signature()
248 return usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe, in alauda_get_media_signature()
255 static int alauda_reset_media(struct us_data *us) in alauda_reset_media() argument
257 unsigned char *command = us->iobuf; in alauda_reset_media()
262 command[8] = MEDIA_PORT(us); in alauda_reset_media()
264 return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_reset_media()
271 static int alauda_init_media(struct us_data *us) in alauda_init_media() argument
273 unsigned char *data = us->iobuf; in alauda_init_media()
281 if (alauda_get_media_status(us, data) != USB_STOR_XFER_GOOD) in alauda_init_media()
290 if (alauda_ack_media(us) != USB_STOR_XFER_GOOD) in alauda_init_media()
295 if (alauda_get_media_status(us, data) != USB_STOR_XFER_GOOD) in alauda_init_media()
303 if (alauda_get_media_signature(us, data) != USB_STOR_XFER_GOOD) in alauda_init_media()
316 MEDIA_INFO(us).capacity = 1 << media_info->chipshift; in alauda_init_media()
318 MEDIA_INFO(us).capacity >> 20); in alauda_init_media()
320 MEDIA_INFO(us).pageshift = media_info->pageshift; in alauda_init_media()
321 MEDIA_INFO(us).blockshift = media_info->blockshift; in alauda_init_media()
322 MEDIA_INFO(us).zoneshift = media_info->zoneshift; in alauda_init_media()
324 MEDIA_INFO(us).pagesize = 1 << media_info->pageshift; in alauda_init_media()
325 MEDIA_INFO(us).blocksize = 1 << media_info->blockshift; in alauda_init_media()
326 MEDIA_INFO(us).zonesize = 1 << media_info->zoneshift; in alauda_init_media()
328 MEDIA_INFO(us).uzonesize = ((1 << media_info->zoneshift) / 128) * 125; in alauda_init_media()
329 MEDIA_INFO(us).blockmask = MEDIA_INFO(us).blocksize - 1; in alauda_init_media()
331 num_zones = MEDIA_INFO(us).capacity >> (MEDIA_INFO(us).zoneshift in alauda_init_media()
332 + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift); in alauda_init_media()
333 MEDIA_INFO(us).pba_to_lba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO); in alauda_init_media()
334 MEDIA_INFO(us).lba_to_pba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO); in alauda_init_media()
336 if (alauda_reset_media(us) != USB_STOR_XFER_GOOD) in alauda_init_media()
346 static int alauda_check_media(struct us_data *us) in alauda_check_media() argument
348 struct alauda_info *info = (struct alauda_info *) us->extra; in alauda_check_media()
352 rc = alauda_get_media_status(us, status); in alauda_check_media()
358 alauda_free_maps(&MEDIA_INFO(us)); in alauda_check_media()
368 alauda_free_maps(&MEDIA_INFO(us)); in alauda_check_media()
369 alauda_init_media(us); in alauda_check_media()
384 static int alauda_check_status2(struct us_data *us) in alauda_check_status2() argument
389 0, 0, 0, 0, 3, 0, MEDIA_PORT(us) in alauda_check_status2()
393 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_check_status2()
398 rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_check_status2()
414 static int alauda_get_redu_data(struct us_data *us, u16 pba, unsigned char *data) in alauda_get_redu_data() argument
419 PBA_HI(pba), PBA_ZONE(pba), 0, PBA_LO(pba), 0, 0, MEDIA_PORT(us) in alauda_get_redu_data()
422 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_get_redu_data()
427 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_get_redu_data()
452 static int alauda_read_map(struct us_data *us, unsigned int zone) in alauda_read_map() argument
454 unsigned char *data = us->iobuf; in alauda_read_map()
457 unsigned int zonesize = MEDIA_INFO(us).zonesize; in alauda_read_map()
458 unsigned int uzonesize = MEDIA_INFO(us).uzonesize; in alauda_read_map()
478 result = alauda_get_redu_data(us, blocknum, data); in alauda_read_map()
557 MEDIA_INFO(us).lba_to_pba[zone] = lba_to_pba; in alauda_read_map()
558 MEDIA_INFO(us).pba_to_lba[zone] = pba_to_lba; in alauda_read_map()
573 static void alauda_ensure_map_for_zone(struct us_data *us, unsigned int zone) in alauda_ensure_map_for_zone() argument
575 if (MEDIA_INFO(us).lba_to_pba[zone] == NULL in alauda_ensure_map_for_zone()
576 || MEDIA_INFO(us).pba_to_lba[zone] == NULL) in alauda_ensure_map_for_zone()
577 alauda_read_map(us, zone); in alauda_ensure_map_for_zone()
583 static int alauda_erase_block(struct us_data *us, u16 pba) in alauda_erase_block() argument
588 PBA_ZONE(pba), 0, PBA_LO(pba), 0x02, 0, MEDIA_PORT(us) in alauda_erase_block()
594 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_erase_block()
599 rc = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_erase_block()
613 static int alauda_read_block_raw(struct us_data *us, u16 pba, in alauda_read_block_raw() argument
619 PBA_ZONE(pba), 0, PBA_LO(pba) + page, pages, 0, MEDIA_PORT(us) in alauda_read_block_raw()
625 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_read_block_raw()
630 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, in alauda_read_block_raw()
631 data, (MEDIA_INFO(us).pagesize + 64) * pages, NULL); in alauda_read_block_raw()
640 static int alauda_read_block(struct us_data *us, u16 pba, in alauda_read_block() argument
644 unsigned int pagesize = MEDIA_INFO(us).pagesize; in alauda_read_block()
646 rc = alauda_read_block_raw(us, pba, page, pages, data); in alauda_read_block()
665 static int alauda_write_block(struct us_data *us, u16 pba, unsigned char *data) in alauda_write_block() argument
668 struct alauda_info *info = (struct alauda_info *) us->extra; in alauda_write_block()
671 PBA_ZONE(pba), 0, PBA_LO(pba), 32, 0, MEDIA_PORT(us) in alauda_write_block()
676 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, in alauda_write_block()
681 rc = usb_stor_bulk_transfer_buf(us, info->wr_ep, data, in alauda_write_block()
682 (MEDIA_INFO(us).pagesize + 64) * MEDIA_INFO(us).blocksize, in alauda_write_block()
687 return alauda_check_status2(us); in alauda_write_block()
693 static int alauda_write_lba(struct us_data *us, u16 lba, in alauda_write_lba() argument
701 unsigned int uzonesize = MEDIA_INFO(us).uzonesize; in alauda_write_lba()
702 unsigned int zonesize = MEDIA_INFO(us).zonesize; in alauda_write_lba()
703 unsigned int pagesize = MEDIA_INFO(us).pagesize; in alauda_write_lba()
704 unsigned int blocksize = MEDIA_INFO(us).blocksize; in alauda_write_lba()
709 alauda_ensure_map_for_zone(us, zone); in alauda_write_lba()
711 pba = MEDIA_INFO(us).lba_to_pba[zone][lba_offset]; in alauda_write_lba()
719 new_pba = alauda_find_unused_pba(&MEDIA_INFO(us), zone); in alauda_write_lba()
727 result = alauda_read_block_raw(us, pba, 0, in alauda_write_lba()
772 result = alauda_write_block(us, new_pba, blockbuffer); in alauda_write_lba()
777 MEDIA_INFO(us).pba_to_lba[zone][new_pba_offset] = lba; in alauda_write_lba()
778 MEDIA_INFO(us).lba_to_pba[zone][lba_offset] = new_pba; in alauda_write_lba()
784 result = alauda_erase_block(us, pba); in alauda_write_lba()
787 MEDIA_INFO(us).pba_to_lba[zone][pba_offset] = UNDEF; in alauda_write_lba()
796 static int alauda_read_data(struct us_data *us, unsigned long address, in alauda_read_data() argument
802 unsigned int blockshift = MEDIA_INFO(us).blockshift; in alauda_read_data()
803 unsigned int pageshift = MEDIA_INFO(us).pageshift; in alauda_read_data()
804 unsigned int blocksize = MEDIA_INFO(us).blocksize; in alauda_read_data()
805 unsigned int pagesize = MEDIA_INFO(us).pagesize; in alauda_read_data()
806 unsigned int uzonesize = MEDIA_INFO(us).uzonesize; in alauda_read_data()
827 page = (address & MEDIA_INFO(us).blockmask); in alauda_read_data()
828 max_lba = MEDIA_INFO(us).capacity >> (blockshift + pageshift); in alauda_read_data()
839 alauda_ensure_map_for_zone(us, zone); in alauda_read_data()
854 pba = MEDIA_INFO(us).lba_to_pba[zone][lba_offset]; in alauda_read_data()
871 result = alauda_read_block(us, pba, page, pages, buffer); in alauda_read_data()
877 usb_stor_access_xfer_buf(buffer, len, us->srb, in alauda_read_data()
892 static int alauda_write_data(struct us_data *us, unsigned long address, in alauda_write_data() argument
897 unsigned int blockshift = MEDIA_INFO(us).blockshift; in alauda_write_data()
898 unsigned int pageshift = MEDIA_INFO(us).pageshift; in alauda_write_data()
899 unsigned int blocksize = MEDIA_INFO(us).blocksize; in alauda_write_data()
900 unsigned int pagesize = MEDIA_INFO(us).pagesize; in alauda_write_data()
931 page = (address & MEDIA_INFO(us).blockmask); in alauda_write_data()
932 max_lba = MEDIA_INFO(us).capacity >> (pageshift + blockshift); in alauda_write_data()
952 usb_stor_access_xfer_buf(buffer, len, us->srb, in alauda_write_data()
955 result = alauda_write_lba(us, lba, page, pages, buffer, in alauda_write_data()
994 int init_alauda(struct us_data *us) in init_alauda() argument
997 struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting; in init_alauda()
1000 us->extra = kzalloc(sizeof(struct alauda_info), GFP_NOIO); in init_alauda()
1001 if (!us->extra) { in init_alauda()
1006 info = (struct alauda_info *) us->extra; in init_alauda()
1007 us->extra_destructor = alauda_info_destructor; in init_alauda()
1009 info->wr_ep = usb_sndbulkpipe(us->pusb_dev, in init_alauda()
1016 int alauda_transport(struct scsi_cmnd *srb, struct us_data *us) in alauda_transport() argument
1019 struct alauda_info *info = (struct alauda_info *) us->extra; in alauda_transport()
1020 unsigned char *ptr = us->iobuf; in alauda_transport()
1029 fill_inquiry_response(us, ptr, 36); in alauda_transport()
1035 return alauda_check_media(us); in alauda_transport()
1042 rc = alauda_check_media(us); in alauda_transport()
1046 num_zones = MEDIA_INFO(us).capacity >> (MEDIA_INFO(us).zoneshift in alauda_transport()
1047 + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift); in alauda_transport()
1049 capacity = num_zones * MEDIA_INFO(us).uzonesize in alauda_transport()
1050 * MEDIA_INFO(us).blocksize; in alauda_transport()
1063 rc = alauda_check_media(us); in alauda_transport()
1075 return alauda_read_data(us, page, pages); in alauda_transport()
1081 rc = alauda_check_media(us); in alauda_transport()
1093 return alauda_write_data(us, page, pages); in alauda_transport()