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

ub: ubcore add jetty, event and hash table definition



driver inclusion
category: feature
bugzilla: NA
CVE: NA

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

Ubcore add jetty and hash table definition

**Introduce of Jetty:**

Jetty is a logical concept, an I/O unit that provides
end-to-end communication services. Jetty is classified into three types:
Jetty for Send, Jetty for Receive, and Jetty for Completion.
Each Jetty has a queue that maintains its sending and receiving requests.
1. JFS (Jetty for send): used to submit a DMA task
or send a message on the user side.
2. JFR (jetty for receive): used to prepare a resource for
receiving a message on the home side.
3. JFC (jetty for complete): stores JFS/JFR completion events.
It can be bound to JFS or JFR, or specified separately in specific
URMA commands.
4. jetty: Jetty is duplex and contains both jfs and jfr functions.
5. tjetty (target jetty): represent remote JFR/Jetty imported to local.
6. jetty id: represent a unique jetty in global, contructed by eid,
uasid and id itself.
A Jetty for Send (JFS) can implement the remote memory DMA service
on one side. JFS (source end) + JFR (destination end) can implement
bilateral message services.

**Event in ubcore:**

There are 2 types of event in ubcore:
- JFCE (jetty for completion event): JFS/JFR completion events.
The jfc_comp_callback interrupt processing function is used to set
the JFC completion type during kernel-mode driver loading.
This callback function searches for the kernel-mode JFC pointer based on
the jfc_id reported by the hardware, and invokes the comp_handler stored
in the JFC data structure.
- JFAE (jetty for async event): Kernel-Mode Exception Events. Once a Jetty
exception occurs, the chip reports a hardware interrupt to the UBN driver.
The UBN driver parses the interrupt information, finds the abnormal Jetty,
and invokes ubcore_event_callback to report the exception to the UB Core
protocol stack.

**Hashtable:**

Use hlist_head and hlist_node as the implementation of hash table,
which will be used to store info of jetty and tps in ubcore device.

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

struct ubcore_ht_param {
	uint32_t size;
	uint32_t node_offset; /* offset of hlist node in the hash table object */
	uint32_t key_offset;
	uint32_t key_size;
	int (*cmp_f)(void *obj, const void *key);
	void (*free_f)(void *obj);
};

struct ubcore_hash_table {
	struct ubcore_ht_param p;
	struct hlist_head *head;
	spinlock_t lock;
	struct kref kref;
};

union ubcore_jfc_flag {
	struct {
		uint32_t lock_free : 1;
		uint32_t jfc_inline : 1;
		uint32_t reserved : 30;
	} bs;
	uint32_t value;
};

union ubcore_jfs_flag {
	struct {
		/* 0: IDC_MODE.
		 * 1: DC_MODE.
		 * 2: LS_MODE
		 */
		uint32_t mode : 2;
		uint32_t lock_free : 1;
		uint32_t reserved : 29;
	} bs;
	uint32_t value;
};

union ubcore_jfr_flag {
	struct {
		uint32_t key_policy : 3;	/* 0: UBCORE_KEY_NONE
						 * 1: UBCORE_KEY_PLAIN_TEXT
						 * 2: UBCORE_KEY_SIGNED
						 * 3: UBCORE_KEY_ALL_ENCRYPTED
						 * 4: UBCORE_KEY_RESERVED
						 */
		uint32_t tag_matching : 1;
		uint32_t lock_free : 1;
		uint32_t reserved : 27;
	} bs;
	uint32_t value;
};

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

struct ubcore_jfc;
typedef void (*ubcore_comp_callback_t)(struct ubcore_jfc *jfc);

enum ubcore_event_type {
	UBCORE_EVENT_JFC_ERR,
	UBCORE_EVENT_JFS_FATAL,
	UBCORE_EVENT_JFS_ACCESS_ERR,
	UBCORE_EVENT_JFR_FATAL,
	UBCORE_EVENT_JFR_ACCESS_ERR,
	UBCORE_EVENT_JETTY_FATAL,
	UBCORE_EVENT_JETTY_ACCESS_ERR,
	UBCORE_EVENT_PORT_ACTIVE,
	UBCORE_EVENT_PORT_ERR,
	UBCORE_EVENT_DEV_FATAL,
	UBCORE_EVENT_ID_CHANGE,
	UBCORE_EVENT_TP_ERR
};

struct ubcore_event {
	struct ubcore_device *ub_dev;
	union {
		struct ubcore_jfc *jfc;
		struct ubcore_jfs *jfs;
		struct ubcore_jfr *jfr;
		struct ubcore_jetty *jetty;
		struct ubcore_tp *tp;
		uint32_t port_id;
	} element;
	enum ubcore_event_type event_type;
};

typedef void (*ubcore_event_callback_t)(struct ubcore_event *event, struct ubcore_ucontext *ctx);

struct ubcore_event_handler {
	void (*event_callback)(struct ubcore_event *event, struct ubcore_event_handler *handler);
	struct list_head node;
};

struct ubcore_jfc_cfg {
	uint32_t depth;
	union ubcore_jfc_flag flag;
	void *jfc_context;
	uint32_t eq_id;
};

struct ubcore_jfc {
	struct ubcore_device *ub_dev;
	struct ubcore_ucontext *uctx;
	struct ubcore_jfc_cfg jfc_cfg;
	uint32_t id; /* allocated by driver */
	ubcore_comp_callback_t jfce_handler;
	ubcore_event_callback_t jfae_handler;
	uint64_t urma_jfc; /* user space jfc pointer */
	struct hlist_node hnode;
	atomic_t use_cnt;
};

/* transport mode */
enum ubcore_transport_mode {
	UBCORE_TP_RM = 0x1, /* Reliable message */
@@ -98,6 +208,124 @@ enum ubcore_transport_mode {
	UBCORE_TP_UM = 0x1 << 2 /* Unreliable message */
};

struct ubcore_jfs_cfg {
	uint32_t depth;
	union ubcore_jfs_flag flag;
	uint8_t priority;
	uint8_t max_sge;
	uint8_t max_rsge;
	uint32_t max_inline_data;
	uint8_t retry_cnt;
	uint8_t rnr_retry;
	uint8_t err_timeout;
	void *jfs_context;
	struct ubcore_jfc *jfc;
	enum ubcore_transport_mode trans_mode;
};

struct ubcore_jfs {
	struct ubcore_device *ub_dev;
	struct ubcore_ucontext *uctx;
	struct ubcore_jfs_cfg jfs_cfg;
	uint32_t id; /* allocted by driver */
	ubcore_event_callback_t jfae_handler;
	uint64_t urma_jfs; /* user space jfs pointer */
	struct hlist_node hnode;
	atomic_t use_cnt;
	struct ubcore_hash_table *tptable; /* Only for devices not natively supporting RM mode */
};

struct ubcore_key {
	uint32_t key;
};

struct ubcore_jfr_cfg {
	uint32_t id; /* user may assign id */
	uint32_t depth;
	union ubcore_jfr_flag flag;
	uint8_t max_sge;
	uint8_t min_rnr_timer;
	enum ubcore_transport_mode trans_mode;
	struct ubcore_jfc *jfc;
	struct ubcore_key ukey;
	void *jfr_context;
};

struct ubcore_jfr {
	struct ubcore_device *ub_dev;
	struct ubcore_ucontext *uctx;
	struct ubcore_jfr_cfg jfr_cfg;
	uint32_t id; /* allocted by driver */
	ubcore_event_callback_t jfae_handler;
	uint64_t urma_jfr; /* user space jfr pointer */
	struct hlist_node hnode;
	atomic_t use_cnt;
	struct ubcore_hash_table *tptable; /* Only for devices not natively supporting RM mode */
};

union ubcore_jetty_flag {
	struct {
		uint32_t share_jfr : 1; /* 0: URMA_NO_SHARE_JFR.
					 * 1: URMA_SHARE_JFR.
					 */
		uint32_t reserved : 31;
	} bs;
	uint32_t value;
};

struct ubcore_jetty_cfg {
	uint32_t id; /* user may assign id */
	uint32_t jfs_depth;
	uint32_t jfr_depth;
	union ubcore_jetty_flag flag;
	struct ubcore_jfc *send_jfc;
	struct ubcore_jfc *recv_jfc;
	struct ubcore_jfr *jfr; /* shared jfr */
	uint8_t max_send_sge;
	uint8_t max_send_rsge;
	uint8_t max_recv_sge;
	uint32_t max_inline_data;
	uint8_t priority;
	uint8_t retry_cnt;
	uint8_t rnr_retry;
	uint8_t err_timeout;
	uint8_t min_rnr_timer;
	enum ubcore_transport_mode trans_mode;
	struct ubcore_key ukey;
	void *jetty_context;
};

struct ubcore_tjetty_cfg {
	struct ubcore_jetty_id id; /* jfr, jetty or jetty group id to be imported */
	enum ubcore_transport_mode trans_mode;
	struct ubcore_key ukey; /* jfr, jetty or jetty group ukey value to be imported */
};

enum ubcore_target_type { UBCORE_JFR = 0, UBCORE_JETTY, UBCORE_JFR_GROUP, UBCORE_JETTY_GROUP };

struct ubcore_tjetty {
	struct ubcore_device *ub_dev;
	struct ubcore_ucontext *uctx;
	enum ubcore_target_type type;
	struct ubcore_tjetty_cfg cfg;
	struct ubcore_tp *tp; /* for UB transport device  */
	atomic_t use_cnt;
	struct mutex lock;
};

struct ubcore_jetty {
	struct ubcore_device *ub_dev;
	struct ubcore_ucontext *uctx;
	struct ubcore_jetty_cfg jetty_cfg;
	uint32_t id; /* allocted by driver */
	struct ubcore_tjetty *remote_jetty; // bind to remote jetty
	ubcore_event_callback_t jfae_handler;
	uint64_t urma_jetty; /* user space jetty pointer */
	struct hlist_node hnode;
	atomic_t use_cnt;
	struct ubcore_hash_table *tptable; /* Only for devices not natively supporting RM mode */
};

enum ubcore_mtu {
	UBCORE_MTU_256 = 1,
	UBCORE_MTU_512,