Commit a9b4d53a authored by Yizhen Fan's avatar Yizhen Fan Committed by fanyizhen1995
Browse files

ub: ubcore add import/unimport seg api.



driver inclusion
category: feature
bugzilla: NA
CVE: NA

--------------------------------

Ubcore add import/unimport seg api, which will finally call hw driver's
registered method import/unimport seg.

import_seg:
The UB Core invokes the UBN driver to import segments and keys.
Input parameter:
dev: UB device to which the remote segment is imported.
cfg: specifies the basic information about the remote segment to be
imported by the ubcore protocol stack.
udata: contains the pointer of the URMA context and the address of the
private data exchanged between the UBN user-mode driver and kernel-mode
driver.
Output parameter:
None.
Return value:
If the import is successful, the target segment structure pointer
is returned. The returned information includes the segment address and
length. The import fails and NULL is returned.

unimport_seg:
The UB Core invokes the UBN driver to unimport the remote segment and key.
Input parameter:
tseg: pointer to the target segment
Return value:
The value 0 indicates that the unimport is successful.
Other values indicate that the unimport fails.

Signed-off-by: default avatarGuoxin Qian <qianguoxin@huawei.com>
Signed-off-by: default avatarYizhen Fan <fanyizhen@huawei.com>
parent 25407e00
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -122,3 +122,43 @@ int ubcore_unregister_seg(struct ubcore_target_seg *tseg)
	return ret;
}
EXPORT_SYMBOL(ubcore_unregister_seg);

struct ubcore_target_seg *ubcore_import_seg(struct ubcore_device *dev,
					    const struct ubcore_target_seg_cfg *cfg,
					    struct ubcore_udata *udata)
{
	struct ubcore_target_seg *tseg;

	if (dev == NULL || cfg == NULL || dev->ops->import_seg == NULL ||
	    dev->ops->unimport_seg == NULL) {
		ubcore_log_err("invalid parameter.\n");
		return NULL;
	}

	tseg = dev->ops->import_seg(dev, cfg, udata);
	if (tseg == NULL) {
		ubcore_log_err("UBEP failed to import segment with va:%llu\n", cfg->seg.ubva.va);
		return NULL;
	}
	tseg->ub_dev = dev;
	tseg->uctx = ubcore_get_uctx(udata);
	tseg->seg = cfg->seg;
	atomic_set(&tseg->use_cnt, 0);

	return tseg;
}
EXPORT_SYMBOL(ubcore_import_seg);

int ubcore_unimport_seg(struct ubcore_target_seg *tseg)
{
	struct ubcore_device *dev;

	if (tseg == NULL || tseg->ub_dev == NULL || tseg->ub_dev->ops->unimport_seg == NULL) {
		ubcore_log_err("invalid parameter.\n");
		return -1;
	}
	dev = tseg->ub_dev;

	return dev->ops->unimport_seg(tseg);
}
EXPORT_SYMBOL(ubcore_unimport_seg);
+16 −0
Original line number Diff line number Diff line
@@ -165,6 +165,22 @@ struct ubcore_target_seg *ubcore_register_seg(struct ubcore_device *dev,
 * @return: 0 on success, other value on error
 */
int ubcore_unregister_seg(struct ubcore_target_seg *tseg);
/**
 * import a remote segment to ubcore device
 * @param[in] dev: the ubcore device handle;
 * @param[in] cfg: import configurations
 * @param[in] udata (optional): ucontext and user space driver data
 * @return: target segment handle on success, NULL on error
 */
struct ubcore_target_seg *ubcore_import_seg(struct ubcore_device *dev,
					    const struct ubcore_target_seg_cfg *cfg,
					    struct ubcore_udata *udata);
/**
 * unimport seg from ubcore device
 * @param[in] tseg: the segment imported before;
 * @return: 0 on success, other value on error
 */
int ubcore_unimport_seg(struct ubcore_target_seg *tseg);
/**
 * create jfc with ubcore device.
 * @param[in] dev: the ubcore device handle;