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