summaryrefslogtreecommitdiff
path: root/drivers/usb
diff options
context:
space:
mode:
authorNiklas Neronin <niklas.neronin@linux.intel.com>2026-06-03 12:11:31 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-06-03 19:23:30 +0200
commit6ef46f3a013012e8b9943adac4d9e8780de9688e (patch)
tree251c04d2792a4ca069ecf5f4979aa0f14e759d3a /drivers/usb
parent7cd89392f6f981e3c537ce5e06d928f8e4f87489 (diff)
downloadlinux-next-6ef46f3a013012e8b9943adac4d9e8780de9688e.tar.gz
linux-next-6ef46f3a013012e8b9943adac4d9e8780de9688e.zip
usb: xhci: allocate DCBAA based on host controller max slots
Allocate the Device Context Base Address Array (DCBAA) according to the maximum number of device slots supported by the host controller, instead of always allocating the absolute maximum of 255 entries. The xHCI specification defines the DCBAA size as (MaxSlotsEnabled + 1) entries. In the xhci driver there is currently no distinction between MaxSlots and MaxSlotsEnabled, as all available slots are enabled during initialization. As a result, 'max_slots' effectively represents both values. This change allows the xHCI driver to respect custom slot limits, reduces unnecessary memory usage, and removes the obsolete "TODO" comment. Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Link: https://patch.msgid.link/20260603091132.1110849-15-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/host/xhci-mem.c6
-rw-r--r--drivers/usb/host/xhci-ring.c4
-rw-r--r--drivers/usb/host/xhci.h7
3 files changed, 7 insertions, 10 deletions
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 019dac47c5d6..939151e5440e 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1975,7 +1975,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
dcbaa = &xhci->dcbaa;
if (dcbaa->ctx_array) {
- dma_free_coherent(dev, array_size(sizeof(*dcbaa->ctx_array), MAX_HC_SLOTS),
+ dma_free_coherent(dev, array_size(sizeof(*dcbaa->ctx_array), xhci->max_slots + 1),
dcbaa->ctx_array, dcbaa->dma);
dcbaa->ctx_array = NULL;
}
@@ -2411,8 +2411,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Starting %s", __func__);
- dcbaa->ctx_array =
- dma_alloc_coherent(dev, array_size(sizeof(*dcbaa->ctx_array), MAX_HC_SLOTS),
+ xhci->dcbaa.ctx_array =
+ dma_alloc_coherent(dev, array_size(sizeof(*dcbaa->ctx_array), xhci->max_slots + 1),
&dcbaa->dma, flags);
if (!dcbaa->ctx_array)
goto fail;
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 3c304372bad3..4f98d8269625 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -609,7 +609,7 @@ static struct xhci_virt_ep *xhci_get_virt_ep(struct xhci_hcd *xhci,
unsigned int slot_id,
unsigned int ep_index)
{
- if (slot_id == 0 || slot_id >= MAX_HC_SLOTS) {
+ if (slot_id == 0 || slot_id > xhci->max_slots) {
xhci_warn(xhci, "Invalid slot_id %u\n", slot_id);
return NULL;
}
@@ -1804,7 +1804,7 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
struct xhci_command *cmd;
u32 cmd_type;
- if (slot_id >= MAX_HC_SLOTS) {
+ if (slot_id > xhci->max_slots) {
xhci_warn(xhci, "Invalid slot_id %u\n", slot_id);
return;
}
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 9d57def08ea6..cb80acac97d4 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -792,7 +792,8 @@ struct xhci_tt_bw_info {
/**
* struct xhci_device_context_array
- * @ctx_array: Pointer to an array of addresses
+ * @ctx_array: Pointer to an array of addresses. The array size depends on Max
+ * Slots read from HCSPARAMS1.
* @dma: DMA address to @ctx_array
*
* Device Context Base Address Array (DCBAA) - Section 6.1.
@@ -803,10 +804,6 @@ struct xhci_device_context_array {
__le64 *ctx_array;
dma_addr_t dma;
};
-/*
- * TODO: change this to be dynamically sized at HC mem init time since the HC
- * might not be able to handle the maximum number of devices possible.
- */
struct xhci_transfer_event {