Skip to content

Commit 220a0ff

Browse files
matnymangregkh
authored andcommitted
xhci: dbc: decouple endpoint allocation from initialization
Decouple allocation of endpoint ring buffer from initialization of the buffer, and initialization of endpoint context parts from from the rest of the contexts. It allows driver to clear up and reinitialize endpoint rings after disconnect without reallocating everything. This is a prerequisite for the next patch that prevents the transfer ring from filling up with cancelled (no-op) TRBs if a debug cable is reconnected several times without transferring anything. Cc: stable@vger.kernel.org Fixes: dfba217 ("usb: xhci: Add DbC support in xHCI driver") Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Link: https://lore.kernel.org/r/20250902105306.877476-2-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1b237f1 commit 220a0ff

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

drivers/usb/host/xhci-dbgcap.c

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,34 @@ static u32 xhci_dbc_populate_strings(struct dbc_str_descs *strings)
101101
return string_length;
102102
}
103103

104+
static void xhci_dbc_init_ep_contexts(struct xhci_dbc *dbc)
105+
{
106+
struct xhci_ep_ctx *ep_ctx;
107+
unsigned int max_burst;
108+
dma_addr_t deq;
109+
110+
max_burst = DBC_CTRL_MAXBURST(readl(&dbc->regs->control));
111+
112+
/* Populate bulk out endpoint context: */
113+
ep_ctx = dbc_bulkout_ctx(dbc);
114+
deq = dbc_bulkout_enq(dbc);
115+
ep_ctx->ep_info = 0;
116+
ep_ctx->ep_info2 = dbc_epctx_info2(BULK_OUT_EP, 1024, max_burst);
117+
ep_ctx->deq = cpu_to_le64(deq | dbc->ring_out->cycle_state);
118+
119+
/* Populate bulk in endpoint context: */
120+
ep_ctx = dbc_bulkin_ctx(dbc);
121+
deq = dbc_bulkin_enq(dbc);
122+
ep_ctx->ep_info = 0;
123+
ep_ctx->ep_info2 = dbc_epctx_info2(BULK_IN_EP, 1024, max_burst);
124+
ep_ctx->deq = cpu_to_le64(deq | dbc->ring_in->cycle_state);
125+
}
126+
104127
static void xhci_dbc_init_contexts(struct xhci_dbc *dbc, u32 string_length)
105128
{
106129
struct dbc_info_context *info;
107-
struct xhci_ep_ctx *ep_ctx;
108130
u32 dev_info;
109-
dma_addr_t deq, dma;
110-
unsigned int max_burst;
131+
dma_addr_t dma;
111132

112133
if (!dbc)
113134
return;
@@ -121,20 +142,8 @@ static void xhci_dbc_init_contexts(struct xhci_dbc *dbc, u32 string_length)
121142
info->serial = cpu_to_le64(dma + DBC_MAX_STRING_LENGTH * 3);
122143
info->length = cpu_to_le32(string_length);
123144

124-
/* Populate bulk out endpoint context: */
125-
ep_ctx = dbc_bulkout_ctx(dbc);
126-
max_burst = DBC_CTRL_MAXBURST(readl(&dbc->regs->control));
127-
deq = dbc_bulkout_enq(dbc);
128-
ep_ctx->ep_info = 0;
129-
ep_ctx->ep_info2 = dbc_epctx_info2(BULK_OUT_EP, 1024, max_burst);
130-
ep_ctx->deq = cpu_to_le64(deq | dbc->ring_out->cycle_state);
131-
132-
/* Populate bulk in endpoint context: */
133-
ep_ctx = dbc_bulkin_ctx(dbc);
134-
deq = dbc_bulkin_enq(dbc);
135-
ep_ctx->ep_info = 0;
136-
ep_ctx->ep_info2 = dbc_epctx_info2(BULK_IN_EP, 1024, max_burst);
137-
ep_ctx->deq = cpu_to_le64(deq | dbc->ring_in->cycle_state);
145+
/* Populate bulk in and out endpoint contexts: */
146+
xhci_dbc_init_ep_contexts(dbc);
138147

139148
/* Set DbC context and info registers: */
140149
lo_hi_writeq(dbc->ctx->dma, &dbc->regs->dccp);
@@ -436,6 +445,23 @@ dbc_alloc_ctx(struct device *dev, gfp_t flags)
436445
return ctx;
437446
}
438447

448+
static void xhci_dbc_ring_init(struct xhci_ring *ring)
449+
{
450+
struct xhci_segment *seg = ring->first_seg;
451+
452+
/* clear all trbs on ring in case of old ring */
453+
memset(seg->trbs, 0, TRB_SEGMENT_SIZE);
454+
455+
/* Only event ring does not use link TRB */
456+
if (ring->type != TYPE_EVENT) {
457+
union xhci_trb *trb = &seg->trbs[TRBS_PER_SEGMENT - 1];
458+
459+
trb->link.segment_ptr = cpu_to_le64(ring->first_seg->dma);
460+
trb->link.control = cpu_to_le32(LINK_TOGGLE | TRB_TYPE(TRB_LINK));
461+
}
462+
xhci_initialize_ring_info(ring);
463+
}
464+
439465
static struct xhci_ring *
440466
xhci_dbc_ring_alloc(struct device *dev, enum xhci_ring_type type, gfp_t flags)
441467
{
@@ -464,15 +490,10 @@ xhci_dbc_ring_alloc(struct device *dev, enum xhci_ring_type type, gfp_t flags)
464490

465491
seg->dma = dma;
466492

467-
/* Only event ring does not use link TRB */
468-
if (type != TYPE_EVENT) {
469-
union xhci_trb *trb = &seg->trbs[TRBS_PER_SEGMENT - 1];
470-
471-
trb->link.segment_ptr = cpu_to_le64(dma);
472-
trb->link.control = cpu_to_le32(LINK_TOGGLE | TRB_TYPE(TRB_LINK));
473-
}
474493
INIT_LIST_HEAD(&ring->td_list);
475-
xhci_initialize_ring_info(ring);
494+
495+
xhci_dbc_ring_init(ring);
496+
476497
return ring;
477498
dma_fail:
478499
kfree(seg);

0 commit comments

Comments
 (0)