diff mbox series

[1/2] usb: linux/usb.h: Move USB port definition to usb.h

Message ID 20240905042447.418662-1-kai.heng.feng@canonical.com (mailing list archive)
State New
Headers show
Series [1/2] usb: linux/usb.h: Move USB port definition to usb.h | expand

Commit Message

Kai-Heng Feng Sept. 5, 2024, 4:24 a.m. UTC
Move struct usb_port to linux/usb.h so other subsystems can use it too.

The user will be introduced in next patch.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 drivers/usb/core/hub.h | 45 -------------------------------------
 drivers/usb/core/usb.h |  6 -----
 include/linux/usb.h    | 51 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 51 deletions(-)

Comments

Greg KH Sept. 5, 2024, 5:19 a.m. UTC | #1
On Thu, Sep 05, 2024 at 12:24:46PM +0800, Kai-Heng Feng wrote:
> Move struct usb_port to linux/usb.h so other subsystems can use it too.

These really are "internal to the usb core" functions and variables, I
am loath to export them as it requires that you "know" what the device
type is of something without any recorse if you get it wrong.  I
commented on patch 2/2 about that.

Could we provide a usb core function for you instead to help out?  What
exactly are you trying to get access to on the USB bus that you need to
use here, the port or the device?

thanks,

greg k-h
Kai-Heng Feng Sept. 5, 2024, 6:24 a.m. UTC | #2
On Thu, Sep 5, 2024 at 1:20 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Thu, Sep 05, 2024 at 12:24:46PM +0800, Kai-Heng Feng wrote:
> > Move struct usb_port to linux/usb.h so other subsystems can use it too.
>
> These really are "internal to the usb core" functions and variables, I
> am loath to export them as it requires that you "know" what the device
> type is of something without any recorse if you get it wrong.  I
> commented on patch 2/2 about that.
>
> Could we provide a usb core function for you instead to help out?  What
> exactly are you trying to get access to on the USB bus that you need to
> use here, the port or the device?

The device so the quirk can check its vendor and product id.

That means a function or helper that can return USB port/device from
an ACPI path.

Kai-Heng

>
> thanks,
>
> greg k-h
Greg KH Sept. 5, 2024, 6:49 a.m. UTC | #3
On Thu, Sep 05, 2024 at 02:24:31PM +0800, Kai-Heng Feng wrote:
> On Thu, Sep 5, 2024 at 1:20 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> >
> > On Thu, Sep 05, 2024 at 12:24:46PM +0800, Kai-Heng Feng wrote:
> > > Move struct usb_port to linux/usb.h so other subsystems can use it too.
> >
> > These really are "internal to the usb core" functions and variables, I
> > am loath to export them as it requires that you "know" what the device
> > type is of something without any recorse if you get it wrong.  I
> > commented on patch 2/2 about that.
> >
> > Could we provide a usb core function for you instead to help out?  What
> > exactly are you trying to get access to on the USB bus that you need to
> > use here, the port or the device?
> 
> The device so the quirk can check its vendor and product id.
> 
> That means a function or helper that can return USB port/device from
> an ACPI path.

So you don't want the port, only the device.  Why not just search the
bus for a device, you don't care where in the acpi path it lives, right?
Or better yet, do this in the driver for the device itself, that's when
you know you have the right device.

thanks,

greg k-h
Kai-Heng Feng Sept. 6, 2024, 2:20 a.m. UTC | #4
On Thu, Sep 5, 2024 at 2:50 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Thu, Sep 05, 2024 at 02:24:31PM +0800, Kai-Heng Feng wrote:
> > On Thu, Sep 5, 2024 at 1:20 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> > >
> > > On Thu, Sep 05, 2024 at 12:24:46PM +0800, Kai-Heng Feng wrote:
> > > > Move struct usb_port to linux/usb.h so other subsystems can use it too.
> > >
> > > These really are "internal to the usb core" functions and variables, I
> > > am loath to export them as it requires that you "know" what the device
> > > type is of something without any recorse if you get it wrong.  I
> > > commented on patch 2/2 about that.
> > >
> > > Could we provide a usb core function for you instead to help out?  What
> > > exactly are you trying to get access to on the USB bus that you need to
> > > use here, the port or the device?
> >
> > The device so the quirk can check its vendor and product id.
> >
> > That means a function or helper that can return USB port/device from
> > an ACPI path.
>
> So you don't want the port, only the device.  Why not just search the
> bus for a device, you don't care where in the acpi path it lives, right?
> Or better yet, do this in the driver for the device itself, that's when
> you know you have the right device.

The crucial part of the quirk is the device links between VGA and USB
controller to enforce suspend order, it can be hard to create and
maintain the links when the USB device can disappear at any moment.

Kai-Heng

>
> thanks,
>
> greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index e6ae73f8a95d..8b488c247a1e 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -77,51 +77,6 @@  struct usb_hub {
 	struct list_head        onboard_devs;
 };
 
-/**
- * struct usb port - kernel's representation of a usb port
- * @child: usb device attached to the port
- * @dev: generic device interface
- * @port_owner: port's owner
- * @peer: related usb2 and usb3 ports (share the same connector)
- * @connector: USB Type-C connector
- * @req: default pm qos request for hubs without port power control
- * @connect_type: port's connect type
- * @state: device state of the usb device attached to the port
- * @state_kn: kernfs_node of the sysfs attribute that accesses @state
- * @location: opaque representation of platform connector location
- * @status_lock: synchronize port_event() vs usb_port_{suspend|resume}
- * @portnum: port index num based one
- * @is_superspeed cache super-speed status
- * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted.
- * @usb3_lpm_u2_permit: whether USB3 U2 LPM is permitted.
- * @early_stop: whether port initialization will be stopped earlier.
- * @ignore_event: whether events of the port are ignored.
- */
-struct usb_port {
-	struct usb_device *child;
-	struct device dev;
-	struct usb_dev_state *port_owner;
-	struct usb_port *peer;
-	struct typec_connector *connector;
-	struct dev_pm_qos_request *req;
-	enum usb_port_connect_type connect_type;
-	enum usb_device_state state;
-	struct kernfs_node *state_kn;
-	usb_port_location_t location;
-	struct mutex status_lock;
-	u32 over_current_count;
-	u8 portnum;
-	u32 quirks;
-	unsigned int early_stop:1;
-	unsigned int ignore_event:1;
-	unsigned int is_superspeed:1;
-	unsigned int usb3_lpm_u1_permit:1;
-	unsigned int usb3_lpm_u2_permit:1;
-};
-
-#define to_usb_port(_dev) \
-	container_of(_dev, struct usb_port, dev)
-
 extern int usb_hub_create_port_device(struct usb_hub *hub,
 		int port1);
 extern void usb_hub_remove_port_device(struct usb_hub *hub,
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index b8324ea05b20..3f45b6978660 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -192,12 +192,6 @@  extern const struct file_operations usbdev_file_operations;
 extern int usb_devio_init(void);
 extern void usb_devio_cleanup(void);
 
-/*
- * Firmware specific cookie identifying a port's location. '0' == no location
- * data available
- */
-typedef u32 usb_port_location_t;
-
 /* internal notify stuff */
 extern void usb_notify_add_device(struct usb_device *udev);
 extern void usb_notify_remove_device(struct usb_device *udev);
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 832997a9da0a..1a8f94cc2bc1 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -772,6 +772,57 @@  extern void usb_queue_reset_device(struct usb_interface *dev);
 
 extern struct device *usb_intf_get_dma_device(struct usb_interface *intf);
 
+/*
+ * Firmware specific cookie identifying a port's location. '0' == no location
+ * data available
+ */
+typedef u32 usb_port_location_t;
+
+/**
+ * struct usb port - kernel's representation of a usb port
+ * @child: usb device attached to the port
+ * @dev: generic device interface
+ * @port_owner: port's owner
+ * @peer: related usb2 and usb3 ports (share the same connector)
+ * @connector: USB Type-C connector
+ * @req: default pm qos request for hubs without port power control
+ * @connect_type: port's connect type
+ * @state: device state of the usb device attached to the port
+ * @state_kn: kernfs_node of the sysfs attribute that accesses @state
+ * @location: opaque representation of platform connector location
+ * @status_lock: synchronize port_event() vs usb_port_{suspend|resume}
+ * @portnum: port index num based one
+ * @is_superspeed cache super-speed status
+ * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted.
+ * @usb3_lpm_u2_permit: whether USB3 U2 LPM is permitted.
+ * @early_stop: whether port initialization will be stopped earlier.
+ * @ignore_event: whether events of the port are ignored.
+ */
+struct usb_port {
+	struct usb_device *child;
+	struct device dev;
+	struct usb_dev_state *port_owner;
+	struct usb_port *peer;
+	struct typec_connector *connector;
+	struct dev_pm_qos_request *req;
+	enum usb_port_connect_type connect_type;
+	enum usb_device_state state;
+	struct kernfs_node *state_kn;
+	usb_port_location_t location;
+	struct mutex status_lock;
+	u32 over_current_count;
+	u8 portnum;
+	u32 quirks;
+	unsigned int early_stop:1;
+	unsigned int ignore_event:1;
+	unsigned int is_superspeed:1;
+	unsigned int usb3_lpm_u1_permit:1;
+	unsigned int usb3_lpm_u2_permit:1;
+};
+
+#define to_usb_port(_dev) \
+	container_of(_dev, struct usb_port, dev)
+
 #ifdef CONFIG_ACPI
 extern int usb_acpi_set_power_state(struct usb_device *hdev, int index,
 	bool enable);