usb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. #include <linux/sched.h>
  2. #include <linux/errno.h>
  3. #include <linux/freezer.h>
  4. #include <linux/module.h>
  5. #include <linux/init.h>
  6. #include <linux/slab.h>
  7. #include <linux/kthread.h>
  8. #include <linux/mutex.h>
  9. #include <linux/utsname.h>
  10. #include <scsi/scsi.h>
  11. #include <scsi/scsi_cmnd.h>
  12. #include <scsi/scsi_device.h>
  13. #include "usb.h"
  14. #include "scsiglue.h"
  15. #include "smil.h"
  16. #include "transport.h"
  17. /* Some informational data */
  18. MODULE_AUTHOR("Domao");
  19. MODULE_DESCRIPTION("ENE USB Mass Storage driver for Linux");
  20. MODULE_LICENSE("GPL");
  21. static unsigned int delay_use = 1;
  22. static struct usb_device_id eucr_usb_ids [] = {
  23. { USB_DEVICE(0x058f, 0x6366) },
  24. { USB_DEVICE(0x0cf2, 0x6230) },
  25. { USB_DEVICE(0x0cf2, 0x6250) },
  26. { } /* Terminating entry */
  27. };
  28. MODULE_DEVICE_TABLE (usb, eucr_usb_ids);
  29. #ifdef CONFIG_PM
  30. static int eucr_suspend(struct usb_interface *iface, pm_message_t message)
  31. {
  32. struct us_data *us = usb_get_intfdata(iface);
  33. pr_info("--- eucr_suspend ---\n");
  34. /* Wait until no command is running */
  35. mutex_lock(&us->dev_mutex);
  36. //US_DEBUGP("%s\n", __func__);
  37. if (us->suspend_resume_hook)
  38. (us->suspend_resume_hook)(us, US_SUSPEND);
  39. /* When runtime PM is working, we'll set a flag to indicate
  40. * whether we should autoresume when a SCSI request arrives. */
  41. // us->Power_IsResum = true;
  42. //us->SD_Status.Ready = 0;
  43. mutex_unlock(&us->dev_mutex);
  44. return 0;
  45. }
  46. //EXPORT_SYMBOL_GPL(eucr_suspend);
  47. static int eucr_resume(struct usb_interface *iface)
  48. {
  49. BYTE tmp = 0;
  50. struct us_data *us = usb_get_intfdata(iface);
  51. pr_info("--- eucr_resume---\n");
  52. mutex_lock(&us->dev_mutex);
  53. //US_DEBUGP("%s\n", __func__);
  54. if (us->suspend_resume_hook)
  55. (us->suspend_resume_hook)(us, US_RESUME);
  56. mutex_unlock(&us->dev_mutex);
  57. us->Power_IsResum = true;
  58. //
  59. //us->SD_Status.Ready = 0; //??
  60. us->MS_Status = *(PMS_STATUS)&tmp;
  61. us->SM_Status = *(PSM_STATUS)&tmp;
  62. return 0;
  63. }
  64. //EXPORT_SYMBOL_GPL(eucr_resume);
  65. static int eucr_reset_resume(struct usb_interface *iface)
  66. {
  67. BYTE tmp = 0;
  68. struct us_data *us = usb_get_intfdata(iface);
  69. pr_info("--- eucr_reset_resume---\n");
  70. //US_DEBUGP("%s\n", __func__);
  71. /* Report the reset to the SCSI core */
  72. usb_stor_report_bus_reset(us);
  73. /* FIXME: Notify the subdrivers that they need to reinitialize
  74. * the device */
  75. //ENE_InitMedia(us);
  76. us->Power_IsResum = true;
  77. //
  78. //us->SD_Status.Ready = 0; //??
  79. us->MS_Status = *(PMS_STATUS)&tmp;
  80. us->SM_Status = *(PSM_STATUS)&tmp;
  81. return 0;
  82. }
  83. //EXPORT_SYMBOL_GPL(usb_stor_reset_resume);
  84. #else
  85. #define eucr_suspend NULL
  86. #define eucr_resume NULL
  87. #define eucr_reset_resume NULL
  88. #endif
  89. //----- eucr_pre_reset() ---------------------
  90. static int eucr_pre_reset(struct usb_interface *iface)
  91. {
  92. struct us_data *us = usb_get_intfdata(iface);
  93. pr_info("usb --- eucr_pre_reset\n");
  94. /* Make sure no command runs during the reset */
  95. mutex_lock(&us->dev_mutex);
  96. return 0;
  97. }
  98. //----- eucr_post_reset() ---------------------
  99. static int eucr_post_reset(struct usb_interface *iface)
  100. {
  101. struct us_data *us = usb_get_intfdata(iface);
  102. pr_info("usb --- eucr_post_reset\n");
  103. /* Report the reset to the SCSI core */
  104. usb_stor_report_bus_reset(us);
  105. mutex_unlock(&us->dev_mutex);
  106. return 0;
  107. }
  108. //----- fill_inquiry_response() ---------------------
  109. void fill_inquiry_response(struct us_data *us, unsigned char *data, unsigned int data_len)
  110. {
  111. pr_info("usb --- fill_inquiry_response\n");
  112. if (data_len<36) // You lose.
  113. return;
  114. if (data[0]&0x20)
  115. {
  116. memset(data+8,0,28);
  117. }
  118. else
  119. {
  120. u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice);
  121. memcpy(data+8, us->unusual_dev->vendorName,
  122. strlen(us->unusual_dev->vendorName) > 8 ? 8 :
  123. strlen(us->unusual_dev->vendorName));
  124. memcpy(data+16, us->unusual_dev->productName,
  125. strlen(us->unusual_dev->productName) > 16 ? 16 :
  126. strlen(us->unusual_dev->productName));
  127. data[32] = 0x30 + ((bcdDevice>>12) & 0x0F);
  128. data[33] = 0x30 + ((bcdDevice>>8) & 0x0F);
  129. data[34] = 0x30 + ((bcdDevice>>4) & 0x0F);
  130. data[35] = 0x30 + ((bcdDevice) & 0x0F);
  131. }
  132. usb_stor_set_xfer_buf(us, data, data_len, us->srb, TO_XFER_BUF);
  133. }
  134. //----- usb_stor_control_thread() ---------------------
  135. static int usb_stor_control_thread(void * __us)
  136. {
  137. struct us_data *us = (struct us_data *)__us;
  138. struct Scsi_Host *host = us_to_host(us);
  139. pr_info("usb --- usb_stor_control_thread\n");
  140. for(;;)
  141. {
  142. if (wait_for_completion_interruptible(&us->cmnd_ready))
  143. break;
  144. /* lock the device pointers */
  145. mutex_lock(&(us->dev_mutex));
  146. /* if the device has disconnected, we are free to exit */
  147. if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
  148. mutex_unlock(&us->dev_mutex);
  149. break;
  150. }
  151. /* lock access to the state */
  152. scsi_lock(host);
  153. /* When we are called with no command pending, we're done */
  154. if (us->srb == NULL)
  155. {
  156. scsi_unlock(host);
  157. mutex_unlock(&us->dev_mutex);
  158. //US_DEBUGP("-- exiting\n");
  159. break;
  160. }
  161. /* has the command timed out *already* ? */
  162. if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags))
  163. {
  164. us->srb->result = DID_ABORT << 16;
  165. goto SkipForAbort;
  166. }
  167. scsi_unlock(host);
  168. if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL)
  169. {
  170. us->srb->result = DID_ERROR << 16;
  171. }
  172. else if (us->srb->device->id && !(us->fflags & US_FL_SCM_MULT_TARG))
  173. {
  174. us->srb->result = DID_BAD_TARGET << 16;
  175. }
  176. else if (us->srb->device->lun > us->max_lun)
  177. {
  178. us->srb->result = DID_BAD_TARGET << 16;
  179. }
  180. else if ((us->srb->cmnd[0] == INQUIRY) && (us->fflags & US_FL_FIX_INQUIRY))
  181. {
  182. unsigned char data_ptr[36] = {0x00, 0x80, 0x02, 0x02, 0x1F, 0x00, 0x00, 0x00};
  183. fill_inquiry_response(us, data_ptr, 36);
  184. us->srb->result = SAM_STAT_GOOD;
  185. }
  186. else
  187. {
  188. us->proto_handler(us->srb, us);
  189. }
  190. /* lock access to the state */
  191. scsi_lock(host);
  192. /* indicate that the command is done */
  193. if (us->srb->result != DID_ABORT << 16)
  194. {
  195. us->srb->scsi_done(us->srb);
  196. }
  197. else
  198. {
  199. SkipForAbort:
  200. pr_info("scsi command aborted\n");
  201. }
  202. if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags))
  203. {
  204. complete(&(us->notify));
  205. /* Allow USB transfers to resume */
  206. clear_bit(US_FLIDX_ABORTING, &us->dflags);
  207. clear_bit(US_FLIDX_TIMED_OUT, &us->dflags);
  208. }
  209. /* finished working on this command */
  210. us->srb = NULL;
  211. scsi_unlock(host);
  212. /* unlock the device pointers */
  213. mutex_unlock(&us->dev_mutex);
  214. } /* for (;;) */
  215. /* Wait until we are told to stop */
  216. for (;;)
  217. {
  218. set_current_state(TASK_INTERRUPTIBLE);
  219. if (kthread_should_stop())
  220. break;
  221. schedule();
  222. }
  223. __set_current_state(TASK_RUNNING);
  224. return 0;
  225. }
  226. //----- associate_dev() ---------------------
  227. static int associate_dev(struct us_data *us, struct usb_interface *intf)
  228. {
  229. pr_info("usb --- associate_dev\n");
  230. /* Fill in the device-related fields */
  231. us->pusb_dev = interface_to_usbdev(intf);
  232. us->pusb_intf = intf;
  233. us->ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
  234. /* Store our private data in the interface */
  235. usb_set_intfdata(intf, us);
  236. /* Allocate the device-related DMA-mapped buffers */
  237. us->cr = usb_alloc_coherent(us->pusb_dev, sizeof(*us->cr), GFP_KERNEL, &us->cr_dma);
  238. if (!us->cr)
  239. {
  240. pr_info("usb_ctrlrequest allocation failed\n");
  241. return -ENOMEM;
  242. }
  243. us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE, GFP_KERNEL, &us->iobuf_dma);
  244. if (!us->iobuf)
  245. {
  246. pr_info("I/O buffer allocation failed\n");
  247. return -ENOMEM;
  248. }
  249. us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL);
  250. if (!us->sensebuf)
  251. {
  252. pr_info("Sense buffer allocation failed\n");
  253. return -ENOMEM;
  254. }
  255. return 0;
  256. }
  257. //----- get_device_info() ---------------------
  258. static int get_device_info(struct us_data *us, const struct usb_device_id *id)
  259. {
  260. struct usb_device *dev = us->pusb_dev;
  261. struct usb_interface_descriptor *idesc = &us->pusb_intf->cur_altsetting->desc;
  262. pr_info("usb --- get_device_info\n");
  263. us->subclass = idesc->bInterfaceSubClass;
  264. us->protocol = idesc->bInterfaceProtocol;
  265. us->fflags = USB_US_ORIG_FLAGS(id->driver_info);
  266. us->Power_IsResum = false;
  267. if (us->fflags & US_FL_IGNORE_DEVICE)
  268. {
  269. pr_info("device ignored\n");
  270. return -ENODEV;
  271. }
  272. if (dev->speed != USB_SPEED_HIGH)
  273. us->fflags &= ~US_FL_GO_SLOW;
  274. return 0;
  275. }
  276. //----- get_transport() ---------------------
  277. static int get_transport(struct us_data *us)
  278. {
  279. pr_info("usb --- get_transport\n");
  280. switch (us->protocol) {
  281. case USB_PR_BULK:
  282. us->transport_name = "Bulk";
  283. us->transport = usb_stor_Bulk_transport;
  284. us->transport_reset = usb_stor_Bulk_reset;
  285. break;
  286. default:
  287. return -EIO;
  288. }
  289. /* pr_info("Transport: %s\n", us->transport_name); */
  290. /* fix for single-lun devices */
  291. if (us->fflags & US_FL_SINGLE_LUN)
  292. us->max_lun = 0;
  293. return 0;
  294. }
  295. //----- get_protocol() ---------------------
  296. static int get_protocol(struct us_data *us)
  297. {
  298. pr_info("usb --- get_protocol\n");
  299. pr_info("us->pusb_dev->descriptor.idVendor = %x\n",
  300. us->pusb_dev->descriptor.idVendor);
  301. pr_info("us->pusb_dev->descriptor.idProduct = %x\n",
  302. us->pusb_dev->descriptor.idProduct);
  303. switch (us->subclass) {
  304. case USB_SC_SCSI:
  305. us->protocol_name = "Transparent SCSI";
  306. if( (us->pusb_dev->descriptor.idVendor == 0x0CF2) && (us->pusb_dev->descriptor.idProduct == 0x6250) )
  307. us->proto_handler = ENE_stor_invoke_transport;
  308. else
  309. us->proto_handler = usb_stor_invoke_transport;
  310. break;
  311. default:
  312. return -EIO;
  313. }
  314. /* pr_info("Protocol: %s\n", us->protocol_name); */
  315. return 0;
  316. }
  317. //----- get_pipes() ---------------------
  318. static int get_pipes(struct us_data *us)
  319. {
  320. struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting;
  321. int i;
  322. struct usb_endpoint_descriptor *ep;
  323. struct usb_endpoint_descriptor *ep_in = NULL;
  324. struct usb_endpoint_descriptor *ep_out = NULL;
  325. struct usb_endpoint_descriptor *ep_int = NULL;
  326. pr_info("usb --- get_pipes\n");
  327. for (i = 0; i < altsetting->desc.bNumEndpoints; i++)
  328. {
  329. ep = &altsetting->endpoint[i].desc;
  330. if (usb_endpoint_xfer_bulk(ep))
  331. {
  332. if (usb_endpoint_dir_in(ep))
  333. {
  334. if (!ep_in)
  335. ep_in = ep;
  336. }
  337. else
  338. {
  339. if (!ep_out)
  340. ep_out = ep;
  341. }
  342. }
  343. else if (usb_endpoint_is_int_in(ep))
  344. {
  345. if (!ep_int)
  346. ep_int = ep;
  347. }
  348. }
  349. if (!ep_in || !ep_out || (us->protocol == USB_PR_CBI && !ep_int))
  350. {
  351. pr_info("Endpoint sanity check failed! Rejecting dev.\n");
  352. return -EIO;
  353. }
  354. /* Calculate and store the pipe values */
  355. us->send_ctrl_pipe = usb_sndctrlpipe(us->pusb_dev, 0);
  356. us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0);
  357. us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev, ep_out->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
  358. us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev, ep_in->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
  359. if (ep_int)
  360. {
  361. us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev, ep_int->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
  362. us->ep_bInterval = ep_int->bInterval;
  363. }
  364. return 0;
  365. }
  366. //----- usb_stor_acquire_resources() ---------------------
  367. static int usb_stor_acquire_resources(struct us_data *us)
  368. {
  369. struct task_struct *th;
  370. pr_info("usb --- usb_stor_acquire_resources\n");
  371. us->current_urb = usb_alloc_urb(0, GFP_KERNEL);
  372. if (!us->current_urb)
  373. {
  374. pr_info("URB allocation failed\n");
  375. return -ENOMEM;
  376. }
  377. /* Start up our control thread */
  378. th = kthread_run(usb_stor_control_thread, us, "eucr-storage");
  379. if (IS_ERR(th))
  380. {
  381. pr_info("Unable to start control thread\n");
  382. return PTR_ERR(th);
  383. }
  384. us->ctl_thread = th;
  385. return 0;
  386. }
  387. //----- usb_stor_release_resources() ---------------------
  388. static void usb_stor_release_resources(struct us_data *us)
  389. {
  390. pr_info("usb --- usb_stor_release_resources\n");
  391. SM_FreeMem();
  392. complete(&us->cmnd_ready);
  393. if (us->ctl_thread)
  394. kthread_stop(us->ctl_thread);
  395. /* Call the destructor routine, if it exists */
  396. if (us->extra_destructor)
  397. {
  398. pr_info("-- calling extra_destructor()\n");
  399. us->extra_destructor(us->extra);
  400. }
  401. /* Free the extra data and the URB */
  402. kfree(us->extra);
  403. usb_free_urb(us->current_urb);
  404. }
  405. //----- dissociate_dev() ---------------------
  406. static void dissociate_dev(struct us_data *us)
  407. {
  408. pr_info("usb --- dissociate_dev\n");
  409. kfree(us->sensebuf);
  410. /* Free the device-related DMA-mapped buffers */
  411. if (us->cr)
  412. usb_free_coherent(us->pusb_dev, sizeof(*us->cr), us->cr, us->cr_dma);
  413. if (us->iobuf)
  414. usb_free_coherent(us->pusb_dev, US_IOBUF_SIZE, us->iobuf, us->iobuf_dma);
  415. /* Remove our private data from the interface */
  416. usb_set_intfdata(us->pusb_intf, NULL);
  417. }
  418. //----- quiesce_and_remove_host() ---------------------
  419. static void quiesce_and_remove_host(struct us_data *us)
  420. {
  421. struct Scsi_Host *host = us_to_host(us);
  422. pr_info("usb --- quiesce_and_remove_host\n");
  423. /* If the device is really gone, cut short reset delays */
  424. if (us->pusb_dev->state == USB_STATE_NOTATTACHED)
  425. set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
  426. /* Prevent SCSI-scanning (if it hasn't started yet)
  427. * and wait for the SCSI-scanning thread to stop.
  428. */
  429. set_bit(US_FLIDX_DONT_SCAN, &us->dflags);
  430. wake_up(&us->delay_wait);
  431. wait_for_completion(&us->scanning_done);
  432. /* Removing the host will perform an orderly shutdown: caches
  433. * synchronized, disks spun down, etc.
  434. */
  435. scsi_remove_host(host);
  436. /* Prevent any new commands from being accepted and cut short
  437. * reset delays.
  438. */
  439. scsi_lock(host);
  440. set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
  441. scsi_unlock(host);
  442. wake_up(&us->delay_wait);
  443. }
  444. //----- release_everything() ---------------------
  445. static void release_everything(struct us_data *us)
  446. {
  447. pr_info("usb --- release_everything\n");
  448. usb_stor_release_resources(us);
  449. dissociate_dev(us);
  450. scsi_host_put(us_to_host(us));
  451. }
  452. //----- usb_stor_scan_thread() ---------------------
  453. static int usb_stor_scan_thread(void * __us)
  454. {
  455. struct us_data *us = (struct us_data *)__us;
  456. pr_info("usb --- usb_stor_scan_thread\n");
  457. pr_info("EUCR : device found at %d\n", us->pusb_dev->devnum);
  458. set_freezable();
  459. /* Wait for the timeout to expire or for a disconnect */
  460. if (delay_use > 0) {
  461. wait_event_freezable_timeout(us->delay_wait,
  462. test_bit(US_FLIDX_DONT_SCAN, &us->dflags),
  463. delay_use * HZ);
  464. }
  465. /* If the device is still connected, perform the scanning */
  466. if (!test_bit(US_FLIDX_DONT_SCAN, &us->dflags))
  467. {
  468. /* For bulk-only devices, determine the max LUN value */
  469. if (us->protocol == USB_PR_BULK && !(us->fflags & US_FL_SINGLE_LUN))
  470. {
  471. mutex_lock(&us->dev_mutex);
  472. us->max_lun = usb_stor_Bulk_max_lun(us);
  473. mutex_unlock(&us->dev_mutex);
  474. }
  475. scsi_scan_host(us_to_host(us));
  476. pr_info("EUCR : device scan complete\n");
  477. }
  478. complete_and_exit(&us->scanning_done, 0);
  479. }
  480. //----- eucr_probe() ---------------------
  481. static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id)
  482. {
  483. struct Scsi_Host *host;
  484. struct us_data *us;
  485. int result;
  486. BYTE MiscReg03 = 0;
  487. struct task_struct *th;
  488. pr_info("usb --- eucr_probe\n");
  489. host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us));
  490. if (!host)
  491. {
  492. pr_info("Unable to allocate the scsi host\n");
  493. return -ENOMEM;
  494. }
  495. /* Allow 16-byte CDBs and thus > 2TB */
  496. host->max_cmd_len = 16;
  497. us = host_to_us(host);
  498. memset(us, 0, sizeof(struct us_data));
  499. mutex_init(&(us->dev_mutex));
  500. init_completion(&us->cmnd_ready);
  501. init_completion(&(us->notify));
  502. init_waitqueue_head(&us->delay_wait);
  503. init_completion(&us->scanning_done);
  504. /* Associate the us_data structure with the USB device */
  505. result = associate_dev(us, intf);
  506. if (result)
  507. goto BadDevice;
  508. /* Get Device info */
  509. result = get_device_info(us, id);
  510. if (result)
  511. goto BadDevice;
  512. /* Get the transport, protocol, and pipe settings */
  513. result = get_transport(us);
  514. if (result)
  515. goto BadDevice;
  516. result = get_protocol(us);
  517. if (result)
  518. goto BadDevice;
  519. result = get_pipes(us);
  520. if (result)
  521. goto BadDevice;
  522. /* Acquire all the other resources and add the host */
  523. result = usb_stor_acquire_resources(us);
  524. if (result)
  525. goto BadDevice;
  526. result = scsi_add_host(host, &intf->dev);
  527. if (result)
  528. {
  529. pr_info("Unable to add the scsi host\n");
  530. goto BadDevice;
  531. }
  532. /* Start up the thread for delayed SCSI-device scanning */
  533. th = kthread_create(usb_stor_scan_thread, us, "eucr-stor-scan");
  534. if (IS_ERR(th))
  535. {
  536. pr_info("Unable to start the device-scanning thread\n");
  537. complete(&us->scanning_done);
  538. quiesce_and_remove_host(us);
  539. result = PTR_ERR(th);
  540. goto BadDevice;
  541. }
  542. wake_up_process(th);
  543. /* probe card type */
  544. result = ENE_Read_BYTE(us, REG_CARD_STATUS, &MiscReg03);
  545. if (result != USB_STOR_XFER_GOOD) {
  546. result = USB_STOR_TRANSPORT_ERROR;
  547. quiesce_and_remove_host(us);
  548. goto BadDevice;
  549. }
  550. if (!(MiscReg03 & 0x02)) {
  551. result = -ENODEV;
  552. quiesce_and_remove_host(us);
  553. pr_info("keucr: The driver only supports SM/MS card.\
  554. To use SD card, \
  555. please build driver/usb/storage/ums-eneub6250.ko\n");
  556. goto BadDevice;
  557. }
  558. return 0;
  559. /* We come here if there are any problems */
  560. BadDevice:
  561. pr_info("usb --- eucr_probe failed\n");
  562. release_everything(us);
  563. return result;
  564. }
  565. //----- eucr_disconnect() ---------------------
  566. static void eucr_disconnect(struct usb_interface *intf)
  567. {
  568. struct us_data *us = usb_get_intfdata(intf);
  569. pr_info("usb --- eucr_disconnect\n");
  570. quiesce_and_remove_host(us);
  571. release_everything(us);
  572. }
  573. /***********************************************************************
  574. * Initialization and registration
  575. ***********************************************************************/
  576. //----- usb_storage_driver() ---------------------
  577. static struct usb_driver usb_storage_driver = {
  578. .name = "eucr",
  579. .probe = eucr_probe,
  580. .suspend = eucr_suspend,
  581. .resume = eucr_resume,
  582. .reset_resume = eucr_reset_resume,
  583. .disconnect = eucr_disconnect,
  584. .pre_reset = eucr_pre_reset,
  585. .post_reset = eucr_post_reset,
  586. .id_table = eucr_usb_ids,
  587. .soft_unbind = 1,
  588. };
  589. //----- usb_stor_init() ---------------------
  590. static int __init usb_stor_init(void)
  591. {
  592. int retval;
  593. pr_info("usb --- usb_stor_init start\n");
  594. retval = usb_register(&usb_storage_driver);
  595. if (retval == 0)
  596. pr_info("ENE USB Mass Storage support registered.\n");
  597. return retval;
  598. }
  599. //----- usb_stor_exit() ---------------------
  600. static void __exit usb_stor_exit(void)
  601. {
  602. pr_info("usb --- usb_stor_exit\n");
  603. usb_deregister(&usb_storage_driver) ;
  604. }
  605. module_init(usb_stor_init);
  606. module_exit(usb_stor_exit);