Skip to content

Commit cedd644

Browse files
author
Jakub Ramaseuski
committed
RDMA/ionic: Register device ops for miscellaneous functionality
JIRA: https://issues.redhat.com/browse/RHEL-121486 commit 2075bbe Author: Abhijit Gangurde <abhijit.gangurde@amd.com> Date: Wed Sep 3 11:46:04 2025 +0530 RDMA/ionic: Register device ops for miscellaneous functionality Implement idbdev ops for device and port information. 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-13-abhijit.gangurde@amd.com Signed-off-by: Leon Romanovsky <leon@kernel.org> Signed-off-by: Jakub Ramaseuski <jramaseu@redhat.com>
1 parent f10e756 commit cedd644

File tree

4 files changed

+217
-0
lines changed

4 files changed

+217
-0
lines changed

drivers/infiniband/hw/ionic/ionic_ibdev.c

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
#include <linux/module.h>
55
#include <linux/printk.h>
6+
#include <linux/pci.h>
7+
#include <linux/irq.h>
68
#include <net/addrconf.h>
9+
#include <rdma/ib_addr.h>
10+
#include <rdma/ib_mad.h>
711

812
#include "ionic_ibdev.h"
913

@@ -15,6 +19,192 @@ MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
1519
MODULE_LICENSE("GPL");
1620
MODULE_IMPORT_NS("NET_IONIC");
1721

22+
static int ionic_query_device(struct ib_device *ibdev,
23+
struct ib_device_attr *attr,
24+
struct ib_udata *udata)
25+
{
26+
struct ionic_ibdev *dev = to_ionic_ibdev(ibdev);
27+
struct net_device *ndev;
28+
29+
ndev = ib_device_get_netdev(ibdev, 1);
30+
addrconf_ifid_eui48((u8 *)&attr->sys_image_guid, ndev);
31+
dev_put(ndev);
32+
attr->max_mr_size = dev->lif_cfg.npts_per_lif * PAGE_SIZE / 2;
33+
attr->page_size_cap = dev->lif_cfg.page_size_supported;
34+
35+
attr->vendor_id = to_pci_dev(dev->lif_cfg.hwdev)->vendor;
36+
attr->vendor_part_id = to_pci_dev(dev->lif_cfg.hwdev)->device;
37+
38+
attr->hw_ver = ionic_lif_asic_rev(dev->lif_cfg.lif);
39+
attr->fw_ver = 0;
40+
attr->max_qp = dev->lif_cfg.qp_count;
41+
attr->max_qp_wr = IONIC_MAX_DEPTH;
42+
attr->device_cap_flags =
43+
IB_DEVICE_MEM_WINDOW |
44+
IB_DEVICE_MEM_MGT_EXTENSIONS |
45+
IB_DEVICE_MEM_WINDOW_TYPE_2B |
46+
0;
47+
attr->max_send_sge =
48+
min(ionic_v1_send_wqe_max_sge(dev->lif_cfg.max_stride, 0, false),
49+
IONIC_SPEC_HIGH);
50+
attr->max_recv_sge =
51+
min(ionic_v1_recv_wqe_max_sge(dev->lif_cfg.max_stride, 0, false),
52+
IONIC_SPEC_HIGH);
53+
attr->max_sge_rd = attr->max_send_sge;
54+
attr->max_cq = dev->lif_cfg.cq_count / dev->lif_cfg.udma_count;
55+
attr->max_cqe = IONIC_MAX_CQ_DEPTH - IONIC_CQ_GRACE;
56+
attr->max_mr = dev->lif_cfg.nmrs_per_lif;
57+
attr->max_pd = IONIC_MAX_PD;
58+
attr->max_qp_rd_atom = IONIC_MAX_RD_ATOM;
59+
attr->max_ee_rd_atom = 0;
60+
attr->max_res_rd_atom = IONIC_MAX_RD_ATOM;
61+
attr->max_qp_init_rd_atom = IONIC_MAX_RD_ATOM;
62+
attr->max_ee_init_rd_atom = 0;
63+
attr->atomic_cap = IB_ATOMIC_GLOB;
64+
attr->masked_atomic_cap = IB_ATOMIC_GLOB;
65+
attr->max_mw = dev->lif_cfg.nmrs_per_lif;
66+
attr->max_mcast_grp = 0;
67+
attr->max_mcast_qp_attach = 0;
68+
attr->max_ah = dev->lif_cfg.nahs_per_lif;
69+
attr->max_fast_reg_page_list_len = dev->lif_cfg.npts_per_lif / 2;
70+
attr->max_pkeys = IONIC_PKEY_TBL_LEN;
71+
72+
return 0;
73+
}
74+
75+
static int ionic_query_port(struct ib_device *ibdev, u32 port,
76+
struct ib_port_attr *attr)
77+
{
78+
struct net_device *ndev;
79+
80+
if (port != 1)
81+
return -EINVAL;
82+
83+
ndev = ib_device_get_netdev(ibdev, port);
84+
85+
if (netif_running(ndev) && netif_carrier_ok(ndev)) {
86+
attr->state = IB_PORT_ACTIVE;
87+
attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
88+
} else if (netif_running(ndev)) {
89+
attr->state = IB_PORT_DOWN;
90+
attr->phys_state = IB_PORT_PHYS_STATE_POLLING;
91+
} else {
92+
attr->state = IB_PORT_DOWN;
93+
attr->phys_state = IB_PORT_PHYS_STATE_DISABLED;
94+
}
95+
96+
attr->max_mtu = iboe_get_mtu(ndev->max_mtu);
97+
attr->active_mtu = min(attr->max_mtu, iboe_get_mtu(ndev->mtu));
98+
attr->gid_tbl_len = IONIC_GID_TBL_LEN;
99+
attr->ip_gids = true;
100+
attr->port_cap_flags = 0;
101+
attr->max_msg_sz = 0x80000000;
102+
attr->pkey_tbl_len = IONIC_PKEY_TBL_LEN;
103+
attr->max_vl_num = 1;
104+
attr->subnet_prefix = 0xfe80000000000000ull;
105+
106+
dev_put(ndev);
107+
108+
return ib_get_eth_speed(ibdev, port,
109+
&attr->active_speed,
110+
&attr->active_width);
111+
}
112+
113+
static enum rdma_link_layer ionic_get_link_layer(struct ib_device *ibdev,
114+
u32 port)
115+
{
116+
return IB_LINK_LAYER_ETHERNET;
117+
}
118+
119+
static int ionic_query_pkey(struct ib_device *ibdev, u32 port, u16 index,
120+
u16 *pkey)
121+
{
122+
if (port != 1)
123+
return -EINVAL;
124+
125+
if (index != 0)
126+
return -EINVAL;
127+
128+
*pkey = IB_DEFAULT_PKEY_FULL;
129+
130+
return 0;
131+
}
132+
133+
static int ionic_modify_device(struct ib_device *ibdev, int mask,
134+
struct ib_device_modify *attr)
135+
{
136+
struct ionic_ibdev *dev = to_ionic_ibdev(ibdev);
137+
138+
if (mask & ~IB_DEVICE_MODIFY_NODE_DESC)
139+
return -EOPNOTSUPP;
140+
141+
if (mask & IB_DEVICE_MODIFY_NODE_DESC)
142+
memcpy(dev->ibdev.node_desc, attr->node_desc,
143+
IB_DEVICE_NODE_DESC_MAX);
144+
145+
return 0;
146+
}
147+
148+
static int ionic_get_port_immutable(struct ib_device *ibdev, u32 port,
149+
struct ib_port_immutable *attr)
150+
{
151+
if (port != 1)
152+
return -EINVAL;
153+
154+
attr->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP;
155+
156+
attr->pkey_tbl_len = IONIC_PKEY_TBL_LEN;
157+
attr->gid_tbl_len = IONIC_GID_TBL_LEN;
158+
attr->max_mad_size = IB_MGMT_MAD_SIZE;
159+
160+
return 0;
161+
}
162+
163+
static void ionic_get_dev_fw_str(struct ib_device *ibdev, char *str)
164+
{
165+
struct ionic_ibdev *dev = to_ionic_ibdev(ibdev);
166+
167+
ionic_lif_fw_version(dev->lif_cfg.lif, str, IB_FW_VERSION_NAME_MAX);
168+
}
169+
170+
static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
171+
char *buf)
172+
{
173+
struct ionic_ibdev *dev =
174+
rdma_device_to_drv_device(device, struct ionic_ibdev, ibdev);
175+
176+
return sysfs_emit(buf, "0x%x\n", ionic_lif_asic_rev(dev->lif_cfg.lif));
177+
}
178+
static DEVICE_ATTR_RO(hw_rev);
179+
180+
static ssize_t hca_type_show(struct device *device,
181+
struct device_attribute *attr, char *buf)
182+
{
183+
struct ionic_ibdev *dev =
184+
rdma_device_to_drv_device(device, struct ionic_ibdev, ibdev);
185+
186+
return sysfs_emit(buf, "%s\n", dev->ibdev.node_desc);
187+
}
188+
static DEVICE_ATTR_RO(hca_type);
189+
190+
static struct attribute *ionic_rdma_attributes[] = {
191+
&dev_attr_hw_rev.attr,
192+
&dev_attr_hca_type.attr,
193+
NULL
194+
};
195+
196+
static const struct attribute_group ionic_rdma_attr_group = {
197+
.attrs = ionic_rdma_attributes,
198+
};
199+
200+
static void ionic_disassociate_ucontext(struct ib_ucontext *ibcontext)
201+
{
202+
/*
203+
* Dummy define disassociate_ucontext so that it does not
204+
* wait for user context before cleaning up hw resources.
205+
*/
206+
}
207+
18208
static const struct ib_device_ops ionic_dev_ops = {
19209
.owner = THIS_MODULE,
20210
.driver_id = RDMA_DRIVER_IONIC,
@@ -50,6 +240,16 @@ static const struct ib_device_ops ionic_dev_ops = {
50240
.poll_cq = ionic_poll_cq,
51241
.req_notify_cq = ionic_req_notify_cq,
52242

243+
.query_device = ionic_query_device,
244+
.query_port = ionic_query_port,
245+
.get_link_layer = ionic_get_link_layer,
246+
.query_pkey = ionic_query_pkey,
247+
.modify_device = ionic_modify_device,
248+
.get_port_immutable = ionic_get_port_immutable,
249+
.get_dev_fw_str = ionic_get_dev_fw_str,
250+
.device_group = &ionic_rdma_attr_group,
251+
.disassociate_ucontext = ionic_disassociate_ucontext,
252+
53253
INIT_RDMA_OBJ_SIZE(ib_ucontext, ionic_ctx, ibctx),
54254
INIT_RDMA_OBJ_SIZE(ib_pd, ionic_pd, ibpd),
55255
INIT_RDMA_OBJ_SIZE(ib_ah, ionic_ah, ibah),

drivers/infiniband/hw/ionic/ionic_ibdev.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
#define IONIC_AQ_COUNT 4
2727
#define IONIC_EQ_ISR_BUDGET 10
2828
#define IONIC_EQ_WORK_BUDGET 1000
29+
#define IONIC_MAX_RD_ATOM 16
30+
#define IONIC_PKEY_TBL_LEN 1
31+
#define IONIC_GID_TBL_LEN 256
32+
33+
#define IONIC_SPEC_HIGH 8
2934
#define IONIC_MAX_PD 1024
3035
#define IONIC_SPEC_HIGH 8
3136
#define IONIC_SQCMB_ORDER 5

drivers/infiniband/hw/ionic/ionic_lif_cfg.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,13 @@ struct net_device *ionic_lif_netdev(struct ionic_lif *lif)
9999
dev_hold(netdev);
100100
return netdev;
101101
}
102+
103+
void ionic_lif_fw_version(struct ionic_lif *lif, char *str, size_t len)
104+
{
105+
strscpy(str, lif->ionic->idev.dev_info.fw_version, len);
106+
}
107+
108+
u8 ionic_lif_asic_rev(struct ionic_lif *lif)
109+
{
110+
return lif->ionic->idev.dev_info.asic_rev;
111+
}

drivers/infiniband/hw/ionic/ionic_lif_cfg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,7 @@ struct ionic_lif_cfg {
6060

6161
void ionic_fill_lif_cfg(struct ionic_lif *lif, struct ionic_lif_cfg *cfg);
6262
struct net_device *ionic_lif_netdev(struct ionic_lif *lif);
63+
void ionic_lif_fw_version(struct ionic_lif *lif, char *str, size_t len);
64+
u8 ionic_lif_asic_rev(struct ionic_lif *lif);
6365

6466
#endif /* _IONIC_LIF_CFG_H_ */

0 commit comments

Comments
 (0)