Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Copyright (C) 2003-2008 Takahiro Hirofuchi
0004  * Copyright (C) 2015 Nobuo Iwata
0005  */
0006 
0007 #ifndef __USBIP_VHCI_H
0008 #define __USBIP_VHCI_H
0009 
0010 #include <linux/device.h>
0011 #include <linux/list.h>
0012 #include <linux/spinlock.h>
0013 #include <linux/sysfs.h>
0014 #include <linux/types.h>
0015 #include <linux/usb.h>
0016 #include <linux/usb/hcd.h>
0017 #include <linux/wait.h>
0018 
0019 struct vhci_device {
0020     struct usb_device *udev;
0021 
0022     /*
0023      * devid specifies a remote usb device uniquely instead
0024      * of combination of busnum and devnum.
0025      */
0026     __u32 devid;
0027 
0028     /* speed of a remote device */
0029     enum usb_device_speed speed;
0030 
0031     /* vhci root-hub port to which this device is attached */
0032     __u32 rhport;
0033 
0034     struct usbip_device ud;
0035 
0036     /* lock for the below link lists */
0037     spinlock_t priv_lock;
0038 
0039     /* vhci_priv is linked to one of them. */
0040     struct list_head priv_tx;
0041     struct list_head priv_rx;
0042 
0043     /* vhci_unlink is linked to one of them */
0044     struct list_head unlink_tx;
0045     struct list_head unlink_rx;
0046 
0047     /* vhci_tx thread sleeps for this queue */
0048     wait_queue_head_t waitq_tx;
0049 };
0050 
0051 /* urb->hcpriv, use container_of() */
0052 struct vhci_priv {
0053     unsigned long seqnum;
0054     struct list_head list;
0055 
0056     struct vhci_device *vdev;
0057     struct urb *urb;
0058 };
0059 
0060 struct vhci_unlink {
0061     /* seqnum of this request */
0062     unsigned long seqnum;
0063 
0064     struct list_head list;
0065 
0066     /* seqnum of the unlink target */
0067     unsigned long unlink_seqnum;
0068 };
0069 
0070 enum hub_speed {
0071     HUB_SPEED_HIGH = 0,
0072     HUB_SPEED_SUPER,
0073 };
0074 
0075 /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
0076 #ifdef CONFIG_USBIP_VHCI_HC_PORTS
0077 #define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS
0078 #else
0079 #define VHCI_HC_PORTS 8
0080 #endif
0081 
0082 /* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */
0083 #define VHCI_PORTS  (VHCI_HC_PORTS*2)
0084 
0085 #ifdef CONFIG_USBIP_VHCI_NR_HCS
0086 #define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
0087 #else
0088 #define VHCI_NR_HCS 1
0089 #endif
0090 
0091 #define MAX_STATUS_NAME 16
0092 
0093 struct vhci {
0094     spinlock_t lock;
0095 
0096     struct platform_device *pdev;
0097 
0098     struct vhci_hcd *vhci_hcd_hs;
0099     struct vhci_hcd *vhci_hcd_ss;
0100 };
0101 
0102 /* for usb_hcd.hcd_priv[0] */
0103 struct vhci_hcd {
0104     struct vhci *vhci;
0105 
0106     u32 port_status[VHCI_HC_PORTS];
0107 
0108     unsigned resuming:1;
0109     unsigned long re_timeout;
0110 
0111     atomic_t seqnum;
0112 
0113     /*
0114      * NOTE:
0115      * wIndex shows the port number and begins from 1.
0116      * But, the index of this array begins from 0.
0117      */
0118     struct vhci_device vdev[VHCI_HC_PORTS];
0119 };
0120 
0121 extern int vhci_num_controllers;
0122 extern struct vhci *vhcis;
0123 extern struct attribute_group vhci_attr_group;
0124 
0125 /* vhci_hcd.c */
0126 void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed);
0127 
0128 /* vhci_sysfs.c */
0129 int vhci_init_attr_group(void);
0130 void vhci_finish_attr_group(void);
0131 
0132 /* vhci_rx.c */
0133 struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
0134 int vhci_rx_loop(void *data);
0135 
0136 /* vhci_tx.c */
0137 int vhci_tx_loop(void *data);
0138 
0139 static inline __u32 port_to_rhport(__u32 port)
0140 {
0141     return port % VHCI_HC_PORTS;
0142 }
0143 
0144 static inline int port_to_pdev_nr(__u32 port)
0145 {
0146     return port / VHCI_PORTS;
0147 }
0148 
0149 static inline struct vhci_hcd *hcd_to_vhci_hcd(struct usb_hcd *hcd)
0150 {
0151     return (struct vhci_hcd *) (hcd->hcd_priv);
0152 }
0153 
0154 static inline struct device *hcd_dev(struct usb_hcd *hcd)
0155 {
0156     return (hcd)->self.controller;
0157 }
0158 
0159 static inline const char *hcd_name(struct usb_hcd *hcd)
0160 {
0161     return (hcd)->self.bus_name;
0162 }
0163 
0164 static inline struct usb_hcd *vhci_hcd_to_hcd(struct vhci_hcd *vhci_hcd)
0165 {
0166     return container_of((void *) vhci_hcd, struct usb_hcd, hcd_priv);
0167 }
0168 
0169 static inline struct vhci_hcd *vdev_to_vhci_hcd(struct vhci_device *vdev)
0170 {
0171     return container_of((void *)(vdev - vdev->rhport), struct vhci_hcd, vdev);
0172 }
0173 
0174 #endif /* __USBIP_VHCI_H */