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

ub: add alloc/free ucontext ops in ubcore



driver inclusion
category: feature
bugzilla: NA
CVE: NA

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

The UB Core invokes the UBN driver to
create a URMA context and set the uasid value.

Input parameter:
dev: UB device for creating the context.
eid: specifies an EID to create a context.
udrv_data: address of the private data exchanged
between the UBN user-mode driver and kernel-mode driver,
including the address of the urma context.

Signed-off-by: default avatarGuoxin Qian <qianguoxin@huawei.com>
Signed-off-by: default avatarYizhen Fan <fanyizhen@huawei.com>
parent 0b6bc5d2
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -425,6 +425,43 @@ void ubcore_unregister_device(struct ubcore_device *dev)
}
EXPORT_SYMBOL(ubcore_unregister_device);

struct ubcore_ucontext *ubcore_alloc_ucontext(struct ubcore_device *dev, uint32_t uasid,
					      struct ubcore_udrv_priv *udrv_data)
{
	struct ubcore_ucontext *ucontext;

	if (dev == NULL || dev->ops == NULL || dev->ops->alloc_ucontext == NULL) {
		ubcore_log_err("alloc_ucontext not registered.\n");
		return NULL;
	}
	ucontext = dev->ops->alloc_ucontext(dev, uasid, udrv_data);
	if (ucontext == NULL) {
		ubcore_log_err("failed to alloc ucontext.\n");
		return NULL;
	}
	ucontext->uasid = uasid;
	ucontext->ub_dev = dev;
	ubcore_log_info("success to alloc ucontext with uasid = %u", uasid);
	return ucontext;
}
EXPORT_SYMBOL(ubcore_alloc_ucontext);

void ubcore_free_ucontext(const struct ubcore_device *dev, struct ubcore_ucontext *ucontext)
{
	int ret;

	if (dev == NULL || ucontext == NULL || dev->ops == NULL ||
	    dev->ops->free_ucontext == NULL) {
		ubcore_log_err("Invalid argument.\n");
		return;
	}

	ret = dev->ops->free_ucontext(ucontext);
	if (ret != 0)
		ubcore_log_err("failed to free_adu, ret: %d.\n", ret);
}
EXPORT_SYMBOL(ubcore_free_ucontext);

int ubcore_set_eid(struct ubcore_device *dev, union ubcore_eid *eid)
{
	int ret;
+34 −0
Original line number Diff line number Diff line
@@ -66,6 +66,25 @@ union ubcore_eid {
	} in6;
};

struct ubcore_udrv_priv {
	uint64_t in_addr;
	uint32_t in_len;
	uint64_t out_addr;
	uint32_t out_len;
};

struct ubcore_ucontext {
	struct ubcore_device *ub_dev;
	uint32_t uasid;
	void *jfae; /* jfae uobj */
	atomic_t use_cnt;
};

struct ubcore_udata {
	struct ubcore_ucontext *uctx;
	struct ubcore_udrv_priv *udrv_data;
};

struct ubcore_device_attr {
	union ubcore_eid eid; // RW
	uint32_t max_eid_cnt;
@@ -188,6 +207,21 @@ struct ubcore_ops {
	 * @return: 0 on success, other value on error
	 */
	int (*unset_net_addr)(struct ubcore_device *dev, const struct ubcore_net_addr *net_addr);
	/**
	 * allocate a context from ubep for a user process
	 * @param[in] dev: the ub device handle;
	 * @param[in] uasid: uasid for the context to be allocated
	 * @param[in] udrv_data: user space driver data
	 * @return: pointer to user context on success, null or error,
	 */
	struct ubcore_ucontext *(*alloc_ucontext)(struct ubcore_device *dev, uint32_t uasid,
						  struct ubcore_udrv_priv *udrv_data);
	/**
	 * free a context to ubep
	 * @param[in] uctx: the user context created before;
	 * @return: 0 on success, other value on error
	 */
	int (*free_ucontext)(struct ubcore_ucontext *uctx);
	/**
	 * query_stats. success to query and buffer length is enough
	 * @param[in] dev: the ub device handle;
+19 −0
Original line number Diff line number Diff line
@@ -25,6 +25,25 @@

#include <urma/ubcore_types.h>

/**
 * Application specifies the device to allocate an context.
 * @param[in] dev: ubcore_device found by add ops in the client.
 * @param[in] uasid: (deprecated)
 * @param[in] udrv_data (optional): ucontext and user space driver data
 * @return: ubcore_ucontext pointer on success, NULL on fail.
 * Note: this API is called only by uburma representing user-space application,
 * not by other kernel modules
 */
struct ubcore_ucontext *ubcore_alloc_ucontext(struct ubcore_device *dev, uint32_t uasid,
					      struct ubcore_udrv_priv *udrv_data);
/**
 * Free the allocated context.
 * @param[in] dev: device to free context.
 * @param[in] ucontext: handle of the allocated context.
 * Note: this API is called only by uburma representing user-space application,
 * not by other kernel modules
 */
void ubcore_free_ucontext(const struct ubcore_device *dev, struct ubcore_ucontext *ucontext);
/**
 * set function entity id for ub device. must be called before alloc context
 * @param[in] dev: the ubcore_device handle;