storage_common.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /*
  2. * storage_common.c -- Common definitions for mass storage functionality
  3. *
  4. * Copyright (C) 2003-2008 Alan Stern
  5. * Copyeight (C) 2009 Samsung Electronics
  6. * Author: Michal Nazarewicz (m.nazarewicz@samsung.com)
  7. *
  8. * Ported to u-boot:
  9. * Andrzej Pietrasiewicz <andrzej.p@samsung.com>
  10. *
  11. * Code refactoring & cleanup:
  12. * Łukasz Majewski <l.majewski@samsung.com>
  13. *
  14. * SPDX-License-Identifier: GPL-2.0+
  15. */
  16. /*
  17. * This file requires the following identifiers used in USB strings to
  18. * be defined (each of type pointer to char):
  19. * - fsg_string_manufacturer -- name of the manufacturer
  20. * - fsg_string_product -- name of the product
  21. * - fsg_string_serial -- product's serial
  22. * - fsg_string_config -- name of the configuration
  23. * - fsg_string_interface -- name of the interface
  24. * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS
  25. * macro is defined prior to including this file.
  26. */
  27. /*
  28. * When FSG_NO_INTR_EP is defined fsg_fs_intr_in_desc and
  29. * fsg_hs_intr_in_desc objects as well as
  30. * FSG_FS_FUNCTION_PRE_EP_ENTRIES and FSG_HS_FUNCTION_PRE_EP_ENTRIES
  31. * macros are not defined.
  32. *
  33. * When FSG_NO_DEVICE_STRINGS is defined FSG_STRING_MANUFACTURER,
  34. * FSG_STRING_PRODUCT, FSG_STRING_SERIAL and FSG_STRING_CONFIG are not
  35. * defined (as well as corresponding entries in string tables are
  36. * missing) and FSG_STRING_INTERFACE has value of zero.
  37. *
  38. * When FSG_NO_OTG is defined fsg_otg_desc won't be defined.
  39. */
  40. /*
  41. * When FSG_BUFFHD_STATIC_BUFFER is defined when this file is included
  42. * the fsg_buffhd structure's buf field will be an array of FSG_BUFLEN
  43. * characters rather then a pointer to void.
  44. */
  45. /* #include <asm/unaligned.h> */
  46. /*
  47. * Thanks to NetChip Technologies for donating this product ID.
  48. *
  49. * DO NOT REUSE THESE IDs with any other driver!! Ever!!
  50. * Instead: allocate your own, using normal USB-IF procedures.
  51. */
  52. #define FSG_VENDOR_ID 0x0525 /* NetChip */
  53. #define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */
  54. /*-------------------------------------------------------------------------*/
  55. #ifndef DEBUG
  56. #undef VERBOSE_DEBUG
  57. #undef DUMP_MSGS
  58. #endif /* !DEBUG */
  59. #ifdef VERBOSE_DEBUG
  60. #define VLDBG LDBG
  61. #else
  62. #define VLDBG(lun, fmt, args...) do { } while (0)
  63. #endif /* VERBOSE_DEBUG */
  64. /*
  65. #define LDBG(lun, fmt, args...) dev_dbg (&(lun)->dev, fmt, ## args)
  66. #define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args)
  67. #define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args)
  68. #define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args)
  69. */
  70. #define LDBG(lun, fmt, args...) do { } while (0)
  71. #define LERROR(lun, fmt, args...) do { } while (0)
  72. #define LWARN(lun, fmt, args...) do { } while (0)
  73. #define LINFO(lun, fmt, args...) do { } while (0)
  74. /*
  75. * Keep those macros in sync with those in
  76. * include/linux/usb/composite.h or else GCC will complain. If they
  77. * are identical (the same names of arguments, white spaces in the
  78. * same places) GCC will allow redefinition otherwise (even if some
  79. * white space is removed or added) warning will be issued.
  80. *
  81. * Those macros are needed here because File Storage Gadget does not
  82. * include the composite.h header. For composite gadgets those macros
  83. * are redundant since composite.h is included any way.
  84. *
  85. * One could check whether those macros are already defined (which
  86. * would indicate composite.h had been included) or not (which would
  87. * indicate we were in FSG) but this is not done because a warning is
  88. * desired if definitions here differ from the ones in composite.h.
  89. *
  90. * We want the definitions to match and be the same in File Storage
  91. * Gadget as well as Mass Storage Function (and so composite gadgets
  92. * using MSF). If someone changes them in composite.h it will produce
  93. * a warning in this file when building MSF.
  94. */
  95. #define DBG(d, fmt, args...) debug(fmt , ## args)
  96. #define VDBG(d, fmt, args...) debug(fmt , ## args)
  97. /* #define ERROR(d, fmt, args...) printf(fmt , ## args) */
  98. /* #define WARNING(d, fmt, args...) printf(fmt , ## args) */
  99. /* #define INFO(d, fmt, args...) printf(fmt , ## args) */
  100. /* #define DBG(d, fmt, args...) do { } while (0) */
  101. /* #define VDBG(d, fmt, args...) do { } while (0) */
  102. #define ERROR(d, fmt, args...) do { } while (0)
  103. #define WARNING(d, fmt, args...) do { } while (0)
  104. #define INFO(d, fmt, args...) do { } while (0)
  105. #ifdef DUMP_MSGS
  106. /* dump_msg(fsg, const char * label, const u8 * buf, unsigned length); */
  107. # define dump_msg(fsg, label, buf, length) do { \
  108. if (length < 512) { \
  109. DBG(fsg, "%s, length %u:\n", label, length); \
  110. print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \
  111. 16, 1, buf, length, 0); \
  112. } \
  113. } while (0)
  114. # define dump_cdb(fsg) do { } while (0)
  115. #else
  116. # define dump_msg(fsg, /* const char * */ label, \
  117. /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
  118. # ifdef VERBOSE_DEBUG
  119. # define dump_cdb(fsg) \
  120. print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \
  121. 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \
  122. # else
  123. # define dump_cdb(fsg) do { } while (0)
  124. # endif /* VERBOSE_DEBUG */
  125. #endif /* DUMP_MSGS */
  126. /*-------------------------------------------------------------------------*/
  127. /* SCSI device types */
  128. #define TYPE_DISK 0x00
  129. #define TYPE_CDROM 0x05
  130. /* USB protocol value = the transport method */
  131. #define USB_PR_CBI 0x00 /* Control/Bulk/Interrupt */
  132. #define USB_PR_CB 0x01 /* Control/Bulk w/o interrupt */
  133. #define USB_PR_BULK 0x50 /* Bulk-only */
  134. /* USB subclass value = the protocol encapsulation */
  135. #define USB_SC_RBC 0x01 /* Reduced Block Commands (flash) */
  136. #define USB_SC_8020 0x02 /* SFF-8020i, MMC-2, ATAPI (CD-ROM) */
  137. #define USB_SC_QIC 0x03 /* QIC-157 (tape) */
  138. #define USB_SC_UFI 0x04 /* UFI (floppy) */
  139. #define USB_SC_8070 0x05 /* SFF-8070i (removable) */
  140. #define USB_SC_SCSI 0x06 /* Transparent SCSI */
  141. /* Bulk-only data structures */
  142. /* Command Block Wrapper */
  143. struct fsg_bulk_cb_wrap {
  144. __le32 Signature; /* Contains 'USBC' */
  145. u32 Tag; /* Unique per command id */
  146. __le32 DataTransferLength; /* Size of the data */
  147. u8 Flags; /* Direction in bit 7 */
  148. u8 Lun; /* LUN (normally 0) */
  149. u8 Length; /* Of the CDB, <= MAX_COMMAND_SIZE */
  150. u8 CDB[16]; /* Command Data Block */
  151. };
  152. #define USB_BULK_CB_WRAP_LEN 31
  153. #define USB_BULK_CB_SIG 0x43425355 /* Spells out USBC */
  154. #define USB_BULK_IN_FLAG 0x80
  155. /* Command Status Wrapper */
  156. struct bulk_cs_wrap {
  157. __le32 Signature; /* Should = 'USBS' */
  158. u32 Tag; /* Same as original command */
  159. __le32 Residue; /* Amount not transferred */
  160. u8 Status; /* See below */
  161. };
  162. #define USB_BULK_CS_WRAP_LEN 13
  163. #define USB_BULK_CS_SIG 0x53425355 /* Spells out 'USBS' */
  164. #define USB_STATUS_PASS 0
  165. #define USB_STATUS_FAIL 1
  166. #define USB_STATUS_PHASE_ERROR 2
  167. /* Bulk-only class specific requests */
  168. #define USB_BULK_RESET_REQUEST 0xff
  169. #define USB_BULK_GET_MAX_LUN_REQUEST 0xfe
  170. /* CBI Interrupt data structure */
  171. struct interrupt_data {
  172. u8 bType;
  173. u8 bValue;
  174. };
  175. #define CBI_INTERRUPT_DATA_LEN 2
  176. /* CBI Accept Device-Specific Command request */
  177. #define USB_CBI_ADSC_REQUEST 0x00
  178. /* Length of a SCSI Command Data Block */
  179. #define MAX_COMMAND_SIZE 16
  180. /* SCSI commands that we recognize */
  181. #define SC_FORMAT_UNIT 0x04
  182. #define SC_INQUIRY 0x12
  183. #define SC_MODE_SELECT_6 0x15
  184. #define SC_MODE_SELECT_10 0x55
  185. #define SC_MODE_SENSE_6 0x1a
  186. #define SC_MODE_SENSE_10 0x5a
  187. #define SC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
  188. #define SC_READ_6 0x08
  189. #define SC_READ_10 0x28
  190. #define SC_READ_12 0xa8
  191. #define SC_READ_CAPACITY 0x25
  192. #define SC_READ_FORMAT_CAPACITIES 0x23
  193. #define SC_READ_HEADER 0x44
  194. #define SC_READ_TOC 0x43
  195. #define SC_RELEASE 0x17
  196. #define SC_REQUEST_SENSE 0x03
  197. #define SC_RESERVE 0x16
  198. #define SC_SEND_DIAGNOSTIC 0x1d
  199. #define SC_START_STOP_UNIT 0x1b
  200. #define SC_SYNCHRONIZE_CACHE 0x35
  201. #define SC_TEST_UNIT_READY 0x00
  202. #define SC_VERIFY 0x2f
  203. #define SC_WRITE_6 0x0a
  204. #define SC_WRITE_10 0x2a
  205. #define SC_WRITE_12 0xaa
  206. /* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
  207. #define SS_NO_SENSE 0
  208. #define SS_COMMUNICATION_FAILURE 0x040800
  209. #define SS_INVALID_COMMAND 0x052000
  210. #define SS_INVALID_FIELD_IN_CDB 0x052400
  211. #define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
  212. #define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
  213. #define SS_MEDIUM_NOT_PRESENT 0x023a00
  214. #define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
  215. #define SS_NOT_READY_TO_READY_TRANSITION 0x062800
  216. #define SS_RESET_OCCURRED 0x062900
  217. #define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
  218. #define SS_UNRECOVERED_READ_ERROR 0x031100
  219. #define SS_WRITE_ERROR 0x030c02
  220. #define SS_WRITE_PROTECTED 0x072700
  221. #define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */
  222. #define ASC(x) ((u8) ((x) >> 8))
  223. #define ASCQ(x) ((u8) (x))
  224. struct device_attribute { int i; };
  225. struct rw_semaphore { int i; };
  226. #define down_write(...) do { } while (0)
  227. #define up_write(...) do { } while (0)
  228. #define down_read(...) do { } while (0)
  229. #define up_read(...) do { } while (0)
  230. #define ETOOSMALL 525
  231. #include <usb_mass_storage.h>
  232. /*-------------------------------------------------------------------------*/
  233. struct fsg_lun {
  234. loff_t file_length;
  235. loff_t num_sectors;
  236. unsigned int initially_ro:1;
  237. unsigned int ro:1;
  238. unsigned int removable:1;
  239. unsigned int cdrom:1;
  240. unsigned int prevent_medium_removal:1;
  241. unsigned int registered:1;
  242. unsigned int info_valid:1;
  243. unsigned int nofua:1;
  244. u32 sense_data;
  245. u32 sense_data_info;
  246. u32 unit_attention_data;
  247. struct device dev;
  248. };
  249. #define fsg_lun_is_open(curlun) ((curlun)->filp != NULL)
  250. #if 0
  251. static struct fsg_lun *fsg_lun_from_dev(struct device *dev)
  252. {
  253. return container_of(dev, struct fsg_lun, dev);
  254. }
  255. #endif
  256. /* Big enough to hold our biggest descriptor */
  257. #define EP0_BUFSIZE 256
  258. #define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */
  259. /* Number of buffers we will use. 2 is enough for double-buffering */
  260. #define FSG_NUM_BUFFERS 2
  261. /* Default size of buffer length. */
  262. #define FSG_BUFLEN ((u32)16384)
  263. /* Maximal number of LUNs supported in mass storage function */
  264. #define FSG_MAX_LUNS 8
  265. enum fsg_buffer_state {
  266. BUF_STATE_EMPTY = 0,
  267. BUF_STATE_FULL,
  268. BUF_STATE_BUSY
  269. };
  270. struct fsg_buffhd {
  271. #ifdef FSG_BUFFHD_STATIC_BUFFER
  272. char buf[FSG_BUFLEN];
  273. #else
  274. void *buf;
  275. #endif
  276. enum fsg_buffer_state state;
  277. struct fsg_buffhd *next;
  278. /*
  279. * The NetChip 2280 is faster, and handles some protocol faults
  280. * better, if we don't submit any short bulk-out read requests.
  281. * So we will record the intended request length here.
  282. */
  283. unsigned int bulk_out_intended_length;
  284. struct usb_request *inreq;
  285. int inreq_busy;
  286. struct usb_request *outreq;
  287. int outreq_busy;
  288. };
  289. enum fsg_state {
  290. /* This one isn't used anywhere */
  291. FSG_STATE_COMMAND_PHASE = -10,
  292. FSG_STATE_DATA_PHASE,
  293. FSG_STATE_STATUS_PHASE,
  294. FSG_STATE_IDLE = 0,
  295. FSG_STATE_ABORT_BULK_OUT,
  296. FSG_STATE_RESET,
  297. FSG_STATE_INTERFACE_CHANGE,
  298. FSG_STATE_CONFIG_CHANGE,
  299. FSG_STATE_DISCONNECT,
  300. FSG_STATE_EXIT,
  301. FSG_STATE_TERMINATED
  302. };
  303. enum data_direction {
  304. DATA_DIR_UNKNOWN = 0,
  305. DATA_DIR_FROM_HOST,
  306. DATA_DIR_TO_HOST,
  307. DATA_DIR_NONE
  308. };
  309. /*-------------------------------------------------------------------------*/
  310. static inline u32 get_unaligned_be24(u8 *buf)
  311. {
  312. return 0xffffff & (u32) get_unaligned_be32(buf - 1);
  313. }
  314. /*-------------------------------------------------------------------------*/
  315. enum {
  316. #ifndef FSG_NO_DEVICE_STRINGS
  317. FSG_STRING_MANUFACTURER = 1,
  318. FSG_STRING_PRODUCT,
  319. FSG_STRING_SERIAL,
  320. FSG_STRING_CONFIG,
  321. #endif
  322. FSG_STRING_INTERFACE
  323. };
  324. #ifndef FSG_NO_OTG
  325. static struct usb_otg_descriptor
  326. fsg_otg_desc = {
  327. .bLength = sizeof fsg_otg_desc,
  328. .bDescriptorType = USB_DT_OTG,
  329. .bmAttributes = USB_OTG_SRP,
  330. };
  331. #endif
  332. /* There is only one interface. */
  333. static struct usb_interface_descriptor
  334. fsg_intf_desc = {
  335. .bLength = sizeof fsg_intf_desc,
  336. .bDescriptorType = USB_DT_INTERFACE,
  337. .bNumEndpoints = 2, /* Adjusted during fsg_bind() */
  338. .bInterfaceClass = USB_CLASS_MASS_STORAGE,
  339. .bInterfaceSubClass = USB_SC_SCSI, /* Adjusted during fsg_bind() */
  340. .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */
  341. .iInterface = FSG_STRING_INTERFACE,
  342. };
  343. /*
  344. * Three full-speed endpoint descriptors: bulk-in, bulk-out, and
  345. * interrupt-in.
  346. */
  347. static struct usb_endpoint_descriptor
  348. fsg_fs_bulk_in_desc = {
  349. .bLength = USB_DT_ENDPOINT_SIZE,
  350. .bDescriptorType = USB_DT_ENDPOINT,
  351. .bEndpointAddress = USB_DIR_IN,
  352. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  353. /* wMaxPacketSize set by autoconfiguration */
  354. };
  355. static struct usb_endpoint_descriptor
  356. fsg_fs_bulk_out_desc = {
  357. .bLength = USB_DT_ENDPOINT_SIZE,
  358. .bDescriptorType = USB_DT_ENDPOINT,
  359. .bEndpointAddress = USB_DIR_OUT,
  360. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  361. /* wMaxPacketSize set by autoconfiguration */
  362. };
  363. #ifndef FSG_NO_INTR_EP
  364. static struct usb_endpoint_descriptor
  365. fsg_fs_intr_in_desc = {
  366. .bLength = USB_DT_ENDPOINT_SIZE,
  367. .bDescriptorType = USB_DT_ENDPOINT,
  368. .bEndpointAddress = USB_DIR_IN,
  369. .bmAttributes = USB_ENDPOINT_XFER_INT,
  370. .wMaxPacketSize = cpu_to_le16(2),
  371. .bInterval = 32, /* frames -> 32 ms */
  372. };
  373. #ifndef FSG_NO_OTG
  374. # define FSG_FS_FUNCTION_PRE_EP_ENTRIES 2
  375. #else
  376. # define FSG_FS_FUNCTION_PRE_EP_ENTRIES 1
  377. #endif
  378. #endif
  379. static struct usb_descriptor_header *fsg_fs_function[] = {
  380. #ifndef FSG_NO_OTG
  381. (struct usb_descriptor_header *) &fsg_otg_desc,
  382. #endif
  383. (struct usb_descriptor_header *) &fsg_intf_desc,
  384. (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc,
  385. (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc,
  386. #ifndef FSG_NO_INTR_EP
  387. (struct usb_descriptor_header *) &fsg_fs_intr_in_desc,
  388. #endif
  389. NULL,
  390. };
  391. /*
  392. * USB 2.0 devices need to expose both high speed and full speed
  393. * descriptors, unless they only run at full speed.
  394. *
  395. * That means alternate endpoint descriptors (bigger packets)
  396. * and a "device qualifier" ... plus more construction options
  397. * for the configuration descriptor.
  398. */
  399. static struct usb_endpoint_descriptor
  400. fsg_hs_bulk_in_desc = {
  401. .bLength = USB_DT_ENDPOINT_SIZE,
  402. .bDescriptorType = USB_DT_ENDPOINT,
  403. /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */
  404. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  405. .wMaxPacketSize = cpu_to_le16(512),
  406. };
  407. static struct usb_endpoint_descriptor
  408. fsg_hs_bulk_out_desc = {
  409. .bLength = USB_DT_ENDPOINT_SIZE,
  410. .bDescriptorType = USB_DT_ENDPOINT,
  411. /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */
  412. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  413. .wMaxPacketSize = cpu_to_le16(512),
  414. .bInterval = 1, /* NAK every 1 uframe */
  415. };
  416. #ifndef FSG_NO_INTR_EP
  417. static struct usb_endpoint_descriptor
  418. fsg_hs_intr_in_desc = {
  419. .bLength = USB_DT_ENDPOINT_SIZE,
  420. .bDescriptorType = USB_DT_ENDPOINT,
  421. /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */
  422. .bmAttributes = USB_ENDPOINT_XFER_INT,
  423. .wMaxPacketSize = cpu_to_le16(2),
  424. .bInterval = 9, /* 2**(9-1) = 256 uframes -> 32 ms */
  425. };
  426. #ifndef FSG_NO_OTG
  427. # define FSG_HS_FUNCTION_PRE_EP_ENTRIES 2
  428. #else
  429. # define FSG_HS_FUNCTION_PRE_EP_ENTRIES 1
  430. #endif
  431. #endif
  432. static struct usb_descriptor_header *fsg_hs_function[] = {
  433. #ifndef FSG_NO_OTG
  434. (struct usb_descriptor_header *) &fsg_otg_desc,
  435. #endif
  436. (struct usb_descriptor_header *) &fsg_intf_desc,
  437. (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc,
  438. (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc,
  439. #ifndef FSG_NO_INTR_EP
  440. (struct usb_descriptor_header *) &fsg_hs_intr_in_desc,
  441. #endif
  442. NULL,
  443. };
  444. /* Maxpacket and other transfer characteristics vary by speed. */
  445. static struct usb_endpoint_descriptor *
  446. fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
  447. struct usb_endpoint_descriptor *hs)
  448. {
  449. if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
  450. return hs;
  451. return fs;
  452. }
  453. /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
  454. static struct usb_string fsg_strings[] = {
  455. #ifndef FSG_NO_DEVICE_STRINGS
  456. {FSG_STRING_MANUFACTURER, fsg_string_manufacturer},
  457. {FSG_STRING_PRODUCT, fsg_string_product},
  458. {FSG_STRING_SERIAL, fsg_string_serial},
  459. {FSG_STRING_CONFIG, fsg_string_config},
  460. #endif
  461. {FSG_STRING_INTERFACE, fsg_string_interface},
  462. {}
  463. };
  464. static struct usb_gadget_strings fsg_stringtab = {
  465. .language = 0x0409, /* en-us */
  466. .strings = fsg_strings,
  467. };
  468. /*-------------------------------------------------------------------------*/
  469. /*
  470. * If the next two routines are called while the gadget is registered,
  471. * the caller must own fsg->filesem for writing.
  472. */
  473. static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
  474. {
  475. int ro;
  476. /* R/W if we can, R/O if we must */
  477. ro = curlun->initially_ro;
  478. curlun->ro = ro;
  479. curlun->file_length = ums->num_sectors << 9;
  480. curlun->num_sectors = ums->num_sectors;
  481. debug("open backing file: %s\n", filename);
  482. return 0;
  483. }
  484. static void fsg_lun_close(struct fsg_lun *curlun)
  485. {
  486. }
  487. /*-------------------------------------------------------------------------*/
  488. /*
  489. * Sync the file data, don't bother with the metadata.
  490. * This code was copied from fs/buffer.c:sys_fdatasync().
  491. */
  492. static int fsg_lun_fsync_sub(struct fsg_lun *curlun)
  493. {
  494. return 0;
  495. }
  496. static void store_cdrom_address(u8 *dest, int msf, u32 addr)
  497. {
  498. if (msf) {
  499. /* Convert to Minutes-Seconds-Frames */
  500. addr >>= 2; /* Convert to 2048-byte frames */
  501. addr += 2*75; /* Lead-in occupies 2 seconds */
  502. dest[3] = addr % 75; /* Frames */
  503. addr /= 75;
  504. dest[2] = addr % 60; /* Seconds */
  505. addr /= 60;
  506. dest[1] = addr; /* Minutes */
  507. dest[0] = 0; /* Reserved */
  508. } else {
  509. /* Absolute sector */
  510. put_unaligned_be32(addr, dest);
  511. }
  512. }
  513. /*-------------------------------------------------------------------------*/