162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
462306a36Sopenharmony_ci * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef RXE_H
862306a36Sopenharmony_ci#define RXE_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifdef pr_fmt
1162306a36Sopenharmony_ci#undef pr_fmt
1262306a36Sopenharmony_ci#endif
1362306a36Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#include <linux/skbuff.h>
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#include <rdma/ib_verbs.h>
1862306a36Sopenharmony_ci#include <rdma/ib_user_verbs.h>
1962306a36Sopenharmony_ci#include <rdma/ib_pack.h>
2062306a36Sopenharmony_ci#include <rdma/ib_smi.h>
2162306a36Sopenharmony_ci#include <rdma/ib_umem.h>
2262306a36Sopenharmony_ci#include <rdma/ib_cache.h>
2362306a36Sopenharmony_ci#include <rdma/ib_addr.h>
2462306a36Sopenharmony_ci#include <crypto/hash.h>
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#include "rxe_net.h"
2762306a36Sopenharmony_ci#include "rxe_opcode.h"
2862306a36Sopenharmony_ci#include "rxe_hdr.h"
2962306a36Sopenharmony_ci#include "rxe_param.h"
3062306a36Sopenharmony_ci#include "rxe_verbs.h"
3162306a36Sopenharmony_ci#include "rxe_loc.h"
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci/*
3462306a36Sopenharmony_ci * Version 1 and Version 2 are identical on 64 bit machines, but on 32 bit
3562306a36Sopenharmony_ci * machines Version 2 has a different struct layout.
3662306a36Sopenharmony_ci */
3762306a36Sopenharmony_ci#define RXE_UVERBS_ABI_VERSION		2
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#define RXE_ROCE_V2_SPORT		(0xc000)
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#define rxe_dbg(fmt, ...) pr_debug("%s: " fmt "\n", __func__, ##__VA_ARGS__)
4262306a36Sopenharmony_ci#define rxe_dbg_dev(rxe, fmt, ...) ibdev_dbg(&(rxe)->ib_dev,		\
4362306a36Sopenharmony_ci		"%s: " fmt, __func__, ##__VA_ARGS__)
4462306a36Sopenharmony_ci#define rxe_dbg_uc(uc, fmt, ...) ibdev_dbg((uc)->ibuc.device,		\
4562306a36Sopenharmony_ci		"uc#%d %s: " fmt, (uc)->elem.index, __func__, ##__VA_ARGS__)
4662306a36Sopenharmony_ci#define rxe_dbg_pd(pd, fmt, ...) ibdev_dbg((pd)->ibpd.device,		\
4762306a36Sopenharmony_ci		"pd#%d %s: " fmt, (pd)->elem.index, __func__, ##__VA_ARGS__)
4862306a36Sopenharmony_ci#define rxe_dbg_ah(ah, fmt, ...) ibdev_dbg((ah)->ibah.device,		\
4962306a36Sopenharmony_ci		"ah#%d %s: " fmt, (ah)->elem.index, __func__, ##__VA_ARGS__)
5062306a36Sopenharmony_ci#define rxe_dbg_srq(srq, fmt, ...) ibdev_dbg((srq)->ibsrq.device,	\
5162306a36Sopenharmony_ci		"srq#%d %s: " fmt, (srq)->elem.index, __func__, ##__VA_ARGS__)
5262306a36Sopenharmony_ci#define rxe_dbg_qp(qp, fmt, ...) ibdev_dbg((qp)->ibqp.device,		\
5362306a36Sopenharmony_ci		"qp#%d %s: " fmt, (qp)->elem.index, __func__, ##__VA_ARGS__)
5462306a36Sopenharmony_ci#define rxe_dbg_cq(cq, fmt, ...) ibdev_dbg((cq)->ibcq.device,		\
5562306a36Sopenharmony_ci		"cq#%d %s: " fmt, (cq)->elem.index, __func__, ##__VA_ARGS__)
5662306a36Sopenharmony_ci#define rxe_dbg_mr(mr, fmt, ...) ibdev_dbg((mr)->ibmr.device,		\
5762306a36Sopenharmony_ci		"mr#%d %s:  " fmt, (mr)->elem.index, __func__, ##__VA_ARGS__)
5862306a36Sopenharmony_ci#define rxe_dbg_mw(mw, fmt, ...) ibdev_dbg((mw)->ibmw.device,		\
5962306a36Sopenharmony_ci		"mw#%d %s:  " fmt, (mw)->elem.index, __func__, ##__VA_ARGS__)
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci#define rxe_err(fmt, ...) pr_err_ratelimited("%s: " fmt "\n", __func__, \
6262306a36Sopenharmony_ci					##__VA_ARGS__)
6362306a36Sopenharmony_ci#define rxe_err_dev(rxe, fmt, ...) ibdev_err_ratelimited(&(rxe)->ib_dev, \
6462306a36Sopenharmony_ci		"%s: " fmt, __func__, ##__VA_ARGS__)
6562306a36Sopenharmony_ci#define rxe_err_uc(uc, fmt, ...) ibdev_err_ratelimited((uc)->ibuc.device, \
6662306a36Sopenharmony_ci		"uc#%d %s: " fmt, (uc)->elem.index, __func__, ##__VA_ARGS__)
6762306a36Sopenharmony_ci#define rxe_err_pd(pd, fmt, ...) ibdev_err_ratelimited((pd)->ibpd.device, \
6862306a36Sopenharmony_ci		"pd#%d %s: " fmt, (pd)->elem.index, __func__, ##__VA_ARGS__)
6962306a36Sopenharmony_ci#define rxe_err_ah(ah, fmt, ...) ibdev_err_ratelimited((ah)->ibah.device, \
7062306a36Sopenharmony_ci		"ah#%d %s: " fmt, (ah)->elem.index, __func__, ##__VA_ARGS__)
7162306a36Sopenharmony_ci#define rxe_err_srq(srq, fmt, ...) ibdev_err_ratelimited((srq)->ibsrq.device, \
7262306a36Sopenharmony_ci		"srq#%d %s: " fmt, (srq)->elem.index, __func__, ##__VA_ARGS__)
7362306a36Sopenharmony_ci#define rxe_err_qp(qp, fmt, ...) ibdev_err_ratelimited((qp)->ibqp.device, \
7462306a36Sopenharmony_ci		"qp#%d %s: " fmt, (qp)->elem.index, __func__, ##__VA_ARGS__)
7562306a36Sopenharmony_ci#define rxe_err_cq(cq, fmt, ...) ibdev_err_ratelimited((cq)->ibcq.device, \
7662306a36Sopenharmony_ci		"cq#%d %s: " fmt, (cq)->elem.index, __func__, ##__VA_ARGS__)
7762306a36Sopenharmony_ci#define rxe_err_mr(mr, fmt, ...) ibdev_err_ratelimited((mr)->ibmr.device, \
7862306a36Sopenharmony_ci		"mr#%d %s:  " fmt, (mr)->elem.index, __func__, ##__VA_ARGS__)
7962306a36Sopenharmony_ci#define rxe_err_mw(mw, fmt, ...) ibdev_err_ratelimited((mw)->ibmw.device, \
8062306a36Sopenharmony_ci		"mw#%d %s:  " fmt, (mw)->elem.index, __func__, ##__VA_ARGS__)
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#define rxe_info(fmt, ...) pr_info_ratelimited("%s: " fmt "\n", __func__, \
8362306a36Sopenharmony_ci					##__VA_ARGS__)
8462306a36Sopenharmony_ci#define rxe_info_dev(rxe, fmt, ...) ibdev_info_ratelimited(&(rxe)->ib_dev, \
8562306a36Sopenharmony_ci		"%s: " fmt, __func__, ##__VA_ARGS__)
8662306a36Sopenharmony_ci#define rxe_info_uc(uc, fmt, ...) ibdev_info_ratelimited((uc)->ibuc.device, \
8762306a36Sopenharmony_ci		"uc#%d %s: " fmt, (uc)->elem.index, __func__, ##__VA_ARGS__)
8862306a36Sopenharmony_ci#define rxe_info_pd(pd, fmt, ...) ibdev_info_ratelimited((pd)->ibpd.device, \
8962306a36Sopenharmony_ci		"pd#%d %s: " fmt, (pd)->elem.index, __func__, ##__VA_ARGS__)
9062306a36Sopenharmony_ci#define rxe_info_ah(ah, fmt, ...) ibdev_info_ratelimited((ah)->ibah.device, \
9162306a36Sopenharmony_ci		"ah#%d %s: " fmt, (ah)->elem.index, __func__, ##__VA_ARGS__)
9262306a36Sopenharmony_ci#define rxe_info_srq(srq, fmt, ...) ibdev_info_ratelimited((srq)->ibsrq.device, \
9362306a36Sopenharmony_ci		"srq#%d %s: " fmt, (srq)->elem.index, __func__, ##__VA_ARGS__)
9462306a36Sopenharmony_ci#define rxe_info_qp(qp, fmt, ...) ibdev_info_ratelimited((qp)->ibqp.device, \
9562306a36Sopenharmony_ci		"qp#%d %s: " fmt, (qp)->elem.index, __func__, ##__VA_ARGS__)
9662306a36Sopenharmony_ci#define rxe_info_cq(cq, fmt, ...) ibdev_info_ratelimited((cq)->ibcq.device, \
9762306a36Sopenharmony_ci		"cq#%d %s: " fmt, (cq)->elem.index, __func__, ##__VA_ARGS__)
9862306a36Sopenharmony_ci#define rxe_info_mr(mr, fmt, ...) ibdev_info_ratelimited((mr)->ibmr.device, \
9962306a36Sopenharmony_ci		"mr#%d %s:  " fmt, (mr)->elem.index, __func__, ##__VA_ARGS__)
10062306a36Sopenharmony_ci#define rxe_info_mw(mw, fmt, ...) ibdev_info_ratelimited((mw)->ibmw.device, \
10162306a36Sopenharmony_ci		"mw#%d %s:  " fmt, (mw)->elem.index, __func__, ##__VA_ARGS__)
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci/* responder states */
10462306a36Sopenharmony_cienum resp_states {
10562306a36Sopenharmony_ci	RESPST_NONE,
10662306a36Sopenharmony_ci	RESPST_GET_REQ,
10762306a36Sopenharmony_ci	RESPST_CHK_PSN,
10862306a36Sopenharmony_ci	RESPST_CHK_OP_SEQ,
10962306a36Sopenharmony_ci	RESPST_CHK_OP_VALID,
11062306a36Sopenharmony_ci	RESPST_CHK_RESOURCE,
11162306a36Sopenharmony_ci	RESPST_CHK_LENGTH,
11262306a36Sopenharmony_ci	RESPST_CHK_RKEY,
11362306a36Sopenharmony_ci	RESPST_EXECUTE,
11462306a36Sopenharmony_ci	RESPST_READ_REPLY,
11562306a36Sopenharmony_ci	RESPST_ATOMIC_REPLY,
11662306a36Sopenharmony_ci	RESPST_ATOMIC_WRITE_REPLY,
11762306a36Sopenharmony_ci	RESPST_PROCESS_FLUSH,
11862306a36Sopenharmony_ci	RESPST_COMPLETE,
11962306a36Sopenharmony_ci	RESPST_ACKNOWLEDGE,
12062306a36Sopenharmony_ci	RESPST_CLEANUP,
12162306a36Sopenharmony_ci	RESPST_DUPLICATE_REQUEST,
12262306a36Sopenharmony_ci	RESPST_ERR_MALFORMED_WQE,
12362306a36Sopenharmony_ci	RESPST_ERR_UNSUPPORTED_OPCODE,
12462306a36Sopenharmony_ci	RESPST_ERR_MISALIGNED_ATOMIC,
12562306a36Sopenharmony_ci	RESPST_ERR_PSN_OUT_OF_SEQ,
12662306a36Sopenharmony_ci	RESPST_ERR_MISSING_OPCODE_FIRST,
12762306a36Sopenharmony_ci	RESPST_ERR_MISSING_OPCODE_LAST_C,
12862306a36Sopenharmony_ci	RESPST_ERR_MISSING_OPCODE_LAST_D1E,
12962306a36Sopenharmony_ci	RESPST_ERR_TOO_MANY_RDMA_ATM_REQ,
13062306a36Sopenharmony_ci	RESPST_ERR_RNR,
13162306a36Sopenharmony_ci	RESPST_ERR_RKEY_VIOLATION,
13262306a36Sopenharmony_ci	RESPST_ERR_INVALIDATE_RKEY,
13362306a36Sopenharmony_ci	RESPST_ERR_LENGTH,
13462306a36Sopenharmony_ci	RESPST_ERR_CQ_OVERFLOW,
13562306a36Sopenharmony_ci	RESPST_ERROR,
13662306a36Sopenharmony_ci	RESPST_DONE,
13762306a36Sopenharmony_ci	RESPST_EXIT,
13862306a36Sopenharmony_ci};
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_civoid rxe_set_mtu(struct rxe_dev *rxe, unsigned int dev_mtu);
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ciint rxe_add(struct rxe_dev *rxe, unsigned int mtu, const char *ibdev_name);
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_civoid rxe_rcv(struct sk_buff *skb);
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci/* The caller must do a matching ib_device_put(&dev->ib_dev) */
14762306a36Sopenharmony_cistatic inline struct rxe_dev *rxe_get_dev_from_net(struct net_device *ndev)
14862306a36Sopenharmony_ci{
14962306a36Sopenharmony_ci	struct ib_device *ibdev =
15062306a36Sopenharmony_ci		ib_device_get_by_netdev(ndev, RDMA_DRIVER_RXE);
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci	if (!ibdev)
15362306a36Sopenharmony_ci		return NULL;
15462306a36Sopenharmony_ci	return container_of(ibdev, struct rxe_dev, ib_dev);
15562306a36Sopenharmony_ci}
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_civoid rxe_port_up(struct rxe_dev *rxe);
15862306a36Sopenharmony_civoid rxe_port_down(struct rxe_dev *rxe);
15962306a36Sopenharmony_civoid rxe_set_port_state(struct rxe_dev *rxe);
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci#endif /* RXE_H */
162