1f9f848faSopenharmony_ci/*- 2f9f848faSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause 3f9f848faSopenharmony_ci * 4f9f848faSopenharmony_ci * Copyright (c) 2008-2023 Hans Petter Selasky 5f9f848faSopenharmony_ci * 6f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without 7f9f848faSopenharmony_ci * modification, are permitted provided that the following conditions 8f9f848faSopenharmony_ci * are met: 9f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright 10f9f848faSopenharmony_ci * notice, this list of conditions and the following disclaimer. 11f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 12f9f848faSopenharmony_ci * notice, this list of conditions and the following disclaimer in the 13f9f848faSopenharmony_ci * documentation and/or other materials provided with the distribution. 14f9f848faSopenharmony_ci * 15f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16f9f848faSopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17f9f848faSopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18f9f848faSopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19f9f848faSopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20f9f848faSopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21f9f848faSopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22f9f848faSopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23f9f848faSopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24f9f848faSopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25f9f848faSopenharmony_ci * SUCH DAMAGE. 26f9f848faSopenharmony_ci */ 27f9f848faSopenharmony_ci 28f9f848faSopenharmony_ci#ifndef _USB_DEV_H_ 29f9f848faSopenharmony_ci#define _USB_DEV_H_ 30f9f848faSopenharmony_ci 31f9f848faSopenharmony_cistruct usb_fifo; 32f9f848faSopenharmony_cistruct usb_mbuf; 33f9f848faSopenharmony_ci 34f9f848faSopenharmony_ci#define UID_ROOT 0 35f9f848faSopenharmony_ci#define GID_OPERATOR 5 36f9f848faSopenharmony_ci 37f9f848faSopenharmony_cistruct usb_symlink { 38f9f848faSopenharmony_ci TAILQ_ENTRY(usb_symlink) sym_entry; 39f9f848faSopenharmony_ci char src_path[32]; /* Source path - including terminating 40f9f848faSopenharmony_ci * zero */ 41f9f848faSopenharmony_ci char dst_path[32]; /* Destination path - including 42f9f848faSopenharmony_ci * terminating zero */ 43f9f848faSopenharmony_ci uint8_t src_len; /* String length */ 44f9f848faSopenharmony_ci uint8_t dst_len; /* String length */ 45f9f848faSopenharmony_ci}; 46f9f848faSopenharmony_ci 47f9f848faSopenharmony_ci/* 48f9f848faSopenharmony_ci * Private per-device information. 49f9f848faSopenharmony_ci */ 50f9f848faSopenharmony_cistruct usb_cdev_privdata { 51f9f848faSopenharmony_ci struct usb_bus *bus; 52f9f848faSopenharmony_ci struct usb_device *udev; 53f9f848faSopenharmony_ci struct usb_interface *iface; 54f9f848faSopenharmony_ci int bus_index; /* bus index */ 55f9f848faSopenharmony_ci int dev_index; /* device index */ 56f9f848faSopenharmony_ci int ep_addr; /* endpoint address */ 57f9f848faSopenharmony_ci int fflags; 58f9f848faSopenharmony_ci uint8_t fifo_index; /* FIFO index */ 59f9f848faSopenharmony_ci}; 60f9f848faSopenharmony_ci 61f9f848faSopenharmony_ci/* 62f9f848faSopenharmony_ci * The following structure defines a minimum re-implementation of the 63f9f848faSopenharmony_ci * ifqueue structure in the kernel. 64f9f848faSopenharmony_ci */ 65f9f848faSopenharmony_cistruct usb_ifqueue { 66f9f848faSopenharmony_ci struct usb_mbuf *ifq_head; 67f9f848faSopenharmony_ci struct usb_mbuf *ifq_tail; 68f9f848faSopenharmony_ci 69f9f848faSopenharmony_ci usb_size_t ifq_len; 70f9f848faSopenharmony_ci usb_size_t ifq_maxlen; 71f9f848faSopenharmony_ci}; 72f9f848faSopenharmony_ci 73f9f848faSopenharmony_ci/* 74f9f848faSopenharmony_ci * Private per-device and per-thread reference information 75f9f848faSopenharmony_ci */ 76f9f848faSopenharmony_cistruct usb_cdev_refdata { 77f9f848faSopenharmony_ci struct usb_fifo *rxfifo; 78f9f848faSopenharmony_ci struct usb_fifo *txfifo; 79f9f848faSopenharmony_ci uint8_t is_read; /* location has read access */ 80f9f848faSopenharmony_ci uint8_t is_write; /* location has write access */ 81f9f848faSopenharmony_ci uint8_t is_uref; /* USB refcount decr. needed */ 82f9f848faSopenharmony_ci uint8_t is_usbfs; /* USB-FS is active */ 83f9f848faSopenharmony_ci uint8_t do_unlock; /* USB enum unlock needed */ 84f9f848faSopenharmony_ci}; 85f9f848faSopenharmony_ci 86f9f848faSopenharmony_cistruct usb_fs_privdata { 87f9f848faSopenharmony_ci int bus_index; 88f9f848faSopenharmony_ci int dev_index; 89f9f848faSopenharmony_ci int ep_addr; 90f9f848faSopenharmony_ci int mode; 91f9f848faSopenharmony_ci int fifo_index; 92f9f848faSopenharmony_ci char cdev_name[32]; 93f9f848faSopenharmony_ci 94f9f848faSopenharmony_ci LIST_ENTRY(usb_fs_privdata) pd_next; 95f9f848faSopenharmony_ci}; 96f9f848faSopenharmony_ci 97f9f848faSopenharmony_ci/* 98f9f848faSopenharmony_ci * Most of the fields in the "usb_fifo" structure are used by the 99f9f848faSopenharmony_ci * generic USB access layer. 100f9f848faSopenharmony_ci */ 101f9f848faSopenharmony_cistruct usb_fifo { 102f9f848faSopenharmony_ci struct usb_ifqueue free_q; 103f9f848faSopenharmony_ci struct usb_ifqueue used_q; 104f9f848faSopenharmony_ci struct cv cv_io; 105f9f848faSopenharmony_ci struct cv cv_drain; 106f9f848faSopenharmony_ci struct usb_fifo_methods *methods; 107f9f848faSopenharmony_ci struct usb_symlink *symlink[2];/* our symlinks */ 108f9f848faSopenharmony_ci struct proc *async_p; /* process that wants SIGIO */ 109f9f848faSopenharmony_ci struct usb_fs_endpoint *fs_ep_ptr; 110f9f848faSopenharmony_ci struct usb_device *udev; 111f9f848faSopenharmony_ci struct usb_xfer *xfer[2]; 112f9f848faSopenharmony_ci struct usb_xfer **fs_xfer; 113f9f848faSopenharmony_ci struct mtx *priv_mtx; /* client data */ 114f9f848faSopenharmony_ci /* set if FIFO is opened by a FILE: */ 115f9f848faSopenharmony_ci struct usb_cdev_privdata *curr_cpd; 116f9f848faSopenharmony_ci void *priv_sc0; /* client data */ 117f9f848faSopenharmony_ci void *priv_sc1; /* client data */ 118f9f848faSopenharmony_ci void *queue_data; 119f9f848faSopenharmony_ci usb_timeout_t timeout; /* timeout in milliseconds */ 120f9f848faSopenharmony_ci usb_frlength_t bufsize; /* BULK and INTERRUPT buffer size */ 121f9f848faSopenharmony_ci usb_frcount_t nframes; /* for isochronous mode */ 122f9f848faSopenharmony_ci uint16_t dev_ep_index; /* our device endpoint index */ 123f9f848faSopenharmony_ci uint8_t flag_sleeping; /* set if FIFO is sleeping */ 124f9f848faSopenharmony_ci uint8_t flag_iscomplete; /* set if a USB transfer is complete */ 125f9f848faSopenharmony_ci uint8_t flag_iserror; /* set if FIFO error happened */ 126f9f848faSopenharmony_ci uint8_t flag_isselect; /* set if FIFO is selected */ 127f9f848faSopenharmony_ci uint8_t flag_flushing; /* set if FIFO is flushing data */ 128f9f848faSopenharmony_ci uint8_t flag_short; /* set if short_ok or force_short 129f9f848faSopenharmony_ci * transfer flags should be set */ 130f9f848faSopenharmony_ci uint8_t flag_stall; /* set if clear stall should be run */ 131f9f848faSopenharmony_ci uint8_t flag_write_defrag; /* set to defrag written data */ 132f9f848faSopenharmony_ci uint8_t flag_have_fragment; /* set if defragging */ 133f9f848faSopenharmony_ci uint8_t iface_index; /* set to the interface we belong to */ 134f9f848faSopenharmony_ci uint8_t fifo_index; /* set to the FIFO index in "struct 135f9f848faSopenharmony_ci * usb_device" */ 136f9f848faSopenharmony_ci uint8_t fs_ep_max; 137f9f848faSopenharmony_ci uint8_t fifo_zlp; /* zero length packet count */ 138f9f848faSopenharmony_ci uint8_t refcount; 139f9f848faSopenharmony_ci#define USB_FIFO_REF_MAX 0xFF 140f9f848faSopenharmony_ci}; 141f9f848faSopenharmony_ci 142f9f848faSopenharmony_ciextern struct file_operations_vfs usb_devsw; 143f9f848faSopenharmony_ci 144f9f848faSopenharmony_ciint usb_fifo_wait(struct usb_fifo *fifo); 145f9f848faSopenharmony_civoid usb_fifo_signal(struct usb_fifo *fifo); 146f9f848faSopenharmony_ciuint8_t usb_fifo_opened(struct usb_fifo *fifo); 147f9f848faSopenharmony_cistruct usb_symlink *usb_alloc_symlink(const char *target); 148f9f848faSopenharmony_civoid usb_free_symlink(struct usb_symlink *ps); 149f9f848faSopenharmony_ciint usb_read_symlink(uint8_t *user_ptr, uint32_t startentry, 150f9f848faSopenharmony_ci uint32_t user_len); 151f9f848faSopenharmony_civoid usb_dev_init(void *arg); 152f9f848faSopenharmony_civoid usb_dev_uninit(void *arg); 153f9f848faSopenharmony_ci 154f9f848faSopenharmony_ci#endif /* _USB_DEV_H_ */ 155