Lines Matching defs:ring
23 * Allocates a generic ring segment from the ring pool, sets the dma address,
124 * Link the ring to the new segments.
125 * Set Toggle Cycle for the new ring if needed.
127 static void xhci_link_rings(struct xhci_hcd *xhci, struct xhci_ring *ring,
134 if (!ring || !first || !last)
139 (ring->type == TYPE_ISOC &&
142 next = ring->enq_seg->next;
143 xhci_link_segments(ring->enq_seg, first, ring->type, chain_links);
144 xhci_link_segments(last, next, ring->type, chain_links);
145 ring->num_segs += num_segs;
147 if (ring->type != TYPE_EVENT && ring->enq_seg == ring->last_seg) {
148 ring->last_seg->trbs[TRBS_PER_SEGMENT-1].link.control
152 ring->last_seg = last;
159 * us which stream ring the TRB came from. We could store the stream ID in an
163 * The radix tree maps the upper portion of the TRB DMA address to a ring
175 * will make the radix tree return the stream ID for that ring.
188 struct xhci_ring *ring,
204 key, ring);
221 struct xhci_ring *ring,
236 ring, seg, mem_flags);
259 static void xhci_remove_stream_mapping(struct xhci_ring *ring)
263 if (WARN_ON_ONCE(ring->trb_address_map == NULL))
266 seg = ring->first_seg;
268 xhci_remove_segment_mapping(ring->trb_address_map, seg);
270 } while (seg != ring->first_seg);
273 static int xhci_update_stream_mapping(struct xhci_ring *ring, gfp_t mem_flags)
275 return xhci_update_stream_segment_mapping(ring->trb_address_map, ring,
276 ring->first_seg, ring->last_seg, mem_flags);
280 void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring)
282 if (!ring)
285 trace_xhci_ring_free(ring);
287 if (ring->first_seg) {
288 if (ring->type == TYPE_STREAM)
289 xhci_remove_stream_mapping(ring);
290 xhci_free_segments_for_ring(xhci, ring->first_seg);
293 kfree(ring);
296 void xhci_initialize_ring_info(struct xhci_ring *ring,
299 /* The ring is empty, so the enqueue pointer == dequeue pointer */
300 ring->enqueue = ring->first_seg->trbs;
301 ring->enq_seg = ring->first_seg;
302 ring->dequeue = ring->enqueue;
303 ring->deq_seg = ring->first_seg;
304 /* The ring is initialized to 0. The producer must write 1 to the cycle
309 * handling ring expansion, set the cycle state equal to the old ring.
311 ring->cycle_state = cycle_state;
317 ring->num_trbs_free = ring->num_segs * (TRBS_PER_SEGMENT - 1) - 1;
320 /* Allocate segments and link them for a ring */
365 * Create a new ring with zero or more segments.
367 * Link each segment together into a ring.
375 struct xhci_ring *ring;
379 ring = kzalloc_node(sizeof(*ring), flags, dev_to_node(dev));
380 if (!ring)
383 ring->num_segs = num_segs;
384 ring->bounce_buf_len = max_packet;
385 INIT_LIST_HEAD(&ring->td_list);
386 ring->type = type;
388 return ring;
390 ret = xhci_alloc_segments_for_ring(xhci, &ring->first_seg,
391 &ring->last_seg, num_segs, cycle_state, type,
396 /* Only event ring does not use link TRB */
399 ring->last_seg->trbs[TRBS_PER_SEGMENT - 1].link.control |=
402 xhci_initialize_ring_info(ring, cycle_state);
403 trace_xhci_ring_alloc(ring);
404 return ring;
407 kfree(ring);
415 xhci_ring_free(xhci, virt_dev->eps[ep_index].ring);
416 virt_dev->eps[ep_index].ring = NULL;
420 * Expand an existing ring.
421 * Allocate a new ring which has same segment numbers and link the two rings.
423 int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
431 num_new_segs, ring->cycle_state, ring->type,
432 ring->bounce_buf_len, flags);
436 if (ring->type == TYPE_STREAM)
437 ret = xhci_update_stream_segment_mapping(ring->trb_address_map,
438 ring, first, last, flags);
451 xhci_link_rings(xhci, ring, first, last, num_new_segs);
452 trace_xhci_ring_expansion(ring);
454 "ring expansion succeed, now has %d segments",
455 ring->num_segs);
577 return ep->ring;
604 xhci_dbg(xhci, "Command ring has no reserved TRBs available\n");
659 xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n", cur_stream, addr);
668 /* Leave the other unused stream ring pointers in the stream context
671 * was any other way, the host controller would assume the ring is
724 * Reinstalls the "normal" endpoint ring (at its previous dequeue mark,
725 * not at the beginning of the ring).
732 addr = xhci_trb_virt_to_dma(ep->ring->deq_seg, ep->ring->dequeue);
733 ep_ctx->deq = cpu_to_le64(addr | ep->ring->cycle_state);
842 /* All the xhci_tds in the ring's TD list should be freed at this point.
869 if (dev->eps[i].ring)
870 xhci_ring_free(xhci, dev->eps[i].ring);
987 /* Allocate endpoint 0 ring */
988 dev->eps[0].ring = xhci_ring_alloc(xhci, 2, 1, TYPE_CTRL, 0, flags);
989 if (!dev->eps[0].ring)
1026 ep_ring = virt_dev->eps[0].ring;
1169 /* Step 4 - ring already allocated */
1177 ep0_ctx->deq = cpu_to_le64(dev->eps[0].ring->first_seg->dma |
1178 dev->eps[0].ring->cycle_state);
1391 /* Set up an endpoint with one ring segment. Do not allocate stream rings.
1467 /* Set up the endpoint ring */
1507 /* Don't free the endpoint ring until the set interface or configuration
1832 /* free interrrupter event ring */
1849 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed primary event ring");
1854 xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Freed command ring");
1942 xhci_warn(xhci, "WARN something wrong with SW event ring dequeue ptr.\n");
1943 /* Update HC event ring dequeue pointer */
1951 "// Write event ring dequeue pointer, preserving EHB bit");
2250 xhci_warn(xhci, "Failed to allocate interrupter event ring\n");
2292 /* Set the event ring dequeue address of this interrupter */
2356 * Initialize the ring segment pool. The ring must be a contiguous
2358 * however, the command ring segment needs 64-byte aligned segments
2363 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev,
2366 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev,
2391 /* Set up the command ring to have one segments for now. */
2396 "Allocated command ring at %p", xhci->cmd_ring);
2406 "// Setting command ring address to 0x%016llx", val_64);
2409 /* Reserve one command ring TRB for disabling LPM.
2422 /* Allocate and set up primary interrupter 0 with an event ring. */
2424 "Allocating primary event ring");