12SN/A/* SPDX-License-Identifier: GPL-2.0 */
21612Smhaupt/*
32SN/A *  Shared Memory Communications Direct over loopback-ism device.
42SN/A *
52SN/A *  SMC-D loopback-ism device structure definitions.
62SN/A *
72SN/A *  Copyright (c) 2024, Alibaba Inc.
82SN/A *
92SN/A *  Author: Wen Gu <guwen@linux.alibaba.com>
102SN/A *          Tony Lu <tonylu@linux.alibaba.com>
112SN/A *
122SN/A */
132SN/A
142SN/A#ifndef _SMC_LOOPBACK_H
152SN/A#define _SMC_LOOPBACK_H
162SN/A
172SN/A#include <linux/device.h>
182SN/A#include <linux/err.h>
192SN/A#include <net/smc.h>
202SN/A
212SN/A#if IS_ENABLED(CONFIG_SMC_LO)
222SN/A#define SMC_LO_MAX_DMBS		5000
232SN/A#define SMC_LO_DMBS_HASH_BITS	12
242SN/A#define SMC_LO_RESERVED_CHID	0xFFFF
252SN/A
262SN/Astruct smc_lo_dmb_node {
272SN/A	struct hlist_node list;
282SN/A	u64 token;
292SN/A	u32 len;
302SN/A	u32 sba_idx;
31604SN/A	void *cpu_addr;
322SN/A	dma_addr_t dma_addr;
33210SN/A	refcount_t refcnt;
342SN/A};
35604SN/A
362SN/Astruct smc_lo_dev {
3756SN/A	struct smcd_dev *smcd;
382SN/A	struct device dev;
392SN/A	u16 chid;
4056SN/A	struct smcd_gid local_gid;
412SN/A	atomic_t dmb_cnt;
422SN/A	rwlock_t dmb_ht_lock;
432SN/A	DECLARE_BITMAP(sba_idx_mask, SMC_LO_MAX_DMBS);
442SN/A	DECLARE_HASHTABLE(dmb_ht, SMC_LO_DMBS_HASH_BITS);
452SN/A	wait_queue_head_t ldev_release;
462SN/A};
472SN/A
48210SN/Aint smc_loopback_init(void);
49429SN/Avoid smc_loopback_exit(void);
501068Sattila#else
511068Sattilastatic inline int smc_loopback_init(void)
522SN/A{
53143SN/A	return 0;
542SN/A}
55414SN/A
56414SN/Astatic inline void smc_loopback_exit(void)
57414SN/A{
58251SN/A}
592SN/A#endif
602SN/A
612SN/A#endif /* _SMC_LOOPBACK_H */
622SN/A