Commit 8c4ed83b authored by Darek Stojaczyk's avatar Darek Stojaczyk Committed by Jim Harris
Browse files

vtophys: add length parameter to the vtophys function



This follows the same trend as the mem_map APIs.

Currently, most of the spdk_vtophys() callers manually
detect physically noncontiguous buffers to split them
into multiple physically contiguous chunks. This patch
is a first step towards encapsulating most of that logic
in a single place - in spdk_vtophys() itself.

This patch doesn't change any functionality on its own,
it only extends the API.

Change-Id: I16faa9dea270c370f2a814cd399f59055b5ccc3d
Signed-off-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/438449


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarwuzhouhui <wuzhouhui@kingsoft.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent daa3b8b2
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -574,11 +574,14 @@ size_t spdk_ring_dequeue(struct spdk_ring *ring, void **objs, size_t count);
 * Get the physical address of a buffer.
 *
 * \param buf A pointer to a buffer.
 * \param size Contains the size of the memory region pointed to by vaddr.
 * If vaddr is successfully translated, then this is updated with the size of
 * the memory region for which the translation is valid.
 *
 * \return the physical address of this buffer on success, or SPDK_VTOPHYS_ERROR
 * on failure.
 */
uint64_t spdk_vtophys(void *buf);
uint64_t spdk_vtophys(void *buf, uint64_t *size);

struct spdk_pci_addr {
	uint32_t			domain;
+3 −2
Original line number Diff line number Diff line
@@ -626,7 +626,7 @@ _crypto_operation(struct spdk_bdev_io *bdev_io, enum rte_crypto_cipher_operation

		/* Set the mbuf elements address and length. Null out the next pointer. */
		src_mbufs[crypto_index]->buf_addr = current_iov;
		src_mbufs[crypto_index]->buf_iova = spdk_vtophys((void *)current_iov);
		src_mbufs[crypto_index]->buf_iova = spdk_vtophys((void *)current_iov, NULL);
		src_mbufs[crypto_index]->data_len = crypto_len;
		src_mbufs[crypto_index]->next = NULL;
		/* Store context in every mbuf as we don't know anything about completion order */
@@ -659,7 +659,8 @@ _crypto_operation(struct spdk_bdev_io *bdev_io, enum rte_crypto_cipher_operation

			/* Set the relevant destination en_mbuf elements. */
			dst_mbufs[crypto_index]->buf_addr = io_ctx->cry_iov.iov_base + en_offset;
			dst_mbufs[crypto_index]->buf_iova = spdk_vtophys(dst_mbufs[crypto_index]->buf_addr);
			dst_mbufs[crypto_index]->buf_iova = spdk_vtophys(dst_mbufs[crypto_index]->buf_addr,
							    NULL);
			dst_mbufs[crypto_index]->data_len = crypto_len;
			crypto_ops[crypto_index]->sym->m_dst = dst_mbufs[crypto_index];
			en_offset += crypto_len;
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ virt_to_phys(void *vaddr)
	}
#endif

	return spdk_vtophys(vaddr);
	return spdk_vtophys(vaddr, NULL);
}

void *
+3 −4
Original line number Diff line number Diff line
@@ -624,13 +624,12 @@ spdk_vtophys_init(void)
}

uint64_t
spdk_vtophys(void *buf)
spdk_vtophys(void *buf, uint64_t *size)
{
	uint64_t vaddr, paddr_2mb;

	vaddr = (uint64_t)buf;

	paddr_2mb = spdk_mem_map_translate(g_vtophys_map, vaddr, NULL);
	paddr_2mb = spdk_mem_map_translate(g_vtophys_map, vaddr, size);

	/*
	 * SPDK_VTOPHYS_ERROR has all bits set, so if the lookup returned SPDK_VTOPHYS_ERROR,
@@ -642,7 +641,7 @@ spdk_vtophys(void *buf)
	if (paddr_2mb == SPDK_VTOPHYS_ERROR) {
		return SPDK_VTOPHYS_ERROR;
	} else {
		return paddr_2mb + ((uint64_t)buf & MASK_2MB);
		return paddr_2mb + (vaddr & MASK_2MB);
	}
}

+4 −4
Original line number Diff line number Diff line
@@ -432,7 +432,7 @@ ioat_channel_start(struct spdk_ioat_chan *ioat)
	}

	for (i = 0; i < num_descriptors; i++) {
		phys_addr = spdk_vtophys(&ioat->hw_ring[i]);
		phys_addr = spdk_vtophys(&ioat->hw_ring[i], NULL);
		if (phys_addr == SPDK_VTOPHYS_ERROR) {
			SPDK_ERRLOG("Failed to translate descriptor %u to physical address\n", i);
			return -1;
@@ -611,12 +611,12 @@ spdk_ioat_submit_copy(struct spdk_ioat_chan *ioat, void *cb_arg, spdk_ioat_req_c
	while (remaining) {
		if (_2MB_PAGE(vsrc) != vsrc_page) {
			vsrc_page = _2MB_PAGE(vsrc);
			psrc_page = spdk_vtophys((void *)vsrc_page);
			psrc_page = spdk_vtophys((void *)vsrc_page, NULL);
		}

		if (_2MB_PAGE(vdst) != vdst_page) {
			vdst_page = _2MB_PAGE(vdst);
			pdst_page = spdk_vtophys((void *)vdst_page);
			pdst_page = spdk_vtophys((void *)vdst_page, NULL);
		}
		op_size = remaining;
		op_size = spdk_min(op_size, (0x200000 - _2MB_OFFSET(vsrc)));
@@ -688,7 +688,7 @@ spdk_ioat_submit_fill(struct spdk_ioat_chan *ioat, void *cb_arg, spdk_ioat_req_c
		remaining -= op_size;

		last_desc = ioat_prep_fill(ioat,
					   spdk_vtophys((void *)vdst),
					   spdk_vtophys((void *)vdst, NULL),
					   fill_pattern,
					   op_size);

Loading