1 /* Transport & Protocol Driver for In-System Design, Inc. ISD200 ASIC
3 * $Id: isd200.c,v 1.16 2002/04/22 03:39:43 mdharm Exp $
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.
18 * This program is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the
20 * Free Software Foundation; either version 2, or (at your option) any
23 * This program is distributed in the hope that it will be useful, but
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * General Public License for more details.
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 675 Mass Ave, Cambridge, MA 02139, USA.
34 * 2002-10-19: Removed the specialized transfer routines.
35 * (Alan Stern <stern@rowland.harvard.edu>)
36 * 2001-02-24: Removed lots of duplicate code and simplified the structure.
38 * 2002-01-16: Fixed endianness bug so it works on the ppc arch.
39 * (Luc Saillard <luc@saillard.org>)
40 * 2002-01-17: All bitfields removed.
47 #include <linux/jiffies.h>
48 #include <linux/errno.h>
49 #include <linux/slab.h>
50 #include <linux/hdreg.h>
51 #include <linux/ide.h>
53 #include <scsi/scsi.h>
54 #include <scsi/scsi_cmnd.h>
55 #include <scsi/scsi_device.h>
58 #include "transport.h"
65 /* Timeout defines (in Seconds) */
67 #define ISD200_ENUM_BSY_TIMEOUT 35
68 #define ISD200_ENUM_DETECT_TIMEOUT 30
69 #define ISD200_DEFAULT_TIMEOUT 30
72 #define DF_ATA_DEVICE 0x0001
73 #define DF_MEDIA_STATUS_ENABLED 0x0002
74 #define DF_REMOVABLE_MEDIA 0x0004
76 /* capability bit definitions */
77 #define CAPABILITY_DMA 0x01
78 #define CAPABILITY_LBA 0x02
80 /* command_setX bit definitions */
81 #define COMMANDSET_REMOVABLE 0x02
82 #define COMMANDSET_MEDIA_STATUS 0x10
84 /* ATA Vendor Specific defines */
85 #define ATA_ADDRESS_DEVHEAD_STD 0xa0
86 #define ATA_ADDRESS_DEVHEAD_LBA_MODE 0x40
87 #define ATA_ADDRESS_DEVHEAD_SLAVE 0x10
89 /* Action Select bits */
90 #define ACTION_SELECT_0 0x01
91 #define ACTION_SELECT_1 0x02
92 #define ACTION_SELECT_2 0x04
93 #define ACTION_SELECT_3 0x08
94 #define ACTION_SELECT_4 0x10
95 #define ACTION_SELECT_5 0x20
96 #define ACTION_SELECT_6 0x40
97 #define ACTION_SELECT_7 0x80
99 /* Register Select bits */
100 #define REG_ALTERNATE_STATUS 0x01
101 #define REG_DEVICE_CONTROL 0x01
102 #define REG_ERROR 0x02
103 #define REG_FEATURES 0x02
104 #define REG_SECTOR_COUNT 0x04
105 #define REG_SECTOR_NUMBER 0x08
106 #define REG_CYLINDER_LOW 0x10
107 #define REG_CYLINDER_HIGH 0x20
108 #define REG_DEVICE_HEAD 0x40
109 #define REG_STATUS 0x80
110 #define REG_COMMAND 0x80
112 /* ATA error definitions not in <linux/hdreg.h> */
113 #define ATA_ERROR_MEDIA_CHANGE 0x20
115 /* ATA command definitions not in <linux/hdreg.h> */
116 #define ATA_COMMAND_GET_MEDIA_STATUS 0xDA
117 #define ATA_COMMAND_MEDIA_EJECT 0xED
119 /* ATA drive control definitions */
120 #define ATA_DC_DISABLE_INTERRUPTS 0x02
121 #define ATA_DC_RESET_CONTROLLER 0x04
122 #define ATA_DC_REENABLE_CONTROLLER 0x00
125 * General purpose return codes
128 #define ISD200_ERROR -1
129 #define ISD200_GOOD 0
132 * Transport return codes
135 #define ISD200_TRANSPORT_GOOD 0 /* Transport good, command good */
136 #define ISD200_TRANSPORT_FAILED 1 /* Transport good, command failed */
137 #define ISD200_TRANSPORT_ERROR 2 /* Transport bad (i.e. device dead) */
139 /* driver action codes */
140 #define ACTION_READ_STATUS 0
141 #define ACTION_RESET 1
142 #define ACTION_REENABLE 2
143 #define ACTION_SOFT_RESET 3
144 #define ACTION_ENUM 4
145 #define ACTION_IDENTIFY 5
155 unsigned char SignatureByte0
;
156 unsigned char SignatureByte1
;
157 unsigned char ActionSelect
;
158 unsigned char RegisterSelect
;
159 unsigned char TransferBlockSize
;
160 unsigned char WriteData3F6
;
161 unsigned char WriteData1F1
;
162 unsigned char WriteData1F2
;
163 unsigned char WriteData1F3
;
164 unsigned char WriteData1F4
;
165 unsigned char WriteData1F5
;
166 unsigned char WriteData1F6
;
167 unsigned char WriteData1F7
;
168 unsigned char Reserved
[3];
172 unsigned char SignatureByte0
;
173 unsigned char SignatureByte1
;
174 unsigned char ActionSelect
;
175 unsigned char RegisterSelect
;
176 unsigned char TransferBlockSize
;
177 unsigned char AlternateStatusByte
;
178 unsigned char ErrorByte
;
179 unsigned char SectorCountByte
;
180 unsigned char SectorNumberByte
;
181 unsigned char CylinderLowByte
;
182 unsigned char CylinderHighByte
;
183 unsigned char DeviceHeadByte
;
184 unsigned char StatusByte
;
185 unsigned char Reserved
[3];
189 unsigned char SignatureByte0
;
190 unsigned char SignatureByte1
;
191 unsigned char ActionSelect
;
192 unsigned char RegisterSelect
;
193 unsigned char TransferBlockSize
;
194 unsigned char DeviceControlByte
;
195 unsigned char FeaturesByte
;
196 unsigned char SectorCountByte
;
197 unsigned char SectorNumberByte
;
198 unsigned char CylinderLowByte
;
199 unsigned char CylinderHighByte
;
200 unsigned char DeviceHeadByte
;
201 unsigned char CommandByte
;
202 unsigned char Reserved
[3];
208 * Inquiry data structure. This is the data returned from the target
209 * after it receives an inquiry.
211 * This structure may be extended by the number of bytes specified
212 * in the field AdditionalLength. The defined size constant only
213 * includes fields through ProductRevisionLevel.
219 #define DIRECT_ACCESS_DEVICE 0x00 /* disks */
220 #define DEVICE_REMOVABLE 0x80
222 struct inquiry_data
{
223 unsigned char DeviceType
;
224 unsigned char DeviceTypeModifier
;
225 unsigned char Versions
;
226 unsigned char Format
;
227 unsigned char AdditionalLength
;
228 unsigned char Reserved
[2];
229 unsigned char Capability
;
230 unsigned char VendorId
[8];
231 unsigned char ProductId
[16];
232 unsigned char ProductRevisionLevel
[4];
233 unsigned char VendorSpecific
[20];
234 unsigned char Reserved3
[40];
235 } __attribute__ ((packed
));
238 * INQUIRY data buffer size
241 #define INQUIRYDATABUFFERSIZE 36
245 * ISD200 CONFIG data struct
248 #define ATACFG_TIMING 0x0f
249 #define ATACFG_ATAPI_RESET 0x10
250 #define ATACFG_MASTER 0x20
251 #define ATACFG_BLOCKSIZE 0xa0
253 #define ATACFGE_LAST_LUN 0x07
254 #define ATACFGE_DESC_OVERRIDE 0x08
255 #define ATACFGE_STATE_SUSPEND 0x10
256 #define ATACFGE_SKIP_BOOT 0x20
257 #define ATACFGE_CONF_DESC2 0x40
258 #define ATACFGE_INIT_STATUS 0x80
260 #define CFG_CAPABILITY_SRST 0x01
262 struct isd200_config
{
263 unsigned char EventNotification
;
264 unsigned char ExternalClock
;
265 unsigned char ATAInitTimeout
;
266 unsigned char ATAConfig
;
267 unsigned char ATAMajorCommand
;
268 unsigned char ATAMinorCommand
;
269 unsigned char ATAExtraConfig
;
270 unsigned char Capability
;
271 }__attribute__ ((packed
));
275 * ISD200 driver information struct
279 struct inquiry_data InquiryData
;
280 struct hd_driveid
*id
;
281 struct isd200_config ConfigData
;
282 unsigned char *RegsBuf
;
283 unsigned char ATARegs
[8];
284 unsigned char DeviceHead
;
285 unsigned char DeviceFlags
;
287 /* maximum number of LUNs supported */
288 unsigned char MaxLUNs
;
289 struct scsi_cmnd srb
;
294 * Read Capacity Data - returned in Big Endian format
297 struct read_capacity_data
{
298 __be32 LogicalBlockAddress
;
299 __be32 BytesPerBlock
;
303 * Read Block Limits Data - returned in Big Endian format
304 * This structure returns the maximum and minimum block
305 * size for a TAPE device.
308 struct read_block_limits
{
309 unsigned char Reserved
;
310 unsigned char BlockMaximumSize
[3];
311 unsigned char BlockMinimumSize
[2];
319 #define SENSE_ERRCODE 0x7f
320 #define SENSE_ERRCODE_VALID 0x80
321 #define SENSE_FLAG_SENSE_KEY 0x0f
322 #define SENSE_FLAG_BAD_LENGTH 0x20
323 #define SENSE_FLAG_END_OF_MEDIA 0x40
324 #define SENSE_FLAG_FILE_MARK 0x80
326 unsigned char ErrorCode
;
327 unsigned char SegmentNumber
;
329 unsigned char Information
[4];
330 unsigned char AdditionalSenseLength
;
331 unsigned char CommandSpecificInformation
[4];
332 unsigned char AdditionalSenseCode
;
333 unsigned char AdditionalSenseCodeQualifier
;
334 unsigned char FieldReplaceableUnitCode
;
335 unsigned char SenseKeySpecific
[3];
336 } __attribute__ ((packed
));
339 * Default request sense buffer size
342 #define SENSE_BUFFER_SIZE 18
344 /***********************************************************************
346 ***********************************************************************/
348 /**************************************************************************
351 * Builds an artificial sense buffer to report the results of a
357 static void isd200_build_sense(struct us_data
*us
, struct scsi_cmnd
*srb
)
359 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
360 struct sense_data
*buf
= (struct sense_data
*) &srb
->sense_buffer
[0];
361 unsigned char error
= info
->ATARegs
[IDE_ERROR_OFFSET
];
363 if(error
& ATA_ERROR_MEDIA_CHANGE
) {
364 buf
->ErrorCode
= 0x70 | SENSE_ERRCODE_VALID
;
365 buf
->AdditionalSenseLength
= 0xb;
366 buf
->Flags
= UNIT_ATTENTION
;
367 buf
->AdditionalSenseCode
= 0;
368 buf
->AdditionalSenseCodeQualifier
= 0;
369 } else if(error
& MCR_ERR
) {
370 buf
->ErrorCode
= 0x70 | SENSE_ERRCODE_VALID
;
371 buf
->AdditionalSenseLength
= 0xb;
372 buf
->Flags
= UNIT_ATTENTION
;
373 buf
->AdditionalSenseCode
= 0;
374 buf
->AdditionalSenseCodeQualifier
= 0;
375 } else if(error
& TRK0_ERR
) {
376 buf
->ErrorCode
= 0x70 | SENSE_ERRCODE_VALID
;
377 buf
->AdditionalSenseLength
= 0xb;
378 buf
->Flags
= NOT_READY
;
379 buf
->AdditionalSenseCode
= 0;
380 buf
->AdditionalSenseCodeQualifier
= 0;
381 } else if(error
& ECC_ERR
) {
382 buf
->ErrorCode
= 0x70 | SENSE_ERRCODE_VALID
;
383 buf
->AdditionalSenseLength
= 0xb;
384 buf
->Flags
= DATA_PROTECT
;
385 buf
->AdditionalSenseCode
= 0;
386 buf
->AdditionalSenseCodeQualifier
= 0;
389 buf
->AdditionalSenseLength
= 0;
391 buf
->AdditionalSenseCode
= 0;
392 buf
->AdditionalSenseCodeQualifier
= 0;
397 /***********************************************************************
399 ***********************************************************************/
402 /**************************************************************************
405 * Routine for sending commands to the isd200
410 static int isd200_action( struct us_data
*us
, int action
,
411 void* pointer
, int value
)
414 struct scsi_device srb_dev
;
415 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
416 struct scsi_cmnd
*srb
= &info
->srb
;
419 memset(&ata
, 0, sizeof(ata
));
420 memset(&srb_dev
, 0, sizeof(srb_dev
));
421 srb
->device
= &srb_dev
;
422 ++srb
->serial_number
;
424 ata
.generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
425 ata
.generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
426 ata
.generic
.TransferBlockSize
= 1;
429 case ACTION_READ_STATUS
:
430 US_DEBUGP(" isd200_action(READ_STATUS)\n");
431 ata
.generic
.ActionSelect
= ACTION_SELECT_0
|ACTION_SELECT_2
;
432 ata
.generic
.RegisterSelect
=
433 REG_CYLINDER_LOW
| REG_CYLINDER_HIGH
|
434 REG_STATUS
| REG_ERROR
;
435 srb
->sc_data_direction
= DMA_FROM_DEVICE
;
436 srb
->request_buffer
= pointer
;
437 srb
->request_bufflen
= value
;
441 US_DEBUGP(" isd200_action(ENUM,0x%02x)\n",value
);
442 ata
.generic
.ActionSelect
= ACTION_SELECT_1
|ACTION_SELECT_2
|
443 ACTION_SELECT_3
|ACTION_SELECT_4
|
445 ata
.generic
.RegisterSelect
= REG_DEVICE_HEAD
;
446 ata
.write
.DeviceHeadByte
= value
;
447 srb
->sc_data_direction
= DMA_NONE
;
451 US_DEBUGP(" isd200_action(RESET)\n");
452 ata
.generic
.ActionSelect
= ACTION_SELECT_1
|ACTION_SELECT_2
|
453 ACTION_SELECT_3
|ACTION_SELECT_4
;
454 ata
.generic
.RegisterSelect
= REG_DEVICE_CONTROL
;
455 ata
.write
.DeviceControlByte
= ATA_DC_RESET_CONTROLLER
;
456 srb
->sc_data_direction
= DMA_NONE
;
459 case ACTION_REENABLE
:
460 US_DEBUGP(" isd200_action(REENABLE)\n");
461 ata
.generic
.ActionSelect
= ACTION_SELECT_1
|ACTION_SELECT_2
|
462 ACTION_SELECT_3
|ACTION_SELECT_4
;
463 ata
.generic
.RegisterSelect
= REG_DEVICE_CONTROL
;
464 ata
.write
.DeviceControlByte
= ATA_DC_REENABLE_CONTROLLER
;
465 srb
->sc_data_direction
= DMA_NONE
;
468 case ACTION_SOFT_RESET
:
469 US_DEBUGP(" isd200_action(SOFT_RESET)\n");
470 ata
.generic
.ActionSelect
= ACTION_SELECT_1
|ACTION_SELECT_5
;
471 ata
.generic
.RegisterSelect
= REG_DEVICE_HEAD
| REG_COMMAND
;
472 ata
.write
.DeviceHeadByte
= info
->DeviceHead
;
473 ata
.write
.CommandByte
= WIN_SRST
;
474 srb
->sc_data_direction
= DMA_NONE
;
477 case ACTION_IDENTIFY
:
478 US_DEBUGP(" isd200_action(IDENTIFY)\n");
479 ata
.generic
.RegisterSelect
= REG_COMMAND
;
480 ata
.write
.CommandByte
= WIN_IDENTIFY
;
481 srb
->sc_data_direction
= DMA_FROM_DEVICE
;
482 srb
->request_buffer
= (void *) info
->id
;
483 srb
->request_bufflen
= sizeof(struct hd_driveid
);
487 US_DEBUGP("Error: Undefined action %d\n",action
);
491 memcpy(srb
->cmnd
, &ata
, sizeof(ata
.generic
));
492 srb
->cmd_len
= sizeof(ata
.generic
);
493 status
= usb_stor_Bulk_transport(srb
, us
);
494 if (status
== USB_STOR_TRANSPORT_GOOD
)
495 status
= ISD200_GOOD
;
497 US_DEBUGP(" isd200_action(0x%02x) error: %d\n",action
,status
);
498 status
= ISD200_ERROR
;
499 /* need to reset device here */
505 /**************************************************************************
513 static int isd200_read_regs( struct us_data
*us
)
515 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
516 int retStatus
= ISD200_GOOD
;
519 US_DEBUGP("Entering isd200_IssueATAReadRegs\n");
521 transferStatus
= isd200_action( us
, ACTION_READ_STATUS
,
522 info
->RegsBuf
, sizeof(info
->ATARegs
) );
523 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
524 US_DEBUGP(" Error reading ATA registers\n");
525 retStatus
= ISD200_ERROR
;
527 memcpy(info
->ATARegs
, info
->RegsBuf
, sizeof(info
->ATARegs
));
528 US_DEBUGP(" Got ATA Register[IDE_ERROR_OFFSET] = 0x%x\n",
529 info
->ATARegs
[IDE_ERROR_OFFSET
]);
536 /**************************************************************************
537 * Invoke the transport and basic error-handling/recovery methods
539 * This is used by the protocol layers to actually send the message to
540 * the device and receive the response.
542 static void isd200_invoke_transport( struct us_data
*us
,
543 struct scsi_cmnd
*srb
,
544 union ata_cdb
*ataCdb
)
546 int need_auto_sense
= 0;
550 /* send the command to the transport layer */
551 memcpy(srb
->cmnd
, ataCdb
, sizeof(ataCdb
->generic
));
552 srb
->cmd_len
= sizeof(ataCdb
->generic
);
553 transferStatus
= usb_stor_Bulk_transport(srb
, us
);
555 /* if the command gets aborted by the higher layers, we need to
556 * short-circuit all other processing
558 if (test_bit(US_FLIDX_TIMED_OUT
, &us
->flags
)) {
559 US_DEBUGP("-- command was aborted\n");
563 switch (transferStatus
) {
565 case USB_STOR_TRANSPORT_GOOD
:
566 /* Indicate a good result */
567 srb
->result
= SAM_STAT_GOOD
;
570 case USB_STOR_TRANSPORT_NO_SENSE
:
571 US_DEBUGP("-- transport indicates protocol failure\n");
572 srb
->result
= SAM_STAT_CHECK_CONDITION
;
575 case USB_STOR_TRANSPORT_FAILED
:
576 US_DEBUGP("-- transport indicates command failure\n");
580 case USB_STOR_TRANSPORT_ERROR
:
581 US_DEBUGP("-- transport indicates transport error\n");
582 srb
->result
= DID_ERROR
<< 16;
583 /* Need reset here */
587 US_DEBUGP("-- transport indicates unknown error\n");
588 srb
->result
= DID_ERROR
<< 16;
589 /* Need reset here */
593 if ((srb
->resid
> 0) &&
594 !((srb
->cmnd
[0] == REQUEST_SENSE
) ||
595 (srb
->cmnd
[0] == INQUIRY
) ||
596 (srb
->cmnd
[0] == MODE_SENSE
) ||
597 (srb
->cmnd
[0] == LOG_SENSE
) ||
598 (srb
->cmnd
[0] == MODE_SENSE_10
))) {
599 US_DEBUGP("-- unexpectedly short transfer\n");
603 if (need_auto_sense
) {
604 result
= isd200_read_regs(us
);
605 if (test_bit(US_FLIDX_TIMED_OUT
, &us
->flags
)) {
606 US_DEBUGP("-- auto-sense aborted\n");
609 if (result
== ISD200_GOOD
) {
610 isd200_build_sense(us
, srb
);
611 srb
->result
= SAM_STAT_CHECK_CONDITION
;
613 /* If things are really okay, then let's show that */
614 if ((srb
->sense_buffer
[2] & 0xf) == 0x0)
615 srb
->result
= SAM_STAT_GOOD
;
617 srb
->result
= DID_ERROR
<< 16;
618 /* Need reset here */
622 /* Regardless of auto-sense, if we _know_ we have an error
623 * condition, show that in the result code
625 if (transferStatus
== USB_STOR_TRANSPORT_FAILED
)
626 srb
->result
= SAM_STAT_CHECK_CONDITION
;
629 /* abort processing: the bulk-only transport requires a reset
630 * following an abort */
632 srb
->result
= DID_ABORT
<< 16;
634 /* permit the reset transfer to take place */
635 clear_bit(US_FLIDX_ABORTING
, &us
->flags
);
636 /* Need reset here */
639 #ifdef CONFIG_USB_STORAGE_DEBUG
640 static void isd200_log_config( struct isd200_info
* info
)
642 US_DEBUGP(" Event Notification: 0x%x\n",
643 info
->ConfigData
.EventNotification
);
644 US_DEBUGP(" External Clock: 0x%x\n",
645 info
->ConfigData
.ExternalClock
);
646 US_DEBUGP(" ATA Init Timeout: 0x%x\n",
647 info
->ConfigData
.ATAInitTimeout
);
648 US_DEBUGP(" ATAPI Command Block Size: 0x%x\n",
649 (info
->ConfigData
.ATAConfig
& ATACFG_BLOCKSIZE
) >> 6);
650 US_DEBUGP(" Master/Slave Selection: 0x%x\n",
651 info
->ConfigData
.ATAConfig
& ATACFG_MASTER
);
652 US_DEBUGP(" ATAPI Reset: 0x%x\n",
653 info
->ConfigData
.ATAConfig
& ATACFG_ATAPI_RESET
);
654 US_DEBUGP(" ATA Timing: 0x%x\n",
655 info
->ConfigData
.ATAConfig
& ATACFG_TIMING
);
656 US_DEBUGP(" ATA Major Command: 0x%x\n",
657 info
->ConfigData
.ATAMajorCommand
);
658 US_DEBUGP(" ATA Minor Command: 0x%x\n",
659 info
->ConfigData
.ATAMinorCommand
);
660 US_DEBUGP(" Init Status: 0x%x\n",
661 info
->ConfigData
.ATAExtraConfig
& ATACFGE_INIT_STATUS
);
662 US_DEBUGP(" Config Descriptor 2: 0x%x\n",
663 info
->ConfigData
.ATAExtraConfig
& ATACFGE_CONF_DESC2
);
664 US_DEBUGP(" Skip Device Boot: 0x%x\n",
665 info
->ConfigData
.ATAExtraConfig
& ATACFGE_SKIP_BOOT
);
666 US_DEBUGP(" ATA 3 State Supsend: 0x%x\n",
667 info
->ConfigData
.ATAExtraConfig
& ATACFGE_STATE_SUSPEND
);
668 US_DEBUGP(" Descriptor Override: 0x%x\n",
669 info
->ConfigData
.ATAExtraConfig
& ATACFGE_DESC_OVERRIDE
);
670 US_DEBUGP(" Last LUN Identifier: 0x%x\n",
671 info
->ConfigData
.ATAExtraConfig
& ATACFGE_LAST_LUN
);
672 US_DEBUGP(" SRST Enable: 0x%x\n",
673 info
->ConfigData
.ATAExtraConfig
& CFG_CAPABILITY_SRST
);
677 /**************************************************************************
678 * isd200_write_config
680 * Write the ISD200 Configuration data
685 static int isd200_write_config( struct us_data
*us
)
687 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
688 int retStatus
= ISD200_GOOD
;
691 #ifdef CONFIG_USB_STORAGE_DEBUG
692 US_DEBUGP("Entering isd200_write_config\n");
693 US_DEBUGP(" Writing the following ISD200 Config Data:\n");
694 isd200_log_config(info
);
697 /* let's send the command via the control pipe */
698 result
= usb_stor_ctrl_transfer(
702 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
705 (void *) &info
->ConfigData
,
706 sizeof(info
->ConfigData
));
709 US_DEBUGP(" ISD200 Config Data was written successfully\n");
711 US_DEBUGP(" Request to write ISD200 Config Data failed!\n");
712 retStatus
= ISD200_ERROR
;
715 US_DEBUGP("Leaving isd200_write_config %08X\n", retStatus
);
720 /**************************************************************************
723 * Reads the ISD200 Configuration data
728 static int isd200_read_config( struct us_data
*us
)
730 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
731 int retStatus
= ISD200_GOOD
;
734 US_DEBUGP("Entering isd200_read_config\n");
736 /* read the configuration information from ISD200. Use this to */
737 /* determine what the special ATA CDB bytes are. */
739 result
= usb_stor_ctrl_transfer(
743 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
746 (void *) &info
->ConfigData
,
747 sizeof(info
->ConfigData
));
751 US_DEBUGP(" Retrieved the following ISD200 Config Data:\n");
752 #ifdef CONFIG_USB_STORAGE_DEBUG
753 isd200_log_config(info
);
756 US_DEBUGP(" Request to get ISD200 Config Data failed!\n");
757 retStatus
= ISD200_ERROR
;
760 US_DEBUGP("Leaving isd200_read_config %08X\n", retStatus
);
765 /**************************************************************************
766 * isd200_atapi_soft_reset
768 * Perform an Atapi Soft Reset on the device
773 static int isd200_atapi_soft_reset( struct us_data
*us
)
775 int retStatus
= ISD200_GOOD
;
778 US_DEBUGP("Entering isd200_atapi_soft_reset\n");
780 transferStatus
= isd200_action( us
, ACTION_SOFT_RESET
, NULL
, 0 );
781 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
782 US_DEBUGP(" Error issuing Atapi Soft Reset\n");
783 retStatus
= ISD200_ERROR
;
786 US_DEBUGP("Leaving isd200_atapi_soft_reset %08X\n", retStatus
);
791 /**************************************************************************
794 * Perform an SRST on the device
799 static int isd200_srst( struct us_data
*us
)
801 int retStatus
= ISD200_GOOD
;
804 US_DEBUGP("Entering isd200_SRST\n");
806 transferStatus
= isd200_action( us
, ACTION_RESET
, NULL
, 0 );
808 /* check to see if this request failed */
809 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
810 US_DEBUGP(" Error issuing SRST\n");
811 retStatus
= ISD200_ERROR
;
813 /* delay 10ms to give the drive a chance to see it */
816 transferStatus
= isd200_action( us
, ACTION_REENABLE
, NULL
, 0 );
817 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
818 US_DEBUGP(" Error taking drive out of reset\n");
819 retStatus
= ISD200_ERROR
;
821 /* delay 50ms to give the drive a chance to recover after SRST */
826 US_DEBUGP("Leaving isd200_srst %08X\n", retStatus
);
831 /**************************************************************************
834 * Helper function for isd200_manual_enum(). Does ENUM and READ_STATUS
835 * and tries to analyze the status registers
840 static int isd200_try_enum(struct us_data
*us
, unsigned char master_slave
,
843 int status
= ISD200_GOOD
;
844 unsigned long endTime
;
845 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
846 unsigned char *regs
= info
->RegsBuf
;
847 int recheckAsMaster
= 0;
850 endTime
= jiffies
+ ISD200_ENUM_DETECT_TIMEOUT
* HZ
;
852 endTime
= jiffies
+ ISD200_ENUM_BSY_TIMEOUT
* HZ
;
854 /* loop until we detect !BSY or timeout */
856 #ifdef CONFIG_USB_STORAGE_DEBUG
857 char* mstr
= master_slave
== ATA_ADDRESS_DEVHEAD_STD
?
861 status
= isd200_action( us
, ACTION_ENUM
, NULL
, master_slave
);
862 if ( status
!= ISD200_GOOD
)
865 status
= isd200_action( us
, ACTION_READ_STATUS
,
867 if ( status
!= ISD200_GOOD
)
871 if (regs
[IDE_STATUS_OFFSET
] & BUSY_STAT
) {
872 US_DEBUGP(" %s status is still BSY, try again...\n",mstr
);
874 US_DEBUGP(" %s status !BSY, continue with next operation\n",mstr
);
878 /* check for BUSY_STAT and */
879 /* WRERR_STAT (workaround ATA Zip drive) and */
880 /* ERR_STAT (workaround for Archos CD-ROM) */
881 else if (regs
[IDE_STATUS_OFFSET
] &
882 (BUSY_STAT
| WRERR_STAT
| ERR_STAT
)) {
883 US_DEBUGP(" Status indicates it is not ready, try again...\n");
885 /* check for DRDY, ATA devices set DRDY after SRST */
886 else if (regs
[IDE_STATUS_OFFSET
] & READY_STAT
) {
887 US_DEBUGP(" Identified ATA device\n");
888 info
->DeviceFlags
|= DF_ATA_DEVICE
;
889 info
->DeviceHead
= master_slave
;
892 /* check Cylinder High/Low to
893 determine if it is an ATAPI device
895 else if ((regs
[IDE_HCYL_OFFSET
] == 0xEB) &&
896 (regs
[IDE_LCYL_OFFSET
] == 0x14)) {
897 /* It seems that the RICOH
898 MP6200A CD/RW drive will
899 report itself okay as a
900 slave when it is really a
901 master. So this check again
902 as a master device just to
903 make sure it doesn't report
904 itself okay as a master also
906 if ((master_slave
& ATA_ADDRESS_DEVHEAD_SLAVE
) &&
908 US_DEBUGP(" Identified ATAPI device as slave. Rechecking again as master\n");
910 master_slave
= ATA_ADDRESS_DEVHEAD_STD
;
912 US_DEBUGP(" Identified ATAPI device\n");
913 info
->DeviceHead
= master_slave
;
915 status
= isd200_atapi_soft_reset(us
);
919 US_DEBUGP(" Not ATA, not ATAPI. Weird.\n");
923 /* check for timeout on this request */
924 if (time_after_eq(jiffies
, endTime
)) {
926 US_DEBUGP(" BSY check timeout, just continue with next operation...\n");
928 US_DEBUGP(" Device detect timeout!\n");
936 /**************************************************************************
939 * Determines if the drive attached is an ATA or ATAPI and if it is a
945 static int isd200_manual_enum(struct us_data
*us
)
947 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
948 int retStatus
= ISD200_GOOD
;
950 US_DEBUGP("Entering isd200_manual_enum\n");
952 retStatus
= isd200_read_config(us
);
953 if (retStatus
== ISD200_GOOD
) {
955 /* master or slave? */
956 retStatus
= isd200_try_enum( us
, ATA_ADDRESS_DEVHEAD_STD
, 0);
957 if (retStatus
== ISD200_GOOD
)
958 retStatus
= isd200_try_enum( us
, ATA_ADDRESS_DEVHEAD_SLAVE
, 0);
960 if (retStatus
== ISD200_GOOD
) {
961 retStatus
= isd200_srst(us
);
962 if (retStatus
== ISD200_GOOD
)
964 retStatus
= isd200_try_enum( us
, ATA_ADDRESS_DEVHEAD_STD
, 1);
967 isslave
= (info
->DeviceHead
& ATA_ADDRESS_DEVHEAD_SLAVE
) ? 1 : 0;
968 if (!(info
->ConfigData
.ATAConfig
& ATACFG_MASTER
)) {
969 US_DEBUGP(" Setting Master/Slave selection to %d\n", isslave
);
970 info
->ConfigData
.ATAConfig
&= 0x3f;
971 info
->ConfigData
.ATAConfig
|= (isslave
<<6);
972 retStatus
= isd200_write_config(us
);
976 US_DEBUGP("Leaving isd200_manual_enum %08X\n", retStatus
);
981 * We are the last non IDE user of the legacy IDE ident structures
982 * and we thus want to keep a private copy of this function so the
983 * driver can be used without the obsolete drivers/ide layer
986 static void isd200_fix_driveid (struct hd_driveid
*id
)
988 #ifndef __LITTLE_ENDIAN
993 id
->config
= __le16_to_cpu(id
->config
);
994 id
->cyls
= __le16_to_cpu(id
->cyls
);
995 id
->reserved2
= __le16_to_cpu(id
->reserved2
);
996 id
->heads
= __le16_to_cpu(id
->heads
);
997 id
->track_bytes
= __le16_to_cpu(id
->track_bytes
);
998 id
->sector_bytes
= __le16_to_cpu(id
->sector_bytes
);
999 id
->sectors
= __le16_to_cpu(id
->sectors
);
1000 id
->vendor0
= __le16_to_cpu(id
->vendor0
);
1001 id
->vendor1
= __le16_to_cpu(id
->vendor1
);
1002 id
->vendor2
= __le16_to_cpu(id
->vendor2
);
1003 stringcast
= (u16
*)&id
->serial_no
[0];
1004 for (i
= 0; i
< (20/2); i
++)
1005 stringcast
[i
] = __le16_to_cpu(stringcast
[i
]);
1006 id
->buf_type
= __le16_to_cpu(id
->buf_type
);
1007 id
->buf_size
= __le16_to_cpu(id
->buf_size
);
1008 id
->ecc_bytes
= __le16_to_cpu(id
->ecc_bytes
);
1009 stringcast
= (u16
*)&id
->fw_rev
[0];
1010 for (i
= 0; i
< (8/2); i
++)
1011 stringcast
[i
] = __le16_to_cpu(stringcast
[i
]);
1012 stringcast
= (u16
*)&id
->model
[0];
1013 for (i
= 0; i
< (40/2); i
++)
1014 stringcast
[i
] = __le16_to_cpu(stringcast
[i
]);
1015 id
->dword_io
= __le16_to_cpu(id
->dword_io
);
1016 id
->reserved50
= __le16_to_cpu(id
->reserved50
);
1017 id
->field_valid
= __le16_to_cpu(id
->field_valid
);
1018 id
->cur_cyls
= __le16_to_cpu(id
->cur_cyls
);
1019 id
->cur_heads
= __le16_to_cpu(id
->cur_heads
);
1020 id
->cur_sectors
= __le16_to_cpu(id
->cur_sectors
);
1021 id
->cur_capacity0
= __le16_to_cpu(id
->cur_capacity0
);
1022 id
->cur_capacity1
= __le16_to_cpu(id
->cur_capacity1
);
1023 id
->lba_capacity
= __le32_to_cpu(id
->lba_capacity
);
1024 id
->dma_1word
= __le16_to_cpu(id
->dma_1word
);
1025 id
->dma_mword
= __le16_to_cpu(id
->dma_mword
);
1026 id
->eide_pio_modes
= __le16_to_cpu(id
->eide_pio_modes
);
1027 id
->eide_dma_min
= __le16_to_cpu(id
->eide_dma_min
);
1028 id
->eide_dma_time
= __le16_to_cpu(id
->eide_dma_time
);
1029 id
->eide_pio
= __le16_to_cpu(id
->eide_pio
);
1030 id
->eide_pio_iordy
= __le16_to_cpu(id
->eide_pio_iordy
);
1031 for (i
= 0; i
< 2; ++i
)
1032 id
->words69_70
[i
] = __le16_to_cpu(id
->words69_70
[i
]);
1033 for (i
= 0; i
< 4; ++i
)
1034 id
->words71_74
[i
] = __le16_to_cpu(id
->words71_74
[i
]);
1035 id
->queue_depth
= __le16_to_cpu(id
->queue_depth
);
1036 for (i
= 0; i
< 4; ++i
)
1037 id
->words76_79
[i
] = __le16_to_cpu(id
->words76_79
[i
]);
1038 id
->major_rev_num
= __le16_to_cpu(id
->major_rev_num
);
1039 id
->minor_rev_num
= __le16_to_cpu(id
->minor_rev_num
);
1040 id
->command_set_1
= __le16_to_cpu(id
->command_set_1
);
1041 id
->command_set_2
= __le16_to_cpu(id
->command_set_2
);
1042 id
->cfsse
= __le16_to_cpu(id
->cfsse
);
1043 id
->cfs_enable_1
= __le16_to_cpu(id
->cfs_enable_1
);
1044 id
->cfs_enable_2
= __le16_to_cpu(id
->cfs_enable_2
);
1045 id
->csf_default
= __le16_to_cpu(id
->csf_default
);
1046 id
->dma_ultra
= __le16_to_cpu(id
->dma_ultra
);
1047 id
->trseuc
= __le16_to_cpu(id
->trseuc
);
1048 id
->trsEuc
= __le16_to_cpu(id
->trsEuc
);
1049 id
->CurAPMvalues
= __le16_to_cpu(id
->CurAPMvalues
);
1050 id
->mprc
= __le16_to_cpu(id
->mprc
);
1051 id
->hw_config
= __le16_to_cpu(id
->hw_config
);
1052 id
->acoustic
= __le16_to_cpu(id
->acoustic
);
1053 id
->msrqs
= __le16_to_cpu(id
->msrqs
);
1054 id
->sxfert
= __le16_to_cpu(id
->sxfert
);
1055 id
->sal
= __le16_to_cpu(id
->sal
);
1056 id
->spg
= __le32_to_cpu(id
->spg
);
1057 id
->lba_capacity_2
= __le64_to_cpu(id
->lba_capacity_2
);
1058 for (i
= 0; i
< 22; i
++)
1059 id
->words104_125
[i
] = __le16_to_cpu(id
->words104_125
[i
]);
1060 id
->last_lun
= __le16_to_cpu(id
->last_lun
);
1061 id
->word127
= __le16_to_cpu(id
->word127
);
1062 id
->dlf
= __le16_to_cpu(id
->dlf
);
1063 id
->csfo
= __le16_to_cpu(id
->csfo
);
1064 for (i
= 0; i
< 26; i
++)
1065 id
->words130_155
[i
] = __le16_to_cpu(id
->words130_155
[i
]);
1066 id
->word156
= __le16_to_cpu(id
->word156
);
1067 for (i
= 0; i
< 3; i
++)
1068 id
->words157_159
[i
] = __le16_to_cpu(id
->words157_159
[i
]);
1069 id
->cfa_power
= __le16_to_cpu(id
->cfa_power
);
1070 for (i
= 0; i
< 14; i
++)
1071 id
->words161_175
[i
] = __le16_to_cpu(id
->words161_175
[i
]);
1072 for (i
= 0; i
< 31; i
++)
1073 id
->words176_205
[i
] = __le16_to_cpu(id
->words176_205
[i
]);
1074 for (i
= 0; i
< 48; i
++)
1075 id
->words206_254
[i
] = __le16_to_cpu(id
->words206_254
[i
]);
1076 id
->integrity_word
= __le16_to_cpu(id
->integrity_word
);
1078 # error "Please fix <asm/byteorder.h>"
1084 /**************************************************************************
1085 * isd200_get_inquiry_data
1092 static int isd200_get_inquiry_data( struct us_data
*us
)
1094 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
1095 int retStatus
= ISD200_GOOD
;
1096 struct hd_driveid
*id
= info
->id
;
1098 US_DEBUGP("Entering isd200_get_inquiry_data\n");
1100 /* set default to Master */
1101 info
->DeviceHead
= ATA_ADDRESS_DEVHEAD_STD
;
1103 /* attempt to manually enumerate this device */
1104 retStatus
= isd200_manual_enum(us
);
1105 if (retStatus
== ISD200_GOOD
) {
1108 /* check for an ATA device */
1109 if (info
->DeviceFlags
& DF_ATA_DEVICE
) {
1110 /* this must be an ATA device */
1111 /* perform an ATA Command Identify */
1112 transferStatus
= isd200_action( us
, ACTION_IDENTIFY
,
1114 sizeof(struct hd_driveid
) );
1115 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
1116 /* Error issuing ATA Command Identify */
1117 US_DEBUGP(" Error issuing ATA Command Identify\n");
1118 retStatus
= ISD200_ERROR
;
1120 /* ATA Command Identify successful */
1124 isd200_fix_driveid(id
);
1126 US_DEBUGP(" Identify Data Structure:\n");
1127 US_DEBUGP(" config = 0x%x\n", id
->config
);
1128 US_DEBUGP(" cyls = 0x%x\n", id
->cyls
);
1129 US_DEBUGP(" heads = 0x%x\n", id
->heads
);
1130 US_DEBUGP(" track_bytes = 0x%x\n", id
->track_bytes
);
1131 US_DEBUGP(" sector_bytes = 0x%x\n", id
->sector_bytes
);
1132 US_DEBUGP(" sectors = 0x%x\n", id
->sectors
);
1133 US_DEBUGP(" serial_no[0] = 0x%x\n", id
->serial_no
[0]);
1134 US_DEBUGP(" buf_type = 0x%x\n", id
->buf_type
);
1135 US_DEBUGP(" buf_size = 0x%x\n", id
->buf_size
);
1136 US_DEBUGP(" ecc_bytes = 0x%x\n", id
->ecc_bytes
);
1137 US_DEBUGP(" fw_rev[0] = 0x%x\n", id
->fw_rev
[0]);
1138 US_DEBUGP(" model[0] = 0x%x\n", id
->model
[0]);
1139 US_DEBUGP(" max_multsect = 0x%x\n", id
->max_multsect
);
1140 US_DEBUGP(" dword_io = 0x%x\n", id
->dword_io
);
1141 US_DEBUGP(" capability = 0x%x\n", id
->capability
);
1142 US_DEBUGP(" tPIO = 0x%x\n", id
->tPIO
);
1143 US_DEBUGP(" tDMA = 0x%x\n", id
->tDMA
);
1144 US_DEBUGP(" field_valid = 0x%x\n", id
->field_valid
);
1145 US_DEBUGP(" cur_cyls = 0x%x\n", id
->cur_cyls
);
1146 US_DEBUGP(" cur_heads = 0x%x\n", id
->cur_heads
);
1147 US_DEBUGP(" cur_sectors = 0x%x\n", id
->cur_sectors
);
1148 US_DEBUGP(" cur_capacity = 0x%x\n", (id
->cur_capacity1
<< 16) + id
->cur_capacity0
);
1149 US_DEBUGP(" multsect = 0x%x\n", id
->multsect
);
1150 US_DEBUGP(" lba_capacity = 0x%x\n", id
->lba_capacity
);
1151 US_DEBUGP(" command_set_1 = 0x%x\n", id
->command_set_1
);
1152 US_DEBUGP(" command_set_2 = 0x%x\n", id
->command_set_2
);
1154 memset(&info
->InquiryData
, 0, sizeof(info
->InquiryData
));
1156 /* Standard IDE interface only supports disks */
1157 info
->InquiryData
.DeviceType
= DIRECT_ACCESS_DEVICE
;
1159 /* The length must be at least 36 (5 + 31) */
1160 info
->InquiryData
.AdditionalLength
= 0x1F;
1162 if (id
->command_set_1
& COMMANDSET_MEDIA_STATUS
) {
1163 /* set the removable bit */
1164 info
->InquiryData
.DeviceTypeModifier
= DEVICE_REMOVABLE
;
1165 info
->DeviceFlags
|= DF_REMOVABLE_MEDIA
;
1168 /* Fill in vendor identification fields */
1169 src
= (__be16
*)id
->model
;
1170 dest
= (__u16
*)info
->InquiryData
.VendorId
;
1172 dest
[i
] = be16_to_cpu(src
[i
]);
1174 src
= (__be16
*)(id
->model
+8);
1175 dest
= (__u16
*)info
->InquiryData
.ProductId
;
1177 dest
[i
] = be16_to_cpu(src
[i
]);
1179 src
= (__be16
*)id
->fw_rev
;
1180 dest
= (__u16
*)info
->InquiryData
.ProductRevisionLevel
;
1182 dest
[i
] = be16_to_cpu(src
[i
]);
1184 /* determine if it supports Media Status Notification */
1185 if (id
->command_set_2
& COMMANDSET_MEDIA_STATUS
) {
1186 US_DEBUGP(" Device supports Media Status Notification\n");
1188 /* Indicate that it is enabled, even though it is not
1189 * This allows the lock/unlock of the media to work
1192 info
->DeviceFlags
|= DF_MEDIA_STATUS_ENABLED
;
1195 info
->DeviceFlags
&= ~DF_MEDIA_STATUS_ENABLED
;
1200 * this must be an ATAPI device
1201 * use an ATAPI protocol (Transparent SCSI)
1203 us
->protocol_name
= "Transparent SCSI";
1204 us
->proto_handler
= usb_stor_transparent_scsi_command
;
1206 US_DEBUGP("Protocol changed to: %s\n", us
->protocol_name
);
1208 /* Free driver structure */
1209 us
->extra_destructor(info
);
1211 us
->extra_destructor
= NULL
;
1215 US_DEBUGP("Leaving isd200_get_inquiry_data %08X\n", retStatus
);
1221 /**************************************************************************
1222 * isd200_scsi_to_ata
1224 * Translate SCSI commands to ATA commands.
1227 * 1 if the command needs to be sent to the transport layer
1230 static int isd200_scsi_to_ata(struct scsi_cmnd
*srb
, struct us_data
*us
,
1231 union ata_cdb
* ataCdb
)
1233 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
1234 struct hd_driveid
*id
= info
->id
;
1235 int sendToTransport
= 1;
1236 unsigned char sectnum
, head
;
1237 unsigned short cylinder
;
1239 unsigned long blockCount
;
1240 unsigned char senseData
[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1242 memset(ataCdb
, 0, sizeof(union ata_cdb
));
1245 switch (srb
->cmnd
[0]) {
1247 US_DEBUGP(" ATA OUT - INQUIRY\n");
1249 /* copy InquiryData */
1250 usb_stor_set_xfer_buf((unsigned char *) &info
->InquiryData
,
1251 sizeof(info
->InquiryData
), srb
);
1252 srb
->result
= SAM_STAT_GOOD
;
1253 sendToTransport
= 0;
1257 US_DEBUGP(" ATA OUT - SCSIOP_MODE_SENSE\n");
1259 /* Initialize the return buffer */
1260 usb_stor_set_xfer_buf(senseData
, sizeof(senseData
), srb
);
1262 if (info
->DeviceFlags
& DF_MEDIA_STATUS_ENABLED
)
1264 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1265 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1266 ataCdb
->generic
.TransferBlockSize
= 1;
1267 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1268 ataCdb
->write
.CommandByte
= ATA_COMMAND_GET_MEDIA_STATUS
;
1269 srb
->request_bufflen
= 0;
1271 US_DEBUGP(" Media Status not supported, just report okay\n");
1272 srb
->result
= SAM_STAT_GOOD
;
1273 sendToTransport
= 0;
1277 case TEST_UNIT_READY
:
1278 US_DEBUGP(" ATA OUT - SCSIOP_TEST_UNIT_READY\n");
1280 if (info
->DeviceFlags
& DF_MEDIA_STATUS_ENABLED
)
1282 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1283 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1284 ataCdb
->generic
.TransferBlockSize
= 1;
1285 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1286 ataCdb
->write
.CommandByte
= ATA_COMMAND_GET_MEDIA_STATUS
;
1287 srb
->request_bufflen
= 0;
1289 US_DEBUGP(" Media Status not supported, just report okay\n");
1290 srb
->result
= SAM_STAT_GOOD
;
1291 sendToTransport
= 0;
1297 unsigned long capacity
;
1298 struct read_capacity_data readCapacityData
;
1300 US_DEBUGP(" ATA OUT - SCSIOP_READ_CAPACITY\n");
1302 if (id
->capability
& CAPABILITY_LBA
) {
1303 capacity
= id
->lba_capacity
- 1;
1305 capacity
= (id
->heads
*
1309 readCapacityData
.LogicalBlockAddress
= cpu_to_be32(capacity
);
1310 readCapacityData
.BytesPerBlock
= cpu_to_be32(0x200);
1312 usb_stor_set_xfer_buf((unsigned char *) &readCapacityData
,
1313 sizeof(readCapacityData
), srb
);
1314 srb
->result
= SAM_STAT_GOOD
;
1315 sendToTransport
= 0;
1320 US_DEBUGP(" ATA OUT - SCSIOP_READ\n");
1322 lba
= be32_to_cpu(*(__be32
*)&srb
->cmnd
[2]);
1323 blockCount
= (unsigned long)srb
->cmnd
[7]<<8 | (unsigned long)srb
->cmnd
[8];
1325 if (id
->capability
& CAPABILITY_LBA
) {
1326 sectnum
= (unsigned char)(lba
);
1327 cylinder
= (unsigned short)(lba
>>8);
1328 head
= ATA_ADDRESS_DEVHEAD_LBA_MODE
| (unsigned char)(lba
>>24 & 0x0F);
1330 sectnum
= (unsigned char)((lba
% id
->sectors
) + 1);
1331 cylinder
= (unsigned short)(lba
/ (id
->sectors
*
1333 head
= (unsigned char)((lba
/ id
->sectors
) %
1336 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1337 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1338 ataCdb
->generic
.TransferBlockSize
= 1;
1339 ataCdb
->generic
.RegisterSelect
=
1340 REG_SECTOR_COUNT
| REG_SECTOR_NUMBER
|
1341 REG_CYLINDER_LOW
| REG_CYLINDER_HIGH
|
1342 REG_DEVICE_HEAD
| REG_COMMAND
;
1343 ataCdb
->write
.SectorCountByte
= (unsigned char)blockCount
;
1344 ataCdb
->write
.SectorNumberByte
= sectnum
;
1345 ataCdb
->write
.CylinderHighByte
= (unsigned char)(cylinder
>>8);
1346 ataCdb
->write
.CylinderLowByte
= (unsigned char)cylinder
;
1347 ataCdb
->write
.DeviceHeadByte
= (head
| ATA_ADDRESS_DEVHEAD_STD
);
1348 ataCdb
->write
.CommandByte
= WIN_READ
;
1352 US_DEBUGP(" ATA OUT - SCSIOP_WRITE\n");
1354 lba
= be32_to_cpu(*(__be32
*)&srb
->cmnd
[2]);
1355 blockCount
= (unsigned long)srb
->cmnd
[7]<<8 | (unsigned long)srb
->cmnd
[8];
1357 if (id
->capability
& CAPABILITY_LBA
) {
1358 sectnum
= (unsigned char)(lba
);
1359 cylinder
= (unsigned short)(lba
>>8);
1360 head
= ATA_ADDRESS_DEVHEAD_LBA_MODE
| (unsigned char)(lba
>>24 & 0x0F);
1362 sectnum
= (unsigned char)((lba
% id
->sectors
) + 1);
1363 cylinder
= (unsigned short)(lba
/ (id
->sectors
* id
->heads
));
1364 head
= (unsigned char)((lba
/ id
->sectors
) % id
->heads
);
1366 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1367 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1368 ataCdb
->generic
.TransferBlockSize
= 1;
1369 ataCdb
->generic
.RegisterSelect
=
1370 REG_SECTOR_COUNT
| REG_SECTOR_NUMBER
|
1371 REG_CYLINDER_LOW
| REG_CYLINDER_HIGH
|
1372 REG_DEVICE_HEAD
| REG_COMMAND
;
1373 ataCdb
->write
.SectorCountByte
= (unsigned char)blockCount
;
1374 ataCdb
->write
.SectorNumberByte
= sectnum
;
1375 ataCdb
->write
.CylinderHighByte
= (unsigned char)(cylinder
>>8);
1376 ataCdb
->write
.CylinderLowByte
= (unsigned char)cylinder
;
1377 ataCdb
->write
.DeviceHeadByte
= (head
| ATA_ADDRESS_DEVHEAD_STD
);
1378 ataCdb
->write
.CommandByte
= WIN_WRITE
;
1381 case ALLOW_MEDIUM_REMOVAL
:
1382 US_DEBUGP(" ATA OUT - SCSIOP_MEDIUM_REMOVAL\n");
1384 if (info
->DeviceFlags
& DF_REMOVABLE_MEDIA
) {
1385 US_DEBUGP(" srb->cmnd[4] = 0x%X\n", srb
->cmnd
[4]);
1387 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1388 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1389 ataCdb
->generic
.TransferBlockSize
= 1;
1390 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1391 ataCdb
->write
.CommandByte
= (srb
->cmnd
[4] & 0x1) ?
1392 WIN_DOORLOCK
: WIN_DOORUNLOCK
;
1393 srb
->request_bufflen
= 0;
1395 US_DEBUGP(" Not removeable media, just report okay\n");
1396 srb
->result
= SAM_STAT_GOOD
;
1397 sendToTransport
= 0;
1402 US_DEBUGP(" ATA OUT - SCSIOP_START_STOP_UNIT\n");
1403 US_DEBUGP(" srb->cmnd[4] = 0x%X\n", srb
->cmnd
[4]);
1405 if ((srb
->cmnd
[4] & 0x3) == 0x2) {
1406 US_DEBUGP(" Media Eject\n");
1407 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1408 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1409 ataCdb
->generic
.TransferBlockSize
= 0;
1410 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1411 ataCdb
->write
.CommandByte
= ATA_COMMAND_MEDIA_EJECT
;
1412 } else if ((srb
->cmnd
[4] & 0x3) == 0x1) {
1413 US_DEBUGP(" Get Media Status\n");
1414 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1415 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1416 ataCdb
->generic
.TransferBlockSize
= 1;
1417 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1418 ataCdb
->write
.CommandByte
= ATA_COMMAND_GET_MEDIA_STATUS
;
1419 srb
->request_bufflen
= 0;
1421 US_DEBUGP(" Nothing to do, just report okay\n");
1422 srb
->result
= SAM_STAT_GOOD
;
1423 sendToTransport
= 0;
1428 US_DEBUGP("Unsupported SCSI command - 0x%X\n", srb
->cmnd
[0]);
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
);
1453 /**************************************************************************
1456 * Allocates (if necessary) and initializes the driver structure.
1461 static int isd200_init_info(struct us_data
*us
)
1463 int retStatus
= ISD200_GOOD
;
1464 struct isd200_info
*info
;
1466 info
= (struct isd200_info
*)
1467 kzalloc(sizeof(struct isd200_info
), GFP_KERNEL
);
1469 retStatus
= ISD200_ERROR
;
1471 info
->id
= (struct hd_driveid
*)
1472 kzalloc(sizeof(struct hd_driveid
), GFP_KERNEL
);
1473 info
->RegsBuf
= (unsigned char *)
1474 kmalloc(sizeof(info
->ATARegs
), GFP_KERNEL
);
1475 if (!info
->id
|| !info
->RegsBuf
) {
1476 isd200_free_info_ptrs(info
);
1478 retStatus
= ISD200_ERROR
;
1482 if (retStatus
== ISD200_GOOD
) {
1484 us
->extra_destructor
= isd200_free_info_ptrs
;
1486 US_DEBUGP("ERROR - kmalloc failure\n");
1491 /**************************************************************************
1492 * Initialization for the ISD200
1495 int isd200_Initialization(struct us_data
*us
)
1497 US_DEBUGP("ISD200 Initialization...\n");
1499 /* Initialize ISD200 info struct */
1501 if (isd200_init_info(us
) == ISD200_ERROR
) {
1502 US_DEBUGP("ERROR Initializing ISD200 Info struct\n");
1504 /* Get device specific data */
1506 if (isd200_get_inquiry_data(us
) != ISD200_GOOD
)
1507 US_DEBUGP("ISD200 Initialization Failure\n");
1509 US_DEBUGP("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 conected 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 void isd200_ata_command(struct scsi_cmnd
*srb
, struct us_data
*us
)
1528 int sendToTransport
= 1;
1529 union ata_cdb ataCdb
;
1531 /* Make sure driver was initialized */
1533 if (us
->extra
== NULL
)
1534 US_DEBUGP("ERROR Driver not initialized\n");
1536 /* Convert command */
1538 sendToTransport
= isd200_scsi_to_ata(srb
, us
, &ataCdb
);
1540 /* send the command to the transport layer */
1541 if (sendToTransport
)
1542 isd200_invoke_transport(us
, srb
, &ataCdb
);