#ifndef _USB_DEVICE_H_
#define _USB_DEVICE_H_
#include <bus/u4b/usb_core.h>
#include <bus/u4b/usb_busdma.h>
#include <bus/u4b/usb_transfer.h>
struct usb_bus_methods;
struct usb_config_descriptor;
struct usb_device;
struct usb_fs_privdata;
struct usb_hw_ep_profile;
struct usb_symlink;
#define USB_CTRL_XFER_MAX 2
#define USB_CFG_ALLOC 0
#define USB_CFG_FREE 1
#define USB_CFG_INIT 2
#define USB_UNCFG_FLAG_NONE 0x00
#define USB_UNCFG_FLAG_FREE_EP0 0x02
struct usb_udev_msg {
struct usb_proc_msg hdr;
struct usb_device *udev;
};
struct usb_host_endpoint {
struct usb_endpoint_descriptor desc;
TAILQ_HEAD(, urb) bsd_urb_list;
struct usb_xfer *bsd_xfer[2];
uint8_t *extra;
usb_frlength_t fbsd_buf_size;
uint16_t extralen;
uint8_t bsd_iface_index;
} __aligned(USB_HOST_ALIGN);
struct usb_host_interface {
struct usb_interface_descriptor desc;
struct usb_host_endpoint *endpoint;
const char *string;
uint8_t *extra;
uint16_t extralen;
uint8_t bsd_iface_index;
} __aligned(USB_HOST_ALIGN);
struct usb_device_flags {
enum usb_hc_mode usb_mode;
uint8_t self_powered:1;
uint8_t no_strings:1;
uint8_t remote_wakeup:1;
uint8_t uq_bus_powered:1;
uint8_t peer_suspended:1;
uint8_t self_suspended:1;
uint8_t uq_delay_ctrl:1;
uint8_t uq_delay_init:1;
};
struct usb_power_save {
usb_ticks_t last_xfer_time;
usb_size_t type_refs[4];
usb_size_t read_refs;
usb_size_t write_refs;
};
struct usb_hw_ep_scratch_sub {
const struct usb_hw_ep_profile *pf;
uint16_t max_frame_size;
uint8_t hw_endpoint_out;
uint8_t hw_endpoint_in;
uint8_t needs_ep_type;
uint8_t needs_in:1;
uint8_t needs_out:1;
};
struct usb_hw_ep_scratch {
struct usb_hw_ep_scratch_sub ep[USB_EP_MAX];
struct usb_hw_ep_scratch_sub *ep_max;
struct usb_config_descriptor *cd;
struct usb_device *udev;
const struct usb_bus_methods *methods;
uint8_t bmOutAlloc[(USB_EP_MAX + 15) / 16];
uint8_t bmInAlloc[(USB_EP_MAX + 15) / 16];
};
struct usb_temp_setup {
void *buf;
usb_size_t size;
enum usb_dev_speed usb_speed;
uint8_t self_powered;
uint8_t bNumEndpoints;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bConfigurationValue;
usb_error_t err;
};
union usb_device_scratch {
struct usb_hw_ep_scratch hw_ep_scratch[1];
struct usb_temp_setup temp_setup[1];
struct {
struct usb_xfer dummy;
struct usb_setup_params parm;
} xfer_setup[1];
uint8_t data[255];
};
struct usb_device {
struct usb_udev_msg cs_msg[2];
struct lock enum_lock;
struct lock sr_lock;
struct lock ctrl_lock;
struct lock device_lock;
struct cv ctrlreq_cv;
struct cv ref_cv;
#if (USB_HAVE_FIXED_IFACE == 0)
struct usb_interface *ifaces;
#else
struct usb_interface ifaces[USB_IFACE_MAX];
#endif
struct usb_endpoint ctrl_ep;
#if (USB_HAVE_FIXED_ENDPOINT == 0)
struct usb_endpoint *endpoints;
#else
struct usb_endpoint endpoints[USB_MAX_EP_UNITS];
#endif
struct usb_power_save pwr_save;
struct usb_bus *bus;
device_t parent_dev;
struct usb_device *parent_hub;
struct usb_device *parent_hs_hub;
struct usb_config_descriptor *cdesc;
struct usb_hub *hub;
struct usb_xfer *ctrl_xfer[USB_CTRL_XFER_MAX];
struct usb_temp_data *usb_template_ptr;
struct usb_endpoint *ep_curr;
#if USB_HAVE_UGEN
struct usb_fifo *fifo[USB_FIFO_MAX];
struct usb_symlink *ugen_symlink;
struct usb_fs_privdata *ctrl_dev;
LIST_HEAD(,usb_fs_privdata) pd_list;
char ugen_name[20];
#endif
usb_ticks_t plugtime;
enum usb_dev_state state;
enum usb_dev_speed speed;
uint16_t refcount;
#define USB_DEV_REF_MAX 0xffff
uint16_t power;
uint16_t langid;
uint16_t autoQuirk[USB_MAX_AUTO_QUIRK];
uint8_t address;
uint8_t device_index;
uint8_t controller_slot_id;
uint8_t next_config_index;
uint8_t curr_config_index;
uint8_t curr_config_no;
uint8_t depth;
uint8_t port_index;
uint8_t port_no;
uint8_t hs_hub_addr;
uint8_t hs_port_no;
uint8_t driver_added_refcount;
uint8_t power_mode;
uint8_t re_enumerate_wait;
#define USB_RE_ENUM_DONE 0
#define USB_RE_ENUM_START 1
#define USB_RE_ENUM_PWR_OFF 2
#define USB_RE_ENUM_SET_CONFIG 3
uint8_t ifaces_max;
uint8_t endpoints_max;
struct usb_device_flags flags;
struct usb_endpoint_descriptor ctrl_ep_desc;
struct usb_endpoint_ss_comp_descriptor ctrl_ep_comp_desc;
struct usb_device_descriptor ddesc;
char *serial;
char *manufacturer;
char *product;
#if USB_HAVE_COMPAT_LINUX
struct usb_device_descriptor descriptor;
struct usb_host_endpoint ep0;
struct usb_interface *linux_iface_start;
struct usb_interface *linux_iface_end;
struct usb_host_endpoint *linux_endpoint_start;
struct usb_host_endpoint *linux_endpoint_end;
uint16_t devnum;
#endif
uint32_t clear_stall_errors;
union usb_device_scratch scratch;
#if (USB_HAVE_FIXED_CONFIG != 0)
uint32_t config_data[(USB_CONFIG_MAX + 3) / 4];
#endif
};
extern int usb_template;
const char *usb_statestr(enum usb_dev_state state);
struct usb_device *usb_alloc_device(device_t parent_dev, struct usb_bus *bus,
struct usb_device *parent_hub, uint8_t depth,
uint8_t port_index, uint8_t port_no,
enum usb_dev_speed speed, enum usb_hc_mode mode);
#if USB_HAVE_UGEN
struct usb_fs_privdata *usb_make_dev(struct usb_device *, const char *,
int, int, int, uid_t, gid_t, int);
void usb_destroy_dev(struct usb_fs_privdata *);
void usb_destroy_dev_sync(struct usb_fs_privdata *);
#endif
usb_error_t usb_probe_and_attach(struct usb_device *udev,
uint8_t iface_index);
void usb_detach_device(struct usb_device *, uint8_t, uint8_t);
usb_error_t usb_reset_iface_endpoints(struct usb_device *udev,
uint8_t iface_index);
usb_error_t usbd_set_config_index(struct usb_device *udev, uint8_t index);
usb_error_t usbd_set_endpoint_stall(struct usb_device *udev,
struct usb_endpoint *ep, uint8_t do_stall);
usb_error_t usb_suspend_resume(struct usb_device *udev,
uint8_t do_suspend);
void usb_devinfo(struct usb_device *udev, char *dst_ptr, uint16_t dst_len);
void usb_free_device(struct usb_device *, uint8_t);
void usb_linux_free_device(struct usb_device *dev);
uint8_t usb_peer_can_wakeup(struct usb_device *udev);
struct usb_endpoint *usb_endpoint_foreach(struct usb_device *udev, struct usb_endpoint *ep);
void usb_set_device_state(struct usb_device *, enum usb_dev_state);
enum usb_dev_state usb_get_device_state(struct usb_device *);
uint8_t usbd_enum_lock(struct usb_device *);
void usbd_enum_unlock(struct usb_device *);
void usbd_sr_lock(struct usb_device *);
void usbd_sr_unlock(struct usb_device *);
uint8_t usbd_ctrl_lock(struct usb_device *);
void usbd_ctrl_unlock(struct usb_device *);
uint8_t usbd_enum_is_locked(struct usb_device *);
#if USB_HAVE_TT_SUPPORT
void uhub_tt_buffer_reset_async_locked(struct usb_device *, struct usb_endpoint *);
#endif
uint8_t uhub_count_active_host_ports(struct usb_device *, enum usb_dev_speed);
void device_get_usb_iproduct(device_t dev, char *iProduct, size_t size);
void device_get_usb_vidpid(device_t dev, uint32_t *vid, uint32_t *pid);
int usb_device_is_UVC(struct usb_device *udev);
void usbd_get_phys(struct usb_device *udev, char *phys, uint8_t len);
#endif