Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (c) 2022, Microsoft Corporation. All rights reserved.
  4 */
  5
  6#include "mana_ib.h"
  7#include <net/mana/mana_auxiliary.h>
 
  8
  9MODULE_DESCRIPTION("Microsoft Azure Network Adapter IB driver");
 10MODULE_LICENSE("GPL");
 11MODULE_IMPORT_NS(NET_MANA);
 12
 13static const struct ib_device_ops mana_ib_dev_ops = {
 14	.owner = THIS_MODULE,
 15	.driver_id = RDMA_DRIVER_MANA,
 16	.uverbs_abi_ver = MANA_IB_UVERBS_ABI_VERSION,
 17
 
 18	.alloc_pd = mana_ib_alloc_pd,
 19	.alloc_ucontext = mana_ib_alloc_ucontext,
 20	.create_cq = mana_ib_create_cq,
 21	.create_qp = mana_ib_create_qp,
 22	.create_rwq_ind_table = mana_ib_create_rwq_ind_table,
 23	.create_wq = mana_ib_create_wq,
 24	.dealloc_pd = mana_ib_dealloc_pd,
 25	.dealloc_ucontext = mana_ib_dealloc_ucontext,
 
 26	.dereg_mr = mana_ib_dereg_mr,
 27	.destroy_cq = mana_ib_destroy_cq,
 28	.destroy_qp = mana_ib_destroy_qp,
 29	.destroy_rwq_ind_table = mana_ib_destroy_rwq_ind_table,
 30	.destroy_wq = mana_ib_destroy_wq,
 31	.disassociate_ucontext = mana_ib_disassociate_ucontext,
 
 32	.get_port_immutable = mana_ib_get_port_immutable,
 33	.mmap = mana_ib_mmap,
 34	.modify_qp = mana_ib_modify_qp,
 35	.modify_wq = mana_ib_modify_wq,
 36	.query_device = mana_ib_query_device,
 37	.query_gid = mana_ib_query_gid,
 
 38	.query_port = mana_ib_query_port,
 39	.reg_user_mr = mana_ib_reg_user_mr,
 40
 41	INIT_RDMA_OBJ_SIZE(ib_cq, mana_ib_cq, ibcq),
 42	INIT_RDMA_OBJ_SIZE(ib_pd, mana_ib_pd, ibpd),
 43	INIT_RDMA_OBJ_SIZE(ib_qp, mana_ib_qp, ibqp),
 44	INIT_RDMA_OBJ_SIZE(ib_ucontext, mana_ib_ucontext, ibucontext),
 45	INIT_RDMA_OBJ_SIZE(ib_rwq_ind_table, mana_ib_rwq_ind_table,
 46			   ib_ind_table),
 47};
 48
 49static int mana_ib_probe(struct auxiliary_device *adev,
 50			 const struct auxiliary_device_id *id)
 51{
 52	struct mana_adev *madev = container_of(adev, struct mana_adev, adev);
 53	struct gdma_dev *mdev = madev->mdev;
 
 54	struct mana_context *mc;
 55	struct mana_ib_dev *dev;
 
 56	int ret;
 57
 58	mc = mdev->driver_data;
 59
 60	dev = ib_alloc_device(mana_ib_dev, ib_dev);
 61	if (!dev)
 62		return -ENOMEM;
 63
 64	ib_set_device_ops(&dev->ib_dev, &mana_ib_dev_ops);
 65
 66	dev->ib_dev.phys_port_cnt = mc->num_ports;
 67
 68	ibdev_dbg(&dev->ib_dev, "mdev=%p id=%d num_ports=%d\n", mdev,
 69		  mdev->dev_id.as_uint32, dev->ib_dev.phys_port_cnt);
 70
 71	dev->ib_dev.node_type = RDMA_NODE_IB_CA;
 72
 73	/*
 74	 * num_comp_vectors needs to set to the max MSIX index
 75	 * when interrupts and event queues are implemented
 76	 */
 77	dev->ib_dev.num_comp_vectors = 1;
 78	dev->ib_dev.dev.parent = mdev->gdma_context->dev;
 79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 80	ret = mana_gd_register_device(&mdev->gdma_context->mana_ib);
 81	if (ret) {
 82		ibdev_err(&dev->ib_dev, "Failed to register device, ret %d",
 83			  ret);
 84		goto free_ib_device;
 85	}
 86	dev->gdma_dev = &mdev->gdma_context->mana_ib;
 87
 88	ret = mana_ib_gd_query_adapter_caps(dev);
 89	if (ret) {
 90		ibdev_err(&dev->ib_dev, "Failed to query device caps, ret %d",
 91			  ret);
 92		goto deregister_device;
 93	}
 94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 95	ret = ib_register_device(&dev->ib_dev, "mana_%d",
 96				 mdev->gdma_context->dev);
 97	if (ret)
 98		goto deregister_device;
 99
100	dev_set_drvdata(&adev->dev, dev);
101
102	return 0;
103
 
 
 
 
 
104deregister_device:
105	mana_gd_deregister_device(dev->gdma_dev);
106free_ib_device:
107	ib_dealloc_device(&dev->ib_dev);
108	return ret;
109}
110
111static void mana_ib_remove(struct auxiliary_device *adev)
112{
113	struct mana_ib_dev *dev = dev_get_drvdata(&adev->dev);
114
115	ib_unregister_device(&dev->ib_dev);
116
 
 
117	mana_gd_deregister_device(dev->gdma_dev);
118
119	ib_dealloc_device(&dev->ib_dev);
120}
121
122static const struct auxiliary_device_id mana_id_table[] = {
123	{
124		.name = "mana.rdma",
125	},
126	{},
127};
128
129MODULE_DEVICE_TABLE(auxiliary, mana_id_table);
130
131static struct auxiliary_driver mana_driver = {
132	.name = "rdma",
133	.probe = mana_ib_probe,
134	.remove = mana_ib_remove,
135	.id_table = mana_id_table,
136};
137
138module_auxiliary_driver(mana_driver);
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (c) 2022, Microsoft Corporation. All rights reserved.
  4 */
  5
  6#include "mana_ib.h"
  7#include <net/mana/mana_auxiliary.h>
  8#include <net/addrconf.h>
  9
 10MODULE_DESCRIPTION("Microsoft Azure Network Adapter IB driver");
 11MODULE_LICENSE("GPL");
 12MODULE_IMPORT_NS("NET_MANA");
 13
 14static const struct ib_device_ops mana_ib_dev_ops = {
 15	.owner = THIS_MODULE,
 16	.driver_id = RDMA_DRIVER_MANA,
 17	.uverbs_abi_ver = MANA_IB_UVERBS_ABI_VERSION,
 18
 19	.add_gid = mana_ib_gd_add_gid,
 20	.alloc_pd = mana_ib_alloc_pd,
 21	.alloc_ucontext = mana_ib_alloc_ucontext,
 22	.create_cq = mana_ib_create_cq,
 23	.create_qp = mana_ib_create_qp,
 24	.create_rwq_ind_table = mana_ib_create_rwq_ind_table,
 25	.create_wq = mana_ib_create_wq,
 26	.dealloc_pd = mana_ib_dealloc_pd,
 27	.dealloc_ucontext = mana_ib_dealloc_ucontext,
 28	.del_gid = mana_ib_gd_del_gid,
 29	.dereg_mr = mana_ib_dereg_mr,
 30	.destroy_cq = mana_ib_destroy_cq,
 31	.destroy_qp = mana_ib_destroy_qp,
 32	.destroy_rwq_ind_table = mana_ib_destroy_rwq_ind_table,
 33	.destroy_wq = mana_ib_destroy_wq,
 34	.disassociate_ucontext = mana_ib_disassociate_ucontext,
 35	.get_link_layer = mana_ib_get_link_layer,
 36	.get_port_immutable = mana_ib_get_port_immutable,
 37	.mmap = mana_ib_mmap,
 38	.modify_qp = mana_ib_modify_qp,
 39	.modify_wq = mana_ib_modify_wq,
 40	.query_device = mana_ib_query_device,
 41	.query_gid = mana_ib_query_gid,
 42	.query_pkey = mana_ib_query_pkey,
 43	.query_port = mana_ib_query_port,
 44	.reg_user_mr = mana_ib_reg_user_mr,
 45
 46	INIT_RDMA_OBJ_SIZE(ib_cq, mana_ib_cq, ibcq),
 47	INIT_RDMA_OBJ_SIZE(ib_pd, mana_ib_pd, ibpd),
 48	INIT_RDMA_OBJ_SIZE(ib_qp, mana_ib_qp, ibqp),
 49	INIT_RDMA_OBJ_SIZE(ib_ucontext, mana_ib_ucontext, ibucontext),
 50	INIT_RDMA_OBJ_SIZE(ib_rwq_ind_table, mana_ib_rwq_ind_table,
 51			   ib_ind_table),
 52};
 53
 54static int mana_ib_probe(struct auxiliary_device *adev,
 55			 const struct auxiliary_device_id *id)
 56{
 57	struct mana_adev *madev = container_of(adev, struct mana_adev, adev);
 58	struct gdma_dev *mdev = madev->mdev;
 59	struct net_device *ndev;
 60	struct mana_context *mc;
 61	struct mana_ib_dev *dev;
 62	u8 mac_addr[ETH_ALEN];
 63	int ret;
 64
 65	mc = mdev->driver_data;
 66
 67	dev = ib_alloc_device(mana_ib_dev, ib_dev);
 68	if (!dev)
 69		return -ENOMEM;
 70
 71	ib_set_device_ops(&dev->ib_dev, &mana_ib_dev_ops);
 72
 73	dev->ib_dev.phys_port_cnt = mc->num_ports;
 74
 75	ibdev_dbg(&dev->ib_dev, "mdev=%p id=%d num_ports=%d\n", mdev,
 76		  mdev->dev_id.as_uint32, dev->ib_dev.phys_port_cnt);
 77
 78	dev->ib_dev.node_type = RDMA_NODE_IB_CA;
 79
 80	/*
 81	 * num_comp_vectors needs to set to the max MSIX index
 82	 * when interrupts and event queues are implemented
 83	 */
 84	dev->ib_dev.num_comp_vectors = mdev->gdma_context->max_num_queues;
 85	dev->ib_dev.dev.parent = mdev->gdma_context->dev;
 86
 87	rcu_read_lock(); /* required to get primary netdev */
 88	ndev = mana_get_primary_netdev_rcu(mc, 0);
 89	if (!ndev) {
 90		rcu_read_unlock();
 91		ret = -ENODEV;
 92		ibdev_err(&dev->ib_dev, "Failed to get netdev for IB port 1");
 93		goto free_ib_device;
 94	}
 95	ether_addr_copy(mac_addr, ndev->dev_addr);
 96	addrconf_addr_eui48((u8 *)&dev->ib_dev.node_guid, ndev->dev_addr);
 97	ret = ib_device_set_netdev(&dev->ib_dev, ndev, 1);
 98	rcu_read_unlock();
 99	if (ret) {
100		ibdev_err(&dev->ib_dev, "Failed to set ib netdev, ret %d", ret);
101		goto free_ib_device;
102	}
103
104	ret = mana_gd_register_device(&mdev->gdma_context->mana_ib);
105	if (ret) {
106		ibdev_err(&dev->ib_dev, "Failed to register device, ret %d",
107			  ret);
108		goto free_ib_device;
109	}
110	dev->gdma_dev = &mdev->gdma_context->mana_ib;
111
112	ret = mana_ib_gd_query_adapter_caps(dev);
113	if (ret) {
114		ibdev_err(&dev->ib_dev, "Failed to query device caps, ret %d",
115			  ret);
116		goto deregister_device;
117	}
118
119	ret = mana_ib_create_eqs(dev);
120	if (ret) {
121		ibdev_err(&dev->ib_dev, "Failed to create EQs, ret %d", ret);
122		goto deregister_device;
123	}
124
125	ret = mana_ib_gd_create_rnic_adapter(dev);
126	if (ret)
127		goto destroy_eqs;
128
129	xa_init_flags(&dev->qp_table_wq, XA_FLAGS_LOCK_IRQ);
130	ret = mana_ib_gd_config_mac(dev, ADDR_OP_ADD, mac_addr);
131	if (ret) {
132		ibdev_err(&dev->ib_dev, "Failed to add Mac address, ret %d",
133			  ret);
134		goto destroy_rnic;
135	}
136
137	ret = ib_register_device(&dev->ib_dev, "mana_%d",
138				 mdev->gdma_context->dev);
139	if (ret)
140		goto destroy_rnic;
141
142	dev_set_drvdata(&adev->dev, dev);
143
144	return 0;
145
146destroy_rnic:
147	xa_destroy(&dev->qp_table_wq);
148	mana_ib_gd_destroy_rnic_adapter(dev);
149destroy_eqs:
150	mana_ib_destroy_eqs(dev);
151deregister_device:
152	mana_gd_deregister_device(dev->gdma_dev);
153free_ib_device:
154	ib_dealloc_device(&dev->ib_dev);
155	return ret;
156}
157
158static void mana_ib_remove(struct auxiliary_device *adev)
159{
160	struct mana_ib_dev *dev = dev_get_drvdata(&adev->dev);
161
162	ib_unregister_device(&dev->ib_dev);
163	xa_destroy(&dev->qp_table_wq);
164	mana_ib_gd_destroy_rnic_adapter(dev);
165	mana_ib_destroy_eqs(dev);
166	mana_gd_deregister_device(dev->gdma_dev);
 
167	ib_dealloc_device(&dev->ib_dev);
168}
169
170static const struct auxiliary_device_id mana_id_table[] = {
171	{
172		.name = "mana.rdma",
173	},
174	{},
175};
176
177MODULE_DEVICE_TABLE(auxiliary, mana_id_table);
178
179static struct auxiliary_driver mana_driver = {
180	.name = "rdma",
181	.probe = mana_ib_probe,
182	.remove = mana_ib_remove,
183	.id_table = mana_id_table,
184};
185
186module_auxiliary_driver(mana_driver);