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 "transport.h"
54 #include <linux/jiffies.h>
55 #include <linux/errno.h>
56 #include <linux/slab.h>
57 #include <linux/hdreg.h>
58 #include <linux/ide.h>
60 /* Timeout defines (in Seconds) */
62 #define ISD200_ENUM_BSY_TIMEOUT 35
63 #define ISD200_ENUM_DETECT_TIMEOUT 30
64 #define ISD200_DEFAULT_TIMEOUT 30
67 #define DF_ATA_DEVICE 0x0001
68 #define DF_MEDIA_STATUS_ENABLED 0x0002
69 #define DF_REMOVABLE_MEDIA 0x0004
71 /* capability bit definitions */
72 #define CAPABILITY_DMA 0x01
73 #define CAPABILITY_LBA 0x02
75 /* command_setX bit definitions */
76 #define COMMANDSET_REMOVABLE 0x02
77 #define COMMANDSET_MEDIA_STATUS 0x10
79 /* ATA Vendor Specific defines */
80 #define ATA_ADDRESS_DEVHEAD_STD 0xa0
81 #define ATA_ADDRESS_DEVHEAD_LBA_MODE 0x40
82 #define ATA_ADDRESS_DEVHEAD_SLAVE 0x10
84 /* Action Select bits */
85 #define ACTION_SELECT_0 0x01
86 #define ACTION_SELECT_1 0x02
87 #define ACTION_SELECT_2 0x04
88 #define ACTION_SELECT_3 0x08
89 #define ACTION_SELECT_4 0x10
90 #define ACTION_SELECT_5 0x20
91 #define ACTION_SELECT_6 0x40
92 #define ACTION_SELECT_7 0x80
94 /* Register Select bits */
95 #define REG_ALTERNATE_STATUS 0x01
96 #define REG_DEVICE_CONTROL 0x01
97 #define REG_ERROR 0x02
98 #define REG_FEATURES 0x02
99 #define REG_SECTOR_COUNT 0x04
100 #define REG_SECTOR_NUMBER 0x08
101 #define REG_CYLINDER_LOW 0x10
102 #define REG_CYLINDER_HIGH 0x20
103 #define REG_DEVICE_HEAD 0x40
104 #define REG_STATUS 0x80
105 #define REG_COMMAND 0x80
107 /* ATA error definitions not in <linux/hdreg.h> */
108 #define ATA_ERROR_MEDIA_CHANGE 0x20
110 /* ATA command definitions not in <linux/hdreg.h> */
111 #define ATA_COMMAND_GET_MEDIA_STATUS 0xDA
112 #define ATA_COMMAND_MEDIA_EJECT 0xED
114 /* ATA drive control definitions */
115 #define ATA_DC_DISABLE_INTERRUPTS 0x02
116 #define ATA_DC_RESET_CONTROLLER 0x04
117 #define ATA_DC_REENABLE_CONTROLLER 0x00
120 * General purpose return codes
123 #define ISD200_ERROR -1
124 #define ISD200_GOOD 0
127 * Transport return codes
130 #define ISD200_TRANSPORT_GOOD 0 /* Transport good, command good */
131 #define ISD200_TRANSPORT_FAILED 1 /* Transport good, command failed */
132 #define ISD200_TRANSPORT_ERROR 2 /* Transport bad (i.e. device dead) */
134 /* driver action codes */
135 #define ACTION_READ_STATUS 0
136 #define ACTION_RESET 1
137 #define ACTION_REENABLE 2
138 #define ACTION_SOFT_RESET 3
139 #define ACTION_ENUM 4
140 #define ACTION_IDENTIFY 5
150 unsigned char SignatureByte0
;
151 unsigned char SignatureByte1
;
152 unsigned char ActionSelect
;
153 unsigned char RegisterSelect
;
154 unsigned char TransferBlockSize
;
155 unsigned char WriteData3F6
;
156 unsigned char WriteData1F1
;
157 unsigned char WriteData1F2
;
158 unsigned char WriteData1F3
;
159 unsigned char WriteData1F4
;
160 unsigned char WriteData1F5
;
161 unsigned char WriteData1F6
;
162 unsigned char WriteData1F7
;
163 unsigned char Reserved
[3];
167 unsigned char SignatureByte0
;
168 unsigned char SignatureByte1
;
169 unsigned char ActionSelect
;
170 unsigned char RegisterSelect
;
171 unsigned char TransferBlockSize
;
172 unsigned char AlternateStatusByte
;
173 unsigned char ErrorByte
;
174 unsigned char SectorCountByte
;
175 unsigned char SectorNumberByte
;
176 unsigned char CylinderLowByte
;
177 unsigned char CylinderHighByte
;
178 unsigned char DeviceHeadByte
;
179 unsigned char StatusByte
;
180 unsigned char Reserved
[3];
184 unsigned char SignatureByte0
;
185 unsigned char SignatureByte1
;
186 unsigned char ActionSelect
;
187 unsigned char RegisterSelect
;
188 unsigned char TransferBlockSize
;
189 unsigned char DeviceControlByte
;
190 unsigned char FeaturesByte
;
191 unsigned char SectorCountByte
;
192 unsigned char SectorNumberByte
;
193 unsigned char CylinderLowByte
;
194 unsigned char CylinderHighByte
;
195 unsigned char DeviceHeadByte
;
196 unsigned char CommandByte
;
197 unsigned char Reserved
[3];
203 * Inquiry data structure. This is the data returned from the target
204 * after it receives an inquiry.
206 * This structure may be extended by the number of bytes specified
207 * in the field AdditionalLength. The defined size constant only
208 * includes fields through ProductRevisionLevel.
214 #define DIRECT_ACCESS_DEVICE 0x00 /* disks */
215 #define DEVICE_REMOVABLE 0x80
217 struct inquiry_data
{
218 unsigned char DeviceType
;
219 unsigned char DeviceTypeModifier
;
220 unsigned char Versions
;
221 unsigned char Format
;
222 unsigned char AdditionalLength
;
223 unsigned char Reserved
[2];
224 unsigned char Capability
;
225 unsigned char VendorId
[8];
226 unsigned char ProductId
[16];
227 unsigned char ProductRevisionLevel
[4];
228 unsigned char VendorSpecific
[20];
229 unsigned char Reserved3
[40];
230 } __attribute__ ((packed
));
233 * INQUIRY data buffer size
236 #define INQUIRYDATABUFFERSIZE 36
240 * ISD200 CONFIG data struct
243 #define ATACFG_TIMING 0x0f
244 #define ATACFG_ATAPI_RESET 0x10
245 #define ATACFG_MASTER 0x20
246 #define ATACFG_BLOCKSIZE 0xa0
248 #define ATACFGE_LAST_LUN 0x07
249 #define ATACFGE_DESC_OVERRIDE 0x08
250 #define ATACFGE_STATE_SUSPEND 0x10
251 #define ATACFGE_SKIP_BOOT 0x20
252 #define ATACFGE_CONF_DESC2 0x40
253 #define ATACFGE_INIT_STATUS 0x80
255 #define CFG_CAPABILITY_SRST 0x01
257 struct isd200_config
{
258 unsigned char EventNotification
;
259 unsigned char ExternalClock
;
260 unsigned char ATAInitTimeout
;
261 unsigned char ATAConfig
;
262 unsigned char ATAMajorCommand
;
263 unsigned char ATAMinorCommand
;
264 unsigned char ATAExtraConfig
;
265 unsigned char Capability
;
266 }__attribute__ ((packed
));
270 * ISD200 driver information struct
274 struct inquiry_data InquiryData
;
275 struct hd_driveid drive
;
276 struct isd200_config ConfigData
;
277 unsigned char ATARegs
[8];
278 unsigned char DeviceHead
;
279 unsigned char DeviceFlags
;
281 /* maximum number of LUNs supported */
282 unsigned char MaxLUNs
;
287 * Read Capacity Data - returned in Big Endian format
290 struct read_capacity_data
{
291 unsigned long LogicalBlockAddress
;
292 unsigned long BytesPerBlock
;
296 * Read Block Limits Data - returned in Big Endian format
297 * This structure returns the maximum and minimum block
298 * size for a TAPE device.
301 struct read_block_limits
{
302 unsigned char Reserved
;
303 unsigned char BlockMaximumSize
[3];
304 unsigned char BlockMinimumSize
[2];
312 #define SENSE_ERRCODE 0x7f
313 #define SENSE_ERRCODE_VALID 0x80
314 #define SENSE_FLAG_SENSE_KEY 0x0f
315 #define SENSE_FLAG_BAD_LENGTH 0x20
316 #define SENSE_FLAG_END_OF_MEDIA 0x40
317 #define SENSE_FLAG_FILE_MARK 0x80
319 unsigned char ErrorCode
;
320 unsigned char SegmentNumber
;
322 unsigned char Information
[4];
323 unsigned char AdditionalSenseLength
;
324 unsigned char CommandSpecificInformation
[4];
325 unsigned char AdditionalSenseCode
;
326 unsigned char AdditionalSenseCodeQualifier
;
327 unsigned char FieldReplaceableUnitCode
;
328 unsigned char SenseKeySpecific
[3];
329 } __attribute__ ((packed
));
332 * Default request sense buffer size
335 #define SENSE_BUFFER_SIZE 18
337 /***********************************************************************
339 ***********************************************************************/
341 /**************************************************************************
344 * Builds an artificial sense buffer to report the results of a
350 void isd200_build_sense(struct us_data
*us
, Scsi_Cmnd
*srb
)
352 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
353 struct sense_data
*buf
= (struct sense_data
*) &srb
->sense_buffer
[0];
354 unsigned char error
= info
->ATARegs
[IDE_ERROR_OFFSET
];
356 if(error
& ATA_ERROR_MEDIA_CHANGE
) {
357 buf
->ErrorCode
= 0x70 | SENSE_ERRCODE_VALID
;
358 buf
->AdditionalSenseLength
= 0xb;
359 buf
->Flags
= UNIT_ATTENTION
;
360 buf
->AdditionalSenseCode
= 0;
361 buf
->AdditionalSenseCodeQualifier
= 0;
362 } else if(error
& MCR_ERR
) {
363 buf
->ErrorCode
= 0x70 | SENSE_ERRCODE_VALID
;
364 buf
->AdditionalSenseLength
= 0xb;
365 buf
->Flags
= UNIT_ATTENTION
;
366 buf
->AdditionalSenseCode
= 0;
367 buf
->AdditionalSenseCodeQualifier
= 0;
368 } else if(error
& TRK0_ERR
) {
369 buf
->ErrorCode
= 0x70 | SENSE_ERRCODE_VALID
;
370 buf
->AdditionalSenseLength
= 0xb;
371 buf
->Flags
= NOT_READY
;
372 buf
->AdditionalSenseCode
= 0;
373 buf
->AdditionalSenseCodeQualifier
= 0;
374 } else if(error
& ECC_ERR
) {
375 buf
->ErrorCode
= 0x70 | SENSE_ERRCODE_VALID
;
376 buf
->AdditionalSenseLength
= 0xb;
377 buf
->Flags
= DATA_PROTECT
;
378 buf
->AdditionalSenseCode
= 0;
379 buf
->AdditionalSenseCodeQualifier
= 0;
382 buf
->AdditionalSenseLength
= 0;
384 buf
->AdditionalSenseCode
= 0;
385 buf
->AdditionalSenseCodeQualifier
= 0;
390 /***********************************************************************
392 ***********************************************************************/
395 /**************************************************************************
398 * Routine for sending commands to the isd200
403 static int isd200_action( struct us_data
*us
, int action
,
404 void* pointer
, int value
)
407 struct scsi_cmnd srb
;
408 struct scsi_device srb_dev
;
409 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
412 memset(&ata
, 0, sizeof(ata
));
413 memset(&srb
, 0, sizeof(srb
));
414 memset(&srb_dev
, 0, sizeof(srb_dev
));
415 srb
.device
= &srb_dev
;
417 ata
.generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
418 ata
.generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
419 ata
.generic
.TransferBlockSize
= 1;
422 case ACTION_READ_STATUS
:
423 US_DEBUGP(" isd200_action(READ_STATUS)\n");
424 ata
.generic
.ActionSelect
= ACTION_SELECT_0
|ACTION_SELECT_2
;
425 ata
.generic
.RegisterSelect
=
426 REG_CYLINDER_LOW
| REG_CYLINDER_HIGH
|
427 REG_STATUS
| REG_ERROR
;
428 srb
.sc_data_direction
= SCSI_DATA_READ
;
429 srb
.request_buffer
= pointer
;
430 srb
.request_bufflen
= value
;
434 US_DEBUGP(" isd200_action(ENUM,0x%02x)\n",value
);
435 ata
.generic
.ActionSelect
= ACTION_SELECT_1
|ACTION_SELECT_2
|
436 ACTION_SELECT_3
|ACTION_SELECT_4
|
438 ata
.generic
.RegisterSelect
= REG_DEVICE_HEAD
;
439 ata
.write
.DeviceHeadByte
= value
;
440 srb
.sc_data_direction
= SCSI_DATA_NONE
;
444 US_DEBUGP(" isd200_action(RESET)\n");
445 ata
.generic
.ActionSelect
= ACTION_SELECT_1
|ACTION_SELECT_2
|
446 ACTION_SELECT_3
|ACTION_SELECT_4
;
447 ata
.generic
.RegisterSelect
= REG_DEVICE_CONTROL
;
448 ata
.write
.DeviceControlByte
= ATA_DC_RESET_CONTROLLER
;
449 srb
.sc_data_direction
= SCSI_DATA_NONE
;
452 case ACTION_REENABLE
:
453 US_DEBUGP(" isd200_action(REENABLE)\n");
454 ata
.generic
.ActionSelect
= ACTION_SELECT_1
|ACTION_SELECT_2
|
455 ACTION_SELECT_3
|ACTION_SELECT_4
;
456 ata
.generic
.RegisterSelect
= REG_DEVICE_CONTROL
;
457 ata
.write
.DeviceControlByte
= ATA_DC_REENABLE_CONTROLLER
;
458 srb
.sc_data_direction
= SCSI_DATA_NONE
;
461 case ACTION_SOFT_RESET
:
462 US_DEBUGP(" isd200_action(SOFT_RESET)\n");
463 ata
.generic
.ActionSelect
= ACTION_SELECT_1
|ACTION_SELECT_5
;
464 ata
.generic
.RegisterSelect
= REG_DEVICE_HEAD
| REG_COMMAND
;
465 ata
.write
.DeviceHeadByte
= info
->DeviceHead
;
466 ata
.write
.CommandByte
= WIN_SRST
;
467 srb
.sc_data_direction
= SCSI_DATA_NONE
;
470 case ACTION_IDENTIFY
:
471 US_DEBUGP(" isd200_action(IDENTIFY)\n");
472 ata
.generic
.RegisterSelect
= REG_COMMAND
;
473 ata
.write
.CommandByte
= WIN_IDENTIFY
;
474 srb
.sc_data_direction
= SCSI_DATA_READ
;
475 srb
.request_buffer
= (void *)&info
->drive
;
476 srb
.request_bufflen
= sizeof(struct hd_driveid
);
480 US_DEBUGP("Error: Undefined action %d\n",action
);
484 memcpy(srb
.cmnd
, &ata
, sizeof(ata
.generic
));
485 srb
.cmd_len
= sizeof(ata
.generic
);
486 status
= usb_stor_Bulk_transport(&srb
, us
);
487 if (status
== USB_STOR_TRANSPORT_GOOD
)
488 status
= ISD200_GOOD
;
490 US_DEBUGP(" isd200_action(0x%02x) error: %d\n",action
,status
);
491 status
= ISD200_ERROR
;
492 /* need to reset device here */
498 /**************************************************************************
506 int isd200_read_regs( struct us_data
*us
)
508 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
509 int retStatus
= ISD200_GOOD
;
512 US_DEBUGP("Entering isd200_IssueATAReadRegs\n");
514 transferStatus
= isd200_action( us
, ACTION_READ_STATUS
,
515 info
->ATARegs
, sizeof(info
->ATARegs
) );
516 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
517 US_DEBUGP(" Error reading ATA registers\n");
518 retStatus
= ISD200_ERROR
;
520 US_DEBUGP(" Got ATA Register[IDE_ERROR_OFFSET] = 0x%x\n",
521 info
->ATARegs
[IDE_ERROR_OFFSET
]);
528 /**************************************************************************
529 * Invoke the transport and basic error-handling/recovery methods
531 * This is used by the protocol layers to actually send the message to
532 * the device and receive the response.
534 void isd200_invoke_transport( struct us_data
*us
,
536 union ata_cdb
*ataCdb
)
538 int need_auto_sense
= 0;
542 /* send the command to the transport layer */
544 memcpy(srb
->cmnd
, ataCdb
, sizeof(ataCdb
->generic
));
545 srb
->cmd_len
= sizeof(ataCdb
->generic
);
546 transferStatus
= usb_stor_Bulk_transport(srb
, us
);
548 /* if the command gets aborted by the higher layers, we need to
549 * short-circuit all other processing
551 if (us
->sm_state
== US_STATE_ABORTING
) {
552 US_DEBUGP("-- command was aborted\n");
556 switch (transferStatus
) {
558 case USB_STOR_TRANSPORT_GOOD
:
559 /* Indicate a good result */
560 srb
->result
= SAM_STAT_GOOD
;
563 case USB_STOR_TRANSPORT_NO_SENSE
:
564 US_DEBUGP("-- transport indicates protocol failure\n");
565 srb
->result
= SAM_STAT_CHECK_CONDITION
;
568 case USB_STOR_TRANSPORT_FAILED
:
569 US_DEBUGP("-- transport indicates command failure\n");
573 case USB_STOR_TRANSPORT_ERROR
:
574 US_DEBUGP("-- transport indicates transport error\n");
575 srb
->result
= DID_ERROR
<< 16;
576 /* Need reset here */
580 US_DEBUGP("-- transport indicates unknown error\n");
581 srb
->result
= DID_ERROR
<< 16;
582 /* Need reset here */
586 if ((srb
->resid
> 0) &&
587 !((srb
->cmnd
[0] == REQUEST_SENSE
) ||
588 (srb
->cmnd
[0] == INQUIRY
) ||
589 (srb
->cmnd
[0] == MODE_SENSE
) ||
590 (srb
->cmnd
[0] == LOG_SENSE
) ||
591 (srb
->cmnd
[0] == MODE_SENSE_10
))) {
592 US_DEBUGP("-- unexpectedly short transfer\n");
596 if (need_auto_sense
) {
597 result
= isd200_read_regs(us
);
598 if (us
->sm_state
== US_STATE_ABORTING
) {
599 US_DEBUGP("-- auto-sense aborted\n");
602 if (result
== ISD200_GOOD
) {
603 isd200_build_sense(us
, srb
);
604 srb
->result
= SAM_STAT_CHECK_CONDITION
;
606 /* If things are really okay, then let's show that */
607 if ((srb
->sense_buffer
[2] & 0xf) == 0x0)
608 srb
->result
= SAM_STAT_GOOD
;
610 srb
->result
= DID_ERROR
<< 16;
611 /* Need reset here */
615 /* Regardless of auto-sense, if we _know_ we have an error
616 * condition, show that in the result code
618 if (transferStatus
== USB_STOR_TRANSPORT_FAILED
)
619 srb
->result
= SAM_STAT_CHECK_CONDITION
;
622 /* abort processing: the bulk-only transport requires a reset
623 * following an abort */
625 srb
->result
= DID_ABORT
<< 16;
627 /* permit the reset transfer to take place */
628 clear_bit(US_FLIDX_ABORTING
, &us
->flags
);
629 /* Need reset here */
632 #ifdef CONFIG_USB_STORAGE_DEBUG
633 static void isd200_log_config( struct isd200_info
* info
)
635 US_DEBUGP(" Event Notification: 0x%x\n",
636 info
->ConfigData
.EventNotification
);
637 US_DEBUGP(" External Clock: 0x%x\n",
638 info
->ConfigData
.ExternalClock
);
639 US_DEBUGP(" ATA Init Timeout: 0x%x\n",
640 info
->ConfigData
.ATAInitTimeout
);
641 US_DEBUGP(" ATAPI Command Block Size: 0x%x\n",
642 (info
->ConfigData
.ATAConfig
& ATACFG_BLOCKSIZE
) >> 6);
643 US_DEBUGP(" Master/Slave Selection: 0x%x\n",
644 info
->ConfigData
.ATAConfig
& ATACFG_MASTER
);
645 US_DEBUGP(" ATAPI Reset: 0x%x\n",
646 info
->ConfigData
.ATAConfig
& ATACFG_ATAPI_RESET
);
647 US_DEBUGP(" ATA Timing: 0x%x\n",
648 info
->ConfigData
.ATAConfig
& ATACFG_TIMING
);
649 US_DEBUGP(" ATA Major Command: 0x%x\n",
650 info
->ConfigData
.ATAMajorCommand
);
651 US_DEBUGP(" ATA Minor Command: 0x%x\n",
652 info
->ConfigData
.ATAMinorCommand
);
653 US_DEBUGP(" Init Status: 0x%x\n",
654 info
->ConfigData
.ATAExtraConfig
& ATACFGE_INIT_STATUS
);
655 US_DEBUGP(" Config Descriptor 2: 0x%x\n",
656 info
->ConfigData
.ATAExtraConfig
& ATACFGE_CONF_DESC2
);
657 US_DEBUGP(" Skip Device Boot: 0x%x\n",
658 info
->ConfigData
.ATAExtraConfig
& ATACFGE_SKIP_BOOT
);
659 US_DEBUGP(" ATA 3 State Supsend: 0x%x\n",
660 info
->ConfigData
.ATAExtraConfig
& ATACFGE_STATE_SUSPEND
);
661 US_DEBUGP(" Descriptor Override: 0x%x\n",
662 info
->ConfigData
.ATAExtraConfig
& ATACFGE_DESC_OVERRIDE
);
663 US_DEBUGP(" Last LUN Identifier: 0x%x\n",
664 info
->ConfigData
.ATAExtraConfig
& ATACFGE_LAST_LUN
);
665 US_DEBUGP(" SRST Enable: 0x%x\n",
666 info
->ConfigData
.ATAExtraConfig
& CFG_CAPABILITY_SRST
);
670 /**************************************************************************
671 * isd200_write_config
673 * Write the ISD200 Configuration data
678 int isd200_write_config( struct us_data
*us
)
680 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
681 int retStatus
= ISD200_GOOD
;
684 #ifdef CONFIG_USB_STORAGE_DEBUG
685 US_DEBUGP("Entering isd200_write_config\n");
686 US_DEBUGP(" Writing the following ISD200 Config Data:\n");
687 isd200_log_config(info
);
690 /* let's send the command via the control pipe */
691 result
= usb_stor_ctrl_transfer(
695 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
698 (void *) &info
->ConfigData
,
699 sizeof(info
->ConfigData
));
702 US_DEBUGP(" ISD200 Config Data was written successfully\n");
704 US_DEBUGP(" Request to write ISD200 Config Data failed!\n");
705 retStatus
= ISD200_ERROR
;
708 US_DEBUGP("Leaving isd200_write_config %08X\n", retStatus
);
713 /**************************************************************************
716 * Reads the ISD200 Configuration data
721 int isd200_read_config( struct us_data
*us
)
723 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
724 int retStatus
= ISD200_GOOD
;
727 US_DEBUGP("Entering isd200_read_config\n");
729 /* read the configuration information from ISD200. Use this to */
730 /* determine what the special ATA CDB bytes are. */
732 result
= usb_stor_ctrl_transfer(
736 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
739 (void *) &info
->ConfigData
,
740 sizeof(info
->ConfigData
));
744 US_DEBUGP(" Retrieved the following ISD200 Config Data:\n");
745 #ifdef CONFIG_USB_STORAGE_DEBUG
746 isd200_log_config(info
);
749 US_DEBUGP(" Request to get ISD200 Config Data failed!\n");
750 retStatus
= ISD200_ERROR
;
753 US_DEBUGP("Leaving isd200_read_config %08X\n", retStatus
);
758 /**************************************************************************
759 * isd200_atapi_soft_reset
761 * Perform an Atapi Soft Reset on the device
766 int isd200_atapi_soft_reset( struct us_data
*us
)
768 int retStatus
= ISD200_GOOD
;
771 US_DEBUGP("Entering isd200_atapi_soft_reset\n");
773 transferStatus
= isd200_action( us
, ACTION_SOFT_RESET
, NULL
, 0 );
774 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
775 US_DEBUGP(" Error issuing Atapi Soft Reset\n");
776 retStatus
= ISD200_ERROR
;
779 US_DEBUGP("Leaving isd200_atapi_soft_reset %08X\n", retStatus
);
784 /**************************************************************************
787 * Perform an SRST on the device
792 int isd200_srst( struct us_data
*us
)
794 int retStatus
= ISD200_GOOD
;
797 US_DEBUGP("Entering isd200_SRST\n");
799 transferStatus
= isd200_action( us
, ACTION_RESET
, NULL
, 0 );
801 /* check to see if this request failed */
802 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
803 US_DEBUGP(" Error issuing SRST\n");
804 retStatus
= ISD200_ERROR
;
806 /* delay 10ms to give the drive a chance to see it */
809 transferStatus
= isd200_action( us
, ACTION_REENABLE
, NULL
, 0 );
810 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
811 US_DEBUGP(" Error taking drive out of reset\n");
812 retStatus
= ISD200_ERROR
;
814 /* delay 50ms to give the drive a chance to recover after SRST */
819 US_DEBUGP("Leaving isd200_srst %08X\n", retStatus
);
824 /**************************************************************************
827 * Helper function for isd200_manual_enum(). Does ENUM and READ_STATUS
828 * and tries to analyze the status registers
833 static int isd200_try_enum(struct us_data
*us
, unsigned char master_slave
,
836 int status
= ISD200_GOOD
;
837 unsigned char regs
[8];
838 unsigned long endTime
;
839 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
840 int recheckAsMaster
= FALSE
;
843 endTime
= jiffies
+ ISD200_ENUM_DETECT_TIMEOUT
* HZ
;
845 endTime
= jiffies
+ ISD200_ENUM_BSY_TIMEOUT
* HZ
;
847 /* loop until we detect !BSY or timeout */
849 #ifdef CONFIG_USB_STORAGE_DEBUG
850 char* mstr
= master_slave
== ATA_ADDRESS_DEVHEAD_STD
?
854 status
= isd200_action( us
, ACTION_ENUM
, NULL
, master_slave
);
855 if ( status
!= ISD200_GOOD
)
858 status
= isd200_action( us
, ACTION_READ_STATUS
,
859 regs
, sizeof(regs
) );
860 if ( status
!= ISD200_GOOD
)
864 if (regs
[IDE_STATUS_OFFSET
] & BUSY_STAT
) {
865 US_DEBUGP(" %s status is still BSY, try again...\n",mstr
);
867 US_DEBUGP(" %s status !BSY, continue with next operation\n",mstr
);
871 /* check for BUSY_STAT and */
872 /* WRERR_STAT (workaround ATA Zip drive) and */
873 /* ERR_STAT (workaround for Archos CD-ROM) */
874 else if (regs
[IDE_STATUS_OFFSET
] &
875 (BUSY_STAT
| WRERR_STAT
| ERR_STAT
)) {
876 US_DEBUGP(" Status indicates it is not ready, try again...\n");
878 /* check for DRDY, ATA devices set DRDY after SRST */
879 else if (regs
[IDE_STATUS_OFFSET
] & READY_STAT
) {
880 US_DEBUGP(" Identified ATA device\n");
881 info
->DeviceFlags
|= DF_ATA_DEVICE
;
882 info
->DeviceHead
= master_slave
;
885 /* check Cylinder High/Low to
886 determine if it is an ATAPI device
888 else if ((regs
[IDE_HCYL_OFFSET
] == 0xEB) &&
889 (regs
[IDE_LCYL_OFFSET
] == 0x14)) {
890 /* It seems that the RICOH
891 MP6200A CD/RW drive will
892 report itself okay as a
893 slave when it is really a
894 master. So this check again
895 as a master device just to
896 make sure it doesn't report
897 itself okay as a master also
899 if ((master_slave
& ATA_ADDRESS_DEVHEAD_SLAVE
) &&
900 (recheckAsMaster
== FALSE
)) {
901 US_DEBUGP(" Identified ATAPI device as slave. Rechecking again as master\n");
902 recheckAsMaster
= TRUE
;
903 master_slave
= ATA_ADDRESS_DEVHEAD_STD
;
905 US_DEBUGP(" Identified ATAPI device\n");
906 info
->DeviceHead
= master_slave
;
908 status
= isd200_atapi_soft_reset(us
);
912 US_DEBUGP(" Not ATA, not ATAPI. Weird.\n");
916 /* check for timeout on this request */
917 if (time_after_eq(jiffies
, endTime
)) {
919 US_DEBUGP(" BSY check timeout, just continue with next operation...\n");
921 US_DEBUGP(" Device detect timeout!\n");
929 /**************************************************************************
932 * Determines if the drive attached is an ATA or ATAPI and if it is a
938 int isd200_manual_enum(struct us_data
*us
)
940 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
941 int retStatus
= ISD200_GOOD
;
943 US_DEBUGP("Entering isd200_manual_enum\n");
945 retStatus
= isd200_read_config(us
);
946 if (retStatus
== ISD200_GOOD
) {
948 /* master or slave? */
949 retStatus
= isd200_try_enum( us
, ATA_ADDRESS_DEVHEAD_STD
, FALSE
);
950 if (retStatus
== ISD200_GOOD
)
951 retStatus
= isd200_try_enum( us
, ATA_ADDRESS_DEVHEAD_SLAVE
, FALSE
);
953 if (retStatus
== ISD200_GOOD
) {
954 retStatus
= isd200_srst(us
);
955 if (retStatus
== ISD200_GOOD
)
957 retStatus
= isd200_try_enum( us
, ATA_ADDRESS_DEVHEAD_STD
, TRUE
);
960 isslave
= (info
->DeviceHead
& ATA_ADDRESS_DEVHEAD_SLAVE
) ? 1 : 0;
961 if (!(info
->ConfigData
.ATAConfig
& ATACFG_MASTER
)) {
962 US_DEBUGP(" Setting Master/Slave selection to %d\n", isslave
);
963 info
->ConfigData
.ATAConfig
&= 0x3f;
964 info
->ConfigData
.ATAConfig
|= (isslave
<<6);
965 retStatus
= isd200_write_config(us
);
969 US_DEBUGP("Leaving isd200_manual_enum %08X\n", retStatus
);
974 /**************************************************************************
975 * isd200_get_inquiry_data
982 int isd200_get_inquiry_data( struct us_data
*us
)
984 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
985 int retStatus
= ISD200_GOOD
;
987 US_DEBUGP("Entering isd200_get_inquiry_data\n");
989 /* set default to Master */
990 info
->DeviceHead
= ATA_ADDRESS_DEVHEAD_STD
;
992 /* attempt to manually enumerate this device */
993 retStatus
= isd200_manual_enum(us
);
994 if (retStatus
== ISD200_GOOD
) {
997 /* check for an ATA device */
998 if (info
->DeviceFlags
& DF_ATA_DEVICE
) {
999 /* this must be an ATA device */
1000 /* perform an ATA Command Identify */
1001 transferStatus
= isd200_action( us
, ACTION_IDENTIFY
,
1003 sizeof(struct hd_driveid
) );
1004 if (transferStatus
!= ISD200_TRANSPORT_GOOD
) {
1005 /* Error issuing ATA Command Identify */
1006 US_DEBUGP(" Error issuing ATA Command Identify\n");
1007 retStatus
= ISD200_ERROR
;
1009 /* ATA Command Identify successful */
1012 ide_fix_driveid(&info
->drive
);
1014 US_DEBUGP(" Identify Data Structure:\n");
1015 US_DEBUGP(" config = 0x%x\n", info
->drive
.config
);
1016 US_DEBUGP(" cyls = 0x%x\n", info
->drive
.cyls
);
1017 US_DEBUGP(" heads = 0x%x\n", info
->drive
.heads
);
1018 US_DEBUGP(" track_bytes = 0x%x\n", info
->drive
.track_bytes
);
1019 US_DEBUGP(" sector_bytes = 0x%x\n", info
->drive
.sector_bytes
);
1020 US_DEBUGP(" sectors = 0x%x\n", info
->drive
.sectors
);
1021 US_DEBUGP(" serial_no[0] = 0x%x\n", info
->drive
.serial_no
[0]);
1022 US_DEBUGP(" buf_type = 0x%x\n", info
->drive
.buf_type
);
1023 US_DEBUGP(" buf_size = 0x%x\n", info
->drive
.buf_size
);
1024 US_DEBUGP(" ecc_bytes = 0x%x\n", info
->drive
.ecc_bytes
);
1025 US_DEBUGP(" fw_rev[0] = 0x%x\n", info
->drive
.fw_rev
[0]);
1026 US_DEBUGP(" model[0] = 0x%x\n", info
->drive
.model
[0]);
1027 US_DEBUGP(" max_multsect = 0x%x\n", info
->drive
.max_multsect
);
1028 US_DEBUGP(" dword_io = 0x%x\n", info
->drive
.dword_io
);
1029 US_DEBUGP(" capability = 0x%x\n", info
->drive
.capability
);
1030 US_DEBUGP(" tPIO = 0x%x\n", info
->drive
.tPIO
);
1031 US_DEBUGP(" tDMA = 0x%x\n", info
->drive
.tDMA
);
1032 US_DEBUGP(" field_valid = 0x%x\n", info
->drive
.field_valid
);
1033 US_DEBUGP(" cur_cyls = 0x%x\n", info
->drive
.cur_cyls
);
1034 US_DEBUGP(" cur_heads = 0x%x\n", info
->drive
.cur_heads
);
1035 US_DEBUGP(" cur_sectors = 0x%x\n", info
->drive
.cur_sectors
);
1036 US_DEBUGP(" cur_capacity = 0x%x\n", (info
->drive
.cur_capacity1
<< 16) + info
->drive
.cur_capacity0
);
1037 US_DEBUGP(" multsect = 0x%x\n", info
->drive
.multsect
);
1038 US_DEBUGP(" lba_capacity = 0x%x\n", info
->drive
.lba_capacity
);
1039 US_DEBUGP(" command_set_1 = 0x%x\n", info
->drive
.command_set_1
);
1040 US_DEBUGP(" command_set_2 = 0x%x\n", info
->drive
.command_set_2
);
1042 memset(&info
->InquiryData
, 0, sizeof(info
->InquiryData
));
1044 /* Standard IDE interface only supports disks */
1045 info
->InquiryData
.DeviceType
= DIRECT_ACCESS_DEVICE
;
1047 /* Fix-up the return data from an INQUIRY command to show
1048 * ANSI SCSI rev 2 so we don't confuse the SCSI layers above us
1051 info
->InquiryData
.Versions
= 0x2;
1053 /* The length must be at least 36 (5 + 31) */
1054 info
->InquiryData
.AdditionalLength
= 0x1F;
1056 if (info
->drive
.command_set_1
& COMMANDSET_MEDIA_STATUS
) {
1057 /* set the removable bit */
1058 info
->InquiryData
.DeviceTypeModifier
= DEVICE_REMOVABLE
;
1059 info
->DeviceFlags
|= DF_REMOVABLE_MEDIA
;
1062 /* Fill in vendor identification fields */
1063 src
= (__u16
*)info
->drive
.model
;
1064 dest
= (__u16
*)info
->InquiryData
.VendorId
;
1066 dest
[i
] = be16_to_cpu(src
[i
]);
1068 src
= (__u16
*)(info
->drive
.model
+8);
1069 dest
= (__u16
*)info
->InquiryData
.ProductId
;
1071 dest
[i
] = be16_to_cpu(src
[i
]);
1073 src
= (__u16
*)info
->drive
.fw_rev
;
1074 dest
= (__u16
*)info
->InquiryData
.ProductRevisionLevel
;
1076 dest
[i
] = be16_to_cpu(src
[i
]);
1078 /* determine if it supports Media Status Notification */
1079 if (info
->drive
.command_set_2
& COMMANDSET_MEDIA_STATUS
) {
1080 US_DEBUGP(" Device supports Media Status Notification\n");
1082 /* Indicate that it is enabled, even though it is not
1083 * This allows the lock/unlock of the media to work
1086 info
->DeviceFlags
|= DF_MEDIA_STATUS_ENABLED
;
1089 info
->DeviceFlags
&= ~DF_MEDIA_STATUS_ENABLED
;
1094 * this must be an ATAPI device
1095 * use an ATAPI protocol (Transparent SCSI)
1097 us
->protocol_name
= "Transparent SCSI";
1098 us
->proto_handler
= usb_stor_transparent_scsi_command
;
1100 US_DEBUGP("Protocol changed to: %s\n", us
->protocol_name
);
1102 /* Free driver structure */
1103 if (us
->extra
!= NULL
) {
1106 us
->extra_destructor
= NULL
;
1111 US_DEBUGP("Leaving isd200_get_inquiry_data %08X\n", retStatus
);
1117 /**************************************************************************
1120 * Copy data into the srb request buffer. Use scatter gather if required.
1125 void isd200_data_copy(Scsi_Cmnd
*srb
, char * src
, int length
)
1127 unsigned int len
= length
;
1128 struct scatterlist
*sg
;
1132 unsigned int total
= 0;
1134 /* Add up the sizes of all the sg segments */
1135 sg
= (struct scatterlist
*) srb
->request_buffer
;
1136 for (i
= 0; i
< srb
->use_sg
; i
++)
1137 total
+= sg
[i
].length
;
1144 /* Copy data into sg buffer(s) */
1145 for (i
= 0; i
< srb
->use_sg
; i
++) {
1146 if ((len
> total
) && (len
> 0)) {
1147 /* transfer the lesser of the next buffer or the
1149 if (len
- total
>= sg
[i
].length
) {
1150 memcpy(sg_address(sg
[i
]), src
+ total
, sg
[i
].length
);
1151 total
+= sg
[i
].length
;
1153 memcpy(sg_address(sg
[i
]), src
+ total
, len
- total
);
1161 /* Make sure length does not exceed buffer length */
1162 if (length
> srb
->request_bufflen
)
1163 len
= srb
->request_bufflen
;
1166 memcpy(srb
->request_buffer
, src
, len
);
1171 /**************************************************************************
1172 * isd200_scsi_to_ata
1174 * Translate SCSI commands to ATA commands.
1177 * TRUE if the command needs to be sent to the transport layer
1180 int isd200_scsi_to_ata(Scsi_Cmnd
*srb
, struct us_data
*us
,
1181 union ata_cdb
* ataCdb
)
1183 struct isd200_info
*info
= (struct isd200_info
*)us
->extra
;
1184 int sendToTransport
= TRUE
;
1185 unsigned char sectnum
, head
;
1186 unsigned short cylinder
;
1188 unsigned long blockCount
;
1189 unsigned char senseData
[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
1191 memset(ataCdb
, 0, sizeof(union ata_cdb
));
1194 switch (srb
->cmnd
[0]) {
1196 US_DEBUGP(" ATA OUT - INQUIRY\n");
1198 if (srb
->request_bufflen
> sizeof(struct inquiry_data
))
1199 srb
->request_bufflen
= sizeof(struct inquiry_data
);
1201 /* copy InquiryData */
1202 isd200_data_copy(srb
, (char *) &info
->InquiryData
, srb
->request_bufflen
);
1203 srb
->result
= SAM_STAT_GOOD
;
1204 sendToTransport
= FALSE
;
1208 US_DEBUGP(" ATA OUT - SCSIOP_MODE_SENSE\n");
1210 /* Initialize the return buffer */
1211 isd200_data_copy(srb
, (char *) &senseData
, 8);
1213 if (info
->DeviceFlags
& DF_MEDIA_STATUS_ENABLED
)
1215 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1216 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1217 ataCdb
->generic
.TransferBlockSize
= 1;
1218 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1219 ataCdb
->write
.CommandByte
= ATA_COMMAND_GET_MEDIA_STATUS
;
1220 srb
->request_bufflen
= 0;
1222 US_DEBUGP(" Media Status not supported, just report okay\n");
1223 srb
->result
= SAM_STAT_GOOD
;
1224 sendToTransport
= FALSE
;
1228 case TEST_UNIT_READY
:
1229 US_DEBUGP(" ATA OUT - SCSIOP_TEST_UNIT_READY\n");
1231 /* Initialize the return buffer */
1232 isd200_data_copy(srb
, (char *) &senseData
, 8);
1234 if (info
->DeviceFlags
& DF_MEDIA_STATUS_ENABLED
)
1236 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1237 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1238 ataCdb
->generic
.TransferBlockSize
= 1;
1239 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1240 ataCdb
->write
.CommandByte
= ATA_COMMAND_GET_MEDIA_STATUS
;
1241 srb
->request_bufflen
= 0;
1243 US_DEBUGP(" Media Status not supported, just report okay\n");
1244 srb
->result
= SAM_STAT_GOOD
;
1245 sendToTransport
= FALSE
;
1251 unsigned long capacity
;
1252 struct read_capacity_data readCapacityData
;
1254 US_DEBUGP(" ATA OUT - SCSIOP_READ_CAPACITY\n");
1256 if (info
->drive
.capability
& CAPABILITY_LBA
) {
1257 capacity
= info
->drive
.lba_capacity
- 1;
1259 capacity
= (info
->drive
.heads
*
1261 info
->drive
.sectors
) - 1;
1263 readCapacityData
.LogicalBlockAddress
= cpu_to_be32(capacity
);
1264 readCapacityData
.BytesPerBlock
= cpu_to_be32(0x200);
1266 if (srb
->request_bufflen
> sizeof(struct read_capacity_data
))
1267 srb
->request_bufflen
= sizeof(struct read_capacity_data
);
1269 isd200_data_copy(srb
, (char *) &readCapacityData
, srb
->request_bufflen
);
1270 srb
->result
= SAM_STAT_GOOD
;
1271 sendToTransport
= FALSE
;
1276 US_DEBUGP(" ATA OUT - SCSIOP_READ\n");
1278 lba
= *(unsigned long *)&srb
->cmnd
[2];
1279 lba
= cpu_to_be32(lba
);
1280 blockCount
= (unsigned long)srb
->cmnd
[7]<<8 | (unsigned long)srb
->cmnd
[8];
1282 if (info
->drive
.capability
& CAPABILITY_LBA
) {
1283 sectnum
= (unsigned char)(lba
);
1284 cylinder
= (unsigned short)(lba
>>8);
1285 head
= ATA_ADDRESS_DEVHEAD_LBA_MODE
| (unsigned char)(lba
>>24 & 0x0F);
1287 sectnum
= (unsigned char)((lba
% info
->drive
.sectors
) + 1);
1288 cylinder
= (unsigned short)(lba
/ (info
->drive
.sectors
*
1289 info
->drive
.heads
));
1290 head
= (unsigned char)((lba
/ info
->drive
.sectors
) %
1293 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1294 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1295 ataCdb
->generic
.TransferBlockSize
= 1;
1296 ataCdb
->generic
.RegisterSelect
=
1297 REG_SECTOR_COUNT
| REG_SECTOR_NUMBER
|
1298 REG_CYLINDER_LOW
| REG_CYLINDER_HIGH
|
1299 REG_DEVICE_HEAD
| REG_COMMAND
;
1300 ataCdb
->write
.SectorCountByte
= (unsigned char)blockCount
;
1301 ataCdb
->write
.SectorNumberByte
= sectnum
;
1302 ataCdb
->write
.CylinderHighByte
= (unsigned char)(cylinder
>>8);
1303 ataCdb
->write
.CylinderLowByte
= (unsigned char)cylinder
;
1304 ataCdb
->write
.DeviceHeadByte
= (head
| ATA_ADDRESS_DEVHEAD_STD
);
1305 ataCdb
->write
.CommandByte
= WIN_READ
;
1309 US_DEBUGP(" ATA OUT - SCSIOP_WRITE\n");
1311 lba
= *(unsigned long *)&srb
->cmnd
[2];
1312 lba
= cpu_to_be32(lba
);
1313 blockCount
= (unsigned long)srb
->cmnd
[7]<<8 | (unsigned long)srb
->cmnd
[8];
1315 if (info
->drive
.capability
& CAPABILITY_LBA
) {
1316 sectnum
= (unsigned char)(lba
);
1317 cylinder
= (unsigned short)(lba
>>8);
1318 head
= ATA_ADDRESS_DEVHEAD_LBA_MODE
| (unsigned char)(lba
>>24 & 0x0F);
1320 sectnum
= (unsigned char)((lba
% info
->drive
.sectors
) + 1);
1321 cylinder
= (unsigned short)(lba
/ (info
->drive
.sectors
* info
->drive
.heads
));
1322 head
= (unsigned char)((lba
/ info
->drive
.sectors
) % info
->drive
.heads
);
1324 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1325 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1326 ataCdb
->generic
.TransferBlockSize
= 1;
1327 ataCdb
->generic
.RegisterSelect
=
1328 REG_SECTOR_COUNT
| REG_SECTOR_NUMBER
|
1329 REG_CYLINDER_LOW
| REG_CYLINDER_HIGH
|
1330 REG_DEVICE_HEAD
| REG_COMMAND
;
1331 ataCdb
->write
.SectorCountByte
= (unsigned char)blockCount
;
1332 ataCdb
->write
.SectorNumberByte
= sectnum
;
1333 ataCdb
->write
.CylinderHighByte
= (unsigned char)(cylinder
>>8);
1334 ataCdb
->write
.CylinderLowByte
= (unsigned char)cylinder
;
1335 ataCdb
->write
.DeviceHeadByte
= (head
| ATA_ADDRESS_DEVHEAD_STD
);
1336 ataCdb
->write
.CommandByte
= WIN_WRITE
;
1339 case ALLOW_MEDIUM_REMOVAL
:
1340 US_DEBUGP(" ATA OUT - SCSIOP_MEDIUM_REMOVAL\n");
1342 if (info
->DeviceFlags
& DF_REMOVABLE_MEDIA
) {
1343 US_DEBUGP(" srb->cmnd[4] = 0x%X\n", srb
->cmnd
[4]);
1345 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1346 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1347 ataCdb
->generic
.TransferBlockSize
= 1;
1348 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1349 ataCdb
->write
.CommandByte
= (srb
->cmnd
[4] & 0x1) ?
1350 WIN_DOORLOCK
: WIN_DOORUNLOCK
;
1351 srb
->request_bufflen
= 0;
1353 US_DEBUGP(" Not removeable media, just report okay\n");
1354 srb
->result
= SAM_STAT_GOOD
;
1355 sendToTransport
= FALSE
;
1360 US_DEBUGP(" ATA OUT - SCSIOP_START_STOP_UNIT\n");
1361 US_DEBUGP(" srb->cmnd[4] = 0x%X\n", srb
->cmnd
[4]);
1363 /* Initialize the return buffer */
1364 isd200_data_copy(srb
, (char *) &senseData
, 8);
1366 if ((srb
->cmnd
[4] & 0x3) == 0x2) {
1367 US_DEBUGP(" Media Eject\n");
1368 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1369 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1370 ataCdb
->generic
.TransferBlockSize
= 0;
1371 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1372 ataCdb
->write
.CommandByte
= ATA_COMMAND_MEDIA_EJECT
;
1373 } else if ((srb
->cmnd
[4] & 0x3) == 0x1) {
1374 US_DEBUGP(" Get Media Status\n");
1375 ataCdb
->generic
.SignatureByte0
= info
->ConfigData
.ATAMajorCommand
;
1376 ataCdb
->generic
.SignatureByte1
= info
->ConfigData
.ATAMinorCommand
;
1377 ataCdb
->generic
.TransferBlockSize
= 1;
1378 ataCdb
->generic
.RegisterSelect
= REG_COMMAND
;
1379 ataCdb
->write
.CommandByte
= ATA_COMMAND_GET_MEDIA_STATUS
;
1380 srb
->request_bufflen
= 0;
1382 US_DEBUGP(" Nothing to do, just report okay\n");
1383 srb
->result
= SAM_STAT_GOOD
;
1384 sendToTransport
= FALSE
;
1389 US_DEBUGP("Unsupported SCSI command - 0x%X\n", srb
->cmnd
[0]);
1390 srb
->result
= DID_ERROR
<< 16;
1391 sendToTransport
= FALSE
;
1395 return(sendToTransport
);
1399 /**************************************************************************
1402 * Allocates (if necessary) and initializes the driver structure.
1407 int isd200_init_info(struct us_data
*us
)
1409 int retStatus
= ISD200_GOOD
;
1412 us
->extra
= (void *) kmalloc(sizeof(struct isd200_info
), GFP_KERNEL
);
1414 US_DEBUGP("ERROR - kmalloc failure\n");
1415 retStatus
= ISD200_ERROR
;
1419 if (retStatus
== ISD200_GOOD
) {
1420 memset(us
->extra
, 0, sizeof(struct isd200_info
));
1426 /**************************************************************************
1427 * Initialization for the ISD200
1430 int isd200_Initialization(struct us_data
*us
)
1432 US_DEBUGP("ISD200 Initialization...\n");
1434 /* Initialize ISD200 info struct */
1436 if (isd200_init_info(us
) == ISD200_ERROR
) {
1437 US_DEBUGP("ERROR Initializing ISD200 Info struct\n");
1439 /* Get device specific data */
1441 if (isd200_get_inquiry_data(us
) != ISD200_GOOD
)
1442 US_DEBUGP("ISD200 Initialization Failure\n");
1444 US_DEBUGP("ISD200 Initialization complete\n");
1451 /**************************************************************************
1452 * Protocol and Transport for the ISD200 ASIC
1454 * This protocol and transport are for ATA devices connected to an ISD200
1455 * ASIC. An ATAPI device that is conected as a slave device will be
1456 * detected in the driver initialization function and the protocol will
1457 * be changed to an ATAPI protocol (Transparent SCSI).
1461 void isd200_ata_command(Scsi_Cmnd
*srb
, struct us_data
*us
)
1463 int sendToTransport
= TRUE
;
1464 union ata_cdb ataCdb
;
1466 /* Make sure driver was initialized */
1468 if (us
->extra
== NULL
)
1469 US_DEBUGP("ERROR Driver not initialized\n");
1471 /* Convert command */
1472 sendToTransport
= isd200_scsi_to_ata(srb
, us
, &ataCdb
);
1474 /* send the command to the transport layer */
1475 if (sendToTransport
)
1476 isd200_invoke_transport(us
, srb
, &ataCdb
);