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

ub: support set client ctx data in ubcore



driver inclusion
category: feature
bugzilla: NA
CVE: NA

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

Add ubcore_set_client_ctx_data api
which support set ubcore client ctx data.

Uburma use this api to set its device structure in ubcore ctx.

Signed-off-by: default avatarGuoxin Qian <qianguoxin@huawei.com>
Signed-off-by: default avatarYizhen Fan <fanyizhen@huawei.com>
parent 87455c98
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -46,6 +46,53 @@ static LIST_HEAD(g_device_list);
static DEFINE_MUTEX(g_device_mutex);
static DECLARE_RWSEM(g_lists_rwsem);

void ubcore_set_client_ctx_data(struct ubcore_device *dev, const struct ubcore_client *client,
				void *data)
{
	struct ubcore_client_ctx *ctx;
	unsigned long flags;

	spin_lock_irqsave(&dev->client_ctx_lock, flags);
	list_for_each_entry(ctx, &dev->client_ctx_list, list_node) {
		if (ctx->client == client) {
			ctx->data = data;
			goto out;
		}
	}
	ubcore_log_err("no client ctx found, device_name: %s, client_name: %s.\n", dev->dev_name,
		       client->client_name);

out:
	spin_unlock_irqrestore(&dev->client_ctx_lock, flags);
}
EXPORT_SYMBOL(ubcore_set_client_ctx_data);

void *ubcore_get_client_ctx_data(struct ubcore_device *dev, const struct ubcore_client *client)
{
	struct ubcore_client_ctx *found_ctx = NULL;
	struct ubcore_client_ctx *ctx, *tmp;
	unsigned long flags;

	spin_lock_irqsave(&dev->client_ctx_lock, flags);
	list_for_each_entry_safe(ctx, tmp, &dev->client_ctx_list, list_node) {
		if (ctx->client == client) {
			found_ctx = ctx;
			break;
		}
	}

	if (found_ctx == NULL) {
		spin_unlock_irqrestore(&dev->client_ctx_lock, flags);
		ubcore_log_warn("no client ctx found, dev_name: %s, client_name: %s.\n",
				dev->dev_name, client->client_name);
		return NULL;
	}
	spin_unlock_irqrestore(&dev->client_ctx_lock, flags);

	return found_ctx->data;
}
EXPORT_SYMBOL(ubcore_get_client_ctx_data);

static struct ubcore_client_ctx *create_client_ctx(struct ubcore_device *dev,
						   struct ubcore_client *client)
{
+1 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@ static int uburma_add_device(struct ubcore_device *ubc_dev)
		goto err;
	}

	ubcore_set_client_ctx_data(ubc_dev, &g_urma_client, ubu_dev);
	return 0;

err:
+16 −0
Original line number Diff line number Diff line
@@ -39,6 +39,22 @@ int ubcore_set_eid(struct ubcore_device *dev, union ubcore_eid *eid);
 * @return: 0 on success, other value on error
 */
int ubcore_query_device_attr(struct ubcore_device *dev, struct ubcore_device_attr *attr);
/**
 * set ctx data of a client
 * @param[in] dev: the ubcore_device handle;
 * @param[in] client: ubcore client pointer
 * @param[in] data: client private data to be set
 * @return: 0 on success, other value on error
 */
void ubcore_set_client_ctx_data(struct ubcore_device *dev, const struct ubcore_client *client,
				void *data);
/**
 * get ctx data of a client
 * @param[in] dev: the ubcore_device handle;
 * @param[in] client: ubcore client pointer
 * @return: client private data set before
 */
void *ubcore_get_client_ctx_data(struct ubcore_device *dev, const struct ubcore_client *client);
/**
 * Register a new client to ubcore
 * @param[in] dev: the ubcore_device handle;