Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (C) 2022 Intel Corporation. 3 : : * All rights reserved. 4 : : */ 5 : : 6 : : #include "spdk/ftl.h" 7 : : #include "spdk/env.h" 8 : : 9 : : #include "ftl_io.h" 10 : : #include "ftl_core.h" 11 : : 12 : : struct ftl_rq * 13 : 531 : ftl_rq_new(struct spdk_ftl_dev *dev, uint32_t io_md_size) 14 : : { 15 : : struct ftl_rq *rq; 16 : : struct ftl_rq_entry *entry; 17 : 531 : void *io_payload, *io_md = NULL; 18 : : uint64_t i; 19 : : size_t size; 20 : 531 : uint32_t num_blocks = dev->xfer_size; 21 : : 22 : 531 : size = sizeof(*rq) + (sizeof(rq->entries[0]) * num_blocks); 23 : 531 : rq = calloc(1, size); 24 [ - + ]: 531 : if (!rq) { 25 : 0 : return NULL; 26 : : } 27 : 531 : rq->dev = dev; 28 : 531 : rq->num_blocks = num_blocks; 29 : : 30 : : /* Allocate payload for IO and IO vector */ 31 : 531 : io_payload = rq->io_payload = spdk_zmalloc(FTL_BLOCK_SIZE * num_blocks, 32 : : FTL_BLOCK_SIZE, NULL, SPDK_ENV_LCORE_ID_ANY, 33 : : SPDK_MALLOC_DMA); 34 [ - + ]: 531 : if (!io_payload) { 35 : 0 : goto error; 36 : : } 37 : : 38 : : /* Allocate extended metadata for IO */ 39 [ + + ]: 531 : if (io_md_size) { 40 : 178 : rq->io_md_size = io_md_size; 41 : 178 : io_md = rq->io_md = spdk_zmalloc(io_md_size * num_blocks, 42 : : FTL_BLOCK_SIZE, NULL, 43 : : SPDK_ENV_LCORE_ID_ANY, 44 : : SPDK_MALLOC_DMA); 45 [ - + ]: 178 : if (!io_md) { 46 : 0 : goto error; 47 : : } 48 : : } 49 : : 50 : 531 : entry = rq->entries; 51 [ + + ]: 136467 : for (i = 0; i < num_blocks; ++i) { 52 : 135936 : uint64_t *index = (uint64_t *)&entry->index; 53 : 135936 : *index = i; 54 : : 55 : 135936 : entry->addr = FTL_ADDR_INVALID; 56 : 135936 : entry->lba = FTL_LBA_INVALID; 57 : 135936 : entry->io_payload = io_payload; 58 : 135936 : entry->seq_id = 0; 59 : : 60 [ + + ]: 135936 : if (io_md_size) { 61 : 45568 : entry->io_md = io_md; 62 : : } 63 : : 64 : 135936 : entry++; 65 : 135936 : io_payload += FTL_BLOCK_SIZE; 66 : 135936 : io_md += io_md_size; 67 : : } 68 : : 69 : 531 : return rq; 70 : 0 : error: 71 : 0 : ftl_rq_del(rq); 72 : 0 : return NULL; 73 : : } 74 : : 75 : : void 76 : 1544 : ftl_rq_del(struct ftl_rq *rq) 77 : : { 78 [ + + ]: 1544 : if (!rq) { 79 : 1013 : return; 80 : : } 81 : : 82 : 531 : spdk_free(rq->io_payload); 83 : 531 : spdk_free(rq->io_md); 84 : : 85 : 531 : free(rq); 86 : : } 87 : : 88 : : void 89 : 0 : ftl_rq_unpin(struct ftl_rq *rq) 90 : : { 91 : : struct ftl_l2p_pin_ctx *pin_ctx; 92 : : uint64_t i; 93 : : 94 [ # # ]: 0 : for (i = 0; i < rq->iter.count; i++) { 95 : 0 : pin_ctx = &rq->entries[i].l2p_pin_ctx; 96 [ # # ]: 0 : if (pin_ctx->lba != FTL_LBA_INVALID) { 97 : 0 : ftl_l2p_unpin(rq->dev, pin_ctx->lba, pin_ctx->count); 98 : : } 99 : : } 100 : 0 : }