Skip to content

Commit 915d3a7

Browse files
author
Jakub Ramaseuski
committed
RDMA/ionic: Register auxiliary module for ionic ethernet adapter
JIRA: https://issues.redhat.com/browse/RHEL-121486 commit 8d765af Author: Abhijit Gangurde <abhijit.gangurde@amd.com> Date: Wed Sep 3 11:46:00 2025 +0530 RDMA/ionic: Register auxiliary module for ionic ethernet adapter Register auxiliary module to create ibdevice for ionic ethernet adapter. Co-developed-by: Andrew Boyer <andrew.boyer@amd.com> Signed-off-by: Andrew Boyer <andrew.boyer@amd.com> Co-developed-by: Allen Hubbe <allen.hubbe@amd.com> Signed-off-by: Allen Hubbe <allen.hubbe@amd.com> Signed-off-by: Abhijit Gangurde <abhijit.gangurde@amd.com> Link: https://patch.msgid.link/20250903061606.4139957-9-abhijit.gangurde@amd.com Signed-off-by: Leon Romanovsky <leon@kernel.org> Signed-off-by: Jakub Ramaseuski <jramaseu@redhat.com>
1 parent 26300d4 commit 915d3a7

File tree

4 files changed

+314
-0
lines changed

4 files changed

+314
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
3+
4+
#include <linux/module.h>
5+
#include <linux/printk.h>
6+
#include <net/addrconf.h>
7+
8+
#include "ionic_ibdev.h"
9+
10+
#define DRIVER_DESCRIPTION "AMD Pensando RoCE HCA driver"
11+
#define DEVICE_DESCRIPTION "AMD Pensando RoCE HCA"
12+
13+
MODULE_AUTHOR("Allen Hubbe <allen.hubbe@amd.com>");
14+
MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
15+
MODULE_LICENSE("GPL");
16+
MODULE_IMPORT_NS("NET_IONIC");
17+
18+
static void ionic_destroy_ibdev(struct ionic_ibdev *dev)
19+
{
20+
ib_unregister_device(&dev->ibdev);
21+
ib_dealloc_device(&dev->ibdev);
22+
}
23+
24+
static struct ionic_ibdev *ionic_create_ibdev(struct ionic_aux_dev *ionic_adev)
25+
{
26+
struct ib_device *ibdev;
27+
struct ionic_ibdev *dev;
28+
struct net_device *ndev;
29+
int rc;
30+
31+
dev = ib_alloc_device(ionic_ibdev, ibdev);
32+
if (!dev)
33+
return ERR_PTR(-EINVAL);
34+
35+
ionic_fill_lif_cfg(ionic_adev->lif, &dev->lif_cfg);
36+
37+
ibdev = &dev->ibdev;
38+
ibdev->dev.parent = dev->lif_cfg.hwdev;
39+
40+
strscpy(ibdev->name, "ionic_%d", IB_DEVICE_NAME_MAX);
41+
strscpy(ibdev->node_desc, DEVICE_DESCRIPTION, IB_DEVICE_NODE_DESC_MAX);
42+
43+
ibdev->node_type = RDMA_NODE_IB_CA;
44+
ibdev->phys_port_cnt = 1;
45+
46+
/* the first two eq are reserved for async events */
47+
ibdev->num_comp_vectors = dev->lif_cfg.eq_count - 2;
48+
49+
ndev = ionic_lif_netdev(ionic_adev->lif);
50+
addrconf_ifid_eui48((u8 *)&ibdev->node_guid, ndev);
51+
rc = ib_device_set_netdev(ibdev, ndev, 1);
52+
/* ionic_lif_netdev() returns ndev with refcount held */
53+
dev_put(ndev);
54+
if (rc)
55+
goto err_admin;
56+
57+
rc = ib_register_device(ibdev, "ionic_%d", ibdev->dev.parent);
58+
if (rc)
59+
goto err_register;
60+
61+
return dev;
62+
63+
err_register:
64+
err_admin:
65+
ib_dealloc_device(&dev->ibdev);
66+
67+
return ERR_PTR(rc);
68+
}
69+
70+
static int ionic_aux_probe(struct auxiliary_device *adev,
71+
const struct auxiliary_device_id *id)
72+
{
73+
struct ionic_aux_dev *ionic_adev;
74+
struct ionic_ibdev *dev;
75+
76+
ionic_adev = container_of(adev, struct ionic_aux_dev, adev);
77+
dev = ionic_create_ibdev(ionic_adev);
78+
if (IS_ERR(dev))
79+
return dev_err_probe(&adev->dev, PTR_ERR(dev),
80+
"Failed to register ibdev\n");
81+
82+
auxiliary_set_drvdata(adev, dev);
83+
ibdev_dbg(&dev->ibdev, "registered\n");
84+
85+
return 0;
86+
}
87+
88+
static void ionic_aux_remove(struct auxiliary_device *adev)
89+
{
90+
struct ionic_ibdev *dev = auxiliary_get_drvdata(adev);
91+
92+
dev_dbg(&adev->dev, "unregister ibdev\n");
93+
ionic_destroy_ibdev(dev);
94+
dev_dbg(&adev->dev, "unregistered\n");
95+
}
96+
97+
static const struct auxiliary_device_id ionic_aux_id_table[] = {
98+
{ .name = "ionic.rdma", },
99+
{},
100+
};
101+
102+
MODULE_DEVICE_TABLE(auxiliary, ionic_aux_id_table);
103+
104+
static struct auxiliary_driver ionic_aux_r_driver = {
105+
.name = "rdma",
106+
.probe = ionic_aux_probe,
107+
.remove = ionic_aux_remove,
108+
.id_table = ionic_aux_id_table,
109+
};
110+
111+
static int __init ionic_mod_init(void)
112+
{
113+
int rc;
114+
115+
rc = auxiliary_driver_register(&ionic_aux_r_driver);
116+
if (rc)
117+
goto err_aux;
118+
119+
return 0;
120+
121+
err_aux:
122+
return rc;
123+
}
124+
125+
static void __exit ionic_mod_exit(void)
126+
{
127+
auxiliary_driver_unregister(&ionic_aux_r_driver);
128+
}
129+
130+
module_init(ionic_mod_init);
131+
module_exit(ionic_mod_exit);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
3+
4+
#ifndef _IONIC_IBDEV_H_
5+
#define _IONIC_IBDEV_H_
6+
7+
#include <rdma/ib_verbs.h>
8+
#include <ionic_api.h>
9+
10+
#include "ionic_lif_cfg.h"
11+
12+
struct ionic_ibdev {
13+
struct ib_device ibdev;
14+
15+
struct ionic_lif_cfg lif_cfg;
16+
};
17+
18+
#endif /* _IONIC_IBDEV_H_ */
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
3+
4+
#include <linux/kernel.h>
5+
6+
#include <ionic.h>
7+
#include <ionic_lif.h>
8+
9+
#include "ionic_lif_cfg.h"
10+
11+
#define IONIC_MIN_RDMA_VERSION 0
12+
#define IONIC_MAX_RDMA_VERSION 2
13+
14+
static u8 ionic_get_expdb(struct ionic_lif *lif)
15+
{
16+
u8 expdb_support = 0;
17+
18+
if (lif->ionic->idev.phy_cmb_expdb64_pages)
19+
expdb_support |= IONIC_EXPDB_64B_WQE;
20+
if (lif->ionic->idev.phy_cmb_expdb128_pages)
21+
expdb_support |= IONIC_EXPDB_128B_WQE;
22+
if (lif->ionic->idev.phy_cmb_expdb256_pages)
23+
expdb_support |= IONIC_EXPDB_256B_WQE;
24+
if (lif->ionic->idev.phy_cmb_expdb512_pages)
25+
expdb_support |= IONIC_EXPDB_512B_WQE;
26+
27+
return expdb_support;
28+
}
29+
30+
void ionic_fill_lif_cfg(struct ionic_lif *lif, struct ionic_lif_cfg *cfg)
31+
{
32+
union ionic_lif_identity *ident = &lif->ionic->ident.lif;
33+
34+
cfg->lif = lif;
35+
cfg->hwdev = &lif->ionic->pdev->dev;
36+
cfg->lif_index = lif->index;
37+
cfg->lif_hw_index = lif->hw_index;
38+
39+
cfg->dbid = lif->kern_pid;
40+
cfg->dbid_count = le32_to_cpu(lif->ionic->ident.dev.ndbpgs_per_lif);
41+
cfg->dbpage = lif->kern_dbpage;
42+
cfg->intr_ctrl = lif->ionic->idev.intr_ctrl;
43+
44+
cfg->db_phys = lif->ionic->bars[IONIC_PCI_BAR_DBELL].bus_addr;
45+
46+
if (IONIC_VERSION(ident->rdma.version, ident->rdma.minor_version) >=
47+
IONIC_VERSION(2, 1))
48+
cfg->page_size_supported =
49+
le64_to_cpu(ident->rdma.page_size_cap);
50+
else
51+
cfg->page_size_supported = IONIC_PAGE_SIZE_SUPPORTED;
52+
53+
cfg->rdma_version = ident->rdma.version;
54+
cfg->qp_opcodes = ident->rdma.qp_opcodes;
55+
cfg->admin_opcodes = ident->rdma.admin_opcodes;
56+
57+
cfg->stats_type = le16_to_cpu(ident->rdma.stats_type);
58+
cfg->npts_per_lif = le32_to_cpu(ident->rdma.npts_per_lif);
59+
cfg->nmrs_per_lif = le32_to_cpu(ident->rdma.nmrs_per_lif);
60+
cfg->nahs_per_lif = le32_to_cpu(ident->rdma.nahs_per_lif);
61+
62+
cfg->aq_base = le32_to_cpu(ident->rdma.aq_qtype.qid_base);
63+
cfg->cq_base = le32_to_cpu(ident->rdma.cq_qtype.qid_base);
64+
cfg->eq_base = le32_to_cpu(ident->rdma.eq_qtype.qid_base);
65+
66+
/*
67+
* ionic_create_rdma_admin() may reduce aq_count or eq_count if
68+
* it is unable to allocate all that were requested.
69+
* aq_count is tunable; see ionic_aq_count
70+
* eq_count is tunable; see ionic_eq_count
71+
*/
72+
cfg->aq_count = le32_to_cpu(ident->rdma.aq_qtype.qid_count);
73+
cfg->eq_count = le32_to_cpu(ident->rdma.eq_qtype.qid_count);
74+
cfg->cq_count = le32_to_cpu(ident->rdma.cq_qtype.qid_count);
75+
cfg->qp_count = le32_to_cpu(ident->rdma.sq_qtype.qid_count);
76+
cfg->dbid_count = le32_to_cpu(lif->ionic->ident.dev.ndbpgs_per_lif);
77+
78+
cfg->aq_qtype = ident->rdma.aq_qtype.qtype;
79+
cfg->sq_qtype = ident->rdma.sq_qtype.qtype;
80+
cfg->rq_qtype = ident->rdma.rq_qtype.qtype;
81+
cfg->cq_qtype = ident->rdma.cq_qtype.qtype;
82+
cfg->eq_qtype = ident->rdma.eq_qtype.qtype;
83+
cfg->udma_qgrp_shift = ident->rdma.udma_shift;
84+
cfg->udma_count = 2;
85+
86+
cfg->max_stride = ident->rdma.max_stride;
87+
cfg->expdb_mask = ionic_get_expdb(lif);
88+
89+
cfg->sq_expdb =
90+
!!(lif->qtype_info[IONIC_QTYPE_TXQ].features & IONIC_QIDENT_F_EXPDB);
91+
cfg->rq_expdb =
92+
!!(lif->qtype_info[IONIC_QTYPE_RXQ].features & IONIC_QIDENT_F_EXPDB);
93+
}
94+
95+
struct net_device *ionic_lif_netdev(struct ionic_lif *lif)
96+
{
97+
struct net_device *netdev = lif->netdev;
98+
99+
dev_hold(netdev);
100+
return netdev;
101+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* Copyright (C) 2018-2025, Advanced Micro Devices, Inc. */
3+
4+
#ifndef _IONIC_LIF_CFG_H_
5+
6+
#define IONIC_VERSION(a, b) (((a) << 16) + ((b) << 8))
7+
#define IONIC_PAGE_SIZE_SUPPORTED 0x40201000 /* 4kb, 2Mb, 1Gb */
8+
9+
#define IONIC_EXPDB_64B_WQE BIT(0)
10+
#define IONIC_EXPDB_128B_WQE BIT(1)
11+
#define IONIC_EXPDB_256B_WQE BIT(2)
12+
#define IONIC_EXPDB_512B_WQE BIT(3)
13+
14+
struct ionic_lif_cfg {
15+
struct device *hwdev;
16+
struct ionic_lif *lif;
17+
18+
int lif_index;
19+
int lif_hw_index;
20+
21+
u32 dbid;
22+
int dbid_count;
23+
u64 __iomem *dbpage;
24+
struct ionic_intr __iomem *intr_ctrl;
25+
phys_addr_t db_phys;
26+
27+
u64 page_size_supported;
28+
u32 npts_per_lif;
29+
u32 nmrs_per_lif;
30+
u32 nahs_per_lif;
31+
32+
u32 aq_base;
33+
u32 cq_base;
34+
u32 eq_base;
35+
36+
int aq_count;
37+
int eq_count;
38+
int cq_count;
39+
int qp_count;
40+
41+
u16 stats_type;
42+
u8 aq_qtype;
43+
u8 sq_qtype;
44+
u8 rq_qtype;
45+
u8 cq_qtype;
46+
u8 eq_qtype;
47+
48+
u8 udma_count;
49+
u8 udma_qgrp_shift;
50+
51+
u8 rdma_version;
52+
u8 qp_opcodes;
53+
u8 admin_opcodes;
54+
55+
u8 max_stride;
56+
bool sq_expdb;
57+
bool rq_expdb;
58+
u8 expdb_mask;
59+
};
60+
61+
void ionic_fill_lif_cfg(struct ionic_lif *lif, struct ionic_lif_cfg *cfg);
62+
struct net_device *ionic_lif_netdev(struct ionic_lif *lif);
63+
64+
#endif /* _IONIC_LIF_CFG_H_ */

0 commit comments

Comments
 (0)