usb.h 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563
  1. #ifndef __LINUX_USB_H
  2. #define __LINUX_USB_H
  3. #include <linux/mod_devicetable.h>
  4. #include <linux/usb/ch9.h>
  5. #define USB_MAJOR 180
  6. #define USB_DEVICE_MAJOR 189
  7. #ifdef __KERNEL__
  8. #include <linux/errno.h> /* for -ENODEV */
  9. #include <linux/delay.h> /* for mdelay() */
  10. #include <linux/interrupt.h> /* for in_interrupt() */
  11. #include <linux/list.h> /* for struct list_head */
  12. #include <linux/kref.h> /* for struct kref */
  13. #include <linux/device.h> /* for struct device */
  14. #include <linux/fs.h> /* for struct file_operations */
  15. #include <linux/completion.h> /* for struct completion */
  16. #include <linux/sched.h> /* for current && schedule_timeout */
  17. #include <linux/mutex.h> /* for struct mutex */
  18. struct usb_device;
  19. struct usb_driver;
  20. struct wusb_dev;
  21. /*-------------------------------------------------------------------------*/
  22. /*
  23. * Host-side wrappers for standard USB descriptors ... these are parsed
  24. * from the data provided by devices. Parsing turns them from a flat
  25. * sequence of descriptors into a hierarchy:
  26. *
  27. * - devices have one (usually) or more configs;
  28. * - configs have one (often) or more interfaces;
  29. * - interfaces have one (usually) or more settings;
  30. * - each interface setting has zero or (usually) more endpoints.
  31. *
  32. * And there might be other descriptors mixed in with those.
  33. *
  34. * Devices may also have class-specific or vendor-specific descriptors.
  35. */
  36. struct ep_device;
  37. /**
  38. * struct usb_host_endpoint - host-side endpoint descriptor and queue
  39. * @desc: descriptor for this endpoint, wMaxPacketSize in native byteorder
  40. * @urb_list: urbs queued to this endpoint; maintained by usbcore
  41. * @hcpriv: for use by HCD; typically holds hardware dma queue head (QH)
  42. * with one or more transfer descriptors (TDs) per urb
  43. * @ep_dev: ep_device for sysfs info
  44. * @extra: descriptors following this endpoint in the configuration
  45. * @extralen: how many bytes of "extra" are valid
  46. * @enabled: URBs may be submitted to this endpoint
  47. *
  48. * USB requests are always queued to a given endpoint, identified by a
  49. * descriptor within an active interface in a given USB configuration.
  50. */
  51. struct usb_host_endpoint {
  52. struct usb_endpoint_descriptor desc;
  53. struct list_head urb_list;
  54. void *hcpriv;
  55. struct ep_device *ep_dev; /* For sysfs info */
  56. unsigned char *extra; /* Extra descriptors */
  57. int extralen;
  58. int enabled;
  59. };
  60. /* host-side wrapper for one interface setting's parsed descriptors */
  61. struct usb_host_interface {
  62. struct usb_interface_descriptor desc;
  63. /* array of desc.bNumEndpoint endpoints associated with this
  64. * interface setting. these will be in no particular order.
  65. */
  66. struct usb_host_endpoint *endpoint;
  67. char *string; /* iInterface string, if present */
  68. unsigned char *extra; /* Extra descriptors */
  69. int extralen;
  70. };
  71. enum usb_interface_condition {
  72. USB_INTERFACE_UNBOUND = 0,
  73. USB_INTERFACE_BINDING,
  74. USB_INTERFACE_BOUND,
  75. USB_INTERFACE_UNBINDING,
  76. };
  77. /**
  78. * struct usb_interface - what usb device drivers talk to
  79. * @altsetting: array of interface structures, one for each alternate
  80. * setting that may be selected. Each one includes a set of
  81. * endpoint configurations. They will be in no particular order.
  82. * @cur_altsetting: the current altsetting.
  83. * @num_altsetting: number of altsettings defined.
  84. * @intf_assoc: interface association descriptor
  85. * @minor: the minor number assigned to this interface, if this
  86. * interface is bound to a driver that uses the USB major number.
  87. * If this interface does not use the USB major, this field should
  88. * be unused. The driver should set this value in the probe()
  89. * function of the driver, after it has been assigned a minor
  90. * number from the USB core by calling usb_register_dev().
  91. * @condition: binding state of the interface: not bound, binding
  92. * (in probe()), bound to a driver, or unbinding (in disconnect())
  93. * @is_active: flag set when the interface is bound and not suspended.
  94. * @sysfs_files_created: sysfs attributes exist
  95. * @ep_devs_created: endpoint child pseudo-devices exist
  96. * @unregistering: flag set when the interface is being unregistered
  97. * @needs_remote_wakeup: flag set when the driver requires remote-wakeup
  98. * capability during autosuspend.
  99. * @needs_altsetting0: flag set when a set-interface request for altsetting 0
  100. * has been deferred.
  101. * @needs_binding: flag set when the driver should be re-probed or unbound
  102. * following a reset or suspend operation it doesn't support.
  103. * @dev: driver model's view of this device
  104. * @usb_dev: if an interface is bound to the USB major, this will point
  105. * to the sysfs representation for that device.
  106. * @pm_usage_cnt: PM usage counter for this interface; autosuspend is not
  107. * allowed unless the counter is 0.
  108. * @reset_ws: Used for scheduling resets from atomic context.
  109. * @reset_running: set to 1 if the interface is currently running a
  110. * queued reset so that usb_cancel_queued_reset() doesn't try to
  111. * remove from the workqueue when running inside the worker
  112. * thread. See __usb_queue_reset_device().
  113. *
  114. * USB device drivers attach to interfaces on a physical device. Each
  115. * interface encapsulates a single high level function, such as feeding
  116. * an audio stream to a speaker or reporting a change in a volume control.
  117. * Many USB devices only have one interface. The protocol used to talk to
  118. * an interface's endpoints can be defined in a usb "class" specification,
  119. * or by a product's vendor. The (default) control endpoint is part of
  120. * every interface, but is never listed among the interface's descriptors.
  121. *
  122. * The driver that is bound to the interface can use standard driver model
  123. * calls such as dev_get_drvdata() on the dev member of this structure.
  124. *
  125. * Each interface may have alternate settings. The initial configuration
  126. * of a device sets altsetting 0, but the device driver can change
  127. * that setting using usb_set_interface(). Alternate settings are often
  128. * used to control the use of periodic endpoints, such as by having
  129. * different endpoints use different amounts of reserved USB bandwidth.
  130. * All standards-conformant USB devices that use isochronous endpoints
  131. * will use them in non-default settings.
  132. *
  133. * The USB specification says that alternate setting numbers must run from
  134. * 0 to one less than the total number of alternate settings. But some
  135. * devices manage to mess this up, and the structures aren't necessarily
  136. * stored in numerical order anyhow. Use usb_altnum_to_altsetting() to
  137. * look up an alternate setting in the altsetting array based on its number.
  138. */
  139. struct usb_interface {
  140. /* array of alternate settings for this interface,
  141. * stored in no particular order */
  142. struct usb_host_interface *altsetting;
  143. struct usb_host_interface *cur_altsetting; /* the currently
  144. * active alternate setting */
  145. unsigned num_altsetting; /* number of alternate settings */
  146. /* If there is an interface association descriptor then it will list
  147. * the associated interfaces */
  148. struct usb_interface_assoc_descriptor *intf_assoc;
  149. int minor; /* minor number this interface is
  150. * bound to */
  151. enum usb_interface_condition condition; /* state of binding */
  152. unsigned is_active:1; /* the interface is not suspended */
  153. unsigned sysfs_files_created:1; /* the sysfs attributes exist */
  154. unsigned ep_devs_created:1; /* endpoint "devices" exist */
  155. unsigned unregistering:1; /* unregistration is in progress */
  156. unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */
  157. unsigned needs_altsetting0:1; /* switch to altsetting 0 is pending */
  158. unsigned needs_binding:1; /* needs delayed unbind/rebind */
  159. unsigned reset_running:1;
  160. struct device dev; /* interface specific device info */
  161. struct device *usb_dev;
  162. int pm_usage_cnt; /* usage counter for autosuspend */
  163. struct work_struct reset_ws; /* for resets in atomic context */
  164. };
  165. #define to_usb_interface(d) container_of(d, struct usb_interface, dev)
  166. #define interface_to_usbdev(intf) \
  167. container_of(intf->dev.parent, struct usb_device, dev)
  168. static inline void *usb_get_intfdata(struct usb_interface *intf)
  169. {
  170. return dev_get_drvdata(&intf->dev);
  171. }
  172. static inline void usb_set_intfdata(struct usb_interface *intf, void *data)
  173. {
  174. dev_set_drvdata(&intf->dev, data);
  175. }
  176. struct usb_interface *usb_get_intf(struct usb_interface *intf);
  177. void usb_put_intf(struct usb_interface *intf);
  178. /* this maximum is arbitrary */
  179. #define USB_MAXINTERFACES 32
  180. #define USB_MAXIADS USB_MAXINTERFACES/2
  181. /**
  182. * struct usb_interface_cache - long-term representation of a device interface
  183. * @num_altsetting: number of altsettings defined.
  184. * @ref: reference counter.
  185. * @altsetting: variable-length array of interface structures, one for
  186. * each alternate setting that may be selected. Each one includes a
  187. * set of endpoint configurations. They will be in no particular order.
  188. *
  189. * These structures persist for the lifetime of a usb_device, unlike
  190. * struct usb_interface (which persists only as long as its configuration
  191. * is installed). The altsetting arrays can be accessed through these
  192. * structures at any time, permitting comparison of configurations and
  193. * providing support for the /proc/bus/usb/devices pseudo-file.
  194. */
  195. struct usb_interface_cache {
  196. unsigned num_altsetting; /* number of alternate settings */
  197. struct kref ref; /* reference counter */
  198. /* variable-length array of alternate settings for this interface,
  199. * stored in no particular order */
  200. struct usb_host_interface altsetting[0];
  201. };
  202. #define ref_to_usb_interface_cache(r) \
  203. container_of(r, struct usb_interface_cache, ref)
  204. #define altsetting_to_usb_interface_cache(a) \
  205. container_of(a, struct usb_interface_cache, altsetting[0])
  206. /**
  207. * struct usb_host_config - representation of a device's configuration
  208. * @desc: the device's configuration descriptor.
  209. * @string: pointer to the cached version of the iConfiguration string, if
  210. * present for this configuration.
  211. * @intf_assoc: list of any interface association descriptors in this config
  212. * @interface: array of pointers to usb_interface structures, one for each
  213. * interface in the configuration. The number of interfaces is stored
  214. * in desc.bNumInterfaces. These pointers are valid only while the
  215. * the configuration is active.
  216. * @intf_cache: array of pointers to usb_interface_cache structures, one
  217. * for each interface in the configuration. These structures exist
  218. * for the entire life of the device.
  219. * @extra: pointer to buffer containing all extra descriptors associated
  220. * with this configuration (those preceding the first interface
  221. * descriptor).
  222. * @extralen: length of the extra descriptors buffer.
  223. *
  224. * USB devices may have multiple configurations, but only one can be active
  225. * at any time. Each encapsulates a different operational environment;
  226. * for example, a dual-speed device would have separate configurations for
  227. * full-speed and high-speed operation. The number of configurations
  228. * available is stored in the device descriptor as bNumConfigurations.
  229. *
  230. * A configuration can contain multiple interfaces. Each corresponds to
  231. * a different function of the USB device, and all are available whenever
  232. * the configuration is active. The USB standard says that interfaces
  233. * are supposed to be numbered from 0 to desc.bNumInterfaces-1, but a lot
  234. * of devices get this wrong. In addition, the interface array is not
  235. * guaranteed to be sorted in numerical order. Use usb_ifnum_to_if() to
  236. * look up an interface entry based on its number.
  237. *
  238. * Device drivers should not attempt to activate configurations. The choice
  239. * of which configuration to install is a policy decision based on such
  240. * considerations as available power, functionality provided, and the user's
  241. * desires (expressed through userspace tools). However, drivers can call
  242. * usb_reset_configuration() to reinitialize the current configuration and
  243. * all its interfaces.
  244. */
  245. struct usb_host_config {
  246. struct usb_config_descriptor desc;
  247. char *string; /* iConfiguration string, if present */
  248. /* List of any Interface Association Descriptors in this
  249. * configuration. */
  250. struct usb_interface_assoc_descriptor *intf_assoc[USB_MAXIADS];
  251. /* the interfaces associated with this configuration,
  252. * stored in no particular order */
  253. struct usb_interface *interface[USB_MAXINTERFACES];
  254. /* Interface information available even when this is not the
  255. * active configuration */
  256. struct usb_interface_cache *intf_cache[USB_MAXINTERFACES];
  257. unsigned char *extra; /* Extra descriptors */
  258. int extralen;
  259. };
  260. int __usb_get_extra_descriptor(char *buffer, unsigned size,
  261. unsigned char type, void **ptr);
  262. #define usb_get_extra_descriptor(ifpoint, type, ptr) \
  263. __usb_get_extra_descriptor((ifpoint)->extra, \
  264. (ifpoint)->extralen, \
  265. type, (void **)ptr)
  266. /* ----------------------------------------------------------------------- */
  267. /* USB device number allocation bitmap */
  268. struct usb_devmap {
  269. unsigned long devicemap[128 / (8*sizeof(unsigned long))];
  270. };
  271. /*
  272. * Allocated per bus (tree of devices) we have:
  273. */
  274. struct usb_bus {
  275. struct device *controller; /* host/master side hardware */
  276. int busnum; /* Bus number (in order of reg) */
  277. const char *bus_name; /* stable id (PCI slot_name etc) */
  278. u8 uses_dma; /* Does the host controller use DMA? */
  279. u8 otg_port; /* 0, or number of OTG/HNP port */
  280. unsigned is_b_host:1; /* true during some HNP roleswitches */
  281. unsigned b_hnp_enable:1; /* OTG: did A-Host enable HNP? */
  282. int devnum_next; /* Next open device number in
  283. * round-robin allocation */
  284. struct usb_devmap devmap; /* device address allocation map */
  285. struct usb_device *root_hub; /* Root hub */
  286. struct list_head bus_list; /* list of busses */
  287. int bandwidth_allocated; /* on this bus: how much of the time
  288. * reserved for periodic (intr/iso)
  289. * requests is used, on average?
  290. * Units: microseconds/frame.
  291. * Limits: Full/low speed reserve 90%,
  292. * while high speed reserves 80%.
  293. */
  294. int bandwidth_int_reqs; /* number of Interrupt requests */
  295. int bandwidth_isoc_reqs; /* number of Isoc. requests */
  296. #ifdef CONFIG_USB_DEVICEFS
  297. struct dentry *usbfs_dentry; /* usbfs dentry entry for the bus */
  298. #endif
  299. struct device *dev; /* device for this bus */
  300. #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
  301. struct mon_bus *mon_bus; /* non-null when associated */
  302. int monitored; /* non-zero when monitored */
  303. #endif
  304. };
  305. /* ----------------------------------------------------------------------- */
  306. /* This is arbitrary.
  307. * From USB 2.0 spec Table 11-13, offset 7, a hub can
  308. * have up to 255 ports. The most yet reported is 10.
  309. *
  310. * Current Wireless USB host hardware (Intel i1480 for example) allows
  311. * up to 22 devices to connect. Upcoming hardware might raise that
  312. * limit. Because the arrays need to add a bit for hub status data, we
  313. * do 31, so plus one evens out to four bytes.
  314. */
  315. #define USB_MAXCHILDREN (31)
  316. struct usb_tt;
  317. /**
  318. * struct usb_device - kernel's representation of a USB device
  319. * @devnum: device number; address on a USB bus
  320. * @devpath: device ID string for use in messages (e.g., /port/...)
  321. * @state: device state: configured, not attached, etc.
  322. * @speed: device speed: high/full/low (or error)
  323. * @tt: Transaction Translator info; used with low/full speed dev, highspeed hub
  324. * @ttport: device port on that tt hub
  325. * @toggle: one bit for each endpoint, with ([0] = IN, [1] = OUT) endpoints
  326. * @parent: our hub, unless we're the root
  327. * @bus: bus we're part of
  328. * @ep0: endpoint 0 data (default control pipe)
  329. * @dev: generic device interface
  330. * @descriptor: USB device descriptor
  331. * @config: all of the device's configs
  332. * @actconfig: the active configuration
  333. * @ep_in: array of IN endpoints
  334. * @ep_out: array of OUT endpoints
  335. * @rawdescriptors: raw descriptors for each config
  336. * @bus_mA: Current available from the bus
  337. * @portnum: parent port number (origin 1)
  338. * @level: number of USB hub ancestors
  339. * @can_submit: URBs may be submitted
  340. * @discon_suspended: disconnected while suspended
  341. * @persist_enabled: USB_PERSIST enabled for this device
  342. * @have_langid: whether string_langid is valid
  343. * @authorized: policy has said we can use it;
  344. * (user space) policy determines if we authorize this device to be
  345. * used or not. By default, wired USB devices are authorized.
  346. * WUSB devices are not, until we authorize them from user space.
  347. * FIXME -- complete doc
  348. * @authenticated: Crypto authentication passed
  349. * @wusb: device is Wireless USB
  350. * @string_langid: language ID for strings
  351. * @product: iProduct string, if present (static)
  352. * @manufacturer: iManufacturer string, if present (static)
  353. * @serial: iSerialNumber string, if present (static)
  354. * @filelist: usbfs files that are open to this device
  355. * @usb_classdev: USB class device that was created for usbfs device
  356. * access from userspace
  357. * @usbfs_dentry: usbfs dentry entry for the device
  358. * @maxchild: number of ports if hub
  359. * @children: child devices - USB devices that are attached to this hub
  360. * @pm_usage_cnt: usage counter for autosuspend
  361. * @quirks: quirks of the whole device
  362. * @urbnum: number of URBs submitted for the whole device
  363. * @active_duration: total time device is not suspended
  364. * @autosuspend: for delayed autosuspends
  365. * @autoresume: for autoresumes requested while in_interrupt
  366. * @pm_mutex: protects PM operations
  367. * @last_busy: time of last use
  368. * @autosuspend_delay: in jiffies
  369. * @connect_time: time device was first connected
  370. * @auto_pm: autosuspend/resume in progress
  371. * @do_remote_wakeup: remote wakeup should be enabled
  372. * @reset_resume: needs reset instead of resume
  373. * @autosuspend_disabled: autosuspend disabled by the user
  374. * @autoresume_disabled: autoresume disabled by the user
  375. * @skip_sys_resume: skip the next system resume
  376. * @wusb_dev: if this is a Wireless USB device, link to the WUSB
  377. * specific data for the device.
  378. *
  379. * Notes:
  380. * Usbcore drivers should not set usbdev->state directly. Instead use
  381. * usb_set_device_state().
  382. */
  383. struct usb_device {
  384. int devnum;
  385. char devpath [16];
  386. enum usb_device_state state;
  387. enum usb_device_speed speed;
  388. struct usb_tt *tt;
  389. int ttport;
  390. unsigned int toggle[2];
  391. struct usb_device *parent;
  392. struct usb_bus *bus;
  393. struct usb_host_endpoint ep0;
  394. struct device dev;
  395. struct usb_device_descriptor descriptor;
  396. struct usb_host_config *config;
  397. struct usb_host_config *actconfig;
  398. struct usb_host_endpoint *ep_in[16];
  399. struct usb_host_endpoint *ep_out[16];
  400. char **rawdescriptors;
  401. unsigned short bus_mA;
  402. u8 portnum;
  403. u8 level;
  404. unsigned can_submit:1;
  405. unsigned discon_suspended:1;
  406. unsigned persist_enabled:1;
  407. unsigned have_langid:1;
  408. unsigned authorized:1;
  409. unsigned authenticated:1;
  410. unsigned wusb:1;
  411. int string_langid;
  412. /* static strings from the device */
  413. char *product;
  414. char *manufacturer;
  415. char *serial;
  416. struct list_head filelist;
  417. #ifdef CONFIG_USB_DEVICE_CLASS
  418. struct device *usb_classdev;
  419. #endif
  420. #ifdef CONFIG_USB_DEVICEFS
  421. struct dentry *usbfs_dentry;
  422. #endif
  423. int maxchild;
  424. struct usb_device *children[USB_MAXCHILDREN];
  425. int pm_usage_cnt;
  426. u32 quirks;
  427. atomic_t urbnum;
  428. unsigned long active_duration;
  429. #ifdef CONFIG_PM
  430. struct delayed_work autosuspend;
  431. struct work_struct autoresume;
  432. struct mutex pm_mutex;
  433. unsigned long last_busy;
  434. int autosuspend_delay;
  435. unsigned long connect_time;
  436. unsigned auto_pm:1;
  437. unsigned do_remote_wakeup:1;
  438. unsigned reset_resume:1;
  439. unsigned autosuspend_disabled:1;
  440. unsigned autoresume_disabled:1;
  441. unsigned skip_sys_resume:1;
  442. #endif
  443. struct wusb_dev *wusb_dev;
  444. };
  445. #define to_usb_device(d) container_of(d, struct usb_device, dev)
  446. extern struct usb_device *usb_get_dev(struct usb_device *dev);
  447. extern void usb_put_dev(struct usb_device *dev);
  448. /* USB device locking */
  449. #define usb_lock_device(udev) down(&(udev)->dev.sem)
  450. #define usb_unlock_device(udev) up(&(udev)->dev.sem)
  451. #define usb_trylock_device(udev) down_trylock(&(udev)->dev.sem)
  452. extern int usb_lock_device_for_reset(struct usb_device *udev,
  453. const struct usb_interface *iface);
  454. /* USB port reset for device reinitialization */
  455. extern int usb_reset_device(struct usb_device *dev);
  456. extern void usb_queue_reset_device(struct usb_interface *dev);
  457. extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id);
  458. /* USB autosuspend and autoresume */
  459. #ifdef CONFIG_USB_SUSPEND
  460. extern int usb_autopm_set_interface(struct usb_interface *intf);
  461. extern int usb_autopm_get_interface(struct usb_interface *intf);
  462. extern void usb_autopm_put_interface(struct usb_interface *intf);
  463. extern int usb_autopm_get_interface_async(struct usb_interface *intf);
  464. extern void usb_autopm_put_interface_async(struct usb_interface *intf);
  465. static inline void usb_autopm_enable(struct usb_interface *intf)
  466. {
  467. intf->pm_usage_cnt = 0;
  468. usb_autopm_set_interface(intf);
  469. }
  470. static inline void usb_autopm_disable(struct usb_interface *intf)
  471. {
  472. intf->pm_usage_cnt = 1;
  473. usb_autopm_set_interface(intf);
  474. }
  475. static inline void usb_mark_last_busy(struct usb_device *udev)
  476. {
  477. udev->last_busy = jiffies;
  478. }
  479. #else
  480. static inline int usb_autopm_set_interface(struct usb_interface *intf)
  481. { return 0; }
  482. static inline int usb_autopm_get_interface(struct usb_interface *intf)
  483. { return 0; }
  484. static inline int usb_autopm_get_interface_async(struct usb_interface *intf)
  485. { return 0; }
  486. static inline void usb_autopm_put_interface(struct usb_interface *intf)
  487. { }
  488. static inline void usb_autopm_put_interface_async(struct usb_interface *intf)
  489. { }
  490. static inline void usb_autopm_enable(struct usb_interface *intf)
  491. { }
  492. static inline void usb_autopm_disable(struct usb_interface *intf)
  493. { }
  494. static inline void usb_mark_last_busy(struct usb_device *udev)
  495. { }
  496. #endif
  497. /*-------------------------------------------------------------------------*/
  498. /* for drivers using iso endpoints */
  499. extern int usb_get_current_frame_number(struct usb_device *usb_dev);
  500. /* used these for multi-interface device registration */
  501. extern int usb_driver_claim_interface(struct usb_driver *driver,
  502. struct usb_interface *iface, void *priv);
  503. /**
  504. * usb_interface_claimed - returns true iff an interface is claimed
  505. * @iface: the interface being checked
  506. *
  507. * Returns true (nonzero) iff the interface is claimed, else false (zero).
  508. * Callers must own the driver model's usb bus readlock. So driver
  509. * probe() entries don't need extra locking, but other call contexts
  510. * may need to explicitly claim that lock.
  511. *
  512. */
  513. static inline int usb_interface_claimed(struct usb_interface *iface)
  514. {
  515. return (iface->dev.driver != NULL);
  516. }
  517. extern void usb_driver_release_interface(struct usb_driver *driver,
  518. struct usb_interface *iface);
  519. const struct usb_device_id *usb_match_id(struct usb_interface *interface,
  520. const struct usb_device_id *id);
  521. extern int usb_match_one_id(struct usb_interface *interface,
  522. const struct usb_device_id *id);
  523. extern struct usb_interface *usb_find_interface(struct usb_driver *drv,
  524. int minor);
  525. extern struct usb_interface *usb_ifnum_to_if(const struct usb_device *dev,
  526. unsigned ifnum);
  527. extern struct usb_host_interface *usb_altnum_to_altsetting(
  528. const struct usb_interface *intf, unsigned int altnum);
  529. /**
  530. * usb_make_path - returns stable device path in the usb tree
  531. * @dev: the device whose path is being constructed
  532. * @buf: where to put the string
  533. * @size: how big is "buf"?
  534. *
  535. * Returns length of the string (> 0) or negative if size was too small.
  536. *
  537. * This identifier is intended to be "stable", reflecting physical paths in
  538. * hardware such as physical bus addresses for host controllers or ports on
  539. * USB hubs. That makes it stay the same until systems are physically
  540. * reconfigured, by re-cabling a tree of USB devices or by moving USB host
  541. * controllers. Adding and removing devices, including virtual root hubs
  542. * in host controller driver modules, does not change these path identifers;
  543. * neither does rebooting or re-enumerating. These are more useful identifiers
  544. * than changeable ("unstable") ones like bus numbers or device addresses.
  545. *
  546. * With a partial exception for devices connected to USB 2.0 root hubs, these
  547. * identifiers are also predictable. So long as the device tree isn't changed,
  548. * plugging any USB device into a given hub port always gives it the same path.
  549. * Because of the use of "companion" controllers, devices connected to ports on
  550. * USB 2.0 root hubs (EHCI host controllers) will get one path ID if they are
  551. * high speed, and a different one if they are full or low speed.
  552. */
  553. static inline int usb_make_path(struct usb_device *dev, char *buf, size_t size)
  554. {
  555. int actual;
  556. actual = snprintf(buf, size, "usb-%s-%s", dev->bus->bus_name,
  557. dev->devpath);
  558. return (actual >= (int)size) ? -1 : actual;
  559. }
  560. /*-------------------------------------------------------------------------*/
  561. #define USB_DEVICE_ID_MATCH_DEVICE \
  562. (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
  563. #define USB_DEVICE_ID_MATCH_DEV_RANGE \
  564. (USB_DEVICE_ID_MATCH_DEV_LO | USB_DEVICE_ID_MATCH_DEV_HI)
  565. #define USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION \
  566. (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_RANGE)
  567. #define USB_DEVICE_ID_MATCH_DEV_INFO \
  568. (USB_DEVICE_ID_MATCH_DEV_CLASS | \
  569. USB_DEVICE_ID_MATCH_DEV_SUBCLASS | \
  570. USB_DEVICE_ID_MATCH_DEV_PROTOCOL)
  571. #define USB_DEVICE_ID_MATCH_INT_INFO \
  572. (USB_DEVICE_ID_MATCH_INT_CLASS | \
  573. USB_DEVICE_ID_MATCH_INT_SUBCLASS | \
  574. USB_DEVICE_ID_MATCH_INT_PROTOCOL)
  575. /**
  576. * USB_DEVICE - macro used to describe a specific usb device
  577. * @vend: the 16 bit USB Vendor ID
  578. * @prod: the 16 bit USB Product ID
  579. *
  580. * This macro is used to create a struct usb_device_id that matches a
  581. * specific device.
  582. */
  583. #define USB_DEVICE(vend,prod) \
  584. .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
  585. .idVendor = (vend), \
  586. .idProduct = (prod)
  587. /**
  588. * USB_DEVICE_VER - describe a specific usb device with a version range
  589. * @vend: the 16 bit USB Vendor ID
  590. * @prod: the 16 bit USB Product ID
  591. * @lo: the bcdDevice_lo value
  592. * @hi: the bcdDevice_hi value
  593. *
  594. * This macro is used to create a struct usb_device_id that matches a
  595. * specific device, with a version range.
  596. */
  597. #define USB_DEVICE_VER(vend, prod, lo, hi) \
  598. .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, \
  599. .idVendor = (vend), \
  600. .idProduct = (prod), \
  601. .bcdDevice_lo = (lo), \
  602. .bcdDevice_hi = (hi)
  603. /**
  604. * USB_DEVICE_INTERFACE_PROTOCOL - describe a usb device with a specific interface protocol
  605. * @vend: the 16 bit USB Vendor ID
  606. * @prod: the 16 bit USB Product ID
  607. * @pr: bInterfaceProtocol value
  608. *
  609. * This macro is used to create a struct usb_device_id that matches a
  610. * specific interface protocol of devices.
  611. */
  612. #define USB_DEVICE_INTERFACE_PROTOCOL(vend, prod, pr) \
  613. .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
  614. USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
  615. .idVendor = (vend), \
  616. .idProduct = (prod), \
  617. .bInterfaceProtocol = (pr)
  618. /**
  619. * USB_DEVICE_INFO - macro used to describe a class of usb devices
  620. * @cl: bDeviceClass value
  621. * @sc: bDeviceSubClass value
  622. * @pr: bDeviceProtocol value
  623. *
  624. * This macro is used to create a struct usb_device_id that matches a
  625. * specific class of devices.
  626. */
  627. #define USB_DEVICE_INFO(cl, sc, pr) \
  628. .match_flags = USB_DEVICE_ID_MATCH_DEV_INFO, \
  629. .bDeviceClass = (cl), \
  630. .bDeviceSubClass = (sc), \
  631. .bDeviceProtocol = (pr)
  632. /**
  633. * USB_INTERFACE_INFO - macro used to describe a class of usb interfaces
  634. * @cl: bInterfaceClass value
  635. * @sc: bInterfaceSubClass value
  636. * @pr: bInterfaceProtocol value
  637. *
  638. * This macro is used to create a struct usb_device_id that matches a
  639. * specific class of interfaces.
  640. */
  641. #define USB_INTERFACE_INFO(cl, sc, pr) \
  642. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO, \
  643. .bInterfaceClass = (cl), \
  644. .bInterfaceSubClass = (sc), \
  645. .bInterfaceProtocol = (pr)
  646. /**
  647. * USB_DEVICE_AND_INTERFACE_INFO - describe a specific usb device with a class of usb interfaces
  648. * @vend: the 16 bit USB Vendor ID
  649. * @prod: the 16 bit USB Product ID
  650. * @cl: bInterfaceClass value
  651. * @sc: bInterfaceSubClass value
  652. * @pr: bInterfaceProtocol value
  653. *
  654. * This macro is used to create a struct usb_device_id that matches a
  655. * specific device with a specific class of interfaces.
  656. *
  657. * This is especially useful when explicitly matching devices that have
  658. * vendor specific bDeviceClass values, but standards-compliant interfaces.
  659. */
  660. #define USB_DEVICE_AND_INTERFACE_INFO(vend, prod, cl, sc, pr) \
  661. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
  662. | USB_DEVICE_ID_MATCH_DEVICE, \
  663. .idVendor = (vend), \
  664. .idProduct = (prod), \
  665. .bInterfaceClass = (cl), \
  666. .bInterfaceSubClass = (sc), \
  667. .bInterfaceProtocol = (pr)
  668. /* ----------------------------------------------------------------------- */
  669. /* Stuff for dynamic usb ids */
  670. struct usb_dynids {
  671. spinlock_t lock;
  672. struct list_head list;
  673. };
  674. struct usb_dynid {
  675. struct list_head node;
  676. struct usb_device_id id;
  677. };
  678. extern ssize_t usb_store_new_id(struct usb_dynids *dynids,
  679. struct device_driver *driver,
  680. const char *buf, size_t count);
  681. /**
  682. * struct usbdrv_wrap - wrapper for driver-model structure
  683. * @driver: The driver-model core driver structure.
  684. * @for_devices: Non-zero for device drivers, 0 for interface drivers.
  685. */
  686. struct usbdrv_wrap {
  687. struct device_driver driver;
  688. int for_devices;
  689. };
  690. /**
  691. * struct usb_driver - identifies USB interface driver to usbcore
  692. * @name: The driver name should be unique among USB drivers,
  693. * and should normally be the same as the module name.
  694. * @probe: Called to see if the driver is willing to manage a particular
  695. * interface on a device. If it is, probe returns zero and uses
  696. * usb_set_intfdata() to associate driver-specific data with the
  697. * interface. It may also use usb_set_interface() to specify the
  698. * appropriate altsetting. If unwilling to manage the interface,
  699. * return -ENODEV, if genuine IO errors occured, an appropriate
  700. * negative errno value.
  701. * @disconnect: Called when the interface is no longer accessible, usually
  702. * because its device has been (or is being) disconnected or the
  703. * driver module is being unloaded.
  704. * @ioctl: Used for drivers that want to talk to userspace through
  705. * the "usbfs" filesystem. This lets devices provide ways to
  706. * expose information to user space regardless of where they
  707. * do (or don't) show up otherwise in the filesystem.
  708. * @suspend: Called when the device is going to be suspended by the system.
  709. * @resume: Called when the device is being resumed by the system.
  710. * @reset_resume: Called when the suspended device has been reset instead
  711. * of being resumed.
  712. * @pre_reset: Called by usb_reset_device() when the device
  713. * is about to be reset.
  714. * @post_reset: Called by usb_reset_device() after the device
  715. * has been reset
  716. * @id_table: USB drivers use ID table to support hotplugging.
  717. * Export this with MODULE_DEVICE_TABLE(usb,...). This must be set
  718. * or your driver's probe function will never get called.
  719. * @dynids: used internally to hold the list of dynamically added device
  720. * ids for this driver.
  721. * @drvwrap: Driver-model core structure wrapper.
  722. * @no_dynamic_id: if set to 1, the USB core will not allow dynamic ids to be
  723. * added to this driver by preventing the sysfs file from being created.
  724. * @supports_autosuspend: if set to 0, the USB core will not allow autosuspend
  725. * for interfaces bound to this driver.
  726. * @soft_unbind: if set to 1, the USB core will not kill URBs and disable
  727. * endpoints before calling the driver's disconnect method.
  728. *
  729. * USB interface drivers must provide a name, probe() and disconnect()
  730. * methods, and an id_table. Other driver fields are optional.
  731. *
  732. * The id_table is used in hotplugging. It holds a set of descriptors,
  733. * and specialized data may be associated with each entry. That table
  734. * is used by both user and kernel mode hotplugging support.
  735. *
  736. * The probe() and disconnect() methods are called in a context where
  737. * they can sleep, but they should avoid abusing the privilege. Most
  738. * work to connect to a device should be done when the device is opened,
  739. * and undone at the last close. The disconnect code needs to address
  740. * concurrency issues with respect to open() and close() methods, as
  741. * well as forcing all pending I/O requests to complete (by unlinking
  742. * them as necessary, and blocking until the unlinks complete).
  743. */
  744. struct usb_driver {
  745. const char *name;
  746. int (*probe) (struct usb_interface *intf,
  747. const struct usb_device_id *id);
  748. void (*disconnect) (struct usb_interface *intf);
  749. int (*ioctl) (struct usb_interface *intf, unsigned int code,
  750. void *buf);
  751. int (*suspend) (struct usb_interface *intf, pm_message_t message);
  752. int (*resume) (struct usb_interface *intf);
  753. int (*reset_resume)(struct usb_interface *intf);
  754. int (*pre_reset)(struct usb_interface *intf);
  755. int (*post_reset)(struct usb_interface *intf);
  756. const struct usb_device_id *id_table;
  757. struct usb_dynids dynids;
  758. struct usbdrv_wrap drvwrap;
  759. unsigned int no_dynamic_id:1;
  760. unsigned int supports_autosuspend:1;
  761. unsigned int soft_unbind:1;
  762. };
  763. #define to_usb_driver(d) container_of(d, struct usb_driver, drvwrap.driver)
  764. /**
  765. * struct usb_device_driver - identifies USB device driver to usbcore
  766. * @name: The driver name should be unique among USB drivers,
  767. * and should normally be the same as the module name.
  768. * @probe: Called to see if the driver is willing to manage a particular
  769. * device. If it is, probe returns zero and uses dev_set_drvdata()
  770. * to associate driver-specific data with the device. If unwilling
  771. * to manage the device, return a negative errno value.
  772. * @disconnect: Called when the device is no longer accessible, usually
  773. * because it has been (or is being) disconnected or the driver's
  774. * module is being unloaded.
  775. * @suspend: Called when the device is going to be suspended by the system.
  776. * @resume: Called when the device is being resumed by the system.
  777. * @drvwrap: Driver-model core structure wrapper.
  778. * @supports_autosuspend: if set to 0, the USB core will not allow autosuspend
  779. * for devices bound to this driver.
  780. *
  781. * USB drivers must provide all the fields listed above except drvwrap.
  782. */
  783. struct usb_device_driver {
  784. const char *name;
  785. int (*probe) (struct usb_device *udev);
  786. void (*disconnect) (struct usb_device *udev);
  787. int (*suspend) (struct usb_device *udev, pm_message_t message);
  788. int (*resume) (struct usb_device *udev, pm_message_t message);
  789. struct usbdrv_wrap drvwrap;
  790. unsigned int supports_autosuspend:1;
  791. };
  792. #define to_usb_device_driver(d) container_of(d, struct usb_device_driver, \
  793. drvwrap.driver)
  794. extern struct bus_type usb_bus_type;
  795. /**
  796. * struct usb_class_driver - identifies a USB driver that wants to use the USB major number
  797. * @name: the usb class device name for this driver. Will show up in sysfs.
  798. * @fops: pointer to the struct file_operations of this driver.
  799. * @minor_base: the start of the minor range for this driver.
  800. *
  801. * This structure is used for the usb_register_dev() and
  802. * usb_unregister_dev() functions, to consolidate a number of the
  803. * parameters used for them.
  804. */
  805. struct usb_class_driver {
  806. char *name;
  807. const struct file_operations *fops;
  808. int minor_base;
  809. };
  810. /*
  811. * use these in module_init()/module_exit()
  812. * and don't forget MODULE_DEVICE_TABLE(usb, ...)
  813. */
  814. extern int usb_register_driver(struct usb_driver *, struct module *,
  815. const char *);
  816. static inline int usb_register(struct usb_driver *driver)
  817. {
  818. return usb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME);
  819. }
  820. extern void usb_deregister(struct usb_driver *);
  821. extern int usb_register_device_driver(struct usb_device_driver *,
  822. struct module *);
  823. extern void usb_deregister_device_driver(struct usb_device_driver *);
  824. extern int usb_register_dev(struct usb_interface *intf,
  825. struct usb_class_driver *class_driver);
  826. extern void usb_deregister_dev(struct usb_interface *intf,
  827. struct usb_class_driver *class_driver);
  828. extern int usb_disabled(void);
  829. /* ----------------------------------------------------------------------- */
  830. /*
  831. * URB support, for asynchronous request completions
  832. */
  833. /*
  834. * urb->transfer_flags:
  835. *
  836. * Note: URB_DIR_IN/OUT is automatically set in usb_submit_urb().
  837. */
  838. #define URB_SHORT_NOT_OK 0x0001 /* report short reads as errors */
  839. #define URB_ISO_ASAP 0x0002 /* iso-only, urb->start_frame
  840. * ignored */
  841. #define URB_NO_TRANSFER_DMA_MAP 0x0004 /* urb->transfer_dma valid on submit */
  842. #define URB_NO_SETUP_DMA_MAP 0x0008 /* urb->setup_dma valid on submit */
  843. #define URB_NO_FSBR 0x0020 /* UHCI-specific */
  844. #define URB_ZERO_PACKET 0x0040 /* Finish bulk OUT with short packet */
  845. #define URB_NO_INTERRUPT 0x0080 /* HINT: no non-error interrupt
  846. * needed */
  847. #define URB_FREE_BUFFER 0x0100 /* Free transfer buffer with the URB */
  848. #define URB_DIR_IN 0x0200 /* Transfer from device to host */
  849. #define URB_DIR_OUT 0
  850. #define URB_DIR_MASK URB_DIR_IN
  851. struct usb_iso_packet_descriptor {
  852. unsigned int offset;
  853. unsigned int length; /* expected length */
  854. unsigned int actual_length;
  855. int status;
  856. };
  857. struct urb;
  858. struct usb_anchor {
  859. struct list_head urb_list;
  860. wait_queue_head_t wait;
  861. spinlock_t lock;
  862. unsigned int poisoned:1;
  863. };
  864. static inline void init_usb_anchor(struct usb_anchor *anchor)
  865. {
  866. INIT_LIST_HEAD(&anchor->urb_list);
  867. init_waitqueue_head(&anchor->wait);
  868. spin_lock_init(&anchor->lock);
  869. }
  870. typedef void (*usb_complete_t)(struct urb *);
  871. /**
  872. * struct urb - USB Request Block
  873. * @urb_list: For use by current owner of the URB.
  874. * @anchor_list: membership in the list of an anchor
  875. * @anchor: to anchor URBs to a common mooring
  876. * @ep: Points to the endpoint's data structure. Will eventually
  877. * replace @pipe.
  878. * @pipe: Holds endpoint number, direction, type, and more.
  879. * Create these values with the eight macros available;
  880. * usb_{snd,rcv}TYPEpipe(dev,endpoint), where the TYPE is "ctrl"
  881. * (control), "bulk", "int" (interrupt), or "iso" (isochronous).
  882. * For example usb_sndbulkpipe() or usb_rcvintpipe(). Endpoint
  883. * numbers range from zero to fifteen. Note that "in" endpoint two
  884. * is a different endpoint (and pipe) from "out" endpoint two.
  885. * The current configuration controls the existence, type, and
  886. * maximum packet size of any given endpoint.
  887. * @dev: Identifies the USB device to perform the request.
  888. * @status: This is read in non-iso completion functions to get the
  889. * status of the particular request. ISO requests only use it
  890. * to tell whether the URB was unlinked; detailed status for
  891. * each frame is in the fields of the iso_frame-desc.
  892. * @transfer_flags: A variety of flags may be used to affect how URB
  893. * submission, unlinking, or operation are handled. Different
  894. * kinds of URB can use different flags.
  895. * @transfer_buffer: This identifies the buffer to (or from) which
  896. * the I/O request will be performed (unless URB_NO_TRANSFER_DMA_MAP
  897. * is set). This buffer must be suitable for DMA; allocate it with
  898. * kmalloc() or equivalent. For transfers to "in" endpoints, contents
  899. * of this buffer will be modified. This buffer is used for the data
  900. * stage of control transfers.
  901. * @transfer_dma: When transfer_flags includes URB_NO_TRANSFER_DMA_MAP,
  902. * the device driver is saying that it provided this DMA address,
  903. * which the host controller driver should use in preference to the
  904. * transfer_buffer.
  905. * @transfer_buffer_length: How big is transfer_buffer. The transfer may
  906. * be broken up into chunks according to the current maximum packet
  907. * size for the endpoint, which is a function of the configuration
  908. * and is encoded in the pipe. When the length is zero, neither
  909. * transfer_buffer nor transfer_dma is used.
  910. * @actual_length: This is read in non-iso completion functions, and
  911. * it tells how many bytes (out of transfer_buffer_length) were
  912. * transferred. It will normally be the same as requested, unless
  913. * either an error was reported or a short read was performed.
  914. * The URB_SHORT_NOT_OK transfer flag may be used to make such
  915. * short reads be reported as errors.
  916. * @setup_packet: Only used for control transfers, this points to eight bytes
  917. * of setup data. Control transfers always start by sending this data
  918. * to the device. Then transfer_buffer is read or written, if needed.
  919. * @setup_dma: For control transfers with URB_NO_SETUP_DMA_MAP set, the
  920. * device driver has provided this DMA address for the setup packet.
  921. * The host controller driver should use this in preference to
  922. * setup_packet.
  923. * @start_frame: Returns the initial frame for isochronous transfers.
  924. * @number_of_packets: Lists the number of ISO transfer buffers.
  925. * @interval: Specifies the polling interval for interrupt or isochronous
  926. * transfers. The units are frames (milliseconds) for for full and low
  927. * speed devices, and microframes (1/8 millisecond) for highspeed ones.
  928. * @error_count: Returns the number of ISO transfers that reported errors.
  929. * @context: For use in completion functions. This normally points to
  930. * request-specific driver context.
  931. * @complete: Completion handler. This URB is passed as the parameter to the
  932. * completion function. The completion function may then do what
  933. * it likes with the URB, including resubmitting or freeing it.
  934. * @iso_frame_desc: Used to provide arrays of ISO transfer buffers and to
  935. * collect the transfer status for each buffer.
  936. *
  937. * This structure identifies USB transfer requests. URBs must be allocated by
  938. * calling usb_alloc_urb() and freed with a call to usb_free_urb().
  939. * Initialization may be done using various usb_fill_*_urb() functions. URBs
  940. * are submitted using usb_submit_urb(), and pending requests may be canceled
  941. * using usb_unlink_urb() or usb_kill_urb().
  942. *
  943. * Data Transfer Buffers:
  944. *
  945. * Normally drivers provide I/O buffers allocated with kmalloc() or otherwise
  946. * taken from the general page pool. That is provided by transfer_buffer
  947. * (control requests also use setup_packet), and host controller drivers
  948. * perform a dma mapping (and unmapping) for each buffer transferred. Those
  949. * mapping operations can be expensive on some platforms (perhaps using a dma
  950. * bounce buffer or talking to an IOMMU),
  951. * although they're cheap on commodity x86 and ppc hardware.
  952. *
  953. * Alternatively, drivers may pass the URB_NO_xxx_DMA_MAP transfer flags,
  954. * which tell the host controller driver that no such mapping is needed since
  955. * the device driver is DMA-aware. For example, a device driver might
  956. * allocate a DMA buffer with usb_buffer_alloc() or call usb_buffer_map().
  957. * When these transfer flags are provided, host controller drivers will
  958. * attempt to use the dma addresses found in the transfer_dma and/or
  959. * setup_dma fields rather than determining a dma address themselves. (Note
  960. * that transfer_buffer and setup_packet must still be set because not all
  961. * host controllers use DMA, nor do virtual root hubs).
  962. *
  963. * Initialization:
  964. *
  965. * All URBs submitted must initialize the dev, pipe, transfer_flags (may be
  966. * zero), and complete fields. All URBs must also initialize
  967. * transfer_buffer and transfer_buffer_length. They may provide the
  968. * URB_SHORT_NOT_OK transfer flag, indicating that short reads are
  969. * to be treated as errors; that flag is invalid for write requests.
  970. *
  971. * Bulk URBs may
  972. * use the URB_ZERO_PACKET transfer flag, indicating that bulk OUT transfers
  973. * should always terminate with a short packet, even if it means adding an
  974. * extra zero length packet.
  975. *
  976. * Control URBs must provide a setup_packet. The setup_packet and
  977. * transfer_buffer may each be mapped for DMA or not, independently of
  978. * the other. The transfer_flags bits URB_NO_TRANSFER_DMA_MAP and
  979. * URB_NO_SETUP_DMA_MAP indicate which buffers have already been mapped.
  980. * URB_NO_SETUP_DMA_MAP is ignored for non-control URBs.
  981. *
  982. * Interrupt URBs must provide an interval, saying how often (in milliseconds
  983. * or, for highspeed devices, 125 microsecond units)
  984. * to poll for transfers. After the URB has been submitted, the interval
  985. * field reflects how the transfer was actually scheduled.
  986. * The polling interval may be more frequent than requested.
  987. * For example, some controllers have a maximum interval of 32 milliseconds,
  988. * while others support intervals of up to 1024 milliseconds.
  989. * Isochronous URBs also have transfer intervals. (Note that for isochronous
  990. * endpoints, as well as high speed interrupt endpoints, the encoding of
  991. * the transfer interval in the endpoint descriptor is logarithmic.
  992. * Device drivers must convert that value to linear units themselves.)
  993. *
  994. * Isochronous URBs normally use the URB_ISO_ASAP transfer flag, telling
  995. * the host controller to schedule the transfer as soon as bandwidth
  996. * utilization allows, and then set start_frame to reflect the actual frame
  997. * selected during submission. Otherwise drivers must specify the start_frame
  998. * and handle the case where the transfer can't begin then. However, drivers
  999. * won't know how bandwidth is currently allocated, and while they can
  1000. * find the current frame using usb_get_current_frame_number () they can't
  1001. * know the range for that frame number. (Ranges for frame counter values
  1002. * are HC-specific, and can go from 256 to 65536 frames from "now".)
  1003. *
  1004. * Isochronous URBs have a different data transfer model, in part because
  1005. * the quality of service is only "best effort". Callers provide specially
  1006. * allocated URBs, with number_of_packets worth of iso_frame_desc structures
  1007. * at the end. Each such packet is an individual ISO transfer. Isochronous
  1008. * URBs are normally queued, submitted by drivers to arrange that
  1009. * transfers are at least double buffered, and then explicitly resubmitted
  1010. * in completion handlers, so
  1011. * that data (such as audio or video) streams at as constant a rate as the
  1012. * host controller scheduler can support.
  1013. *
  1014. * Completion Callbacks:
  1015. *
  1016. * The completion callback is made in_interrupt(), and one of the first
  1017. * things that a completion handler should do is check the status field.
  1018. * The status field is provided for all URBs. It is used to report
  1019. * unlinked URBs, and status for all non-ISO transfers. It should not
  1020. * be examined before the URB is returned to the completion handler.
  1021. *
  1022. * The context field is normally used to link URBs back to the relevant
  1023. * driver or request state.
  1024. *
  1025. * When the completion callback is invoked for non-isochronous URBs, the
  1026. * actual_length field tells how many bytes were transferred. This field
  1027. * is updated even when the URB terminated with an error or was unlinked.
  1028. *
  1029. * ISO transfer status is reported in the status and actual_length fields
  1030. * of the iso_frame_desc array, and the number of errors is reported in
  1031. * error_count. Completion callbacks for ISO transfers will normally
  1032. * (re)submit URBs to ensure a constant transfer rate.
  1033. *
  1034. * Note that even fields marked "public" should not be touched by the driver
  1035. * when the urb is owned by the hcd, that is, since the call to
  1036. * usb_submit_urb() till the entry into the completion routine.
  1037. */
  1038. struct urb {
  1039. /* private: usb core and host controller only fields in the urb */
  1040. struct kref kref; /* reference count of the URB */
  1041. void *hcpriv; /* private data for host controller */
  1042. atomic_t use_count; /* concurrent submissions counter */
  1043. atomic_t reject; /* submissions will fail */
  1044. int unlinked; /* unlink error code */
  1045. /* public: documented fields in the urb that can be used by drivers */
  1046. struct list_head urb_list; /* list head for use by the urb's
  1047. * current owner */
  1048. struct list_head anchor_list; /* the URB may be anchored */
  1049. struct usb_anchor *anchor;
  1050. struct usb_device *dev; /* (in) pointer to associated device */
  1051. struct usb_host_endpoint *ep; /* (internal) pointer to endpoint */
  1052. unsigned int pipe; /* (in) pipe information */
  1053. int status; /* (return) non-ISO status */
  1054. unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/
  1055. void *transfer_buffer; /* (in) associated data buffer */
  1056. dma_addr_t transfer_dma; /* (in) dma addr for transfer_buffer */
  1057. u32 transfer_buffer_length; /* (in) data buffer length */
  1058. u32 actual_length; /* (return) actual transfer length */
  1059. unsigned char *setup_packet; /* (in) setup packet (control only) */
  1060. dma_addr_t setup_dma; /* (in) dma addr for setup_packet */
  1061. int start_frame; /* (modify) start frame (ISO) */
  1062. int number_of_packets; /* (in) number of ISO packets */
  1063. int interval; /* (modify) transfer interval
  1064. * (INT/ISO) */
  1065. int error_count; /* (return) number of ISO errors */
  1066. void *context; /* (in) context for completion */
  1067. usb_complete_t complete; /* (in) completion routine */
  1068. struct usb_iso_packet_descriptor iso_frame_desc[0];
  1069. /* (in) ISO ONLY */
  1070. };
  1071. /* ----------------------------------------------------------------------- */
  1072. /**
  1073. * usb_fill_control_urb - initializes a control urb
  1074. * @urb: pointer to the urb to initialize.
  1075. * @dev: pointer to the struct usb_device for this urb.
  1076. * @pipe: the endpoint pipe
  1077. * @setup_packet: pointer to the setup_packet buffer
  1078. * @transfer_buffer: pointer to the transfer buffer
  1079. * @buffer_length: length of the transfer buffer
  1080. * @complete_fn: pointer to the usb_complete_t function
  1081. * @context: what to set the urb context to.
  1082. *
  1083. * Initializes a control urb with the proper information needed to submit
  1084. * it to a device.
  1085. */
  1086. static inline void usb_fill_control_urb(struct urb *urb,
  1087. struct usb_device *dev,
  1088. unsigned int pipe,
  1089. unsigned char *setup_packet,
  1090. void *transfer_buffer,
  1091. int buffer_length,
  1092. usb_complete_t complete_fn,
  1093. void *context)
  1094. {
  1095. urb->dev = dev;
  1096. urb->pipe = pipe;
  1097. urb->setup_packet = setup_packet;
  1098. urb->transfer_buffer = transfer_buffer;
  1099. urb->transfer_buffer_length = buffer_length;
  1100. urb->complete = complete_fn;
  1101. urb->context = context;
  1102. }
  1103. /**
  1104. * usb_fill_bulk_urb - macro to help initialize a bulk urb
  1105. * @urb: pointer to the urb to initialize.
  1106. * @dev: pointer to the struct usb_device for this urb.
  1107. * @pipe: the endpoint pipe
  1108. * @transfer_buffer: pointer to the transfer buffer
  1109. * @buffer_length: length of the transfer buffer
  1110. * @complete_fn: pointer to the usb_complete_t function
  1111. * @context: what to set the urb context to.
  1112. *
  1113. * Initializes a bulk urb with the proper information needed to submit it
  1114. * to a device.
  1115. */
  1116. static inline void usb_fill_bulk_urb(struct urb *urb,
  1117. struct usb_device *dev,
  1118. unsigned int pipe,
  1119. void *transfer_buffer,
  1120. int buffer_length,
  1121. usb_complete_t complete_fn,
  1122. void *context)
  1123. {
  1124. urb->dev = dev;
  1125. urb->pipe = pipe;
  1126. urb->transfer_buffer = transfer_buffer;
  1127. urb->transfer_buffer_length = buffer_length;
  1128. urb->complete = complete_fn;
  1129. urb->context = context;
  1130. }
  1131. /**
  1132. * usb_fill_int_urb - macro to help initialize a interrupt urb
  1133. * @urb: pointer to the urb to initialize.
  1134. * @dev: pointer to the struct usb_device for this urb.
  1135. * @pipe: the endpoint pipe
  1136. * @transfer_buffer: pointer to the transfer buffer
  1137. * @buffer_length: length of the transfer buffer
  1138. * @complete_fn: pointer to the usb_complete_t function
  1139. * @context: what to set the urb context to.
  1140. * @interval: what to set the urb interval to, encoded like
  1141. * the endpoint descriptor's bInterval value.
  1142. *
  1143. * Initializes a interrupt urb with the proper information needed to submit
  1144. * it to a device.
  1145. * Note that high speed interrupt endpoints use a logarithmic encoding of
  1146. * the endpoint interval, and express polling intervals in microframes
  1147. * (eight per millisecond) rather than in frames (one per millisecond).
  1148. */
  1149. static inline void usb_fill_int_urb(struct urb *urb,
  1150. struct usb_device *dev,
  1151. unsigned int pipe,
  1152. void *transfer_buffer,
  1153. int buffer_length,
  1154. usb_complete_t complete_fn,
  1155. void *context,
  1156. int interval)
  1157. {
  1158. urb->dev = dev;
  1159. urb->pipe = pipe;
  1160. urb->transfer_buffer = transfer_buffer;
  1161. urb->transfer_buffer_length = buffer_length;
  1162. urb->complete = complete_fn;
  1163. urb->context = context;
  1164. if (dev->speed == USB_SPEED_HIGH)
  1165. urb->interval = 1 << (interval - 1);
  1166. else
  1167. urb->interval = interval;
  1168. urb->start_frame = -1;
  1169. }
  1170. extern void usb_init_urb(struct urb *urb);
  1171. extern struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags);
  1172. extern void usb_free_urb(struct urb *urb);
  1173. #define usb_put_urb usb_free_urb
  1174. extern struct urb *usb_get_urb(struct urb *urb);
  1175. extern int usb_submit_urb(struct urb *urb, gfp_t mem_flags);
  1176. extern int usb_unlink_urb(struct urb *urb);
  1177. extern void usb_kill_urb(struct urb *urb);
  1178. extern void usb_poison_urb(struct urb *urb);
  1179. extern void usb_unpoison_urb(struct urb *urb);
  1180. extern void usb_kill_anchored_urbs(struct usb_anchor *anchor);
  1181. extern void usb_poison_anchored_urbs(struct usb_anchor *anchor);
  1182. extern void usb_unpoison_anchored_urbs(struct usb_anchor *anchor);
  1183. extern void usb_unlink_anchored_urbs(struct usb_anchor *anchor);
  1184. extern void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor);
  1185. extern void usb_unanchor_urb(struct urb *urb);
  1186. extern int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor,
  1187. unsigned int timeout);
  1188. extern struct urb *usb_get_from_anchor(struct usb_anchor *anchor);
  1189. extern void usb_scuttle_anchored_urbs(struct usb_anchor *anchor);
  1190. extern int usb_anchor_empty(struct usb_anchor *anchor);
  1191. /**
  1192. * usb_urb_dir_in - check if an URB describes an IN transfer
  1193. * @urb: URB to be checked
  1194. *
  1195. * Returns 1 if @urb describes an IN transfer (device-to-host),
  1196. * otherwise 0.
  1197. */
  1198. static inline int usb_urb_dir_in(struct urb *urb)
  1199. {
  1200. return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_IN;
  1201. }
  1202. /**
  1203. * usb_urb_dir_out - check if an URB describes an OUT transfer
  1204. * @urb: URB to be checked
  1205. *
  1206. * Returns 1 if @urb describes an OUT transfer (host-to-device),
  1207. * otherwise 0.
  1208. */
  1209. static inline int usb_urb_dir_out(struct urb *urb)
  1210. {
  1211. return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_OUT;
  1212. }
  1213. void *usb_buffer_alloc(struct usb_device *dev, size_t size,
  1214. gfp_t mem_flags, dma_addr_t *dma);
  1215. void usb_buffer_free(struct usb_device *dev, size_t size,
  1216. void *addr, dma_addr_t dma);
  1217. #if 0
  1218. struct urb *usb_buffer_map(struct urb *urb);
  1219. void usb_buffer_dmasync(struct urb *urb);
  1220. void usb_buffer_unmap(struct urb *urb);
  1221. #endif
  1222. struct scatterlist;
  1223. int usb_buffer_map_sg(const struct usb_device *dev, int is_in,
  1224. struct scatterlist *sg, int nents);
  1225. #if 0
  1226. void usb_buffer_dmasync_sg(const struct usb_device *dev, int is_in,
  1227. struct scatterlist *sg, int n_hw_ents);
  1228. #endif
  1229. void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
  1230. struct scatterlist *sg, int n_hw_ents);
  1231. /*-------------------------------------------------------------------*
  1232. * SYNCHRONOUS CALL SUPPORT *
  1233. *-------------------------------------------------------------------*/
  1234. extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
  1235. __u8 request, __u8 requesttype, __u16 value, __u16 index,
  1236. void *data, __u16 size, int timeout);
  1237. extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
  1238. void *data, int len, int *actual_length, int timeout);
  1239. extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
  1240. void *data, int len, int *actual_length,
  1241. int timeout);
  1242. /* wrappers around usb_control_msg() for the most common standard requests */
  1243. extern int usb_get_descriptor(struct usb_device *dev, unsigned char desctype,
  1244. unsigned char descindex, void *buf, int size);
  1245. extern int usb_get_status(struct usb_device *dev,
  1246. int type, int target, void *data);
  1247. extern int usb_string(struct usb_device *dev, int index,
  1248. char *buf, size_t size);
  1249. /* wrappers that also update important state inside usbcore */
  1250. extern int usb_clear_halt(struct usb_device *dev, int pipe);
  1251. extern int usb_reset_configuration(struct usb_device *dev);
  1252. extern int usb_set_interface(struct usb_device *dev, int ifnum, int alternate);
  1253. extern void usb_reset_endpoint(struct usb_device *dev, unsigned int epaddr);
  1254. /* this request isn't really synchronous, but it belongs with the others */
  1255. extern int usb_driver_set_configuration(struct usb_device *udev, int config);
  1256. /*
  1257. * timeouts, in milliseconds, used for sending/receiving control messages
  1258. * they typically complete within a few frames (msec) after they're issued
  1259. * USB identifies 5 second timeouts, maybe more in a few cases, and a few
  1260. * slow devices (like some MGE Ellipse UPSes) actually push that limit.
  1261. */
  1262. #define USB_CTRL_GET_TIMEOUT 5000
  1263. #define USB_CTRL_SET_TIMEOUT 5000
  1264. /**
  1265. * struct usb_sg_request - support for scatter/gather I/O
  1266. * @status: zero indicates success, else negative errno
  1267. * @bytes: counts bytes transferred.
  1268. *
  1269. * These requests are initialized using usb_sg_init(), and then are used
  1270. * as request handles passed to usb_sg_wait() or usb_sg_cancel(). Most
  1271. * members of the request object aren't for driver access.
  1272. *
  1273. * The status and bytecount values are valid only after usb_sg_wait()
  1274. * returns. If the status is zero, then the bytecount matches the total
  1275. * from the request.
  1276. *
  1277. * After an error completion, drivers may need to clear a halt condition
  1278. * on the endpoint.
  1279. */
  1280. struct usb_sg_request {
  1281. int status;
  1282. size_t bytes;
  1283. /*
  1284. * members below are private: to usbcore,
  1285. * and are not provided for driver access!
  1286. */
  1287. spinlock_t lock;
  1288. struct usb_device *dev;
  1289. int pipe;
  1290. struct scatterlist *sg;
  1291. int nents;
  1292. int entries;
  1293. struct urb **urbs;
  1294. int count;
  1295. struct completion complete;
  1296. };
  1297. int usb_sg_init(
  1298. struct usb_sg_request *io,
  1299. struct usb_device *dev,
  1300. unsigned pipe,
  1301. unsigned period,
  1302. struct scatterlist *sg,
  1303. int nents,
  1304. size_t length,
  1305. gfp_t mem_flags
  1306. );
  1307. void usb_sg_cancel(struct usb_sg_request *io);
  1308. void usb_sg_wait(struct usb_sg_request *io);
  1309. /* ----------------------------------------------------------------------- */
  1310. /*
  1311. * For various legacy reasons, Linux has a small cookie that's paired with
  1312. * a struct usb_device to identify an endpoint queue. Queue characteristics
  1313. * are defined by the endpoint's descriptor. This cookie is called a "pipe",
  1314. * an unsigned int encoded as:
  1315. *
  1316. * - direction: bit 7 (0 = Host-to-Device [Out],
  1317. * 1 = Device-to-Host [In] ...
  1318. * like endpoint bEndpointAddress)
  1319. * - device address: bits 8-14 ... bit positions known to uhci-hcd
  1320. * - endpoint: bits 15-18 ... bit positions known to uhci-hcd
  1321. * - pipe type: bits 30-31 (00 = isochronous, 01 = interrupt,
  1322. * 10 = control, 11 = bulk)
  1323. *
  1324. * Given the device address and endpoint descriptor, pipes are redundant.
  1325. */
  1326. /* NOTE: these are not the standard USB_ENDPOINT_XFER_* values!! */
  1327. /* (yet ... they're the values used by usbfs) */
  1328. #define PIPE_ISOCHRONOUS 0
  1329. #define PIPE_INTERRUPT 1
  1330. #define PIPE_CONTROL 2
  1331. #define PIPE_BULK 3
  1332. #define usb_pipein(pipe) ((pipe) & USB_DIR_IN)
  1333. #define usb_pipeout(pipe) (!usb_pipein(pipe))
  1334. #define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)
  1335. #define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)
  1336. #define usb_pipetype(pipe) (((pipe) >> 30) & 3)
  1337. #define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
  1338. #define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)
  1339. #define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)
  1340. #define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
  1341. static inline unsigned int __create_pipe(struct usb_device *dev,
  1342. unsigned int endpoint)
  1343. {
  1344. return (dev->devnum << 8) | (endpoint << 15);
  1345. }
  1346. /* Create various pipes... */
  1347. #define usb_sndctrlpipe(dev,endpoint) \
  1348. ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint))
  1349. #define usb_rcvctrlpipe(dev,endpoint) \
  1350. ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
  1351. #define usb_sndisocpipe(dev,endpoint) \
  1352. ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint))
  1353. #define usb_rcvisocpipe(dev,endpoint) \
  1354. ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
  1355. #define usb_sndbulkpipe(dev,endpoint) \
  1356. ((PIPE_BULK << 30) | __create_pipe(dev, endpoint))
  1357. #define usb_rcvbulkpipe(dev,endpoint) \
  1358. ((PIPE_BULK << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
  1359. #define usb_sndintpipe(dev,endpoint) \
  1360. ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint))
  1361. #define usb_rcvintpipe(dev,endpoint) \
  1362. ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
  1363. /*-------------------------------------------------------------------------*/
  1364. static inline __u16
  1365. usb_maxpacket(struct usb_device *udev, int pipe, int is_out)
  1366. {
  1367. struct usb_host_endpoint *ep;
  1368. unsigned epnum = usb_pipeendpoint(pipe);
  1369. if (is_out) {
  1370. WARN_ON(usb_pipein(pipe));
  1371. ep = udev->ep_out[epnum];
  1372. } else {
  1373. WARN_ON(usb_pipeout(pipe));
  1374. ep = udev->ep_in[epnum];
  1375. }
  1376. if (!ep)
  1377. return 0;
  1378. /* NOTE: only 0x07ff bits are for packet size... */
  1379. return le16_to_cpu(ep->desc.wMaxPacketSize);
  1380. }
  1381. /* ----------------------------------------------------------------------- */
  1382. /* Events from the usb core */
  1383. #define USB_DEVICE_ADD 0x0001
  1384. #define USB_DEVICE_REMOVE 0x0002
  1385. #define USB_BUS_ADD 0x0003
  1386. #define USB_BUS_REMOVE 0x0004
  1387. extern void usb_register_notify(struct notifier_block *nb);
  1388. extern void usb_unregister_notify(struct notifier_block *nb);
  1389. #ifdef DEBUG
  1390. #define dbg(format, arg...) printk(KERN_DEBUG "%s: " format "\n" , \
  1391. __FILE__ , ## arg)
  1392. #else
  1393. #define dbg(format, arg...) do {} while (0)
  1394. #endif
  1395. #define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \
  1396. format "\n" , ## arg)
  1397. #endif /* __KERNEL__ */
  1398. #endif