IB/Verbs: Reform cma_acquire_dev()

Reform cma_acquire_dev() with management helpers, introduce
cma_validate_port() to make the code more clean.

Signed-off-by: Michael Wang <yun.wang@profitbricks.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Tested-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Sean Hefty <sean.hefty@intel.com>
Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Tested-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
This commit is contained in:
Michael Wang 2015-05-05 14:50:30 +02:00 committed by Doug Ledford
parent 5c9a52828a
commit 7c11147da2
1 changed files with 39 additions and 27 deletions

View File

@ -349,18 +349,35 @@ static int cma_translate_addr(struct sockaddr *addr, struct rdma_dev_addr *dev_a
return ret; return ret;
} }
static inline int cma_validate_port(struct ib_device *device, u8 port,
union ib_gid *gid, int dev_type)
{
u8 found_port;
int ret = -ENODEV;
if ((dev_type == ARPHRD_INFINIBAND) && !rdma_protocol_ib(device, port))
return ret;
if ((dev_type != ARPHRD_INFINIBAND) && rdma_protocol_ib(device, port))
return ret;
ret = ib_find_cached_gid(device, gid, &found_port, NULL);
if (port != found_port)
return -ENODEV;
return ret;
}
static int cma_acquire_dev(struct rdma_id_private *id_priv, static int cma_acquire_dev(struct rdma_id_private *id_priv,
struct rdma_id_private *listen_id_priv) struct rdma_id_private *listen_id_priv)
{ {
struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
struct cma_device *cma_dev; struct cma_device *cma_dev;
union ib_gid gid, iboe_gid; union ib_gid gid, iboe_gid, *gidp;
int ret = -ENODEV; int ret = -ENODEV;
u8 port, found_port; u8 port;
enum rdma_link_layer dev_ll = dev_addr->dev_type == ARPHRD_INFINIBAND ?
IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET;
if (dev_ll != IB_LINK_LAYER_INFINIBAND && if (dev_addr->dev_type != ARPHRD_INFINIBAND &&
id_priv->id.ps == RDMA_PS_IPOIB) id_priv->id.ps == RDMA_PS_IPOIB)
return -EINVAL; return -EINVAL;
@ -370,41 +387,36 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv,
memcpy(&gid, dev_addr->src_dev_addr + memcpy(&gid, dev_addr->src_dev_addr +
rdma_addr_gid_offset(dev_addr), sizeof gid); rdma_addr_gid_offset(dev_addr), sizeof gid);
if (listen_id_priv &&
rdma_port_get_link_layer(listen_id_priv->id.device, if (listen_id_priv) {
listen_id_priv->id.port_num) == dev_ll) {
cma_dev = listen_id_priv->cma_dev; cma_dev = listen_id_priv->cma_dev;
port = listen_id_priv->id.port_num; port = listen_id_priv->id.port_num;
if (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB && gidp = rdma_protocol_iboe(cma_dev->device, port) ?
rdma_port_get_link_layer(cma_dev->device, port) == IB_LINK_LAYER_ETHERNET) &iboe_gid : &gid;
ret = ib_find_cached_gid(cma_dev->device, &iboe_gid,
&found_port, NULL);
else
ret = ib_find_cached_gid(cma_dev->device, &gid,
&found_port, NULL);
if (!ret && (port == found_port)) { ret = cma_validate_port(cma_dev->device, port, gidp,
id_priv->id.port_num = found_port; dev_addr->dev_type);
if (!ret) {
id_priv->id.port_num = port;
goto out; goto out;
} }
} }
list_for_each_entry(cma_dev, &dev_list, list) { list_for_each_entry(cma_dev, &dev_list, list) {
for (port = 1; port <= cma_dev->device->phys_port_cnt; ++port) { for (port = 1; port <= cma_dev->device->phys_port_cnt; ++port) {
if (listen_id_priv && if (listen_id_priv &&
listen_id_priv->cma_dev == cma_dev && listen_id_priv->cma_dev == cma_dev &&
listen_id_priv->id.port_num == port) listen_id_priv->id.port_num == port)
continue; continue;
if (rdma_port_get_link_layer(cma_dev->device, port) == dev_ll) {
if (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB &&
rdma_port_get_link_layer(cma_dev->device, port) == IB_LINK_LAYER_ETHERNET)
ret = ib_find_cached_gid(cma_dev->device, &iboe_gid, &found_port, NULL);
else
ret = ib_find_cached_gid(cma_dev->device, &gid, &found_port, NULL);
if (!ret && (port == found_port)) { gidp = rdma_protocol_iboe(cma_dev->device, port) ?
id_priv->id.port_num = found_port; &iboe_gid : &gid;
goto out;
} ret = cma_validate_port(cma_dev->device, port, gidp,
dev_addr->dev_type);
if (!ret) {
id_priv->id.port_num = port;
goto out;
} }
} }
} }