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

ub: ubcore add get_mtu and other APIs that will be used by the driver.



driver inclusion
category: feature
bugzilla: NA
CVE: NA

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

Ubcore add ubcore_get_mtu() support drivers to invoke to get mtu value.

Ubcore add other api definition (just def of api and data structure)
used by drivers:
- ubcore_create_vtp
- ubcore_destroy_vtp

Add definition of ubcore_tp:

Introduce to tp, tpg, ta:

TP: As defined in the UB protocol,
the transport layer is established between two UB ports
to provide reliability, congestion control, and multiplexing.

TPG: A transport group is established between two nodes and
contains several TPs. It fully utilizes the transmission capability of
all TPs in the TPG to implement multipathing.

TA: transaction layer in the UB protocol. It provides flexible
definitions for the TA model and supports weak transaction sequences.

Signed-off-by: default avatarGuoxin Qian <qianguoxin@huawei.com>
Signed-off-by: default avatarYizhen Fan <fanyizhen@huawei.com>
parent ba51fa59
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_umem.o \
			ubcore_tp.o \
			ubcore_netlink.o

obj-$(CONFIG_UB) += ubcore.o
+69 −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 tp implementation
 * Author: Yan Fangfang
 * Create: 2022-08-25
 * Note:
 * History: 2022-08-25: Create file
 */

#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/random.h>
#include <linux/netdevice.h>
#include <urma/ubcore_api.h>
#include <urma/ubcore_uapi.h>

#define UB_PROTOCOL_HEAD_BYTES 313
#define UB_MTU_BITS_BASE_SHIFT 7

static inline int ubcore_mtu_enum_to_int(enum ubcore_mtu mtu)
{
	return 1 << ((int)mtu + UB_MTU_BITS_BASE_SHIFT);
}

enum ubcore_mtu ubcore_get_mtu(int mtu)
{
	mtu = mtu - UB_PROTOCOL_HEAD_BYTES;

	if (mtu >= ubcore_mtu_enum_to_int(UBCORE_MTU_8192))
		return UBCORE_MTU_8192;
	if (mtu >= ubcore_mtu_enum_to_int(UBCORE_MTU_4096))
		return UBCORE_MTU_4096;
	else if (mtu >= ubcore_mtu_enum_to_int(UBCORE_MTU_2048))
		return UBCORE_MTU_2048;
	else if (mtu >= ubcore_mtu_enum_to_int(UBCORE_MTU_1024))
		return UBCORE_MTU_1024;
	else if (mtu >= ubcore_mtu_enum_to_int(UBCORE_MTU_512))
		return UBCORE_MTU_512;
	else if (mtu >= ubcore_mtu_enum_to_int(UBCORE_MTU_256))
		return UBCORE_MTU_256;
	else
		return 0;
}
EXPORT_SYMBOL(ubcore_get_mtu);

struct ubcore_tp *ubcore_create_vtp(struct ubcore_device *dev, const union ubcore_eid *remote_eid,
				    enum ubcore_transport_mode trans_mode,
				    struct ubcore_udata *udata)
{
	return NULL;
}
EXPORT_SYMBOL(ubcore_create_vtp);

int ubcore_destroy_vtp(struct ubcore_tp *vtp)
{
	return -1;
}
EXPORT_SYMBOL(ubcore_destroy_vtp);
+28 −0
Original line number Diff line number Diff line
@@ -51,4 +51,32 @@ struct ubcore_umem *ubcore_umem_get(struct ubcore_device *dev, uint64_t va, uint
 */
void ubcore_umem_release(struct ubcore_umem *umem);

/**
 * Invoke create virtual tp on a PF device, called only by driver
 * @param[in] dev: the ubcore device;
 * @param[in] remote_eid: destination remote eid address of the tp to be created
 * @param[in] trans_mode: transport mode of the tp to be created
 * @param[in] udata: driver defined data
 * @return: tp pointer on success, NULL on error
 */
struct ubcore_tp *ubcore_create_vtp(struct ubcore_device *dev,
				    const union ubcore_eid *remote_eid,
				    enum ubcore_transport_mode trans_mode,
				    struct ubcore_udata *udata);

/**
 * Invoke destroy virtual tp from a PF device, called only by driver
 * @param[in] tp: the tp to be destroyed
 * @return: 0 on success, other value on error
 */
int ubcore_destroy_vtp(struct ubcore_tp *vtp);

/**
 * Invoke get mtu value, called only by driver
 * @param[in] mtu: specifies the MTU value of the NIC interface.
 * @return: The MTU of the UB protocol, this value removes the length of the network layer,
 * transport layer, transaction layer header and ICRC.
 */
enum ubcore_mtu ubcore_get_mtu(int mtu);

#endif
+160 −0
Original line number Diff line number Diff line
@@ -66,6 +66,12 @@ union ubcore_eid {
	} in6;
};

struct ubcore_jetty_id {
	union ubcore_eid eid;
	uint32_t uasid;
	uint32_t id;
};

struct ubcore_udrv_priv {
	uint64_t in_addr;
	uint32_t in_len;
@@ -85,6 +91,22 @@ struct ubcore_udata {
	struct ubcore_udrv_priv *udrv_data;
};

/* transport mode */
enum ubcore_transport_mode {
	UBCORE_TP_RM = 0x1, /* Reliable message */
	UBCORE_TP_RC = 0x1 << 1, /* Reliable connection */
	UBCORE_TP_UM = 0x1 << 2 /* Unreliable message */
};

enum ubcore_mtu {
	UBCORE_MTU_256 = 1,
	UBCORE_MTU_512,
	UBCORE_MTU_1024,
	UBCORE_MTU_2048,
	UBCORE_MTU_4096,
	UBCORE_MTU_8192
};

struct ubcore_device_attr {
	union ubcore_eid eid; // RW
	uint32_t max_eid_cnt;
@@ -133,6 +155,144 @@ struct ubcore_net_addr {
	uint8_t mac[UBCORE_MAC_BYTES]; /* available for UBOE */
};

union ubcore_tp_cfg_flag {
	struct {
		uint32_t target : 1; /* 0: initiator, 1: target */
		uint32_t oor_en : 1; /* out of order receive, 0: disable 1: enable */
		uint32_t sr_en : 1; /* selective retransmission, 0: disable 1: enable */
		uint32_t cc_en : 1; /* congestion control algorithm, 0: disable 1: enable */
		uint32_t spray_en : 1; /* spray with src udp port, 0: disable 1: enable */
		uint32_t reserved : 27;
	} bs;
	uint32_t value;
};

union ubcore_tp_mod_flag {
	struct {
		uint32_t oor_en : 1; /* out of order receive, 0: disable 1: enable */
		uint32_t sr_en : 1; /* selective retransmission, 0: disable 1: enable */
		uint32_t cc_en : 1; /* congestion control algorithm, 0: disable 1: enable */
		uint32_t cc_alg : 4; /* The value is enum ubcore_tp_cc_alg */
		uint32_t spray_en : 1; /* spray with src udp port, 0: disable 1: enable */
		uint32_t reserved : 24;
	} bs;
	uint32_t value;
};

/* The first bits must be consistent with union ubcore_tp_cfg_flag */
union ubcore_tp_flag {
	struct {
		uint32_t target : 1; /* 0: initiator, 1: target */
		uint32_t oor_en : 1; /* out of order receive, 0: disable 1: enable */
		uint32_t sr_en : 1; /* selective retransmission, 0: disable 1: enable */
		uint32_t cc_en : 1; /* congestion control algorithm, 0: disable 1: enable */
		uint32_t cc_alg : 4; /* The value is enum ubcore_tp_cc_alg */
		uint32_t spray_en : 1; /* spray with src udp port, 0: disable 1: enable */
		uint32_t reserved : 23;
	} bs;
	uint32_t value;
};

enum ubcore_tp_state {
	UBCORE_TP_STATE_RESET = 0,
	UBCORE_TP_STATE_RTR,
	UBCORE_TP_STATE_RTS,
	UBCORE_TP_STATE_ERROR
};

enum ubcore_ta_type {
	UBCORE_TA_NONE = 0,
	UBCORE_TA_JFS_TJFR,
	UBCORE_TA_JETTY_TJETTY,
	UBCORE_TA_VIRT /* virtualization */
};

struct ubcore_ta {
	enum ubcore_ta_type type;
	union {
		struct ubcore_jfs *jfs;
		struct ubcore_jfr *jfr;
		struct ubcore_jetty *jetty;
	};
	struct ubcore_jetty_id tjetty_id; /* peer jetty id */
};

struct ubcore_tp_cfg {
	struct ubcore_ta *ta; /* NULL for UB device */
	union ubcore_tp_cfg_flag flag; /* indicate initiator or target, etc */
	struct ubcore_net_addr local_net_addr;
	struct ubcore_net_addr peer_net_addr;
	union ubcore_eid local_eid;
	union ubcore_eid peer_eid;
	enum ubcore_transport_mode trans_mode;
	uint32_t rx_psn;
	enum ubcore_mtu mtu;
	uint16_t data_udp_start; /* src udp port start, for multipath data */
	uint16_t ack_udp_start; /* src udp port start, for multipath ack */
	uint8_t udp_range; /* src udp port range, for both multipath data and ack */
	uint8_t retry_num;
	uint8_t ack_timeout;
	uint8_t tc; /* traffic class */
};

struct ubcore_tp_ext {
	uint64_t addr;
	uint32_t len;
};

union ubcore_tp_attr_mask {
	struct {
		uint32_t flag : 1;
		uint32_t peer_tpn : 1;
		uint32_t state : 1;
		uint32_t tx_psn : 1;
		uint32_t rx_psn : 1; /* modify both rx psn and tx psn when restore tp */
		uint32_t mtu : 1;
		uint32_t cc_pattern_idx : 1;
		uint32_t peer_ext : 1;
		uint32_t reserved : 24;
	} bs;
	uint32_t value;
};

struct ubcore_tp_attr {
	union ubcore_tp_mod_flag flag;
	uint32_t peer_tpn;
	enum ubcore_tp_state state;
	uint32_t tx_psn;
	uint32_t rx_psn; /* modify both rx psn and tx psn when restore tp */
	enum ubcore_mtu mtu;
	uint8_t cc_pattern_idx;
	struct ubcore_tp_ext peer_ext;
};

struct ubcore_tp {
	uint32_t tpn; /* driver assgined in creating tp */
	uint32_t peer_tpn;
	struct ubcore_device *ub_dev;
	union ubcore_tp_flag flag; /* indicate initiator or target, etc */
	struct ubcore_net_addr local_net_addr;
	struct ubcore_net_addr peer_net_addr;
	union ubcore_eid local_eid;
	union ubcore_eid peer_eid;
	enum ubcore_transport_mode trans_mode;
	enum ubcore_tp_state state;
	uint32_t rx_psn;
	uint32_t tx_psn;
	enum ubcore_mtu mtu;
	uint16_t data_udp_start; /* src udp port start, for multipath data */
	uint16_t ack_udp_start; /* src udp port start, for multipath ack */
	uint8_t udp_range; /* src udp port range, for both multipath data and ack */
	uint8_t retry_num;
	uint8_t ack_timeout;
	uint8_t tc; /* traffic class */
	uint8_t cc_pattern_idx;
	struct ubcore_tp_ext tp_ext; /* driver fill in creating tp */
	struct ubcore_tp_ext peer_ext; /* ubcore fill before modifying tp */
	atomic_t use_cnt;
	void *priv; /* ubcore private data for tp management */
};

enum ubcore_stats_key_type {
	UBCORE_STATS_KEY_TP = 1,
	UBCORE_STATS_KEY_TPG = 2,