[openib-general] [PATCH] extend ib_device node_type to include iWarp
Sean Hefty
sean.hefty at intel.com
Mon Jan 30 15:42:22 PST 2006
Here's an updated version that actually does the device checks correctly, and
hopefully clarifies how node_type is formatted. I include two helper functions
to extract the transport and device information from the node_type.
I tried to include related changes to all files with this patch, so a few
more files are affected than with the previous patch.
Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
Index: ulp/ipoib/ipoib_main.c
===================================================================
--- ulp/ipoib/ipoib_main.c (revision 5098)
+++ ulp/ipoib/ipoib_main.c (working copy)
@@ -1078,13 +1078,16 @@ static void ipoib_add_one(struct ib_devi
struct ipoib_dev_priv *priv;
int s, e, p;
+ if (ib_node_get_transport(device->node_type) != IB_NODE_IB)
+ return;
+
dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL);
if (!dev_list)
return;
INIT_LIST_HEAD(dev_list);
- if (device->node_type == IB_NODE_SWITCH) {
+ if (ib_node_get_device(device->node_type) == IB_NODE_SWITCH) {
s = 0;
e = 0;
} else {
Index: ulp/srp/ib_srp.c
===================================================================
--- ulp/srp/ib_srp.c (revision 5098)
+++ ulp/srp/ib_srp.c (working copy)
@@ -1581,13 +1581,16 @@ static void srp_add_one(struct ib_device
struct srp_host *host;
int s, e, p;
+ if (ib_node_get_transport(device->node_type) != IB_NODE_IB)
+ return;
+
dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL);
if (!dev_list)
return;
INIT_LIST_HEAD(dev_list);
- if (device->node_type == IB_NODE_SWITCH) {
+ if (ib_node_get_device(device->node_type) == IB_NODE_SWITCH) {
s = 0;
e = 0;
} else {
Index: include/rdma/ib_verbs.h
===================================================================
--- include/rdma/ib_verbs.h (revision 5098)
+++ include/rdma/ib_verbs.h (working copy)
@@ -56,12 +56,32 @@ union ib_gid {
} global;
};
+/*
+ * 8-bit node type - for IB this maps to NodeInfo:NodeType.
+ */
enum ib_node_type {
+ /* bits 7:4 - transport type */
+ IB_NODE_TRANSPORT_MASK = 0xF0,
+ IB_NODE_IB = (0<<4),
+ IB_NODE_IWARP = (1<<4),
+
+ /* bits 3:0 - device type */
+ IB_NODE_DEVICE_MASK = 0x0F,
IB_NODE_CA = 1,
IB_NODE_SWITCH,
IB_NODE_ROUTER
};
+static inline int ib_node_get_transport(enum ib_node_type type)
+{
+ return type & IB_NODE_TRANSPORT_MASK;
+}
+
+static inline int ib_node_get_device(enum ib_node_type type)
+{
+ return type & IB_NODE_DEVICE_MASK;
+}
+
enum ib_device_cap_flags {
IB_DEVICE_RESIZE_MAX_WR = 1,
IB_DEVICE_BAD_PKEY_CNTR = (1<<1),
Index: core/cm.c
===================================================================
--- core/cm.c (revision 5098)
+++ core/cm.c (working copy)
@@ -3245,6 +3245,9 @@ static void cm_add_one(struct ib_device
int ret;
u8 i;
+ if (ib_node_get_transport(device->node_type) != IB_NODE_IB)
+ return;
+
cm_dev = kmalloc(sizeof(*cm_dev) + sizeof(*port) *
device->phys_port_cnt, GFP_KERNEL);
if (!cm_dev)
Index: core/addr.c
===================================================================
--- core/addr.c (revision 5098)
+++ core/addr.c (working copy)
@@ -63,7 +63,7 @@ static int copy_addr(struct rdma_dev_add
{
switch (dev->type) {
case ARPHRD_INFINIBAND:
- dev_addr->dev_type = IB_NODE_CA;
+ dev_addr->dev_type = IB_NODE_IB | IB_NODE_CA;
break;
default:
return -EADDRNOTAVAIL;
Index: core/local_sa.c
===================================================================
--- core/local_sa.c (revision 5194)
+++ core/local_sa.c (working copy)
@@ -362,6 +362,9 @@ static void sa_db_add_one(struct ib_devi
struct sa_db_port *port;
int i;
+ if (ib_node_get_transport(device->node_type) != IB_NODE_IB)
+ return;
+
dev = kmalloc(sizeof *dev + device->phys_port_cnt * sizeof *port,
GFP_KERNEL);
if (!dev)
Index: core/sa_query.c
===================================================================
--- core/sa_query.c (revision 5194)
+++ core/sa_query.c (working copy)
@@ -912,7 +912,10 @@ static void ib_sa_add_one(struct ib_devi
struct ib_sa_device *sa_dev;
int s, e, i;
- if (device->node_type == IB_NODE_SWITCH)
+ if (ib_node_get_transport(device->node_type) != IB_NODE_IB)
+ return;
+
+ if (ib_node_get_device(device->node_type) == IB_NODE_SWITCH)
s = e = 0;
else {
s = 1;
Index: core/user_mad.c
===================================================================
--- core/user_mad.c (revision 5098)
+++ core/user_mad.c (working copy)
@@ -936,7 +936,10 @@ static void ib_umad_add_one(struct ib_de
struct ib_umad_device *umad_dev;
int s, e, i;
- if (device->node_type == IB_NODE_SWITCH)
+ if (ib_node_get_transport(device->node_type) != IB_NODE_IB)
+ return;
+
+ if (ib_node_get_device(device->node_type) == IB_NODE_SWITCH)
s = e = 0;
else {
s = 1;
Index: core/device.c
===================================================================
--- core/device.c (revision 5098)
+++ core/device.c (working copy)
@@ -514,7 +514,7 @@ int ib_query_port(struct ib_device *devi
u8 port_num,
struct ib_port_attr *port_attr)
{
- if (device->node_type == IB_NODE_SWITCH) {
+ if (ib_node_get_device(device->node_type) == IB_NODE_SWITCH) {
if (port_num)
return -EINVAL;
} else if (port_num < 1 || port_num > device->phys_port_cnt)
@@ -589,7 +589,7 @@ int ib_modify_port(struct ib_device *dev
u8 port_num, int port_modify_mask,
struct ib_port_modify *port_modify)
{
- if (device->node_type == IB_NODE_SWITCH) {
+ if (ib_node_get_device(device->node_type) == IB_NODE_SWITCH) {
if (port_num)
return -EINVAL;
} else if (port_num < 1 || port_num > device->phys_port_cnt)
Index: core/cma.c
===================================================================
--- core/cma.c (revision 5194)
+++ core/cma.c (working copy)
@@ -244,8 +244,10 @@ static int cma_acquire_ib_dev(struct rdm
static int cma_acquire_dev(struct rdma_id_private *id_priv)
{
- switch (id_priv->id.route.addr.dev_addr.dev_type) {
- case IB_NODE_CA:
+ enum ib_node_type dev_type = id_priv->id.route.addr.dev_addr.dev_type;
+
+ switch (ib_node_get_transport(dev_type) == IB_NODE_TRANSPORT_MASK) {
+ case IB_NODE_IB:
return cma_acquire_ib_dev(id_priv);
default:
return -ENODEV;
@@ -324,8 +326,8 @@ int rdma_create_qp(struct rdma_cm_id *id
if (IS_ERR(qp))
return PTR_ERR(qp);
- switch (id->device->node_type) {
- case IB_NODE_CA:
+ switch (ib_node_get_transport(id->device->node_type)) {
+ case IB_NODE_IB:
ret = cma_init_ib_qp(id_priv, qp);
break;
default:
@@ -413,8 +415,8 @@ int rdma_init_qp_attr(struct rdma_cm_id
int ret;
id_priv = container_of(id, struct rdma_id_private, id);
- switch (id_priv->id.device->node_type) {
- case IB_NODE_CA:
+ switch (ib_node_get_transport(id_priv->id.device->node_type)) {
+ case IB_NODE_IB:
ret = ib_cm_init_qp_attr(id_priv->cm_id.ib, qp_attr,
qp_attr_mask);
if (qp_attr->qp_state == IB_QPS_RTR)
@@ -540,8 +542,8 @@ static int cma_notify_user(struct rdma_i
static void cma_cancel_addr(struct rdma_id_private *id_priv)
{
- switch (id_priv->id.device->node_type) {
- case IB_NODE_CA:
+ switch (ib_node_get_transport(id_priv->id.device->node_type)) {
+ case IB_NODE_IB:
rdma_addr_cancel(&id_priv->id.route.addr.dev_addr);
break;
default:
@@ -560,8 +562,8 @@ static void cma_destroy_listen(struct rd
cma_exch(id_priv, CMA_DESTROYING);
if (id_priv->cma_dev) {
- switch (id_priv->id.device->node_type) {
- case IB_NODE_CA:
+ switch (ib_node_get_transport(id_priv->id.device->node_type)) {
+ case IB_NODE_IB:
if (id_priv->cm_id.ib && !IS_ERR(id_priv->cm_id.ib))
ib_destroy_cm_id(id_priv->cm_id.ib);
break;
@@ -620,8 +622,8 @@ void rdma_destroy_id(struct rdma_cm_id *
cma_cancel_operation(id_priv, state);
if (id_priv->cma_dev) {
- switch (id->device->node_type) {
- case IB_NODE_CA:
+ switch (ib_node_get_transport(id->device->node_type)) {
+ case IB_NODE_IB:
if (id_priv->cm_id.ib && !IS_ERR(id_priv->cm_id.ib))
ib_destroy_cm_id(id_priv->cm_id.ib);
break;
@@ -782,7 +784,7 @@ static struct rdma_id_private* cma_new_i
ib_addr_set_sgid(&rt->addr.dev_addr, &rt->path_rec[0].sgid);
ib_addr_set_dgid(&rt->addr.dev_addr, &rt->path_rec[0].dgid);
ib_addr_set_pkey(&rt->addr.dev_addr, be16_to_cpu(rt->path_rec[0].pkey));
- rt->addr.dev_addr.dev_type = IB_NODE_CA;
+ rt->addr.dev_addr.dev_type = IB_NODE_IB | IB_NODE_CA;
id_priv = container_of(id, struct rdma_id_private, id);
id_priv->state = CMA_CONNECT;
@@ -984,8 +986,8 @@ int rdma_listen(struct rdma_cm_id *id, i
return -EINVAL;
if (id->device) {
- switch (id->device->node_type) {
- case IB_NODE_CA:
+ switch (ib_node_get_transport(id->device->node_type)) {
+ case IB_NODE_IB:
ret = cma_ib_listen(id_priv);
break;
default:
@@ -1077,8 +1079,8 @@ int rdma_resolve_route(struct rdma_cm_id
return -EINVAL;
atomic_inc(&id_priv->refcount);
- switch (id->device->node_type) {
- case IB_NODE_CA:
+ switch (ib_node_get_transport(id->device->node_type)) {
+ case IB_NODE_IB:
ret = cma_resolve_ib_route(id_priv, timeout_ms);
break;
default:
@@ -1372,8 +1374,8 @@ int rdma_connect(struct rdma_cm_id *id,
id_priv->srq = conn_param->srq;
}
- switch (id->device->node_type) {
- case IB_NODE_CA:
+ switch (ib_node_get_transport(id->device->node_type)) {
+ case IB_NODE_IB:
ret = cma_connect_ib(id_priv, conn_param);
break;
default:
@@ -1431,8 +1433,8 @@ int rdma_accept(struct rdma_cm_id *id, s
id_priv->srq = conn_param->srq;
}
- switch (id->device->node_type) {
- case IB_NODE_CA:
+ switch (ib_node_get_transport(id->device->node_type)) {
+ case IB_NODE_IB:
if (conn_param)
ret = cma_accept_ib(id_priv, conn_param);
else
@@ -1464,8 +1466,8 @@ int rdma_reject(struct rdma_cm_id *id, c
if (!cma_comp(id_priv, CMA_CONNECT))
return -EINVAL;
- switch (id->device->node_type) {
- case IB_NODE_CA:
+ switch (ib_node_get_transport(id->device->node_type)) {
+ case IB_NODE_IB:
ret = ib_send_cm_rej(id_priv->cm_id.ib,
IB_CM_REJ_CONSUMER_DEFINED, NULL, 0,
private_data, private_data_len);
@@ -1491,8 +1493,8 @@ int rdma_disconnect(struct rdma_cm_id *i
if (ret)
goto out;
- switch (id->device->node_type) {
- case IB_NODE_CA:
+ switch (ib_node_get_transport(id->device->node_type)) {
+ case IB_NODE_IB:
/* Initiate or respond to a disconnect. */
if (ib_send_cm_dreq(id_priv->cm_id.ib, NULL, 0))
ib_send_cm_drep(id_priv->cm_id.ib, NULL, 0);
Index: core/mad.c
===================================================================
--- core/mad.c (revision 5098)
+++ core/mad.c (working copy)
@@ -2661,7 +2661,10 @@ static void ib_mad_init_device(struct ib
{
int start, end, i;
- if (device->node_type == IB_NODE_SWITCH) {
+ if (ib_node_get_transport(device->node_type) != IB_NODE_IB)
+ return;
+
+ if (ib_node_get_device(device->node_type) == IB_NODE_SWITCH) {
start = 0;
end = 0;
} else {
@@ -2708,7 +2711,7 @@ static void ib_mad_remove_device(struct
{
int i, num_ports, cur_port;
- if (device->node_type == IB_NODE_SWITCH) {
+ if (ib_node_get_device(device->node_type) == IB_NODE_SWITCH) {
num_ports = 1;
cur_port = 0;
} else {
Index: core/cache.c
===================================================================
--- core/cache.c (revision 5098)
+++ core/cache.c (working copy)
@@ -61,12 +61,13 @@ struct ib_update_work {
static inline int start_port(struct ib_device *device)
{
- return device->node_type == IB_NODE_SWITCH ? 0 : 1;
+ return (ib_node_get_device(device->node_type) == IB_NODE_SWITCH) ? 0 : 1;
}
static inline int end_port(struct ib_device *device)
{
- return device->node_type == IB_NODE_SWITCH ? 0 : device->phys_port_cnt;
+ return (ib_node_get_device(device->node_type) == IB_NODE_SWITCH) ?
+ 0 : device->phys_port_cnt;
}
int ib_get_cached_gid(struct ib_device *device,
Index: core/sysfs.c
===================================================================
--- core/sysfs.c (revision 5098)
+++ core/sysfs.c (working copy)
@@ -590,7 +590,7 @@ static ssize_t show_node_type(struct cla
if (!ibdev_is_alive(dev))
return -ENODEV;
- switch (dev->node_type) {
+ switch (ib_node_get_device(dev->node_type)) {
case IB_NODE_CA: return sprintf(buf, "%d: CA\n", dev->node_type);
case IB_NODE_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type);
case IB_NODE_ROUTER: return sprintf(buf, "%d: router\n", dev->node_type);
@@ -687,7 +687,7 @@ int ib_device_register_sysfs(struct ib_d
if (ret)
goto err_put;
- if (device->node_type == IB_NODE_SWITCH) {
+ if (ib_node_get_device(device->node_type) == IB_NODE_SWITCH) {
ret = add_port(device, 0);
if (ret)
goto err_put;
Index: core/ucm.c
===================================================================
--- core/ucm.c (revision 5117)
+++ core/ucm.c (working copy)
@@ -1255,7 +1255,8 @@ static void ib_ucm_add_one(struct ib_dev
{
struct ib_ucm_device *ucm_dev;
- if (!device->alloc_ucontext)
+ if (!device->alloc_ucontext ||
+ ib_node_get_transport(device->node_type) != IB_NODE_IB)
return;
ucm_dev = kzalloc(sizeof *ucm_dev, GFP_KERNEL);
Index: core/ucma.c
===================================================================
--- core/ucma.c (revision 5098)
+++ core/ucma.c (working copy)
@@ -479,8 +479,8 @@ static ssize_t ucma_query_route(struct u
sizeof(struct sockaddr_in6));
resp.node_guid = ctx->cm_id->device->node_guid;
resp.port_num = ctx->cm_id->port_num;
- switch (ctx->cm_id->device->node_type) {
- case IB_NODE_CA:
+ switch (ib_node_get_transport(ctx->cm_id->device->node_type)) {
+ case IB_NODE_IB:
ucma_copy_ib_route(&resp, &ctx->cm_id->route);
default:
break;
Index: core/smi.c
===================================================================
--- core/smi.c (revision 5098)
+++ core/smi.c (working copy)
@@ -64,7 +64,7 @@ int smi_handle_dr_smp_send(struct ib_smp
/* C14-9:2 */
if (hop_ptr && hop_ptr < hop_cnt) {
- if (node_type != IB_NODE_SWITCH)
+ if (ib_node_get_device(node_type) != IB_NODE_SWITCH)
return 0;
/* smp->return_path set when received */
@@ -77,7 +77,7 @@ int smi_handle_dr_smp_send(struct ib_smp
if (hop_ptr == hop_cnt) {
/* smp->return_path set when received */
smp->hop_ptr++;
- return (node_type == IB_NODE_SWITCH ||
+ return (ib_node_get_device(node_type) == IB_NODE_SWITCH ||
smp->dr_dlid == IB_LID_PERMISSIVE);
}
@@ -95,7 +95,7 @@ int smi_handle_dr_smp_send(struct ib_smp
/* C14-13:2 */
if (2 <= hop_ptr && hop_ptr <= hop_cnt) {
- if (node_type != IB_NODE_SWITCH)
+ if (ib_node_get_device(node_type) != IB_NODE_SWITCH)
return 0;
smp->hop_ptr--;
@@ -107,7 +107,7 @@ int smi_handle_dr_smp_send(struct ib_smp
if (hop_ptr == 1) {
smp->hop_ptr--;
/* C14-13:3 -- SMPs destined for SM shouldn't be here */
- return (node_type == IB_NODE_SWITCH ||
+ return (ib_node_get_device(node_type) == IB_NODE_SWITCH ||
smp->dr_slid == IB_LID_PERMISSIVE);
}
@@ -142,7 +142,7 @@ int smi_handle_dr_smp_recv(struct ib_smp
/* C14-9:2 -- intermediate hop */
if (hop_ptr && hop_ptr < hop_cnt) {
- if (node_type != IB_NODE_SWITCH)
+ if (ib_node_get_device(node_type) != IB_NODE_SWITCH)
return 0;
smp->return_path[hop_ptr] = port_num;
@@ -156,7 +156,7 @@ int smi_handle_dr_smp_recv(struct ib_smp
smp->return_path[hop_ptr] = port_num;
/* smp->hop_ptr updated when sending */
- return (node_type == IB_NODE_SWITCH ||
+ return (ib_node_get_device(node_type) == IB_NODE_SWITCH ||
smp->dr_dlid == IB_LID_PERMISSIVE);
}
@@ -175,7 +175,7 @@ int smi_handle_dr_smp_recv(struct ib_smp
/* C14-13:2 */
if (2 <= hop_ptr && hop_ptr <= hop_cnt) {
- if (node_type != IB_NODE_SWITCH)
+ if (ib_node_get_device(node_type) != IB_NODE_SWITCH)
return 0;
/* smp->hop_ptr updated when sending */
@@ -190,7 +190,7 @@ int smi_handle_dr_smp_recv(struct ib_smp
return 1;
}
/* smp->hop_ptr updated when sending */
- return (node_type == IB_NODE_SWITCH);
+ return (ib_node_get_device(node_type) == IB_NODE_SWITCH);
}
/* C14-13:4 -- hop_ptr = 0 -> give to SM */
Index: core/ping.c
===================================================================
--- core/ping.c (revision 5098)
+++ core/ping.c (working copy)
@@ -247,7 +247,10 @@ static void ib_ping_init_device(struct i
{
int num_ports, cur_port, i;
- if (device->node_type == IB_NODE_SWITCH) {
+ if (ib_node_get_transport(device->node_type) != IB_NODE_IB)
+ return;
+
+ if (ib_node_get_device(device->node_type) == IB_NODE_SWITCH) {
num_ports = 1;
cur_port = 0;
} else {
@@ -278,7 +281,7 @@ static void ib_ping_remove_device(struct
{
int i, num_ports, cur_port;
- if (device->node_type == IB_NODE_SWITCH) {
+ if (ib_node_get_device(device->node_type) == IB_NODE_SWITCH) {
num_ports = 1;
cur_port = 0;
} else {
Index: hw/mthca/mthca_provider.c
===================================================================
--- hw/mthca/mthca_provider.c (revision 5098)
+++ hw/mthca/mthca_provider.c (working copy)
@@ -1122,7 +1122,7 @@ int mthca_register_device(struct mthca_d
(1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
(1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
(1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
- dev->ib_dev.node_type = IB_NODE_CA;
+ dev->ib_dev.node_type = IB_NODE_IB | IB_NODE_CA;
dev->ib_dev.phys_port_cnt = dev->limits.num_ports;
dev->ib_dev.dma_device = &dev->pdev->dev;
dev->ib_dev.class_dev.dev = &dev->pdev->dev;
More information about the general
mailing list