Lines Matching refs:ring
40 static int hnae_alloc_buffer(struct hnae_ring *ring, struct hnae_desc_cb *cb) in hnae_alloc_buffer() argument
42 unsigned int order = hnae_page_order(ring); in hnae_alloc_buffer()
52 cb->length = hnae_page_size(ring); in hnae_alloc_buffer()
58 static void hnae_free_buffer(struct hnae_ring *ring, struct hnae_desc_cb *cb) in hnae_free_buffer() argument
62 else if (unlikely(is_rx_ring(ring))) in hnae_free_buffer()
67 static int hnae_map_buffer(struct hnae_ring *ring, struct hnae_desc_cb *cb) in hnae_map_buffer() argument
69 cb->dma = dma_map_page(ring_to_dev(ring), cb->priv, 0, in hnae_map_buffer()
70 cb->length, ring_to_dma_dir(ring)); in hnae_map_buffer()
72 if (dma_mapping_error(ring_to_dev(ring), cb->dma)) in hnae_map_buffer()
78 static void hnae_unmap_buffer(struct hnae_ring *ring, struct hnae_desc_cb *cb) in hnae_unmap_buffer() argument
81 dma_unmap_single(ring_to_dev(ring), cb->dma, cb->length, in hnae_unmap_buffer()
82 ring_to_dma_dir(ring)); in hnae_unmap_buffer()
84 dma_unmap_page(ring_to_dev(ring), cb->dma, cb->length, in hnae_unmap_buffer()
85 ring_to_dma_dir(ring)); in hnae_unmap_buffer()
119 static void hnae_free_buffers(struct hnae_ring *ring) in hnae_free_buffers() argument
123 for (i = 0; i < ring->desc_num; i++) in hnae_free_buffers()
124 hnae_free_buffer_detach(ring, i); in hnae_free_buffers()
128 static int hnae_alloc_buffers(struct hnae_ring *ring) in hnae_alloc_buffers() argument
132 for (i = 0; i < ring->desc_num; i++) { in hnae_alloc_buffers()
133 ret = hnae_alloc_buffer_attach(ring, i); in hnae_alloc_buffers()
142 hnae_free_buffer_detach(ring, j); in hnae_alloc_buffers()
147 static void hnae_free_desc(struct hnae_ring *ring) in hnae_free_desc() argument
149 hnae_free_buffers(ring); in hnae_free_desc()
150 dma_unmap_single(ring_to_dev(ring), ring->desc_dma_addr, in hnae_free_desc()
151 ring->desc_num * sizeof(ring->desc[0]), in hnae_free_desc()
152 ring_to_dma_dir(ring)); in hnae_free_desc()
153 ring->desc_dma_addr = 0; in hnae_free_desc()
154 kfree(ring->desc); in hnae_free_desc()
155 ring->desc = NULL; in hnae_free_desc()
159 static int hnae_alloc_desc(struct hnae_ring *ring) in hnae_alloc_desc() argument
161 int size = ring->desc_num * sizeof(ring->desc[0]); in hnae_alloc_desc()
163 ring->desc = kzalloc(size, GFP_KERNEL); in hnae_alloc_desc()
164 if (!ring->desc) in hnae_alloc_desc()
167 ring->desc_dma_addr = dma_map_single(ring_to_dev(ring), in hnae_alloc_desc()
168 ring->desc, size, ring_to_dma_dir(ring)); in hnae_alloc_desc()
169 if (dma_mapping_error(ring_to_dev(ring), ring->desc_dma_addr)) { in hnae_alloc_desc()
170 ring->desc_dma_addr = 0; in hnae_alloc_desc()
171 kfree(ring->desc); in hnae_alloc_desc()
172 ring->desc = NULL; in hnae_alloc_desc()
180 static void hnae_fini_ring(struct hnae_ring *ring) in hnae_fini_ring() argument
182 hnae_free_desc(ring); in hnae_fini_ring()
183 kfree(ring->desc_cb); in hnae_fini_ring()
184 ring->desc_cb = NULL; in hnae_fini_ring()
185 ring->next_to_clean = 0; in hnae_fini_ring()
186 ring->next_to_use = 0; in hnae_fini_ring()
191 hnae_init_ring(struct hnae_queue *q, struct hnae_ring *ring, int flags) in hnae_init_ring() argument
195 if (ring->desc_num <= 0 || ring->buf_size <= 0) in hnae_init_ring()
198 ring->q = q; in hnae_init_ring()
199 ring->flags = flags; in hnae_init_ring()
200 assert(!ring->desc && !ring->desc_cb && !ring->desc_dma_addr); in hnae_init_ring()
203 assert(ring->next_to_use == 0); in hnae_init_ring()
204 assert(ring->next_to_clean == 0); in hnae_init_ring()
206 ring->desc_cb = kcalloc(ring->desc_num, sizeof(ring->desc_cb[0]), in hnae_init_ring()
208 if (!ring->desc_cb) { in hnae_init_ring()
213 ret = hnae_alloc_desc(ring); in hnae_init_ring()
217 if (is_rx_ring(ring)) { in hnae_init_ring()
218 ret = hnae_alloc_buffers(ring); in hnae_init_ring()
226 hnae_free_desc(ring); in hnae_init_ring()
228 kfree(ring->desc_cb); in hnae_init_ring()
229 ring->desc_cb = NULL; in hnae_init_ring()