0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <linux/usb.h>
0015 #include <linux/usb/ch11.h>
0016 #include <linux/usb/hcd.h>
0017 #include "usb.h"
0018
0019 struct usb_hub {
0020 struct device *intfdev;
0021 struct usb_device *hdev;
0022 struct kref kref;
0023 struct urb *urb;
0024
0025
0026 u8 (*buffer)[8];
0027 union {
0028 struct usb_hub_status hub;
0029 struct usb_port_status port;
0030 } *status;
0031 struct mutex status_mutex;
0032
0033 int error;
0034 int nerrors;
0035
0036 unsigned long event_bits[1];
0037 unsigned long change_bits[1];
0038
0039 unsigned long removed_bits[1];
0040
0041 unsigned long wakeup_bits[1];
0042
0043 unsigned long power_bits[1];
0044 unsigned long child_usage_bits[1];
0045
0046 unsigned long warm_reset_bits[1];
0047
0048 #if USB_MAXCHILDREN > 31
0049 #error event_bits[] is too short!
0050 #endif
0051
0052 struct usb_hub_descriptor *descriptor;
0053 struct usb_tt tt;
0054
0055 unsigned mA_per_port;
0056 #ifdef CONFIG_PM
0057 unsigned wakeup_enabled_descendants;
0058 #endif
0059
0060 unsigned limited_power:1;
0061 unsigned quiescing:1;
0062 unsigned disconnected:1;
0063 unsigned in_reset:1;
0064 unsigned quirk_disable_autosuspend:1;
0065
0066 unsigned quirk_check_port_auto_suspend:1;
0067
0068 unsigned has_indicators:1;
0069 u8 indicator[USB_MAXCHILDREN];
0070 struct delayed_work leds;
0071 struct delayed_work init_work;
0072 struct work_struct events;
0073 spinlock_t irq_urb_lock;
0074 struct timer_list irq_urb_retry;
0075 struct usb_port **ports;
0076 struct list_head onboard_hub_devs;
0077 };
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 struct usb_port {
0095 struct usb_device *child;
0096 struct device dev;
0097 struct usb_dev_state *port_owner;
0098 struct usb_port *peer;
0099 struct dev_pm_qos_request *req;
0100 enum usb_port_connect_type connect_type;
0101 usb_port_location_t location;
0102 struct mutex status_lock;
0103 u32 over_current_count;
0104 u8 portnum;
0105 u32 quirks;
0106 unsigned int is_superspeed:1;
0107 unsigned int usb3_lpm_u1_permit:1;
0108 unsigned int usb3_lpm_u2_permit:1;
0109 };
0110
0111 #define to_usb_port(_dev) \
0112 container_of(_dev, struct usb_port, dev)
0113
0114 extern int usb_hub_create_port_device(struct usb_hub *hub,
0115 int port1);
0116 extern void usb_hub_remove_port_device(struct usb_hub *hub,
0117 int port1);
0118 extern int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub,
0119 int port1, bool set);
0120 extern struct usb_hub *usb_hub_to_struct_hub(struct usb_device *hdev);
0121 extern int hub_port_debounce(struct usb_hub *hub, int port1,
0122 bool must_be_connected);
0123 extern int usb_clear_port_feature(struct usb_device *hdev,
0124 int port1, int feature);
0125 extern int usb_hub_port_status(struct usb_hub *hub, int port1,
0126 u16 *status, u16 *change);
0127 extern int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus);
0128
0129 static inline bool hub_is_port_power_switchable(struct usb_hub *hub)
0130 {
0131 __le16 hcs;
0132
0133 if (!hub)
0134 return false;
0135 hcs = hub->descriptor->wHubCharacteristics;
0136 return (le16_to_cpu(hcs) & HUB_CHAR_LPSM) < HUB_CHAR_NO_LPSM;
0137 }
0138
0139 static inline int hub_is_superspeed(struct usb_device *hdev)
0140 {
0141 return hdev->descriptor.bDeviceProtocol == USB_HUB_PR_SS;
0142 }
0143
0144 static inline int hub_is_superspeedplus(struct usb_device *hdev)
0145 {
0146 return (hdev->descriptor.bDeviceProtocol == USB_HUB_PR_SS &&
0147 le16_to_cpu(hdev->descriptor.bcdUSB) >= 0x0310 &&
0148 hdev->bos->ssp_cap);
0149 }
0150
0151 static inline unsigned hub_power_on_good_delay(struct usb_hub *hub)
0152 {
0153 unsigned delay = hub->descriptor->bPwrOn2PwrGood * 2;
0154
0155 if (!hub->hdev->parent)
0156 return delay;
0157 else
0158 return max(delay, 100U);
0159 }
0160
0161 static inline int hub_port_debounce_be_connected(struct usb_hub *hub,
0162 int port1)
0163 {
0164 return hub_port_debounce(hub, port1, true);
0165 }
0166
0167 static inline int hub_port_debounce_be_stable(struct usb_hub *hub,
0168 int port1)
0169 {
0170 return hub_port_debounce(hub, port1, false);
0171 }