2017-11-03 13:28:30 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-07-10 00:56:51 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2008 Takahiro Hirofuchi
|
2016-06-13 05:33:40 +03:00
|
|
|
* Copyright (C) 2015 Nobuo Iwata
|
2008-07-10 00:56:51 +04:00
|
|
|
*/
|
|
|
|
|
2011-08-22 10:53:28 +04:00
|
|
|
#ifndef __USBIP_VHCI_H
|
|
|
|
#define __USBIP_VHCI_H
|
|
|
|
|
2011-05-12 09:33:43 +04:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/usb.h>
|
2010-04-25 01:21:52 +04:00
|
|
|
#include <linux/usb/hcd.h>
|
2011-05-12 09:33:43 +04:00
|
|
|
#include <linux/wait.h>
|
2008-07-10 00:56:51 +04:00
|
|
|
|
|
|
|
struct vhci_device {
|
|
|
|
struct usb_device *udev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* devid specifies a remote usb device uniquely instead
|
|
|
|
* of combination of busnum and devnum.
|
|
|
|
*/
|
|
|
|
__u32 devid;
|
|
|
|
|
|
|
|
/* speed of a remote device */
|
|
|
|
enum usb_device_speed speed;
|
|
|
|
|
2011-05-06 14:47:49 +04:00
|
|
|
/* vhci root-hub port to which this device is attached */
|
2008-07-10 00:56:51 +04:00
|
|
|
__u32 rhport;
|
|
|
|
|
|
|
|
struct usbip_device ud;
|
|
|
|
|
|
|
|
/* lock for the below link lists */
|
|
|
|
spinlock_t priv_lock;
|
|
|
|
|
|
|
|
/* vhci_priv is linked to one of them. */
|
|
|
|
struct list_head priv_tx;
|
|
|
|
struct list_head priv_rx;
|
|
|
|
|
|
|
|
/* vhci_unlink is linked to one of them */
|
|
|
|
struct list_head unlink_tx;
|
|
|
|
struct list_head unlink_rx;
|
|
|
|
|
|
|
|
/* vhci_tx thread sleeps for this queue */
|
|
|
|
wait_queue_head_t waitq_tx;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* urb->hcpriv, use container_of() */
|
|
|
|
struct vhci_priv {
|
|
|
|
unsigned long seqnum;
|
|
|
|
struct list_head list;
|
|
|
|
|
|
|
|
struct vhci_device *vdev;
|
|
|
|
struct urb *urb;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vhci_unlink {
|
|
|
|
/* seqnum of this request */
|
|
|
|
unsigned long seqnum;
|
|
|
|
|
|
|
|
struct list_head list;
|
|
|
|
|
|
|
|
/* seqnum of the unlink target */
|
|
|
|
unsigned long unlink_seqnum;
|
|
|
|
};
|
|
|
|
|
2017-06-08 08:04:10 +03:00
|
|
|
enum hub_speed {
|
|
|
|
HUB_SPEED_HIGH = 0,
|
|
|
|
HUB_SPEED_SUPER,
|
|
|
|
};
|
|
|
|
|
2012-06-12 00:57:30 +04:00
|
|
|
/* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
|
2016-06-13 05:33:40 +03:00
|
|
|
#ifdef CONFIG_USBIP_VHCI_HC_PORTS
|
|
|
|
#define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS
|
|
|
|
#else
|
|
|
|
#define VHCI_HC_PORTS 8
|
|
|
|
#endif
|
|
|
|
|
2017-06-08 08:04:13 +03:00
|
|
|
/* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */
|
|
|
|
#define VHCI_PORTS (VHCI_HC_PORTS*2)
|
|
|
|
|
2016-06-13 05:33:40 +03:00
|
|
|
#ifdef CONFIG_USBIP_VHCI_NR_HCS
|
|
|
|
#define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
|
|
|
|
#else
|
|
|
|
#define VHCI_NR_HCS 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MAX_STATUS_NAME 16
|
2008-07-10 00:56:51 +04:00
|
|
|
|
2017-06-08 08:04:06 +03:00
|
|
|
struct vhci {
|
|
|
|
spinlock_t lock;
|
|
|
|
|
2017-06-08 08:04:07 +03:00
|
|
|
struct platform_device *pdev;
|
|
|
|
|
2017-06-08 08:04:06 +03:00
|
|
|
struct vhci_hcd *vhci_hcd_hs;
|
|
|
|
struct vhci_hcd *vhci_hcd_ss;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* for usb_hcd.hcd_priv[0] */
|
2008-07-10 00:56:51 +04:00
|
|
|
struct vhci_hcd {
|
2017-06-08 08:04:06 +03:00
|
|
|
struct vhci *vhci;
|
|
|
|
|
2016-06-13 05:33:40 +03:00
|
|
|
u32 port_status[VHCI_HC_PORTS];
|
2008-07-10 00:56:51 +04:00
|
|
|
|
2011-05-06 14:47:49 +04:00
|
|
|
unsigned resuming:1;
|
|
|
|
unsigned long re_timeout;
|
2008-07-10 00:56:51 +04:00
|
|
|
|
|
|
|
atomic_t seqnum;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE:
|
|
|
|
* wIndex shows the port number and begins from 1.
|
|
|
|
* But, the index of this array begins from 0.
|
|
|
|
*/
|
2016-06-13 05:33:40 +03:00
|
|
|
struct vhci_device vdev[VHCI_HC_PORTS];
|
2008-07-10 00:56:51 +04:00
|
|
|
};
|
|
|
|
|
2016-06-13 05:33:40 +03:00
|
|
|
extern int vhci_num_controllers;
|
2017-06-08 08:04:06 +03:00
|
|
|
extern struct vhci *vhcis;
|
2016-06-13 05:33:40 +03:00
|
|
|
extern struct attribute_group vhci_attr_group;
|
2008-07-10 00:56:51 +04:00
|
|
|
|
|
|
|
/* vhci_hcd.c */
|
2016-06-13 05:33:40 +03:00
|
|
|
void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed);
|
|
|
|
|
|
|
|
/* vhci_sysfs.c */
|
|
|
|
int vhci_init_attr_group(void);
|
|
|
|
void vhci_finish_attr_group(void);
|
2008-07-10 00:56:51 +04:00
|
|
|
|
2011-05-11 12:54:23 +04:00
|
|
|
/* vhci_rx.c */
|
2011-05-06 14:47:49 +04:00
|
|
|
struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
|
2011-05-11 12:54:23 +04:00
|
|
|
int vhci_rx_loop(void *data);
|
2011-01-12 16:02:01 +03:00
|
|
|
|
2011-05-11 12:54:23 +04:00
|
|
|
/* vhci_tx.c */
|
|
|
|
int vhci_tx_loop(void *data);
|
2008-07-10 00:56:51 +04:00
|
|
|
|
2016-06-13 05:33:40 +03:00
|
|
|
static inline __u32 port_to_rhport(__u32 port)
|
|
|
|
{
|
|
|
|
return port % VHCI_HC_PORTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int port_to_pdev_nr(__u32 port)
|
2008-07-10 00:56:51 +04:00
|
|
|
{
|
2017-06-08 08:04:13 +03:00
|
|
|
return port / VHCI_PORTS;
|
2008-07-10 00:56:51 +04:00
|
|
|
}
|
|
|
|
|
2017-06-08 08:04:05 +03:00
|
|
|
static inline struct vhci_hcd *hcd_to_vhci_hcd(struct usb_hcd *hcd)
|
2008-07-10 00:56:51 +04:00
|
|
|
{
|
|
|
|
return (struct vhci_hcd *) (hcd->hcd_priv);
|
|
|
|
}
|
|
|
|
|
2016-06-13 05:33:40 +03:00
|
|
|
static inline struct device *hcd_dev(struct usb_hcd *hcd)
|
|
|
|
{
|
|
|
|
return (hcd)->self.controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const char *hcd_name(struct usb_hcd *hcd)
|
|
|
|
{
|
|
|
|
return (hcd)->self.bus_name;
|
|
|
|
}
|
|
|
|
|
2017-06-08 08:04:05 +03:00
|
|
|
static inline struct usb_hcd *vhci_hcd_to_hcd(struct vhci_hcd *vhci_hcd)
|
2008-07-10 00:56:51 +04:00
|
|
|
{
|
2017-06-08 08:04:05 +03:00
|
|
|
return container_of((void *) vhci_hcd, struct usb_hcd, hcd_priv);
|
2008-07-10 00:56:51 +04:00
|
|
|
}
|
|
|
|
|
2017-06-08 08:04:05 +03:00
|
|
|
static inline struct vhci_hcd *vdev_to_vhci_hcd(struct vhci_device *vdev)
|
2008-07-10 00:56:51 +04:00
|
|
|
{
|
2017-06-08 08:04:05 +03:00
|
|
|
return container_of((void *)(vdev - vdev->rhport), struct vhci_hcd, vdev);
|
2008-07-10 00:56:51 +04:00
|
|
|
}
|
2011-08-22 10:53:28 +04:00
|
|
|
|
|
|
|
#endif /* __USBIP_VHCI_H */
|