Commit 63a1f845 authored by Mathias Nyman's avatar Mathias Nyman Committed by Greg Kroah-Hartman

xhci: stored cached port capability values in one place

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: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20240429140245.3955523-2-mathias.nyman@linux.intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9b780c84
...@@ -1950,7 +1950,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) ...@@ -1950,7 +1950,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
kfree(xhci->usb3_rhub.ports); kfree(xhci->usb3_rhub.ports);
kfree(xhci->hw_ports); kfree(xhci->hw_ports);
kfree(xhci->rh_bw); kfree(xhci->rh_bw);
kfree(xhci->ext_caps);
for (i = 0; i < xhci->num_port_caps; i++) for (i = 0; i < xhci->num_port_caps; i++)
kfree(xhci->port_caps[i].psi); kfree(xhci->port_caps[i].psi);
kfree(xhci->port_caps); kfree(xhci->port_caps);
...@@ -1961,7 +1960,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci) ...@@ -1961,7 +1960,6 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
xhci->usb3_rhub.ports = NULL; xhci->usb3_rhub.ports = NULL;
xhci->hw_ports = NULL; xhci->hw_ports = NULL;
xhci->rh_bw = NULL; xhci->rh_bw = NULL;
xhci->ext_caps = NULL;
xhci->port_caps = NULL; xhci->port_caps = NULL;
xhci->interrupters = NULL; xhci->interrupters = NULL;
...@@ -2089,10 +2087,7 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports, ...@@ -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->maj_rev = major_revision;
port_cap->min_rev = minor_revision; port_cap->min_rev = minor_revision;
port_cap->protocol_caps = temp;
/* cache usb2 port capabilities */
if (major_revision < 0x03 && xhci->num_ext_caps < max_caps)
xhci->ext_caps[xhci->num_ext_caps++] = temp;
if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) && if ((xhci->hci_version >= 0x100) && (major_revision != 0x03) &&
(temp & XHCI_HLC)) { (temp & XHCI_HLC)) {
...@@ -2212,11 +2207,6 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) ...@@ -2212,11 +2207,6 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
XHCI_EXT_CAPS_PROTOCOL); 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), xhci->port_caps = kcalloc_node(cap_count, sizeof(*xhci->port_caps),
flags, dev_to_node(dev)); flags, dev_to_node(dev));
if (!xhci->port_caps) if (!xhci->port_caps)
......
...@@ -4511,23 +4511,14 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd, ...@@ -4511,23 +4511,14 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
* only USB2 ports extended protocol capability values are cached. * only USB2 ports extended protocol capability values are cached.
* Return 1 if capability is supported * 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) unsigned capability)
{ {
u32 port_offset, port_count; struct xhci_port *port;
int i;
for (i = 0; i < xhci->num_ext_caps; i++) { port = xhci->usb2_rhub.ports[portnum];
if (xhci->ext_caps[i] & capability) {
/* port offsets starts at 1 */ return !!(port->port_cap->protocol_caps & capability);
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;
} }
static int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev) static int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
......
...@@ -1451,6 +1451,7 @@ struct xhci_port_cap { ...@@ -1451,6 +1451,7 @@ struct xhci_port_cap {
u8 psi_uid_count; u8 psi_uid_count;
u8 maj_rev; u8 maj_rev;
u8 min_rev; u8 min_rev;
u32 protocol_caps;
}; };
struct xhci_port { struct xhci_port {
...@@ -1640,9 +1641,6 @@ struct xhci_hcd { ...@@ -1640,9 +1641,6 @@ struct xhci_hcd {
unsigned broken_suspend:1; unsigned broken_suspend:1;
/* Indicates that omitting hcd is supported if root hub has no ports */ /* Indicates that omitting hcd is supported if root hub has no ports */
unsigned allow_single_roothub:1; unsigned allow_single_roothub:1;
/* cached usb2 extened protocol capabilites */
u32 *ext_caps;
unsigned int num_ext_caps;
/* cached extended protocol port capabilities */ /* cached extended protocol port capabilities */
struct xhci_port_cap *port_caps; struct xhci_port_cap *port_caps;
unsigned int num_port_caps; unsigned int num_port_caps;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment