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>
This commit is contained in:
Abhijit Gangurde 2025-09-03 11:46:04 +05:30 committed by Leon Romanovsky
parent b83c62055b
commit 2075bbe8ef
4 changed files with 217 additions and 0 deletions

View file

@ -3,7 +3,11 @@
#include <linux/module.h>
#include <linux/printk.h>
#include <linux/pci.h>
#include <linux/irq.h>
#include <net/addrconf.h>
#include <rdma/ib_addr.h>
#include <rdma/ib_mad.h>
#include "ionic_ibdev.h"
@ -15,6 +19,192 @@ MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
MODULE_LICENSE("GPL");
MODULE_IMPORT_NS("NET_IONIC");
static int ionic_query_device(struct ib_device *ibdev,
struct ib_device_attr *attr,
struct ib_udata *udata)
{
struct ionic_ibdev *dev = to_ionic_ibdev(ibdev);
struct net_device *ndev;
ndev = ib_device_get_netdev(ibdev, 1);
addrconf_ifid_eui48((u8 *)&attr->sys_image_guid, ndev);
dev_put(ndev);
attr->max_mr_size = dev->lif_cfg.npts_per_lif * PAGE_SIZE / 2;
attr->page_size_cap = dev->lif_cfg.page_size_supported;
attr->vendor_id = to_pci_dev(dev->lif_cfg.hwdev)->vendor;
attr->vendor_part_id = to_pci_dev(dev->lif_cfg.hwdev)->device;
attr->hw_ver = ionic_lif_asic_rev(dev->lif_cfg.lif);
attr->fw_ver = 0;
attr->max_qp = dev->lif_cfg.qp_count;
attr->max_qp_wr = IONIC_MAX_DEPTH;
attr->device_cap_flags =
IB_DEVICE_MEM_WINDOW |
IB_DEVICE_MEM_MGT_EXTENSIONS |
IB_DEVICE_MEM_WINDOW_TYPE_2B |
0;
attr->max_send_sge =
min(ionic_v1_send_wqe_max_sge(dev->lif_cfg.max_stride, 0, false),
IONIC_SPEC_HIGH);
attr->max_recv_sge =
min(ionic_v1_recv_wqe_max_sge(dev->lif_cfg.max_stride, 0, false),
IONIC_SPEC_HIGH);
attr->max_sge_rd = attr->max_send_sge;
attr->max_cq = dev->lif_cfg.cq_count / dev->lif_cfg.udma_count;
attr->max_cqe = IONIC_MAX_CQ_DEPTH - IONIC_CQ_GRACE;
attr->max_mr = dev->lif_cfg.nmrs_per_lif;
attr->max_pd = IONIC_MAX_PD;
attr->max_qp_rd_atom = IONIC_MAX_RD_ATOM;
attr->max_ee_rd_atom = 0;
attr->max_res_rd_atom = IONIC_MAX_RD_ATOM;
attr->max_qp_init_rd_atom = IONIC_MAX_RD_ATOM;
attr->max_ee_init_rd_atom = 0;
attr->atomic_cap = IB_ATOMIC_GLOB;
attr->masked_atomic_cap = IB_ATOMIC_GLOB;
attr->max_mw = dev->lif_cfg.nmrs_per_lif;
attr->max_mcast_grp = 0;
attr->max_mcast_qp_attach = 0;
attr->max_ah = dev->lif_cfg.nahs_per_lif;
attr->max_fast_reg_page_list_len = dev->lif_cfg.npts_per_lif / 2;
attr->max_pkeys = IONIC_PKEY_TBL_LEN;
return 0;
}
static int ionic_query_port(struct ib_device *ibdev, u32 port,
struct ib_port_attr *attr)
{
struct net_device *ndev;
if (port != 1)
return -EINVAL;
ndev = ib_device_get_netdev(ibdev, port);
if (netif_running(ndev) && netif_carrier_ok(ndev)) {
attr->state = IB_PORT_ACTIVE;
attr->phys_state = IB_PORT_PHYS_STATE_LINK_UP;
} else if (netif_running(ndev)) {
attr->state = IB_PORT_DOWN;
attr->phys_state = IB_PORT_PHYS_STATE_POLLING;
} else {
attr->state = IB_PORT_DOWN;
attr->phys_state = IB_PORT_PHYS_STATE_DISABLED;
}
attr->max_mtu = iboe_get_mtu(ndev->max_mtu);
attr->active_mtu = min(attr->max_mtu, iboe_get_mtu(ndev->mtu));
attr->gid_tbl_len = IONIC_GID_TBL_LEN;
attr->ip_gids = true;
attr->port_cap_flags = 0;
attr->max_msg_sz = 0x80000000;
attr->pkey_tbl_len = IONIC_PKEY_TBL_LEN;
attr->max_vl_num = 1;
attr->subnet_prefix = 0xfe80000000000000ull;
dev_put(ndev);
return ib_get_eth_speed(ibdev, port,
&attr->active_speed,
&attr->active_width);
}
static enum rdma_link_layer ionic_get_link_layer(struct ib_device *ibdev,
u32 port)
{
return IB_LINK_LAYER_ETHERNET;
}
static int ionic_query_pkey(struct ib_device *ibdev, u32 port, u16 index,
u16 *pkey)
{
if (port != 1)
return -EINVAL;
if (index != 0)
return -EINVAL;
*pkey = IB_DEFAULT_PKEY_FULL;
return 0;
}
static int ionic_modify_device(struct ib_device *ibdev, int mask,
struct ib_device_modify *attr)
{
struct ionic_ibdev *dev = to_ionic_ibdev(ibdev);
if (mask & ~IB_DEVICE_MODIFY_NODE_DESC)
return -EOPNOTSUPP;
if (mask & IB_DEVICE_MODIFY_NODE_DESC)
memcpy(dev->ibdev.node_desc, attr->node_desc,
IB_DEVICE_NODE_DESC_MAX);
return 0;
}
static int ionic_get_port_immutable(struct ib_device *ibdev, u32 port,
struct ib_port_immutable *attr)
{
if (port != 1)
return -EINVAL;
attr->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP;
attr->pkey_tbl_len = IONIC_PKEY_TBL_LEN;
attr->gid_tbl_len = IONIC_GID_TBL_LEN;
attr->max_mad_size = IB_MGMT_MAD_SIZE;
return 0;
}
static void ionic_get_dev_fw_str(struct ib_device *ibdev, char *str)
{
struct ionic_ibdev *dev = to_ionic_ibdev(ibdev);
ionic_lif_fw_version(dev->lif_cfg.lif, str, IB_FW_VERSION_NAME_MAX);
}
static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
char *buf)
{
struct ionic_ibdev *dev =
rdma_device_to_drv_device(device, struct ionic_ibdev, ibdev);
return sysfs_emit(buf, "0x%x\n", ionic_lif_asic_rev(dev->lif_cfg.lif));
}
static DEVICE_ATTR_RO(hw_rev);
static ssize_t hca_type_show(struct device *device,
struct device_attribute *attr, char *buf)
{
struct ionic_ibdev *dev =
rdma_device_to_drv_device(device, struct ionic_ibdev, ibdev);
return sysfs_emit(buf, "%s\n", dev->ibdev.node_desc);
}
static DEVICE_ATTR_RO(hca_type);
static struct attribute *ionic_rdma_attributes[] = {
&dev_attr_hw_rev.attr,
&dev_attr_hca_type.attr,
NULL
};
static const struct attribute_group ionic_rdma_attr_group = {
.attrs = ionic_rdma_attributes,
};
static void ionic_disassociate_ucontext(struct ib_ucontext *ibcontext)
{
/*
* Dummy define disassociate_ucontext so that it does not
* wait for user context before cleaning up hw resources.
*/
}
static const struct ib_device_ops ionic_dev_ops = {
.owner = THIS_MODULE,
.driver_id = RDMA_DRIVER_IONIC,
@ -50,6 +240,16 @@ static const struct ib_device_ops ionic_dev_ops = {
.poll_cq = ionic_poll_cq,
.req_notify_cq = ionic_req_notify_cq,
.query_device = ionic_query_device,
.query_port = ionic_query_port,
.get_link_layer = ionic_get_link_layer,
.query_pkey = ionic_query_pkey,
.modify_device = ionic_modify_device,
.get_port_immutable = ionic_get_port_immutable,
.get_dev_fw_str = ionic_get_dev_fw_str,
.device_group = &ionic_rdma_attr_group,
.disassociate_ucontext = ionic_disassociate_ucontext,
INIT_RDMA_OBJ_SIZE(ib_ucontext, ionic_ctx, ibctx),
INIT_RDMA_OBJ_SIZE(ib_pd, ionic_pd, ibpd),
INIT_RDMA_OBJ_SIZE(ib_ah, ionic_ah, ibah),

View file

@ -26,6 +26,11 @@
#define IONIC_AQ_COUNT 4
#define IONIC_EQ_ISR_BUDGET 10
#define IONIC_EQ_WORK_BUDGET 1000
#define IONIC_MAX_RD_ATOM 16
#define IONIC_PKEY_TBL_LEN 1
#define IONIC_GID_TBL_LEN 256
#define IONIC_SPEC_HIGH 8
#define IONIC_MAX_PD 1024
#define IONIC_SPEC_HIGH 8
#define IONIC_SQCMB_ORDER 5

View file

@ -99,3 +99,13 @@ struct net_device *ionic_lif_netdev(struct ionic_lif *lif)
dev_hold(netdev);
return netdev;
}
void ionic_lif_fw_version(struct ionic_lif *lif, char *str, size_t len)
{
strscpy(str, lif->ionic->idev.dev_info.fw_version, len);
}
u8 ionic_lif_asic_rev(struct ionic_lif *lif)
{
return lif->ionic->idev.dev_info.asic_rev;
}

View file

@ -60,5 +60,7 @@ struct ionic_lif_cfg {
void ionic_fill_lif_cfg(struct ionic_lif *lif, struct ionic_lif_cfg *cfg);
struct net_device *ionic_lif_netdev(struct ionic_lif *lif);
void ionic_lif_fw_version(struct ionic_lif *lif, char *str, size_t len);
u8 ionic_lif_asic_rev(struct ionic_lif *lif);
#endif /* _IONIC_LIF_CFG_H_ */