vhci.h 3.6 KB
Newer Older
1 2
/*
 * Copyright (C) 2003-2008 Takahiro Hirofuchi
3
 * Copyright (C) 2015 Nobuo Iwata
4 5 6 7 8 9 10 11
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 */

12 13 14
#ifndef __USBIP_VHCI_H
#define __USBIP_VHCI_H

15 16 17 18 19 20
#include <linux/device.h>
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/sysfs.h>
#include <linux/types.h>
#include <linux/usb.h>
21
#include <linux/usb/hcd.h>
22
#include <linux/wait.h>
23 24 25 26 27 28 29 30 31 32 33 34 35

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;

36
	/* vhci root-hub port to which this device is attached */
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
	__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;
};

75
/* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
76 77 78 79 80 81 82 83 84 85 86 87 88
#ifdef CONFIG_USBIP_VHCI_HC_PORTS
#define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS
#else
#define VHCI_HC_PORTS 8
#endif

#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
89

Y
Yuyang Du 已提交
90 91 92
struct vhci {
	spinlock_t lock;

93 94
	struct platform_device *pdev;

Y
Yuyang Du 已提交
95 96 97 98 99
	struct vhci_hcd *vhci_hcd_hs;
	struct vhci_hcd *vhci_hcd_ss;
};

/* for usb_hcd.hcd_priv[0] */
100
struct vhci_hcd {
Y
Yuyang Du 已提交
101 102
	struct vhci *vhci;

103
	u32 port_status[VHCI_HC_PORTS];
104

105 106
	unsigned resuming:1;
	unsigned long re_timeout;
107 108 109 110 111 112 113 114

	atomic_t seqnum;

	/*
	 * NOTE:
	 * wIndex shows the port number and begins from 1.
	 * But, the index of this array begins from 0.
	 */
115
	struct vhci_device vdev[VHCI_HC_PORTS];
116 117
};

118
extern int vhci_num_controllers;
Y
Yuyang Du 已提交
119
extern struct vhci *vhcis;
120
extern struct attribute_group vhci_attr_group;
121 122

/* vhci_hcd.c */
123 124 125 126 127
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);
128

M
matt mooney 已提交
129
/* vhci_rx.c */
130
struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
M
matt mooney 已提交
131
int vhci_rx_loop(void *data);
132

M
matt mooney 已提交
133 134
/* vhci_tx.c */
int vhci_tx_loop(void *data);
135

136 137 138 139 140 141
static inline __u32 port_to_rhport(__u32 port)
{
	return port % VHCI_HC_PORTS;
}

static inline int port_to_pdev_nr(__u32 port)
142
{
143
	return port / VHCI_HC_PORTS;
144 145
}

146
static inline struct vhci_hcd *hcd_to_vhci_hcd(struct usb_hcd *hcd)
147 148 149 150
{
	return (struct vhci_hcd *) (hcd->hcd_priv);
}

151 152 153 154 155 156 157 158 159 160
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;
}

161
static inline struct usb_hcd *vhci_hcd_to_hcd(struct vhci_hcd *vhci_hcd)
162
{
163
	return container_of((void *) vhci_hcd, struct usb_hcd, hcd_priv);
164 165
}

166
static inline struct vhci_hcd *vdev_to_vhci_hcd(struct vhci_device *vdev)
167
{
168
	return container_of((void *)(vdev - vdev->rhport), struct vhci_hcd, vdev);
169
}
170 171

#endif /* __USBIP_VHCI_H */