usb: add struct usb_hub_port to store port related members.
PATCH v3 1/4 usb: add struct usb_hub_port to store port related members.
Add struct usb_hub_port pointer port_data in the struct usb_hub and allocate struct usb_hub_port perspectively for each ports to store private data.
--- drivers/usb/core/hub.c | 29 ++++++++++++++++------------- 1 files changed, 16 insertions(+), 13 deletions(-)
drivers/usb/core/hub.c +16 -13
@@ -37,6 +37,10 @@#endif #endif +struct usb_hub_port { +void *port_owner; +}; +struct usb_hub {struct device *intfdev;/* the "interface" device */ struct usb_device *hdev;
@@ -81,7 +85,7 @@ struct usb_hub {u8 indicator[USB_MAXCHILDREN ];struct delayed_work leds;struct delayed_work init_work; -void **port_owners; +struct usb_hub_port *port_data; };static inline int hub_is_superspeed (struct usb_device *hdev)
@@ -1271,8 +1275,9 @@ static int hub_configure(struct usb_hub *hub, hdev->children =kzalloc (hdev->maxchild *sizeof (struct usb_device *),GFP_KERNEL ); - hub->port_owners =kzalloc (hdev->maxchild *sizeof (void *),GFP_KERNEL ); -if (!hdev->children || !hub->port_owners) { + hub->port_data =kzalloc (hdev->maxchild *sizeof (struct usb_hub_port ), +GFP_KERNEL ); +if (!hub->port_data || !hdev->children) { ret = -ENOMEM ; goto fail; }
@@ -1527,7 +1532,7 @@ static void hub_disconnect(struct usb_interface *intf)usb_free_urb (hub->urb);kfree (hdev->children); -kfree (hub->port_owners); +kfree (hub->port_data);kfree (hub->descriptor);kfree (hub->status);kfree (hub->buffer);
@@ -1659,7 +1664,7 @@ static int find_port_owner(struct usb_device *hdev, unsigned port1,/* This assumes that devices not managed by the hub driver * will always have maxchild equal to 0. */ - *ppowner = &(hdev_to_hub (hdev)->port_owners[port1 -1 ]); + *ppowner = &(hdev_to_hub (hdev)->port_data[port1 -1 ].port_owner);return 0 ; }
@@ -1694,16 +1699,14 @@ int usb_hub_release_port(struct usb_device *hdev, unsigned port1, void *owner)void usb_hub_release_all_ports (struct usb_device *hdev,void *owner) { +struct usb_hub *hub =hdev_to_hub (hdev);int n; -void **powner; - n =find_port_owner (hdev,1 , &powner); -if (n ==0 ) { -for (; n < hdev->maxchild; (++n, ++powner)) { -if (*powner == owner) - *powner =NULL ; - } +for (n =0 ; n < hdev->maxchild; n++) { +if (hub->port_data[n].port_owner == owner) + hub->port_data[n].port_owner =NULL ; } + }/* The caller must hold udev's lock */
@@ -1714,7 +1717,7 @@ bool usb_device_is_owned(struct usb_device *udev)if (udev->state ==USB_STATE_NOTATTACHED || !udev->parent)return false; hub =hdev_to_hub (udev->parent); -return !!hub->port_owners[udev->portnum -1 ]; +return !!hub->port_data[udev->portnum -1 ].port_owner; }
Signature · 1 line
1.7.6.rc2.8.g28eb
A message that is not in the archive (sent off-list or not yet received): 1337954787-28388-1-git-send-email-tianyu.lan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
PATCH v3 3/4 usb/acpi: add the support of usb hub ports' acpi binding without attached devices.
The usb port is a device in the acpi table but it's not in the linux usb subsystem. USB hub port doesn't have struct device. So the acpi glue framework only can cover the usb port connected with usb device and store the acpi handle to struct device.archdata.acpi_handle. This patch is to add member port_acpi_handle in the struct usb_hub_port to store acpi handle. The acpi method "_UPC" and "_PLD" can be accessed without attached device.
v2
replace struct usb_hub_port member platform_data with member port_acpi_handle
to store acpi_handle
--- drivers/usb/core/hub.c | 42 ++++++++++++++++++++++++++++++++++++++++++ drivers/usb/core/usb-acpi.c | 37 ++++++++++++++++++++++++++++++++++++- drivers/usb/core/usb.h | 9 +++++++++ 3 files changed, 87 insertions(+), 1 deletions(-)
drivers/usb/core/hub.c +42 -0
@@ -30,6 +30,10 @@#include "usb.h" +#ifdef CONFIG_ACPI +#include <linux/acpi.h> +#endif +/* if we are in debug mode, always announce new devices */ #ifdef DEBUG #ifndef CONFIG_USB_ANNOUNCE_NEW_DEVICES
@@ -40,6 +44,9 @@struct usb_hub_port {void *port_owner;struct usb_device *child; +#ifdef CONFIG_ACPI +acpi_handle port_acpi_handle; +#endif };struct usb_hub {
@@ -1485,6 +1492,7 @@ static int hub_configure(struct usb_hub *hub,if (hub->has_indicators && blinkenlights) hub->indicator [0 ] =INDICATOR_CYCLE ; +usb_acpi_bind_hub_ports (hdev);hub_activate (hub,HUB_INIT );return 0 ;
@@ -4933,3 +4941,37 @@ struct usb_device *usb_get_hub_child(struct usb_device *hdev, }EXPORT_SYMBOL_GPL (usb_get_hub_child); +#ifdef CONFIG_ACPI +/** +* usb_set_hub_port_acpi_handle - Set the usb port's acpi handle +* @hdev: USB device belonging to the usb hub +* @port1: port num of the port +* @handle: port's acpi handle +*/ +void usb_set_hub_port_acpi_handle (struct usb_device *hdev,int port1, +void *handle) +{ +struct usb_hub *hub =hdev_to_hub (hdev); + +if (port1 <1 || port1 > hdev->maxchild) +return ; + hub->port_data[port1 -1 ].port_acpi_handle = handle; +} + +/** +* usb_get_hub_port_acpi_handle - Get the usb port's acpi handle +* @hdev: USB device belonging to the usb hub +* @port1: port num of the port +* +* Return port's acpi handle if successful, NULL if params are +* invaild. +*/ +acpi_handle usb_get_hub_port_acpi_handle (struct usb_device *hdev,int port1) +{ +struct usb_hub *hub =hdev_to_hub (hdev); + +if (port1 <1 || port1 > hdev->maxchild) +return NULL ; +return hub->port_data[port1 -1 ].port_acpi_handle; +} +#endif
drivers/usb/core/usb-acpi.c +36 -1
@@ -83,7 +83,16 @@ static int usb_acpi_find_device(struct device *dev, acpi_handle *handle)if (!parent_handle)return -ENODEV ; - *handle =acpi_get_child (parent_handle, udev->portnum); +/* +* The root hub's acpi handle is got from acpi method. +* Other device's acpi handle can be got from the usb hub +* port's platform_data. +*/ +if (!udev->parent) + *handle =acpi_get_child (parent_handle, udev->portnum); +else + *handle =usb_get_hub_port_acpi_handle ( + udev->parent, udev->portnum);if (!*handle)return -ENODEV ;
@@ -106,6 +115,32 @@ static struct acpi_bus_type usb_acpi_bus = { .find_device = usb_acpi_find_device, }; +int usb_acpi_bind_hub_ports (struct usb_device *hdev) +{ +acpi_handle hub_handle =NULL ; +acpi_handle port_handle =NULL ; +struct device *dev = &hdev->dev; +int i; + + hub_handle =DEVICE_ACPI_HANDLE (dev); +if (!hub_handle) +return -ENODEV ; + +/* +* usb hub port is not a device in the usb subsystem but it is a device +* in the acpi table. Store its acpi handle in the platform data of usb +* hub port. +*/ +for (i =1 ; i <= hdev->maxchild; i++) { + port_handle =acpi_get_child (hub_handle, i); +if (!port_handle) +continue ; +usb_set_hub_port_acpi_handle (hdev, i, + port_handle); + } +return 0 ; +} +int usb_acpi_register (void ) {return register_acpi_bus_type (&usb_acpi_bus);
drivers/usb/core/usb.h +9 -0
@@ -1,5 +1,8 @@#include <linux/pm.h> +#ifdef CONFIG_ACPI +#include <linux/acpi.h> +#endif /* Functions local to drivers/usb/core/ */ extern int usb_create_sysfs_dev_files (struct usb_device *dev);
@@ -159,7 +162,13 @@ extern void usb_notify_remove_bus(struct usb_bus *ubus);#ifdef CONFIG_ACPI extern int usb_acpi_register (void );extern void usb_acpi_unregister (void ); +extern int usb_acpi_bind_hub_ports (struct usb_device *hdev); +extern void usb_set_hub_port_acpi_handle (struct usb_device *hdev, +int port1,acpi_handle handle); +extern acpi_handle usb_get_hub_port_acpi_handle (struct usb_device *hdev, +int port1);#else static inline int usb_acpi_register (void ) {return 0 ; };static inline void usb_acpi_unregister (void ) { }; +static inline int usb_acpi_bind_hub_ports (struct usb_device *dev) {return 0 ; };#endif
Signature · 6 lines
1.7.6.rc2.8.g28eb -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 4/4 usb/acpi: add usb check for the connect type of usb port
In reply to a message not in the archiveCheck the connect type of usb port when getting the usb port's acpi_handle and store result into connect_type in the struct usb_hub_port.
Accoding to ACPI Spec 9.13. PLD indicates whether usb port is user visible and _UPC indicates whether it is connectable. If the port was visible and connectable, it could be freely connected and disconnected with USB devices. If no visible and connectable, a usb device is directly hard-wired to the port. If no visible and no connectable, the port would be not used.
When a device was found on the port, if the connect_type was hot-plug, then the device would be removable. If the connect_type was hard-wired, the device would be non-removable.
--- drivers/usb/core/hub.c | 44 ++++++++++++++++++++++++++++ drivers/usb/core/usb-acpi.c | 67 ++++++++++++++++++++++-------------------- drivers/usb/core/usb.h | 4 ++ include/linux/usb.h | 7 ++++ 4 files changed, 90 insertions(+), 32 deletions(-)
drivers/usb/core/hub.c +44 -0
@@ -47,6 +47,7 @@ struct usb_hub_port {#ifdef CONFIG_ACPI acpi_handle port_acpi_handle;#endif +enum usb_port_connect_type connect_type; };struct usb_hub {
@@ -4941,6 +4942,49 @@ struct usb_device *usb_get_hub_child(struct usb_device *hdev, }EXPORT_SYMBOL_GPL (usb_get_hub_child); +/** +* usb_set_hub_port_connect_type - set hub port connect type. +* @hdev: USB device belonging to the usb hub +* @port1: port num of the port +* @type: connect type of the port +* USB_PORT_CONNECT_TYPE_UNKNOWN +* USB_PORT_CONNECT_TYPE_HOT_PLUG +* USB_PORT_CONNECT_TYPE_HARD_WIRED +* USB_PORT_NOT_USED +*/ +void usb_set_hub_port_connect_type (struct usb_device *hdev,int port1, +enum usb_port_connect_type type) +{ +struct usb_hub *hub =hdev_to_hub (hdev); + +if (port1 <1 || port1 > hdev->maxchild) +return ; + hub->port_data[port1 -1 ].connect_type = type; +} + +/** +* usb_get_hub_port_connect_type - Get the port's connect +* type +* @hdev: USB device belonging to the usb hub +* @port1: port num of the port +* +* Return connect type of the port annd if input params are +* invalid, return USB_PORT_CONNECT_TYPE_UNKNOWN. +* USB_PORT_CONNECT_TYPE_UNKNOWN +* USB_PORT_CONNECT_TYPE_HOT_PLUG +* USB_PORT_CONNECT_TYPE_HARD_WIRED +* USB_PORT_NOT_USED +*/ +enum usb_port_connect_type +usb_get_hub_port_connect_type (struct usb_device *hdev,int port1) +{ +struct usb_hub *hub =hdev_to_hub (hdev); + +if (port1 <1 || port1 > hdev->maxchild) +return USB_PORT_CONNECT_TYPE_UNKNOWN ; +return hub->port_data[port1 -1 ].connect_type; +} +#ifdef CONFIG_ACPI /** * usb_set_hub_port_acpi_handle - Set the usb port's acpi handle
drivers/usb/core/usb-acpi.c +35 -32
113 lines not on this page · raw message
drivers/usb/core/usb.h +4 -0
@@ -158,6 +158,10 @@ extern void usb_notify_add_device(struct usb_device *udev);extern void usb_notify_remove_device (struct usb_device *udev);extern void usb_notify_add_bus (struct usb_bus *ubus);extern void usb_notify_remove_bus (struct usb_bus *ubus); +extern enum usb_port_connect_type +usb_get_hub_port_connect_type (struct usb_device *hdev,int port1); +extern void usb_set_hub_port_connect_type (struct usb_device *hdev,int port1, +enum usb_port_connect_type type);#ifdef CONFIG_ACPI extern int usb_acpi_register (void );
include/linux/usb.h +7 -0
@@ -417,6 +417,13 @@ struct usb3_lpm_parameters {int timeout; }; +enum usb_port_connect_type { +USB_PORT_CONNECT_TYPE_UNKNOWN =0 , +USB_PORT_CONNECT_TYPE_HOT_PLUG , +USB_PORT_CONNECT_TYPE_HARD_WIRED , +USB_PORT_NOT_USED , +}; +/** * struct usb_device - kernel's representation of a USB device * @devnum: device number; address on a USB bus
Signature · 6 lines
1.7.6.rc2.8.g28eb -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 2/4 usb: move struct usb_device->children to struct usb_hub_port->child
In reply to Lan TianyuMove child's pointer to the struct usb_hub_port since the child device is directly associated with the port. Provide usb_get_hub_child() to get child's pointer and macrio macro usb_get_hub_each_child to iterate all child devices on the hub. The child device's refcount will be increased before return. The caller should invoke usb_put_dev() to decrease the device's refcount when the child will not be used.
In the usb_get_hub_child(), still check the port1 param since the usb_get_hub_each_child() will pass maxchild+1 as port1 at end of last loop.
v3
add marco usb_get_hub_each_child() to iterate all hub devices usb_get_hub_child() increases child's refcount before return
--- drivers/staging/usbip/usbip_common.c | 3 +- drivers/usb/core/devices.c | 11 +++-- drivers/usb/core/hub.c | 81 +++++++++++++++++++++++----------- drivers/usb/host/r8a66597-hcd.c | 10 ++-- include/linux/usb.h | 17 ++++++- 5 files changed, 82 insertions(+), 40 deletions(-)
drivers/staging/usbip/usbip_common.c +1 -2
@@ -157,8 +157,7 @@ static void usbip_dump_usb_device(struct usb_device *udev)dev_dbg (dev,"have_langid %d, string_langid %d\n" , udev->have_langid, udev->string_langid); -dev_dbg (dev,"maxchild %d, children %p\n" , - udev->maxchild, udev->children); +dev_dbg (dev,"maxchild %d\n" , udev->maxchild); }static void usbip_dump_request_type (__u8 rt)
drivers/usb/core/devices.c +6 -5
@@ -496,6 +496,7 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,char *pages_start, *data_end, *speed;unsigned int length;ssize_t total_written =0 ; +struct usb_device *childdev =NULL ;/* don't bother with anything else if we're not writing any data */ if (*nbytes <=0 )
@@ -589,20 +590,20 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,free_pages ((unsigned long )pages_start,1 );/* Now look at all of this device's children. */ -for (chix =0 ; chix < usbdev->maxchild; chix++) { -struct usb_device *childdev = usbdev->children[chix]; - + usb_get_hub_each_child(usbdev, chix, childdev) +pr_info ("%s: %d\n" , __func__, chix);if (childdev) {usb_lock_device (childdev); ret =usb_device_dump (buffer, nbytes, skip_bytes, file_offset, childdev, bus, - level +1 , chix, ++cnt); + level +1 , chix -1 , ++cnt);usb_unlock_device (childdev); +usb_put_dev (childdev);if (ret == -EFAULT )return total_written; total_written += ret; } - } +return total_written; }
drivers/usb/core/hub.c +55 -26
224 lines not on this page · raw message
drivers/usb/host/r8a66597-hcd.c +5 -5
@@ -2033,18 +2033,18 @@ static int r8a66597_get_frame(struct usb_hcd *hcd)static void collect_usb_address_map (struct usb_device *udev,unsigned long *map) {int chix; +struct usb_device *childdev;if (udev->state ==USB_STATE_CONFIGURED && udev->parent && udev->parent->devnum >1 && udev->parent->descriptor.bDeviceClass ==USB_CLASS_HUB ) map[udev->devnum/32 ] |= (1 << (udev->devnum %32 )); -for (chix =0 ; chix < udev->maxchild; chix++) { -struct usb_device *childdev = udev->children[chix]; - -if (childdev) + usb_get_hub_each_child(udev, chix, childdev) +if (childdev) {collect_usb_address_map (childdev, map); - } +usb_put_dev (childdev); + } }/* this function must be called with interrupt disabled */
include/linux/usb.h +15 -2
@@ -463,7 +463,6 @@ struct usb3_lpm_parameters {* access from userspace * @usbfs_dentry: usbfs dentry entry for the device * @maxchild: number of ports if hub -* @children: child devices - USB devices that are attached to this hub * @quirks: quirks of the whole device * @urbnum: number of URBs submitted for the whole device * @active_duration: total time device is not suspended
@@ -537,7 +536,6 @@ struct usb_device {struct list_head filelist;int maxchild; -struct usb_device **children;u32 quirks;atomic_t urbnum;
@@ -567,6 +565,21 @@ static inline struct usb_device *interface_to_usbdev(struct usb_interface *intf)extern struct usb_device *usb_get_dev (struct usb_device *dev);extern void usb_put_dev (struct usb_device *dev); +extern struct usb_device *usb_get_hub_child (struct usb_device *hdev, +int port1); + +/** +* usb_get_hub_each_child - iterate over all child devices on the hub +* @hdev: USB device belonging to the usb hub +* @port1: portnum associated with child device +* @child: child device pointer +* +* NOTE: usb_get_hub_child() increases the child device's refcount. +*/ +#define usb_get_hub_each_child (hdev, port1, child) \ + for (port1 = 1, child = usb_get_hub_child(hdev, port1); \ + port1 <= hdev->maxchild; \ + child = usb_get_hub_child(hdev, ++port1))/* USB device locking */ #define usb_lock_device (udev) device_lock(&(udev)->dev)
Signature · 1 line
1.7.6.rc2.8.g28eb