isd200.c 48 KB

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