Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2003-2008 Takahiro Hirofuchi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2015 Nobuo Iwata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #ifndef __USBIP_VHCI_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #define __USBIP_VHCI_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/usb/hcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) struct vhci_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	 * devid specifies a remote usb device uniquely instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	 * of combination of busnum and devnum.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	__u32 devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	/* speed of a remote device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	enum usb_device_speed speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	/* vhci root-hub port to which this device is attached */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	__u32 rhport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct usbip_device ud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	/* lock for the below link lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	spinlock_t priv_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	/* vhci_priv is linked to one of them. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct list_head priv_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct list_head priv_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	/* vhci_unlink is linked to one of them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct list_head unlink_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct list_head unlink_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	/* vhci_tx thread sleeps for this queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	wait_queue_head_t waitq_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) /* urb->hcpriv, use container_of() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) struct vhci_priv {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	unsigned long seqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct vhci_device *vdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) struct vhci_unlink {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	/* seqnum of this request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	unsigned long seqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/* seqnum of the unlink target */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned long unlink_seqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) enum hub_speed {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	HUB_SPEED_HIGH = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	HUB_SPEED_SUPER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #ifdef CONFIG_USBIP_VHCI_HC_PORTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #define VHCI_HC_PORTS 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) /* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) #define VHCI_PORTS	(VHCI_HC_PORTS*2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #ifdef CONFIG_USBIP_VHCI_NR_HCS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #define VHCI_NR_HCS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #define MAX_STATUS_NAME 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) struct vhci {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct vhci_hcd *vhci_hcd_hs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct vhci_hcd *vhci_hcd_ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* for usb_hcd.hcd_priv[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct vhci_hcd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct vhci *vhci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	u32 port_status[VHCI_HC_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	unsigned resuming:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	unsigned long re_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	atomic_t seqnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * NOTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * wIndex shows the port number and begins from 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 * But, the index of this array begins from 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct vhci_device vdev[VHCI_HC_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) extern int vhci_num_controllers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) extern struct vhci *vhcis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) extern struct attribute_group vhci_attr_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* vhci_hcd.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* vhci_sysfs.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int vhci_init_attr_group(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void vhci_finish_attr_group(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /* vhci_rx.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int vhci_rx_loop(void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* vhci_tx.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int vhci_tx_loop(void *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static inline __u32 port_to_rhport(__u32 port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return port % VHCI_HC_PORTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static inline int port_to_pdev_nr(__u32 port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return port / VHCI_PORTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static inline struct vhci_hcd *hcd_to_vhci_hcd(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	return (struct vhci_hcd *) (hcd->hcd_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static inline struct device *hcd_dev(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return (hcd)->self.controller;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static inline const char *hcd_name(struct usb_hcd *hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return (hcd)->self.bus_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static inline struct usb_hcd *vhci_hcd_to_hcd(struct vhci_hcd *vhci_hcd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return container_of((void *) vhci_hcd, struct usb_hcd, hcd_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static inline struct vhci_hcd *vdev_to_vhci_hcd(struct vhci_device *vdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return container_of((void *)(vdev - vdev->rhport), struct vhci_hcd, vdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) #endif /* __USBIP_VHCI_H */