[openib-general] [PATCH][RFC] Put phys_port_cnt in device struct
Roland Dreier
roland at topspin.com
Fri Nov 5 21:39:38 PST 2004
It seems that there are lots of places where consumers need to
allocate an entire ib_device_attr struct and deal with the possibility
that ib_query_device() might fail, just to find out how many ports a
device has. We discussed this before and concluded that it was OK to
assume that the number of physical ports is constant.
This patch simplifies a lot of code by making phys_port_cnt a field in
struct ib_device, so consumers can just read the value when they need it.
Does this look good to commit?
Thanks,
Roland
Index: infiniband/ulp/ipoib/ipoib_main.c
===================================================================
--- infiniband/ulp/ipoib/ipoib_main.c (revision 1167)
+++ infiniband/ulp/ipoib/ipoib_main.c (working copy)
@@ -821,19 +821,12 @@
static void ipoib_add_one(struct ib_device *device)
{
- struct ib_device_attr props;
int port;
- if (ib_query_device(device, &props)) {
- printk(KERN_WARNING "%s: ib_device_properties_get failed\n",
- device->name);
- return;
- }
-
if (device->node_type == IB_NODE_SWITCH)
ipoib_add_port("ib%d", device, 0);
else
- for (port = 1; port <= props.phys_port_cnt; ++port)
+ for (port = 1; port <= device->phys_port_cnt; ++port)
ipoib_add_port("ib%d", device, port);
}
Index: infiniband/include/ib_verbs.h
===================================================================
--- infiniband/include/ib_verbs.h (revision 1167)
+++ infiniband/include/ib_verbs.h (working copy)
@@ -91,7 +91,6 @@
int max_cqe;
int max_mr;
int max_pd;
- int phys_port_cnt;
int max_qp_rd_atom;
int max_ee_rd_atom;
int max_res_rd_atom;
@@ -794,6 +793,7 @@
} reg_state;
u8 node_type;
+ u8 phys_port_cnt;
};
struct ib_client {
Index: infiniband/core/device.c
===================================================================
--- infiniband/core/device.c (revision 1167)
+++ infiniband/core/device.c (working copy)
@@ -191,7 +191,6 @@
int ib_register_device(struct ib_device *device)
{
struct ib_device_private *priv;
- struct ib_device_attr prop;
int ret;
down(&device_sem);
@@ -217,18 +216,11 @@
*priv = (struct ib_device_private) { 0 };
- ret = device->query_device(device, &prop);
- if (ret) {
- printk(KERN_WARNING "query_device failed for %s\n",
- device->name);
- goto out_free;
- }
-
if (device->node_type == IB_NODE_SWITCH) {
priv->start_port = priv->end_port = 0;
} else {
priv->start_port = 1;
- priv->end_port = prop.phys_port_cnt;
+ priv->end_port = device->phys_port_cnt;
}
priv->port_data = kmalloc((priv->end_port + 1) * sizeof (struct ib_port_data),
@@ -236,6 +228,7 @@
if (!priv->port_data) {
printk(KERN_WARNING "Couldn't allocate port info for %s\n",
device->name);
+ ret = -ENOMEM;
goto out_free;
}
@@ -253,7 +246,8 @@
goto out_free_port;
}
- if (ib_device_register_sysfs(device)) {
+ ret = ib_device_register_sysfs(device);
+ if (ret) {
printk(KERN_WARNING "Couldn't register device %s with driver model\n",
device->name);
goto out_free_cache;
Index: infiniband/core/user_mad.c
===================================================================
--- infiniband/core/user_mad.c (revision 1167)
+++ infiniband/core/user_mad.c (working copy)
@@ -489,12 +489,8 @@
if (device->node_type == IB_NODE_SWITCH)
s = e = 0;
else {
- struct ib_device_attr attr;
- if (ib_query_device(device, &attr))
- return;
-
s = 1;
- e = attr.phys_port_cnt;
+ e = device->phys_port_cnt;
}
umad_dev = kmalloc(sizeof *umad_dev +
Index: infiniband/core/mad.c
===================================================================
--- infiniband/core/mad.c (revision 1167)
+++ infiniband/core/mad.c (working copy)
@@ -244,7 +244,6 @@
mad_agent_priv->qp_info = &port_priv->qp_info[qpn];
mad_agent_priv->reg_req = reg_req;
mad_agent_priv->rmpp_version = rmpp_version;
- mad_agent_priv->phys_port_cnt = port_priv->phys_port_cnt;
mad_agent_priv->agent.device = device;
mad_agent_priv->agent.recv_handler = recv_handler;
mad_agent_priv->agent.send_handler = send_handler;
@@ -418,7 +417,7 @@
if (!smi_handle_dr_smp_recv((struct ib_smp *)&mad_priv->mad,
mad_agent->device->node_type,
mad_agent->port_num,
- mad_agent_priv->phys_port_cnt)) {
+ mad_agent->device->phys_port_cnt)) {
ret = -EINVAL;
kmem_cache_free(ib_mad_cache, mad_priv);
goto error1;
@@ -1085,7 +1084,7 @@
if (!smi_handle_dr_smp_recv(smp,
port_priv->device->node_type,
port_priv->port_num,
- port_priv->phys_port_cnt))
+ port_priv->device->phys_port_cnt))
goto out;
if (!smi_check_forward_dr_smp(smp))
goto out;
@@ -1125,7 +1124,7 @@
(struct ib_smp *)response,
port_priv->device->node_type,
port_priv->port_num,
- port_priv->phys_port_cnt)) {
+ port_priv->device->phys_port_cnt)) {
kfree(response);
goto out;
}
@@ -1842,8 +1841,7 @@
* Create the QP, PD, MR, and CQ if needed
*/
static int ib_mad_port_open(struct ib_device *device,
- int port_num,
- int num_ports)
+ int port_num)
{
int ret, cq_size;
u64 iova = 0;
@@ -1872,7 +1870,6 @@
memset(port_priv, 0, sizeof *port_priv);
port_priv->device = device;
port_priv->port_num = port_num;
- port_priv->phys_port_cnt = num_ports;
spin_lock_init(&port_priv->reg_lock);
cq_size = (IB_MAD_QP_SEND_SIZE + IB_MAD_QP_RECV_SIZE) * 2;
@@ -1985,29 +1982,22 @@
static void ib_mad_init_device(struct ib_device *device)
{
int ret, num_ports, cur_port, i, ret2;
- struct ib_device_attr device_attr;
- ret = ib_query_device(device, &device_attr);
- if (ret) {
- printk(KERN_ERR PFX "Couldn't query device %s\n", device->name);
- goto error_device_query;
- }
-
if (device->node_type == IB_NODE_SWITCH) {
num_ports = 1;
cur_port = 0;
} else {
- num_ports = device_attr.phys_port_cnt;
+ num_ports = device->phys_port_cnt;
cur_port = 1;
}
for (i = 0; i < num_ports; i++, cur_port++) {
- ret = ib_mad_port_open(device, cur_port, num_ports);
+ ret = ib_mad_port_open(device, cur_port);
if (ret) {
printk(KERN_ERR PFX "Couldn't open %s port %d\n",
device->name, cur_port);
goto error_device_open;
}
- ret = ib_agent_port_open(device, cur_port, num_ports);
+ ret = ib_agent_port_open(device, cur_port);
if (ret) {
printk(KERN_ERR PFX "Couldn't open %s port %d for agents\n",
device->name, cur_port);
@@ -2039,20 +2029,13 @@
static void ib_mad_remove_device(struct ib_device *device)
{
- int ret, i, num_ports, cur_port, ret2;
- struct ib_device_attr device_attr;
+ int ret = 0, i, num_ports, cur_port, ret2;
- ret = ib_query_device(device, &device_attr);
- if (ret) {
- printk(KERN_ERR PFX "Couldn't query device %s\n", device->name);
- goto error_device_query;
- }
-
if (device->node_type == IB_NODE_SWITCH) {
num_ports = 1;
cur_port = 0;
} else {
- num_ports = device_attr.phys_port_cnt;
+ num_ports = device->phys_port_cnt;
cur_port = 1;
}
for (i = 0; i < num_ports; i++, cur_port++) {
@@ -2071,9 +2054,6 @@
ret = ret2;
}
}
-
-error_device_query:
- return;
}
static struct ib_client mad_client = {
Index: infiniband/core/agent.h
===================================================================
--- infiniband/core/agent.h (revision 1167)
+++ infiniband/core/agent.h (working copy)
@@ -27,8 +27,7 @@
#define __AGENT_H_
extern int ib_agent_port_open(struct ib_device *device,
- int port_num,
- int phys_port_cnt);
+ int port_num);
extern int ib_agent_port_close(struct ib_device *device, int port_num);
Index: infiniband/core/sysfs.c
===================================================================
--- infiniband/core/sysfs.c (revision 1167)
+++ infiniband/core/sysfs.c (working copy)
@@ -640,14 +640,9 @@
if (ret)
goto err_put;
} else {
- struct ib_device_attr attr;
int i;
- ret = ib_query_device(device, &attr);
- if (ret)
- goto err_put;
-
- for (i = 1; i <= attr.phys_port_cnt; ++i) {
+ for (i = 1; i <= device->phys_port_cnt; ++i) {
ret = add_port(device, i);
if (ret)
goto err_put;
Index: infiniband/core/sa_query.c
===================================================================
--- infiniband/core/sa_query.c (revision 1167)
+++ infiniband/core/sa_query.c (working copy)
@@ -696,12 +696,8 @@
if (device->node_type == IB_NODE_SWITCH)
s = e = 0;
else {
- struct ib_device_attr attr;
- if (ib_query_device(device, &attr))
- return;
-
s = 1;
- e = attr.phys_port_cnt;
+ e = device->phys_port_cnt;
}
sa_dev = kmalloc(sizeof *sa_dev +
Index: infiniband/hw/mthca/mthca_provider.c
===================================================================
--- infiniband/hw/mthca/mthca_provider.c (revision 1167)
+++ infiniband/hw/mthca/mthca_provider.c (working copy)
@@ -47,7 +47,6 @@
if (!in_mad || !out_mad)
goto out;
- props->phys_port_cnt = to_mdev(ibdev)->limits.num_ports;
props->fw_ver = to_mdev(ibdev)->fw_ver;
memset(in_mad, 0, sizeof *in_mad);
@@ -573,6 +572,7 @@
strlcpy(dev->ib_dev.name, "mthca%d", IB_DEVICE_NAME_MAX);
dev->ib_dev.node_type = IB_NODE_CA;
+ dev->ib_dev.phys_port_cnt = dev->limits.num_ports;
dev->ib_dev.dma_device = dev->pdev;
dev->ib_dev.class_dev.dev = &dev->pdev->dev;
dev->ib_dev.query_device = mthca_query_device;
More information about the general
mailing list