1 // SPDX-License-Identifier: GPL-2.0+
3 * Transport & Protocol Driver for In-System Design, Inc. ISD200 ASIC
5 * Current development and maintenance:
6 * (C) 2001-2002 Björn Stenberg (bjorn@haxx.se)
8 * Developed with the assistance of:
9 * (C) 2002 Alan Stern <stern@rowland.org>
12 * (C) 2000 In-System Design, Inc. (support@in-system.com)
14 * The ISD200 ASIC does not natively support ATA devices. The chip
15 * does implement an interface, the ATA Command Block (ATACB) which provides
16 * a means of passing ATA commands and ATA register accesses to a device.
20 * 2002-10-19: Removed the specialized transfer routines.
21 * (Alan Stern <stern@rowland.harvard.edu>)
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.
25 * (Luc Saillard <luc@saillard.org>)
26 * 2002-01-17: All bitfields removed.
33 #include <linux/jiffies.h>
34 #include <linux/errno.h>
35 #include <linux/module.h>
36 #include <linux/slab.h>
37 #include <linux/ata.h>
38 #include <linux/hdreg.h>
39 #include <linux/scatterlist.h>
41 #include <scsi/scsi.h>
42 #include <scsi/scsi_cmnd.h>
43 #include <scsi/scsi_device.h>
46 #include "transport.h"
51 #define DRV_NAME "ums-isd200"
53 MODULE_DESCRIPTION("Driver for In-System Design, Inc. ISD200 ASIC");
54 MODULE_AUTHOR("Björn Stenberg <bjorn@haxx.se>");
55 MODULE_LICENSE("GPL");
56 MODULE_IMPORT_NS("USB_STORAGE");
58 static int isd200_Initialization(struct us_data
*us
);
62 * The table of devices
64 #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
65 vendorName, productName, useProtocol, useTransport, \
66 initFunction, flags) \
67 { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
68 .driver_info = (flags) }
70 static const struct usb_device_id isd200_usb_ids
[] = {
71 # include "unusual_isd200.h"
72 { } /* Terminating entry */
74 MODULE_DEVICE_TABLE(usb
, isd200_usb_ids
);
81 #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
82 vendor_name, product_name, use_protocol, use_transport, \
83 init_function, Flags) \
85 .vendorName = vendor_name, \
86 .productName = product_name, \
87 .useProtocol = use_protocol, \
88 .useTransport = use_transport, \
89 .initFunction = init_function, \
92 static const struct us_unusual_dev isd200_unusual_dev_list
[] = {
93 # include "unusual_isd200.h"
94 { } /* Terminating entry */
99 /* Timeout defines (in Seconds) */
101 #define ISD200_ENUM_BSY_TIMEOUT 35
102 #define ISD200_ENUM_DETECT_TIMEOUT 30
103 #define ISD200_DEFAULT_TIMEOUT 30
106 #define DF_ATA_DEVICE 0x0001
107 #define DF_MEDIA_STATUS_ENABLED 0x0002
108 #define DF_REMOVABLE_MEDIA 0x0004
110 /* capability bit definitions */
111 #define CAPABILITY_DMA 0x01
112 #define CAPABILITY_LBA 0x02
114 /* command_setX bit definitions */
115 #define COMMANDSET_REMOVABLE 0x02
116 #define COMMANDSET_MEDIA_STATUS 0x10
118 /* ATA Vendor Specific defines */
119 #define ATA_ADDRESS_DEVHEAD_STD 0xa0
120 #define ATA_ADDRESS_DEVHEAD_LBA_MODE 0x40
121 #define ATA_ADDRESS_DEVHEAD_SLAVE 0x10
123 /* Action Select bits */
124 #define ACTION_SELECT_0 0x01
125 #define ACTION_SELECT_1 0x02
126 #define ACTION_SELECT_2 0x04
127 #define ACTION_SELECT_3 0x08
128 #define ACTION_SELECT_4 0x10
129 #define ACTION_SELECT_5 0x20
130 #define ACTION_SELECT_6 0x40
131 #define ACTION_SELECT_7 0x80
133 /* Register Select bits */
134 #define REG_ALTERNATE_STATUS 0x01
135 #define REG_DEVICE_CONTROL 0x01
136 #define REG_ERROR 0x02
137 #define REG_FEATURES 0x02
138 #define REG_SECTOR_COUNT 0x04
139 #define REG_SECTOR_NUMBER 0x08
140 #define REG_CYLINDER_LOW 0x10
141 #define REG_CYLINDER_HIGH 0x20
142 #define REG_DEVICE_HEAD 0x40
143 #define REG_STATUS 0x80
144 #define REG_COMMAND 0x80
146 /* ATA registers offset definitions */
147 #define ATA_REG_ERROR_OFFSET 1
148 #define ATA_REG_LCYL_OFFSET 4
149 #define ATA_REG_HCYL_OFFSET 5
150 #define ATA_REG_STATUS_OFFSET 7
152 /* ATA error definitions not in <linux/hdreg.h> */
153 #define ATA_ERROR_MEDIA_CHANGE 0x20
155 /* ATA command definitions not in <linux/hdreg.h> */
156 #define ATA_COMMAND_GET_MEDIA_STATUS 0xDA
157 #define ATA_COMMAND_MEDIA_EJECT 0xED
159 /* ATA drive control definitions */
160 #define ATA_DC_DISABLE_INTERRUPTS 0x02
161 #define ATA_DC_RESET_CONTROLLER 0x04
162 #define ATA_DC_REENABLE_CONTROLLER 0x00
165 * General purpose return codes
168 #define ISD200_ERROR -1
169 #define ISD200_GOOD 0
172 * Transport return codes
175 #define ISD200_TRANSPORT_GOOD 0 /* Transport good, command good */
176 #define ISD200_TRANSPORT_FAILED 1 /* Transport good, command failed */
177 #define ISD200_TRANSPORT_ERROR 2 /* Transport bad (i.e. device dead) */
179 /* driver action codes */
180 #define ACTION_READ_STATUS 0
181 #define ACTION_RESET 1
182 #define ACTION_REENABLE 2
183 #define ACTION_SOFT_RESET 3
184 #define ACTION_ENUM 4
185 #define ACTION_IDENTIFY 5
195 unsigned char SignatureByte0
;
196 unsigned char SignatureByte1
;
197 unsigned char ActionSelect
;
198 unsigned char RegisterSelect
;
199 unsigned char TransferBlockSize
;
200 unsigned char WriteData3F6
;
201 unsigned char WriteData1F1
;
202 unsigned char WriteData1F2
;
203 unsigned char WriteData1F3
;
204 unsigned char WriteData1F4
;
205 unsigned char WriteData1F5
;
206 unsigned char WriteData1F6
;
207 unsigned char WriteData1F7
;
208 unsigned char Reserved
[3];
212 unsigned char SignatureByte0
;
213 unsigned char SignatureByte1
;
214 unsigned char ActionSelect
;
215 unsigned char RegisterSelect
;
216 unsigned char TransferBlockSize
;
217 unsigned char AlternateStatusByte
;
218 unsigned char ErrorByte
;
219 unsigned char SectorCountByte
;
220 unsigned char SectorNumberByte
;
221 unsigned char CylinderLowByte
;
222 unsigned char CylinderHighByte
;
223 unsigned char DeviceHeadByte
;
224 unsigned char StatusByte
;
225 unsigned char Reserved
[3];
229 unsigned char SignatureByte0
;
230 unsigned char SignatureByte1
;
231 unsigned char ActionSelect
;
232 unsigned char RegisterSelect
;
233 unsigned char TransferBlockSize
;
234 unsigned char DeviceControlByte
;
235 unsigned char FeaturesByte
;
236 unsigned char SectorCountByte
;
237 unsigned char SectorNumberByte
;
238 unsigned char CylinderLowByte
;
239 unsigned char CylinderHighByte
;
240 unsigned char DeviceHeadByte
;
241 unsigned char CommandByte
;
242 unsigned char Reserved
[3];
248 * Inquiry data structure. This is the data returned from the target
249 * after it receives an inquiry.
251 * This structure may be extended by the number of bytes specified
252 * in the field AdditionalLength. The defined size constant only
253 * includes fields through ProductRevisionLevel.
259 #define DIRECT_ACCESS_DEVICE 0x00 /* disks */
260 #define DEVICE_REMOVABLE 0x80
262 struct inquiry_data
{
263 unsigned char DeviceType
;
264 unsigned char DeviceTypeModifier
;
265 unsigned char Versions
;
266 unsigned char Format
;
267 unsigned char AdditionalLength
;
268 unsigned char Reserved
[2];
269 unsigned char Capability
;
270 unsigned char VendorId
[8];
271 unsigned char ProductId
[16];
272 unsigned char ProductRevisionLevel
[4];
273 unsigned char VendorSpecific
[20];
274 unsigned char Reserved3
[40];
275 } __attribute__ ((packed
));
278 * INQUIRY data buffer size
281 #define INQUIRYDATABUFFERSIZE 36
285 * ISD200 CONFIG data struct
288 #define ATACFG_TIMING 0x0f
289 #define ATACFG_ATAPI_RESET 0x10
290 #define ATACFG_MASTER 0x20
291 #define ATACFG_BLOCKSIZE 0xa0
293 #define ATACFGE_LAST_LUN 0x07
294 #define ATACFGE_DESC_OVERRIDE 0x08
295 #define ATACFGE_STATE_SUSPEND 0x10
296 #define ATACFGE_SKIP_BOOT 0x20
297 #define ATACFGE_CONF_DESC2 0x40
298 #define ATACFGE_INIT_STATUS 0x80
300 #define CFG_CAPABILITY_SRST 0x01
302 struct isd200_config
{
303 unsigned char EventNotification
;
304 unsigned char ExternalClock
;
305 unsigned char ATAInitTimeout
;
306 unsigned char ATAConfig
;
307 unsigned char ATAMajorCommand
;
308 unsigned char ATAMinorCommand
;
309 unsigned char ATAExtraConfig
;
310 unsigned char Capability
;
311 }__attribute__ ((packed
));
315 * ISD200 driver information struct
319 struct inquiry_data InquiryData
;
321 struct isd200_config ConfigData
;
322 unsigned char *RegsBuf
;
323 unsigned char ATARegs
[8];
324 unsigned char DeviceHead
;
325 unsigned char DeviceFlags
;
327 /* maximum number of LUNs supported */
328 unsigned char MaxLUNs
;
329 unsigned char cmnd
[MAX_COMMAND_SIZE
];
330 struct scsi_cmnd srb
;
331 struct scatterlist sg
;
336 * Read Capacity Data - returned in Big Endian format
339 struct read_capacity_data
{
340 __be32 LogicalBlockAddress
;
341 __be32 BytesPerBlock
;
345 * Read Block Limits Data - returned in Big Endian format
346 * This structure returns the maximum and minimum block
347 * size for a TAPE device.
350 struct read_block_limits
{
351 unsigned char Reserved
;
352 unsigned char BlockMaximumSize
[3];
353 unsigned char BlockMinimumSize
[2];
361 #define SENSE_ERRCODE 0x7f
362 #define SENSE_ERRCODE_VALID 0x80
363 #define SENSE_FLAG_SENSE_KEY 0x0f
364 #define SENSE_FLAG_BAD_LENGTH 0x20
365 #define SENSE_FLAG_END_OF_MEDIA 0x40
366 #define SENSE_FLAG_FILE_MARK 0x80
368 unsigned char ErrorCode
;
369 unsigned char SegmentNumber
;
371 unsigned char Information
[4];
372 unsigned char AdditionalSenseLength
;
373 unsigned char CommandSpecificInformation
[4];
374 unsigned char AdditionalSenseCode
;
375 unsigned char AdditionalSenseCodeQualifier
;
376 unsigned char FieldReplaceableUnitCode
;
377 unsigned char SenseKeySpecific
[3];
378 } __attribute__ ((packed
));
381 * Default request sense buffer size
384 #define SENSE_BUFFER_SIZE 18
386 /***********************************************************************
388 ***********************************************************************/
390 /**************************************************************************
393 * Builds an artificial sense buffer to report the results of a
399 static void isd200_build_sense(struct us_data
*us
, struct scsi_cmnd
*srb
)
401 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
402 struct sense_data
*buf
= (struct sense_data
*) &srb
->sense_buffer
[0];
403 unsigned char error
= info
->ATARegs
[ATA_REG_ERROR_OFFSET
];
405 if(error
& ATA_ERROR_MEDIA_CHANGE
) {
406 buf
->ErrorCode
= 0x70 | SENSE_ERRCODE_VALID
;
407 buf
->AdditionalSenseLength
= 0xb;
408 buf
->Flags
= UNIT_ATTENTION
;
409 buf
->AdditionalSenseCode
= 0;
410 buf
->AdditionalSenseCodeQualifier
= 0;
411 } else if (error
& ATA_MCR
) {
412 buf
->ErrorCode
= 0x70 | SENSE_ERRCODE_VALID
;
413 buf
->AdditionalSenseLength
= 0xb;
414 buf
->Flags
= UNIT_ATTENTION
;
415 buf
->AdditionalSenseCode
= 0;
416 buf
->AdditionalSenseCodeQualifier
= 0;
417 } else if (error
& ATA_TRK0NF
) {
418 buf
->ErrorCode
= 0x70 | SENSE_ERRCODE_VALID
;
419 buf
->AdditionalSenseLength
= 0xb;
420 buf
->Flags
= NOT_READY
;
421 buf
->AdditionalSenseCode
= 0;
422 buf
->AdditionalSenseCodeQualifier
= 0;
423 } else if (error
& ATA_UNC
) {
424 buf
->ErrorCode
= 0x70 | SENSE_ERRCODE_VALID
;
425 buf
->AdditionalSenseLength
= 0xb;
426 buf
->Flags
= DATA_PROTECT
;
427 buf
->AdditionalSenseCode
= 0;
428 buf
->AdditionalSenseCodeQualifier
= 0;
431 buf
->AdditionalSenseLength
= 0;
433 buf
->AdditionalSenseCode
= 0;
434 buf
->AdditionalSenseCodeQualifier
= 0;
439 /***********************************************************************
441 ***********************************************************************/
443 /**************************************************************************
444 * isd200_set_srb(), isd200_srb_set_bufflen()
446 * Two helpers to facilitate in initialization of scsi_cmnd structure
447 * Will need to change when struct scsi_cmnd changes
449 static void isd200_set_srb(struct isd200_info
*info
,
450 enum dma_data_direction dir
, void* buff
, unsigned bufflen
)
452 struct scsi_cmnd
*srb
= &info
->srb
;
455 sg_init_one(&info
->sg
, buff
, bufflen
);
457 srb
->sc_data_direction
= dir
;
458 srb
->sdb
.table
.sgl
= buff
? &info
->sg
: NULL
;
459 srb
->sdb
.length
= bufflen
;
460 srb
->sdb
.table
.nents
= buff
? 1 : 0;
463 static void isd200_srb_set_bufflen(struct scsi_cmnd
*srb
, unsigned bufflen
)
465 srb
->sdb
.length
= bufflen
;
469 /**************************************************************************
472 * Routine for sending commands to the isd200
477 static int isd200_action( struct us_data
*us
, int action
,
478 void* pointer
, int value
)
481 /* static to prevent this large struct being placed on the valuable stack */
482 static struct scsi_device srb_dev
;
483 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
484 struct scsi_cmnd
*srb
= &info
->srb
;
487 memset(&ata
, 0, sizeof(ata
));
488 memcpy(srb
->cmnd
, info
->cmnd
, MAX_COMMAND_SIZE
);
489 srb
->device
= &srb_dev
;
491 ata
.generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
492 ata
.generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
493 ata
.generic
.TransferBlockSize
= 1;
496 case ACTION_READ_STATUS
:
497 usb_stor_dbg(us
, " isd200_action(READ_STATUS)\n");
498 ata
.generic
.ActionSelect
= ACTION_SELECT_0
|ACTION_SELECT_2
;
499 ata
.generic
.RegisterSelect
=
500 REG_CYLINDER_LOW
| REG_CYLINDER_HIGH
|
501 REG_STATUS
| REG_ERROR
;
502 isd200_set_srb(info
, DMA_FROM_DEVICE
, pointer
, value
);
506 usb_stor_dbg(us
, " isd200_action(ENUM,0x%02x)\n", value
);
507 ata
.generic
.ActionSelect
= ACTION_SELECT_1
|ACTION_SELECT_2
|
508 ACTION_SELECT_3
|ACTION_SELECT_4
|
510 ata
.generic
.RegisterSelect
= REG_DEVICE_HEAD
;
511 ata
.write
.DeviceHeadByte
= value
;
512 isd200_set_srb(info
, DMA_NONE
, NULL
, 0);
516 usb_stor_dbg(us
, " isd200_action(RESET)\n");
517 ata
.generic
.ActionSelect
= ACTION_SELECT_1
|ACTION_SELECT_2
|
518 ACTION_SELECT_3
|ACTION_SELECT_4
;
519 ata
.generic
.RegisterSelect
= REG_DEVICE_CONTROL
;
520 ata
.write
.DeviceControlByte
= ATA_DC_RESET_CONTROLLER
;
521 isd200_set_srb(info
, DMA_NONE
, NULL
, 0);
524 case ACTION_REENABLE
:
525 usb_stor_dbg(us
, " isd200_action(REENABLE)\n");
526 ata
.generic
.ActionSelect
= ACTION_SELECT_1
|ACTION_SELECT_2
|
527 ACTION_SELECT_3
|ACTION_SELECT_4
;
528 ata
.generic
.RegisterSelect
= REG_DEVICE_CONTROL
;
529 ata
.write
.DeviceControlByte
= ATA_DC_REENABLE_CONTROLLER
;
530 isd200_set_srb(info
, DMA_NONE
, NULL
, 0);
533 case ACTION_SOFT_RESET
:
534 usb_stor_dbg(us
, " isd200_action(SOFT_RESET)\n");
535 ata
.generic
.ActionSelect
= ACTION_SELECT_1
|ACTION_SELECT_5
;
536 ata
.generic
.RegisterSelect
= REG_DEVICE_HEAD
| REG_COMMAND
;
537 ata
.write
.DeviceHeadByte
= info
->DeviceHead
;
538 ata
.write
.CommandByte
= ATA_CMD_DEV_RESET
;
539 isd200_set_srb(info
, DMA_NONE
, NULL
, 0);
542 case ACTION_IDENTIFY
:
543 usb_stor_dbg(us
, " isd200_action(IDENTIFY)\n");
544 ata
.generic
.RegisterSelect
= REG_COMMAND
;
545 ata
.write
.CommandByte
= ATA_CMD_ID_ATA
;
546 isd200_set_srb(info
, DMA_FROM_DEVICE
, info
->id
,
551 usb_stor_dbg(us
, "Error: Undefined action %d\n", action
);
555 memcpy(srb
->cmnd
, &ata
, sizeof(ata
.generic
));
556 srb
->cmd_len
= sizeof(ata
.generic
);
557 status
= usb_stor_Bulk_transport(srb
, us
);
558 if (status
== USB_STOR_TRANSPORT_GOOD
)
559 status
= ISD200_GOOD
;
561 usb_stor_dbg(us
, " isd200_action(0x%02x) error: %d\n",
563 status
= ISD200_ERROR
;
564 /* need to reset device here */
570 /**************************************************************************
578 static int isd200_read_regs( struct us_data
*us
)
580 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
581 int retStatus
= ISD200_GOOD
;
584 usb_stor_dbg(us
, "Entering isd200_IssueATAReadRegs\n");
586 transferStatus
= isd200_action( us
, ACTION_READ_STATUS
,
587 info
->RegsBuf
, sizeof(info
->ATARegs
) );
588 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
589 usb_stor_dbg(us
, " Error reading ATA registers\n");
590 retStatus
= ISD200_ERROR
;
592 memcpy(info
->ATARegs
, info
->RegsBuf
, sizeof(info
->ATARegs
));
593 usb_stor_dbg(us
, " Got ATA Register[ATA_REG_ERROR_OFFSET] = 0x%x\n",
594 info
->ATARegs
[ATA_REG_ERROR_OFFSET
]);
601 /**************************************************************************
602 * Invoke the transport and basic error-handling/recovery methods
604 * This is used by the protocol layers to actually send the message to
605 * the device and receive the response.
607 static void isd200_invoke_transport( struct us_data
*us
,
608 struct scsi_cmnd
*srb
,
609 union ata_cdb
*ataCdb
)
611 int need_auto_sense
= 0;
615 /* send the command to the transport layer */
616 memcpy(srb
->cmnd
, ataCdb
, sizeof(ataCdb
->generic
));
617 srb
->cmd_len
= sizeof(ataCdb
->generic
);
618 transferStatus
= usb_stor_Bulk_transport(srb
, us
);
621 * if the command gets aborted by the higher layers, we need to
622 * short-circuit all other processing
624 if (test_bit(US_FLIDX_TIMED_OUT
, &us
->dflags
)) {
625 usb_stor_dbg(us
, "-- command was aborted\n");
629 switch (transferStatus
) {
631 case USB_STOR_TRANSPORT_GOOD
:
632 /* Indicate a good result */
633 srb
->result
= SAM_STAT_GOOD
;
636 case USB_STOR_TRANSPORT_NO_SENSE
:
637 usb_stor_dbg(us
, "-- transport indicates protocol failure\n");
638 srb
->result
= SAM_STAT_CHECK_CONDITION
;
641 case USB_STOR_TRANSPORT_FAILED
:
642 usb_stor_dbg(us
, "-- transport indicates command failure\n");
646 case USB_STOR_TRANSPORT_ERROR
:
647 usb_stor_dbg(us
, "-- transport indicates transport error\n");
648 srb
->result
= DID_ERROR
<< 16;
649 /* Need reset here */
653 usb_stor_dbg(us
, "-- transport indicates unknown error\n");
654 srb
->result
= DID_ERROR
<< 16;
655 /* Need reset here */
659 if ((scsi_get_resid(srb
) > 0) &&
660 !((srb
->cmnd
[0] == REQUEST_SENSE
) ||
661 (srb
->cmnd
[0] == INQUIRY
) ||
662 (srb
->cmnd
[0] == MODE_SENSE
) ||
663 (srb
->cmnd
[0] == LOG_SENSE
) ||
664 (srb
->cmnd
[0] == MODE_SENSE_10
))) {
665 usb_stor_dbg(us
, "-- unexpectedly short transfer\n");
669 if (need_auto_sense
) {
670 result
= isd200_read_regs(us
);
671 if (test_bit(US_FLIDX_TIMED_OUT
, &us
->dflags
)) {
672 usb_stor_dbg(us
, "-- auto-sense aborted\n");
675 if (result
== ISD200_GOOD
) {
676 isd200_build_sense(us
, srb
);
677 srb
->result
= SAM_STAT_CHECK_CONDITION
;
679 /* If things are really okay, then let's show that */
680 if ((srb
->sense_buffer
[2] & 0xf) == 0x0)
681 srb
->result
= SAM_STAT_GOOD
;
683 srb
->result
= DID_ERROR
<< 16;
684 /* Need reset here */
689 * Regardless of auto-sense, if we _know_ we have an error
690 * condition, show that in the result code
692 if (transferStatus
== USB_STOR_TRANSPORT_FAILED
)
693 srb
->result
= SAM_STAT_CHECK_CONDITION
;
697 * abort processing: the bulk-only transport requires a reset
701 srb
->result
= DID_ABORT
<< 16;
703 /* permit the reset transfer to take place */
704 clear_bit(US_FLIDX_ABORTING
, &us
->dflags
);
705 /* Need reset here */
708 #ifdef CONFIG_USB_STORAGE_DEBUG
709 static void isd200_log_config(struct us_data
*us
, struct isd200_info
*info
)
711 usb_stor_dbg(us
, " Event Notification: 0x%x\n",
712 info
->ConfigData
.EventNotification
);
713 usb_stor_dbg(us
, " External Clock: 0x%x\n",
714 info
->ConfigData
.ExternalClock
);
715 usb_stor_dbg(us
, " ATA Init Timeout: 0x%x\n",
716 info
->ConfigData
.ATAInitTimeout
);
717 usb_stor_dbg(us
, " ATAPI Command Block Size: 0x%x\n",
718 (info
->ConfigData
.ATAConfig
& ATACFG_BLOCKSIZE
) >> 6);
719 usb_stor_dbg(us
, " Master/Slave Selection: 0x%x\n",
720 info
->ConfigData
.ATAConfig
& ATACFG_MASTER
);
721 usb_stor_dbg(us
, " ATAPI Reset: 0x%x\n",
722 info
->ConfigData
.ATAConfig
& ATACFG_ATAPI_RESET
);
723 usb_stor_dbg(us
, " ATA Timing: 0x%x\n",
724 info
->ConfigData
.ATAConfig
& ATACFG_TIMING
);
725 usb_stor_dbg(us
, " ATA Major Command: 0x%x\n",
726 info
->ConfigData
.ATAMajorCommand
);
727 usb_stor_dbg(us
, " ATA Minor Command: 0x%x\n",
728 info
->ConfigData
.ATAMinorCommand
);
729 usb_stor_dbg(us
, " Init Status: 0x%x\n",
730 info
->ConfigData
.ATAExtraConfig
& ATACFGE_INIT_STATUS
);
731 usb_stor_dbg(us
, " Config Descriptor 2: 0x%x\n",
732 info
->ConfigData
.ATAExtraConfig
& ATACFGE_CONF_DESC2
);
733 usb_stor_dbg(us
, " Skip Device Boot: 0x%x\n",
734 info
->ConfigData
.ATAExtraConfig
& ATACFGE_SKIP_BOOT
);
735 usb_stor_dbg(us
, " ATA 3 State Suspend: 0x%x\n",
736 info
->ConfigData
.ATAExtraConfig
& ATACFGE_STATE_SUSPEND
);
737 usb_stor_dbg(us
, " Descriptor Override: 0x%x\n",
738 info
->ConfigData
.ATAExtraConfig
& ATACFGE_DESC_OVERRIDE
);
739 usb_stor_dbg(us
, " Last LUN Identifier: 0x%x\n",
740 info
->ConfigData
.ATAExtraConfig
& ATACFGE_LAST_LUN
);
741 usb_stor_dbg(us
, " SRST Enable: 0x%x\n",
742 info
->ConfigData
.ATAExtraConfig
& CFG_CAPABILITY_SRST
);
746 /**************************************************************************
747 * isd200_write_config
749 * Write the ISD200 Configuration data
754 static int isd200_write_config( struct us_data
*us
)
756 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
757 int retStatus
= ISD200_GOOD
;
760 #ifdef CONFIG_USB_STORAGE_DEBUG
761 usb_stor_dbg(us
, "Entering isd200_write_config\n");
762 usb_stor_dbg(us
, " Writing the following ISD200 Config Data:\n");
763 isd200_log_config(us
, info
);
766 /* let's send the command via the control pipe */
767 result
= usb_stor_ctrl_transfer(
771 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
774 (void *) &info
->ConfigData
,
775 sizeof(info
->ConfigData
));
778 usb_stor_dbg(us
, " ISD200 Config Data was written successfully\n");
780 usb_stor_dbg(us
, " Request to write ISD200 Config Data failed!\n");
781 retStatus
= ISD200_ERROR
;
784 usb_stor_dbg(us
, "Leaving isd200_write_config %08X\n", retStatus
);
789 /**************************************************************************
792 * Reads the ISD200 Configuration data
797 static int isd200_read_config( struct us_data
*us
)
799 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
800 int retStatus
= ISD200_GOOD
;
803 usb_stor_dbg(us
, "Entering isd200_read_config\n");
805 /* read the configuration information from ISD200. Use this to */
806 /* determine what the special ATA CDB bytes are. */
808 result
= usb_stor_ctrl_transfer(
812 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
815 (void *) &info
->ConfigData
,
816 sizeof(info
->ConfigData
));
820 usb_stor_dbg(us
, " Retrieved the following ISD200 Config Data:\n");
821 #ifdef CONFIG_USB_STORAGE_DEBUG
822 isd200_log_config(us
, info
);
825 usb_stor_dbg(us
, " Request to get ISD200 Config Data failed!\n");
826 retStatus
= ISD200_ERROR
;
829 usb_stor_dbg(us
, "Leaving isd200_read_config %08X\n", retStatus
);
834 /**************************************************************************
835 * isd200_atapi_soft_reset
837 * Perform an Atapi Soft Reset on the device
842 static int isd200_atapi_soft_reset( struct us_data
*us
)
844 int retStatus
= ISD200_GOOD
;
847 usb_stor_dbg(us
, "Entering isd200_atapi_soft_reset\n");
849 transferStatus
= isd200_action( us
, ACTION_SOFT_RESET
, NULL
, 0 );
850 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
851 usb_stor_dbg(us
, " Error issuing Atapi Soft Reset\n");
852 retStatus
= ISD200_ERROR
;
855 usb_stor_dbg(us
, "Leaving isd200_atapi_soft_reset %08X\n", retStatus
);
860 /**************************************************************************
863 * Perform an SRST on the device
868 static int isd200_srst( struct us_data
*us
)
870 int retStatus
= ISD200_GOOD
;
873 usb_stor_dbg(us
, "Entering isd200_SRST\n");
875 transferStatus
= isd200_action( us
, ACTION_RESET
, NULL
, 0 );
877 /* check to see if this request failed */
878 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
879 usb_stor_dbg(us
, " Error issuing SRST\n");
880 retStatus
= ISD200_ERROR
;
882 /* delay 10ms to give the drive a chance to see it */
885 transferStatus
= isd200_action( us
, ACTION_REENABLE
, NULL
, 0 );
886 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
887 usb_stor_dbg(us
, " Error taking drive out of reset\n");
888 retStatus
= ISD200_ERROR
;
890 /* delay 50ms to give the drive a chance to recover after SRST */
895 usb_stor_dbg(us
, "Leaving isd200_srst %08X\n", retStatus
);
900 /**************************************************************************
903 * Helper function for isd200_manual_enum(). Does ENUM and READ_STATUS
904 * and tries to analyze the status registers
909 static int isd200_try_enum(struct us_data
*us
, unsigned char master_slave
,
912 int status
= ISD200_GOOD
;
913 unsigned long endTime
;
914 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
915 unsigned char *regs
= info
->RegsBuf
;
916 int recheckAsMaster
= 0;
919 endTime
= jiffies
+ ISD200_ENUM_DETECT_TIMEOUT
* HZ
;
921 endTime
= jiffies
+ ISD200_ENUM_BSY_TIMEOUT
* HZ
;
923 /* loop until we detect !BSY or timeout */
926 status
= isd200_action( us
, ACTION_ENUM
, NULL
, master_slave
);
927 if ( status
!= ISD200_GOOD
)
930 status
= isd200_action( us
, ACTION_READ_STATUS
,
932 if ( status
!= ISD200_GOOD
)
936 if (regs
[ATA_REG_STATUS_OFFSET
] & ATA_BUSY
) {
937 usb_stor_dbg(us
, " %s status is still BSY, try again...\n",
938 master_slave
== ATA_ADDRESS_DEVHEAD_STD
?
941 usb_stor_dbg(us
, " %s status !BSY, continue with next operation\n",
942 master_slave
== ATA_ADDRESS_DEVHEAD_STD
?
947 /* check for ATA_BUSY and */
948 /* ATA_DF (workaround ATA Zip drive) and */
949 /* ATA_ERR (workaround for Archos CD-ROM) */
950 else if (regs
[ATA_REG_STATUS_OFFSET
] &
951 (ATA_BUSY
| ATA_DF
| ATA_ERR
)) {
952 usb_stor_dbg(us
, " Status indicates it is not ready, try again...\n");
954 /* check for DRDY, ATA devices set DRDY after SRST */
955 else if (regs
[ATA_REG_STATUS_OFFSET
] & ATA_DRDY
) {
956 usb_stor_dbg(us
, " Identified ATA device\n");
957 info
->DeviceFlags
|= DF_ATA_DEVICE
;
958 info
->DeviceHead
= master_slave
;
962 * check Cylinder High/Low to
963 * determine if it is an ATAPI device
965 else if (regs
[ATA_REG_HCYL_OFFSET
] == 0xEB &&
966 regs
[ATA_REG_LCYL_OFFSET
] == 0x14) {
968 * It seems that the RICOH
969 * MP6200A CD/RW drive will
970 * report itself okay as a
971 * slave when it is really a
972 * master. So this check again
973 * as a master device just to
974 * make sure it doesn't report
975 * itself okay as a master also
977 if ((master_slave
& ATA_ADDRESS_DEVHEAD_SLAVE
) &&
979 usb_stor_dbg(us
, " Identified ATAPI device as slave. Rechecking again as master\n");
981 master_slave
= ATA_ADDRESS_DEVHEAD_STD
;
983 usb_stor_dbg(us
, " Identified ATAPI device\n");
984 info
->DeviceHead
= master_slave
;
986 status
= isd200_atapi_soft_reset(us
);
990 usb_stor_dbg(us
, " Not ATA, not ATAPI - Weird\n");
994 /* check for timeout on this request */
995 if (time_after_eq(jiffies
, endTime
)) {
997 usb_stor_dbg(us
, " BSY check timeout, just continue with next operation...\n");
999 usb_stor_dbg(us
, " Device detect timeout!\n");
1007 /**************************************************************************
1008 * isd200_manual_enum
1010 * Determines if the drive attached is an ATA or ATAPI and if it is a
1016 static int isd200_manual_enum(struct us_data
*us
)
1018 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
1019 int retStatus
= ISD200_GOOD
;
1021 usb_stor_dbg(us
, "Entering isd200_manual_enum\n");
1023 retStatus
= isd200_read_config(us
);
1024 if (retStatus
== ISD200_GOOD
) {
1026 /* master or slave? */
1027 retStatus
= isd200_try_enum( us
, ATA_ADDRESS_DEVHEAD_STD
, 0);
1028 if (retStatus
== ISD200_GOOD
)
1029 retStatus
= isd200_try_enum( us
, ATA_ADDRESS_DEVHEAD_SLAVE
, 0);
1031 if (retStatus
== ISD200_GOOD
) {
1032 retStatus
= isd200_srst(us
);
1033 if (retStatus
== ISD200_GOOD
)
1035 retStatus
= isd200_try_enum( us
, ATA_ADDRESS_DEVHEAD_STD
, 1);
1038 isslave
= (info
->DeviceHead
& ATA_ADDRESS_DEVHEAD_SLAVE
) ? 1 : 0;
1039 if (!(info
->ConfigData
.ATAConfig
& ATACFG_MASTER
)) {
1040 usb_stor_dbg(us
, " Setting Master/Slave selection to %d\n",
1042 info
->ConfigData
.ATAConfig
&= 0x3f;
1043 info
->ConfigData
.ATAConfig
|= (isslave
<<6);
1044 retStatus
= isd200_write_config(us
);
1048 usb_stor_dbg(us
, "Leaving isd200_manual_enum %08X\n", retStatus
);
1052 static void isd200_fix_driveid(u16
*id
)
1054 #ifndef __LITTLE_ENDIAN
1055 # ifdef __BIG_ENDIAN
1058 for (i
= 0; i
< ATA_ID_WORDS
; i
++)
1059 id
[i
] = __le16_to_cpu(id
[i
]);
1061 # error "Please fix <asm/byteorder.h>"
1066 static void isd200_dump_driveid(struct us_data
*us
, u16
*id
)
1068 usb_stor_dbg(us
, " Identify Data Structure:\n");
1069 usb_stor_dbg(us
, " config = 0x%x\n", id
[ATA_ID_CONFIG
]);
1070 usb_stor_dbg(us
, " cyls = 0x%x\n", id
[ATA_ID_CYLS
]);
1071 usb_stor_dbg(us
, " heads = 0x%x\n", id
[ATA_ID_HEADS
]);
1072 usb_stor_dbg(us
, " track_bytes = 0x%x\n", id
[4]);
1073 usb_stor_dbg(us
, " sector_bytes = 0x%x\n", id
[5]);
1074 usb_stor_dbg(us
, " sectors = 0x%x\n", id
[ATA_ID_SECTORS
]);
1075 usb_stor_dbg(us
, " serial_no[0] = 0x%x\n", *(char *)&id
[ATA_ID_SERNO
]);
1076 usb_stor_dbg(us
, " buf_type = 0x%x\n", id
[20]);
1077 usb_stor_dbg(us
, " buf_size = 0x%x\n", id
[ATA_ID_BUF_SIZE
]);
1078 usb_stor_dbg(us
, " ecc_bytes = 0x%x\n", id
[22]);
1079 usb_stor_dbg(us
, " fw_rev[0] = 0x%x\n", *(char *)&id
[ATA_ID_FW_REV
]);
1080 usb_stor_dbg(us
, " model[0] = 0x%x\n", *(char *)&id
[ATA_ID_PROD
]);
1081 usb_stor_dbg(us
, " max_multsect = 0x%x\n", id
[ATA_ID_MAX_MULTSECT
] & 0xff);
1082 usb_stor_dbg(us
, " dword_io = 0x%x\n", id
[ATA_ID_DWORD_IO
]);
1083 usb_stor_dbg(us
, " capability = 0x%x\n", id
[ATA_ID_CAPABILITY
] >> 8);
1084 usb_stor_dbg(us
, " tPIO = 0x%x\n", id
[ATA_ID_OLD_PIO_MODES
] >> 8);
1085 usb_stor_dbg(us
, " tDMA = 0x%x\n", id
[ATA_ID_OLD_DMA_MODES
] >> 8);
1086 usb_stor_dbg(us
, " field_valid = 0x%x\n", id
[ATA_ID_FIELD_VALID
]);
1087 usb_stor_dbg(us
, " cur_cyls = 0x%x\n", id
[ATA_ID_CUR_CYLS
]);
1088 usb_stor_dbg(us
, " cur_heads = 0x%x\n", id
[ATA_ID_CUR_HEADS
]);
1089 usb_stor_dbg(us
, " cur_sectors = 0x%x\n", id
[ATA_ID_CUR_SECTORS
]);
1090 usb_stor_dbg(us
, " cur_capacity = 0x%x\n", ata_id_u32(id
, 57));
1091 usb_stor_dbg(us
, " multsect = 0x%x\n", id
[ATA_ID_MULTSECT
] & 0xff);
1092 usb_stor_dbg(us
, " lba_capacity = 0x%x\n", ata_id_u32(id
, ATA_ID_LBA_CAPACITY
));
1093 usb_stor_dbg(us
, " command_set_1 = 0x%x\n", id
[ATA_ID_COMMAND_SET_1
]);
1094 usb_stor_dbg(us
, " command_set_2 = 0x%x\n", id
[ATA_ID_COMMAND_SET_2
]);
1097 /**************************************************************************
1098 * isd200_get_inquiry_data
1105 static int isd200_get_inquiry_data( struct us_data
*us
)
1107 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
1111 usb_stor_dbg(us
, "Entering isd200_get_inquiry_data\n");
1113 /* set default to Master */
1114 info
->DeviceHead
= ATA_ADDRESS_DEVHEAD_STD
;
1116 /* attempt to manually enumerate this device */
1117 retStatus
= isd200_manual_enum(us
);
1118 if (retStatus
== ISD200_GOOD
) {
1121 /* check for an ATA device */
1122 if (info
->DeviceFlags
& DF_ATA_DEVICE
) {
1123 /* this must be an ATA device */
1124 /* perform an ATA Command Identify */
1125 transferStatus
= isd200_action( us
, ACTION_IDENTIFY
,
1126 id
, ATA_ID_WORDS
* 2);
1127 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
1128 /* Error issuing ATA Command Identify */
1129 usb_stor_dbg(us
, " Error issuing ATA Command Identify\n");
1130 retStatus
= ISD200_ERROR
;
1132 /* ATA Command Identify successful */
1137 isd200_fix_driveid(id
);
1138 isd200_dump_driveid(us
, id
);
1140 /* Prevent division by 0 in isd200_scsi_to_ata() */
1141 if (id
[ATA_ID_HEADS
] == 0 || id
[ATA_ID_SECTORS
] == 0) {
1142 usb_stor_dbg(us
, " Invalid ATA Identify data\n");
1143 retStatus
= ISD200_ERROR
;
1147 memset(&info
->InquiryData
, 0, sizeof(info
->InquiryData
));
1149 /* Standard IDE interface only supports disks */
1150 info
->InquiryData
.DeviceType
= DIRECT_ACCESS_DEVICE
;
1152 /* The length must be at least 36 (5 + 31) */
1153 info
->InquiryData
.AdditionalLength
= 0x1F;
1155 if (id
[ATA_ID_COMMAND_SET_1
] & COMMANDSET_MEDIA_STATUS
) {
1156 /* set the removable bit */
1157 info
->InquiryData
.DeviceTypeModifier
= DEVICE_REMOVABLE
;
1158 info
->DeviceFlags
|= DF_REMOVABLE_MEDIA
;
1161 /* Fill in vendor identification fields */
1162 src
= (__be16
*)&id
[ATA_ID_PROD
];
1163 dest
= (__u16
*)info
->InquiryData
.VendorId
;
1164 for (i
= 0; i
< 4; i
++)
1165 dest
[i
] = be16_to_cpu(src
[i
]);
1167 src
= (__be16
*)&id
[ATA_ID_PROD
+ 8/2];
1168 dest
= (__u16
*)info
->InquiryData
.ProductId
;
1170 dest
[i
] = be16_to_cpu(src
[i
]);
1172 src
= (__be16
*)&id
[ATA_ID_FW_REV
];
1173 dest
= (__u16
*)info
->InquiryData
.ProductRevisionLevel
;
1175 dest
[i
] = be16_to_cpu(src
[i
]);
1177 /* determine if it supports Media Status Notification */
1178 if (id
[ATA_ID_COMMAND_SET_2
] & COMMANDSET_MEDIA_STATUS
) {
1179 usb_stor_dbg(us
, " Device supports Media Status Notification\n");
1182 * Indicate that it is enabled, even
1184 * This allows the lock/unlock of the
1185 * media to work correctly.
1187 info
->DeviceFlags
|= DF_MEDIA_STATUS_ENABLED
;
1190 info
->DeviceFlags
&= ~DF_MEDIA_STATUS_ENABLED
;
1195 * this must be an ATAPI device
1196 * use an ATAPI protocol (Transparent SCSI)
1198 us
->protocol_name
= "Transparent SCSI";
1199 us
->proto_handler
= usb_stor_transparent_scsi_command
;
1201 usb_stor_dbg(us
, "Protocol changed to: %s\n",
1204 /* Free driver structure */
1205 us
->extra_destructor(info
);
1208 us
->extra_destructor
= NULL
;
1213 usb_stor_dbg(us
, "Leaving isd200_get_inquiry_data %08X\n", retStatus
);
1218 /**************************************************************************
1219 * isd200_scsi_to_ata
1221 * Translate SCSI commands to ATA commands.
1224 * 1 if the command needs to be sent to the transport layer
1227 static int isd200_scsi_to_ata(struct scsi_cmnd
*srb
, struct us_data
*us
,
1228 union ata_cdb
* ataCdb
)
1230 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
1232 int sendToTransport
= 1;
1233 unsigned char sectnum
, head
;
1234 unsigned short cylinder
;
1236 unsigned long blockCount
;
1237 unsigned char senseData
[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1239 memset(ataCdb
, 0, sizeof(union ata_cdb
));
1242 switch (srb
->cmnd
[0]) {
1244 usb_stor_dbg(us
, " ATA OUT - INQUIRY\n");
1246 /* copy InquiryData */
1247 usb_stor_set_xfer_buf((unsigned char *) &info
->InquiryData
,
1248 sizeof(info
->InquiryData
), srb
);
1249 srb
->result
= SAM_STAT_GOOD
;
1250 sendToTransport
= 0;
1254 usb_stor_dbg(us
, " ATA OUT - SCSIOP_MODE_SENSE\n");
1256 /* Initialize the return buffer */
1257 usb_stor_set_xfer_buf(senseData
, sizeof(senseData
), srb
);
1259 if (info
->DeviceFlags
& DF_MEDIA_STATUS_ENABLED
)
1261 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1262 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1263 ataCdb
->generic
.TransferBlockSize
= 1;
1264 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1265 ataCdb
->write
.CommandByte
= ATA_COMMAND_GET_MEDIA_STATUS
;
1266 isd200_srb_set_bufflen(srb
, 0);
1268 usb_stor_dbg(us
, " Media Status not supported, just report okay\n");
1269 srb
->result
= SAM_STAT_GOOD
;
1270 sendToTransport
= 0;
1274 case TEST_UNIT_READY
:
1275 usb_stor_dbg(us
, " ATA OUT - SCSIOP_TEST_UNIT_READY\n");
1277 if (info
->DeviceFlags
& DF_MEDIA_STATUS_ENABLED
)
1279 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1280 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1281 ataCdb
->generic
.TransferBlockSize
= 1;
1282 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1283 ataCdb
->write
.CommandByte
= ATA_COMMAND_GET_MEDIA_STATUS
;
1284 isd200_srb_set_bufflen(srb
, 0);
1286 usb_stor_dbg(us
, " Media Status not supported, just report okay\n");
1287 srb
->result
= SAM_STAT_GOOD
;
1288 sendToTransport
= 0;
1294 unsigned long capacity
;
1295 struct read_capacity_data readCapacityData
;
1297 usb_stor_dbg(us
, " ATA OUT - SCSIOP_READ_CAPACITY\n");
1299 if (ata_id_has_lba(id
))
1300 capacity
= ata_id_u32(id
, ATA_ID_LBA_CAPACITY
) - 1;
1302 capacity
= (id
[ATA_ID_HEADS
] * id
[ATA_ID_CYLS
] *
1303 id
[ATA_ID_SECTORS
]) - 1;
1305 readCapacityData
.LogicalBlockAddress
= cpu_to_be32(capacity
);
1306 readCapacityData
.BytesPerBlock
= cpu_to_be32(0x200);
1308 usb_stor_set_xfer_buf((unsigned char *) &readCapacityData
,
1309 sizeof(readCapacityData
), srb
);
1310 srb
->result
= SAM_STAT_GOOD
;
1311 sendToTransport
= 0;
1316 usb_stor_dbg(us
, " ATA OUT - SCSIOP_READ\n");
1318 lba
= be32_to_cpu(*(__be32
*)&srb
->cmnd
[2]);
1319 blockCount
= (unsigned long)srb
->cmnd
[7]<<8 | (unsigned long)srb
->cmnd
[8];
1321 if (ata_id_has_lba(id
)) {
1322 sectnum
= (unsigned char)(lba
);
1323 cylinder
= (unsigned short)(lba
>>8);
1324 head
= ATA_ADDRESS_DEVHEAD_LBA_MODE
| (unsigned char)(lba
>>24 & 0x0F);
1326 sectnum
= (u8
)((lba
% id
[ATA_ID_SECTORS
]) + 1);
1327 cylinder
= (u16
)(lba
/ (id
[ATA_ID_SECTORS
] *
1329 head
= (u8
)((lba
/ id
[ATA_ID_SECTORS
]) %
1332 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1333 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1334 ataCdb
->generic
.TransferBlockSize
= 1;
1335 ataCdb
->generic
.RegisterSelect
=
1336 REG_SECTOR_COUNT
| REG_SECTOR_NUMBER
|
1337 REG_CYLINDER_LOW
| REG_CYLINDER_HIGH
|
1338 REG_DEVICE_HEAD
| REG_COMMAND
;
1339 ataCdb
->write
.SectorCountByte
= (unsigned char)blockCount
;
1340 ataCdb
->write
.SectorNumberByte
= sectnum
;
1341 ataCdb
->write
.CylinderHighByte
= (unsigned char)(cylinder
>>8);
1342 ataCdb
->write
.CylinderLowByte
= (unsigned char)cylinder
;
1343 ataCdb
->write
.DeviceHeadByte
= (head
| ATA_ADDRESS_DEVHEAD_STD
);
1344 ataCdb
->write
.CommandByte
= ATA_CMD_PIO_READ
;
1348 usb_stor_dbg(us
, " ATA OUT - SCSIOP_WRITE\n");
1350 lba
= be32_to_cpu(*(__be32
*)&srb
->cmnd
[2]);
1351 blockCount
= (unsigned long)srb
->cmnd
[7]<<8 | (unsigned long)srb
->cmnd
[8];
1353 if (ata_id_has_lba(id
)) {
1354 sectnum
= (unsigned char)(lba
);
1355 cylinder
= (unsigned short)(lba
>>8);
1356 head
= ATA_ADDRESS_DEVHEAD_LBA_MODE
| (unsigned char)(lba
>>24 & 0x0F);
1358 sectnum
= (u8
)((lba
% id
[ATA_ID_SECTORS
]) + 1);
1359 cylinder
= (u16
)(lba
/ (id
[ATA_ID_SECTORS
] *
1361 head
= (u8
)((lba
/ id
[ATA_ID_SECTORS
]) %
1364 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1365 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1366 ataCdb
->generic
.TransferBlockSize
= 1;
1367 ataCdb
->generic
.RegisterSelect
=
1368 REG_SECTOR_COUNT
| REG_SECTOR_NUMBER
|
1369 REG_CYLINDER_LOW
| REG_CYLINDER_HIGH
|
1370 REG_DEVICE_HEAD
| REG_COMMAND
;
1371 ataCdb
->write
.SectorCountByte
= (unsigned char)blockCount
;
1372 ataCdb
->write
.SectorNumberByte
= sectnum
;
1373 ataCdb
->write
.CylinderHighByte
= (unsigned char)(cylinder
>>8);
1374 ataCdb
->write
.CylinderLowByte
= (unsigned char)cylinder
;
1375 ataCdb
->write
.DeviceHeadByte
= (head
| ATA_ADDRESS_DEVHEAD_STD
);
1376 ataCdb
->write
.CommandByte
= ATA_CMD_PIO_WRITE
;
1379 case ALLOW_MEDIUM_REMOVAL
:
1380 usb_stor_dbg(us
, " ATA OUT - SCSIOP_MEDIUM_REMOVAL\n");
1382 if (info
->DeviceFlags
& DF_REMOVABLE_MEDIA
) {
1383 usb_stor_dbg(us
, " srb->cmnd[4] = 0x%X\n",
1386 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1387 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1388 ataCdb
->generic
.TransferBlockSize
= 1;
1389 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1390 ataCdb
->write
.CommandByte
= (srb
->cmnd
[4] & 0x1) ?
1391 ATA_CMD_MEDIA_LOCK
: ATA_CMD_MEDIA_UNLOCK
;
1392 isd200_srb_set_bufflen(srb
, 0);
1394 usb_stor_dbg(us
, " Not removable media, just report okay\n");
1395 srb
->result
= SAM_STAT_GOOD
;
1396 sendToTransport
= 0;
1401 usb_stor_dbg(us
, " ATA OUT - SCSIOP_START_STOP_UNIT\n");
1402 usb_stor_dbg(us
, " srb->cmnd[4] = 0x%X\n", srb
->cmnd
[4]);
1404 if ((srb
->cmnd
[4] & 0x3) == 0x2) {
1405 usb_stor_dbg(us
, " Media Eject\n");
1406 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1407 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1408 ataCdb
->generic
.TransferBlockSize
= 0;
1409 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1410 ataCdb
->write
.CommandByte
= ATA_COMMAND_MEDIA_EJECT
;
1411 } else if ((srb
->cmnd
[4] & 0x3) == 0x1) {
1412 usb_stor_dbg(us
, " Get Media Status\n");
1413 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1414 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1415 ataCdb
->generic
.TransferBlockSize
= 1;
1416 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1417 ataCdb
->write
.CommandByte
= ATA_COMMAND_GET_MEDIA_STATUS
;
1418 isd200_srb_set_bufflen(srb
, 0);
1420 usb_stor_dbg(us
, " Nothing to do, just report okay\n");
1421 srb
->result
= SAM_STAT_GOOD
;
1422 sendToTransport
= 0;
1427 usb_stor_dbg(us
, "Unsupported SCSI command - 0x%X\n",
1429 srb
->result
= DID_ERROR
<< 16;
1430 sendToTransport
= 0;
1434 return(sendToTransport
);
1438 /**************************************************************************
1441 * Frees the driver structure.
1443 static void isd200_free_info_ptrs(void *info_
)
1445 struct isd200_info
*info
= (struct isd200_info
*) info_
;
1449 kfree(info
->RegsBuf
);
1450 kfree(info
->srb
.sense_buffer
);
1454 /**************************************************************************
1457 * Allocates (if necessary) and initializes the driver structure.
1462 static int isd200_init_info(struct us_data
*us
)
1464 struct isd200_info
*info
;
1466 info
= kzalloc(sizeof(struct isd200_info
), GFP_KERNEL
);
1470 info
->id
= kzalloc(ATA_ID_WORDS
* 2, GFP_KERNEL
);
1471 info
->RegsBuf
= kmalloc(sizeof(info
->ATARegs
), GFP_KERNEL
);
1472 info
->srb
.sense_buffer
= kmalloc(SCSI_SENSE_BUFFERSIZE
, GFP_KERNEL
);
1474 if (!info
->id
|| !info
->RegsBuf
|| !info
->srb
.sense_buffer
) {
1475 isd200_free_info_ptrs(info
);
1481 us
->extra_destructor
= isd200_free_info_ptrs
;
1486 /**************************************************************************
1487 * Initialization for the ISD200
1490 static int isd200_Initialization(struct us_data
*us
)
1494 usb_stor_dbg(us
, "ISD200 Initialization...\n");
1496 /* Initialize ISD200 info struct */
1498 if (isd200_init_info(us
) < 0) {
1499 usb_stor_dbg(us
, "ERROR Initializing ISD200 Info struct\n");
1502 /* Get device specific data */
1504 if (isd200_get_inquiry_data(us
) != ISD200_GOOD
) {
1505 usb_stor_dbg(us
, "ISD200 Initialization Failure\n");
1508 usb_stor_dbg(us
, "ISD200 Initialization complete\n");
1516 /**************************************************************************
1517 * Protocol and Transport for the ISD200 ASIC
1519 * This protocol and transport are for ATA devices connected to an ISD200
1520 * ASIC. An ATAPI device that is connected as a slave device will be
1521 * detected in the driver initialization function and the protocol will
1522 * be changed to an ATAPI protocol (Transparent SCSI).
1526 static void isd200_ata_command(struct scsi_cmnd
*srb
, struct us_data
*us
)
1528 int sendToTransport
, orig_bufflen
;
1529 union ata_cdb ataCdb
;
1531 /* Make sure driver was initialized */
1533 if (us
->extra
== NULL
) {
1534 usb_stor_dbg(us
, "ERROR Driver not initialized\n");
1535 srb
->result
= DID_ERROR
<< 16;
1539 scsi_set_resid(srb
, 0);
1540 /* scsi_bufflen might change in protocol translation to ata */
1541 orig_bufflen
= scsi_bufflen(srb
);
1542 sendToTransport
= isd200_scsi_to_ata(srb
, us
, &ataCdb
);
1544 /* send the command to the transport layer */
1545 if (sendToTransport
)
1546 isd200_invoke_transport(us
, srb
, &ataCdb
);
1548 isd200_srb_set_bufflen(srb
, orig_bufflen
);
1551 static struct scsi_host_template isd200_host_template
;
1553 static int isd200_probe(struct usb_interface
*intf
,
1554 const struct usb_device_id
*id
)
1559 result
= usb_stor_probe1(&us
, intf
, id
,
1560 (id
- isd200_usb_ids
) + isd200_unusual_dev_list
,
1561 &isd200_host_template
);
1565 us
->protocol_name
= "ISD200 ATA/ATAPI";
1566 us
->proto_handler
= isd200_ata_command
;
1568 result
= usb_stor_probe2(us
);
1572 static struct usb_driver isd200_driver
= {
1574 .probe
= isd200_probe
,
1575 .disconnect
= usb_stor_disconnect
,
1576 .suspend
= usb_stor_suspend
,
1577 .resume
= usb_stor_resume
,
1578 .reset_resume
= usb_stor_reset_resume
,
1579 .pre_reset
= usb_stor_pre_reset
,
1580 .post_reset
= usb_stor_post_reset
,
1581 .id_table
= isd200_usb_ids
,
1586 module_usb_stor_driver(isd200_driver
, isd200_host_template
, DRV_NAME
);