Lines Matching full:ring
10 size_t mhi_ep_ring_addr2offset(struct mhi_ep_ring *ring, u64 ptr) in mhi_ep_ring_addr2offset() argument
12 return (ptr - ring->rbase) / sizeof(struct mhi_ring_element); in mhi_ep_ring_addr2offset()
15 static u32 mhi_ep_ring_num_elems(struct mhi_ep_ring *ring) in mhi_ep_ring_num_elems() argument
19 memcpy_fromio(&rlen, (void __iomem *) &ring->ring_ctx->generic.rlen, sizeof(u64)); in mhi_ep_ring_num_elems()
24 void mhi_ep_ring_inc_index(struct mhi_ep_ring *ring) in mhi_ep_ring_inc_index() argument
26 ring->rd_offset = (ring->rd_offset + 1) % ring->ring_size; in mhi_ep_ring_inc_index()
29 static int __mhi_ep_cache_ring(struct mhi_ep_ring *ring, size_t end) in __mhi_ep_cache_ring() argument
31 struct mhi_ep_cntrl *mhi_cntrl = ring->mhi_cntrl; in __mhi_ep_cache_ring()
37 /* Don't proceed in the case of event ring. This happens during mhi_ep_ring_start(). */ in __mhi_ep_cache_ring()
38 if (ring->type == RING_TYPE_ER) in __mhi_ep_cache_ring()
41 /* No need to cache the ring if write pointer is unmodified */ in __mhi_ep_cache_ring()
42 if (ring->wr_offset == end) in __mhi_ep_cache_ring()
45 start = ring->wr_offset; in __mhi_ep_cache_ring()
48 buf_info.host_addr = ring->rbase + (start * sizeof(struct mhi_ring_element)); in __mhi_ep_cache_ring()
49 buf_info.dev_addr = &ring->ring_cache[start]; in __mhi_ep_cache_ring()
55 buf_info.size = (ring->ring_size - start) * sizeof(struct mhi_ring_element); in __mhi_ep_cache_ring()
56 buf_info.host_addr = ring->rbase + (start * sizeof(struct mhi_ring_element)); in __mhi_ep_cache_ring()
57 buf_info.dev_addr = &ring->ring_cache[start]; in __mhi_ep_cache_ring()
64 buf_info.host_addr = ring->rbase; in __mhi_ep_cache_ring()
65 buf_info.dev_addr = &ring->ring_cache[0]; in __mhi_ep_cache_ring()
74 dev_dbg(dev, "Cached ring: start %zu end %zu size %zu\n", start, end, buf_info.size); in __mhi_ep_cache_ring()
79 static int mhi_ep_cache_ring(struct mhi_ep_ring *ring, u64 wr_ptr) in mhi_ep_cache_ring() argument
84 wr_offset = mhi_ep_ring_addr2offset(ring, wr_ptr); in mhi_ep_cache_ring()
86 /* Cache the host ring till write offset */ in mhi_ep_cache_ring()
87 ret = __mhi_ep_cache_ring(ring, wr_offset); in mhi_ep_cache_ring()
91 ring->wr_offset = wr_offset; in mhi_ep_cache_ring()
96 int mhi_ep_update_wr_offset(struct mhi_ep_ring *ring) in mhi_ep_update_wr_offset() argument
100 wr_ptr = mhi_ep_mmio_get_db(ring); in mhi_ep_update_wr_offset()
102 return mhi_ep_cache_ring(ring, wr_ptr); in mhi_ep_update_wr_offset()
105 /* TODO: Support for adding multiple ring elements to the ring */
106 int mhi_ep_ring_add_element(struct mhi_ep_ring *ring, struct mhi_ring_element *el) in mhi_ep_ring_add_element() argument
108 struct mhi_ep_cntrl *mhi_cntrl = ring->mhi_cntrl; in mhi_ep_ring_add_element()
116 ret = mhi_ep_update_wr_offset(ring); in mhi_ep_ring_add_element()
122 if (ring->rd_offset < ring->wr_offset) in mhi_ep_ring_add_element()
123 num_free_elem = (ring->wr_offset - ring->rd_offset) - 1; in mhi_ep_ring_add_element()
125 num_free_elem = ((ring->ring_size - ring->rd_offset) + ring->wr_offset) - 1; in mhi_ep_ring_add_element()
127 /* Check if there is space in ring for adding at least an element */ in mhi_ep_ring_add_element()
129 dev_err(dev, "No space left in the ring\n"); in mhi_ep_ring_add_element()
133 old_offset = ring->rd_offset; in mhi_ep_ring_add_element()
134 mhi_ep_ring_inc_index(ring); in mhi_ep_ring_add_element()
136 dev_dbg(dev, "Adding an element to ring at offset (%zu)\n", ring->rd_offset); in mhi_ep_ring_add_element()
138 /* Update rp in ring context */ in mhi_ep_ring_add_element()
139 rp = cpu_to_le64(ring->rd_offset * sizeof(*el) + ring->rbase); in mhi_ep_ring_add_element()
140 memcpy_toio((void __iomem *) &ring->ring_ctx->generic.rp, &rp, sizeof(u64)); in mhi_ep_ring_add_element()
142 buf_info.host_addr = ring->rbase + (old_offset * sizeof(*el)); in mhi_ep_ring_add_element()
149 void mhi_ep_ring_init(struct mhi_ep_ring *ring, enum mhi_ep_ring_type type, u32 id) in mhi_ep_ring_init() argument
151 ring->type = type; in mhi_ep_ring_init()
152 if (ring->type == RING_TYPE_CMD) { in mhi_ep_ring_init()
153 ring->db_offset_h = EP_CRDB_HIGHER; in mhi_ep_ring_init()
154 ring->db_offset_l = EP_CRDB_LOWER; in mhi_ep_ring_init()
155 } else if (ring->type == RING_TYPE_CH) { in mhi_ep_ring_init()
156 ring->db_offset_h = CHDB_HIGHER_n(id); in mhi_ep_ring_init()
157 ring->db_offset_l = CHDB_LOWER_n(id); in mhi_ep_ring_init()
158 ring->ch_id = id; in mhi_ep_ring_init()
160 ring->db_offset_h = ERDB_HIGHER_n(id); in mhi_ep_ring_init()
161 ring->db_offset_l = ERDB_LOWER_n(id); in mhi_ep_ring_init()
165 int mhi_ep_ring_start(struct mhi_ep_cntrl *mhi_cntrl, struct mhi_ep_ring *ring, in mhi_ep_ring_start() argument
172 ring->mhi_cntrl = mhi_cntrl; in mhi_ep_ring_start()
173 ring->ring_ctx = ctx; in mhi_ep_ring_start()
174 ring->ring_size = mhi_ep_ring_num_elems(ring); in mhi_ep_ring_start()
175 memcpy_fromio(&val, (void __iomem *) &ring->ring_ctx->generic.rbase, sizeof(u64)); in mhi_ep_ring_start()
176 ring->rbase = le64_to_cpu(val); in mhi_ep_ring_start()
178 if (ring->type == RING_TYPE_CH) in mhi_ep_ring_start()
179 ring->er_index = le32_to_cpu(ring->ring_ctx->ch.erindex); in mhi_ep_ring_start()
181 if (ring->type == RING_TYPE_ER) in mhi_ep_ring_start()
182 ring->irq_vector = le32_to_cpu(ring->ring_ctx->ev.msivec); in mhi_ep_ring_start()
184 /* During ring init, both rp and wp are equal */ in mhi_ep_ring_start()
185 memcpy_fromio(&val, (void __iomem *) &ring->ring_ctx->generic.rp, sizeof(u64)); in mhi_ep_ring_start()
186 ring->rd_offset = mhi_ep_ring_addr2offset(ring, le64_to_cpu(val)); in mhi_ep_ring_start()
187 ring->wr_offset = mhi_ep_ring_addr2offset(ring, le64_to_cpu(val)); in mhi_ep_ring_start()
189 /* Allocate ring cache memory for holding the copy of host ring */ in mhi_ep_ring_start()
190 ring->ring_cache = kcalloc(ring->ring_size, sizeof(struct mhi_ring_element), GFP_KERNEL); in mhi_ep_ring_start()
191 if (!ring->ring_cache) in mhi_ep_ring_start()
194 memcpy_fromio(&val, (void __iomem *) &ring->ring_ctx->generic.wp, sizeof(u64)); in mhi_ep_ring_start()
195 ret = mhi_ep_cache_ring(ring, le64_to_cpu(val)); in mhi_ep_ring_start()
197 dev_err(dev, "Failed to cache ring\n"); in mhi_ep_ring_start()
198 kfree(ring->ring_cache); in mhi_ep_ring_start()
202 ring->started = true; in mhi_ep_ring_start()
207 void mhi_ep_ring_reset(struct mhi_ep_cntrl *mhi_cntrl, struct mhi_ep_ring *ring) in mhi_ep_ring_reset() argument
209 ring->started = false; in mhi_ep_ring_reset()
210 kfree(ring->ring_cache); in mhi_ep_ring_reset()
211 ring->ring_cache = NULL; in mhi_ep_ring_reset()