Lines Matching +full:detect +full:- +full:us
1 // SPDX-License-Identifier: GPL-2.0+
3 * Transport & Protocol Driver for In-System Design, Inc. ISD200 ASIC
6 * (C) 2001-2002 Björn Stenberg (bjorn@haxx.se)
12 * (C) 2000 In-System Design, Inc. (support@in-system.com)
20 * 2002-10-19: Removed the specialized transfer routines.
22 * 2001-02-24: Removed lots of duplicate code and simplified the structure.
24 * 2002-01-16: Fixed endianness bug so it works on the ppc arch.
26 * 2002-01-17: All bitfields removed.
51 #define DRV_NAME "ums-isd200"
53 MODULE_DESCRIPTION("Driver for In-System Design, Inc. ISD200 ASIC");
58 static int isd200_Initialization(struct us_data *us);
168 #define ISD200_ERROR -1
336 * Read Capacity Data - returned in Big Endian format
345 * Read Block Limits Data - returned in Big Endian format
399 static void isd200_build_sense(struct us_data *us, struct scsi_cmnd *srb) in isd200_build_sense() argument
401 struct isd200_info *info = (struct isd200_info *)us->extra; in isd200_build_sense()
402 struct sense_data *buf = (struct sense_data *) &srb->sense_buffer[0]; in isd200_build_sense()
403 unsigned char error = info->ATARegs[ATA_REG_ERROR_OFFSET]; in isd200_build_sense()
406 buf->ErrorCode = 0x70 | SENSE_ERRCODE_VALID; in isd200_build_sense()
407 buf->AdditionalSenseLength = 0xb; in isd200_build_sense()
408 buf->Flags = UNIT_ATTENTION; in isd200_build_sense()
409 buf->AdditionalSenseCode = 0; in isd200_build_sense()
410 buf->AdditionalSenseCodeQualifier = 0; in isd200_build_sense()
412 buf->ErrorCode = 0x70 | SENSE_ERRCODE_VALID; in isd200_build_sense()
413 buf->AdditionalSenseLength = 0xb; in isd200_build_sense()
414 buf->Flags = UNIT_ATTENTION; in isd200_build_sense()
415 buf->AdditionalSenseCode = 0; in isd200_build_sense()
416 buf->AdditionalSenseCodeQualifier = 0; in isd200_build_sense()
418 buf->ErrorCode = 0x70 | SENSE_ERRCODE_VALID; in isd200_build_sense()
419 buf->AdditionalSenseLength = 0xb; in isd200_build_sense()
420 buf->Flags = NOT_READY; in isd200_build_sense()
421 buf->AdditionalSenseCode = 0; in isd200_build_sense()
422 buf->AdditionalSenseCodeQualifier = 0; in isd200_build_sense()
424 buf->ErrorCode = 0x70 | SENSE_ERRCODE_VALID; in isd200_build_sense()
425 buf->AdditionalSenseLength = 0xb; in isd200_build_sense()
426 buf->Flags = DATA_PROTECT; in isd200_build_sense()
427 buf->AdditionalSenseCode = 0; in isd200_build_sense()
428 buf->AdditionalSenseCodeQualifier = 0; in isd200_build_sense()
430 buf->ErrorCode = 0; in isd200_build_sense()
431 buf->AdditionalSenseLength = 0; in isd200_build_sense()
432 buf->Flags = 0; in isd200_build_sense()
433 buf->AdditionalSenseCode = 0; in isd200_build_sense()
434 buf->AdditionalSenseCodeQualifier = 0; in isd200_build_sense()
452 struct scsi_cmnd *srb = &info->srb; in isd200_set_srb()
455 sg_init_one(&info->sg, buff, bufflen); in isd200_set_srb()
457 srb->sc_data_direction = dir; in isd200_set_srb()
458 srb->sdb.table.sgl = buff ? &info->sg : NULL; in isd200_set_srb()
459 srb->sdb.length = bufflen; in isd200_set_srb()
460 srb->sdb.table.nents = buff ? 1 : 0; in isd200_set_srb()
465 srb->sdb.length = bufflen; in isd200_srb_set_bufflen()
477 static int isd200_action( struct us_data *us, int action, in isd200_action() argument
483 struct isd200_info *info = (struct isd200_info *)us->extra; in isd200_action()
484 struct scsi_cmnd *srb = &info->srb; in isd200_action()
488 memcpy(srb->cmnd, info->cmnd, MAX_COMMAND_SIZE); in isd200_action()
489 srb->device = &srb_dev; in isd200_action()
491 ata.generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; in isd200_action()
492 ata.generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; in isd200_action()
497 usb_stor_dbg(us, " isd200_action(READ_STATUS)\n"); in isd200_action()
506 usb_stor_dbg(us, " isd200_action(ENUM,0x%02x)\n", value); in isd200_action()
516 usb_stor_dbg(us, " isd200_action(RESET)\n"); in isd200_action()
525 usb_stor_dbg(us, " isd200_action(REENABLE)\n"); in isd200_action()
534 usb_stor_dbg(us, " isd200_action(SOFT_RESET)\n"); in isd200_action()
537 ata.write.DeviceHeadByte = info->DeviceHead; in isd200_action()
543 usb_stor_dbg(us, " isd200_action(IDENTIFY)\n"); in isd200_action()
546 isd200_set_srb(info, DMA_FROM_DEVICE, info->id, in isd200_action()
551 usb_stor_dbg(us, "Error: Undefined action %d\n", action); in isd200_action()
555 memcpy(srb->cmnd, &ata, sizeof(ata.generic)); in isd200_action()
556 srb->cmd_len = sizeof(ata.generic); in isd200_action()
557 status = usb_stor_Bulk_transport(srb, us); in isd200_action()
561 usb_stor_dbg(us, " isd200_action(0x%02x) error: %d\n", in isd200_action()
578 static int isd200_read_regs( struct us_data *us ) in isd200_read_regs() argument
580 struct isd200_info *info = (struct isd200_info *)us->extra; in isd200_read_regs()
584 usb_stor_dbg(us, "Entering isd200_IssueATAReadRegs\n"); in isd200_read_regs()
586 transferStatus = isd200_action( us, ACTION_READ_STATUS, in isd200_read_regs()
587 info->RegsBuf, sizeof(info->ATARegs) ); in isd200_read_regs()
589 usb_stor_dbg(us, " Error reading ATA registers\n"); in isd200_read_regs()
592 memcpy(info->ATARegs, info->RegsBuf, sizeof(info->ATARegs)); in isd200_read_regs()
593 usb_stor_dbg(us, " Got ATA Register[ATA_REG_ERROR_OFFSET] = 0x%x\n", in isd200_read_regs()
594 info->ATARegs[ATA_REG_ERROR_OFFSET]); in isd200_read_regs()
602 * Invoke the transport and basic error-handling/recovery methods
607 static void isd200_invoke_transport( struct us_data *us, in isd200_invoke_transport() argument
616 memcpy(srb->cmnd, ataCdb, sizeof(ataCdb->generic)); in isd200_invoke_transport()
617 srb->cmd_len = sizeof(ataCdb->generic); in isd200_invoke_transport()
618 transferStatus = usb_stor_Bulk_transport(srb, us); in isd200_invoke_transport()
622 * short-circuit all other processing in isd200_invoke_transport()
624 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { in isd200_invoke_transport()
625 usb_stor_dbg(us, "-- command was aborted\n"); in isd200_invoke_transport()
633 srb->result = SAM_STAT_GOOD; in isd200_invoke_transport()
637 usb_stor_dbg(us, "-- transport indicates protocol failure\n"); in isd200_invoke_transport()
638 srb->result = SAM_STAT_CHECK_CONDITION; in isd200_invoke_transport()
642 usb_stor_dbg(us, "-- transport indicates command failure\n"); in isd200_invoke_transport()
647 usb_stor_dbg(us, "-- transport indicates transport error\n"); in isd200_invoke_transport()
648 srb->result = DID_ERROR << 16; in isd200_invoke_transport()
653 usb_stor_dbg(us, "-- transport indicates unknown error\n"); in isd200_invoke_transport()
654 srb->result = DID_ERROR << 16; in isd200_invoke_transport()
660 !((srb->cmnd[0] == REQUEST_SENSE) || in isd200_invoke_transport()
661 (srb->cmnd[0] == INQUIRY) || in isd200_invoke_transport()
662 (srb->cmnd[0] == MODE_SENSE) || in isd200_invoke_transport()
663 (srb->cmnd[0] == LOG_SENSE) || in isd200_invoke_transport()
664 (srb->cmnd[0] == MODE_SENSE_10))) { in isd200_invoke_transport()
665 usb_stor_dbg(us, "-- unexpectedly short transfer\n"); in isd200_invoke_transport()
670 result = isd200_read_regs(us); in isd200_invoke_transport()
671 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { in isd200_invoke_transport()
672 usb_stor_dbg(us, "-- auto-sense aborted\n"); in isd200_invoke_transport()
676 isd200_build_sense(us, srb); in isd200_invoke_transport()
677 srb->result = SAM_STAT_CHECK_CONDITION; in isd200_invoke_transport()
680 if ((srb->sense_buffer[2] & 0xf) == 0x0) in isd200_invoke_transport()
681 srb->result = SAM_STAT_GOOD; in isd200_invoke_transport()
683 srb->result = DID_ERROR << 16; in isd200_invoke_transport()
689 * Regardless of auto-sense, if we _know_ we have an error in isd200_invoke_transport()
693 srb->result = SAM_STAT_CHECK_CONDITION; in isd200_invoke_transport()
697 * abort processing: the bulk-only transport requires a reset in isd200_invoke_transport()
701 srb->result = DID_ABORT << 16; in isd200_invoke_transport()
704 clear_bit(US_FLIDX_ABORTING, &us->dflags); in isd200_invoke_transport()
709 static void isd200_log_config(struct us_data *us, struct isd200_info *info) in isd200_log_config() argument
711 usb_stor_dbg(us, " Event Notification: 0x%x\n", in isd200_log_config()
712 info->ConfigData.EventNotification); in isd200_log_config()
713 usb_stor_dbg(us, " External Clock: 0x%x\n", in isd200_log_config()
714 info->ConfigData.ExternalClock); in isd200_log_config()
715 usb_stor_dbg(us, " ATA Init Timeout: 0x%x\n", in isd200_log_config()
716 info->ConfigData.ATAInitTimeout); in isd200_log_config()
717 usb_stor_dbg(us, " ATAPI Command Block Size: 0x%x\n", in isd200_log_config()
718 (info->ConfigData.ATAConfig & ATACFG_BLOCKSIZE) >> 6); in isd200_log_config()
719 usb_stor_dbg(us, " Master/Slave Selection: 0x%x\n", in isd200_log_config()
720 info->ConfigData.ATAConfig & ATACFG_MASTER); in isd200_log_config()
721 usb_stor_dbg(us, " ATAPI Reset: 0x%x\n", in isd200_log_config()
722 info->ConfigData.ATAConfig & ATACFG_ATAPI_RESET); in isd200_log_config()
723 usb_stor_dbg(us, " ATA Timing: 0x%x\n", in isd200_log_config()
724 info->ConfigData.ATAConfig & ATACFG_TIMING); in isd200_log_config()
725 usb_stor_dbg(us, " ATA Major Command: 0x%x\n", in isd200_log_config()
726 info->ConfigData.ATAMajorCommand); in isd200_log_config()
727 usb_stor_dbg(us, " ATA Minor Command: 0x%x\n", in isd200_log_config()
728 info->ConfigData.ATAMinorCommand); in isd200_log_config()
729 usb_stor_dbg(us, " Init Status: 0x%x\n", in isd200_log_config()
730 info->ConfigData.ATAExtraConfig & ATACFGE_INIT_STATUS); in isd200_log_config()
731 usb_stor_dbg(us, " Config Descriptor 2: 0x%x\n", in isd200_log_config()
732 info->ConfigData.ATAExtraConfig & ATACFGE_CONF_DESC2); in isd200_log_config()
733 usb_stor_dbg(us, " Skip Device Boot: 0x%x\n", in isd200_log_config()
734 info->ConfigData.ATAExtraConfig & ATACFGE_SKIP_BOOT); in isd200_log_config()
735 usb_stor_dbg(us, " ATA 3 State Suspend: 0x%x\n", in isd200_log_config()
736 info->ConfigData.ATAExtraConfig & ATACFGE_STATE_SUSPEND); in isd200_log_config()
737 usb_stor_dbg(us, " Descriptor Override: 0x%x\n", in isd200_log_config()
738 info->ConfigData.ATAExtraConfig & ATACFGE_DESC_OVERRIDE); in isd200_log_config()
739 usb_stor_dbg(us, " Last LUN Identifier: 0x%x\n", in isd200_log_config()
740 info->ConfigData.ATAExtraConfig & ATACFGE_LAST_LUN); in isd200_log_config()
741 usb_stor_dbg(us, " SRST Enable: 0x%x\n", in isd200_log_config()
742 info->ConfigData.ATAExtraConfig & CFG_CAPABILITY_SRST); in isd200_log_config()
754 static int isd200_write_config( struct us_data *us ) in isd200_write_config() argument
756 struct isd200_info *info = (struct isd200_info *)us->extra; in isd200_write_config()
761 usb_stor_dbg(us, "Entering isd200_write_config\n"); in isd200_write_config()
762 usb_stor_dbg(us, " Writing the following ISD200 Config Data:\n"); in isd200_write_config()
763 isd200_log_config(us, info); in isd200_write_config()
768 us, in isd200_write_config()
769 us->send_ctrl_pipe, in isd200_write_config()
774 (void *) &info->ConfigData, in isd200_write_config()
775 sizeof(info->ConfigData)); in isd200_write_config()
778 usb_stor_dbg(us, " ISD200 Config Data was written successfully\n"); in isd200_write_config()
780 usb_stor_dbg(us, " Request to write ISD200 Config Data failed!\n"); in isd200_write_config()
784 usb_stor_dbg(us, "Leaving isd200_write_config %08X\n", retStatus); in isd200_write_config()
797 static int isd200_read_config( struct us_data *us ) in isd200_read_config() argument
799 struct isd200_info *info = (struct isd200_info *)us->extra; in isd200_read_config()
803 usb_stor_dbg(us, "Entering isd200_read_config\n"); in isd200_read_config()
809 us, in isd200_read_config()
810 us->recv_ctrl_pipe, in isd200_read_config()
815 (void *) &info->ConfigData, in isd200_read_config()
816 sizeof(info->ConfigData)); in isd200_read_config()
820 usb_stor_dbg(us, " Retrieved the following ISD200 Config Data:\n"); in isd200_read_config()
822 isd200_log_config(us, info); in isd200_read_config()
825 usb_stor_dbg(us, " Request to get ISD200 Config Data failed!\n"); in isd200_read_config()
829 usb_stor_dbg(us, "Leaving isd200_read_config %08X\n", retStatus); in isd200_read_config()
842 static int isd200_atapi_soft_reset( struct us_data *us ) in isd200_atapi_soft_reset() argument
847 usb_stor_dbg(us, "Entering isd200_atapi_soft_reset\n"); in isd200_atapi_soft_reset()
849 transferStatus = isd200_action( us, ACTION_SOFT_RESET, NULL, 0 ); in isd200_atapi_soft_reset()
851 usb_stor_dbg(us, " Error issuing Atapi Soft Reset\n"); in isd200_atapi_soft_reset()
855 usb_stor_dbg(us, "Leaving isd200_atapi_soft_reset %08X\n", retStatus); in isd200_atapi_soft_reset()
868 static int isd200_srst( struct us_data *us ) in isd200_srst() argument
873 usb_stor_dbg(us, "Entering isd200_SRST\n"); in isd200_srst()
875 transferStatus = isd200_action( us, ACTION_RESET, NULL, 0 ); in isd200_srst()
879 usb_stor_dbg(us, " Error issuing SRST\n"); in isd200_srst()
885 transferStatus = isd200_action( us, ACTION_REENABLE, NULL, 0 ); in isd200_srst()
887 usb_stor_dbg(us, " Error taking drive out of reset\n"); in isd200_srst()
895 usb_stor_dbg(us, "Leaving isd200_srst %08X\n", retStatus); in isd200_srst()
909 static int isd200_try_enum(struct us_data *us, unsigned char master_slave, in isd200_try_enum() argument
910 int detect ) in isd200_try_enum() argument
914 struct isd200_info *info = (struct isd200_info *)us->extra; in isd200_try_enum()
915 unsigned char *regs = info->RegsBuf; in isd200_try_enum()
918 if ( detect ) in isd200_try_enum()
923 /* loop until we detect !BSY or timeout */ in isd200_try_enum()
926 status = isd200_action( us, ACTION_ENUM, NULL, master_slave ); in isd200_try_enum()
930 status = isd200_action( us, ACTION_READ_STATUS, in isd200_try_enum()
935 if (!detect) { in isd200_try_enum()
937 usb_stor_dbg(us, " %s status is still BSY, try again...\n", in isd200_try_enum()
941 usb_stor_dbg(us, " %s status !BSY, continue with next operation\n", in isd200_try_enum()
949 /* ATA_ERR (workaround for Archos CD-ROM) */ in isd200_try_enum()
952 usb_stor_dbg(us, " Status indicates it is not ready, try again...\n"); in isd200_try_enum()
956 usb_stor_dbg(us, " Identified ATA device\n"); in isd200_try_enum()
957 info->DeviceFlags |= DF_ATA_DEVICE; in isd200_try_enum()
958 info->DeviceHead = master_slave; in isd200_try_enum()
979 usb_stor_dbg(us, " Identified ATAPI device as slave. Rechecking again as master\n"); in isd200_try_enum()
983 usb_stor_dbg(us, " Identified ATAPI device\n"); in isd200_try_enum()
984 info->DeviceHead = master_slave; in isd200_try_enum()
986 status = isd200_atapi_soft_reset(us); in isd200_try_enum()
990 usb_stor_dbg(us, " Not ATA, not ATAPI - Weird\n"); in isd200_try_enum()
996 if (!detect) in isd200_try_enum()
997 usb_stor_dbg(us, " BSY check timeout, just continue with next operation...\n"); in isd200_try_enum()
999 usb_stor_dbg(us, " Device detect timeout!\n"); in isd200_try_enum()
1016 static int isd200_manual_enum(struct us_data *us) in isd200_manual_enum() argument
1018 struct isd200_info *info = (struct isd200_info *)us->extra; in isd200_manual_enum()
1021 usb_stor_dbg(us, "Entering isd200_manual_enum\n"); in isd200_manual_enum()
1023 retStatus = isd200_read_config(us); in isd200_manual_enum()
1027 retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_STD, 0); in isd200_manual_enum()
1029 retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_SLAVE, 0); in isd200_manual_enum()
1032 retStatus = isd200_srst(us); in isd200_manual_enum()
1035 retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_STD, 1); in isd200_manual_enum()
1038 isslave = (info->DeviceHead & ATA_ADDRESS_DEVHEAD_SLAVE) ? 1 : 0; in isd200_manual_enum()
1039 if (!(info->ConfigData.ATAConfig & ATACFG_MASTER)) { in isd200_manual_enum()
1040 usb_stor_dbg(us, " Setting Master/Slave selection to %d\n", in isd200_manual_enum()
1042 info->ConfigData.ATAConfig &= 0x3f; in isd200_manual_enum()
1043 info->ConfigData.ATAConfig |= (isslave<<6); in isd200_manual_enum()
1044 retStatus = isd200_write_config(us); in isd200_manual_enum()
1048 usb_stor_dbg(us, "Leaving isd200_manual_enum %08X\n", retStatus); in isd200_manual_enum()
1066 static void isd200_dump_driveid(struct us_data *us, u16 *id) in isd200_dump_driveid() argument
1068 usb_stor_dbg(us, " Identify Data Structure:\n"); in isd200_dump_driveid()
1069 usb_stor_dbg(us, " config = 0x%x\n", id[ATA_ID_CONFIG]); in isd200_dump_driveid()
1070 usb_stor_dbg(us, " cyls = 0x%x\n", id[ATA_ID_CYLS]); in isd200_dump_driveid()
1071 usb_stor_dbg(us, " heads = 0x%x\n", id[ATA_ID_HEADS]); in isd200_dump_driveid()
1072 usb_stor_dbg(us, " track_bytes = 0x%x\n", id[4]); in isd200_dump_driveid()
1073 usb_stor_dbg(us, " sector_bytes = 0x%x\n", id[5]); in isd200_dump_driveid()
1074 usb_stor_dbg(us, " sectors = 0x%x\n", id[ATA_ID_SECTORS]); in isd200_dump_driveid()
1075 usb_stor_dbg(us, " serial_no[0] = 0x%x\n", *(char *)&id[ATA_ID_SERNO]); in isd200_dump_driveid()
1076 usb_stor_dbg(us, " buf_type = 0x%x\n", id[20]); in isd200_dump_driveid()
1077 usb_stor_dbg(us, " buf_size = 0x%x\n", id[ATA_ID_BUF_SIZE]); in isd200_dump_driveid()
1078 usb_stor_dbg(us, " ecc_bytes = 0x%x\n", id[22]); in isd200_dump_driveid()
1079 usb_stor_dbg(us, " fw_rev[0] = 0x%x\n", *(char *)&id[ATA_ID_FW_REV]); in isd200_dump_driveid()
1080 usb_stor_dbg(us, " model[0] = 0x%x\n", *(char *)&id[ATA_ID_PROD]); in isd200_dump_driveid()
1081 usb_stor_dbg(us, " max_multsect = 0x%x\n", id[ATA_ID_MAX_MULTSECT] & 0xff); in isd200_dump_driveid()
1082 usb_stor_dbg(us, " dword_io = 0x%x\n", id[ATA_ID_DWORD_IO]); in isd200_dump_driveid()
1083 usb_stor_dbg(us, " capability = 0x%x\n", id[ATA_ID_CAPABILITY] >> 8); in isd200_dump_driveid()
1084 usb_stor_dbg(us, " tPIO = 0x%x\n", id[ATA_ID_OLD_PIO_MODES] >> 8); in isd200_dump_driveid()
1085 usb_stor_dbg(us, " tDMA = 0x%x\n", id[ATA_ID_OLD_DMA_MODES] >> 8); in isd200_dump_driveid()
1086 usb_stor_dbg(us, " field_valid = 0x%x\n", id[ATA_ID_FIELD_VALID]); in isd200_dump_driveid()
1087 usb_stor_dbg(us, " cur_cyls = 0x%x\n", id[ATA_ID_CUR_CYLS]); in isd200_dump_driveid()
1088 usb_stor_dbg(us, " cur_heads = 0x%x\n", id[ATA_ID_CUR_HEADS]); in isd200_dump_driveid()
1089 usb_stor_dbg(us, " cur_sectors = 0x%x\n", id[ATA_ID_CUR_SECTORS]); in isd200_dump_driveid()
1090 usb_stor_dbg(us, " cur_capacity = 0x%x\n", ata_id_u32(id, 57)); in isd200_dump_driveid()
1091 usb_stor_dbg(us, " multsect = 0x%x\n", id[ATA_ID_MULTSECT] & 0xff); in isd200_dump_driveid()
1092 usb_stor_dbg(us, " lba_capacity = 0x%x\n", ata_id_u32(id, ATA_ID_LBA_CAPACITY)); in isd200_dump_driveid()
1093 usb_stor_dbg(us, " command_set_1 = 0x%x\n", id[ATA_ID_COMMAND_SET_1]); in isd200_dump_driveid()
1094 usb_stor_dbg(us, " command_set_2 = 0x%x\n", id[ATA_ID_COMMAND_SET_2]); in isd200_dump_driveid()
1105 static int isd200_get_inquiry_data( struct us_data *us ) in isd200_get_inquiry_data() argument
1107 struct isd200_info *info = (struct isd200_info *)us->extra; in isd200_get_inquiry_data()
1109 u16 *id = info->id; in isd200_get_inquiry_data()
1111 usb_stor_dbg(us, "Entering isd200_get_inquiry_data\n"); in isd200_get_inquiry_data()
1114 info->DeviceHead = ATA_ADDRESS_DEVHEAD_STD; in isd200_get_inquiry_data()
1117 retStatus = isd200_manual_enum(us); in isd200_get_inquiry_data()
1122 if (info->DeviceFlags & DF_ATA_DEVICE) { in isd200_get_inquiry_data()
1125 transferStatus = isd200_action( us, ACTION_IDENTIFY, in isd200_get_inquiry_data()
1129 usb_stor_dbg(us, " Error issuing ATA Command Identify\n"); in isd200_get_inquiry_data()
1138 isd200_dump_driveid(us, id); in isd200_get_inquiry_data()
1142 usb_stor_dbg(us, " Invalid ATA Identify data\n"); in isd200_get_inquiry_data()
1147 memset(&info->InquiryData, 0, sizeof(info->InquiryData)); in isd200_get_inquiry_data()
1150 info->InquiryData.DeviceType = DIRECT_ACCESS_DEVICE; in isd200_get_inquiry_data()
1153 info->InquiryData.AdditionalLength = 0x1F; in isd200_get_inquiry_data()
1157 info->InquiryData.DeviceTypeModifier = DEVICE_REMOVABLE; in isd200_get_inquiry_data()
1158 info->DeviceFlags |= DF_REMOVABLE_MEDIA; in isd200_get_inquiry_data()
1163 dest = (__u16*)info->InquiryData.VendorId; in isd200_get_inquiry_data()
1168 dest = (__u16*)info->InquiryData.ProductId; in isd200_get_inquiry_data()
1173 dest = (__u16*)info->InquiryData.ProductRevisionLevel; in isd200_get_inquiry_data()
1179 usb_stor_dbg(us, " Device supports Media Status Notification\n"); in isd200_get_inquiry_data()
1187 info->DeviceFlags |= DF_MEDIA_STATUS_ENABLED; in isd200_get_inquiry_data()
1190 info->DeviceFlags &= ~DF_MEDIA_STATUS_ENABLED; in isd200_get_inquiry_data()
1198 us->protocol_name = "Transparent SCSI"; in isd200_get_inquiry_data()
1199 us->proto_handler = usb_stor_transparent_scsi_command; in isd200_get_inquiry_data()
1201 usb_stor_dbg(us, "Protocol changed to: %s\n", in isd200_get_inquiry_data()
1202 us->protocol_name); in isd200_get_inquiry_data()
1205 us->extra_destructor(info); in isd200_get_inquiry_data()
1207 us->extra = NULL; in isd200_get_inquiry_data()
1208 us->extra_destructor = NULL; in isd200_get_inquiry_data()
1213 usb_stor_dbg(us, "Leaving isd200_get_inquiry_data %08X\n", retStatus); in isd200_get_inquiry_data()
1227 static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us, in isd200_scsi_to_ata() argument
1230 struct isd200_info *info = (struct isd200_info *)us->extra; in isd200_scsi_to_ata()
1231 u16 *id = info->id; in isd200_scsi_to_ata()
1242 switch (srb->cmnd[0]) { in isd200_scsi_to_ata()
1244 usb_stor_dbg(us, " ATA OUT - INQUIRY\n"); in isd200_scsi_to_ata()
1247 usb_stor_set_xfer_buf((unsigned char *) &info->InquiryData, in isd200_scsi_to_ata()
1248 sizeof(info->InquiryData), srb); in isd200_scsi_to_ata()
1249 srb->result = SAM_STAT_GOOD; in isd200_scsi_to_ata()
1254 usb_stor_dbg(us, " ATA OUT - SCSIOP_MODE_SENSE\n"); in isd200_scsi_to_ata()
1259 if (info->DeviceFlags & DF_MEDIA_STATUS_ENABLED) in isd200_scsi_to_ata()
1261 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; in isd200_scsi_to_ata()
1262 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; in isd200_scsi_to_ata()
1263 ataCdb->generic.TransferBlockSize = 1; in isd200_scsi_to_ata()
1264 ataCdb->generic.RegisterSelect = REG_COMMAND; in isd200_scsi_to_ata()
1265 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS; in isd200_scsi_to_ata()
1268 usb_stor_dbg(us, " Media Status not supported, just report okay\n"); in isd200_scsi_to_ata()
1269 srb->result = SAM_STAT_GOOD; in isd200_scsi_to_ata()
1275 usb_stor_dbg(us, " ATA OUT - SCSIOP_TEST_UNIT_READY\n"); in isd200_scsi_to_ata()
1277 if (info->DeviceFlags & DF_MEDIA_STATUS_ENABLED) in isd200_scsi_to_ata()
1279 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; in isd200_scsi_to_ata()
1280 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; in isd200_scsi_to_ata()
1281 ataCdb->generic.TransferBlockSize = 1; in isd200_scsi_to_ata()
1282 ataCdb->generic.RegisterSelect = REG_COMMAND; in isd200_scsi_to_ata()
1283 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS; in isd200_scsi_to_ata()
1286 usb_stor_dbg(us, " Media Status not supported, just report okay\n"); in isd200_scsi_to_ata()
1287 srb->result = SAM_STAT_GOOD; in isd200_scsi_to_ata()
1297 usb_stor_dbg(us, " ATA OUT - SCSIOP_READ_CAPACITY\n"); in isd200_scsi_to_ata()
1300 capacity = ata_id_u32(id, ATA_ID_LBA_CAPACITY) - 1; in isd200_scsi_to_ata()
1303 id[ATA_ID_SECTORS]) - 1; in isd200_scsi_to_ata()
1310 srb->result = SAM_STAT_GOOD; in isd200_scsi_to_ata()
1316 usb_stor_dbg(us, " ATA OUT - SCSIOP_READ\n"); in isd200_scsi_to_ata()
1318 lba = be32_to_cpu(*(__be32 *)&srb->cmnd[2]); in isd200_scsi_to_ata()
1319 blockCount = (unsigned long)srb->cmnd[7]<<8 | (unsigned long)srb->cmnd[8]; in isd200_scsi_to_ata()
1332 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; in isd200_scsi_to_ata()
1333 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; in isd200_scsi_to_ata()
1334 ataCdb->generic.TransferBlockSize = 1; in isd200_scsi_to_ata()
1335 ataCdb->generic.RegisterSelect = in isd200_scsi_to_ata()
1339 ataCdb->write.SectorCountByte = (unsigned char)blockCount; in isd200_scsi_to_ata()
1340 ataCdb->write.SectorNumberByte = sectnum; in isd200_scsi_to_ata()
1341 ataCdb->write.CylinderHighByte = (unsigned char)(cylinder>>8); in isd200_scsi_to_ata()
1342 ataCdb->write.CylinderLowByte = (unsigned char)cylinder; in isd200_scsi_to_ata()
1343 ataCdb->write.DeviceHeadByte = (head | ATA_ADDRESS_DEVHEAD_STD); in isd200_scsi_to_ata()
1344 ataCdb->write.CommandByte = ATA_CMD_PIO_READ; in isd200_scsi_to_ata()
1348 usb_stor_dbg(us, " ATA OUT - SCSIOP_WRITE\n"); in isd200_scsi_to_ata()
1350 lba = be32_to_cpu(*(__be32 *)&srb->cmnd[2]); in isd200_scsi_to_ata()
1351 blockCount = (unsigned long)srb->cmnd[7]<<8 | (unsigned long)srb->cmnd[8]; in isd200_scsi_to_ata()
1364 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; in isd200_scsi_to_ata()
1365 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; in isd200_scsi_to_ata()
1366 ataCdb->generic.TransferBlockSize = 1; in isd200_scsi_to_ata()
1367 ataCdb->generic.RegisterSelect = in isd200_scsi_to_ata()
1371 ataCdb->write.SectorCountByte = (unsigned char)blockCount; in isd200_scsi_to_ata()
1372 ataCdb->write.SectorNumberByte = sectnum; in isd200_scsi_to_ata()
1373 ataCdb->write.CylinderHighByte = (unsigned char)(cylinder>>8); in isd200_scsi_to_ata()
1374 ataCdb->write.CylinderLowByte = (unsigned char)cylinder; in isd200_scsi_to_ata()
1375 ataCdb->write.DeviceHeadByte = (head | ATA_ADDRESS_DEVHEAD_STD); in isd200_scsi_to_ata()
1376 ataCdb->write.CommandByte = ATA_CMD_PIO_WRITE; in isd200_scsi_to_ata()
1380 usb_stor_dbg(us, " ATA OUT - SCSIOP_MEDIUM_REMOVAL\n"); in isd200_scsi_to_ata()
1382 if (info->DeviceFlags & DF_REMOVABLE_MEDIA) { in isd200_scsi_to_ata()
1383 usb_stor_dbg(us, " srb->cmnd[4] = 0x%X\n", in isd200_scsi_to_ata()
1384 srb->cmnd[4]); in isd200_scsi_to_ata()
1386 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; in isd200_scsi_to_ata()
1387 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; in isd200_scsi_to_ata()
1388 ataCdb->generic.TransferBlockSize = 1; in isd200_scsi_to_ata()
1389 ataCdb->generic.RegisterSelect = REG_COMMAND; in isd200_scsi_to_ata()
1390 ataCdb->write.CommandByte = (srb->cmnd[4] & 0x1) ? in isd200_scsi_to_ata()
1394 usb_stor_dbg(us, " Not removable media, just report okay\n"); in isd200_scsi_to_ata()
1395 srb->result = SAM_STAT_GOOD; in isd200_scsi_to_ata()
1401 usb_stor_dbg(us, " ATA OUT - SCSIOP_START_STOP_UNIT\n"); in isd200_scsi_to_ata()
1402 usb_stor_dbg(us, " srb->cmnd[4] = 0x%X\n", srb->cmnd[4]); in isd200_scsi_to_ata()
1404 if ((srb->cmnd[4] & 0x3) == 0x2) { in isd200_scsi_to_ata()
1405 usb_stor_dbg(us, " Media Eject\n"); in isd200_scsi_to_ata()
1406 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; in isd200_scsi_to_ata()
1407 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; in isd200_scsi_to_ata()
1408 ataCdb->generic.TransferBlockSize = 0; in isd200_scsi_to_ata()
1409 ataCdb->generic.RegisterSelect = REG_COMMAND; in isd200_scsi_to_ata()
1410 ataCdb->write.CommandByte = ATA_COMMAND_MEDIA_EJECT; in isd200_scsi_to_ata()
1411 } else if ((srb->cmnd[4] & 0x3) == 0x1) { in isd200_scsi_to_ata()
1412 usb_stor_dbg(us, " Get Media Status\n"); in isd200_scsi_to_ata()
1413 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; in isd200_scsi_to_ata()
1414 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; in isd200_scsi_to_ata()
1415 ataCdb->generic.TransferBlockSize = 1; in isd200_scsi_to_ata()
1416 ataCdb->generic.RegisterSelect = REG_COMMAND; in isd200_scsi_to_ata()
1417 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS; in isd200_scsi_to_ata()
1420 usb_stor_dbg(us, " Nothing to do, just report okay\n"); in isd200_scsi_to_ata()
1421 srb->result = SAM_STAT_GOOD; in isd200_scsi_to_ata()
1427 usb_stor_dbg(us, "Unsupported SCSI command - 0x%X\n", in isd200_scsi_to_ata()
1428 srb->cmnd[0]); in isd200_scsi_to_ata()
1429 srb->result = DID_ERROR << 16; in isd200_scsi_to_ata()
1448 kfree(info->id); in isd200_free_info_ptrs()
1449 kfree(info->RegsBuf); in isd200_free_info_ptrs()
1450 kfree(info->srb.sense_buffer); in isd200_free_info_ptrs()
1462 static int isd200_init_info(struct us_data *us) in isd200_init_info() argument
1468 return -ENOMEM; in isd200_init_info()
1470 info->id = kzalloc(ATA_ID_WORDS * 2, GFP_KERNEL); in isd200_init_info()
1471 info->RegsBuf = kmalloc(sizeof(info->ATARegs), GFP_KERNEL); in isd200_init_info()
1472 info->srb.sense_buffer = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); in isd200_init_info()
1474 if (!info->id || !info->RegsBuf || !info->srb.sense_buffer) { in isd200_init_info()
1477 return -ENOMEM; in isd200_init_info()
1480 us->extra = info; in isd200_init_info()
1481 us->extra_destructor = isd200_free_info_ptrs; in isd200_init_info()
1490 static int isd200_Initialization(struct us_data *us) in isd200_Initialization() argument
1494 usb_stor_dbg(us, "ISD200 Initialization...\n"); in isd200_Initialization()
1498 if (isd200_init_info(us) < 0) { in isd200_Initialization()
1499 usb_stor_dbg(us, "ERROR Initializing ISD200 Info struct\n"); in isd200_Initialization()
1500 rc = -ENOMEM; in isd200_Initialization()
1504 if (isd200_get_inquiry_data(us) != ISD200_GOOD) { in isd200_Initialization()
1505 usb_stor_dbg(us, "ISD200 Initialization Failure\n"); in isd200_Initialization()
1506 rc = -EINVAL; in isd200_Initialization()
1508 usb_stor_dbg(us, "ISD200 Initialization complete\n"); in isd200_Initialization()
1526 static void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us) in isd200_ata_command() argument
1533 if (us->extra == NULL) { in isd200_ata_command()
1534 usb_stor_dbg(us, "ERROR Driver not initialized\n"); in isd200_ata_command()
1535 srb->result = DID_ERROR << 16; in isd200_ata_command()
1542 sendToTransport = isd200_scsi_to_ata(srb, us, &ataCdb); in isd200_ata_command()
1546 isd200_invoke_transport(us, srb, &ataCdb); in isd200_ata_command()
1556 struct us_data *us; in isd200_probe() local
1559 result = usb_stor_probe1(&us, intf, id, in isd200_probe()
1560 (id - isd200_usb_ids) + isd200_unusual_dev_list, in isd200_probe()
1565 us->protocol_name = "ISD200 ATA/ATAPI"; in isd200_probe()
1566 us->proto_handler = isd200_ata_command; in isd200_probe()
1568 result = usb_stor_probe2(us); in isd200_probe()