| 234 | } |
| 235 | |
| 236 | static int dma_afu_buf_alloc(struct dma_afu_ctx *ctx, |
| 237 | struct rte_pmd_afu_dma_cfg *cfg) |
| 238 | { |
| 239 | size_t page_sz = sysconf(_SC_PAGE_SIZE); |
| 240 | int i, ret = 0; |
| 241 | |
| 242 | if (!ctx || !cfg) |
| 243 | return -EINVAL; |
| 244 | |
| 245 | for (i = 0; i < NUM_DMA_BUF; i++) { |
| 246 | ctx->dma_buf[i] = (uint64_t *)rte_zmalloc(NULL, cfg->size, |
| 247 | TEST_MEM_ALIGN); |
| 248 | if (!ctx->dma_buf[i]) { |
| 249 | ret = -ENOMEM; |
| 250 | goto free_dma_buf; |
| 251 | } |
| 252 | ctx->dma_iova[i] = rte_malloc_virt2iova(ctx->dma_buf[i]); |
| 253 | if (ctx->dma_iova[i] == RTE_BAD_IOVA) { |
| 254 | ret = -ENOMEM; |
| 255 | goto free_dma_buf; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | ctx->data_buf = rte_malloc(NULL, cfg->length, page_sz); |
| 260 | if (!ctx->data_buf) { |
| 261 | ret = -ENOMEM; |
| 262 | goto free_dma_buf; |
| 263 | } |
| 264 | |
| 265 | ctx->ref_buf = rte_malloc(NULL, cfg->length, page_sz); |
| 266 | if (!ctx->ref_buf) { |
| 267 | ret = -ENOMEM; |
| 268 | goto free_data_buf; |
| 269 | } |
| 270 | |
| 271 | return 0; |
| 272 | |
| 273 | free_data_buf: |
| 274 | rte_free(ctx->data_buf); |
| 275 | ctx->data_buf = NULL; |
| 276 | free_dma_buf: |
| 277 | for (i = 0; i < NUM_DMA_BUF; i++) { |
| 278 | rte_free(ctx->dma_buf[i]); |
| 279 | ctx->dma_buf[i] = NULL; |
| 280 | } |
| 281 | return ret; |
| 282 | } |
| 283 | |
| 284 | static void dma_afu_buf_init(struct dma_afu_ctx *ctx, size_t size) |
| 285 | { |
no test coverage detected