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

ub: ubcore add segment type and api definition



driver inclusion
category: feature
bugzilla: NA
CVE: NA

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

Ubcore add segment type and api definition. Api will be implemented by
drivers.

** Introduce of segment and UBVA: **

When the URMA is used as the shared memory of the home node,
a shared address needs to be created for the shared memory so that
the user node can use the address to access the URMA.
The address is called UBVA.

UBVA: The unified bus virtual address (UBVA) is a hierarchical
virtual address on the UBUS bus. It supports unified addressing of
the shared memory of multiple nodes on the bus, breaking the address
boundary of each node and allowing applications to perform cross-node
addressing and data access through the VA. It consists of the EID/CID,
UASID, and VA address.

Segment: A segment is a continuous VA address space, and physical memory
is allocated to a segment. Created by the segment home node.
The app maps the segment to the process virtual address space and
directly accesses the remote memory through the mapped address.
The VA address of a segment can be the same as or different from the VA
mapped by the user process. Scenarios where the VA IP addresses
are the same, that is, the DSVA scenario.

Signed-off-by: default avatarGuoxin Qian <qianguoxin@huawei.com>
Signed-off-by: default avatarYizhen Fan <fanyizhen@huawei.com>
parent efbc8407
Loading
Loading
Loading
Loading
+135 −0
Original line number Diff line number Diff line
@@ -72,6 +72,12 @@ struct ubcore_jetty_id {
	uint32_t id;
};

struct ubcore_ubva {
	union ubcore_eid eid;
	uint32_t uasid;
	uint64_t va;
} __packed;

struct ubcore_ht_param {
	uint32_t size;
	uint32_t node_offset; /* offset of hlist node in the hash table object */
@@ -169,6 +175,29 @@ struct ubcore_jetty_attr {
	enum ubcore_jetty_state state;
};

union ubcore_import_seg_flag {
	struct {
		uint32_t cacheable : 1;
		uint32_t access : 6;
		uint32_t mapping : 1;
		uint32_t reserved : 24;
	} bs;
	uint32_t value;
};

union ubcore_reg_seg_flag {
	struct {
		uint32_t key_policy : 3;
		uint32_t cacheable : 1;
		uint32_t dsva : 1;
		uint32_t access : 6;
		uint32_t non_pin : 1;
		uint32_t user_iova : 1;
		uint32_t reserved : 19;
	} bs;
	uint32_t value;
};

struct ubcore_udrv_priv {
	uint64_t in_addr;
	uint32_t in_len;
@@ -370,6 +399,58 @@ struct ubcore_jetty {
	struct ubcore_hash_table *tptable; /* Only for devices not natively supporting RM mode */
};

struct ubcore_key_id {
	struct ubcore_device *ub_dev;
	struct ubcore_ucontext *uctx;
	uint32_t key_id;
	atomic_t use_cnt;
};

struct ubcore_seg_cfg {
	uint64_t va;
	uint64_t len;
	struct ubcore_key_id *keyid;
	struct ubcore_key ukey;
	union ubcore_reg_seg_flag flag;
	uint64_t iova;
};

union ubcore_seg_attr {
	struct {
		uint32_t key_policy : 3;
		uint32_t cacheable : 1;
		uint32_t dsva : 1;
		uint32_t access : 6;
		uint32_t non_pin : 1;
		uint32_t user_iova : 1;
		uint32_t reserved : 19;
	} bs;
	uint32_t value;
};

struct ubcore_seg {
	struct ubcore_ubva ubva;
	uint64_t len;
	union ubcore_seg_attr attr;
	uint32_t key_id;
};

struct ubcore_target_seg_cfg {
	struct ubcore_seg seg;
	union ubcore_import_seg_flag flag;
	uint64_t mva; /* optional */
	struct ubcore_key ukey;
};

struct ubcore_target_seg {
	struct ubcore_device *ub_dev;
	struct ubcore_ucontext *uctx;
	struct ubcore_seg seg;
	uint64_t mva;
	struct ubcore_key_id *keyid;
	atomic_t use_cnt;
};

enum ubcore_mtu {
	UBCORE_MTU_256 = 1,
	UBCORE_MTU_512,
@@ -654,6 +735,60 @@ struct ubcore_ops {
	 * @return: 0 on success, other value on error
	 */
	int (*free_ucontext)(struct ubcore_ucontext *uctx);
	/**
	 * mmap doorbell or jetty buffer, etc
	 * @param[in] uctx: the user context created before;
	 * @param[in] vma: linux vma including vm_start, vm_pgoff, etc;
	 * @return: 0 on success, other value on error
	 */
	int (*mmap)(struct ubcore_ucontext *ctx, struct vm_area_struct *vma);

	/* segment part */
	/** alloc key id to ubep
	 * @param[in] dev: the ub device handle;
	 * @param[in] udata: ucontext and user space driver data
	 * @return: key id pointer on success, NULL on error
	 */
	struct ubcore_key_id *(*alloc_key_id)(struct ubcore_device *dev,
					      struct ubcore_udata *udata);

	/** free key id from ubep
	 * @param[in] key_id: the key id alloced before;
	 * @return: 0 on success, other value on error
	 */
	int (*free_key_id)(struct ubcore_key_id *key_id);

	/** register segment to ubep
	 * @param[in] dev: the ub device handle;
	 * @param[in] cfg: segment attributes and configurations
	 * @param[in] udata: ucontext and user space driver data
	 * @return: target segment pointer on success, NULL on error
	 */
	struct ubcore_target_seg *(*register_seg)(struct ubcore_device *dev,
						  const struct ubcore_seg_cfg *cfg,
						  struct ubcore_udata *udata);

	/** unregister segment from ubep
	 * @param[in] tseg: the segment registered before;
	 * @return: 0 on success, other value on error
	 */
	int (*unregister_seg)(struct ubcore_target_seg *tseg);

	/** import a remote segment to ubep
	 * @param[in] dev: the ub device handle;
	 * @param[in] cfg: segment attributes and import configurations
	 * @param[in] udata: ucontext and user space driver data
	 * @return: target segment handle on success, NULL on error
	 */
	struct ubcore_target_seg *(*import_seg)(struct ubcore_device *dev,
						const struct ubcore_target_seg_cfg *cfg,
						struct ubcore_udata *udata);

	/** unimport seg from ubep
	 * @param[in] tseg: the segment imported before;
	 * @return: 0 on success, other value on error
	 */
	int (*unimport_seg)(struct ubcore_target_seg *tseg);

	/* jetty part */
	/**