xhci: stored cached port capability values in one place
authorMathias Nyman <mathias.nyman@linux.intel.com>
Mon, 29 Apr 2024 14:02:28 +0000 (17:02 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 1 May 2024 06:47:13 +0000 (08:47 +0200)
Port capability flags for USB2 ports have been cached in an
u32 xhci->ext_caps[] array long before the driver had struct xhci_port
and struct xhci_port_cap structures.

Move these cached USB2 port capability values together with the other
port capability values into struct xhci_port_cap cability structure.

This also gets rid of the cumbersome way of mapping port to USB2
capability based on portnum as each port has a pointer to its capability
structure.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20240429140245.3955523-2-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/xhci-mem.c
drivers/usb/host/xhci.c
drivers/usb/host/xhci.h

index 69dd866698833e990bf22097f89d165af65d2ba2..7ff2ff29b48e79e726456ac7dadf311a99c59909 100644 (file)
@@ -1950,7 +1950,6 @@ no_bw:
        kfree(xhci->usb3_rhub.ports);
        kfree(xhci->hw_ports);
        kfree(xhci->rh_bw);
-       kfree(xhci->ext_caps);
        for (i = 0; i < xhci->num_port_caps; i++)
                kfree(xhci->port_caps[i].psi);
        kfree(xhci->port_caps);
@@ -1961,7 +1960,6 @@ no_bw:
        xhci->usb3_rhub.ports = NULL;
        xhci->hw_ports = NULL;
        xhci->rh_bw = NULL;
-       xhci->ext_caps = NULL;
        xhci->port_caps = NULL;
        xhci->interrupters = NULL;
 
@@ -2089,10 +2087,7 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
 
        port_cap->maj_rev = major_revision;
        port_cap->min_rev = minor_revision;
-
-       /* cache usb2 port capabilities */
-       if (major_revision < 0x03 && xhci->num_ext_caps < max_caps)
-               xhci->ext_caps[xhci->num_ext_caps++] = temp;
+       port_cap->protocol_caps = temp;
 
        if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) &&
                 (temp & XHCI_HLC)) {
@@ -2212,11 +2207,6 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
                                                      XHCI_EXT_CAPS_PROTOCOL);
        }
 
-       xhci->ext_caps = kcalloc_node(cap_count, sizeof(*xhci->ext_caps),
-                               flags, dev_to_node(dev));
-       if (!xhci->ext_caps)
-               return -ENOMEM;
-
        xhci->port_caps = kcalloc_node(cap_count, sizeof(*xhci->port_caps),
                                flags, dev_to_node(dev));
        if (!xhci->port_caps)
index 8579603edaff17e629f137bd4fe21fcbb90377c1..7f07672d41106ba368db32d4097ec8b579086e0c 100644 (file)
@@ -4511,23 +4511,14 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
  * only USB2 ports extended protocol capability values are cached.
  * Return 1 if capability is supported
  */
-static int xhci_check_usb2_port_capability(struct xhci_hcd *xhci, int port,
+static bool xhci_check_usb2_port_capability(struct xhci_hcd *xhci, int portnum,
                                           unsigned capability)
 {
-       u32 port_offset, port_count;
-       int i;
+       struct xhci_port *port;
 
-       for (i = 0; i < xhci->num_ext_caps; i++) {
-               if (xhci->ext_caps[i] & capability) {
-                       /* port offsets starts at 1 */
-                       port_offset = XHCI_EXT_PORT_OFF(xhci->ext_caps[i]) - 1;
-                       port_count = XHCI_EXT_PORT_COUNT(xhci->ext_caps[i]);
-                       if (port >= port_offset &&
-                           port < port_offset + port_count)
-                               return 1;
-               }
-       }
-       return 0;
+       port = xhci->usb2_rhub.ports[portnum];
+
+       return !!(port->port_cap->protocol_caps & capability);
 }
 
 static int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
index 6f4bf98a628245818c11e32ae355e596efb4c23c..1c9519205330cfbaa064a26b13237a3791b2dc3a 100644 (file)
@@ -1451,6 +1451,7 @@ struct xhci_port_cap {
        u8                      psi_uid_count;
        u8                      maj_rev;
        u8                      min_rev;
+       u32                     protocol_caps;
 };
 
 struct xhci_port {
@@ -1640,9 +1641,6 @@ struct xhci_hcd {
        unsigned                broken_suspend:1;
        /* Indicates that omitting hcd is supported if root hub has no ports */
        unsigned                allow_single_roothub:1;
-       /* cached usb2 extened protocol capabilites */
-       u32                     *ext_caps;
-       unsigned int            num_ext_caps;
        /* cached extended protocol port capabilities */
        struct xhci_port_cap    *port_caps;
        unsigned int            num_port_caps;