Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * usb hub driver head file
0004  *
0005  * Copyright (C) 1999 Linus Torvalds
0006  * Copyright (C) 1999 Johannes Erdfelt
0007  * Copyright (C) 1999 Gregory P. Smith
0008  * Copyright (C) 2001 Brad Hards (bhards@bigpond.net.au)
0009  * Copyright (C) 2012 Intel Corp (tianyu.lan@intel.com)
0010  *
0011  *  move struct usb_hub to this file.
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;   /* the "interface" device */
0021     struct usb_device   *hdev;
0022     struct kref     kref;
0023     struct urb      *urb;       /* for interrupt polling pipe */
0024 
0025     /* buffer for urb ... with extra space in case of babble */
0026     u8          (*buffer)[8];
0027     union {
0028         struct usb_hub_status   hub;
0029         struct usb_port_status  port;
0030     }           *status;    /* buffer for status reports */
0031     struct mutex        status_mutex;   /* for the status buffer */
0032 
0033     int         error;      /* last reported error */
0034     int         nerrors;    /* track consecutive errors */
0035 
0036     unsigned long       event_bits[1];  /* status change bitmask */
0037     unsigned long       change_bits[1]; /* ports with logical connect
0038                             status change */
0039     unsigned long       removed_bits[1]; /* ports with a "removed"
0040                             device present */
0041     unsigned long       wakeup_bits[1]; /* ports that have signaled
0042                             remote wakeup */
0043     unsigned long       power_bits[1]; /* ports that are powered */
0044     unsigned long       child_usage_bits[1]; /* ports powered on for
0045                             children */
0046     unsigned long       warm_reset_bits[1]; /* ports requesting warm
0047                             reset recovery */
0048 #if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */
0049 #error event_bits[] is too short!
0050 #endif
0051 
0052     struct usb_hub_descriptor *descriptor;  /* class descriptor */
0053     struct usb_tt       tt;     /* Transaction Translator */
0054 
0055     unsigned        mA_per_port;    /* current for each child */
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  * struct usb port - kernel's representation of a usb port
0081  * @child: usb device attached to the port
0082  * @dev: generic device interface
0083  * @port_owner: port's owner
0084  * @peer: related usb2 and usb3 ports (share the same connector)
0085  * @req: default pm qos request for hubs without port power control
0086  * @connect_type: port's connect type
0087  * @location: opaque representation of platform connector location
0088  * @status_lock: synchronize port_event() vs usb_port_{suspend|resume}
0089  * @portnum: port index num based one
0090  * @is_superspeed cache super-speed status
0091  * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted.
0092  * @usb3_lpm_u2_permit: whether USB3 U2 LPM is permitted.
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) /* root hub */
0156         return delay;
0157     else /* Wait at least 100 msec for power to become stable */
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 }