diff options
Diffstat (limited to 'include/linux/usb.h')
-rw-r--r-- | include/linux/usb.h | 79 |
1 files changed, 72 insertions, 7 deletions
diff --git a/include/linux/usb.h b/include/linux/usb.h index 4f33a58fa9d1..c5c8f169d3cf 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h | |||
@@ -52,6 +52,7 @@ struct ep_device; | |||
52 | * @ep_dev: ep_device for sysfs info | 52 | * @ep_dev: ep_device for sysfs info |
53 | * @extra: descriptors following this endpoint in the configuration | 53 | * @extra: descriptors following this endpoint in the configuration |
54 | * @extralen: how many bytes of "extra" are valid | 54 | * @extralen: how many bytes of "extra" are valid |
55 | * @enabled: URBs may be submitted to this endpoint | ||
55 | * | 56 | * |
56 | * USB requests are always queued to a given endpoint, identified by a | 57 | * USB requests are always queued to a given endpoint, identified by a |
57 | * descriptor within an active interface in a given USB configuration. | 58 | * descriptor within an active interface in a given USB configuration. |
@@ -64,6 +65,7 @@ struct usb_host_endpoint { | |||
64 | 65 | ||
65 | unsigned char *extra; /* Extra descriptors */ | 66 | unsigned char *extra; /* Extra descriptors */ |
66 | int extralen; | 67 | int extralen; |
68 | int enabled; | ||
67 | }; | 69 | }; |
68 | 70 | ||
69 | /* host-side wrapper for one interface setting's parsed descriptors */ | 71 | /* host-side wrapper for one interface setting's parsed descriptors */ |
@@ -344,6 +346,11 @@ struct usb_tt; | |||
344 | * | 346 | * |
345 | * Usbcore drivers should not set usbdev->state directly. Instead use | 347 | * Usbcore drivers should not set usbdev->state directly. Instead use |
346 | * usb_set_device_state(). | 348 | * usb_set_device_state(). |
349 | * | ||
350 | * @authorized: (user space) policy determines if we authorize this | ||
351 | * device to be used or not. By default, wired USB | ||
352 | * devices are authorized. WUSB devices are not, until we | ||
353 | * authorize them from user space. FIXME -- complete doc | ||
347 | */ | 354 | */ |
348 | struct usb_device { | 355 | struct usb_device { |
349 | int devnum; /* Address on USB bus */ | 356 | int devnum; /* Address on USB bus */ |
@@ -376,8 +383,11 @@ struct usb_device { | |||
376 | u8 portnum; /* Parent port number (origin 1) */ | 383 | u8 portnum; /* Parent port number (origin 1) */ |
377 | u8 level; /* Number of USB hub ancestors */ | 384 | u8 level; /* Number of USB hub ancestors */ |
378 | 385 | ||
386 | unsigned can_submit:1; /* URBs may be submitted */ | ||
379 | unsigned discon_suspended:1; /* Disconnected while suspended */ | 387 | unsigned discon_suspended:1; /* Disconnected while suspended */ |
380 | unsigned have_langid:1; /* whether string_langid is valid */ | 388 | unsigned have_langid:1; /* whether string_langid is valid */ |
389 | unsigned authorized:1; /* Policy has determined we can use it */ | ||
390 | unsigned wusb:1; /* Device is Wireless USB */ | ||
381 | int string_langid; /* language ID for strings */ | 391 | int string_langid; /* language ID for strings */ |
382 | 392 | ||
383 | /* static strings from the device */ | 393 | /* static strings from the device */ |
@@ -405,6 +415,7 @@ struct usb_device { | |||
405 | 415 | ||
406 | int pm_usage_cnt; /* usage counter for autosuspend */ | 416 | int pm_usage_cnt; /* usage counter for autosuspend */ |
407 | u32 quirks; /* quirks of the whole device */ | 417 | u32 quirks; /* quirks of the whole device */ |
418 | atomic_t urbnum; /* number of URBs submitted for the whole device */ | ||
408 | 419 | ||
409 | #ifdef CONFIG_PM | 420 | #ifdef CONFIG_PM |
410 | struct delayed_work autosuspend; /* for delayed autosuspends */ | 421 | struct delayed_work autosuspend; /* for delayed autosuspends */ |
@@ -419,6 +430,7 @@ struct usb_device { | |||
419 | unsigned persist_enabled:1; /* USB_PERSIST enabled for this dev */ | 430 | unsigned persist_enabled:1; /* USB_PERSIST enabled for this dev */ |
420 | unsigned autosuspend_disabled:1; /* autosuspend and autoresume */ | 431 | unsigned autosuspend_disabled:1; /* autosuspend and autoresume */ |
421 | unsigned autoresume_disabled:1; /* disabled by the user */ | 432 | unsigned autoresume_disabled:1; /* disabled by the user */ |
433 | unsigned skip_sys_resume:1; /* skip the next system resume */ | ||
422 | #endif | 434 | #endif |
423 | }; | 435 | }; |
424 | #define to_usb_device(d) container_of(d, struct usb_device, dev) | 436 | #define to_usb_device(d) container_of(d, struct usb_device, dev) |
@@ -555,6 +567,29 @@ static inline int usb_make_path (struct usb_device *dev, char *buf, | |||
555 | /*-------------------------------------------------------------------------*/ | 567 | /*-------------------------------------------------------------------------*/ |
556 | 568 | ||
557 | /** | 569 | /** |
570 | * usb_endpoint_num - get the endpoint's number | ||
571 | * @epd: endpoint to be checked | ||
572 | * | ||
573 | * Returns @epd's number: 0 to 15. | ||
574 | */ | ||
575 | static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd) | ||
576 | { | ||
577 | return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; | ||
578 | } | ||
579 | |||
580 | /** | ||
581 | * usb_endpoint_type - get the endpoint's transfer type | ||
582 | * @epd: endpoint to be checked | ||
583 | * | ||
584 | * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according | ||
585 | * to @epd's transfer type. | ||
586 | */ | ||
587 | static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd) | ||
588 | { | ||
589 | return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; | ||
590 | } | ||
591 | |||
592 | /** | ||
558 | * usb_endpoint_dir_in - check if the endpoint has IN direction | 593 | * usb_endpoint_dir_in - check if the endpoint has IN direction |
559 | * @epd: endpoint to be checked | 594 | * @epd: endpoint to be checked |
560 | * | 595 | * |
@@ -996,6 +1031,8 @@ extern int usb_disabled(void); | |||
996 | 1031 | ||
997 | /* | 1032 | /* |
998 | * urb->transfer_flags: | 1033 | * urb->transfer_flags: |
1034 | * | ||
1035 | * Note: URB_DIR_IN/OUT is automatically set in usb_submit_urb(). | ||
999 | */ | 1036 | */ |
1000 | #define URB_SHORT_NOT_OK 0x0001 /* report short reads as errors */ | 1037 | #define URB_SHORT_NOT_OK 0x0001 /* report short reads as errors */ |
1001 | #define URB_ISO_ASAP 0x0002 /* iso-only, urb->start_frame | 1038 | #define URB_ISO_ASAP 0x0002 /* iso-only, urb->start_frame |
@@ -1008,6 +1045,10 @@ extern int usb_disabled(void); | |||
1008 | * needed */ | 1045 | * needed */ |
1009 | #define URB_FREE_BUFFER 0x0100 /* Free transfer buffer with the URB */ | 1046 | #define URB_FREE_BUFFER 0x0100 /* Free transfer buffer with the URB */ |
1010 | 1047 | ||
1048 | #define URB_DIR_IN 0x0200 /* Transfer from device to host */ | ||
1049 | #define URB_DIR_OUT 0 | ||
1050 | #define URB_DIR_MASK URB_DIR_IN | ||
1051 | |||
1011 | struct usb_iso_packet_descriptor { | 1052 | struct usb_iso_packet_descriptor { |
1012 | unsigned int offset; | 1053 | unsigned int offset; |
1013 | unsigned int length; /* expected length */ | 1054 | unsigned int length; /* expected length */ |
@@ -1037,6 +1078,8 @@ typedef void (*usb_complete_t)(struct urb *); | |||
1037 | * @urb_list: For use by current owner of the URB. | 1078 | * @urb_list: For use by current owner of the URB. |
1038 | * @anchor_list: membership in the list of an anchor | 1079 | * @anchor_list: membership in the list of an anchor |
1039 | * @anchor: to anchor URBs to a common mooring | 1080 | * @anchor: to anchor URBs to a common mooring |
1081 | * @ep: Points to the endpoint's data structure. Will eventually | ||
1082 | * replace @pipe. | ||
1040 | * @pipe: Holds endpoint number, direction, type, and more. | 1083 | * @pipe: Holds endpoint number, direction, type, and more. |
1041 | * Create these values with the eight macros available; | 1084 | * Create these values with the eight macros available; |
1042 | * usb_{snd,rcv}TYPEpipe(dev,endpoint), where the TYPE is "ctrl" | 1085 | * usb_{snd,rcv}TYPEpipe(dev,endpoint), where the TYPE is "ctrl" |
@@ -1201,10 +1244,10 @@ struct urb | |||
1201 | { | 1244 | { |
1202 | /* private: usb core and host controller only fields in the urb */ | 1245 | /* private: usb core and host controller only fields in the urb */ |
1203 | struct kref kref; /* reference count of the URB */ | 1246 | struct kref kref; /* reference count of the URB */ |
1204 | spinlock_t lock; /* lock for the URB */ | ||
1205 | void *hcpriv; /* private data for host controller */ | 1247 | void *hcpriv; /* private data for host controller */ |
1206 | atomic_t use_count; /* concurrent submissions counter */ | 1248 | atomic_t use_count; /* concurrent submissions counter */ |
1207 | u8 reject; /* submissions will fail */ | 1249 | u8 reject; /* submissions will fail */ |
1250 | int unlinked; /* unlink error code */ | ||
1208 | 1251 | ||
1209 | /* public: documented fields in the urb that can be used by drivers */ | 1252 | /* public: documented fields in the urb that can be used by drivers */ |
1210 | struct list_head urb_list; /* list head for use by the urb's | 1253 | struct list_head urb_list; /* list head for use by the urb's |
@@ -1212,6 +1255,7 @@ struct urb | |||
1212 | struct list_head anchor_list; /* the URB may be anchored by the driver */ | 1255 | struct list_head anchor_list; /* the URB may be anchored by the driver */ |
1213 | struct usb_anchor *anchor; | 1256 | struct usb_anchor *anchor; |
1214 | struct usb_device *dev; /* (in) pointer to associated device */ | 1257 | struct usb_device *dev; /* (in) pointer to associated device */ |
1258 | struct usb_host_endpoint *ep; /* (internal) pointer to endpoint struct */ | ||
1215 | unsigned int pipe; /* (in) pipe information */ | 1259 | unsigned int pipe; /* (in) pipe information */ |
1216 | int status; /* (return) non-ISO status */ | 1260 | int status; /* (return) non-ISO status */ |
1217 | unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/ | 1261 | unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/ |
@@ -1257,7 +1301,6 @@ static inline void usb_fill_control_urb (struct urb *urb, | |||
1257 | usb_complete_t complete_fn, | 1301 | usb_complete_t complete_fn, |
1258 | void *context) | 1302 | void *context) |
1259 | { | 1303 | { |
1260 | spin_lock_init(&urb->lock); | ||
1261 | urb->dev = dev; | 1304 | urb->dev = dev; |
1262 | urb->pipe = pipe; | 1305 | urb->pipe = pipe; |
1263 | urb->setup_packet = setup_packet; | 1306 | urb->setup_packet = setup_packet; |
@@ -1288,7 +1331,6 @@ static inline void usb_fill_bulk_urb (struct urb *urb, | |||
1288 | usb_complete_t complete_fn, | 1331 | usb_complete_t complete_fn, |
1289 | void *context) | 1332 | void *context) |
1290 | { | 1333 | { |
1291 | spin_lock_init(&urb->lock); | ||
1292 | urb->dev = dev; | 1334 | urb->dev = dev; |
1293 | urb->pipe = pipe; | 1335 | urb->pipe = pipe; |
1294 | urb->transfer_buffer = transfer_buffer; | 1336 | urb->transfer_buffer = transfer_buffer; |
@@ -1324,7 +1366,6 @@ static inline void usb_fill_int_urb (struct urb *urb, | |||
1324 | void *context, | 1366 | void *context, |
1325 | int interval) | 1367 | int interval) |
1326 | { | 1368 | { |
1327 | spin_lock_init(&urb->lock); | ||
1328 | urb->dev = dev; | 1369 | urb->dev = dev; |
1329 | urb->pipe = pipe; | 1370 | urb->pipe = pipe; |
1330 | urb->transfer_buffer = transfer_buffer; | 1371 | urb->transfer_buffer = transfer_buffer; |
@@ -1352,6 +1393,30 @@ extern void usb_unanchor_urb(struct urb *urb); | |||
1352 | extern int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, | 1393 | extern int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, |
1353 | unsigned int timeout); | 1394 | unsigned int timeout); |
1354 | 1395 | ||
1396 | /** | ||
1397 | * usb_urb_dir_in - check if an URB describes an IN transfer | ||
1398 | * @urb: URB to be checked | ||
1399 | * | ||
1400 | * Returns 1 if @urb describes an IN transfer (device-to-host), | ||
1401 | * otherwise 0. | ||
1402 | */ | ||
1403 | static inline int usb_urb_dir_in(struct urb *urb) | ||
1404 | { | ||
1405 | return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_IN; | ||
1406 | } | ||
1407 | |||
1408 | /** | ||
1409 | * usb_urb_dir_out - check if an URB describes an OUT transfer | ||
1410 | * @urb: URB to be checked | ||
1411 | * | ||
1412 | * Returns 1 if @urb describes an OUT transfer (host-to-device), | ||
1413 | * otherwise 0. | ||
1414 | */ | ||
1415 | static inline int usb_urb_dir_out(struct urb *urb) | ||
1416 | { | ||
1417 | return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_OUT; | ||
1418 | } | ||
1419 | |||
1355 | void *usb_buffer_alloc (struct usb_device *dev, size_t size, | 1420 | void *usb_buffer_alloc (struct usb_device *dev, size_t size, |
1356 | gfp_t mem_flags, dma_addr_t *dma); | 1421 | gfp_t mem_flags, dma_addr_t *dma); |
1357 | void usb_buffer_free (struct usb_device *dev, size_t size, | 1422 | void usb_buffer_free (struct usb_device *dev, size_t size, |
@@ -1364,13 +1429,13 @@ void usb_buffer_unmap (struct urb *urb); | |||
1364 | #endif | 1429 | #endif |
1365 | 1430 | ||
1366 | struct scatterlist; | 1431 | struct scatterlist; |
1367 | int usb_buffer_map_sg(const struct usb_device *dev, unsigned pipe, | 1432 | int usb_buffer_map_sg(const struct usb_device *dev, int is_in, |
1368 | struct scatterlist *sg, int nents); | 1433 | struct scatterlist *sg, int nents); |
1369 | #if 0 | 1434 | #if 0 |
1370 | void usb_buffer_dmasync_sg(const struct usb_device *dev, unsigned pipe, | 1435 | void usb_buffer_dmasync_sg(const struct usb_device *dev, int is_in, |
1371 | struct scatterlist *sg, int n_hw_ents); | 1436 | struct scatterlist *sg, int n_hw_ents); |
1372 | #endif | 1437 | #endif |
1373 | void usb_buffer_unmap_sg(const struct usb_device *dev, unsigned pipe, | 1438 | void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in, |
1374 | struct scatterlist *sg, int n_hw_ents); | 1439 | struct scatterlist *sg, int n_hw_ents); |
1375 | 1440 | ||
1376 | /*-------------------------------------------------------------------* | 1441 | /*-------------------------------------------------------------------* |