Felipe Balbi | f0183a3 | 2016-04-18 13:09:11 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Transport & Protocol Driver for In-System Design, Inc. ISD200 ASIC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Current development and maintenance: |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 5 | * (C) 2001-2002 Björn Stenberg (bjorn@haxx.se) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * Developed with the assistance of: |
| 8 | * (C) 2002 Alan Stern <stern@rowland.org> |
| 9 | * |
| 10 | * Initial work: |
| 11 | * (C) 2000 In-System Design, Inc. (support@in-system.com) |
| 12 | * |
| 13 | * The ISD200 ASIC does not natively support ATA devices. The chip |
| 14 | * does implement an interface, the ATA Command Block (ATACB) which provides |
| 15 | * a means of passing ATA commands and ATA register accesses to a device. |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or modify it |
| 18 | * under the terms of the GNU General Public License as published by the |
| 19 | * Free Software Foundation; either version 2, or (at your option) any |
| 20 | * later version. |
| 21 | * |
| 22 | * This program is distributed in the hope that it will be useful, but |
| 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 25 | * General Public License for more details. |
| 26 | * |
| 27 | * You should have received a copy of the GNU General Public License along |
| 28 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 29 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 30 | * |
| 31 | * History: |
| 32 | * |
| 33 | * 2002-10-19: Removed the specialized transfer routines. |
| 34 | * (Alan Stern <stern@rowland.harvard.edu>) |
| 35 | * 2001-02-24: Removed lots of duplicate code and simplified the structure. |
| 36 | * (bjorn@haxx.se) |
| 37 | * 2002-01-16: Fixed endianness bug so it works on the ppc arch. |
| 38 | * (Luc Saillard <luc@saillard.org>) |
| 39 | * 2002-01-17: All bitfields removed. |
| 40 | * (bjorn@haxx.se) |
| 41 | */ |
| 42 | |
| 43 | |
| 44 | /* Include files */ |
| 45 | |
| 46 | #include <linux/jiffies.h> |
| 47 | #include <linux/errno.h> |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 48 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/slab.h> |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 50 | #include <linux/ata.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/hdreg.h> |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 52 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | #include <scsi/scsi.h> |
| 55 | #include <scsi/scsi_cmnd.h> |
| 56 | #include <scsi/scsi_device.h> |
| 57 | |
| 58 | #include "usb.h" |
| 59 | #include "transport.h" |
| 60 | #include "protocol.h" |
| 61 | #include "debug.h" |
| 62 | #include "scsiglue.h" |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 63 | |
Akinobu Mita | aa519be | 2015-05-06 18:24:21 +0900 | [diff] [blame] | 64 | #define DRV_NAME "ums-isd200" |
| 65 | |
Maciej Grela | 4246b06 | 2009-02-28 12:39:20 -0800 | [diff] [blame] | 66 | MODULE_DESCRIPTION("Driver for In-System Design, Inc. ISD200 ASIC"); |
Al Viro | d36b691 | 2011-12-29 17:09:01 -0500 | [diff] [blame] | 67 | MODULE_AUTHOR("Björn Stenberg <bjorn@haxx.se>"); |
Maciej Grela | 4246b06 | 2009-02-28 12:39:20 -0800 | [diff] [blame] | 68 | MODULE_LICENSE("GPL"); |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 69 | |
| 70 | static int isd200_Initialization(struct us_data *us); |
| 71 | |
| 72 | |
| 73 | /* |
| 74 | * The table of devices |
| 75 | */ |
| 76 | #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \ |
| 77 | vendorName, productName, useProtocol, useTransport, \ |
| 78 | initFunction, flags) \ |
| 79 | { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \ |
Sebastian Andrzej Siewior | f61870e | 2012-08-28 22:37:13 +0200 | [diff] [blame] | 80 | .driver_info = (flags) } |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 81 | |
Felipe Balbi | e7724ba | 2011-11-15 09:53:33 +0200 | [diff] [blame] | 82 | static struct usb_device_id isd200_usb_ids[] = { |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 83 | # include "unusual_isd200.h" |
| 84 | { } /* Terminating entry */ |
| 85 | }; |
| 86 | MODULE_DEVICE_TABLE(usb, isd200_usb_ids); |
| 87 | |
| 88 | #undef UNUSUAL_DEV |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * The flags table |
| 92 | */ |
| 93 | #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \ |
| 94 | vendor_name, product_name, use_protocol, use_transport, \ |
| 95 | init_function, Flags) \ |
| 96 | { \ |
| 97 | .vendorName = vendor_name, \ |
| 98 | .productName = product_name, \ |
| 99 | .useProtocol = use_protocol, \ |
| 100 | .useTransport = use_transport, \ |
| 101 | .initFunction = init_function, \ |
| 102 | } |
| 103 | |
| 104 | static struct us_unusual_dev isd200_unusual_dev_list[] = { |
| 105 | # include "unusual_isd200.h" |
| 106 | { } /* Terminating entry */ |
| 107 | }; |
| 108 | |
| 109 | #undef UNUSUAL_DEV |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | /* Timeout defines (in Seconds) */ |
| 112 | |
| 113 | #define ISD200_ENUM_BSY_TIMEOUT 35 |
| 114 | #define ISD200_ENUM_DETECT_TIMEOUT 30 |
| 115 | #define ISD200_DEFAULT_TIMEOUT 30 |
| 116 | |
| 117 | /* device flags */ |
| 118 | #define DF_ATA_DEVICE 0x0001 |
| 119 | #define DF_MEDIA_STATUS_ENABLED 0x0002 |
| 120 | #define DF_REMOVABLE_MEDIA 0x0004 |
| 121 | |
| 122 | /* capability bit definitions */ |
| 123 | #define CAPABILITY_DMA 0x01 |
| 124 | #define CAPABILITY_LBA 0x02 |
| 125 | |
| 126 | /* command_setX bit definitions */ |
| 127 | #define COMMANDSET_REMOVABLE 0x02 |
| 128 | #define COMMANDSET_MEDIA_STATUS 0x10 |
| 129 | |
| 130 | /* ATA Vendor Specific defines */ |
| 131 | #define ATA_ADDRESS_DEVHEAD_STD 0xa0 |
| 132 | #define ATA_ADDRESS_DEVHEAD_LBA_MODE 0x40 |
| 133 | #define ATA_ADDRESS_DEVHEAD_SLAVE 0x10 |
| 134 | |
| 135 | /* Action Select bits */ |
| 136 | #define ACTION_SELECT_0 0x01 |
| 137 | #define ACTION_SELECT_1 0x02 |
| 138 | #define ACTION_SELECT_2 0x04 |
| 139 | #define ACTION_SELECT_3 0x08 |
| 140 | #define ACTION_SELECT_4 0x10 |
| 141 | #define ACTION_SELECT_5 0x20 |
| 142 | #define ACTION_SELECT_6 0x40 |
| 143 | #define ACTION_SELECT_7 0x80 |
| 144 | |
| 145 | /* Register Select bits */ |
| 146 | #define REG_ALTERNATE_STATUS 0x01 |
| 147 | #define REG_DEVICE_CONTROL 0x01 |
| 148 | #define REG_ERROR 0x02 |
| 149 | #define REG_FEATURES 0x02 |
| 150 | #define REG_SECTOR_COUNT 0x04 |
| 151 | #define REG_SECTOR_NUMBER 0x08 |
| 152 | #define REG_CYLINDER_LOW 0x10 |
| 153 | #define REG_CYLINDER_HIGH 0x20 |
| 154 | #define REG_DEVICE_HEAD 0x40 |
| 155 | #define REG_STATUS 0x80 |
| 156 | #define REG_COMMAND 0x80 |
| 157 | |
Bartlomiej Zolnierkiewicz | c74e809 | 2007-10-27 18:01:04 +0200 | [diff] [blame] | 158 | /* ATA registers offset definitions */ |
| 159 | #define ATA_REG_ERROR_OFFSET 1 |
| 160 | #define ATA_REG_LCYL_OFFSET 4 |
| 161 | #define ATA_REG_HCYL_OFFSET 5 |
| 162 | #define ATA_REG_STATUS_OFFSET 7 |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | /* ATA error definitions not in <linux/hdreg.h> */ |
| 165 | #define ATA_ERROR_MEDIA_CHANGE 0x20 |
| 166 | |
| 167 | /* ATA command definitions not in <linux/hdreg.h> */ |
| 168 | #define ATA_COMMAND_GET_MEDIA_STATUS 0xDA |
| 169 | #define ATA_COMMAND_MEDIA_EJECT 0xED |
| 170 | |
| 171 | /* ATA drive control definitions */ |
| 172 | #define ATA_DC_DISABLE_INTERRUPTS 0x02 |
| 173 | #define ATA_DC_RESET_CONTROLLER 0x04 |
| 174 | #define ATA_DC_REENABLE_CONTROLLER 0x00 |
| 175 | |
| 176 | /* |
| 177 | * General purpose return codes |
| 178 | */ |
| 179 | |
| 180 | #define ISD200_ERROR -1 |
| 181 | #define ISD200_GOOD 0 |
| 182 | |
| 183 | /* |
| 184 | * Transport return codes |
| 185 | */ |
| 186 | |
| 187 | #define ISD200_TRANSPORT_GOOD 0 /* Transport good, command good */ |
| 188 | #define ISD200_TRANSPORT_FAILED 1 /* Transport good, command failed */ |
| 189 | #define ISD200_TRANSPORT_ERROR 2 /* Transport bad (i.e. device dead) */ |
| 190 | |
| 191 | /* driver action codes */ |
| 192 | #define ACTION_READ_STATUS 0 |
| 193 | #define ACTION_RESET 1 |
| 194 | #define ACTION_REENABLE 2 |
| 195 | #define ACTION_SOFT_RESET 3 |
| 196 | #define ACTION_ENUM 4 |
| 197 | #define ACTION_IDENTIFY 5 |
| 198 | |
| 199 | |
| 200 | /* |
| 201 | * ata_cdb struct |
| 202 | */ |
| 203 | |
| 204 | |
| 205 | union ata_cdb { |
| 206 | struct { |
| 207 | unsigned char SignatureByte0; |
| 208 | unsigned char SignatureByte1; |
| 209 | unsigned char ActionSelect; |
| 210 | unsigned char RegisterSelect; |
| 211 | unsigned char TransferBlockSize; |
| 212 | unsigned char WriteData3F6; |
| 213 | unsigned char WriteData1F1; |
| 214 | unsigned char WriteData1F2; |
| 215 | unsigned char WriteData1F3; |
| 216 | unsigned char WriteData1F4; |
| 217 | unsigned char WriteData1F5; |
| 218 | unsigned char WriteData1F6; |
| 219 | unsigned char WriteData1F7; |
| 220 | unsigned char Reserved[3]; |
| 221 | } generic; |
| 222 | |
| 223 | struct { |
| 224 | unsigned char SignatureByte0; |
| 225 | unsigned char SignatureByte1; |
| 226 | unsigned char ActionSelect; |
| 227 | unsigned char RegisterSelect; |
| 228 | unsigned char TransferBlockSize; |
| 229 | unsigned char AlternateStatusByte; |
| 230 | unsigned char ErrorByte; |
| 231 | unsigned char SectorCountByte; |
| 232 | unsigned char SectorNumberByte; |
| 233 | unsigned char CylinderLowByte; |
| 234 | unsigned char CylinderHighByte; |
| 235 | unsigned char DeviceHeadByte; |
| 236 | unsigned char StatusByte; |
| 237 | unsigned char Reserved[3]; |
| 238 | } read; |
| 239 | |
| 240 | struct { |
| 241 | unsigned char SignatureByte0; |
| 242 | unsigned char SignatureByte1; |
| 243 | unsigned char ActionSelect; |
| 244 | unsigned char RegisterSelect; |
| 245 | unsigned char TransferBlockSize; |
| 246 | unsigned char DeviceControlByte; |
| 247 | unsigned char FeaturesByte; |
| 248 | unsigned char SectorCountByte; |
| 249 | unsigned char SectorNumberByte; |
| 250 | unsigned char CylinderLowByte; |
| 251 | unsigned char CylinderHighByte; |
| 252 | unsigned char DeviceHeadByte; |
| 253 | unsigned char CommandByte; |
| 254 | unsigned char Reserved[3]; |
| 255 | } write; |
| 256 | }; |
| 257 | |
| 258 | |
| 259 | /* |
| 260 | * Inquiry data structure. This is the data returned from the target |
| 261 | * after it receives an inquiry. |
| 262 | * |
| 263 | * This structure may be extended by the number of bytes specified |
| 264 | * in the field AdditionalLength. The defined size constant only |
| 265 | * includes fields through ProductRevisionLevel. |
| 266 | */ |
| 267 | |
| 268 | /* |
| 269 | * DeviceType field |
| 270 | */ |
| 271 | #define DIRECT_ACCESS_DEVICE 0x00 /* disks */ |
| 272 | #define DEVICE_REMOVABLE 0x80 |
| 273 | |
| 274 | struct inquiry_data { |
| 275 | unsigned char DeviceType; |
| 276 | unsigned char DeviceTypeModifier; |
| 277 | unsigned char Versions; |
| 278 | unsigned char Format; |
| 279 | unsigned char AdditionalLength; |
| 280 | unsigned char Reserved[2]; |
| 281 | unsigned char Capability; |
| 282 | unsigned char VendorId[8]; |
| 283 | unsigned char ProductId[16]; |
| 284 | unsigned char ProductRevisionLevel[4]; |
| 285 | unsigned char VendorSpecific[20]; |
| 286 | unsigned char Reserved3[40]; |
| 287 | } __attribute__ ((packed)); |
| 288 | |
| 289 | /* |
| 290 | * INQUIRY data buffer size |
| 291 | */ |
| 292 | |
| 293 | #define INQUIRYDATABUFFERSIZE 36 |
| 294 | |
| 295 | |
| 296 | /* |
| 297 | * ISD200 CONFIG data struct |
| 298 | */ |
| 299 | |
| 300 | #define ATACFG_TIMING 0x0f |
| 301 | #define ATACFG_ATAPI_RESET 0x10 |
| 302 | #define ATACFG_MASTER 0x20 |
| 303 | #define ATACFG_BLOCKSIZE 0xa0 |
| 304 | |
| 305 | #define ATACFGE_LAST_LUN 0x07 |
| 306 | #define ATACFGE_DESC_OVERRIDE 0x08 |
| 307 | #define ATACFGE_STATE_SUSPEND 0x10 |
| 308 | #define ATACFGE_SKIP_BOOT 0x20 |
| 309 | #define ATACFGE_CONF_DESC2 0x40 |
| 310 | #define ATACFGE_INIT_STATUS 0x80 |
| 311 | |
| 312 | #define CFG_CAPABILITY_SRST 0x01 |
| 313 | |
| 314 | struct isd200_config { |
| 315 | unsigned char EventNotification; |
| 316 | unsigned char ExternalClock; |
| 317 | unsigned char ATAInitTimeout; |
| 318 | unsigned char ATAConfig; |
| 319 | unsigned char ATAMajorCommand; |
| 320 | unsigned char ATAMinorCommand; |
| 321 | unsigned char ATAExtraConfig; |
| 322 | unsigned char Capability; |
| 323 | }__attribute__ ((packed)); |
| 324 | |
| 325 | |
| 326 | /* |
| 327 | * ISD200 driver information struct |
| 328 | */ |
| 329 | |
| 330 | struct isd200_info { |
| 331 | struct inquiry_data InquiryData; |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 332 | u16 *id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | struct isd200_config ConfigData; |
| 334 | unsigned char *RegsBuf; |
| 335 | unsigned char ATARegs[8]; |
| 336 | unsigned char DeviceHead; |
| 337 | unsigned char DeviceFlags; |
| 338 | |
| 339 | /* maximum number of LUNs supported */ |
| 340 | unsigned char MaxLUNs; |
Boaz Harrosh | 64a87b2 | 2008-04-30 11:19:47 +0300 | [diff] [blame] | 341 | unsigned char cmnd[BLK_MAX_CDB]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | struct scsi_cmnd srb; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 343 | struct scatterlist sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | }; |
| 345 | |
| 346 | |
| 347 | /* |
| 348 | * Read Capacity Data - returned in Big Endian format |
| 349 | */ |
| 350 | |
| 351 | struct read_capacity_data { |
| 352 | __be32 LogicalBlockAddress; |
| 353 | __be32 BytesPerBlock; |
| 354 | }; |
| 355 | |
| 356 | /* |
| 357 | * Read Block Limits Data - returned in Big Endian format |
| 358 | * This structure returns the maximum and minimum block |
| 359 | * size for a TAPE device. |
| 360 | */ |
| 361 | |
| 362 | struct read_block_limits { |
| 363 | unsigned char Reserved; |
| 364 | unsigned char BlockMaximumSize[3]; |
| 365 | unsigned char BlockMinimumSize[2]; |
| 366 | }; |
| 367 | |
| 368 | |
| 369 | /* |
| 370 | * Sense Data Format |
| 371 | */ |
| 372 | |
| 373 | #define SENSE_ERRCODE 0x7f |
| 374 | #define SENSE_ERRCODE_VALID 0x80 |
| 375 | #define SENSE_FLAG_SENSE_KEY 0x0f |
| 376 | #define SENSE_FLAG_BAD_LENGTH 0x20 |
| 377 | #define SENSE_FLAG_END_OF_MEDIA 0x40 |
| 378 | #define SENSE_FLAG_FILE_MARK 0x80 |
| 379 | struct sense_data { |
| 380 | unsigned char ErrorCode; |
| 381 | unsigned char SegmentNumber; |
| 382 | unsigned char Flags; |
| 383 | unsigned char Information[4]; |
| 384 | unsigned char AdditionalSenseLength; |
| 385 | unsigned char CommandSpecificInformation[4]; |
| 386 | unsigned char AdditionalSenseCode; |
| 387 | unsigned char AdditionalSenseCodeQualifier; |
| 388 | unsigned char FieldReplaceableUnitCode; |
| 389 | unsigned char SenseKeySpecific[3]; |
| 390 | } __attribute__ ((packed)); |
| 391 | |
| 392 | /* |
| 393 | * Default request sense buffer size |
| 394 | */ |
| 395 | |
| 396 | #define SENSE_BUFFER_SIZE 18 |
| 397 | |
| 398 | /*********************************************************************** |
| 399 | * Helper routines |
| 400 | ***********************************************************************/ |
| 401 | |
| 402 | /************************************************************************** |
| 403 | * isd200_build_sense |
| 404 | * |
| 405 | * Builds an artificial sense buffer to report the results of a |
| 406 | * failed command. |
| 407 | * |
| 408 | * RETURNS: |
| 409 | * void |
| 410 | */ |
| 411 | static void isd200_build_sense(struct us_data *us, struct scsi_cmnd *srb) |
| 412 | { |
| 413 | struct isd200_info *info = (struct isd200_info *)us->extra; |
| 414 | struct sense_data *buf = (struct sense_data *) &srb->sense_buffer[0]; |
Bartlomiej Zolnierkiewicz | c74e809 | 2007-10-27 18:01:04 +0200 | [diff] [blame] | 415 | unsigned char error = info->ATARegs[ATA_REG_ERROR_OFFSET]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | if(error & ATA_ERROR_MEDIA_CHANGE) { |
| 418 | buf->ErrorCode = 0x70 | SENSE_ERRCODE_VALID; |
| 419 | buf->AdditionalSenseLength = 0xb; |
| 420 | buf->Flags = UNIT_ATTENTION; |
| 421 | buf->AdditionalSenseCode = 0; |
| 422 | buf->AdditionalSenseCodeQualifier = 0; |
Bartlomiej Zolnierkiewicz | fcd3ec6 | 2009-04-01 21:42:25 +0200 | [diff] [blame] | 423 | } else if (error & ATA_MCR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | buf->ErrorCode = 0x70 | SENSE_ERRCODE_VALID; |
| 425 | buf->AdditionalSenseLength = 0xb; |
| 426 | buf->Flags = UNIT_ATTENTION; |
| 427 | buf->AdditionalSenseCode = 0; |
| 428 | buf->AdditionalSenseCodeQualifier = 0; |
Bartlomiej Zolnierkiewicz | fcd3ec6 | 2009-04-01 21:42:25 +0200 | [diff] [blame] | 429 | } else if (error & ATA_TRK0NF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | buf->ErrorCode = 0x70 | SENSE_ERRCODE_VALID; |
| 431 | buf->AdditionalSenseLength = 0xb; |
| 432 | buf->Flags = NOT_READY; |
| 433 | buf->AdditionalSenseCode = 0; |
| 434 | buf->AdditionalSenseCodeQualifier = 0; |
Bartlomiej Zolnierkiewicz | fcd3ec6 | 2009-04-01 21:42:25 +0200 | [diff] [blame] | 435 | } else if (error & ATA_UNC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | buf->ErrorCode = 0x70 | SENSE_ERRCODE_VALID; |
| 437 | buf->AdditionalSenseLength = 0xb; |
| 438 | buf->Flags = DATA_PROTECT; |
| 439 | buf->AdditionalSenseCode = 0; |
| 440 | buf->AdditionalSenseCodeQualifier = 0; |
| 441 | } else { |
| 442 | buf->ErrorCode = 0; |
| 443 | buf->AdditionalSenseLength = 0; |
| 444 | buf->Flags = 0; |
| 445 | buf->AdditionalSenseCode = 0; |
| 446 | buf->AdditionalSenseCodeQualifier = 0; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | |
| 451 | /*********************************************************************** |
| 452 | * Transport routines |
| 453 | ***********************************************************************/ |
| 454 | |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 455 | /************************************************************************** |
| 456 | * isd200_set_srb(), isd200_srb_set_bufflen() |
| 457 | * |
| 458 | * Two helpers to facilitate in initialization of scsi_cmnd structure |
| 459 | * Will need to change when struct scsi_cmnd changes |
| 460 | */ |
| 461 | static void isd200_set_srb(struct isd200_info *info, |
| 462 | enum dma_data_direction dir, void* buff, unsigned bufflen) |
| 463 | { |
| 464 | struct scsi_cmnd *srb = &info->srb; |
| 465 | |
| 466 | if (buff) |
| 467 | sg_init_one(&info->sg, buff, bufflen); |
| 468 | |
| 469 | srb->sc_data_direction = dir; |
Boaz Harrosh | 30b0c37 | 2007-12-13 13:47:40 +0200 | [diff] [blame] | 470 | srb->sdb.table.sgl = buff ? &info->sg : NULL; |
| 471 | srb->sdb.length = bufflen; |
| 472 | srb->sdb.table.nents = buff ? 1 : 0; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | static void isd200_srb_set_bufflen(struct scsi_cmnd *srb, unsigned bufflen) |
| 476 | { |
Boaz Harrosh | 30b0c37 | 2007-12-13 13:47:40 +0200 | [diff] [blame] | 477 | srb->sdb.length = bufflen; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 478 | } |
| 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
| 481 | /************************************************************************** |
| 482 | * isd200_action |
| 483 | * |
| 484 | * Routine for sending commands to the isd200 |
| 485 | * |
| 486 | * RETURNS: |
| 487 | * ISD status code |
| 488 | */ |
| 489 | static int isd200_action( struct us_data *us, int action, |
| 490 | void* pointer, int value ) |
| 491 | { |
| 492 | union ata_cdb ata; |
Ian Munsie | 0df4d8e | 2010-03-03 11:00:37 +1100 | [diff] [blame] | 493 | /* static to prevent this large struct being placed on the valuable stack */ |
| 494 | static struct scsi_device srb_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | struct isd200_info *info = (struct isd200_info *)us->extra; |
| 496 | struct scsi_cmnd *srb = &info->srb; |
| 497 | int status; |
| 498 | |
| 499 | memset(&ata, 0, sizeof(ata)); |
Boaz Harrosh | 64a87b2 | 2008-04-30 11:19:47 +0300 | [diff] [blame] | 500 | srb->cmnd = info->cmnd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | srb->device = &srb_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
| 503 | ata.generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; |
| 504 | ata.generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; |
| 505 | ata.generic.TransferBlockSize = 1; |
| 506 | |
| 507 | switch ( action ) { |
| 508 | case ACTION_READ_STATUS: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 509 | usb_stor_dbg(us, " isd200_action(READ_STATUS)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | ata.generic.ActionSelect = ACTION_SELECT_0|ACTION_SELECT_2; |
| 511 | ata.generic.RegisterSelect = |
| 512 | REG_CYLINDER_LOW | REG_CYLINDER_HIGH | |
| 513 | REG_STATUS | REG_ERROR; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 514 | isd200_set_srb(info, DMA_FROM_DEVICE, pointer, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | break; |
| 516 | |
| 517 | case ACTION_ENUM: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 518 | usb_stor_dbg(us, " isd200_action(ENUM,0x%02x)\n", value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_2| |
| 520 | ACTION_SELECT_3|ACTION_SELECT_4| |
| 521 | ACTION_SELECT_5; |
| 522 | ata.generic.RegisterSelect = REG_DEVICE_HEAD; |
| 523 | ata.write.DeviceHeadByte = value; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 524 | isd200_set_srb(info, DMA_NONE, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | break; |
| 526 | |
| 527 | case ACTION_RESET: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 528 | usb_stor_dbg(us, " isd200_action(RESET)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_2| |
| 530 | ACTION_SELECT_3|ACTION_SELECT_4; |
| 531 | ata.generic.RegisterSelect = REG_DEVICE_CONTROL; |
| 532 | ata.write.DeviceControlByte = ATA_DC_RESET_CONTROLLER; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 533 | isd200_set_srb(info, DMA_NONE, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | break; |
| 535 | |
| 536 | case ACTION_REENABLE: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 537 | usb_stor_dbg(us, " isd200_action(REENABLE)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_2| |
| 539 | ACTION_SELECT_3|ACTION_SELECT_4; |
| 540 | ata.generic.RegisterSelect = REG_DEVICE_CONTROL; |
| 541 | ata.write.DeviceControlByte = ATA_DC_REENABLE_CONTROLLER; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 542 | isd200_set_srb(info, DMA_NONE, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | break; |
| 544 | |
| 545 | case ACTION_SOFT_RESET: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 546 | usb_stor_dbg(us, " isd200_action(SOFT_RESET)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_5; |
| 548 | ata.generic.RegisterSelect = REG_DEVICE_HEAD | REG_COMMAND; |
| 549 | ata.write.DeviceHeadByte = info->DeviceHead; |
Bartlomiej Zolnierkiewicz | f08f31f | 2009-04-01 21:42:24 +0200 | [diff] [blame] | 550 | ata.write.CommandByte = ATA_CMD_DEV_RESET; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 551 | isd200_set_srb(info, DMA_NONE, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | break; |
| 553 | |
| 554 | case ACTION_IDENTIFY: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 555 | usb_stor_dbg(us, " isd200_action(IDENTIFY)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | ata.generic.RegisterSelect = REG_COMMAND; |
Bartlomiej Zolnierkiewicz | f08f31f | 2009-04-01 21:42:24 +0200 | [diff] [blame] | 557 | ata.write.CommandByte = ATA_CMD_ID_ATA; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 558 | isd200_set_srb(info, DMA_FROM_DEVICE, info->id, |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 559 | ATA_ID_WORDS * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | break; |
| 561 | |
| 562 | default: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 563 | usb_stor_dbg(us, "Error: Undefined action %d\n", action); |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 564 | return ISD200_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | memcpy(srb->cmnd, &ata, sizeof(ata.generic)); |
| 568 | srb->cmd_len = sizeof(ata.generic); |
| 569 | status = usb_stor_Bulk_transport(srb, us); |
| 570 | if (status == USB_STOR_TRANSPORT_GOOD) |
| 571 | status = ISD200_GOOD; |
| 572 | else { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 573 | usb_stor_dbg(us, " isd200_action(0x%02x) error: %d\n", |
| 574 | action, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | status = ISD200_ERROR; |
| 576 | /* need to reset device here */ |
| 577 | } |
| 578 | |
| 579 | return status; |
| 580 | } |
| 581 | |
| 582 | /************************************************************************** |
| 583 | * isd200_read_regs |
| 584 | * |
| 585 | * Read ATA Registers |
| 586 | * |
| 587 | * RETURNS: |
| 588 | * ISD status code |
| 589 | */ |
| 590 | static int isd200_read_regs( struct us_data *us ) |
| 591 | { |
| 592 | struct isd200_info *info = (struct isd200_info *)us->extra; |
| 593 | int retStatus = ISD200_GOOD; |
| 594 | int transferStatus; |
| 595 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 596 | usb_stor_dbg(us, "Entering isd200_IssueATAReadRegs\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | transferStatus = isd200_action( us, ACTION_READ_STATUS, |
| 599 | info->RegsBuf, sizeof(info->ATARegs) ); |
| 600 | if (transferStatus != ISD200_TRANSPORT_GOOD) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 601 | usb_stor_dbg(us, " Error reading ATA registers\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | retStatus = ISD200_ERROR; |
| 603 | } else { |
| 604 | memcpy(info->ATARegs, info->RegsBuf, sizeof(info->ATARegs)); |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 605 | usb_stor_dbg(us, " Got ATA Register[ATA_REG_ERROR_OFFSET] = 0x%x\n", |
| 606 | info->ATARegs[ATA_REG_ERROR_OFFSET]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | return retStatus; |
| 610 | } |
| 611 | |
| 612 | |
| 613 | /************************************************************************** |
| 614 | * Invoke the transport and basic error-handling/recovery methods |
| 615 | * |
| 616 | * This is used by the protocol layers to actually send the message to |
| 617 | * the device and receive the response. |
| 618 | */ |
| 619 | static void isd200_invoke_transport( struct us_data *us, |
| 620 | struct scsi_cmnd *srb, |
| 621 | union ata_cdb *ataCdb ) |
| 622 | { |
| 623 | int need_auto_sense = 0; |
| 624 | int transferStatus; |
| 625 | int result; |
| 626 | |
| 627 | /* send the command to the transport layer */ |
| 628 | memcpy(srb->cmnd, ataCdb, sizeof(ataCdb->generic)); |
| 629 | srb->cmd_len = sizeof(ataCdb->generic); |
| 630 | transferStatus = usb_stor_Bulk_transport(srb, us); |
| 631 | |
Felipe Balbi | f0183a3 | 2016-04-18 13:09:11 +0300 | [diff] [blame] | 632 | /* |
| 633 | * if the command gets aborted by the higher layers, we need to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | * short-circuit all other processing |
| 635 | */ |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 636 | if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 637 | usb_stor_dbg(us, "-- command was aborted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | goto Handle_Abort; |
| 639 | } |
| 640 | |
| 641 | switch (transferStatus) { |
| 642 | |
| 643 | case USB_STOR_TRANSPORT_GOOD: |
| 644 | /* Indicate a good result */ |
| 645 | srb->result = SAM_STAT_GOOD; |
| 646 | break; |
| 647 | |
| 648 | case USB_STOR_TRANSPORT_NO_SENSE: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 649 | usb_stor_dbg(us, "-- transport indicates protocol failure\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | srb->result = SAM_STAT_CHECK_CONDITION; |
| 651 | return; |
| 652 | |
| 653 | case USB_STOR_TRANSPORT_FAILED: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 654 | usb_stor_dbg(us, "-- transport indicates command failure\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | need_auto_sense = 1; |
| 656 | break; |
| 657 | |
| 658 | case USB_STOR_TRANSPORT_ERROR: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 659 | usb_stor_dbg(us, "-- transport indicates transport error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | srb->result = DID_ERROR << 16; |
| 661 | /* Need reset here */ |
| 662 | return; |
| 663 | |
| 664 | default: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 665 | usb_stor_dbg(us, "-- transport indicates unknown error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | srb->result = DID_ERROR << 16; |
| 667 | /* Need reset here */ |
| 668 | return; |
| 669 | } |
| 670 | |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 671 | if ((scsi_get_resid(srb) > 0) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | !((srb->cmnd[0] == REQUEST_SENSE) || |
| 673 | (srb->cmnd[0] == INQUIRY) || |
| 674 | (srb->cmnd[0] == MODE_SENSE) || |
| 675 | (srb->cmnd[0] == LOG_SENSE) || |
| 676 | (srb->cmnd[0] == MODE_SENSE_10))) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 677 | usb_stor_dbg(us, "-- unexpectedly short transfer\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | need_auto_sense = 1; |
| 679 | } |
| 680 | |
| 681 | if (need_auto_sense) { |
| 682 | result = isd200_read_regs(us); |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 683 | if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 684 | usb_stor_dbg(us, "-- auto-sense aborted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | goto Handle_Abort; |
| 686 | } |
| 687 | if (result == ISD200_GOOD) { |
| 688 | isd200_build_sense(us, srb); |
| 689 | srb->result = SAM_STAT_CHECK_CONDITION; |
| 690 | |
| 691 | /* If things are really okay, then let's show that */ |
| 692 | if ((srb->sense_buffer[2] & 0xf) == 0x0) |
| 693 | srb->result = SAM_STAT_GOOD; |
| 694 | } else { |
| 695 | srb->result = DID_ERROR << 16; |
| 696 | /* Need reset here */ |
| 697 | } |
| 698 | } |
| 699 | |
Felipe Balbi | f0183a3 | 2016-04-18 13:09:11 +0300 | [diff] [blame] | 700 | /* |
| 701 | * Regardless of auto-sense, if we _know_ we have an error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | * condition, show that in the result code |
| 703 | */ |
| 704 | if (transferStatus == USB_STOR_TRANSPORT_FAILED) |
| 705 | srb->result = SAM_STAT_CHECK_CONDITION; |
| 706 | return; |
| 707 | |
Felipe Balbi | f0183a3 | 2016-04-18 13:09:11 +0300 | [diff] [blame] | 708 | /* |
| 709 | * abort processing: the bulk-only transport requires a reset |
| 710 | * following an abort |
| 711 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | Handle_Abort: |
| 713 | srb->result = DID_ABORT << 16; |
| 714 | |
| 715 | /* permit the reset transfer to take place */ |
Alan Stern | 7e4d6c3 | 2008-05-01 15:35:18 -0400 | [diff] [blame] | 716 | clear_bit(US_FLIDX_ABORTING, &us->dflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | /* Need reset here */ |
| 718 | } |
| 719 | |
| 720 | #ifdef CONFIG_USB_STORAGE_DEBUG |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 721 | static void isd200_log_config(struct us_data *us, struct isd200_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 723 | usb_stor_dbg(us, " Event Notification: 0x%x\n", |
| 724 | info->ConfigData.EventNotification); |
| 725 | usb_stor_dbg(us, " External Clock: 0x%x\n", |
| 726 | info->ConfigData.ExternalClock); |
| 727 | usb_stor_dbg(us, " ATA Init Timeout: 0x%x\n", |
| 728 | info->ConfigData.ATAInitTimeout); |
| 729 | usb_stor_dbg(us, " ATAPI Command Block Size: 0x%x\n", |
| 730 | (info->ConfigData.ATAConfig & ATACFG_BLOCKSIZE) >> 6); |
| 731 | usb_stor_dbg(us, " Master/Slave Selection: 0x%x\n", |
| 732 | info->ConfigData.ATAConfig & ATACFG_MASTER); |
| 733 | usb_stor_dbg(us, " ATAPI Reset: 0x%x\n", |
| 734 | info->ConfigData.ATAConfig & ATACFG_ATAPI_RESET); |
| 735 | usb_stor_dbg(us, " ATA Timing: 0x%x\n", |
| 736 | info->ConfigData.ATAConfig & ATACFG_TIMING); |
| 737 | usb_stor_dbg(us, " ATA Major Command: 0x%x\n", |
| 738 | info->ConfigData.ATAMajorCommand); |
| 739 | usb_stor_dbg(us, " ATA Minor Command: 0x%x\n", |
| 740 | info->ConfigData.ATAMinorCommand); |
| 741 | usb_stor_dbg(us, " Init Status: 0x%x\n", |
| 742 | info->ConfigData.ATAExtraConfig & ATACFGE_INIT_STATUS); |
| 743 | usb_stor_dbg(us, " Config Descriptor 2: 0x%x\n", |
| 744 | info->ConfigData.ATAExtraConfig & ATACFGE_CONF_DESC2); |
| 745 | usb_stor_dbg(us, " Skip Device Boot: 0x%x\n", |
| 746 | info->ConfigData.ATAExtraConfig & ATACFGE_SKIP_BOOT); |
Yannick Guerrini | 333c65b | 2015-02-24 16:42:45 +0100 | [diff] [blame] | 747 | usb_stor_dbg(us, " ATA 3 State Suspend: 0x%x\n", |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 748 | info->ConfigData.ATAExtraConfig & ATACFGE_STATE_SUSPEND); |
| 749 | usb_stor_dbg(us, " Descriptor Override: 0x%x\n", |
| 750 | info->ConfigData.ATAExtraConfig & ATACFGE_DESC_OVERRIDE); |
| 751 | usb_stor_dbg(us, " Last LUN Identifier: 0x%x\n", |
| 752 | info->ConfigData.ATAExtraConfig & ATACFGE_LAST_LUN); |
| 753 | usb_stor_dbg(us, " SRST Enable: 0x%x\n", |
| 754 | info->ConfigData.ATAExtraConfig & CFG_CAPABILITY_SRST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | } |
| 756 | #endif |
| 757 | |
| 758 | /************************************************************************** |
| 759 | * isd200_write_config |
| 760 | * |
| 761 | * Write the ISD200 Configuration data |
| 762 | * |
| 763 | * RETURNS: |
| 764 | * ISD status code |
| 765 | */ |
| 766 | static int isd200_write_config( struct us_data *us ) |
| 767 | { |
| 768 | struct isd200_info *info = (struct isd200_info *)us->extra; |
| 769 | int retStatus = ISD200_GOOD; |
| 770 | int result; |
| 771 | |
| 772 | #ifdef CONFIG_USB_STORAGE_DEBUG |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 773 | usb_stor_dbg(us, "Entering isd200_write_config\n"); |
| 774 | usb_stor_dbg(us, " Writing the following ISD200 Config Data:\n"); |
| 775 | isd200_log_config(us, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | #endif |
| 777 | |
| 778 | /* let's send the command via the control pipe */ |
| 779 | result = usb_stor_ctrl_transfer( |
| 780 | us, |
| 781 | us->send_ctrl_pipe, |
| 782 | 0x01, |
| 783 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, |
| 784 | 0x0000, |
| 785 | 0x0002, |
| 786 | (void *) &info->ConfigData, |
| 787 | sizeof(info->ConfigData)); |
| 788 | |
| 789 | if (result >= 0) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 790 | usb_stor_dbg(us, " ISD200 Config Data was written successfully\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } else { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 792 | usb_stor_dbg(us, " Request to write ISD200 Config Data failed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | retStatus = ISD200_ERROR; |
| 794 | } |
| 795 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 796 | usb_stor_dbg(us, "Leaving isd200_write_config %08X\n", retStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | return retStatus; |
| 798 | } |
| 799 | |
| 800 | |
| 801 | /************************************************************************** |
| 802 | * isd200_read_config |
| 803 | * |
| 804 | * Reads the ISD200 Configuration data |
| 805 | * |
| 806 | * RETURNS: |
| 807 | * ISD status code |
| 808 | */ |
| 809 | static int isd200_read_config( struct us_data *us ) |
| 810 | { |
| 811 | struct isd200_info *info = (struct isd200_info *)us->extra; |
| 812 | int retStatus = ISD200_GOOD; |
| 813 | int result; |
| 814 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 815 | usb_stor_dbg(us, "Entering isd200_read_config\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | |
| 817 | /* read the configuration information from ISD200. Use this to */ |
| 818 | /* determine what the special ATA CDB bytes are. */ |
| 819 | |
| 820 | result = usb_stor_ctrl_transfer( |
| 821 | us, |
| 822 | us->recv_ctrl_pipe, |
| 823 | 0x02, |
| 824 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
| 825 | 0x0000, |
| 826 | 0x0002, |
| 827 | (void *) &info->ConfigData, |
| 828 | sizeof(info->ConfigData)); |
| 829 | |
| 830 | |
| 831 | if (result >= 0) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 832 | usb_stor_dbg(us, " Retrieved the following ISD200 Config Data:\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | #ifdef CONFIG_USB_STORAGE_DEBUG |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 834 | isd200_log_config(us, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | #endif |
| 836 | } else { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 837 | usb_stor_dbg(us, " Request to get ISD200 Config Data failed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | retStatus = ISD200_ERROR; |
| 839 | } |
| 840 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 841 | usb_stor_dbg(us, "Leaving isd200_read_config %08X\n", retStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | return retStatus; |
| 843 | } |
| 844 | |
| 845 | |
| 846 | /************************************************************************** |
| 847 | * isd200_atapi_soft_reset |
| 848 | * |
| 849 | * Perform an Atapi Soft Reset on the device |
| 850 | * |
| 851 | * RETURNS: |
| 852 | * NT status code |
| 853 | */ |
| 854 | static int isd200_atapi_soft_reset( struct us_data *us ) |
| 855 | { |
| 856 | int retStatus = ISD200_GOOD; |
| 857 | int transferStatus; |
| 858 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 859 | usb_stor_dbg(us, "Entering isd200_atapi_soft_reset\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
| 861 | transferStatus = isd200_action( us, ACTION_SOFT_RESET, NULL, 0 ); |
| 862 | if (transferStatus != ISD200_TRANSPORT_GOOD) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 863 | usb_stor_dbg(us, " Error issuing Atapi Soft Reset\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | retStatus = ISD200_ERROR; |
| 865 | } |
| 866 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 867 | usb_stor_dbg(us, "Leaving isd200_atapi_soft_reset %08X\n", retStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | return retStatus; |
| 869 | } |
| 870 | |
| 871 | |
| 872 | /************************************************************************** |
| 873 | * isd200_srst |
| 874 | * |
| 875 | * Perform an SRST on the device |
| 876 | * |
| 877 | * RETURNS: |
| 878 | * ISD status code |
| 879 | */ |
| 880 | static int isd200_srst( struct us_data *us ) |
| 881 | { |
| 882 | int retStatus = ISD200_GOOD; |
| 883 | int transferStatus; |
| 884 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 885 | usb_stor_dbg(us, "Entering isd200_SRST\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
| 887 | transferStatus = isd200_action( us, ACTION_RESET, NULL, 0 ); |
| 888 | |
| 889 | /* check to see if this request failed */ |
| 890 | if (transferStatus != ISD200_TRANSPORT_GOOD) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 891 | usb_stor_dbg(us, " Error issuing SRST\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | retStatus = ISD200_ERROR; |
| 893 | } else { |
| 894 | /* delay 10ms to give the drive a chance to see it */ |
| 895 | msleep(10); |
| 896 | |
| 897 | transferStatus = isd200_action( us, ACTION_REENABLE, NULL, 0 ); |
| 898 | if (transferStatus != ISD200_TRANSPORT_GOOD) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 899 | usb_stor_dbg(us, " Error taking drive out of reset\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | retStatus = ISD200_ERROR; |
| 901 | } else { |
| 902 | /* delay 50ms to give the drive a chance to recover after SRST */ |
| 903 | msleep(50); |
| 904 | } |
| 905 | } |
| 906 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 907 | usb_stor_dbg(us, "Leaving isd200_srst %08X\n", retStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | return retStatus; |
| 909 | } |
| 910 | |
| 911 | |
| 912 | /************************************************************************** |
| 913 | * isd200_try_enum |
| 914 | * |
| 915 | * Helper function for isd200_manual_enum(). Does ENUM and READ_STATUS |
| 916 | * and tries to analyze the status registers |
| 917 | * |
| 918 | * RETURNS: |
| 919 | * ISD status code |
| 920 | */ |
| 921 | static int isd200_try_enum(struct us_data *us, unsigned char master_slave, |
| 922 | int detect ) |
| 923 | { |
| 924 | int status = ISD200_GOOD; |
| 925 | unsigned long endTime; |
| 926 | struct isd200_info *info = (struct isd200_info *)us->extra; |
| 927 | unsigned char *regs = info->RegsBuf; |
| 928 | int recheckAsMaster = 0; |
| 929 | |
| 930 | if ( detect ) |
| 931 | endTime = jiffies + ISD200_ENUM_DETECT_TIMEOUT * HZ; |
| 932 | else |
| 933 | endTime = jiffies + ISD200_ENUM_BSY_TIMEOUT * HZ; |
| 934 | |
| 935 | /* loop until we detect !BSY or timeout */ |
| 936 | while(1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
| 938 | status = isd200_action( us, ACTION_ENUM, NULL, master_slave ); |
| 939 | if ( status != ISD200_GOOD ) |
| 940 | break; |
| 941 | |
| 942 | status = isd200_action( us, ACTION_READ_STATUS, |
| 943 | regs, 8 ); |
| 944 | if ( status != ISD200_GOOD ) |
| 945 | break; |
| 946 | |
| 947 | if (!detect) { |
Bartlomiej Zolnierkiewicz | fcd3ec6 | 2009-04-01 21:42:25 +0200 | [diff] [blame] | 948 | if (regs[ATA_REG_STATUS_OFFSET] & ATA_BUSY) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 949 | usb_stor_dbg(us, " %s status is still BSY, try again...\n", |
| 950 | master_slave == ATA_ADDRESS_DEVHEAD_STD ? |
| 951 | "Master" : "Slave"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | } else { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 953 | usb_stor_dbg(us, " %s status !BSY, continue with next operation\n", |
| 954 | master_slave == ATA_ADDRESS_DEVHEAD_STD ? |
| 955 | "Master" : "Slave"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | break; |
| 957 | } |
| 958 | } |
Bartlomiej Zolnierkiewicz | fcd3ec6 | 2009-04-01 21:42:25 +0200 | [diff] [blame] | 959 | /* check for ATA_BUSY and */ |
| 960 | /* ATA_DF (workaround ATA Zip drive) and */ |
| 961 | /* ATA_ERR (workaround for Archos CD-ROM) */ |
Bartlomiej Zolnierkiewicz | c74e809 | 2007-10-27 18:01:04 +0200 | [diff] [blame] | 962 | else if (regs[ATA_REG_STATUS_OFFSET] & |
Bartlomiej Zolnierkiewicz | fcd3ec6 | 2009-04-01 21:42:25 +0200 | [diff] [blame] | 963 | (ATA_BUSY | ATA_DF | ATA_ERR)) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 964 | usb_stor_dbg(us, " Status indicates it is not ready, try again...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | } |
| 966 | /* check for DRDY, ATA devices set DRDY after SRST */ |
Bartlomiej Zolnierkiewicz | fcd3ec6 | 2009-04-01 21:42:25 +0200 | [diff] [blame] | 967 | else if (regs[ATA_REG_STATUS_OFFSET] & ATA_DRDY) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 968 | usb_stor_dbg(us, " Identified ATA device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | info->DeviceFlags |= DF_ATA_DEVICE; |
| 970 | info->DeviceHead = master_slave; |
| 971 | break; |
| 972 | } |
Felipe Balbi | f0183a3 | 2016-04-18 13:09:11 +0300 | [diff] [blame] | 973 | /* |
| 974 | * check Cylinder High/Low to |
| 975 | * determine if it is an ATAPI device |
| 976 | */ |
Bartlomiej Zolnierkiewicz | c74e809 | 2007-10-27 18:01:04 +0200 | [diff] [blame] | 977 | else if (regs[ATA_REG_HCYL_OFFSET] == 0xEB && |
| 978 | regs[ATA_REG_LCYL_OFFSET] == 0x14) { |
Felipe Balbi | f0183a3 | 2016-04-18 13:09:11 +0300 | [diff] [blame] | 979 | /* |
| 980 | * It seems that the RICOH |
| 981 | * MP6200A CD/RW drive will |
| 982 | * report itself okay as a |
| 983 | * slave when it is really a |
| 984 | * master. So this check again |
| 985 | * as a master device just to |
| 986 | * make sure it doesn't report |
| 987 | * itself okay as a master also |
| 988 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | if ((master_slave & ATA_ADDRESS_DEVHEAD_SLAVE) && |
| 990 | !recheckAsMaster) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 991 | usb_stor_dbg(us, " Identified ATAPI device as slave. Rechecking again as master\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | recheckAsMaster = 1; |
| 993 | master_slave = ATA_ADDRESS_DEVHEAD_STD; |
| 994 | } else { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 995 | usb_stor_dbg(us, " Identified ATAPI device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | info->DeviceHead = master_slave; |
| 997 | |
| 998 | status = isd200_atapi_soft_reset(us); |
| 999 | break; |
| 1000 | } |
| 1001 | } else { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1002 | usb_stor_dbg(us, " Not ATA, not ATAPI - Weird\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | break; |
| 1004 | } |
| 1005 | |
| 1006 | /* check for timeout on this request */ |
| 1007 | if (time_after_eq(jiffies, endTime)) { |
| 1008 | if (!detect) |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1009 | usb_stor_dbg(us, " BSY check timeout, just continue with next operation...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | else |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1011 | usb_stor_dbg(us, " Device detect timeout!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | break; |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | return status; |
| 1017 | } |
| 1018 | |
| 1019 | /************************************************************************** |
| 1020 | * isd200_manual_enum |
| 1021 | * |
| 1022 | * Determines if the drive attached is an ATA or ATAPI and if it is a |
| 1023 | * master or slave. |
| 1024 | * |
| 1025 | * RETURNS: |
| 1026 | * ISD status code |
| 1027 | */ |
| 1028 | static int isd200_manual_enum(struct us_data *us) |
| 1029 | { |
| 1030 | struct isd200_info *info = (struct isd200_info *)us->extra; |
| 1031 | int retStatus = ISD200_GOOD; |
| 1032 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1033 | usb_stor_dbg(us, "Entering isd200_manual_enum\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | |
| 1035 | retStatus = isd200_read_config(us); |
| 1036 | if (retStatus == ISD200_GOOD) { |
| 1037 | int isslave; |
| 1038 | /* master or slave? */ |
| 1039 | retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_STD, 0); |
| 1040 | if (retStatus == ISD200_GOOD) |
| 1041 | retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_SLAVE, 0); |
| 1042 | |
| 1043 | if (retStatus == ISD200_GOOD) { |
| 1044 | retStatus = isd200_srst(us); |
| 1045 | if (retStatus == ISD200_GOOD) |
| 1046 | /* ata or atapi? */ |
| 1047 | retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_STD, 1); |
| 1048 | } |
| 1049 | |
| 1050 | isslave = (info->DeviceHead & ATA_ADDRESS_DEVHEAD_SLAVE) ? 1 : 0; |
| 1051 | if (!(info->ConfigData.ATAConfig & ATACFG_MASTER)) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1052 | usb_stor_dbg(us, " Setting Master/Slave selection to %d\n", |
| 1053 | isslave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | info->ConfigData.ATAConfig &= 0x3f; |
| 1055 | info->ConfigData.ATAConfig |= (isslave<<6); |
| 1056 | retStatus = isd200_write_config(us); |
| 1057 | } |
| 1058 | } |
| 1059 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1060 | usb_stor_dbg(us, "Leaving isd200_manual_enum %08X\n", retStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | return(retStatus); |
| 1062 | } |
| 1063 | |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1064 | static void isd200_fix_driveid(u16 *id) |
Alan Cox | 3794ade | 2007-10-15 15:08:11 +0100 | [diff] [blame] | 1065 | { |
| 1066 | #ifndef __LITTLE_ENDIAN |
| 1067 | # ifdef __BIG_ENDIAN |
| 1068 | int i; |
Alan Cox | 3794ade | 2007-10-15 15:08:11 +0100 | [diff] [blame] | 1069 | |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1070 | for (i = 0; i < ATA_ID_WORDS; i++) |
| 1071 | id[i] = __le16_to_cpu(id[i]); |
Alan Cox | 3794ade | 2007-10-15 15:08:11 +0100 | [diff] [blame] | 1072 | # else |
| 1073 | # error "Please fix <asm/byteorder.h>" |
| 1074 | # endif |
| 1075 | #endif |
| 1076 | } |
| 1077 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1078 | static void isd200_dump_driveid(struct us_data *us, u16 *id) |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1079 | { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1080 | usb_stor_dbg(us, " Identify Data Structure:\n"); |
| 1081 | usb_stor_dbg(us, " config = 0x%x\n", id[ATA_ID_CONFIG]); |
| 1082 | usb_stor_dbg(us, " cyls = 0x%x\n", id[ATA_ID_CYLS]); |
| 1083 | usb_stor_dbg(us, " heads = 0x%x\n", id[ATA_ID_HEADS]); |
| 1084 | usb_stor_dbg(us, " track_bytes = 0x%x\n", id[4]); |
| 1085 | usb_stor_dbg(us, " sector_bytes = 0x%x\n", id[5]); |
| 1086 | usb_stor_dbg(us, " sectors = 0x%x\n", id[ATA_ID_SECTORS]); |
| 1087 | usb_stor_dbg(us, " serial_no[0] = 0x%x\n", *(char *)&id[ATA_ID_SERNO]); |
| 1088 | usb_stor_dbg(us, " buf_type = 0x%x\n", id[20]); |
| 1089 | usb_stor_dbg(us, " buf_size = 0x%x\n", id[ATA_ID_BUF_SIZE]); |
| 1090 | usb_stor_dbg(us, " ecc_bytes = 0x%x\n", id[22]); |
| 1091 | usb_stor_dbg(us, " fw_rev[0] = 0x%x\n", *(char *)&id[ATA_ID_FW_REV]); |
| 1092 | usb_stor_dbg(us, " model[0] = 0x%x\n", *(char *)&id[ATA_ID_PROD]); |
| 1093 | usb_stor_dbg(us, " max_multsect = 0x%x\n", id[ATA_ID_MAX_MULTSECT] & 0xff); |
| 1094 | usb_stor_dbg(us, " dword_io = 0x%x\n", id[ATA_ID_DWORD_IO]); |
| 1095 | usb_stor_dbg(us, " capability = 0x%x\n", id[ATA_ID_CAPABILITY] >> 8); |
| 1096 | usb_stor_dbg(us, " tPIO = 0x%x\n", id[ATA_ID_OLD_PIO_MODES] >> 8); |
| 1097 | usb_stor_dbg(us, " tDMA = 0x%x\n", id[ATA_ID_OLD_DMA_MODES] >> 8); |
| 1098 | usb_stor_dbg(us, " field_valid = 0x%x\n", id[ATA_ID_FIELD_VALID]); |
| 1099 | usb_stor_dbg(us, " cur_cyls = 0x%x\n", id[ATA_ID_CUR_CYLS]); |
| 1100 | usb_stor_dbg(us, " cur_heads = 0x%x\n", id[ATA_ID_CUR_HEADS]); |
| 1101 | usb_stor_dbg(us, " cur_sectors = 0x%x\n", id[ATA_ID_CUR_SECTORS]); |
| 1102 | usb_stor_dbg(us, " cur_capacity = 0x%x\n", ata_id_u32(id, 57)); |
| 1103 | usb_stor_dbg(us, " multsect = 0x%x\n", id[ATA_ID_MULTSECT] & 0xff); |
| 1104 | usb_stor_dbg(us, " lba_capacity = 0x%x\n", ata_id_u32(id, ATA_ID_LBA_CAPACITY)); |
| 1105 | usb_stor_dbg(us, " command_set_1 = 0x%x\n", id[ATA_ID_COMMAND_SET_1]); |
| 1106 | usb_stor_dbg(us, " command_set_2 = 0x%x\n", id[ATA_ID_COMMAND_SET_2]); |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1107 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
| 1109 | /************************************************************************** |
| 1110 | * isd200_get_inquiry_data |
| 1111 | * |
| 1112 | * Get inquiry data |
| 1113 | * |
| 1114 | * RETURNS: |
| 1115 | * ISD status code |
| 1116 | */ |
| 1117 | static int isd200_get_inquiry_data( struct us_data *us ) |
| 1118 | { |
| 1119 | struct isd200_info *info = (struct isd200_info *)us->extra; |
| 1120 | int retStatus = ISD200_GOOD; |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1121 | u16 *id = info->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1123 | usb_stor_dbg(us, "Entering isd200_get_inquiry_data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | |
| 1125 | /* set default to Master */ |
| 1126 | info->DeviceHead = ATA_ADDRESS_DEVHEAD_STD; |
| 1127 | |
| 1128 | /* attempt to manually enumerate this device */ |
| 1129 | retStatus = isd200_manual_enum(us); |
| 1130 | if (retStatus == ISD200_GOOD) { |
| 1131 | int transferStatus; |
| 1132 | |
| 1133 | /* check for an ATA device */ |
| 1134 | if (info->DeviceFlags & DF_ATA_DEVICE) { |
| 1135 | /* this must be an ATA device */ |
| 1136 | /* perform an ATA Command Identify */ |
| 1137 | transferStatus = isd200_action( us, ACTION_IDENTIFY, |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1138 | id, ATA_ID_WORDS * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | if (transferStatus != ISD200_TRANSPORT_GOOD) { |
| 1140 | /* Error issuing ATA Command Identify */ |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1141 | usb_stor_dbg(us, " Error issuing ATA Command Identify\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | retStatus = ISD200_ERROR; |
| 1143 | } else { |
| 1144 | /* ATA Command Identify successful */ |
| 1145 | int i; |
| 1146 | __be16 *src; |
| 1147 | __u16 *dest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1149 | isd200_fix_driveid(id); |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1150 | isd200_dump_driveid(us, id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
| 1152 | memset(&info->InquiryData, 0, sizeof(info->InquiryData)); |
| 1153 | |
| 1154 | /* Standard IDE interface only supports disks */ |
| 1155 | info->InquiryData.DeviceType = DIRECT_ACCESS_DEVICE; |
| 1156 | |
| 1157 | /* The length must be at least 36 (5 + 31) */ |
| 1158 | info->InquiryData.AdditionalLength = 0x1F; |
| 1159 | |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1160 | if (id[ATA_ID_COMMAND_SET_1] & COMMANDSET_MEDIA_STATUS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | /* set the removable bit */ |
| 1162 | info->InquiryData.DeviceTypeModifier = DEVICE_REMOVABLE; |
| 1163 | info->DeviceFlags |= DF_REMOVABLE_MEDIA; |
| 1164 | } |
| 1165 | |
| 1166 | /* Fill in vendor identification fields */ |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1167 | src = (__be16 *)&id[ATA_ID_PROD]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | dest = (__u16*)info->InquiryData.VendorId; |
| 1169 | for (i=0;i<4;i++) |
| 1170 | dest[i] = be16_to_cpu(src[i]); |
| 1171 | |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1172 | src = (__be16 *)&id[ATA_ID_PROD + 8/2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | dest = (__u16*)info->InquiryData.ProductId; |
| 1174 | for (i=0;i<8;i++) |
| 1175 | dest[i] = be16_to_cpu(src[i]); |
| 1176 | |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1177 | src = (__be16 *)&id[ATA_ID_FW_REV]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | dest = (__u16*)info->InquiryData.ProductRevisionLevel; |
| 1179 | for (i=0;i<2;i++) |
| 1180 | dest[i] = be16_to_cpu(src[i]); |
| 1181 | |
| 1182 | /* determine if it supports Media Status Notification */ |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1183 | if (id[ATA_ID_COMMAND_SET_2] & COMMANDSET_MEDIA_STATUS) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1184 | usb_stor_dbg(us, " Device supports Media Status Notification\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | |
Felipe Balbi | f0183a3 | 2016-04-18 13:09:11 +0300 | [diff] [blame] | 1186 | /* |
| 1187 | * Indicate that it is enabled, even |
| 1188 | * though it is not. |
| 1189 | * This allows the lock/unlock of the |
| 1190 | * media to work correctly. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | */ |
| 1192 | info->DeviceFlags |= DF_MEDIA_STATUS_ENABLED; |
| 1193 | } |
| 1194 | else |
| 1195 | info->DeviceFlags &= ~DF_MEDIA_STATUS_ENABLED; |
| 1196 | |
| 1197 | } |
| 1198 | } else { |
| 1199 | /* |
| 1200 | * this must be an ATAPI device |
| 1201 | * use an ATAPI protocol (Transparent SCSI) |
| 1202 | */ |
| 1203 | us->protocol_name = "Transparent SCSI"; |
| 1204 | us->proto_handler = usb_stor_transparent_scsi_command; |
| 1205 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1206 | usb_stor_dbg(us, "Protocol changed to: %s\n", |
| 1207 | us->protocol_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | |
Felipe Balbi | f0183a3 | 2016-04-18 13:09:11 +0300 | [diff] [blame] | 1209 | /* Free driver structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | us->extra_destructor(info); |
Boaz Harrosh | ba2ef3b | 2008-03-17 14:21:01 -0700 | [diff] [blame] | 1211 | kfree(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | us->extra = NULL; |
| 1213 | us->extra_destructor = NULL; |
| 1214 | } |
| 1215 | } |
| 1216 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1217 | usb_stor_dbg(us, "Leaving isd200_get_inquiry_data %08X\n", retStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
| 1219 | return(retStatus); |
| 1220 | } |
| 1221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | /************************************************************************** |
| 1223 | * isd200_scsi_to_ata |
| 1224 | * |
| 1225 | * Translate SCSI commands to ATA commands. |
| 1226 | * |
| 1227 | * RETURNS: |
| 1228 | * 1 if the command needs to be sent to the transport layer |
| 1229 | * 0 otherwise |
| 1230 | */ |
| 1231 | static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us, |
| 1232 | union ata_cdb * ataCdb) |
| 1233 | { |
| 1234 | struct isd200_info *info = (struct isd200_info *)us->extra; |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1235 | u16 *id = info->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | int sendToTransport = 1; |
| 1237 | unsigned char sectnum, head; |
| 1238 | unsigned short cylinder; |
| 1239 | unsigned long lba; |
| 1240 | unsigned long blockCount; |
| 1241 | unsigned char senseData[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 1242 | |
| 1243 | memset(ataCdb, 0, sizeof(union ata_cdb)); |
| 1244 | |
| 1245 | /* SCSI Command */ |
| 1246 | switch (srb->cmnd[0]) { |
| 1247 | case INQUIRY: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1248 | usb_stor_dbg(us, " ATA OUT - INQUIRY\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | |
| 1250 | /* copy InquiryData */ |
| 1251 | usb_stor_set_xfer_buf((unsigned char *) &info->InquiryData, |
| 1252 | sizeof(info->InquiryData), srb); |
| 1253 | srb->result = SAM_STAT_GOOD; |
| 1254 | sendToTransport = 0; |
| 1255 | break; |
| 1256 | |
| 1257 | case MODE_SENSE: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1258 | usb_stor_dbg(us, " ATA OUT - SCSIOP_MODE_SENSE\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | |
| 1260 | /* Initialize the return buffer */ |
| 1261 | usb_stor_set_xfer_buf(senseData, sizeof(senseData), srb); |
| 1262 | |
| 1263 | if (info->DeviceFlags & DF_MEDIA_STATUS_ENABLED) |
| 1264 | { |
| 1265 | ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; |
| 1266 | ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; |
| 1267 | ataCdb->generic.TransferBlockSize = 1; |
| 1268 | ataCdb->generic.RegisterSelect = REG_COMMAND; |
| 1269 | ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 1270 | isd200_srb_set_bufflen(srb, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | } else { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1272 | usb_stor_dbg(us, " Media Status not supported, just report okay\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | srb->result = SAM_STAT_GOOD; |
| 1274 | sendToTransport = 0; |
| 1275 | } |
| 1276 | break; |
| 1277 | |
| 1278 | case TEST_UNIT_READY: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1279 | usb_stor_dbg(us, " ATA OUT - SCSIOP_TEST_UNIT_READY\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | |
| 1281 | if (info->DeviceFlags & DF_MEDIA_STATUS_ENABLED) |
| 1282 | { |
| 1283 | ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; |
| 1284 | ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; |
| 1285 | ataCdb->generic.TransferBlockSize = 1; |
| 1286 | ataCdb->generic.RegisterSelect = REG_COMMAND; |
| 1287 | ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 1288 | isd200_srb_set_bufflen(srb, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | } else { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1290 | usb_stor_dbg(us, " Media Status not supported, just report okay\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | srb->result = SAM_STAT_GOOD; |
| 1292 | sendToTransport = 0; |
| 1293 | } |
| 1294 | break; |
| 1295 | |
| 1296 | case READ_CAPACITY: |
| 1297 | { |
| 1298 | unsigned long capacity; |
| 1299 | struct read_capacity_data readCapacityData; |
| 1300 | |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1301 | usb_stor_dbg(us, " ATA OUT - SCSIOP_READ_CAPACITY\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1303 | if (ata_id_has_lba(id)) |
| 1304 | capacity = ata_id_u32(id, ATA_ID_LBA_CAPACITY) - 1; |
| 1305 | else |
| 1306 | capacity = (id[ATA_ID_HEADS] * id[ATA_ID_CYLS] * |
| 1307 | id[ATA_ID_SECTORS]) - 1; |
| 1308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | readCapacityData.LogicalBlockAddress = cpu_to_be32(capacity); |
| 1310 | readCapacityData.BytesPerBlock = cpu_to_be32(0x200); |
| 1311 | |
| 1312 | usb_stor_set_xfer_buf((unsigned char *) &readCapacityData, |
| 1313 | sizeof(readCapacityData), srb); |
| 1314 | srb->result = SAM_STAT_GOOD; |
| 1315 | sendToTransport = 0; |
| 1316 | } |
| 1317 | break; |
| 1318 | |
| 1319 | case READ_10: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1320 | usb_stor_dbg(us, " ATA OUT - SCSIOP_READ\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | |
| 1322 | lba = be32_to_cpu(*(__be32 *)&srb->cmnd[2]); |
| 1323 | blockCount = (unsigned long)srb->cmnd[7]<<8 | (unsigned long)srb->cmnd[8]; |
| 1324 | |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1325 | if (ata_id_has_lba(id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | sectnum = (unsigned char)(lba); |
| 1327 | cylinder = (unsigned short)(lba>>8); |
| 1328 | head = ATA_ADDRESS_DEVHEAD_LBA_MODE | (unsigned char)(lba>>24 & 0x0F); |
| 1329 | } else { |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1330 | sectnum = (u8)((lba % id[ATA_ID_SECTORS]) + 1); |
| 1331 | cylinder = (u16)(lba / (id[ATA_ID_SECTORS] * |
| 1332 | id[ATA_ID_HEADS])); |
| 1333 | head = (u8)((lba / id[ATA_ID_SECTORS]) % |
| 1334 | id[ATA_ID_HEADS]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | } |
| 1336 | ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; |
| 1337 | ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; |
| 1338 | ataCdb->generic.TransferBlockSize = 1; |
| 1339 | ataCdb->generic.RegisterSelect = |
| 1340 | REG_SECTOR_COUNT | REG_SECTOR_NUMBER | |
| 1341 | REG_CYLINDER_LOW | REG_CYLINDER_HIGH | |
| 1342 | REG_DEVICE_HEAD | REG_COMMAND; |
| 1343 | ataCdb->write.SectorCountByte = (unsigned char)blockCount; |
| 1344 | ataCdb->write.SectorNumberByte = sectnum; |
| 1345 | ataCdb->write.CylinderHighByte = (unsigned char)(cylinder>>8); |
| 1346 | ataCdb->write.CylinderLowByte = (unsigned char)cylinder; |
| 1347 | ataCdb->write.DeviceHeadByte = (head | ATA_ADDRESS_DEVHEAD_STD); |
Bartlomiej Zolnierkiewicz | f08f31f | 2009-04-01 21:42:24 +0200 | [diff] [blame] | 1348 | ataCdb->write.CommandByte = ATA_CMD_PIO_READ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | break; |
| 1350 | |
| 1351 | case WRITE_10: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1352 | usb_stor_dbg(us, " ATA OUT - SCSIOP_WRITE\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | |
| 1354 | lba = be32_to_cpu(*(__be32 *)&srb->cmnd[2]); |
| 1355 | blockCount = (unsigned long)srb->cmnd[7]<<8 | (unsigned long)srb->cmnd[8]; |
| 1356 | |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1357 | if (ata_id_has_lba(id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | sectnum = (unsigned char)(lba); |
| 1359 | cylinder = (unsigned short)(lba>>8); |
| 1360 | head = ATA_ADDRESS_DEVHEAD_LBA_MODE | (unsigned char)(lba>>24 & 0x0F); |
| 1361 | } else { |
Bartlomiej Zolnierkiewicz | d8881cd | 2009-04-01 21:42:19 +0200 | [diff] [blame] | 1362 | sectnum = (u8)((lba % id[ATA_ID_SECTORS]) + 1); |
| 1363 | cylinder = (u16)(lba / (id[ATA_ID_SECTORS] * |
| 1364 | id[ATA_ID_HEADS])); |
| 1365 | head = (u8)((lba / id[ATA_ID_SECTORS]) % |
| 1366 | id[ATA_ID_HEADS]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | } |
| 1368 | ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; |
| 1369 | ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; |
| 1370 | ataCdb->generic.TransferBlockSize = 1; |
| 1371 | ataCdb->generic.RegisterSelect = |
| 1372 | REG_SECTOR_COUNT | REG_SECTOR_NUMBER | |
| 1373 | REG_CYLINDER_LOW | REG_CYLINDER_HIGH | |
| 1374 | REG_DEVICE_HEAD | REG_COMMAND; |
| 1375 | ataCdb->write.SectorCountByte = (unsigned char)blockCount; |
| 1376 | ataCdb->write.SectorNumberByte = sectnum; |
| 1377 | ataCdb->write.CylinderHighByte = (unsigned char)(cylinder>>8); |
| 1378 | ataCdb->write.CylinderLowByte = (unsigned char)cylinder; |
| 1379 | ataCdb->write.DeviceHeadByte = (head | ATA_ADDRESS_DEVHEAD_STD); |
Bartlomiej Zolnierkiewicz | f08f31f | 2009-04-01 21:42:24 +0200 | [diff] [blame] | 1380 | ataCdb->write.CommandByte = ATA_CMD_PIO_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | break; |
| 1382 | |
| 1383 | case ALLOW_MEDIUM_REMOVAL: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1384 | usb_stor_dbg(us, " ATA OUT - SCSIOP_MEDIUM_REMOVAL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | |
| 1386 | if (info->DeviceFlags & DF_REMOVABLE_MEDIA) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1387 | usb_stor_dbg(us, " srb->cmnd[4] = 0x%X\n", |
| 1388 | srb->cmnd[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | |
| 1390 | ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; |
| 1391 | ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; |
| 1392 | ataCdb->generic.TransferBlockSize = 1; |
| 1393 | ataCdb->generic.RegisterSelect = REG_COMMAND; |
| 1394 | ataCdb->write.CommandByte = (srb->cmnd[4] & 0x1) ? |
Bartlomiej Zolnierkiewicz | f08f31f | 2009-04-01 21:42:24 +0200 | [diff] [blame] | 1395 | ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 1396 | isd200_srb_set_bufflen(srb, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | } else { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1398 | usb_stor_dbg(us, " Not removeable media, just report okay\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | srb->result = SAM_STAT_GOOD; |
| 1400 | sendToTransport = 0; |
| 1401 | } |
| 1402 | break; |
| 1403 | |
| 1404 | case START_STOP: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1405 | usb_stor_dbg(us, " ATA OUT - SCSIOP_START_STOP_UNIT\n"); |
| 1406 | usb_stor_dbg(us, " srb->cmnd[4] = 0x%X\n", srb->cmnd[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | |
| 1408 | if ((srb->cmnd[4] & 0x3) == 0x2) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1409 | usb_stor_dbg(us, " Media Eject\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; |
| 1411 | ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; |
| 1412 | ataCdb->generic.TransferBlockSize = 0; |
| 1413 | ataCdb->generic.RegisterSelect = REG_COMMAND; |
| 1414 | ataCdb->write.CommandByte = ATA_COMMAND_MEDIA_EJECT; |
| 1415 | } else if ((srb->cmnd[4] & 0x3) == 0x1) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1416 | usb_stor_dbg(us, " Get Media Status\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; |
| 1418 | ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; |
| 1419 | ataCdb->generic.TransferBlockSize = 1; |
| 1420 | ataCdb->generic.RegisterSelect = REG_COMMAND; |
| 1421 | ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS; |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 1422 | isd200_srb_set_bufflen(srb, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | } else { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1424 | usb_stor_dbg(us, " Nothing to do, just report okay\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | srb->result = SAM_STAT_GOOD; |
| 1426 | sendToTransport = 0; |
| 1427 | } |
| 1428 | break; |
| 1429 | |
| 1430 | default: |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1431 | usb_stor_dbg(us, "Unsupported SCSI command - 0x%X\n", |
| 1432 | srb->cmnd[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | srb->result = DID_ERROR << 16; |
| 1434 | sendToTransport = 0; |
| 1435 | break; |
| 1436 | } |
| 1437 | |
| 1438 | return(sendToTransport); |
| 1439 | } |
| 1440 | |
| 1441 | |
| 1442 | /************************************************************************** |
| 1443 | * isd200_free_info |
| 1444 | * |
| 1445 | * Frees the driver structure. |
| 1446 | */ |
| 1447 | static void isd200_free_info_ptrs(void *info_) |
| 1448 | { |
| 1449 | struct isd200_info *info = (struct isd200_info *) info_; |
| 1450 | |
| 1451 | if (info) { |
| 1452 | kfree(info->id); |
| 1453 | kfree(info->RegsBuf); |
Boaz Harrosh | e92e63a | 2008-03-12 19:20:09 +0200 | [diff] [blame] | 1454 | kfree(info->srb.sense_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | /************************************************************************** |
| 1459 | * isd200_init_info |
| 1460 | * |
| 1461 | * Allocates (if necessary) and initializes the driver structure. |
| 1462 | * |
| 1463 | * RETURNS: |
| 1464 | * ISD status code |
| 1465 | */ |
| 1466 | static int isd200_init_info(struct us_data *us) |
| 1467 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | struct isd200_info *info; |
| 1469 | |
Joe Perches | a5cc804 | 2010-05-31 20:23:19 -0700 | [diff] [blame] | 1470 | info = kzalloc(sizeof(struct isd200_info), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | if (!info) |
Kris Borer | 8091e0c | 2015-08-28 09:31:43 -0400 | [diff] [blame] | 1472 | return ISD200_ERROR; |
| 1473 | |
| 1474 | info->id = kzalloc(ATA_ID_WORDS * 2, GFP_KERNEL); |
| 1475 | info->RegsBuf = kmalloc(sizeof(info->ATARegs), GFP_KERNEL); |
| 1476 | info->srb.sense_buffer = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); |
| 1477 | |
| 1478 | if (!info->id || !info->RegsBuf || !info->srb.sense_buffer) { |
| 1479 | isd200_free_info_ptrs(info); |
| 1480 | kfree(info); |
| 1481 | return ISD200_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
Kris Borer | 8091e0c | 2015-08-28 09:31:43 -0400 | [diff] [blame] | 1484 | us->extra = info; |
| 1485 | us->extra_destructor = isd200_free_info_ptrs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | |
Kris Borer | 8091e0c | 2015-08-28 09:31:43 -0400 | [diff] [blame] | 1487 | return ISD200_GOOD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | /************************************************************************** |
| 1491 | * Initialization for the ISD200 |
| 1492 | */ |
| 1493 | |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 1494 | static int isd200_Initialization(struct us_data *us) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1496 | usb_stor_dbg(us, "ISD200 Initialization...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | |
| 1498 | /* Initialize ISD200 info struct */ |
| 1499 | |
| 1500 | if (isd200_init_info(us) == ISD200_ERROR) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1501 | usb_stor_dbg(us, "ERROR Initializing ISD200 Info struct\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | } else { |
| 1503 | /* Get device specific data */ |
| 1504 | |
| 1505 | if (isd200_get_inquiry_data(us) != ISD200_GOOD) |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1506 | usb_stor_dbg(us, "ISD200 Initialization Failure\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | else |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1508 | usb_stor_dbg(us, "ISD200 Initialization complete\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | return 0; |
| 1512 | } |
| 1513 | |
| 1514 | |
| 1515 | /************************************************************************** |
| 1516 | * Protocol and Transport for the ISD200 ASIC |
| 1517 | * |
| 1518 | * This protocol and transport are for ATA devices connected to an ISD200 |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1519 | * ASIC. An ATAPI device that is connected as a slave device will be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | * detected in the driver initialization function and the protocol will |
| 1521 | * be changed to an ATAPI protocol (Transparent SCSI). |
| 1522 | * |
| 1523 | */ |
| 1524 | |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 1525 | static void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | { |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 1527 | int sendToTransport = 1, orig_bufflen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | union ata_cdb ataCdb; |
| 1529 | |
| 1530 | /* Make sure driver was initialized */ |
| 1531 | |
Colin Ian King | 446230f | 2017-07-06 16:06:32 +0100 | [diff] [blame^] | 1532 | if (us->extra == NULL) { |
Joe Perches | 191648d | 2013-04-19 11:44:00 -0700 | [diff] [blame] | 1533 | usb_stor_dbg(us, "ERROR Driver not initialized\n"); |
Colin Ian King | 446230f | 2017-07-06 16:06:32 +0100 | [diff] [blame^] | 1534 | srb->result = DID_ERROR << 16; |
| 1535 | return; |
| 1536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 1538 | scsi_set_resid(srb, 0); |
| 1539 | /* scsi_bufflen might change in protocol translation to ata */ |
| 1540 | orig_bufflen = scsi_bufflen(srb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | sendToTransport = isd200_scsi_to_ata(srb, us, &ataCdb); |
| 1542 | |
| 1543 | /* send the command to the transport layer */ |
| 1544 | if (sendToTransport) |
| 1545 | isd200_invoke_transport(us, srb, &ataCdb); |
Boaz Harrosh | 48c23d3 | 2007-08-22 19:10:45 +0300 | [diff] [blame] | 1546 | |
| 1547 | isd200_srb_set_bufflen(srb, orig_bufflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | } |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 1549 | |
Akinobu Mita | aa519be | 2015-05-06 18:24:21 +0900 | [diff] [blame] | 1550 | static struct scsi_host_template isd200_host_template; |
| 1551 | |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 1552 | static int isd200_probe(struct usb_interface *intf, |
| 1553 | const struct usb_device_id *id) |
| 1554 | { |
| 1555 | struct us_data *us; |
| 1556 | int result; |
| 1557 | |
| 1558 | result = usb_stor_probe1(&us, intf, id, |
Akinobu Mita | aa519be | 2015-05-06 18:24:21 +0900 | [diff] [blame] | 1559 | (id - isd200_usb_ids) + isd200_unusual_dev_list, |
| 1560 | &isd200_host_template); |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 1561 | if (result) |
| 1562 | return result; |
| 1563 | |
| 1564 | us->protocol_name = "ISD200 ATA/ATAPI"; |
| 1565 | us->proto_handler = isd200_ata_command; |
| 1566 | |
| 1567 | result = usb_stor_probe2(us); |
| 1568 | return result; |
| 1569 | } |
| 1570 | |
| 1571 | static struct usb_driver isd200_driver = { |
Akinobu Mita | aa519be | 2015-05-06 18:24:21 +0900 | [diff] [blame] | 1572 | .name = DRV_NAME, |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 1573 | .probe = isd200_probe, |
| 1574 | .disconnect = usb_stor_disconnect, |
| 1575 | .suspend = usb_stor_suspend, |
| 1576 | .resume = usb_stor_resume, |
| 1577 | .reset_resume = usb_stor_reset_resume, |
| 1578 | .pre_reset = usb_stor_pre_reset, |
| 1579 | .post_reset = usb_stor_post_reset, |
| 1580 | .id_table = isd200_usb_ids, |
| 1581 | .soft_unbind = 1, |
Huajun Li | e73b2db | 2012-01-14 10:15:21 +0800 | [diff] [blame] | 1582 | .no_dynamic_id = 1, |
Alan Stern | 32d5493 | 2009-02-12 14:47:54 -0500 | [diff] [blame] | 1583 | }; |
| 1584 | |
Akinobu Mita | aa519be | 2015-05-06 18:24:21 +0900 | [diff] [blame] | 1585 | module_usb_stor_driver(isd200_driver, isd200_host_template, DRV_NAME); |