isd200.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:57k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /* Transport & Protocol Driver for In-System Design, Inc. ISD200 ASIC
  2.  *
  3.  * First release
  4.  *
  5.  * Current development and maintenance by:
  6.  *   (c) 2000 In-System Design, Inc. (support@in-system.com)
  7.  *
  8.  * The ISD200 ASIC does not natively support ATA devices.  The chip
  9.  * does implement an interface, the ATA Command Block (ATACB) which provides
  10.  * a means of passing ATA commands and ATA register accesses to a device.
  11.  *
  12.  * This program is free software; you can redistribute it and/or modify it
  13.  * under the terms of the GNU General Public License as published by the
  14.  * Free Software Foundation; either version 2, or (at your option) any
  15.  * later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful, but
  18.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.  * General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License along
  23.  * with this program; if not, write to the Free Software Foundation, Inc.,
  24.  * 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  *
  26.  * History:
  27.  *
  28.  *  2001-02-24: Removed lots of duplicate code and simplified the structure.
  29.  *              (bjorn@haxx.se)
  30.  */
  31. /* Include files */
  32. #include "transport.h"
  33. #include "protocol.h"
  34. #include "usb.h"
  35. #include "debug.h"
  36. #include "scsiglue.h"
  37. #include "isd200.h"
  38. #include <linux/sched.h>
  39. #include <linux/errno.h>
  40. #include <linux/slab.h>
  41. #include <linux/hdreg.h>
  42. #include <linux/ide.h>
  43. /*
  44.  * Inquiry defines. Used to interpret data returned from target as result
  45.  * of inquiry command.
  46.  *
  47.  * DeviceType field
  48.  */
  49. #define DIRECT_ACCESS_DEVICE            0x00    /* disks */
  50. /* Timeout defines (in Seconds) */
  51. #define ISD200_ENUM_BSY_TIMEOUT         35
  52. #define ISD200_ENUM_DETECT_TIMEOUT      30
  53. #define ISD200_DEFAULT_TIMEOUT          30
  54. /* device flags */
  55. #define DF_ATA_DEVICE               0x0001
  56. #define DF_MEDIA_STATUS_ENABLED     0x0002
  57. #define DF_REMOVABLE_MEDIA          0x0004
  58. /* capability bit definitions */
  59. #define CAPABILITY_DMA 0x01
  60. #define CAPABILITY_LBA 0x02
  61. /* command_setX bit definitions */
  62. #define COMMANDSET_REMOVABLE 0x02
  63. #define COMMANDSET_MEDIA_STATUS 0x10
  64. /* ATA Vendor Specific defines */
  65. #define ATA_ADDRESS_DEVHEAD_STD      0xa0
  66. #define ATA_ADDRESS_DEVHEAD_LBA_MODE 0x40    
  67. #define ATA_ADDRESS_DEVHEAD_SLAVE    0x10
  68. /* Action Select bits */
  69. #define ACTION_SELECT_0             0x01
  70. #define ACTION_SELECT_1             0x02
  71. #define ACTION_SELECT_2             0x04
  72. #define ACTION_SELECT_3             0x08
  73. #define ACTION_SELECT_4             0x10
  74. #define ACTION_SELECT_5             0x20
  75. #define ACTION_SELECT_6             0x40
  76. #define ACTION_SELECT_7             0x80
  77. /* ATA error definitions not in <linux/hdreg.h> */
  78. #define ATA_ERROR_MEDIA_CHANGE       0x20
  79. /* ATA command definitions not in <linux/hdreg.h> */
  80. #define ATA_COMMAND_GET_MEDIA_STATUS        0xDA
  81. #define ATA_COMMAND_MEDIA_EJECT             0xED
  82. /* ATA drive control definitions */
  83. #define ATA_DC_DISABLE_INTERRUPTS    0x02
  84. #define ATA_DC_RESET_CONTROLLER      0x04
  85. #define ATA_DC_REENABLE_CONTROLLER   0x00
  86. /*
  87.  *  General purpose return codes
  88.  */ 
  89. #define ISD200_ERROR                -1
  90. #define ISD200_GOOD                 0
  91. /*
  92.  * Transport return codes
  93.  */
  94. #define ISD200_TRANSPORT_GOOD       0   /* Transport good, command good     */
  95. #define ISD200_TRANSPORT_FAILED     1   /* Transport good, command failed   */
  96. #define ISD200_TRANSPORT_ERROR      2   /* Transport bad (i.e. device dead) */
  97. #define ISD200_TRANSPORT_ABORTED    3   /* Transport aborted                */
  98. #define ISD200_TRANSPORT_SHORT      4   /* Transport short                  */
  99. /* driver action codes */
  100. #define ACTION_READ_STATUS 0
  101. #define ACTION_RESET 1
  102. #define ACTION_REENABLE 2
  103. #define ACTION_SOFT_RESET 3
  104. #define ACTION_ENUM 4
  105. #define ACTION_IDENTIFY 5
  106. /*
  107.  * ata_cdb struct
  108.  */
  109. union ata_cdb {
  110. struct {
  111. unsigned char SignatureByte0;
  112. unsigned char SignatureByte1;
  113. unsigned char ActionSelect;
  114. unsigned char RegisterSelect;
  115. unsigned char TransferBlockSize;
  116. unsigned char WriteData3F6;
  117. unsigned char WriteData1F1;
  118. unsigned char WriteData1F2;
  119. unsigned char WriteData1F3;
  120. unsigned char WriteData1F4;
  121. unsigned char WriteData1F5;
  122. unsigned char WriteData1F6;
  123. unsigned char WriteData1F7;
  124. unsigned char Reserved[3];
  125. } generic;
  126.         
  127. struct {
  128. unsigned char SignatureByte0;
  129. unsigned char SignatureByte1;
  130. unsigned char ReadRegisterAccessBit : 1;
  131. unsigned char NoDeviceSelectionBit : 1;
  132. unsigned char NoBSYPollBit : 1;
  133. unsigned char IgnorePhaseErrorBit : 1;
  134. unsigned char IgnoreDeviceErrorBit : 1;
  135. unsigned char Reserved0Bit : 3;
  136. unsigned char SelectAlternateStatus : 1;
  137. unsigned char SelectError : 1;
  138. unsigned char SelectSectorCount : 1;
  139. unsigned char SelectSectorNumber : 1;
  140. unsigned char SelectCylinderLow : 1;
  141. unsigned char SelectCylinderHigh : 1;
  142. unsigned char SelectDeviceHead : 1;
  143. unsigned char SelectStatus : 1;
  144. unsigned char TransferBlockSize;
  145. unsigned char AlternateStatusByte;
  146. unsigned char ErrorByte;
  147. unsigned char SectorCountByte;
  148. unsigned char SectorNumberByte;
  149. unsigned char CylinderLowByte;
  150. unsigned char CylinderHighByte;
  151. unsigned char DeviceHeadByte;
  152. unsigned char StatusByte;
  153. unsigned char Reserved[3];
  154. } read;
  155.         struct {
  156. unsigned char SignatureByte0;
  157. unsigned char SignatureByte1;
  158. unsigned char ReadRegisterAccessBit : 1;
  159. unsigned char NoDeviceSelectionBit : 1;
  160. unsigned char NoBSYPollBit : 1;
  161. unsigned char IgnorePhaseErrorBit : 1;
  162. unsigned char IgnoreDeviceErrorBit : 1;
  163. unsigned char Reserved0Bit : 3;
  164. unsigned char SelectDeviceControl : 1;
  165. unsigned char SelectFeatures : 1;
  166. unsigned char SelectSectorCount : 1;
  167. unsigned char SelectSectorNumber : 1;
  168. unsigned char SelectCylinderLow : 1;
  169. unsigned char SelectCylinderHigh : 1;
  170. unsigned char SelectDeviceHead : 1;
  171. unsigned char SelectCommand : 1;
  172. unsigned char TransferBlockSize;
  173. unsigned char DeviceControlByte;
  174. unsigned char FeaturesByte;
  175. unsigned char SectorCountByte;
  176. unsigned char SectorNumberByte;
  177. unsigned char CylinderLowByte;
  178. unsigned char CylinderHighByte;
  179. unsigned char DeviceHeadByte;
  180. unsigned char CommandByte;
  181. unsigned char Reserved[3];
  182. } write;
  183. };
  184. /*
  185.  * Inquiry data structure. This is the data returned from the target
  186.  * after it receives an inquiry.
  187.  *
  188.  * This structure may be extended by the number of bytes specified
  189.  * in the field AdditionalLength. The defined size constant only
  190.  * includes fields through ProductRevisionLevel.
  191.  */
  192. struct inquiry_data {
  193. unsigned char DeviceType : 5;
  194. unsigned char DeviceTypeQualifier : 3;
  195. unsigned char DeviceTypeModifier : 7;
  196. unsigned char RemovableMedia : 1;
  197. unsigned char Versions;
  198. unsigned char ResponseDataFormat : 4;
  199. unsigned char HiSupport : 1;
  200. unsigned char NormACA : 1;
  201. unsigned char ReservedBit : 1;
  202. unsigned char AERC : 1;
  203. unsigned char AdditionalLength;
  204. unsigned char Reserved[2];
  205. unsigned char SoftReset : 1;
  206. unsigned char CommandQueue : 1;
  207. unsigned char Reserved2 : 1;
  208. unsigned char LinkedCommands : 1;
  209. unsigned char Synchronous : 1;
  210. unsigned char Wide16Bit : 1;
  211. unsigned char Wide32Bit : 1;
  212. unsigned char RelativeAddressing : 1;
  213. unsigned char VendorId[8];
  214. unsigned char ProductId[16];
  215. unsigned char ProductRevisionLevel[4];
  216. unsigned char VendorSpecific[20];
  217. unsigned char Reserved3[40];
  218. } __attribute__ ((packed));
  219. /*
  220.  * INQUIRY data buffer size
  221.  */
  222. #define INQUIRYDATABUFFERSIZE 36
  223. /*
  224.  * ISD200 CONFIG data struct
  225.  */
  226. struct isd200_config {
  227.         unsigned char EventNotification;
  228.         unsigned char ExternalClock;
  229.         unsigned char ATAInitTimeout;
  230.         unsigned char ATATiming : 4;
  231.         unsigned char ATAPIReset : 1;
  232.         unsigned char MasterSlaveSelection : 1;
  233.         unsigned char ATAPICommandBlockSize : 2;
  234.         unsigned char ATAMajorCommand;
  235.         unsigned char ATAMinorCommand;
  236.         unsigned char LastLUNIdentifier : 3;
  237.         unsigned char DescriptOverride : 1;
  238.         unsigned char ATA3StateSuspend : 1;
  239.         unsigned char SkipDeviceBoot : 1;
  240.         unsigned char ConfigDescriptor2 : 1;
  241.         unsigned char InitStatus : 1;
  242.         unsigned char SRSTEnable : 1;
  243.         unsigned char Reserved0 : 7;
  244. };
  245. /*
  246.  * ISD200 driver information struct
  247.  */
  248. struct isd200_info {
  249. struct inquiry_data InquiryData;
  250. struct hd_driveid drive;
  251. struct isd200_config ConfigData;
  252. unsigned char ATARegs[8];
  253. unsigned char DeviceHead;
  254. unsigned char DeviceFlags;
  255. /* maximum number of LUNs supported */
  256. unsigned char MaxLUNs;
  257. };
  258. /*
  259.  * Read Capacity Data - returned in Big Endian format
  260.  */
  261. struct read_capacity_data {
  262. unsigned long LogicalBlockAddress;
  263. unsigned long BytesPerBlock;
  264. };
  265. /*
  266.  * Read Block Limits Data - returned in Big Endian format
  267.  * This structure returns the maximum and minimum block
  268.  * size for a TAPE device.
  269.  */
  270. struct read_block_limits {
  271. unsigned char Reserved;
  272. unsigned char BlockMaximumSize[3];
  273. unsigned char BlockMinimumSize[2];
  274. };
  275. /*
  276.  * Sense Data Format
  277.  */
  278. struct sense_data {
  279.         unsigned char ErrorCode:7;
  280.         unsigned char Valid:1;
  281.         unsigned char SegmentNumber;
  282.         unsigned char SenseKey:4;
  283.         unsigned char Reserved:1;
  284.         unsigned char IncorrectLength:1;
  285.         unsigned char EndOfMedia:1;
  286.         unsigned char FileMark:1;
  287.         unsigned char Information[4];
  288.         unsigned char AdditionalSenseLength;
  289.         unsigned char CommandSpecificInformation[4];
  290.         unsigned char AdditionalSenseCode;
  291.         unsigned char AdditionalSenseCodeQualifier;
  292.         unsigned char FieldReplaceableUnitCode;
  293.         unsigned char SenseKeySpecific[3];
  294. } __attribute__ ((packed));
  295. /*
  296.  * Default request sense buffer size
  297.  */
  298. #define SENSE_BUFFER_SIZE 18
  299. /***********************************************************************
  300.  * Helper routines
  301.  ***********************************************************************/
  302. /**************************************************************************
  303.  * isd200_build_sense
  304.  *                                                                         
  305.  *  Builds an artificial sense buffer to report the results of a 
  306.  *  failed command.
  307.  *                                                                       
  308.  * RETURNS:
  309.  *    void
  310.  */                                                                        
  311. void isd200_build_sense(struct us_data *us, Scsi_Cmnd *srb)
  312. {
  313.         struct isd200_info *info = (struct isd200_info *)us->extra;
  314.         struct sense_data *buf = (struct sense_data *) &srb->sense_buffer[0];
  315.         unsigned char error = info->ATARegs[IDE_ERROR_OFFSET];
  316. if(error & ATA_ERROR_MEDIA_CHANGE) {
  317. buf->ErrorCode = 0x70;
  318. buf->Valid     = 1;
  319. buf->AdditionalSenseLength = 0xb;
  320. buf->SenseKey =  UNIT_ATTENTION;
  321. buf->AdditionalSenseCode = 0;
  322. buf->AdditionalSenseCodeQualifier = 0;
  323.         } else if(error & MCR_ERR) {
  324. buf->ErrorCode = 0x70;
  325. buf->Valid     = 1;
  326. buf->AdditionalSenseLength = 0xb;
  327. buf->SenseKey =  UNIT_ATTENTION;
  328. buf->AdditionalSenseCode = 0;
  329. buf->AdditionalSenseCodeQualifier = 0;
  330.         } else if(error & TRK0_ERR) {
  331. buf->ErrorCode = 0x70;
  332. buf->Valid     = 1;
  333. buf->AdditionalSenseLength = 0xb;
  334. buf->SenseKey =  NOT_READY;
  335. buf->AdditionalSenseCode = 0;
  336. buf->AdditionalSenseCodeQualifier = 0;
  337.         } else if(error & ECC_ERR) {
  338. buf->ErrorCode = 0x70;
  339. buf->Valid     = 1;
  340. buf->AdditionalSenseLength = 0xb;
  341. buf->SenseKey =  DATA_PROTECT;
  342. buf->AdditionalSenseCode = 0;
  343. buf->AdditionalSenseCodeQualifier = 0;
  344.         } else {
  345. buf->ErrorCode = 0;
  346. buf->Valid     = 0;
  347. buf->AdditionalSenseLength = 0;
  348. buf->SenseKey =  0;
  349. buf->AdditionalSenseCode = 0;
  350. buf->AdditionalSenseCodeQualifier = 0;
  351.         }
  352. }
  353. /***********************************************************************
  354.  * Data transfer routines
  355.  ***********************************************************************/
  356. /**************************************************************************
  357.  * Transfer one SCSI scatter-gather buffer via bulk transfer
  358.  *
  359.  * Note that this function is necessary because we want the ability to
  360.  * use scatter-gather memory.  Good performance is achieved by a combination
  361.  * of scatter-gather and clustering (which makes each chunk bigger).
  362.  *
  363.  * Note that the lower layer will always retry when a NAK occurs, up to the
  364.  * timeout limit.  Thus we don't have to worry about it for individual
  365.  * packets.
  366.  */
  367. static int isd200_transfer_partial( struct us_data *us, 
  368.     unsigned char dataDirection,
  369.     char *buf, int length )
  370. {
  371.         int result;
  372.         int partial;
  373.         int pipe;
  374.         /* calculate the appropriate pipe information */
  375. if (dataDirection == SCSI_DATA_READ)
  376.                 pipe = usb_rcvbulkpipe(us->pusb_dev, us->ep_in);
  377.         else
  378.                 pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out);
  379.         /* transfer the data */
  380.         US_DEBUGP("isd200_transfer_partial(): xfer %d bytesn", length);
  381.         result = usb_stor_bulk_msg(us, buf, pipe, length, &partial);
  382.         US_DEBUGP("usb_stor_bulk_msg() returned %d xferred %d/%dn",
  383.                   result, partial, length);
  384.         /* if we stall, we need to clear it before we go on */
  385.         if (result == -EPIPE) {
  386.                 US_DEBUGP("clearing endpoint halt for pipe 0x%xn", pipe);
  387.                 usb_stor_clear_halt(us->pusb_dev, pipe);
  388.         }
  389.     
  390.         /* did we send all the data? */
  391.         if (partial == length) {
  392.                 US_DEBUGP("isd200_transfer_partial(): transfer completen");
  393.                 return ISD200_TRANSPORT_GOOD;
  394.         }
  395.         /* uh oh... we have an error code, so something went wrong. */
  396.         if (result) {
  397.                 /* NAK - that means we've retried a few times already */
  398.                 if (result == -ETIMEDOUT) {
  399.                         US_DEBUGP("isd200_transfer_partial(): device NAKedn");
  400.                         return ISD200_TRANSPORT_FAILED;
  401.                 }
  402.                 /* -ENOENT -- we canceled this transfer */
  403.                 if (result == -ENOENT) {
  404.                         US_DEBUGP("isd200_transfer_partial(): transfer abortedn");
  405.                         return ISD200_TRANSPORT_ABORTED;
  406.                 }
  407.                 /* the catch-all case */
  408.                 US_DEBUGP("isd200_transfer_partial(): unknown errorn");
  409.                 return ISD200_TRANSPORT_FAILED;
  410.         }
  411.         /* no error code, so we must have transferred some data, 
  412.          * just not all of it */
  413.         return ISD200_TRANSPORT_SHORT;
  414. }
  415. /**************************************************************************
  416.  * Transfer an entire SCSI command's worth of data payload over the bulk
  417.  * pipe.
  418.  *
  419.  * Note that this uses us_transfer_partial to achieve it's goals -- this
  420.  * function simply determines if we're going to use scatter-gather or not,
  421.  * and acts appropriately.  For now, it also re-interprets the error codes.
  422.  */
  423. static void isd200_transfer( struct us_data *us, Scsi_Cmnd *srb )
  424. {
  425.         int i;
  426.         int result = -1;
  427.         struct scatterlist *sg;
  428.         unsigned int total_transferred = 0;
  429.         unsigned int transfer_amount;
  430.         /* calculate how much we want to transfer */
  431. int dir = srb->sc_data_direction;
  432. srb->sc_data_direction = SCSI_DATA_WRITE;
  433.         transfer_amount = usb_stor_transfer_length(srb);
  434. srb->sc_data_direction = dir;
  435.         /* was someone foolish enough to request more data than available
  436.          * buffer space? */
  437.         if (transfer_amount > srb->request_bufflen)
  438.                 transfer_amount = srb->request_bufflen;
  439.         /* are we scatter-gathering? */
  440.         if (srb->use_sg) {
  441.                 /* loop over all the scatter gather structures and 
  442.                  * make the appropriate requests for each, until done
  443.                  */
  444.                 sg = (struct scatterlist *) srb->request_buffer;
  445.                 for (i = 0; i < srb->use_sg; i++) {
  446.                         /* transfer the lesser of the next buffer or the
  447.                          * remaining data */
  448.                         if (transfer_amount - total_transferred >= 
  449.                             sg[i].length) {
  450.                                 result = isd200_transfer_partial(us, 
  451.                                                                  srb->sc_data_direction,
  452.                                                                  sg[i].address, 
  453.                                                                  sg[i].length);
  454.                                 total_transferred += sg[i].length;
  455.                         } else
  456.                                 result = isd200_transfer_partial(us, 
  457.                                                                  srb->sc_data_direction,                            
  458.                                                                  sg[i].address,
  459.                                                                  transfer_amount - total_transferred);
  460.                         /* if we get an error, end the loop here */
  461.                         if (result)
  462.                                 break;
  463.                 }
  464.         }
  465.         else
  466.                 /* no scatter-gather, just make the request */
  467.                 result = isd200_transfer_partial(us, 
  468.                                                  srb->sc_data_direction,
  469.                                                  srb->request_buffer, 
  470.                                                  transfer_amount);
  471.         /* return the result in the data structure itself */
  472.         srb->result = result;
  473. }
  474. /***********************************************************************
  475.  * Transport routines
  476.  ***********************************************************************/
  477. /**************************************************************************
  478.  *  ISD200 Bulk Transport
  479.  *
  480.  * Note:  This routine was copied from the usb_stor_Bulk_transport routine
  481.  * located in the transport.c source file.  The scsi command is limited to
  482.  * only 12 bytes while the CDB for the ISD200 must be 16 bytes.
  483.  */
  484. int isd200_Bulk_transport( struct us_data *us, Scsi_Cmnd *srb, 
  485.                            union ata_cdb *AtaCdb, unsigned char AtaCdbLength )
  486. {
  487.         struct bulk_cb_wrap bcb;
  488.         struct bulk_cs_wrap bcs;
  489.         int result;
  490.         int pipe;
  491.         int partial;
  492.         unsigned int transfer_amount;
  493. int dir = srb->sc_data_direction;
  494. srb->sc_data_direction = SCSI_DATA_WRITE;
  495.         transfer_amount = usb_stor_transfer_length(srb);
  496. srb->sc_data_direction = dir;
  497.     
  498.         /* set up the command wrapper */
  499.         bcb.Signature = cpu_to_le32(US_BULK_CB_SIGN);
  500.         bcb.DataTransferLength = cpu_to_le32(transfer_amount);
  501.         bcb.Flags = srb->sc_data_direction == SCSI_DATA_READ ? 1 << 7 : 0;
  502.         bcb.Tag = srb->serial_number;
  503.         bcb.Lun = srb->cmnd[1] >> 5;
  504.         if (us->flags & US_FL_SCM_MULT_TARG)
  505.                 bcb.Lun |= srb->target << 4;
  506.         bcb.Length = AtaCdbLength;
  507.     
  508.         /* construct the pipe handle */
  509.         pipe = usb_sndbulkpipe(us->pusb_dev, us->ep_out);
  510.     
  511.         /* copy the command payload */
  512.         memset(bcb.CDB, 0, sizeof(bcb.CDB));
  513.         memcpy(bcb.CDB, AtaCdb, bcb.Length);
  514.     
  515.         /* send it to out endpoint */
  516.         US_DEBUGP("Bulk command S 0x%x T 0x%x Trg %d LUN %d L %d F %d CL %dn",
  517.                   le32_to_cpu(bcb.Signature), bcb.Tag,
  518.                   (bcb.Lun >> 4), (bcb.Lun & 0xFF), 
  519.                   bcb.DataTransferLength, bcb.Flags, bcb.Length);
  520.         result = usb_stor_bulk_msg(us, &bcb, pipe, US_BULK_CB_WRAP_LEN, 
  521.    &partial);
  522.         US_DEBUGP("Bulk command transfer result=%dn", result);
  523.     
  524. if (result == -ENOENT)
  525. return ISD200_TRANSPORT_ABORTED;
  526. else if (result == -EPIPE) {
  527. /* if we stall, we need to clear it before we go on */
  528.                 US_DEBUGP("clearing endpoint halt for pipe 0x%xn", pipe);
  529.                 usb_stor_clear_halt(us->pusb_dev, pipe);
  530. } else if (result)  
  531.                 return ISD200_TRANSPORT_ERROR;
  532.     
  533.         /* if the command transfered well, then we go to the data stage */
  534.         if (!result && bcb.DataTransferLength) {
  535. isd200_transfer(us, srb);
  536. US_DEBUGP("Bulk data transfer result 0x%xn", srb->result);
  537. if (srb->result == ISD200_TRANSPORT_ABORTED)
  538. return ISD200_TRANSPORT_ABORTED;
  539.         }
  540.     
  541.         /* See flow chart on pg 15 of the Bulk Only Transport spec for
  542.          * an explanation of how this code works.
  543.          */
  544.     
  545.         /* construct the pipe handle */
  546.         pipe = usb_rcvbulkpipe(us->pusb_dev, us->ep_in);
  547.     
  548.         /* get CSW for device status */
  549.         US_DEBUGP("Attempting to get CSW...n");
  550.         result = usb_stor_bulk_msg(us, &bcs, pipe, US_BULK_CS_WRAP_LEN, 
  551.    &partial);
  552.         if (result == -ENOENT)
  553.                 return ISD200_TRANSPORT_ABORTED;
  554.         /* did the attempt to read the CSW fail? */
  555.         if (result == -EPIPE) {
  556.                 US_DEBUGP("clearing endpoint halt for pipe 0x%xn", pipe);
  557.                 usb_stor_clear_halt(us->pusb_dev, pipe);
  558.            
  559.                 /* get the status again */
  560.                 US_DEBUGP("Attempting to get CSW (2nd try)...n");
  561.                 result = usb_stor_bulk_msg(us, &bcs, pipe,
  562.                                            US_BULK_CS_WRAP_LEN, &partial);
  563.                 /* if the command was aborted, indicate that */
  564.                 if (result == -ENOENT)
  565.                         return ISD200_TRANSPORT_ABORTED;
  566.         
  567.                 /* if it fails again, we need a reset and return an error*/
  568.                 if (result == -EPIPE) {
  569.                         US_DEBUGP("clearing halt for pipe 0x%xn", pipe);
  570.                         usb_stor_clear_halt(us->pusb_dev, pipe);
  571.                         return ISD200_TRANSPORT_ERROR;
  572.                 }
  573.         }
  574.     
  575.         /* if we still have a failure at this point, we're in trouble */
  576.         US_DEBUGP("Bulk status result = %dn", result);
  577.         if (result)
  578.                 return ISD200_TRANSPORT_ERROR;
  579.     
  580.         /* check bulk status */
  581.         US_DEBUGP("Bulk status Sig 0x%x T 0x%x R %d Stat 0x%xn",
  582.                   le32_to_cpu(bcs.Signature), bcs.Tag, 
  583.                   bcs.Residue, bcs.Status);
  584.         if (bcs.Signature != cpu_to_le32(US_BULK_CS_SIGN) || 
  585.             bcs.Tag != bcb.Tag || 
  586.             bcs.Status > US_BULK_STAT_PHASE || partial != 13) {
  587.                 US_DEBUGP("Bulk logical errorn");
  588.                 return ISD200_TRANSPORT_ERROR;
  589.         }
  590.     
  591.         /* based on the status code, we report good or bad */
  592.         switch (bcs.Status) {
  593.         case US_BULK_STAT_OK:
  594.                 /* command good -- note that we could be short on data */
  595.                 return ISD200_TRANSPORT_GOOD;
  596.         case US_BULK_STAT_FAIL:
  597.                 /* command failed */
  598.                 return ISD200_TRANSPORT_FAILED;
  599.         
  600.         case US_BULK_STAT_PHASE:
  601.                 /* phase error */
  602.                 usb_stor_Bulk_reset(us);
  603.                 return ISD200_TRANSPORT_ERROR;
  604.         }
  605.     
  606.         /* we should never get here, but if we do, we're in trouble */
  607.         return ISD200_TRANSPORT_ERROR;
  608. }
  609. /**************************************************************************
  610.  *  isd200_action
  611.  *
  612.  * Routine for sending commands to the isd200
  613.  *
  614.  * RETURNS:
  615.  *    ISD status code
  616.  */
  617. static int isd200_action( struct us_data *us, int action, 
  618.   void* pointer, int value )
  619. {
  620. union ata_cdb ata;
  621. struct scsi_cmnd srb;
  622. struct isd200_info *info = (struct isd200_info *)us->extra;
  623. int status;
  624. memset(&ata, 0, sizeof(ata));
  625. memset(&srb, 0, sizeof(srb));
  626. ata.generic.SignatureByte0 = info->ConfigData.ATAMajorCommand;
  627. ata.generic.SignatureByte1 = info->ConfigData.ATAMinorCommand;
  628. ata.generic.TransferBlockSize = 1;
  629. switch ( action ) {
  630. case ACTION_READ_STATUS:
  631. US_DEBUGP("   isd200_action(READ_STATUS)n");
  632. ata.generic.ActionSelect = ACTION_SELECT_0|ACTION_SELECT_2;
  633. ata.read.SelectStatus = 1;
  634. ata.read.SelectError = 1;
  635. ata.read.SelectCylinderHigh = 1;
  636. ata.read.SelectCylinderLow = 1;
  637. srb.sc_data_direction = SCSI_DATA_READ;
  638. srb.request_buffer = pointer;
  639. srb.request_bufflen = value;
  640. break;
  641. case ACTION_ENUM:
  642. US_DEBUGP("   isd200_action(ENUM,0x%02x)n",value);
  643. ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_2|
  644.                    ACTION_SELECT_3|ACTION_SELECT_4|
  645.                            ACTION_SELECT_5;
  646. ata.write.SelectDeviceHead = 1;
  647. ata.write.DeviceHeadByte = value;
  648. srb.sc_data_direction = SCSI_DATA_NONE;
  649. break;
  650. case ACTION_RESET:
  651. US_DEBUGP("   isd200_action(RESET)n");
  652. ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_2|
  653.                    ACTION_SELECT_3|ACTION_SELECT_4;
  654. ata.write.SelectDeviceControl = 1;
  655. ata.write.DeviceControlByte = ATA_DC_RESET_CONTROLLER;
  656. srb.sc_data_direction = SCSI_DATA_NONE;
  657. break;
  658. case ACTION_REENABLE:
  659. US_DEBUGP("   isd200_action(REENABLE)n");
  660. ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_2|
  661.                    ACTION_SELECT_3|ACTION_SELECT_4;
  662. ata.write.SelectDeviceControl = 1;
  663. ata.write.DeviceControlByte = ATA_DC_REENABLE_CONTROLLER;
  664. srb.sc_data_direction = SCSI_DATA_NONE;
  665. break;
  666. case ACTION_SOFT_RESET:
  667. US_DEBUGP("   isd200_action(SOFT_RESET)n");
  668. ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_5;
  669. ata.write.SelectDeviceHead = 1;
  670. ata.write.DeviceHeadByte = info->DeviceHead;
  671. ata.write.SelectCommand = 1;
  672. ata.write.CommandByte = WIN_SRST;
  673. srb.sc_data_direction = SCSI_DATA_NONE;
  674. break;
  675. case ACTION_IDENTIFY:
  676. US_DEBUGP("   isd200_action(IDENTIFY)n");
  677. ata.write.SelectCommand = 1;
  678. ata.write.CommandByte = WIN_IDENTIFY;
  679. srb.sc_data_direction = SCSI_DATA_READ;
  680. srb.request_buffer = (void *)&info->drive;
  681. srb.request_bufflen = sizeof(struct hd_driveid);
  682. break;
  683. default:
  684. US_DEBUGP("Error: Undefined action %dn",action);
  685. break;
  686. }
  687. status = isd200_Bulk_transport(us, &srb, &ata, sizeof(ata.generic));
  688. if (status != ISD200_TRANSPORT_GOOD) {
  689. US_DEBUGP("   isd200_action(0x%02x) error: %dn",action,status);
  690. status = ISD200_ERROR;
  691. /* need to reset device here */
  692. }
  693. return status;
  694. }
  695. /**************************************************************************
  696.  * isd200_read_regs
  697.  *                                                                         
  698.  * Read ATA Registers
  699.  *
  700.  * RETURNS:
  701.  *    ISD status code
  702.  */                                                                        
  703. int isd200_read_regs( struct us_data *us )
  704. {
  705. struct isd200_info *info = (struct isd200_info *)us->extra;
  706. int retStatus = ISD200_GOOD;
  707. int transferStatus;
  708. US_DEBUGP("Entering isd200_IssueATAReadRegsn");
  709. transferStatus = isd200_action( us, ACTION_READ_STATUS,
  710.     info->ATARegs, sizeof(info->ATARegs) );
  711. if (transferStatus != ISD200_TRANSPORT_GOOD) {
  712. US_DEBUGP("   Error reading ATA registersn");
  713. retStatus = ISD200_ERROR;
  714.         } else {
  715. US_DEBUGP("   Got ATA Register[IDE_ERROR_OFFSET] = 0x%xn", 
  716.   info->ATARegs[IDE_ERROR_OFFSET]);
  717.         }
  718. return retStatus;
  719. }
  720. /**************************************************************************
  721.  * Invoke the transport and basic error-handling/recovery methods
  722.  *
  723.  * This is used by the protocol layers to actually send the message to
  724.  * the device and recieve the response.
  725.  */
  726. void isd200_invoke_transport( struct us_data *us, 
  727.       Scsi_Cmnd *srb, 
  728.       union ata_cdb *ataCdb )
  729. {
  730. int need_auto_sense = 0;
  731. int transferStatus;
  732. /* send the command to the transport layer */
  733. transferStatus = isd200_Bulk_transport(us, srb, ataCdb,
  734.        sizeof(ataCdb->generic));
  735. switch (transferStatus) {
  736. case ISD200_TRANSPORT_GOOD:
  737. /* Indicate a good result */
  738. srb->result = GOOD;
  739. break;
  740. case ISD200_TRANSPORT_ABORTED:
  741. /* if the command gets aborted by the higher layers, we need to
  742.  * short-circuit all other processing
  743.  */
  744. US_DEBUGP("-- transport indicates command was abortedn");
  745. srb->result = DID_ABORT << 16;
  746. break;
  747. case ISD200_TRANSPORT_FAILED:
  748. US_DEBUGP("-- transport indicates command failuren");
  749. need_auto_sense = 1;
  750. break;
  751. case ISD200_TRANSPORT_ERROR:
  752. US_DEBUGP("-- transport indicates transport failuren");
  753. srb->result = DID_ERROR << 16;
  754. break;
  755. case ISD200_TRANSPORT_SHORT:
  756. if (!((srb->cmnd[0] == REQUEST_SENSE) ||
  757.       (srb->cmnd[0] == INQUIRY) ||
  758.       (srb->cmnd[0] == MODE_SENSE) ||
  759.       (srb->cmnd[0] == LOG_SENSE) ||
  760.       (srb->cmnd[0] == MODE_SENSE_10))) {
  761. US_DEBUGP("-- unexpectedly short transfern");
  762. need_auto_sense = 1;
  763. }
  764. break;
  765.     
  766. default:
  767. US_DEBUGP("-- transport indicates unknown failuren");   
  768. srb->result = DID_ERROR << 16;
  769.        
  770. }
  771. if (need_auto_sense)
  772. if (isd200_read_regs(us) == ISD200_GOOD)
  773. isd200_build_sense(us, srb);
  774. /* Regardless of auto-sense, if we _know_ we have an error
  775.  * condition, show that in the result code
  776.  */
  777. if (transferStatus == ISD200_TRANSPORT_FAILED)
  778. srb->result = CHECK_CONDITION;
  779. }
  780. /**************************************************************************
  781.  * isd200_write_config
  782.  *                                                                         
  783.  * Write the ISD200 Configuraton data
  784.  *
  785.  * RETURNS:
  786.  *    ISD status code
  787.  */                                                                        
  788. int isd200_write_config( struct us_data *us ) 
  789. {
  790. struct isd200_info *info = (struct isd200_info *)us->extra;
  791. int retStatus = ISD200_GOOD;
  792. int result;
  793. US_DEBUGP("Entering isd200_write_confign");
  794. US_DEBUGP("   Writing the following ISD200 Config Data:n");
  795. US_DEBUGP("      Event Notification: 0x%xn", info->ConfigData.EventNotification);
  796. US_DEBUGP("      External Clock: 0x%xn", info->ConfigData.ExternalClock);
  797. US_DEBUGP("      ATA Init Timeout: 0x%xn", info->ConfigData.ATAInitTimeout);
  798. US_DEBUGP("      ATAPI Command Block Size: 0x%xn", info->ConfigData.ATAPICommandBlockSize);
  799. US_DEBUGP("      Master/Slave Selection: 0x%xn", info->ConfigData.MasterSlaveSelection);
  800. US_DEBUGP("      ATAPI Reset: 0x%xn", info->ConfigData.ATAPIReset);
  801. US_DEBUGP("      ATA Timing: 0x%xn", info->ConfigData.ATATiming);
  802. US_DEBUGP("      ATA Major Command: 0x%xn", info->ConfigData.ATAMajorCommand);
  803. US_DEBUGP("      ATA Minor Command: 0x%xn", info->ConfigData.ATAMinorCommand);
  804. US_DEBUGP("      Init Status: 0x%xn", info->ConfigData.InitStatus);
  805. US_DEBUGP("      Config Descriptor 2: 0x%xn", info->ConfigData.ConfigDescriptor2);
  806. US_DEBUGP("      Skip Device Boot: 0x%xn", info->ConfigData.SkipDeviceBoot);
  807. US_DEBUGP("      ATA 3 State Supsend: 0x%xn", info->ConfigData.ATA3StateSuspend);
  808. US_DEBUGP("      Descriptor Override: 0x%xn", info->ConfigData.DescriptOverride);
  809. US_DEBUGP("      Last LUN Identifier: 0x%xn", info->ConfigData.LastLUNIdentifier);
  810. US_DEBUGP("      SRST Enable: 0x%xn", info->ConfigData.SRSTEnable);
  811. /* let's send the command via the control pipe */
  812. result = usb_stor_control_msg(
  813.                 us, 
  814.                 usb_sndctrlpipe(us->pusb_dev,0),
  815.                 0x01, 
  816.                 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  817.                 0x0000, 
  818.                 0x0002, 
  819.                 (void *) &info->ConfigData, 
  820.                 sizeof(info->ConfigData));
  821. if (result >= 0) {
  822. US_DEBUGP("   ISD200 Config Data was written successfullyn");
  823.         } else {
  824. US_DEBUGP("   Request to write ISD200 Config Data failed!n");
  825. /* STALL must be cleared when they are detected */
  826. if (result == -EPIPE) {
  827. US_DEBUGP("-- Stall on control pipe. Clearingn");
  828. result = usb_stor_clear_halt(us->pusb_dev,
  829.      usb_sndctrlpipe(us->pusb_dev, 0));
  830. US_DEBUGP("-- usb_stor_clear_halt() returns %dn", result);
  831. }
  832. retStatus = ISD200_ERROR;
  833.         }
  834. US_DEBUGP("Leaving isd200_write_config %08Xn", retStatus);
  835. return retStatus;
  836. }
  837. /**************************************************************************
  838.  * isd200_read_config
  839.  *                                                                         
  840.  * Reads the ISD200 Configuraton data
  841.  *
  842.  * RETURNS:
  843.  *    ISD status code
  844.  */                                                                        
  845. int isd200_read_config( struct us_data *us ) 
  846. {
  847. struct isd200_info *info = (struct isd200_info *)us->extra;
  848. int retStatus = ISD200_GOOD;
  849. int result;
  850. US_DEBUGP("Entering isd200_read_confign");
  851. /* read the configuration information from ISD200.  Use this to */
  852. /* determine what the special ATA CDB bytes are.                */
  853. result = usb_stor_control_msg(
  854.                 us, 
  855.                 usb_rcvctrlpipe(us->pusb_dev,0),
  856.                 0x02, 
  857.                 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  858.                 0x0000, 
  859.                 0x0002, 
  860.                 (void *) &info->ConfigData, 
  861.                 sizeof(info->ConfigData));
  862. if (result >= 0) {
  863. US_DEBUGP("   Retrieved the following ISD200 Config Data:n");
  864. US_DEBUGP("      Event Notification: 0x%xn", info->ConfigData.EventNotification);
  865. US_DEBUGP("      External Clock: 0x%xn", info->ConfigData.ExternalClock);
  866. US_DEBUGP("      ATA Init Timeout: 0x%xn", info->ConfigData.ATAInitTimeout);
  867. US_DEBUGP("      ATAPI Command Block Size: 0x%xn", info->ConfigData.ATAPICommandBlockSize);
  868. US_DEBUGP("      Master/Slave Selection: 0x%xn", info->ConfigData.MasterSlaveSelection);
  869. US_DEBUGP("      ATAPI Reset: 0x%xn", info->ConfigData.ATAPIReset);
  870. US_DEBUGP("      ATA Timing: 0x%xn", info->ConfigData.ATATiming);
  871. US_DEBUGP("      ATA Major Command: 0x%xn", info->ConfigData.ATAMajorCommand);
  872. US_DEBUGP("      ATA Minor Command: 0x%xn", info->ConfigData.ATAMinorCommand);
  873. US_DEBUGP("      Init Status: 0x%xn", info->ConfigData.InitStatus);
  874. US_DEBUGP("      Config Descriptor 2: 0x%xn", info->ConfigData.ConfigDescriptor2);
  875. US_DEBUGP("      Skip Device Boot: 0x%xn", info->ConfigData.SkipDeviceBoot);
  876. US_DEBUGP("      ATA 3 State Supsend: 0x%xn", info->ConfigData.ATA3StateSuspend);
  877. US_DEBUGP("      Descriptor Override: 0x%xn", info->ConfigData.DescriptOverride);
  878. US_DEBUGP("      Last LUN Identifier: 0x%xn", info->ConfigData.LastLUNIdentifier);
  879. US_DEBUGP("      SRST Enable: 0x%xn", info->ConfigData.SRSTEnable);
  880.         } else {
  881. US_DEBUGP("   Request to get ISD200 Config Data failed!n");
  882. /* STALL must be cleared when they are detected */
  883. if (result == -EPIPE) {
  884. US_DEBUGP("-- Stall on control pipe. Clearingn");
  885. result = usb_stor_clear_halt(us->pusb_dev,   
  886.      usb_sndctrlpipe(us->pusb_dev, 0));
  887. US_DEBUGP("-- usb_stor_clear_halt() returns %dn", result);
  888. }
  889. retStatus = ISD200_ERROR;
  890.         }
  891. US_DEBUGP("Leaving isd200_read_config %08Xn", retStatus);
  892. return retStatus;
  893. }
  894. /**************************************************************************
  895.  * isd200_atapi_soft_reset
  896.  *                                                                         
  897.  * Perform an Atapi Soft Reset on the device
  898.  *
  899.  * RETURNS:
  900.  *    NT status code
  901.  */                                                                        
  902. int isd200_atapi_soft_reset( struct us_data *us ) 
  903. {
  904. int retStatus = ISD200_GOOD;
  905. int transferStatus;
  906. US_DEBUGP("Entering isd200_atapi_soft_resetn");
  907. transferStatus = isd200_action( us, ACTION_SOFT_RESET, NULL, 0 );
  908. if (transferStatus != ISD200_TRANSPORT_GOOD) {
  909. US_DEBUGP("   Error issuing Atapi Soft Resetn");
  910. retStatus = ISD200_ERROR;
  911.         }
  912. US_DEBUGP("Leaving isd200_atapi_soft_reset %08Xn", retStatus);
  913. return retStatus;
  914. }
  915. /**************************************************************************
  916.  * isd200_srst
  917.  *                                                                         
  918.  * Perform an SRST on the device
  919.  *
  920.  * RETURNS:
  921.  *    ISD status code
  922.  */                                                                        
  923. int isd200_srst( struct us_data *us ) 
  924. {
  925. int retStatus = ISD200_GOOD;
  926. int transferStatus;
  927. US_DEBUGP("Entering isd200_SRSTn");
  928. transferStatus = isd200_action( us, ACTION_RESET, NULL, 0 );
  929. /* check to see if this request failed */
  930. if (transferStatus != ISD200_TRANSPORT_GOOD) {
  931. US_DEBUGP("   Error issuing SRSTn");
  932. retStatus = ISD200_ERROR;
  933.         } else {
  934. /* delay 10ms to give the drive a chance to see it */
  935. wait_ms(10);
  936. transferStatus = isd200_action( us, ACTION_REENABLE, NULL, 0 );
  937. if (transferStatus != ISD200_TRANSPORT_GOOD) {
  938. US_DEBUGP("   Error taking drive out of resetn");
  939. retStatus = ISD200_ERROR;
  940. } else {
  941. /* delay 50ms to give the drive a chance to recover after SRST */
  942. wait_ms(50);
  943. }
  944.         }
  945. US_DEBUGP("Leaving isd200_srst %08Xn", retStatus);
  946. return retStatus;
  947. }
  948. /**************************************************************************
  949.  * isd200_try_enum
  950.  *                                                                         
  951.  * Helper function for isd200_manual_enum(). Does ENUM and READ_STATUS
  952.  * and tries to analyze the status registers
  953.  *
  954.  * RETURNS:
  955.  *    ISD status code
  956.  */                                                                        
  957. static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
  958.    int detect )
  959. {
  960. int status = ISD200_GOOD;
  961. unsigned char regs[8];
  962. unsigned long endTime;
  963. struct isd200_info *info = (struct isd200_info *)us->extra;
  964. int recheckAsMaster = FALSE;
  965. if ( detect )
  966. endTime = jiffies + ISD200_ENUM_DETECT_TIMEOUT * HZ;
  967. else
  968. endTime = jiffies + ISD200_ENUM_BSY_TIMEOUT * HZ;
  969. /* loop until we detect !BSY or timeout */
  970. while(TRUE) {
  971. #ifdef CONFIG_USB_STORAGE_DEBUG
  972. char* mstr = master_slave == ATA_ADDRESS_DEVHEAD_STD ?
  973. "Master" : "Slave";
  974. #endif
  975. status = isd200_action( us, ACTION_ENUM, NULL, master_slave );
  976. if ( status != ISD200_GOOD )
  977. break;
  978. status = isd200_action( us, ACTION_READ_STATUS, 
  979. regs, sizeof(regs) );
  980. if ( status != ISD200_GOOD )
  981. break;
  982. if (!detect) {
  983. if (regs[IDE_STATUS_OFFSET] & BUSY_STAT ) {
  984. US_DEBUGP("   %s status is still BSY, try again...n",mstr);
  985. } else {
  986. US_DEBUGP("   %s status !BSY, continue with next operationn",mstr);
  987. break;
  988. }
  989. }
  990. /* check for BUSY_STAT and */
  991. /* WRERR_STAT (workaround ATA Zip drive) and */ 
  992. /* ERR_STAT (workaround for Archos CD-ROM) */
  993. else if (regs[IDE_STATUS_OFFSET] & 
  994.  (BUSY_STAT | WRERR_STAT | ERR_STAT )) {
  995. US_DEBUGP("   Status indicates it is not ready, try again...n");
  996. }
  997. /* check for DRDY, ATA devices set DRDY after SRST */
  998. else if (regs[IDE_STATUS_OFFSET] & READY_STAT) {
  999. US_DEBUGP("   Identified ATA devicen");
  1000. info->DeviceFlags |= DF_ATA_DEVICE;
  1001. info->DeviceHead = master_slave;
  1002. break;
  1003. /* check Cylinder High/Low to
  1004.    determine if it is an ATAPI device
  1005. */
  1006. else if ((regs[IDE_HCYL_OFFSET] == 0xEB) &&
  1007.  (regs[IDE_LCYL_OFFSET] == 0x14)) {
  1008. /* It seems that the RICOH 
  1009.    MP6200A CD/RW drive will 
  1010.    report itself okay as a
  1011.    slave when it is really a
  1012.    master. So this check again
  1013.    as a master device just to
  1014.    make sure it doesn't report
  1015.    itself okay as a master also
  1016. */
  1017. if ((master_slave & ATA_ADDRESS_DEVHEAD_SLAVE) &&
  1018.     (recheckAsMaster == FALSE)) {
  1019. US_DEBUGP("   Identified ATAPI device as slave.  Rechecking again as mastern");
  1020. recheckAsMaster = TRUE;
  1021. master_slave = ATA_ADDRESS_DEVHEAD_STD;
  1022. } else {
  1023. US_DEBUGP("   Identified ATAPI devicen");
  1024. info->DeviceHead = master_slave;
  1025.       
  1026. status = isd200_atapi_soft_reset(us);
  1027. break;
  1028. }
  1029. } else {
  1030. US_DEBUGP("   Not ATA, not ATAPI. Weird.n");
  1031. }
  1032. /* check for timeout on this request */
  1033. if (jiffies >= endTime) {
  1034. if (!detect)
  1035. US_DEBUGP("   BSY check timeout, just continue with next operation...n");
  1036. else
  1037. US_DEBUGP("   Device detect timeout!n");
  1038. break;
  1039. }
  1040. }
  1041. return status;
  1042. }
  1043. /**************************************************************************
  1044.  * isd200_manual_enum
  1045.  *                                                                         
  1046.  * Determines if the drive attached is an ATA or ATAPI and if it is a
  1047.  * master or slave.
  1048.  *
  1049.  * RETURNS:
  1050.  *    ISD status code
  1051.  */                                                                        
  1052. int isd200_manual_enum(struct us_data *us)
  1053. {
  1054. struct isd200_info *info = (struct isd200_info *)us->extra;
  1055. int retStatus = ISD200_GOOD;
  1056. US_DEBUGP("Entering isd200_manual_enumn");
  1057. retStatus = isd200_read_config(us);
  1058. if (retStatus == ISD200_GOOD) {
  1059. int isslave;
  1060. /* master or slave? */
  1061. retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_STD, FALSE );
  1062. if (retStatus == ISD200_GOOD)
  1063. retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_SLAVE, FALSE );
  1064. if (retStatus == ISD200_GOOD) {
  1065. retStatus = isd200_srst(us);
  1066. if (retStatus == ISD200_GOOD)
  1067. /* ata or atapi? */
  1068. retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_STD, TRUE );
  1069. }
  1070. isslave = (info->DeviceHead & ATA_ADDRESS_DEVHEAD_SLAVE) ? 1 : 0;
  1071. if (info->ConfigData.MasterSlaveSelection != isslave) {
  1072. US_DEBUGP("   Setting Master/Slave selection to %dn", isslave);
  1073. info->ConfigData.MasterSlaveSelection = isslave;
  1074. retStatus = isd200_write_config(us);
  1075. }
  1076. }
  1077. US_DEBUGP("Leaving isd200_manual_enum %08Xn", retStatus);
  1078. return(retStatus);
  1079. }
  1080. /**************************************************************************
  1081.  * isd200_get_inquiry_data
  1082.  *
  1083.  * Get inquiry data
  1084.  *
  1085.  * RETURNS:
  1086.  *    ISD status code
  1087.  */
  1088. int isd200_get_inquiry_data( struct us_data *us )
  1089. {
  1090. struct isd200_info *info = (struct isd200_info *)us->extra;
  1091. int retStatus = ISD200_GOOD;
  1092. US_DEBUGP("Entering isd200_get_inquiry_datan");
  1093. /* set default to Master */
  1094. info->DeviceHead = ATA_ADDRESS_DEVHEAD_STD;
  1095. /* attempt to manually enumerate this device */
  1096. retStatus = isd200_manual_enum(us);
  1097. if (retStatus == ISD200_GOOD) {
  1098. int transferStatus;
  1099. /* check for an ATA device */
  1100. if (info->DeviceFlags & DF_ATA_DEVICE) {
  1101. /* this must be an ATA device */
  1102. /* perform an ATA Commmand Identify */
  1103. transferStatus = isd200_action( us, ACTION_IDENTIFY,
  1104. &info->drive, 
  1105. sizeof(struct hd_driveid) );
  1106. if (transferStatus != ISD200_TRANSPORT_GOOD) {
  1107. /* Error issuing ATA Command Identify */
  1108. US_DEBUGP("   Error issuing ATA Command Identifyn");
  1109. retStatus = ISD200_ERROR;
  1110. } else {
  1111. /* ATA Command Identify successful */
  1112. int i;
  1113. US_DEBUGP("   Identify Data Structure:n");
  1114. US_DEBUGP("      config = 0x%xn", info->drive.config);
  1115. US_DEBUGP("      cyls = 0x%xn", info->drive.cyls);
  1116. US_DEBUGP("      heads = 0x%xn", info->drive.heads);
  1117. US_DEBUGP("      track_bytes = 0x%xn", info->drive.track_bytes);
  1118. US_DEBUGP("      sector_bytes = 0x%xn", info->drive.sector_bytes);
  1119. US_DEBUGP("      sectors = 0x%xn", info->drive.sectors);
  1120. US_DEBUGP("      serial_no[0] = 0x%xn", info->drive.serial_no[0]);
  1121. US_DEBUGP("      buf_type = 0x%xn", info->drive.buf_type);
  1122. US_DEBUGP("      buf_size = 0x%xn", info->drive.buf_size);
  1123. US_DEBUGP("      ecc_bytes = 0x%xn", info->drive.ecc_bytes);
  1124. US_DEBUGP("      fw_rev[0] = 0x%xn", info->drive.fw_rev[0]);
  1125. US_DEBUGP("      model[0] = 0x%xn", info->drive.model[0]);
  1126. US_DEBUGP("      max_multsect = 0x%xn", info->drive.max_multsect);
  1127. US_DEBUGP("      dword_io = 0x%xn", info->drive.dword_io);
  1128. US_DEBUGP("      capability = 0x%xn", info->drive.capability);
  1129. US_DEBUGP("      tPIO = 0x%xn", info->drive.tPIO);
  1130. US_DEBUGP("      tDMA = 0x%xn", info->drive.tDMA);
  1131. US_DEBUGP("      field_valid = 0x%xn", info->drive.field_valid);
  1132. US_DEBUGP("      cur_cyls = 0x%xn", info->drive.cur_cyls);
  1133. US_DEBUGP("      cur_heads = 0x%xn", info->drive.cur_heads);
  1134. US_DEBUGP("      cur_sectors = 0x%xn", info->drive.cur_sectors);
  1135. US_DEBUGP("      cur_capacity = 0x%xn", (info->drive.cur_capacity1 << 16) + info->drive.cur_capacity0 );
  1136. US_DEBUGP("      multsect = 0x%xn", info->drive.multsect);
  1137. US_DEBUGP("      lba_capacity = 0x%xn", info->drive.lba_capacity);
  1138. US_DEBUGP("      command_set_1 = 0x%xn", info->drive.command_set_1);
  1139. US_DEBUGP("      command_set_2 = 0x%xn", info->drive.command_set_2);
  1140. memset(&info->InquiryData, 0, sizeof(info->InquiryData));
  1141. /* Standard IDE interface only supports disks */
  1142. info->InquiryData.DeviceType = DIRECT_ACCESS_DEVICE;
  1143. /* Fix-up the return data from an INQUIRY command to show 
  1144.  * ANSI SCSI rev 2 so we don't confuse the SCSI layers above us
  1145.  * in Linux.
  1146.  */
  1147. info->InquiryData.Versions = 0x2;
  1148. /* The length must be at least 36 (5 + 31) */
  1149. info->InquiryData.AdditionalLength = 0x1F;
  1150. if (info->drive.command_set_1 & COMMANDSET_MEDIA_STATUS) {
  1151. /* set the removable bit */
  1152. info->InquiryData.RemovableMedia = 1;
  1153. info->DeviceFlags |= DF_REMOVABLE_MEDIA;
  1154. }
  1155. /* Fill in vendor identification fields */
  1156. for (i = 0; i < 20; i += 2) {
  1157. info->InquiryData.VendorId[i] = 
  1158. info->drive.model[i + 1];
  1159. info->InquiryData.VendorId[i+1] = 
  1160. info->drive.model[i];
  1161. }
  1162. /* Initialize unused portion of product id */
  1163. for (i = 0; i < 4; i++) {
  1164. info->InquiryData.ProductId[12+i] = ' ';
  1165. }
  1166. /* Move firmware revision from IDENTIFY data to */
  1167. /* product revision in INQUIRY data             */
  1168. for (i = 0; i < 4; i += 2) {
  1169. info->InquiryData.ProductRevisionLevel[i] =
  1170. info->drive.fw_rev[i+1];
  1171. info->InquiryData.ProductRevisionLevel[i+1] =
  1172. info->drive.fw_rev[i];
  1173. }
  1174. /* determine if it supports Media Status Notification */
  1175. if (info->drive.command_set_2 & COMMANDSET_MEDIA_STATUS) {
  1176. US_DEBUGP("   Device supports Media Status Notificationn");
  1177. /* Indicate that it is enabled, even though it is not
  1178.  * This allows the lock/unlock of the media to work
  1179.  * correctly.
  1180.  */
  1181. info->DeviceFlags |= DF_MEDIA_STATUS_ENABLED;
  1182. }
  1183. else
  1184. info->DeviceFlags &= ~DF_MEDIA_STATUS_ENABLED;
  1185. }
  1186. } else {
  1187. /* 
  1188.  * this must be an ATAPI device 
  1189.  * use an ATAPI protocol (Transparent SCSI)
  1190.  */
  1191. us->protocol_name = "Transparent SCSI";
  1192. us->proto_handler = usb_stor_transparent_scsi_command;
  1193. US_DEBUGP("Protocol changed to: %sn", us->protocol_name);
  1194.             
  1195. /* Free driver structure */            
  1196. if (us->extra != NULL) {
  1197. kfree(us->extra);
  1198. us->extra = NULL;
  1199. us->extra_destructor = NULL;
  1200. }
  1201. }
  1202.         }
  1203. US_DEBUGP("Leaving isd200_get_inquiry_data %08Xn", retStatus);
  1204. return(retStatus);
  1205. }
  1206. /**************************************************************************
  1207.  * isd200_data_copy
  1208.  *                                                                         
  1209.  * Copy data into the srb request buffer.  Use scatter gather if required.
  1210.  *
  1211.  * RETURNS:
  1212.  *    void
  1213.  */                                                                        
  1214. void isd200_data_copy(Scsi_Cmnd *srb, char * src, int length)
  1215. {
  1216. unsigned int len = length;
  1217. struct scatterlist *sg;
  1218. if (srb->use_sg) {
  1219. int i;
  1220. unsigned int total = 0;
  1221. /* Add up the sizes of all the sg segments */
  1222. sg = (struct scatterlist *) srb->request_buffer;
  1223. for (i = 0; i < srb->use_sg; i++)
  1224. total += sg[i].length;
  1225. if (length > total)
  1226. len = total;
  1227. total = 0;
  1228. /* Copy data into sg buffer(s) */
  1229. for (i = 0; i < srb->use_sg; i++) {
  1230. if ((len > total) && (len > 0)) {
  1231. /* transfer the lesser of the next buffer or the
  1232.  * remaining data */
  1233. if (len - total >= sg[i].length) {
  1234. memcpy(sg[i].address, src + total, sg[i].length);
  1235. total += sg[i].length;
  1236. } else {
  1237. memcpy(sg[i].address, src + total, len - total);
  1238. total = len;
  1239. }
  1240. else
  1241. break;
  1242. }
  1243. } else {
  1244. /* Make sure length does not exceed buffer length */
  1245. if (length > srb->request_bufflen)
  1246. len = srb->request_bufflen;
  1247. if (len > 0)
  1248. memcpy(srb->request_buffer, src, len);
  1249. }
  1250. }
  1251. /**************************************************************************
  1252.  * isd200_scsi_to_ata
  1253.  *                                                                         
  1254.  * Translate SCSI commands to ATA commands.
  1255.  *
  1256.  * RETURNS:
  1257.  *    TRUE if the command needs to be sent to the transport layer
  1258.  *    FALSE otherwise
  1259.  */                                                                        
  1260. int isd200_scsi_to_ata(Scsi_Cmnd *srb, struct us_data *us, 
  1261.        union ata_cdb * ataCdb)
  1262. {
  1263. struct isd200_info *info = (struct isd200_info *)us->extra;
  1264. int sendToTransport = TRUE;
  1265. unsigned char sectnum, head;
  1266. unsigned short cylinder;
  1267. unsigned long lba;
  1268. unsigned long blockCount;
  1269. unsigned char senseData[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
  1270. memset(ataCdb, 0, sizeof(union ata_cdb));
  1271. /* SCSI Command */
  1272. switch (srb->cmnd[0]) {
  1273. case INQUIRY:
  1274. US_DEBUGP("   ATA OUT - INQUIRYn");
  1275. if (srb->request_bufflen > sizeof(struct inquiry_data))
  1276. srb->request_bufflen = sizeof(struct inquiry_data);
  1277. /* copy InquiryData */
  1278. isd200_data_copy(srb, (char *) &info->InquiryData, srb->request_bufflen);
  1279. srb->result = GOOD;
  1280. sendToTransport = FALSE;
  1281. break;
  1282. case MODE_SENSE:
  1283. US_DEBUGP("   ATA OUT - SCSIOP_MODE_SENSEn");
  1284. /* Initialize the return buffer */
  1285. isd200_data_copy(srb, (char *) &senseData, 8);
  1286. if (info->DeviceFlags & DF_MEDIA_STATUS_ENABLED)
  1287. {
  1288. ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand;
  1289. ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand;
  1290. ataCdb->generic.TransferBlockSize = 1;
  1291. ataCdb->write.SelectCommand = 1;
  1292. ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS;
  1293. srb->request_bufflen = 0;
  1294. } else {
  1295. US_DEBUGP("   Media Status not supported, just report okayn");
  1296. srb->result = GOOD;
  1297. sendToTransport = FALSE;
  1298. }
  1299. break;
  1300. case TEST_UNIT_READY:
  1301. US_DEBUGP("   ATA OUT - SCSIOP_TEST_UNIT_READYn");
  1302. /* Initialize the return buffer */
  1303. isd200_data_copy(srb, (char *) &senseData, 8);
  1304. if (info->DeviceFlags & DF_MEDIA_STATUS_ENABLED)
  1305. {
  1306. ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand;
  1307. ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand;
  1308. ataCdb->generic.TransferBlockSize = 1;
  1309. ataCdb->write.SelectCommand = 1;
  1310. ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS;
  1311. srb->request_bufflen = 0;
  1312. } else {
  1313. US_DEBUGP("   Media Status not supported, just report okayn");
  1314. srb->result = GOOD;
  1315. sendToTransport = FALSE;
  1316. }
  1317. break;
  1318. case READ_CAPACITY:
  1319. {
  1320. unsigned long capacity;
  1321. struct read_capacity_data readCapacityData;
  1322. US_DEBUGP("   ATA OUT - SCSIOP_READ_CAPACITYn");
  1323. if (info->drive.capability & CAPABILITY_LBA ) {
  1324. capacity = info->drive.lba_capacity - 1;
  1325. } else {
  1326. capacity = (info->drive.heads *
  1327.     info->drive.cyls *
  1328.     info->drive.sectors) - 1;
  1329. }
  1330. readCapacityData.LogicalBlockAddress = cpu_to_be32(capacity);
  1331. readCapacityData.BytesPerBlock = cpu_to_be32(0x200);
  1332. if (srb->request_bufflen > sizeof(struct read_capacity_data))
  1333. srb->request_bufflen = sizeof(struct read_capacity_data);
  1334. isd200_data_copy(srb, (char *) &readCapacityData, srb->request_bufflen);
  1335. srb->result = GOOD;
  1336. sendToTransport = FALSE;
  1337. }
  1338. break;
  1339. case READ_10:
  1340. US_DEBUGP("   ATA OUT - SCSIOP_READn");
  1341. lba = *(unsigned long *)&srb->cmnd[2]; 
  1342. lba = cpu_to_be32(lba);
  1343. blockCount = (unsigned long)srb->cmnd[7]<<8 | (unsigned long)srb->cmnd[8];
  1344. if (info->drive.capability & CAPABILITY_LBA) {
  1345. sectnum = (unsigned char)(lba);
  1346. cylinder = (unsigned short)(lba>>8);
  1347. head = ATA_ADDRESS_DEVHEAD_LBA_MODE | (unsigned char)(lba>>24 & 0x0F);
  1348. } else {
  1349. sectnum = (unsigned char)((lba % info->drive.sectors) + 1);
  1350. cylinder = (unsigned short)(lba / (info->drive.sectors *
  1351.    info->drive.heads));
  1352. head = (unsigned char)((lba / info->drive.sectors) %
  1353.        info->drive.heads);
  1354. }
  1355. ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand;
  1356. ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand;
  1357. ataCdb->generic.TransferBlockSize = 1;
  1358. ataCdb->write.SelectSectorCount = 1;
  1359. ataCdb->write.SectorCountByte = (unsigned char)blockCount;
  1360. ataCdb->write.SelectSectorNumber = 1;
  1361. ataCdb->write.SectorNumberByte = sectnum;
  1362. ataCdb->write.SelectCylinderHigh = 1;
  1363. ataCdb->write.CylinderHighByte = (unsigned char)(cylinder>>8);
  1364. ataCdb->write.SelectCylinderLow = 1;
  1365. ataCdb->write.CylinderLowByte = (unsigned char)cylinder;
  1366. ataCdb->write.SelectDeviceHead = 1;
  1367. ataCdb->write.DeviceHeadByte = (head | ATA_ADDRESS_DEVHEAD_STD);
  1368. ataCdb->write.SelectCommand = 1;
  1369. ataCdb->write.CommandByte = WIN_READ;
  1370. break;
  1371. case WRITE_10:
  1372. US_DEBUGP("   ATA OUT - SCSIOP_WRITEn");
  1373. lba = *(unsigned long *)&srb->cmnd[2]; 
  1374. lba = cpu_to_be32(lba);
  1375. blockCount = (unsigned long)srb->cmnd[7]<<8 | (unsigned long)srb->cmnd[8];
  1376. if (info->drive.capability & CAPABILITY_LBA) {
  1377. sectnum = (unsigned char)(lba);
  1378. cylinder = (unsigned short)(lba>>8);
  1379. head = ATA_ADDRESS_DEVHEAD_LBA_MODE | (unsigned char)(lba>>24 & 0x0F);
  1380. } else {
  1381. sectnum = (unsigned char)((lba % info->drive.sectors) + 1);
  1382. cylinder = (unsigned short)(lba / (info->drive.sectors * info->drive.heads));
  1383. head = (unsigned char)((lba / info->drive.sectors) % info->drive.heads);
  1384. }
  1385. ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand;
  1386. ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand;
  1387. ataCdb->generic.TransferBlockSize = 1;
  1388. ataCdb->write.SelectSectorCount = 1;
  1389. ataCdb->write.SectorCountByte = (unsigned char)blockCount;
  1390. ataCdb->write.SelectSectorNumber = 1;
  1391. ataCdb->write.SectorNumberByte = sectnum;
  1392. ataCdb->write.SelectCylinderHigh = 1;
  1393. ataCdb->write.CylinderHighByte = (unsigned char)(cylinder>>8);
  1394. ataCdb->write.SelectCylinderLow = 1;
  1395. ataCdb->write.CylinderLowByte = (unsigned char)cylinder;
  1396. ataCdb->write.SelectDeviceHead = 1;
  1397. ataCdb->write.DeviceHeadByte = (head | ATA_ADDRESS_DEVHEAD_STD);
  1398. ataCdb->write.SelectCommand = 1;
  1399. ataCdb->write.CommandByte = WIN_WRITE;
  1400. break;
  1401. case ALLOW_MEDIUM_REMOVAL:
  1402. US_DEBUGP("   ATA OUT - SCSIOP_MEDIUM_REMOVALn");
  1403. if (info->DeviceFlags & DF_REMOVABLE_MEDIA) {
  1404. US_DEBUGP("   srb->cmnd[4] = 0x%Xn", srb->cmnd[4]);
  1405.             
  1406. ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand;
  1407. ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand;
  1408. ataCdb->generic.TransferBlockSize = 1;
  1409. ataCdb->write.SelectCommand = 1;
  1410. ataCdb->write.CommandByte = (srb->cmnd[4] & 0x1) ?
  1411. WIN_DOORLOCK : WIN_DOORUNLOCK;
  1412. srb->request_bufflen = 0;
  1413. } else {
  1414. US_DEBUGP("   Not removeable media, just report okayn");
  1415. srb->result = GOOD;
  1416. sendToTransport = FALSE;
  1417. }
  1418. break;
  1419. case START_STOP:    
  1420. US_DEBUGP("   ATA OUT - SCSIOP_START_STOP_UNITn");
  1421. US_DEBUGP("   srb->cmnd[4] = 0x%Xn", srb->cmnd[4]);
  1422. /* Initialize the return buffer */
  1423. isd200_data_copy(srb, (char *) &senseData, 8);
  1424. if ((srb->cmnd[4] & 0x3) == 0x2) {
  1425. US_DEBUGP("   Media Ejectn");
  1426. ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand;
  1427. ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand;
  1428. ataCdb->generic.TransferBlockSize = 0;
  1429. ataCdb->write.SelectCommand = 1;
  1430. ataCdb->write.CommandByte = ATA_COMMAND_MEDIA_EJECT;
  1431. } else if ((srb->cmnd[4] & 0x3) == 0x1) {
  1432. US_DEBUGP("   Get Media Statusn");
  1433. ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand;
  1434. ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand;
  1435. ataCdb->generic.TransferBlockSize = 1;
  1436. ataCdb->write.SelectCommand = 1;
  1437. ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS;
  1438. srb->request_bufflen = 0;
  1439. } else {
  1440. US_DEBUGP("   Nothing to do, just report okayn");
  1441. srb->result = GOOD;
  1442. sendToTransport = FALSE;
  1443. }
  1444. break;
  1445. default:
  1446. US_DEBUGP("Unsupported SCSI command - 0x%Xn", srb->cmnd[0]);
  1447. srb->result = DID_ERROR << 16;
  1448. sendToTransport = FALSE;
  1449. break;
  1450. }
  1451. return(sendToTransport);
  1452. }
  1453. /**************************************************************************
  1454.  * isd200_init_info
  1455.  *                                                                         
  1456.  * Allocates (if necessary) and initializes the driver structure.
  1457.  *
  1458.  * RETURNS:
  1459.  *    ISD status code
  1460.  */                                                                        
  1461. int isd200_init_info(struct us_data *us)
  1462. {
  1463. int retStatus = ISD200_GOOD;
  1464. if (!us->extra) {
  1465. us->extra = (void *) kmalloc(sizeof(struct isd200_info), GFP_KERNEL);
  1466. if (!us->extra) {
  1467. US_DEBUGP("ERROR - kmalloc failuren");
  1468. retStatus = ISD200_ERROR;
  1469. }
  1470.         }
  1471. if (retStatus == ISD200_GOOD) {
  1472. memset(us->extra, 0, sizeof(struct isd200_info));
  1473.         }
  1474. return(retStatus);
  1475. }
  1476. /**************************************************************************
  1477.  * Initialization for the ISD200 
  1478.  */
  1479. int isd200_Initialization(struct us_data *us)
  1480. {
  1481. US_DEBUGP("ISD200 Initialization...n");
  1482. /* Initialize ISD200 info struct */
  1483. if (isd200_init_info(us) == ISD200_ERROR) {
  1484. US_DEBUGP("ERROR Initializing ISD200 Info structn");
  1485.         } else {
  1486. /* Get device specific data */
  1487. if (isd200_get_inquiry_data(us) != ISD200_GOOD)
  1488. US_DEBUGP("ISD200 Initialization Failuren");
  1489. else
  1490. US_DEBUGP("ISD200 Initialization completen");
  1491.         }
  1492. return 0;
  1493. }
  1494. /**************************************************************************
  1495.  * Protocol and Transport for the ISD200 ASIC
  1496.  *
  1497.  * This protocol and transport are for ATA devices connected to an ISD200
  1498.  * ASIC.  An ATAPI device that is conected as a slave device will be
  1499.  * detected in the driver initialization function and the protocol will
  1500.  * be changed to an ATAPI protocol (Transparent SCSI).
  1501.  *
  1502.  */
  1503. void isd200_ata_command(Scsi_Cmnd *srb, struct us_data *us)
  1504. {
  1505. int sendToTransport = TRUE;
  1506. union ata_cdb ataCdb;
  1507. /* Make sure driver was initialized */
  1508. if (us->extra == NULL)
  1509. US_DEBUGP("ERROR Driver not initializedn");
  1510. /* Convert command */
  1511. sendToTransport = isd200_scsi_to_ata(srb, us, &ataCdb);
  1512. /* send the command to the transport layer */
  1513. if (sendToTransport)
  1514. isd200_invoke_transport(us, srb, &ataCdb);
  1515. }