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

ub: ubcore add alloc and free key id api.



driver inclusion
category: feature
bugzilla: NA
CVE: NA

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

Ubcore add alloc and free key id api, which will finally call hw driver's
registered method to alloc/free key id.

alloc_key_id:
The UB Core invokes the UBN driver to allocate the key ID.
Input parameter:
dev: specifies the key ID allocated to the UB device.
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.
Return value:
If the value is not NULL, the key ID is successfully allocated.
If the value is NULL, the key ID fails to be allocated.

free_key_id:
The UB Core invokes the UBN driver to release the key ID.
Input parameter:
key_id: ID of the key to be released specified by the
ubcore protocol stack.
Return value:
The value 0 indicates that the key ID is successfully released.
The value other than 0 indicates that the key ID fails to be released.

Signed-off-by: default avatarGuoxin Qian <qianguoxin@huawei.com>
Signed-off-by: default avatarYizhen Fan <fanyizhen@huawei.com>
parent 7139bde3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
ubcore-objs := ubcore_main.o \
			ubcore_device.o	\
			ubcore_jetty.o \
			ubcore_segment.o \
			ubcore_umem.o \
			ubcore_hash_table.o \
			ubcore_tp.o \
+64 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * Description: ubcore segment
 * Author: Qian Guoxin, Ouyang Changchun
 * Create: 2022-07-28
 * Note:
 * History: 2022-07-28: Yan Fangfang move segment implementation here
 */

#include "ubcore_log.h"
#include <urma/ubcore_uapi.h>
#include "ubcore_priv.h"
#include "ubcore_hash_table.h"
#include "ubcore_tp.h"
#include "ubcore_tp_table.h"

struct ubcore_key_id *ubcore_alloc_key_id(struct ubcore_device *dev, struct ubcore_udata *udata)
{
	struct ubcore_key_id *key;

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

	key = dev->ops->alloc_key_id(dev, udata);
	if (key == NULL) {
		ubcore_log_err("failed to alloc key id.\n");
		return NULL;
	}
	key->ub_dev = dev;
	key->uctx = ubcore_get_uctx(udata);
	atomic_set(&key->use_cnt, 0);
	return key;
}
EXPORT_SYMBOL(ubcore_alloc_key_id);

int ubcore_free_key_id(struct ubcore_key_id *key)
{
	struct ubcore_device *dev;

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

	if (WARN_ON_ONCE(atomic_read(&key->use_cnt)))
		return -EBUSY;

	return dev->ops->free_key_id(key);
}
EXPORT_SYMBOL(ubcore_free_key_id);
+13 −0
Original line number Diff line number Diff line
@@ -136,6 +136,19 @@ int ubcore_register_client(struct ubcore_client *new_client);
 * @param[in] rm_client: ubcore client to be unregistered
 */
void ubcore_unregister_client(struct ubcore_client *rm_client);
/**
 * alloc key to ubcore device
 * @param[in] dev: the ubcore device handle;
 * @param[in] udata (optional): ucontext and user space driver data
 * @return: key id pointer on success, NULL on error
 */
struct ubcore_key_id *ubcore_alloc_key_id(struct ubcore_device *dev, struct ubcore_udata *udata);
/**
 * free key id from ubcore device
 * @param[in] key: the key id alloced before;
 * @return: 0 on success, other value on error
 */
int ubcore_free_key_id(struct ubcore_key_id *key);
/**
 * create jfc with ubcore device.
 * @param[in] dev: the ubcore device handle;