shuttle_usbat.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Driver for SCM Microsystems (a.k.a. Shuttle) USB-ATAPI cable
  4. *
  5. * Current development and maintenance by:
  6. * (c) 2000, 2001 Robert Baruch ([email protected])
  7. * (c) 2004, 2005 Daniel Drake <[email protected]>
  8. *
  9. * Developed with the assistance of:
  10. * (c) 2002 Alan Stern <[email protected]>
  11. *
  12. * Flash support based on earlier work by:
  13. * (c) 2002 Thomas Kreiling <[email protected]>
  14. *
  15. * Many originally ATAPI devices were slightly modified to meet the USB
  16. * market by using some kind of translation from ATAPI to USB on the host,
  17. * and the peripheral would translate from USB back to ATAPI.
  18. *
  19. * SCM Microsystems (www.scmmicro.com) makes a device, sold to OEM's only,
  20. * which does the USB-to-ATAPI conversion. By obtaining the data sheet on
  21. * their device under nondisclosure agreement, I have been able to write
  22. * this driver for Linux.
  23. *
  24. * The chip used in the device can also be used for EPP and ISA translation
  25. * as well. This driver is only guaranteed to work with the ATAPI
  26. * translation.
  27. *
  28. * See the Kconfig help text for a list of devices known to be supported by
  29. * this driver.
  30. */
  31. #include <linux/errno.h>
  32. #include <linux/module.h>
  33. #include <linux/slab.h>
  34. #include <linux/cdrom.h>
  35. #include <scsi/scsi.h>
  36. #include <scsi/scsi_cmnd.h>
  37. #include "usb.h"
  38. #include "transport.h"
  39. #include "protocol.h"
  40. #include "debug.h"
  41. #include "scsiglue.h"
  42. #define DRV_NAME "ums-usbat"
  43. MODULE_DESCRIPTION("Driver for SCM Microsystems (a.k.a. Shuttle) USB-ATAPI cable");
  44. MODULE_AUTHOR("Daniel Drake <[email protected]>, Robert Baruch <[email protected]>");
  45. MODULE_LICENSE("GPL");
  46. MODULE_IMPORT_NS(USB_STORAGE);
  47. /* Supported device types */
  48. #define USBAT_DEV_HP8200 0x01
  49. #define USBAT_DEV_FLASH 0x02
  50. #define USBAT_EPP_PORT 0x10
  51. #define USBAT_EPP_REGISTER 0x30
  52. #define USBAT_ATA 0x40
  53. #define USBAT_ISA 0x50
  54. /* Commands (need to be logically OR'd with an access type */
  55. #define USBAT_CMD_READ_REG 0x00
  56. #define USBAT_CMD_WRITE_REG 0x01
  57. #define USBAT_CMD_READ_BLOCK 0x02
  58. #define USBAT_CMD_WRITE_BLOCK 0x03
  59. #define USBAT_CMD_COND_READ_BLOCK 0x04
  60. #define USBAT_CMD_COND_WRITE_BLOCK 0x05
  61. #define USBAT_CMD_WRITE_REGS 0x07
  62. /* Commands (these don't need an access type) */
  63. #define USBAT_CMD_EXEC_CMD 0x80
  64. #define USBAT_CMD_SET_FEAT 0x81
  65. #define USBAT_CMD_UIO 0x82
  66. /* Methods of accessing UIO register */
  67. #define USBAT_UIO_READ 1
  68. #define USBAT_UIO_WRITE 0
  69. /* Qualifier bits */
  70. #define USBAT_QUAL_FCQ 0x20 /* full compare */
  71. #define USBAT_QUAL_ALQ 0x10 /* auto load subcount */
  72. /* USBAT Flash Media status types */
  73. #define USBAT_FLASH_MEDIA_NONE 0
  74. #define USBAT_FLASH_MEDIA_CF 1
  75. /* USBAT Flash Media change types */
  76. #define USBAT_FLASH_MEDIA_SAME 0
  77. #define USBAT_FLASH_MEDIA_CHANGED 1
  78. /* USBAT ATA registers */
  79. #define USBAT_ATA_DATA 0x10 /* read/write data (R/W) */
  80. #define USBAT_ATA_FEATURES 0x11 /* set features (W) */
  81. #define USBAT_ATA_ERROR 0x11 /* error (R) */
  82. #define USBAT_ATA_SECCNT 0x12 /* sector count (R/W) */
  83. #define USBAT_ATA_SECNUM 0x13 /* sector number (R/W) */
  84. #define USBAT_ATA_LBA_ME 0x14 /* cylinder low (R/W) */
  85. #define USBAT_ATA_LBA_HI 0x15 /* cylinder high (R/W) */
  86. #define USBAT_ATA_DEVICE 0x16 /* head/device selection (R/W) */
  87. #define USBAT_ATA_STATUS 0x17 /* device status (R) */
  88. #define USBAT_ATA_CMD 0x17 /* device command (W) */
  89. #define USBAT_ATA_ALTSTATUS 0x0E /* status (no clear IRQ) (R) */
  90. /* USBAT User I/O Data registers */
  91. #define USBAT_UIO_EPAD 0x80 /* Enable Peripheral Control Signals */
  92. #define USBAT_UIO_CDT 0x40 /* Card Detect (Read Only) */
  93. /* CDT = ACKD & !UI1 & !UI0 */
  94. #define USBAT_UIO_1 0x20 /* I/O 1 */
  95. #define USBAT_UIO_0 0x10 /* I/O 0 */
  96. #define USBAT_UIO_EPP_ATA 0x08 /* 1=EPP mode, 0=ATA mode */
  97. #define USBAT_UIO_UI1 0x04 /* Input 1 */
  98. #define USBAT_UIO_UI0 0x02 /* Input 0 */
  99. #define USBAT_UIO_INTR_ACK 0x01 /* Interrupt (ATA/ISA)/Acknowledge (EPP) */
  100. /* USBAT User I/O Enable registers */
  101. #define USBAT_UIO_DRVRST 0x80 /* Reset Peripheral */
  102. #define USBAT_UIO_ACKD 0x40 /* Enable Card Detect */
  103. #define USBAT_UIO_OE1 0x20 /* I/O 1 set=output/clr=input */
  104. /* If ACKD=1, set OE1 to 1 also. */
  105. #define USBAT_UIO_OE0 0x10 /* I/O 0 set=output/clr=input */
  106. #define USBAT_UIO_ADPRST 0x01 /* Reset SCM chip */
  107. /* USBAT Features */
  108. #define USBAT_FEAT_ETEN 0x80 /* External trigger enable */
  109. #define USBAT_FEAT_U1 0x08
  110. #define USBAT_FEAT_U0 0x04
  111. #define USBAT_FEAT_ET1 0x02
  112. #define USBAT_FEAT_ET2 0x01
  113. struct usbat_info {
  114. int devicetype;
  115. /* Used for Flash readers only */
  116. unsigned long sectors; /* total sector count */
  117. unsigned long ssize; /* sector size in bytes */
  118. unsigned char sense_key;
  119. unsigned long sense_asc; /* additional sense code */
  120. unsigned long sense_ascq; /* additional sense code qualifier */
  121. };
  122. #define short_pack(LSB,MSB) ( ((u16)(LSB)) | ( ((u16)(MSB))<<8 ) )
  123. #define LSB_of(s) ((s)&0xFF)
  124. #define MSB_of(s) ((s)>>8)
  125. static int transferred = 0;
  126. static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us);
  127. static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us);
  128. static int init_usbat_cd(struct us_data *us);
  129. static int init_usbat_flash(struct us_data *us);
  130. /*
  131. * The table of devices
  132. */
  133. #define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
  134. vendorName, productName, useProtocol, useTransport, \
  135. initFunction, flags) \
  136. { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
  137. .driver_info = (flags) }
  138. static struct usb_device_id usbat_usb_ids[] = {
  139. # include "unusual_usbat.h"
  140. { } /* Terminating entry */
  141. };
  142. MODULE_DEVICE_TABLE(usb, usbat_usb_ids);
  143. #undef UNUSUAL_DEV
  144. /*
  145. * The flags table
  146. */
  147. #define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
  148. vendor_name, product_name, use_protocol, use_transport, \
  149. init_function, Flags) \
  150. { \
  151. .vendorName = vendor_name, \
  152. .productName = product_name, \
  153. .useProtocol = use_protocol, \
  154. .useTransport = use_transport, \
  155. .initFunction = init_function, \
  156. }
  157. static struct us_unusual_dev usbat_unusual_dev_list[] = {
  158. # include "unusual_usbat.h"
  159. { } /* Terminating entry */
  160. };
  161. #undef UNUSUAL_DEV
  162. /*
  163. * Convenience function to produce an ATA read/write sectors command
  164. * Use cmd=0x20 for read, cmd=0x30 for write
  165. */
  166. static void usbat_pack_ata_sector_cmd(unsigned char *buf,
  167. unsigned char thistime,
  168. u32 sector, unsigned char cmd)
  169. {
  170. buf[0] = 0;
  171. buf[1] = thistime;
  172. buf[2] = sector & 0xFF;
  173. buf[3] = (sector >> 8) & 0xFF;
  174. buf[4] = (sector >> 16) & 0xFF;
  175. buf[5] = 0xE0 | ((sector >> 24) & 0x0F);
  176. buf[6] = cmd;
  177. }
  178. /*
  179. * Convenience function to get the device type (flash or hp8200)
  180. */
  181. static int usbat_get_device_type(struct us_data *us)
  182. {
  183. return ((struct usbat_info*)us->extra)->devicetype;
  184. }
  185. /*
  186. * Read a register from the device
  187. */
  188. static int usbat_read(struct us_data *us,
  189. unsigned char access,
  190. unsigned char reg,
  191. unsigned char *content)
  192. {
  193. return usb_stor_ctrl_transfer(us,
  194. us->recv_ctrl_pipe,
  195. access | USBAT_CMD_READ_REG,
  196. 0xC0,
  197. (u16)reg,
  198. 0,
  199. content,
  200. 1);
  201. }
  202. /*
  203. * Write to a register on the device
  204. */
  205. static int usbat_write(struct us_data *us,
  206. unsigned char access,
  207. unsigned char reg,
  208. unsigned char content)
  209. {
  210. return usb_stor_ctrl_transfer(us,
  211. us->send_ctrl_pipe,
  212. access | USBAT_CMD_WRITE_REG,
  213. 0x40,
  214. short_pack(reg, content),
  215. 0,
  216. NULL,
  217. 0);
  218. }
  219. /*
  220. * Convenience function to perform a bulk read
  221. */
  222. static int usbat_bulk_read(struct us_data *us,
  223. void* buf,
  224. unsigned int len,
  225. int use_sg)
  226. {
  227. if (len == 0)
  228. return USB_STOR_XFER_GOOD;
  229. usb_stor_dbg(us, "len = %d\n", len);
  230. return usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe, buf, len, use_sg, NULL);
  231. }
  232. /*
  233. * Convenience function to perform a bulk write
  234. */
  235. static int usbat_bulk_write(struct us_data *us,
  236. void* buf,
  237. unsigned int len,
  238. int use_sg)
  239. {
  240. if (len == 0)
  241. return USB_STOR_XFER_GOOD;
  242. usb_stor_dbg(us, "len = %d\n", len);
  243. return usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe, buf, len, use_sg, NULL);
  244. }
  245. /*
  246. * Some USBAT-specific commands can only be executed over a command transport
  247. * This transport allows one (len=8) or two (len=16) vendor-specific commands
  248. * to be executed.
  249. */
  250. static int usbat_execute_command(struct us_data *us,
  251. unsigned char *commands,
  252. unsigned int len)
  253. {
  254. return usb_stor_ctrl_transfer(us, us->send_ctrl_pipe,
  255. USBAT_CMD_EXEC_CMD, 0x40, 0, 0,
  256. commands, len);
  257. }
  258. /*
  259. * Read the status register
  260. */
  261. static int usbat_get_status(struct us_data *us, unsigned char *status)
  262. {
  263. int rc;
  264. rc = usbat_read(us, USBAT_ATA, USBAT_ATA_STATUS, status);
  265. usb_stor_dbg(us, "0x%02X\n", *status);
  266. return rc;
  267. }
  268. /*
  269. * Check the device status
  270. */
  271. static int usbat_check_status(struct us_data *us)
  272. {
  273. unsigned char *reply = us->iobuf;
  274. int rc;
  275. rc = usbat_get_status(us, reply);
  276. if (rc != USB_STOR_XFER_GOOD)
  277. return USB_STOR_TRANSPORT_FAILED;
  278. /* error/check condition (0x51 is ok) */
  279. if (*reply & 0x01 && *reply != 0x51)
  280. return USB_STOR_TRANSPORT_FAILED;
  281. /* device fault */
  282. if (*reply & 0x20)
  283. return USB_STOR_TRANSPORT_FAILED;
  284. return USB_STOR_TRANSPORT_GOOD;
  285. }
  286. /*
  287. * Stores critical information in internal registers in preparation for the execution
  288. * of a conditional usbat_read_blocks or usbat_write_blocks call.
  289. */
  290. static int usbat_set_shuttle_features(struct us_data *us,
  291. unsigned char external_trigger,
  292. unsigned char epp_control,
  293. unsigned char mask_byte,
  294. unsigned char test_pattern,
  295. unsigned char subcountH,
  296. unsigned char subcountL)
  297. {
  298. unsigned char *command = us->iobuf;
  299. command[0] = 0x40;
  300. command[1] = USBAT_CMD_SET_FEAT;
  301. /*
  302. * The only bit relevant to ATA access is bit 6
  303. * which defines 8 bit data access (set) or 16 bit (unset)
  304. */
  305. command[2] = epp_control;
  306. /*
  307. * If FCQ is set in the qualifier (defined in R/W cmd), then bits U0, U1,
  308. * ET1 and ET2 define an external event to be checked for on event of a
  309. * _read_blocks or _write_blocks operation. The read/write will not take
  310. * place unless the defined trigger signal is active.
  311. */
  312. command[3] = external_trigger;
  313. /*
  314. * The resultant byte of the mask operation (see mask_byte) is compared for
  315. * equivalence with this test pattern. If equal, the read/write will take
  316. * place.
  317. */
  318. command[4] = test_pattern;
  319. /*
  320. * This value is logically ANDed with the status register field specified
  321. * in the read/write command.
  322. */
  323. command[5] = mask_byte;
  324. /*
  325. * If ALQ is set in the qualifier, this field contains the address of the
  326. * registers where the byte count should be read for transferring the data.
  327. * If ALQ is not set, then this field contains the number of bytes to be
  328. * transferred.
  329. */
  330. command[6] = subcountL;
  331. command[7] = subcountH;
  332. return usbat_execute_command(us, command, 8);
  333. }
  334. /*
  335. * Block, waiting for an ATA device to become not busy or to report
  336. * an error condition.
  337. */
  338. static int usbat_wait_not_busy(struct us_data *us, int minutes)
  339. {
  340. int i;
  341. int result;
  342. unsigned char *status = us->iobuf;
  343. /*
  344. * Synchronizing cache on a CDR could take a heck of a long time,
  345. * but probably not more than 10 minutes or so. On the other hand,
  346. * doing a full blank on a CDRW at speed 1 will take about 75
  347. * minutes!
  348. */
  349. for (i=0; i<1200+minutes*60; i++) {
  350. result = usbat_get_status(us, status);
  351. if (result!=USB_STOR_XFER_GOOD)
  352. return USB_STOR_TRANSPORT_ERROR;
  353. if (*status & 0x01) { /* check condition */
  354. result = usbat_read(us, USBAT_ATA, 0x10, status);
  355. return USB_STOR_TRANSPORT_FAILED;
  356. }
  357. if (*status & 0x20) /* device fault */
  358. return USB_STOR_TRANSPORT_FAILED;
  359. if ((*status & 0x80)==0x00) { /* not busy */
  360. usb_stor_dbg(us, "Waited not busy for %d steps\n", i);
  361. return USB_STOR_TRANSPORT_GOOD;
  362. }
  363. if (i<500)
  364. msleep(10); /* 5 seconds */
  365. else if (i<700)
  366. msleep(50); /* 10 seconds */
  367. else if (i<1200)
  368. msleep(100); /* 50 seconds */
  369. else
  370. msleep(1000); /* X minutes */
  371. }
  372. usb_stor_dbg(us, "Waited not busy for %d minutes, timing out\n",
  373. minutes);
  374. return USB_STOR_TRANSPORT_FAILED;
  375. }
  376. /*
  377. * Read block data from the data register
  378. */
  379. static int usbat_read_block(struct us_data *us,
  380. void* buf,
  381. unsigned short len,
  382. int use_sg)
  383. {
  384. int result;
  385. unsigned char *command = us->iobuf;
  386. if (!len)
  387. return USB_STOR_TRANSPORT_GOOD;
  388. command[0] = 0xC0;
  389. command[1] = USBAT_ATA | USBAT_CMD_READ_BLOCK;
  390. command[2] = USBAT_ATA_DATA;
  391. command[3] = 0;
  392. command[4] = 0;
  393. command[5] = 0;
  394. command[6] = LSB_of(len);
  395. command[7] = MSB_of(len);
  396. result = usbat_execute_command(us, command, 8);
  397. if (result != USB_STOR_XFER_GOOD)
  398. return USB_STOR_TRANSPORT_ERROR;
  399. result = usbat_bulk_read(us, buf, len, use_sg);
  400. return (result == USB_STOR_XFER_GOOD ?
  401. USB_STOR_TRANSPORT_GOOD : USB_STOR_TRANSPORT_ERROR);
  402. }
  403. /*
  404. * Write block data via the data register
  405. */
  406. static int usbat_write_block(struct us_data *us,
  407. unsigned char access,
  408. void* buf,
  409. unsigned short len,
  410. int minutes,
  411. int use_sg)
  412. {
  413. int result;
  414. unsigned char *command = us->iobuf;
  415. if (!len)
  416. return USB_STOR_TRANSPORT_GOOD;
  417. command[0] = 0x40;
  418. command[1] = access | USBAT_CMD_WRITE_BLOCK;
  419. command[2] = USBAT_ATA_DATA;
  420. command[3] = 0;
  421. command[4] = 0;
  422. command[5] = 0;
  423. command[6] = LSB_of(len);
  424. command[7] = MSB_of(len);
  425. result = usbat_execute_command(us, command, 8);
  426. if (result != USB_STOR_XFER_GOOD)
  427. return USB_STOR_TRANSPORT_ERROR;
  428. result = usbat_bulk_write(us, buf, len, use_sg);
  429. if (result != USB_STOR_XFER_GOOD)
  430. return USB_STOR_TRANSPORT_ERROR;
  431. return usbat_wait_not_busy(us, minutes);
  432. }
  433. /*
  434. * Process read and write requests
  435. */
  436. static int usbat_hp8200e_rw_block_test(struct us_data *us,
  437. unsigned char access,
  438. unsigned char *registers,
  439. unsigned char *data_out,
  440. unsigned short num_registers,
  441. unsigned char data_reg,
  442. unsigned char status_reg,
  443. unsigned char timeout,
  444. unsigned char qualifier,
  445. int direction,
  446. void *buf,
  447. unsigned short len,
  448. int use_sg,
  449. int minutes)
  450. {
  451. int result;
  452. unsigned int pipe = (direction == DMA_FROM_DEVICE) ?
  453. us->recv_bulk_pipe : us->send_bulk_pipe;
  454. unsigned char *command = us->iobuf;
  455. int i, j;
  456. int cmdlen;
  457. unsigned char *data = us->iobuf;
  458. unsigned char *status = us->iobuf;
  459. BUG_ON(num_registers > US_IOBUF_SIZE/2);
  460. for (i=0; i<20; i++) {
  461. /*
  462. * The first time we send the full command, which consists
  463. * of downloading the SCSI command followed by downloading
  464. * the data via a write-and-test. Any other time we only
  465. * send the command to download the data -- the SCSI command
  466. * is still 'active' in some sense in the device.
  467. *
  468. * We're only going to try sending the data 10 times. After
  469. * that, we just return a failure.
  470. */
  471. if (i==0) {
  472. cmdlen = 16;
  473. /*
  474. * Write to multiple registers
  475. * Not really sure the 0x07, 0x17, 0xfc, 0xe7 is
  476. * necessary here, but that's what came out of the
  477. * trace every single time.
  478. */
  479. command[0] = 0x40;
  480. command[1] = access | USBAT_CMD_WRITE_REGS;
  481. command[2] = 0x07;
  482. command[3] = 0x17;
  483. command[4] = 0xFC;
  484. command[5] = 0xE7;
  485. command[6] = LSB_of(num_registers*2);
  486. command[7] = MSB_of(num_registers*2);
  487. } else
  488. cmdlen = 8;
  489. /* Conditionally read or write blocks */
  490. command[cmdlen-8] = (direction==DMA_TO_DEVICE ? 0x40 : 0xC0);
  491. command[cmdlen-7] = access |
  492. (direction==DMA_TO_DEVICE ?
  493. USBAT_CMD_COND_WRITE_BLOCK : USBAT_CMD_COND_READ_BLOCK);
  494. command[cmdlen-6] = data_reg;
  495. command[cmdlen-5] = status_reg;
  496. command[cmdlen-4] = timeout;
  497. command[cmdlen-3] = qualifier;
  498. command[cmdlen-2] = LSB_of(len);
  499. command[cmdlen-1] = MSB_of(len);
  500. result = usbat_execute_command(us, command, cmdlen);
  501. if (result != USB_STOR_XFER_GOOD)
  502. return USB_STOR_TRANSPORT_ERROR;
  503. if (i==0) {
  504. for (j=0; j<num_registers; j++) {
  505. data[j<<1] = registers[j];
  506. data[1+(j<<1)] = data_out[j];
  507. }
  508. result = usbat_bulk_write(us, data, num_registers*2, 0);
  509. if (result != USB_STOR_XFER_GOOD)
  510. return USB_STOR_TRANSPORT_ERROR;
  511. }
  512. result = usb_stor_bulk_transfer_sg(us,
  513. pipe, buf, len, use_sg, NULL);
  514. /*
  515. * If we get a stall on the bulk download, we'll retry
  516. * the bulk download -- but not the SCSI command because
  517. * in some sense the SCSI command is still 'active' and
  518. * waiting for the data. Don't ask me why this should be;
  519. * I'm only following what the Windoze driver did.
  520. *
  521. * Note that a stall for the test-and-read/write command means
  522. * that the test failed. In this case we're testing to make
  523. * sure that the device is error-free
  524. * (i.e. bit 0 -- CHK -- of status is 0). The most likely
  525. * hypothesis is that the USBAT chip somehow knows what
  526. * the device will accept, but doesn't give the device any
  527. * data until all data is received. Thus, the device would
  528. * still be waiting for the first byte of data if a stall
  529. * occurs, even if the stall implies that some data was
  530. * transferred.
  531. */
  532. if (result == USB_STOR_XFER_SHORT ||
  533. result == USB_STOR_XFER_STALLED) {
  534. /*
  535. * If we're reading and we stalled, then clear
  536. * the bulk output pipe only the first time.
  537. */
  538. if (direction==DMA_FROM_DEVICE && i==0) {
  539. if (usb_stor_clear_halt(us,
  540. us->send_bulk_pipe) < 0)
  541. return USB_STOR_TRANSPORT_ERROR;
  542. }
  543. /*
  544. * Read status: is the device angry, or just busy?
  545. */
  546. result = usbat_read(us, USBAT_ATA,
  547. direction==DMA_TO_DEVICE ?
  548. USBAT_ATA_STATUS : USBAT_ATA_ALTSTATUS,
  549. status);
  550. if (result!=USB_STOR_XFER_GOOD)
  551. return USB_STOR_TRANSPORT_ERROR;
  552. if (*status & 0x01) /* check condition */
  553. return USB_STOR_TRANSPORT_FAILED;
  554. if (*status & 0x20) /* device fault */
  555. return USB_STOR_TRANSPORT_FAILED;
  556. usb_stor_dbg(us, "Redoing %s\n",
  557. direction == DMA_TO_DEVICE
  558. ? "write" : "read");
  559. } else if (result != USB_STOR_XFER_GOOD)
  560. return USB_STOR_TRANSPORT_ERROR;
  561. else
  562. return usbat_wait_not_busy(us, minutes);
  563. }
  564. usb_stor_dbg(us, "Bummer! %s bulk data 20 times failed\n",
  565. direction == DMA_TO_DEVICE ? "Writing" : "Reading");
  566. return USB_STOR_TRANSPORT_FAILED;
  567. }
  568. /*
  569. * Write to multiple registers:
  570. * Allows us to write specific data to any registers. The data to be written
  571. * gets packed in this sequence: reg0, data0, reg1, data1, ..., regN, dataN
  572. * which gets sent through bulk out.
  573. * Not designed for large transfers of data!
  574. */
  575. static int usbat_multiple_write(struct us_data *us,
  576. unsigned char *registers,
  577. unsigned char *data_out,
  578. unsigned short num_registers)
  579. {
  580. int i, result;
  581. unsigned char *data = us->iobuf;
  582. unsigned char *command = us->iobuf;
  583. BUG_ON(num_registers > US_IOBUF_SIZE/2);
  584. /* Write to multiple registers, ATA access */
  585. command[0] = 0x40;
  586. command[1] = USBAT_ATA | USBAT_CMD_WRITE_REGS;
  587. /* No relevance */
  588. command[2] = 0;
  589. command[3] = 0;
  590. command[4] = 0;
  591. command[5] = 0;
  592. /* Number of bytes to be transferred (incl. addresses and data) */
  593. command[6] = LSB_of(num_registers*2);
  594. command[7] = MSB_of(num_registers*2);
  595. /* The setup command */
  596. result = usbat_execute_command(us, command, 8);
  597. if (result != USB_STOR_XFER_GOOD)
  598. return USB_STOR_TRANSPORT_ERROR;
  599. /* Create the reg/data, reg/data sequence */
  600. for (i=0; i<num_registers; i++) {
  601. data[i<<1] = registers[i];
  602. data[1+(i<<1)] = data_out[i];
  603. }
  604. /* Send the data */
  605. result = usbat_bulk_write(us, data, num_registers*2, 0);
  606. if (result != USB_STOR_XFER_GOOD)
  607. return USB_STOR_TRANSPORT_ERROR;
  608. if (usbat_get_device_type(us) == USBAT_DEV_HP8200)
  609. return usbat_wait_not_busy(us, 0);
  610. else
  611. return USB_STOR_TRANSPORT_GOOD;
  612. }
  613. /*
  614. * Conditionally read blocks from device:
  615. * Allows us to read blocks from a specific data register, based upon the
  616. * condition that a status register can be successfully masked with a status
  617. * qualifier. If this condition is not initially met, the read will wait
  618. * up until a maximum amount of time has elapsed, as specified by timeout.
  619. * The read will start when the condition is met, otherwise the command aborts.
  620. *
  621. * The qualifier defined here is not the value that is masked, it defines
  622. * conditions for the write to take place. The actual masked qualifier (and
  623. * other related details) are defined beforehand with _set_shuttle_features().
  624. */
  625. static int usbat_read_blocks(struct us_data *us,
  626. void* buffer,
  627. int len,
  628. int use_sg)
  629. {
  630. int result;
  631. unsigned char *command = us->iobuf;
  632. command[0] = 0xC0;
  633. command[1] = USBAT_ATA | USBAT_CMD_COND_READ_BLOCK;
  634. command[2] = USBAT_ATA_DATA;
  635. command[3] = USBAT_ATA_STATUS;
  636. command[4] = 0xFD; /* Timeout (ms); */
  637. command[5] = USBAT_QUAL_FCQ;
  638. command[6] = LSB_of(len);
  639. command[7] = MSB_of(len);
  640. /* Multiple block read setup command */
  641. result = usbat_execute_command(us, command, 8);
  642. if (result != USB_STOR_XFER_GOOD)
  643. return USB_STOR_TRANSPORT_FAILED;
  644. /* Read the blocks we just asked for */
  645. result = usbat_bulk_read(us, buffer, len, use_sg);
  646. if (result != USB_STOR_XFER_GOOD)
  647. return USB_STOR_TRANSPORT_FAILED;
  648. return USB_STOR_TRANSPORT_GOOD;
  649. }
  650. /*
  651. * Conditionally write blocks to device:
  652. * Allows us to write blocks to a specific data register, based upon the
  653. * condition that a status register can be successfully masked with a status
  654. * qualifier. If this condition is not initially met, the write will wait
  655. * up until a maximum amount of time has elapsed, as specified by timeout.
  656. * The read will start when the condition is met, otherwise the command aborts.
  657. *
  658. * The qualifier defined here is not the value that is masked, it defines
  659. * conditions for the write to take place. The actual masked qualifier (and
  660. * other related details) are defined beforehand with _set_shuttle_features().
  661. */
  662. static int usbat_write_blocks(struct us_data *us,
  663. void* buffer,
  664. int len,
  665. int use_sg)
  666. {
  667. int result;
  668. unsigned char *command = us->iobuf;
  669. command[0] = 0x40;
  670. command[1] = USBAT_ATA | USBAT_CMD_COND_WRITE_BLOCK;
  671. command[2] = USBAT_ATA_DATA;
  672. command[3] = USBAT_ATA_STATUS;
  673. command[4] = 0xFD; /* Timeout (ms) */
  674. command[5] = USBAT_QUAL_FCQ;
  675. command[6] = LSB_of(len);
  676. command[7] = MSB_of(len);
  677. /* Multiple block write setup command */
  678. result = usbat_execute_command(us, command, 8);
  679. if (result != USB_STOR_XFER_GOOD)
  680. return USB_STOR_TRANSPORT_FAILED;
  681. /* Write the data */
  682. result = usbat_bulk_write(us, buffer, len, use_sg);
  683. if (result != USB_STOR_XFER_GOOD)
  684. return USB_STOR_TRANSPORT_FAILED;
  685. return USB_STOR_TRANSPORT_GOOD;
  686. }
  687. /*
  688. * Read the User IO register
  689. */
  690. static int usbat_read_user_io(struct us_data *us, unsigned char *data_flags)
  691. {
  692. int result;
  693. result = usb_stor_ctrl_transfer(us,
  694. us->recv_ctrl_pipe,
  695. USBAT_CMD_UIO,
  696. 0xC0,
  697. 0,
  698. 0,
  699. data_flags,
  700. USBAT_UIO_READ);
  701. usb_stor_dbg(us, "UIO register reads %02X\n", *data_flags);
  702. return result;
  703. }
  704. /*
  705. * Write to the User IO register
  706. */
  707. static int usbat_write_user_io(struct us_data *us,
  708. unsigned char enable_flags,
  709. unsigned char data_flags)
  710. {
  711. return usb_stor_ctrl_transfer(us,
  712. us->send_ctrl_pipe,
  713. USBAT_CMD_UIO,
  714. 0x40,
  715. short_pack(enable_flags, data_flags),
  716. 0,
  717. NULL,
  718. USBAT_UIO_WRITE);
  719. }
  720. /*
  721. * Reset the device
  722. * Often needed on media change.
  723. */
  724. static int usbat_device_reset(struct us_data *us)
  725. {
  726. int rc;
  727. /*
  728. * Reset peripheral, enable peripheral control signals
  729. * (bring reset signal up)
  730. */
  731. rc = usbat_write_user_io(us,
  732. USBAT_UIO_DRVRST | USBAT_UIO_OE1 | USBAT_UIO_OE0,
  733. USBAT_UIO_EPAD | USBAT_UIO_1);
  734. if (rc != USB_STOR_XFER_GOOD)
  735. return USB_STOR_TRANSPORT_ERROR;
  736. /*
  737. * Enable peripheral control signals
  738. * (bring reset signal down)
  739. */
  740. rc = usbat_write_user_io(us,
  741. USBAT_UIO_OE1 | USBAT_UIO_OE0,
  742. USBAT_UIO_EPAD | USBAT_UIO_1);
  743. if (rc != USB_STOR_XFER_GOOD)
  744. return USB_STOR_TRANSPORT_ERROR;
  745. return USB_STOR_TRANSPORT_GOOD;
  746. }
  747. /*
  748. * Enable card detect
  749. */
  750. static int usbat_device_enable_cdt(struct us_data *us)
  751. {
  752. int rc;
  753. /* Enable peripheral control signals and card detect */
  754. rc = usbat_write_user_io(us,
  755. USBAT_UIO_ACKD | USBAT_UIO_OE1 | USBAT_UIO_OE0,
  756. USBAT_UIO_EPAD | USBAT_UIO_1);
  757. if (rc != USB_STOR_XFER_GOOD)
  758. return USB_STOR_TRANSPORT_ERROR;
  759. return USB_STOR_TRANSPORT_GOOD;
  760. }
  761. /*
  762. * Determine if media is present.
  763. */
  764. static int usbat_flash_check_media_present(struct us_data *us,
  765. unsigned char *uio)
  766. {
  767. if (*uio & USBAT_UIO_UI0) {
  768. usb_stor_dbg(us, "no media detected\n");
  769. return USBAT_FLASH_MEDIA_NONE;
  770. }
  771. return USBAT_FLASH_MEDIA_CF;
  772. }
  773. /*
  774. * Determine if media has changed since last operation
  775. */
  776. static int usbat_flash_check_media_changed(struct us_data *us,
  777. unsigned char *uio)
  778. {
  779. if (*uio & USBAT_UIO_0) {
  780. usb_stor_dbg(us, "media change detected\n");
  781. return USBAT_FLASH_MEDIA_CHANGED;
  782. }
  783. return USBAT_FLASH_MEDIA_SAME;
  784. }
  785. /*
  786. * Check for media change / no media and handle the situation appropriately
  787. */
  788. static int usbat_flash_check_media(struct us_data *us,
  789. struct usbat_info *info)
  790. {
  791. int rc;
  792. unsigned char *uio = us->iobuf;
  793. rc = usbat_read_user_io(us, uio);
  794. if (rc != USB_STOR_XFER_GOOD)
  795. return USB_STOR_TRANSPORT_ERROR;
  796. /* Check for media existence */
  797. rc = usbat_flash_check_media_present(us, uio);
  798. if (rc == USBAT_FLASH_MEDIA_NONE) {
  799. info->sense_key = 0x02;
  800. info->sense_asc = 0x3A;
  801. info->sense_ascq = 0x00;
  802. return USB_STOR_TRANSPORT_FAILED;
  803. }
  804. /* Check for media change */
  805. rc = usbat_flash_check_media_changed(us, uio);
  806. if (rc == USBAT_FLASH_MEDIA_CHANGED) {
  807. /* Reset and re-enable card detect */
  808. rc = usbat_device_reset(us);
  809. if (rc != USB_STOR_TRANSPORT_GOOD)
  810. return rc;
  811. rc = usbat_device_enable_cdt(us);
  812. if (rc != USB_STOR_TRANSPORT_GOOD)
  813. return rc;
  814. msleep(50);
  815. rc = usbat_read_user_io(us, uio);
  816. if (rc != USB_STOR_XFER_GOOD)
  817. return USB_STOR_TRANSPORT_ERROR;
  818. info->sense_key = UNIT_ATTENTION;
  819. info->sense_asc = 0x28;
  820. info->sense_ascq = 0x00;
  821. return USB_STOR_TRANSPORT_FAILED;
  822. }
  823. return USB_STOR_TRANSPORT_GOOD;
  824. }
  825. /*
  826. * Determine whether we are controlling a flash-based reader/writer,
  827. * or a HP8200-based CD drive.
  828. * Sets transport functions as appropriate.
  829. */
  830. static int usbat_identify_device(struct us_data *us,
  831. struct usbat_info *info)
  832. {
  833. int rc;
  834. unsigned char status;
  835. if (!us || !info)
  836. return USB_STOR_TRANSPORT_ERROR;
  837. rc = usbat_device_reset(us);
  838. if (rc != USB_STOR_TRANSPORT_GOOD)
  839. return rc;
  840. msleep(500);
  841. /*
  842. * In attempt to distinguish between HP CDRW's and Flash readers, we now
  843. * execute the IDENTIFY PACKET DEVICE command. On ATA devices (i.e. flash
  844. * readers), this command should fail with error. On ATAPI devices (i.e.
  845. * CDROM drives), it should succeed.
  846. */
  847. rc = usbat_write(us, USBAT_ATA, USBAT_ATA_CMD, 0xA1);
  848. if (rc != USB_STOR_XFER_GOOD)
  849. return USB_STOR_TRANSPORT_ERROR;
  850. rc = usbat_get_status(us, &status);
  851. if (rc != USB_STOR_XFER_GOOD)
  852. return USB_STOR_TRANSPORT_ERROR;
  853. /* Check for error bit, or if the command 'fell through' */
  854. if (status == 0xA1 || !(status & 0x01)) {
  855. /* Device is HP 8200 */
  856. usb_stor_dbg(us, "Detected HP8200 CDRW\n");
  857. info->devicetype = USBAT_DEV_HP8200;
  858. } else {
  859. /* Device is a CompactFlash reader/writer */
  860. usb_stor_dbg(us, "Detected Flash reader/writer\n");
  861. info->devicetype = USBAT_DEV_FLASH;
  862. }
  863. return USB_STOR_TRANSPORT_GOOD;
  864. }
  865. /*
  866. * Set the transport function based on the device type
  867. */
  868. static int usbat_set_transport(struct us_data *us,
  869. struct usbat_info *info,
  870. int devicetype)
  871. {
  872. if (!info->devicetype)
  873. info->devicetype = devicetype;
  874. if (!info->devicetype)
  875. usbat_identify_device(us, info);
  876. switch (info->devicetype) {
  877. default:
  878. return USB_STOR_TRANSPORT_ERROR;
  879. case USBAT_DEV_HP8200:
  880. us->transport = usbat_hp8200e_transport;
  881. break;
  882. case USBAT_DEV_FLASH:
  883. us->transport = usbat_flash_transport;
  884. break;
  885. }
  886. return 0;
  887. }
  888. /*
  889. * Read the media capacity
  890. */
  891. static int usbat_flash_get_sector_count(struct us_data *us,
  892. struct usbat_info *info)
  893. {
  894. unsigned char registers[3] = {
  895. USBAT_ATA_SECCNT,
  896. USBAT_ATA_DEVICE,
  897. USBAT_ATA_CMD,
  898. };
  899. unsigned char command[3] = { 0x01, 0xA0, 0xEC };
  900. unsigned char *reply;
  901. unsigned char status;
  902. int rc;
  903. if (!us || !info)
  904. return USB_STOR_TRANSPORT_ERROR;
  905. reply = kmalloc(512, GFP_NOIO);
  906. if (!reply)
  907. return USB_STOR_TRANSPORT_ERROR;
  908. /* ATA command : IDENTIFY DEVICE */
  909. rc = usbat_multiple_write(us, registers, command, 3);
  910. if (rc != USB_STOR_XFER_GOOD) {
  911. usb_stor_dbg(us, "Gah! identify_device failed\n");
  912. rc = USB_STOR_TRANSPORT_ERROR;
  913. goto leave;
  914. }
  915. /* Read device status */
  916. if (usbat_get_status(us, &status) != USB_STOR_XFER_GOOD) {
  917. rc = USB_STOR_TRANSPORT_ERROR;
  918. goto leave;
  919. }
  920. msleep(100);
  921. /* Read the device identification data */
  922. rc = usbat_read_block(us, reply, 512, 0);
  923. if (rc != USB_STOR_TRANSPORT_GOOD)
  924. goto leave;
  925. info->sectors = ((u32)(reply[117]) << 24) |
  926. ((u32)(reply[116]) << 16) |
  927. ((u32)(reply[115]) << 8) |
  928. ((u32)(reply[114]) );
  929. rc = USB_STOR_TRANSPORT_GOOD;
  930. leave:
  931. kfree(reply);
  932. return rc;
  933. }
  934. /*
  935. * Read data from device
  936. */
  937. static int usbat_flash_read_data(struct us_data *us,
  938. struct usbat_info *info,
  939. u32 sector,
  940. u32 sectors)
  941. {
  942. unsigned char registers[7] = {
  943. USBAT_ATA_FEATURES,
  944. USBAT_ATA_SECCNT,
  945. USBAT_ATA_SECNUM,
  946. USBAT_ATA_LBA_ME,
  947. USBAT_ATA_LBA_HI,
  948. USBAT_ATA_DEVICE,
  949. USBAT_ATA_STATUS,
  950. };
  951. unsigned char command[7];
  952. unsigned char *buffer;
  953. unsigned char thistime;
  954. unsigned int totallen, alloclen;
  955. int len, result;
  956. unsigned int sg_offset = 0;
  957. struct scatterlist *sg = NULL;
  958. result = usbat_flash_check_media(us, info);
  959. if (result != USB_STOR_TRANSPORT_GOOD)
  960. return result;
  961. /*
  962. * we're working in LBA mode. according to the ATA spec,
  963. * we can support up to 28-bit addressing. I don't know if Jumpshot
  964. * supports beyond 24-bit addressing. It's kind of hard to test
  965. * since it requires > 8GB CF card.
  966. */
  967. if (sector > 0x0FFFFFFF)
  968. return USB_STOR_TRANSPORT_ERROR;
  969. totallen = sectors * info->ssize;
  970. /*
  971. * Since we don't read more than 64 KB at a time, we have to create
  972. * a bounce buffer and move the data a piece at a time between the
  973. * bounce buffer and the actual transfer buffer.
  974. */
  975. alloclen = min(totallen, 65536u);
  976. buffer = kmalloc(alloclen, GFP_NOIO);
  977. if (buffer == NULL)
  978. return USB_STOR_TRANSPORT_ERROR;
  979. do {
  980. /*
  981. * loop, never allocate or transfer more than 64k at once
  982. * (min(128k, 255*info->ssize) is the real limit)
  983. */
  984. len = min(totallen, alloclen);
  985. thistime = (len / info->ssize) & 0xff;
  986. /* ATA command 0x20 (READ SECTORS) */
  987. usbat_pack_ata_sector_cmd(command, thistime, sector, 0x20);
  988. /* Write/execute ATA read command */
  989. result = usbat_multiple_write(us, registers, command, 7);
  990. if (result != USB_STOR_TRANSPORT_GOOD)
  991. goto leave;
  992. /* Read the data we just requested */
  993. result = usbat_read_blocks(us, buffer, len, 0);
  994. if (result != USB_STOR_TRANSPORT_GOOD)
  995. goto leave;
  996. usb_stor_dbg(us, "%d bytes\n", len);
  997. /* Store the data in the transfer buffer */
  998. usb_stor_access_xfer_buf(buffer, len, us->srb,
  999. &sg, &sg_offset, TO_XFER_BUF);
  1000. sector += thistime;
  1001. totallen -= len;
  1002. } while (totallen > 0);
  1003. kfree(buffer);
  1004. return USB_STOR_TRANSPORT_GOOD;
  1005. leave:
  1006. kfree(buffer);
  1007. return USB_STOR_TRANSPORT_ERROR;
  1008. }
  1009. /*
  1010. * Write data to device
  1011. */
  1012. static int usbat_flash_write_data(struct us_data *us,
  1013. struct usbat_info *info,
  1014. u32 sector,
  1015. u32 sectors)
  1016. {
  1017. unsigned char registers[7] = {
  1018. USBAT_ATA_FEATURES,
  1019. USBAT_ATA_SECCNT,
  1020. USBAT_ATA_SECNUM,
  1021. USBAT_ATA_LBA_ME,
  1022. USBAT_ATA_LBA_HI,
  1023. USBAT_ATA_DEVICE,
  1024. USBAT_ATA_STATUS,
  1025. };
  1026. unsigned char command[7];
  1027. unsigned char *buffer;
  1028. unsigned char thistime;
  1029. unsigned int totallen, alloclen;
  1030. int len, result;
  1031. unsigned int sg_offset = 0;
  1032. struct scatterlist *sg = NULL;
  1033. result = usbat_flash_check_media(us, info);
  1034. if (result != USB_STOR_TRANSPORT_GOOD)
  1035. return result;
  1036. /*
  1037. * we're working in LBA mode. according to the ATA spec,
  1038. * we can support up to 28-bit addressing. I don't know if the device
  1039. * supports beyond 24-bit addressing. It's kind of hard to test
  1040. * since it requires > 8GB media.
  1041. */
  1042. if (sector > 0x0FFFFFFF)
  1043. return USB_STOR_TRANSPORT_ERROR;
  1044. totallen = sectors * info->ssize;
  1045. /*
  1046. * Since we don't write more than 64 KB at a time, we have to create
  1047. * a bounce buffer and move the data a piece at a time between the
  1048. * bounce buffer and the actual transfer buffer.
  1049. */
  1050. alloclen = min(totallen, 65536u);
  1051. buffer = kmalloc(alloclen, GFP_NOIO);
  1052. if (buffer == NULL)
  1053. return USB_STOR_TRANSPORT_ERROR;
  1054. do {
  1055. /*
  1056. * loop, never allocate or transfer more than 64k at once
  1057. * (min(128k, 255*info->ssize) is the real limit)
  1058. */
  1059. len = min(totallen, alloclen);
  1060. thistime = (len / info->ssize) & 0xff;
  1061. /* Get the data from the transfer buffer */
  1062. usb_stor_access_xfer_buf(buffer, len, us->srb,
  1063. &sg, &sg_offset, FROM_XFER_BUF);
  1064. /* ATA command 0x30 (WRITE SECTORS) */
  1065. usbat_pack_ata_sector_cmd(command, thistime, sector, 0x30);
  1066. /* Write/execute ATA write command */
  1067. result = usbat_multiple_write(us, registers, command, 7);
  1068. if (result != USB_STOR_TRANSPORT_GOOD)
  1069. goto leave;
  1070. /* Write the data */
  1071. result = usbat_write_blocks(us, buffer, len, 0);
  1072. if (result != USB_STOR_TRANSPORT_GOOD)
  1073. goto leave;
  1074. sector += thistime;
  1075. totallen -= len;
  1076. } while (totallen > 0);
  1077. kfree(buffer);
  1078. return result;
  1079. leave:
  1080. kfree(buffer);
  1081. return USB_STOR_TRANSPORT_ERROR;
  1082. }
  1083. /*
  1084. * Squeeze a potentially huge (> 65535 byte) read10 command into
  1085. * a little ( <= 65535 byte) ATAPI pipe
  1086. */
  1087. static int usbat_hp8200e_handle_read10(struct us_data *us,
  1088. unsigned char *registers,
  1089. unsigned char *data,
  1090. struct scsi_cmnd *srb)
  1091. {
  1092. int result = USB_STOR_TRANSPORT_GOOD;
  1093. unsigned char *buffer;
  1094. unsigned int len;
  1095. unsigned int sector;
  1096. unsigned int sg_offset = 0;
  1097. struct scatterlist *sg = NULL;
  1098. usb_stor_dbg(us, "transfersize %d\n", srb->transfersize);
  1099. if (scsi_bufflen(srb) < 0x10000) {
  1100. result = usbat_hp8200e_rw_block_test(us, USBAT_ATA,
  1101. registers, data, 19,
  1102. USBAT_ATA_DATA, USBAT_ATA_STATUS, 0xFD,
  1103. (USBAT_QUAL_FCQ | USBAT_QUAL_ALQ),
  1104. DMA_FROM_DEVICE,
  1105. scsi_sglist(srb),
  1106. scsi_bufflen(srb), scsi_sg_count(srb), 1);
  1107. return result;
  1108. }
  1109. /*
  1110. * Since we're requesting more data than we can handle in
  1111. * a single read command (max is 64k-1), we will perform
  1112. * multiple reads, but each read must be in multiples of
  1113. * a sector. Luckily the sector size is in srb->transfersize
  1114. * (see linux/drivers/scsi/sr.c).
  1115. */
  1116. if (data[7+0] == GPCMD_READ_CD) {
  1117. len = short_pack(data[7+9], data[7+8]);
  1118. len <<= 16;
  1119. len |= data[7+7];
  1120. usb_stor_dbg(us, "GPCMD_READ_CD: len %d\n", len);
  1121. srb->transfersize = scsi_bufflen(srb)/len;
  1122. }
  1123. if (!srb->transfersize) {
  1124. srb->transfersize = 2048; /* A guess */
  1125. usb_stor_dbg(us, "transfersize 0, forcing %d\n",
  1126. srb->transfersize);
  1127. }
  1128. /*
  1129. * Since we only read in one block at a time, we have to create
  1130. * a bounce buffer and move the data a piece at a time between the
  1131. * bounce buffer and the actual transfer buffer.
  1132. */
  1133. len = (65535/srb->transfersize) * srb->transfersize;
  1134. usb_stor_dbg(us, "Max read is %d bytes\n", len);
  1135. len = min(len, scsi_bufflen(srb));
  1136. buffer = kmalloc(len, GFP_NOIO);
  1137. if (buffer == NULL) /* bloody hell! */
  1138. return USB_STOR_TRANSPORT_FAILED;
  1139. sector = short_pack(data[7+3], data[7+2]);
  1140. sector <<= 16;
  1141. sector |= short_pack(data[7+5], data[7+4]);
  1142. transferred = 0;
  1143. while (transferred != scsi_bufflen(srb)) {
  1144. if (len > scsi_bufflen(srb) - transferred)
  1145. len = scsi_bufflen(srb) - transferred;
  1146. data[3] = len&0xFF; /* (cylL) = expected length (L) */
  1147. data[4] = (len>>8)&0xFF; /* (cylH) = expected length (H) */
  1148. /* Fix up the SCSI command sector and num sectors */
  1149. data[7+2] = MSB_of(sector>>16); /* SCSI command sector */
  1150. data[7+3] = LSB_of(sector>>16);
  1151. data[7+4] = MSB_of(sector&0xFFFF);
  1152. data[7+5] = LSB_of(sector&0xFFFF);
  1153. if (data[7+0] == GPCMD_READ_CD)
  1154. data[7+6] = 0;
  1155. data[7+7] = MSB_of(len / srb->transfersize); /* SCSI command */
  1156. data[7+8] = LSB_of(len / srb->transfersize); /* num sectors */
  1157. result = usbat_hp8200e_rw_block_test(us, USBAT_ATA,
  1158. registers, data, 19,
  1159. USBAT_ATA_DATA, USBAT_ATA_STATUS, 0xFD,
  1160. (USBAT_QUAL_FCQ | USBAT_QUAL_ALQ),
  1161. DMA_FROM_DEVICE,
  1162. buffer,
  1163. len, 0, 1);
  1164. if (result != USB_STOR_TRANSPORT_GOOD)
  1165. break;
  1166. /* Store the data in the transfer buffer */
  1167. usb_stor_access_xfer_buf(buffer, len, srb,
  1168. &sg, &sg_offset, TO_XFER_BUF);
  1169. /* Update the amount transferred and the sector number */
  1170. transferred += len;
  1171. sector += len / srb->transfersize;
  1172. } /* while transferred != scsi_bufflen(srb) */
  1173. kfree(buffer);
  1174. return result;
  1175. }
  1176. static int usbat_select_and_test_registers(struct us_data *us)
  1177. {
  1178. int selector;
  1179. unsigned char *status = us->iobuf;
  1180. /* try device = master, then device = slave. */
  1181. for (selector = 0xA0; selector <= 0xB0; selector += 0x10) {
  1182. if (usbat_write(us, USBAT_ATA, USBAT_ATA_DEVICE, selector) !=
  1183. USB_STOR_XFER_GOOD)
  1184. return USB_STOR_TRANSPORT_ERROR;
  1185. if (usbat_read(us, USBAT_ATA, USBAT_ATA_STATUS, status) !=
  1186. USB_STOR_XFER_GOOD)
  1187. return USB_STOR_TRANSPORT_ERROR;
  1188. if (usbat_read(us, USBAT_ATA, USBAT_ATA_DEVICE, status) !=
  1189. USB_STOR_XFER_GOOD)
  1190. return USB_STOR_TRANSPORT_ERROR;
  1191. if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) !=
  1192. USB_STOR_XFER_GOOD)
  1193. return USB_STOR_TRANSPORT_ERROR;
  1194. if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_HI, status) !=
  1195. USB_STOR_XFER_GOOD)
  1196. return USB_STOR_TRANSPORT_ERROR;
  1197. if (usbat_write(us, USBAT_ATA, USBAT_ATA_LBA_ME, 0x55) !=
  1198. USB_STOR_XFER_GOOD)
  1199. return USB_STOR_TRANSPORT_ERROR;
  1200. if (usbat_write(us, USBAT_ATA, USBAT_ATA_LBA_HI, 0xAA) !=
  1201. USB_STOR_XFER_GOOD)
  1202. return USB_STOR_TRANSPORT_ERROR;
  1203. if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) !=
  1204. USB_STOR_XFER_GOOD)
  1205. return USB_STOR_TRANSPORT_ERROR;
  1206. if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) !=
  1207. USB_STOR_XFER_GOOD)
  1208. return USB_STOR_TRANSPORT_ERROR;
  1209. }
  1210. return USB_STOR_TRANSPORT_GOOD;
  1211. }
  1212. /*
  1213. * Initialize the USBAT processor and the storage device
  1214. */
  1215. static int init_usbat(struct us_data *us, int devicetype)
  1216. {
  1217. int rc;
  1218. struct usbat_info *info;
  1219. unsigned char subcountH = USBAT_ATA_LBA_HI;
  1220. unsigned char subcountL = USBAT_ATA_LBA_ME;
  1221. unsigned char *status = us->iobuf;
  1222. us->extra = kzalloc(sizeof(struct usbat_info), GFP_NOIO);
  1223. if (!us->extra)
  1224. return -ENOMEM;
  1225. info = (struct usbat_info *) (us->extra);
  1226. /* Enable peripheral control signals */
  1227. rc = usbat_write_user_io(us,
  1228. USBAT_UIO_OE1 | USBAT_UIO_OE0,
  1229. USBAT_UIO_EPAD | USBAT_UIO_1);
  1230. if (rc != USB_STOR_XFER_GOOD)
  1231. return -EIO;
  1232. usb_stor_dbg(us, "INIT 1\n");
  1233. msleep(2000);
  1234. rc = usbat_read_user_io(us, status);
  1235. if (rc != USB_STOR_TRANSPORT_GOOD)
  1236. return -EIO;
  1237. usb_stor_dbg(us, "INIT 2\n");
  1238. rc = usbat_read_user_io(us, status);
  1239. if (rc != USB_STOR_XFER_GOOD)
  1240. return -EIO;
  1241. rc = usbat_read_user_io(us, status);
  1242. if (rc != USB_STOR_XFER_GOOD)
  1243. return -EIO;
  1244. usb_stor_dbg(us, "INIT 3\n");
  1245. rc = usbat_select_and_test_registers(us);
  1246. if (rc != USB_STOR_TRANSPORT_GOOD)
  1247. return -EIO;
  1248. usb_stor_dbg(us, "INIT 4\n");
  1249. rc = usbat_read_user_io(us, status);
  1250. if (rc != USB_STOR_XFER_GOOD)
  1251. return -EIO;
  1252. usb_stor_dbg(us, "INIT 5\n");
  1253. /* Enable peripheral control signals and card detect */
  1254. rc = usbat_device_enable_cdt(us);
  1255. if (rc != USB_STOR_TRANSPORT_GOOD)
  1256. return -EIO;
  1257. usb_stor_dbg(us, "INIT 6\n");
  1258. rc = usbat_read_user_io(us, status);
  1259. if (rc != USB_STOR_XFER_GOOD)
  1260. return -EIO;
  1261. usb_stor_dbg(us, "INIT 7\n");
  1262. msleep(1400);
  1263. rc = usbat_read_user_io(us, status);
  1264. if (rc != USB_STOR_XFER_GOOD)
  1265. return -EIO;
  1266. usb_stor_dbg(us, "INIT 8\n");
  1267. rc = usbat_select_and_test_registers(us);
  1268. if (rc != USB_STOR_TRANSPORT_GOOD)
  1269. return -EIO;
  1270. usb_stor_dbg(us, "INIT 9\n");
  1271. /* At this point, we need to detect which device we are using */
  1272. if (usbat_set_transport(us, info, devicetype))
  1273. return -EIO;
  1274. usb_stor_dbg(us, "INIT 10\n");
  1275. if (usbat_get_device_type(us) == USBAT_DEV_FLASH) {
  1276. subcountH = 0x02;
  1277. subcountL = 0x00;
  1278. }
  1279. rc = usbat_set_shuttle_features(us, (USBAT_FEAT_ETEN | USBAT_FEAT_ET2 | USBAT_FEAT_ET1),
  1280. 0x00, 0x88, 0x08, subcountH, subcountL);
  1281. if (rc != USB_STOR_XFER_GOOD)
  1282. return -EIO;
  1283. usb_stor_dbg(us, "INIT 11\n");
  1284. return 0;
  1285. }
  1286. /*
  1287. * Transport for the HP 8200e
  1288. */
  1289. static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
  1290. {
  1291. int result;
  1292. unsigned char *status = us->iobuf;
  1293. unsigned char registers[32];
  1294. unsigned char data[32];
  1295. unsigned int len;
  1296. int i;
  1297. len = scsi_bufflen(srb);
  1298. /*
  1299. * Send A0 (ATA PACKET COMMAND).
  1300. * Note: I guess we're never going to get any of the ATA
  1301. * commands... just ATA Packet Commands.
  1302. */
  1303. registers[0] = USBAT_ATA_FEATURES;
  1304. registers[1] = USBAT_ATA_SECCNT;
  1305. registers[2] = USBAT_ATA_SECNUM;
  1306. registers[3] = USBAT_ATA_LBA_ME;
  1307. registers[4] = USBAT_ATA_LBA_HI;
  1308. registers[5] = USBAT_ATA_DEVICE;
  1309. registers[6] = USBAT_ATA_CMD;
  1310. data[0] = 0x00;
  1311. data[1] = 0x00;
  1312. data[2] = 0x00;
  1313. data[3] = len&0xFF; /* (cylL) = expected length (L) */
  1314. data[4] = (len>>8)&0xFF; /* (cylH) = expected length (H) */
  1315. data[5] = 0xB0; /* (device sel) = slave */
  1316. data[6] = 0xA0; /* (command) = ATA PACKET COMMAND */
  1317. for (i=7; i<19; i++) {
  1318. registers[i] = 0x10;
  1319. data[i] = (i-7 >= srb->cmd_len) ? 0 : srb->cmnd[i-7];
  1320. }
  1321. result = usbat_get_status(us, status);
  1322. usb_stor_dbg(us, "Status = %02X\n", *status);
  1323. if (result != USB_STOR_XFER_GOOD)
  1324. return USB_STOR_TRANSPORT_ERROR;
  1325. if (srb->cmnd[0] == TEST_UNIT_READY)
  1326. transferred = 0;
  1327. if (srb->sc_data_direction == DMA_TO_DEVICE) {
  1328. result = usbat_hp8200e_rw_block_test(us, USBAT_ATA,
  1329. registers, data, 19,
  1330. USBAT_ATA_DATA, USBAT_ATA_STATUS, 0xFD,
  1331. (USBAT_QUAL_FCQ | USBAT_QUAL_ALQ),
  1332. DMA_TO_DEVICE,
  1333. scsi_sglist(srb),
  1334. len, scsi_sg_count(srb), 10);
  1335. if (result == USB_STOR_TRANSPORT_GOOD) {
  1336. transferred += len;
  1337. usb_stor_dbg(us, "Wrote %08X bytes\n", transferred);
  1338. }
  1339. return result;
  1340. } else if (srb->cmnd[0] == READ_10 ||
  1341. srb->cmnd[0] == GPCMD_READ_CD) {
  1342. return usbat_hp8200e_handle_read10(us, registers, data, srb);
  1343. }
  1344. if (len > 0xFFFF) {
  1345. usb_stor_dbg(us, "Error: len = %08X... what do I do now?\n",
  1346. len);
  1347. return USB_STOR_TRANSPORT_ERROR;
  1348. }
  1349. result = usbat_multiple_write(us, registers, data, 7);
  1350. if (result != USB_STOR_TRANSPORT_GOOD)
  1351. return result;
  1352. /*
  1353. * Write the 12-byte command header.
  1354. *
  1355. * If the command is BLANK then set the timer for 75 minutes.
  1356. * Otherwise set it for 10 minutes.
  1357. *
  1358. * NOTE: THE 8200 DOCUMENTATION STATES THAT BLANKING A CDRW
  1359. * AT SPEED 4 IS UNRELIABLE!!!
  1360. */
  1361. result = usbat_write_block(us, USBAT_ATA, srb->cmnd, 12,
  1362. srb->cmnd[0] == GPCMD_BLANK ? 75 : 10, 0);
  1363. if (result != USB_STOR_TRANSPORT_GOOD)
  1364. return result;
  1365. /* If there is response data to be read in then do it here. */
  1366. if (len != 0 && (srb->sc_data_direction == DMA_FROM_DEVICE)) {
  1367. /* How many bytes to read in? Check cylL register */
  1368. if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, status) !=
  1369. USB_STOR_XFER_GOOD) {
  1370. return USB_STOR_TRANSPORT_ERROR;
  1371. }
  1372. if (len > 0xFF) { /* need to read cylH also */
  1373. len = *status;
  1374. if (usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_HI, status) !=
  1375. USB_STOR_XFER_GOOD) {
  1376. return USB_STOR_TRANSPORT_ERROR;
  1377. }
  1378. len += ((unsigned int) *status)<<8;
  1379. }
  1380. else
  1381. len = *status;
  1382. result = usbat_read_block(us, scsi_sglist(srb), len,
  1383. scsi_sg_count(srb));
  1384. }
  1385. return result;
  1386. }
  1387. /*
  1388. * Transport for USBAT02-based CompactFlash and similar storage devices
  1389. */
  1390. static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
  1391. {
  1392. int rc;
  1393. struct usbat_info *info = (struct usbat_info *) (us->extra);
  1394. unsigned long block, blocks;
  1395. unsigned char *ptr = us->iobuf;
  1396. static unsigned char inquiry_response[36] = {
  1397. 0x00, 0x80, 0x00, 0x01, 0x1F, 0x00, 0x00, 0x00
  1398. };
  1399. if (srb->cmnd[0] == INQUIRY) {
  1400. usb_stor_dbg(us, "INQUIRY - Returning bogus response\n");
  1401. memcpy(ptr, inquiry_response, sizeof(inquiry_response));
  1402. fill_inquiry_response(us, ptr, 36);
  1403. return USB_STOR_TRANSPORT_GOOD;
  1404. }
  1405. if (srb->cmnd[0] == READ_CAPACITY) {
  1406. rc = usbat_flash_check_media(us, info);
  1407. if (rc != USB_STOR_TRANSPORT_GOOD)
  1408. return rc;
  1409. rc = usbat_flash_get_sector_count(us, info);
  1410. if (rc != USB_STOR_TRANSPORT_GOOD)
  1411. return rc;
  1412. /* hard coded 512 byte sectors as per ATA spec */
  1413. info->ssize = 0x200;
  1414. usb_stor_dbg(us, "READ_CAPACITY: %ld sectors, %ld bytes per sector\n",
  1415. info->sectors, info->ssize);
  1416. /*
  1417. * build the reply
  1418. * note: must return the sector number of the last sector,
  1419. * *not* the total number of sectors
  1420. */
  1421. ((__be32 *) ptr)[0] = cpu_to_be32(info->sectors - 1);
  1422. ((__be32 *) ptr)[1] = cpu_to_be32(info->ssize);
  1423. usb_stor_set_xfer_buf(ptr, 8, srb);
  1424. return USB_STOR_TRANSPORT_GOOD;
  1425. }
  1426. if (srb->cmnd[0] == MODE_SELECT_10) {
  1427. usb_stor_dbg(us, "Gah! MODE_SELECT_10\n");
  1428. return USB_STOR_TRANSPORT_ERROR;
  1429. }
  1430. if (srb->cmnd[0] == READ_10) {
  1431. block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
  1432. ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
  1433. blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
  1434. usb_stor_dbg(us, "READ_10: read block 0x%04lx count %ld\n",
  1435. block, blocks);
  1436. return usbat_flash_read_data(us, info, block, blocks);
  1437. }
  1438. if (srb->cmnd[0] == READ_12) {
  1439. /*
  1440. * I don't think we'll ever see a READ_12 but support it anyway
  1441. */
  1442. block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
  1443. ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
  1444. blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
  1445. ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9]));
  1446. usb_stor_dbg(us, "READ_12: read block 0x%04lx count %ld\n",
  1447. block, blocks);
  1448. return usbat_flash_read_data(us, info, block, blocks);
  1449. }
  1450. if (srb->cmnd[0] == WRITE_10) {
  1451. block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
  1452. ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
  1453. blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
  1454. usb_stor_dbg(us, "WRITE_10: write block 0x%04lx count %ld\n",
  1455. block, blocks);
  1456. return usbat_flash_write_data(us, info, block, blocks);
  1457. }
  1458. if (srb->cmnd[0] == WRITE_12) {
  1459. /*
  1460. * I don't think we'll ever see a WRITE_12 but support it anyway
  1461. */
  1462. block = ((u32)(srb->cmnd[2]) << 24) | ((u32)(srb->cmnd[3]) << 16) |
  1463. ((u32)(srb->cmnd[4]) << 8) | ((u32)(srb->cmnd[5]));
  1464. blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
  1465. ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9]));
  1466. usb_stor_dbg(us, "WRITE_12: write block 0x%04lx count %ld\n",
  1467. block, blocks);
  1468. return usbat_flash_write_data(us, info, block, blocks);
  1469. }
  1470. if (srb->cmnd[0] == TEST_UNIT_READY) {
  1471. usb_stor_dbg(us, "TEST_UNIT_READY\n");
  1472. rc = usbat_flash_check_media(us, info);
  1473. if (rc != USB_STOR_TRANSPORT_GOOD)
  1474. return rc;
  1475. return usbat_check_status(us);
  1476. }
  1477. if (srb->cmnd[0] == REQUEST_SENSE) {
  1478. usb_stor_dbg(us, "REQUEST_SENSE\n");
  1479. memset(ptr, 0, 18);
  1480. ptr[0] = 0xF0;
  1481. ptr[2] = info->sense_key;
  1482. ptr[7] = 11;
  1483. ptr[12] = info->sense_asc;
  1484. ptr[13] = info->sense_ascq;
  1485. usb_stor_set_xfer_buf(ptr, 18, srb);
  1486. return USB_STOR_TRANSPORT_GOOD;
  1487. }
  1488. if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
  1489. /*
  1490. * sure. whatever. not like we can stop the user from popping
  1491. * the media out of the device (no locking doors, etc)
  1492. */
  1493. return USB_STOR_TRANSPORT_GOOD;
  1494. }
  1495. usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n",
  1496. srb->cmnd[0], srb->cmnd[0]);
  1497. info->sense_key = 0x05;
  1498. info->sense_asc = 0x20;
  1499. info->sense_ascq = 0x00;
  1500. return USB_STOR_TRANSPORT_FAILED;
  1501. }
  1502. static int init_usbat_cd(struct us_data *us)
  1503. {
  1504. return init_usbat(us, USBAT_DEV_HP8200);
  1505. }
  1506. static int init_usbat_flash(struct us_data *us)
  1507. {
  1508. return init_usbat(us, USBAT_DEV_FLASH);
  1509. }
  1510. static struct scsi_host_template usbat_host_template;
  1511. static int usbat_probe(struct usb_interface *intf,
  1512. const struct usb_device_id *id)
  1513. {
  1514. struct us_data *us;
  1515. int result;
  1516. result = usb_stor_probe1(&us, intf, id,
  1517. (id - usbat_usb_ids) + usbat_unusual_dev_list,
  1518. &usbat_host_template);
  1519. if (result)
  1520. return result;
  1521. /*
  1522. * The actual transport will be determined later by the
  1523. * initialization routine; this is just a placeholder.
  1524. */
  1525. us->transport_name = "Shuttle USBAT";
  1526. us->transport = usbat_flash_transport;
  1527. us->transport_reset = usb_stor_CB_reset;
  1528. us->max_lun = 0;
  1529. result = usb_stor_probe2(us);
  1530. return result;
  1531. }
  1532. static struct usb_driver usbat_driver = {
  1533. .name = DRV_NAME,
  1534. .probe = usbat_probe,
  1535. .disconnect = usb_stor_disconnect,
  1536. .suspend = usb_stor_suspend,
  1537. .resume = usb_stor_resume,
  1538. .reset_resume = usb_stor_reset_resume,
  1539. .pre_reset = usb_stor_pre_reset,
  1540. .post_reset = usb_stor_post_reset,
  1541. .id_table = usbat_usb_ids,
  1542. .soft_unbind = 1,
  1543. .no_dynamic_id = 1,
  1544. };
  1545. module_usb_stor_driver(usbat_driver, usbat_host_template, DRV_NAME);