Rui Miguel Silva | fb0c70c | 2022-06-29 11:06:14 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | |
| 3 | #ifndef __USB_URB_COMPAT_H__ |
| 4 | #define __USB_URB_COMPAT_H__ |
| 5 | |
| 6 | #include <linux/compat.h> |
| 7 | #include <usb.h> |
| 8 | |
| 9 | struct udevice; |
| 10 | struct urb; |
| 11 | struct usb_hcd; |
| 12 | |
| 13 | struct usb_urb_ops { |
| 14 | int (*urb_enqueue)(struct usb_hcd *hcd, struct urb *urb, |
| 15 | gfp_t mem_flags); |
| 16 | int (*urb_dequeue)(struct usb_hcd *hcd, struct urb *urb, int status); |
| 17 | int (*hub_control)(struct usb_hcd *hcd, struct usb_device *dev, |
| 18 | unsigned long pipe, void *buffer, int len, |
| 19 | struct devrequest *setup); |
| 20 | irqreturn_t (*isr)(int irq, void *priv); |
| 21 | }; |
| 22 | |
| 23 | struct usb_hcd { |
| 24 | void *hcd_priv; |
| 25 | const struct usb_urb_ops *urb_ops; |
| 26 | }; |
| 27 | |
| 28 | struct usb_host_endpoint { |
| 29 | struct usb_endpoint_descriptor desc; |
| 30 | struct list_head urb_list; |
| 31 | void *hcpriv; |
| 32 | }; |
| 33 | |
| 34 | /* |
| 35 | * urb->transfer_flags: |
| 36 | * |
| 37 | * Note: URB_DIR_IN/OUT is automatically set in usb_submit_urb(). |
| 38 | */ |
| 39 | #define URB_SHORT_NOT_OK 0x0001 /* report short reads as errors */ |
| 40 | #define URB_ZERO_PACKET 0x0040 /* Finish bulk OUT with short packet */ |
| 41 | |
| 42 | typedef void (*usb_complete_t)(struct urb *); |
| 43 | |
| 44 | struct urb { |
| 45 | void *hcpriv; /* private data for host controller */ |
| 46 | struct list_head urb_list; /* list head for use by the urb's |
| 47 | * current owner */ |
| 48 | struct usb_device *dev; /* (in) pointer to associated device */ |
| 49 | struct usb_host_endpoint *ep; /* (internal) pointer to endpoint */ |
| 50 | unsigned int pipe; /* (in) pipe information */ |
| 51 | int status; /* (return) non-ISO status */ |
| 52 | unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/ |
| 53 | void *transfer_buffer; /* (in) associated data buffer */ |
| 54 | dma_addr_t transfer_dma; /* (in) dma addr for transfer_buffer */ |
| 55 | u32 transfer_buffer_length; /* (in) data buffer length */ |
| 56 | u32 actual_length; /* (return) actual transfer length */ |
| 57 | unsigned char *setup_packet; /* (in) setup packet (control only) */ |
| 58 | int start_frame; /* (modify) start frame (ISO) */ |
| 59 | usb_complete_t complete; /* (in) completion routine */ |
| 60 | }; |
| 61 | |
| 62 | #define usb_hcd_link_urb_to_ep(hcd, urb) ({ \ |
| 63 | int ret = 0; \ |
| 64 | list_add_tail(&urb->urb_list, &urb->ep->urb_list); \ |
| 65 | ret; }) |
| 66 | #define usb_hcd_unlink_urb_from_ep(hcd, urb) list_del_init(&urb->urb_list) |
| 67 | #define usb_hcd_check_unlink_urb(hdc, urb, status) 0 |
| 68 | |
| 69 | static inline void usb_hcd_giveback_urb(struct usb_hcd *hcd, |
| 70 | struct urb *urb, |
| 71 | int status) |
| 72 | { |
| 73 | urb->status = status; |
| 74 | if (urb->complete) |
| 75 | urb->complete(urb); |
| 76 | } |
| 77 | |
| 78 | static inline int usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, |
| 79 | struct urb *urb) |
| 80 | { |
| 81 | /* TODO: add cache invalidation here */ |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * usb_dev_get_parent() - Get the parent of a USB device |
| 87 | * |
| 88 | * @udev: USB struct containing information about the device |
| 89 | * Return: associated device for which udev == dev_get_parent_priv(dev) |
| 90 | */ |
| 91 | struct usb_device *usb_dev_get_parent(struct usb_device *udev); |
| 92 | |
| 93 | int usb_urb_submit_control(struct usb_hcd *hcd, struct urb *urb, |
| 94 | struct usb_host_endpoint *hep, |
| 95 | struct usb_device *dev, unsigned long pipe, |
| 96 | void *buffer, int len, struct devrequest *setup, |
| 97 | int interval, enum usb_device_speed speed); |
| 98 | |
| 99 | int usb_urb_submit_bulk(struct usb_hcd *hcd, struct urb *urb, |
| 100 | struct usb_host_endpoint *hep, struct usb_device *dev, |
| 101 | unsigned long pipe, void *buffer, int len); |
| 102 | |
| 103 | int usb_urb_submit_irq(struct usb_hcd *hcd, struct urb *urb, |
| 104 | struct usb_host_endpoint *hep, struct usb_device *dev, |
| 105 | unsigned long pipe, void *buffer, int len, int interval); |
| 106 | |
| 107 | void usb_urb_fill(struct urb *urb, struct usb_host_endpoint *hep, |
| 108 | struct usb_device *dev, int endpoint_type, |
| 109 | unsigned long pipe, void *buffer, int len, |
| 110 | struct devrequest *setup, int interval); |
| 111 | |
| 112 | int usb_urb_submit(struct usb_hcd *hcd, struct urb *urb); |
| 113 | |
| 114 | #endif /* __USB_COMPAT_H__ */ |