Lines Matching full:us
149 static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us);
150 static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us);
152 static int init_usbat_cd(struct us_data *us);
153 static int init_usbat_flash(struct us_data *us);
214 static int usbat_get_device_type(struct us_data *us) in usbat_get_device_type() argument
216 return ((struct usbat_info*)us->extra)->devicetype; in usbat_get_device_type()
222 static int usbat_read(struct us_data *us, in usbat_read() argument
227 return usb_stor_ctrl_transfer(us, in usbat_read()
228 us->recv_ctrl_pipe, in usbat_read()
240 static int usbat_write(struct us_data *us, in usbat_write() argument
245 return usb_stor_ctrl_transfer(us, in usbat_write()
246 us->send_ctrl_pipe, in usbat_write()
258 static int usbat_bulk_read(struct us_data *us, in usbat_bulk_read() argument
266 usb_stor_dbg(us, "len = %d\n", len); in usbat_bulk_read()
267 return usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe, buf, len, use_sg, NULL); in usbat_bulk_read()
273 static int usbat_bulk_write(struct us_data *us, in usbat_bulk_write() argument
281 usb_stor_dbg(us, "len = %d\n", len); in usbat_bulk_write()
282 return usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe, buf, len, use_sg, NULL); in usbat_bulk_write()
290 static int usbat_execute_command(struct us_data *us, in usbat_execute_command() argument
294 return usb_stor_ctrl_transfer(us, us->send_ctrl_pipe, in usbat_execute_command()
302 static int usbat_get_status(struct us_data *us, unsigned char *status) in usbat_get_status() argument
305 rc = usbat_read(us, USBAT_ATA, USBAT_ATA_STATUS, status); in usbat_get_status()
307 usb_stor_dbg(us, "0x%02X\n", *status); in usbat_get_status()
314 static int usbat_check_status(struct us_data *us) in usbat_check_status() argument
316 unsigned char *reply = us->iobuf; in usbat_check_status()
319 rc = usbat_get_status(us, reply); in usbat_check_status()
338 static int usbat_set_shuttle_features(struct us_data *us, in usbat_set_shuttle_features() argument
346 unsigned char *command = us->iobuf; in usbat_set_shuttle_features()
387 return usbat_execute_command(us, command, 8); in usbat_set_shuttle_features()
394 static int usbat_wait_not_busy(struct us_data *us, int minutes) in usbat_wait_not_busy() argument
398 unsigned char *status = us->iobuf; in usbat_wait_not_busy()
409 result = usbat_get_status(us, status); in usbat_wait_not_busy()
414 result = usbat_read(us, USBAT_ATA, 0x10, status); in usbat_wait_not_busy()
421 usb_stor_dbg(us, "Waited not busy for %d steps\n", i); in usbat_wait_not_busy()
435 usb_stor_dbg(us, "Waited not busy for %d minutes, timing out\n", in usbat_wait_not_busy()
443 static int usbat_read_block(struct us_data *us, in usbat_read_block() argument
449 unsigned char *command = us->iobuf; in usbat_read_block()
463 result = usbat_execute_command(us, command, 8); in usbat_read_block()
467 result = usbat_bulk_read(us, buf, len, use_sg); in usbat_read_block()
475 static int usbat_write_block(struct us_data *us, in usbat_write_block() argument
483 unsigned char *command = us->iobuf; in usbat_write_block()
497 result = usbat_execute_command(us, command, 8); in usbat_write_block()
502 result = usbat_bulk_write(us, buf, len, use_sg); in usbat_write_block()
506 return usbat_wait_not_busy(us, minutes); in usbat_write_block()
512 static int usbat_hp8200e_rw_block_test(struct us_data *us, in usbat_hp8200e_rw_block_test() argument
529 us->recv_bulk_pipe : us->send_bulk_pipe; in usbat_hp8200e_rw_block_test()
531 unsigned char *command = us->iobuf; in usbat_hp8200e_rw_block_test()
534 unsigned char *data = us->iobuf; in usbat_hp8200e_rw_block_test()
535 unsigned char *status = us->iobuf; in usbat_hp8200e_rw_block_test()
583 result = usbat_execute_command(us, command, cmdlen); in usbat_hp8200e_rw_block_test()
595 result = usbat_bulk_write(us, data, num_registers*2, 0); in usbat_hp8200e_rw_block_test()
601 result = usb_stor_bulk_transfer_sg(us, in usbat_hp8200e_rw_block_test()
632 if (usb_stor_clear_halt(us, in usbat_hp8200e_rw_block_test()
633 us->send_bulk_pipe) < 0) in usbat_hp8200e_rw_block_test()
641 result = usbat_read(us, USBAT_ATA, in usbat_hp8200e_rw_block_test()
653 usb_stor_dbg(us, "Redoing %s\n", in usbat_hp8200e_rw_block_test()
660 return usbat_wait_not_busy(us, minutes); in usbat_hp8200e_rw_block_test()
664 usb_stor_dbg(us, "Bummer! %s bulk data 20 times failed\n", in usbat_hp8200e_rw_block_test()
672 * Allows us to write specific data to any registers. The data to be written
677 static int usbat_multiple_write(struct us_data *us, in usbat_multiple_write() argument
683 unsigned char *data = us->iobuf; in usbat_multiple_write()
684 unsigned char *command = us->iobuf; in usbat_multiple_write()
703 result = usbat_execute_command(us, command, 8); in usbat_multiple_write()
714 result = usbat_bulk_write(us, data, num_registers*2, 0); in usbat_multiple_write()
718 if (usbat_get_device_type(us) == USBAT_DEV_HP8200) in usbat_multiple_write()
719 return usbat_wait_not_busy(us, 0); in usbat_multiple_write()
726 * Allows us to read blocks from a specific data register, based upon the
736 static int usbat_read_blocks(struct us_data *us, in usbat_read_blocks() argument
742 unsigned char *command = us->iobuf; in usbat_read_blocks()
754 result = usbat_execute_command(us, command, 8); in usbat_read_blocks()
759 result = usbat_bulk_read(us, buffer, len, use_sg); in usbat_read_blocks()
768 * Allows us to write blocks to a specific data register, based upon the
778 static int usbat_write_blocks(struct us_data *us, in usbat_write_blocks() argument
784 unsigned char *command = us->iobuf; in usbat_write_blocks()
796 result = usbat_execute_command(us, command, 8); in usbat_write_blocks()
801 result = usbat_bulk_write(us, buffer, len, use_sg); in usbat_write_blocks()
811 static int usbat_read_user_io(struct us_data *us, unsigned char *data_flags) in usbat_read_user_io() argument
815 result = usb_stor_ctrl_transfer(us, in usbat_read_user_io()
816 us->recv_ctrl_pipe, in usbat_read_user_io()
824 usb_stor_dbg(us, "UIO register reads %02X\n", *data_flags); in usbat_read_user_io()
832 static int usbat_write_user_io(struct us_data *us, in usbat_write_user_io() argument
836 return usb_stor_ctrl_transfer(us, in usbat_write_user_io()
837 us->send_ctrl_pipe, in usbat_write_user_io()
850 static int usbat_device_reset(struct us_data *us) in usbat_device_reset() argument
858 rc = usbat_write_user_io(us, in usbat_device_reset()
868 rc = usbat_write_user_io(us, in usbat_device_reset()
880 static int usbat_device_enable_cdt(struct us_data *us) in usbat_device_enable_cdt() argument
885 rc = usbat_write_user_io(us, in usbat_device_enable_cdt()
897 static int usbat_flash_check_media_present(struct us_data *us, in usbat_flash_check_media_present() argument
901 usb_stor_dbg(us, "no media detected\n"); in usbat_flash_check_media_present()
911 static int usbat_flash_check_media_changed(struct us_data *us, in usbat_flash_check_media_changed() argument
915 usb_stor_dbg(us, "media change detected\n"); in usbat_flash_check_media_changed()
925 static int usbat_flash_check_media(struct us_data *us, in usbat_flash_check_media() argument
929 unsigned char *uio = us->iobuf; in usbat_flash_check_media()
931 rc = usbat_read_user_io(us, uio); in usbat_flash_check_media()
936 rc = usbat_flash_check_media_present(us, uio); in usbat_flash_check_media()
945 rc = usbat_flash_check_media_changed(us, uio); in usbat_flash_check_media()
949 rc = usbat_device_reset(us); in usbat_flash_check_media()
952 rc = usbat_device_enable_cdt(us); in usbat_flash_check_media()
958 rc = usbat_read_user_io(us, uio); in usbat_flash_check_media()
976 static int usbat_identify_device(struct us_data *us, in usbat_identify_device() argument
982 if (!us || !info) in usbat_identify_device()
985 rc = usbat_device_reset(us); in usbat_identify_device()
996 rc = usbat_write(us, USBAT_ATA, USBAT_ATA_CMD, 0xA1); in usbat_identify_device()
1000 rc = usbat_get_status(us, &status); in usbat_identify_device()
1007 usb_stor_dbg(us, "Detected HP8200 CDRW\n"); in usbat_identify_device()
1011 usb_stor_dbg(us, "Detected Flash reader/writer\n"); in usbat_identify_device()
1021 static int usbat_set_transport(struct us_data *us, in usbat_set_transport() argument
1030 usbat_identify_device(us, info); in usbat_set_transport()
1037 us->transport = usbat_hp8200e_transport; in usbat_set_transport()
1041 us->transport = usbat_flash_transport; in usbat_set_transport()
1051 static int usbat_flash_get_sector_count(struct us_data *us, in usbat_flash_get_sector_count() argument
1064 if (!us || !info) in usbat_flash_get_sector_count()
1072 rc = usbat_multiple_write(us, registers, command, 3); in usbat_flash_get_sector_count()
1074 usb_stor_dbg(us, "Gah! identify_device failed\n"); in usbat_flash_get_sector_count()
1080 if (usbat_get_status(us, &status) != USB_STOR_XFER_GOOD) { in usbat_flash_get_sector_count()
1088 rc = usbat_read_block(us, reply, 512, 0); in usbat_flash_get_sector_count()
1107 static int usbat_flash_read_data(struct us_data *us, in usbat_flash_read_data() argument
1129 result = usbat_flash_check_media(us, info); in usbat_flash_read_data()
1168 result = usbat_multiple_write(us, registers, command, 7); in usbat_flash_read_data()
1173 result = usbat_read_blocks(us, buffer, len, 0); in usbat_flash_read_data()
1177 usb_stor_dbg(us, "%d bytes\n", len); in usbat_flash_read_data()
1180 usb_stor_access_xfer_buf(buffer, len, us->srb, in usbat_flash_read_data()
1198 static int usbat_flash_write_data(struct us_data *us, in usbat_flash_write_data() argument
1220 result = usbat_flash_check_media(us, info); in usbat_flash_write_data()
1256 usb_stor_access_xfer_buf(buffer, len, us->srb, in usbat_flash_write_data()
1263 result = usbat_multiple_write(us, registers, command, 7); in usbat_flash_write_data()
1268 result = usbat_write_blocks(us, buffer, len, 0); in usbat_flash_write_data()
1288 static int usbat_hp8200e_handle_read10(struct us_data *us, in usbat_hp8200e_handle_read10() argument
1300 usb_stor_dbg(us, "transfersize %d\n", srb->transfersize); in usbat_hp8200e_handle_read10()
1304 result = usbat_hp8200e_rw_block_test(us, USBAT_ATA, in usbat_hp8200e_handle_read10()
1327 usb_stor_dbg(us, "GPCMD_READ_CD: len %d\n", len); in usbat_hp8200e_handle_read10()
1333 usb_stor_dbg(us, "transfersize 0, forcing %d\n", in usbat_hp8200e_handle_read10()
1344 usb_stor_dbg(us, "Max read is %d bytes\n", len); in usbat_hp8200e_handle_read10()
1373 result = usbat_hp8200e_rw_block_test(us, USBAT_ATA, in usbat_hp8200e_handle_read10()
1399 static int usbat_select_and_test_registers(struct us_data *us) in usbat_select_and_test_registers() argument
1402 unsigned char *status = us->iobuf; in usbat_select_and_test_registers()
1406 if (usbat_write(us, USBAT_ATA, USBAT_ATA_DEVICE, selector) != in usbat_select_and_test_registers()
1410 if (usbat_read(us, USBAT_ATA, USBAT_ATA_STATUS, status) != in usbat_select_and_test_registers()
1414 if (usbat_read(us, USBAT_ATA, USBAT_ATA_DEVICE, status) != in usbat_select_and_test_registers()
1418 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) != in usbat_select_and_test_registers()
1422 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_HI, status) != in usbat_select_and_test_registers()
1426 if (usbat_write(us, USBAT_ATA, USBAT_ATA_LBA_ME, 0x55) != in usbat_select_and_test_registers()
1430 if (usbat_write(us, USBAT_ATA, USBAT_ATA_LBA_HI, 0xAA) != in usbat_select_and_test_registers()
1434 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) != in usbat_select_and_test_registers()
1438 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) != in usbat_select_and_test_registers()
1449 static int init_usbat(struct us_data *us, int devicetype) in init_usbat() argument
1455 unsigned char *status = us->iobuf; in init_usbat()
1457 us->extra = kzalloc(sizeof(struct usbat_info), GFP_NOIO); in init_usbat()
1458 if (!us->extra) in init_usbat()
1461 info = (struct usbat_info *) (us->extra); in init_usbat()
1464 rc = usbat_write_user_io(us, in init_usbat()
1470 usb_stor_dbg(us, "INIT 1\n"); in init_usbat()
1474 rc = usbat_read_user_io(us, status); in init_usbat()
1478 usb_stor_dbg(us, "INIT 2\n"); in init_usbat()
1480 rc = usbat_read_user_io(us, status); in init_usbat()
1484 rc = usbat_read_user_io(us, status); in init_usbat()
1488 usb_stor_dbg(us, "INIT 3\n"); in init_usbat()
1490 rc = usbat_select_and_test_registers(us); in init_usbat()
1494 usb_stor_dbg(us, "INIT 4\n"); in init_usbat()
1496 rc = usbat_read_user_io(us, status); in init_usbat()
1500 usb_stor_dbg(us, "INIT 5\n"); in init_usbat()
1503 rc = usbat_device_enable_cdt(us); in init_usbat()
1507 usb_stor_dbg(us, "INIT 6\n"); in init_usbat()
1509 rc = usbat_read_user_io(us, status); in init_usbat()
1513 usb_stor_dbg(us, "INIT 7\n"); in init_usbat()
1517 rc = usbat_read_user_io(us, status); in init_usbat()
1521 usb_stor_dbg(us, "INIT 8\n"); in init_usbat()
1523 rc = usbat_select_and_test_registers(us); in init_usbat()
1527 usb_stor_dbg(us, "INIT 9\n"); in init_usbat()
1530 if (usbat_set_transport(us, info, devicetype)) in init_usbat()
1533 usb_stor_dbg(us, "INIT 10\n"); in init_usbat()
1535 if (usbat_get_device_type(us) == USBAT_DEV_FLASH) { in init_usbat()
1539 rc = usbat_set_shuttle_features(us, (USBAT_FEAT_ETEN | USBAT_FEAT_ET2 | USBAT_FEAT_ET1), in init_usbat()
1544 usb_stor_dbg(us, "INIT 11\n"); in init_usbat()
1552 static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us) in usbat_hp8200e_transport() argument
1555 unsigned char *status = us->iobuf; in usbat_hp8200e_transport()
1589 result = usbat_get_status(us, status); in usbat_hp8200e_transport()
1590 usb_stor_dbg(us, "Status = %02X\n", *status); in usbat_hp8200e_transport()
1598 result = usbat_hp8200e_rw_block_test(us, USBAT_ATA, in usbat_hp8200e_transport()
1608 usb_stor_dbg(us, "Wrote %08X bytes\n", transferred); in usbat_hp8200e_transport()
1616 return usbat_hp8200e_handle_read10(us, registers, data, srb); in usbat_hp8200e_transport()
1621 usb_stor_dbg(us, "Error: len = %08X... what do I do now?\n", in usbat_hp8200e_transport()
1626 result = usbat_multiple_write(us, registers, data, 7); in usbat_hp8200e_transport()
1641 result = usbat_write_block(us, USBAT_ATA, srb->cmnd, 12, in usbat_hp8200e_transport()
1653 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) != in usbat_hp8200e_transport()
1660 if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_HI, status) != in usbat_hp8200e_transport()
1670 result = usbat_read_block(us, scsi_sglist(srb), len, in usbat_hp8200e_transport()
1680 static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us) in usbat_flash_transport() argument
1683 struct usbat_info *info = (struct usbat_info *) (us->extra); in usbat_flash_transport()
1685 unsigned char *ptr = us->iobuf; in usbat_flash_transport()
1691 usb_stor_dbg(us, "INQUIRY - Returning bogus response\n"); in usbat_flash_transport()
1693 fill_inquiry_response(us, ptr, 36); in usbat_flash_transport()
1698 rc = usbat_flash_check_media(us, info); in usbat_flash_transport()
1702 rc = usbat_flash_get_sector_count(us, info); in usbat_flash_transport()
1708 usb_stor_dbg(us, "READ_CAPACITY: %ld sectors, %ld bytes per sector\n", in usbat_flash_transport()
1724 usb_stor_dbg(us, "Gah! MODE_SELECT_10\n"); in usbat_flash_transport()
1734 usb_stor_dbg(us, "READ_10: read block 0x%04lx count %ld\n", in usbat_flash_transport()
1736 return usbat_flash_read_data(us, info, block, blocks); in usbat_flash_transport()
1749 usb_stor_dbg(us, "READ_12: read block 0x%04lx count %ld\n", in usbat_flash_transport()
1751 return usbat_flash_read_data(us, info, block, blocks); in usbat_flash_transport()
1760 usb_stor_dbg(us, "WRITE_10: write block 0x%04lx count %ld\n", in usbat_flash_transport()
1762 return usbat_flash_write_data(us, info, block, blocks); in usbat_flash_transport()
1775 usb_stor_dbg(us, "WRITE_12: write block 0x%04lx count %ld\n", in usbat_flash_transport()
1777 return usbat_flash_write_data(us, info, block, blocks); in usbat_flash_transport()
1782 usb_stor_dbg(us, "TEST_UNIT_READY\n"); in usbat_flash_transport()
1784 rc = usbat_flash_check_media(us, info); in usbat_flash_transport()
1788 return usbat_check_status(us); in usbat_flash_transport()
1792 usb_stor_dbg(us, "REQUEST_SENSE\n"); in usbat_flash_transport()
1813 usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n", in usbat_flash_transport()
1821 static int init_usbat_cd(struct us_data *us) in init_usbat_cd() argument
1823 return init_usbat(us, USBAT_DEV_HP8200); in init_usbat_cd()
1826 static int init_usbat_flash(struct us_data *us) in init_usbat_flash() argument
1828 return init_usbat(us, USBAT_DEV_FLASH); in init_usbat_flash()
1836 struct us_data *us; in usbat_probe() local
1839 result = usb_stor_probe1(&us, intf, id, in usbat_probe()
1849 us->transport_name = "Shuttle USBAT"; in usbat_probe()
1850 us->transport = usbat_flash_transport; in usbat_probe()
1851 us->transport_reset = usb_stor_CB_reset; in usbat_probe()
1852 us->max_lun = 0; in usbat_probe()
1854 result = usb_stor_probe2(us); in usbat_probe()