Commit a883e713 authored by Boshi Yu's avatar Boshi Yu Committed by Leon Romanovsky
Browse files

RDMA/erdma: Probe the erdma RoCEv2 device



Currently, the erdma driver supports both the iWARP and RoCEv2 protocols.
The erdma driver reads the ERDMA_REGS_DEV_PROTO_REG register to identify
the protocol used by the erdma device. Since each protocol requires
different ib_device_ops, we introduce the erdma_device_ops_iwarp and
erdma_device_ops_rocev2 for iWARP and RoCEv2 protocols, respectively.

Signed-off-by: default avatarBoshi Yu <boshiyu@linux.alibaba.com>
Link: https://patch.msgid.link/20241211020930.68833-2-boshiyu@linux.alibaba.com


Reviewed-by: default avatarCheng Xu <chengyou@linux.alibaba.com>
Signed-off-by: default avatarLeon Romanovsky <leon@kernel.org>
parent bd96a393
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ config INFINIBAND_ERDMA
	depends on INFINIBAND_ADDR_TRANS
	depends on INFINIBAND_USER_ACCESS
	help
	  This is a RDMA/iWarp driver for Alibaba Elastic RDMA Adapter(ERDMA),
	  This is a RDMA driver for Alibaba Elastic RDMA Adapter(ERDMA),
	  which supports RDMA features in Alibaba cloud environment.

	  To compile this driver as module, choose M here. The module will be
+2 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
#include "erdma_hw.h"

#define DRV_MODULE_NAME "erdma"
#define ERDMA_NODE_DESC "Elastic RDMA(iWARP) stack"
#define ERDMA_NODE_DESC "Elastic RDMA Adapter stack"

struct erdma_eq {
	void *qbuf;
@@ -215,6 +215,7 @@ struct erdma_dev {

	struct dma_pool *db_pool;
	struct dma_pool *resp_pool;
	enum erdma_proto_type proto;
};

static inline void *get_queue_entry(void *qbuf, u32 idx, u32 depth, u32 shift)
+7 −0
Original line number Diff line number Diff line
@@ -21,8 +21,15 @@
#define ERDMA_NUM_MSIX_VEC 32U
#define ERDMA_MSIX_VECTOR_CMDQ 0

/* erdma device protocol type */
enum erdma_proto_type {
	ERDMA_PROTO_IWARP = 0,
	ERDMA_PROTO_ROCEV2 = 1,
};

/* PCIe Bar0 Registers. */
#define ERDMA_REGS_VERSION_REG 0x0
#define ERDMA_REGS_DEV_PROTO_REG 0xC
#define ERDMA_REGS_DEV_CTRL_REG 0x10
#define ERDMA_REGS_DEV_ST_REG 0x14
#define ERDMA_REGS_NETDEV_MAC_L_REG 0x18
+25 −9
Original line number Diff line number Diff line
@@ -172,6 +172,8 @@ static int erdma_device_init(struct erdma_dev *dev, struct pci_dev *pdev)
{
	int ret;

	dev->proto = erdma_reg_read32(dev, ERDMA_REGS_DEV_PROTO_REG);

	dev->resp_pool = dma_pool_create("erdma_resp_pool", &pdev->dev,
					 ERDMA_HW_RESP_SIZE, ERDMA_HW_RESP_SIZE,
					 0);
@@ -474,6 +476,21 @@ static void erdma_res_cb_free(struct erdma_dev *dev)
		bitmap_free(dev->res_cb[i].bitmap);
}

static const struct ib_device_ops erdma_device_ops_rocev2 = {
	.get_link_layer = erdma_get_link_layer,
};

static const struct ib_device_ops erdma_device_ops_iwarp = {
	.iw_accept = erdma_accept,
	.iw_add_ref = erdma_qp_get_ref,
	.iw_connect = erdma_connect,
	.iw_create_listen = erdma_create_listen,
	.iw_destroy_listen = erdma_destroy_listen,
	.iw_get_qp = erdma_get_ibqp,
	.iw_reject = erdma_reject,
	.iw_rem_ref = erdma_qp_put_ref,
};

static const struct ib_device_ops erdma_device_ops = {
	.owner = THIS_MODULE,
	.driver_id = RDMA_DRIVER_ERDMA,
@@ -494,14 +511,6 @@ static const struct ib_device_ops erdma_device_ops = {
	.get_dma_mr = erdma_get_dma_mr,
	.get_hw_stats = erdma_get_hw_stats,
	.get_port_immutable = erdma_get_port_immutable,
	.iw_accept = erdma_accept,
	.iw_add_ref = erdma_qp_get_ref,
	.iw_connect = erdma_connect,
	.iw_create_listen = erdma_create_listen,
	.iw_destroy_listen = erdma_destroy_listen,
	.iw_get_qp = erdma_get_ibqp,
	.iw_reject = erdma_reject,
	.iw_rem_ref = erdma_qp_put_ref,
	.map_mr_sg = erdma_map_mr_sg,
	.mmap = erdma_mmap,
	.mmap_free = erdma_mmap_free,
@@ -537,7 +546,14 @@ static int erdma_ib_device_add(struct pci_dev *pdev)
	if (ret)
		return ret;

	if (erdma_device_iwarp(dev)) {
		ibdev->node_type = RDMA_NODE_RNIC;
		ib_set_device_ops(ibdev, &erdma_device_ops_iwarp);
	} else {
		ibdev->node_type = RDMA_NODE_IB_CA;
		ib_set_device_ops(ibdev, &erdma_device_ops_rocev2);
	}

	memcpy(ibdev->node_desc, ERDMA_NODE_DESC, sizeof(ERDMA_NODE_DESC));

	/*
+15 −1
Original line number Diff line number Diff line
@@ -395,8 +395,17 @@ int erdma_query_port(struct ib_device *ibdev, u32 port,
int erdma_get_port_immutable(struct ib_device *ibdev, u32 port,
			     struct ib_port_immutable *port_immutable)
{
	port_immutable->gid_tbl_len = 1;
	struct erdma_dev *dev = to_edev(ibdev);

	if (erdma_device_iwarp(dev)) {
		port_immutable->core_cap_flags = RDMA_CORE_PORT_IWARP;
	} else {
		port_immutable->core_cap_flags =
			RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP;
		port_immutable->max_mad_size = IB_MGMT_MAD_SIZE;
	}

	port_immutable->gid_tbl_len = 1;

	return 0;
}
@@ -1839,3 +1848,8 @@ int erdma_get_hw_stats(struct ib_device *ibdev, struct rdma_hw_stats *stats,

	return stats->num_counters;
}

enum rdma_link_layer erdma_get_link_layer(struct ib_device *ibdev, u32 port_num)
{
	return IB_LINK_LAYER_ETHERNET;
}
Loading