Commit 9327c7af authored by Parav Pandit's avatar Parav Pandit Committed by Jason Gunthorpe

RDMA/cma: Provide a function to set RoCE path record L2 parameters

Introduce a helper function to set path record L2 fields for RoCE.
This includes setting GID type, destination mac address and netdev
ifindex.
Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
Reviewed-by: default avatarMark Bloch <markb@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leon@kernel.org>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 608bc446
...@@ -2465,6 +2465,58 @@ static int cma_resolve_ib_route(struct rdma_id_private *id_priv, int timeout_ms) ...@@ -2465,6 +2465,58 @@ static int cma_resolve_ib_route(struct rdma_id_private *id_priv, int timeout_ms)
return ret; return ret;
} }
static enum ib_gid_type cma_route_gid_type(enum rdma_network_type network_type,
unsigned long supported_gids,
enum ib_gid_type default_gid)
{
if ((network_type == RDMA_NETWORK_IPV4 ||
network_type == RDMA_NETWORK_IPV6) &&
test_bit(IB_GID_TYPE_ROCE_UDP_ENCAP, &supported_gids))
return IB_GID_TYPE_ROCE_UDP_ENCAP;
return default_gid;
}
/*
* cma_iboe_set_path_rec_l2_fields() is helper function which sets
* path record type based on GID type.
* It also sets up other L2 fields which includes destination mac address
* netdev ifindex, of the path record.
* It returns the netdev of the bound interface for this path record entry.
*/
static struct net_device *
cma_iboe_set_path_rec_l2_fields(struct rdma_id_private *id_priv)
{
struct rdma_route *route = &id_priv->id.route;
enum ib_gid_type gid_type = IB_GID_TYPE_ROCE;
struct rdma_addr *addr = &route->addr;
unsigned long supported_gids;
struct net_device *ndev;
if (!addr->dev_addr.bound_dev_if)
return NULL;
ndev = dev_get_by_index(addr->dev_addr.net,
addr->dev_addr.bound_dev_if);
if (!ndev)
return NULL;
supported_gids = roce_gid_type_mask_support(id_priv->id.device,
id_priv->id.port_num);
gid_type = cma_route_gid_type(addr->dev_addr.network,
supported_gids,
id_priv->gid_type);
/* Use the hint from IP Stack to select GID Type */
if (gid_type < ib_network_to_gid_type(addr->dev_addr.network))
gid_type = ib_network_to_gid_type(addr->dev_addr.network);
route->path_rec->rec_type = sa_conv_gid_to_pathrec_type(gid_type);
sa_path_set_ndev(route->path_rec, addr->dev_addr.net);
sa_path_set_ifindex(route->path_rec, ndev->ifindex);
sa_path_set_dmac(route->path_rec, addr->dev_addr.dst_dev_addr);
return ndev;
}
int rdma_set_ib_paths(struct rdma_cm_id *id, int rdma_set_ib_paths(struct rdma_cm_id *id,
struct sa_path_rec *path_rec, int num_paths) struct sa_path_rec *path_rec, int num_paths)
{ {
...@@ -2522,18 +2574,6 @@ static int iboe_tos_to_sl(struct net_device *ndev, int tos) ...@@ -2522,18 +2574,6 @@ static int iboe_tos_to_sl(struct net_device *ndev, int tos)
return 0; return 0;
} }
static enum ib_gid_type cma_route_gid_type(enum rdma_network_type network_type,
unsigned long supported_gids,
enum ib_gid_type default_gid)
{
if ((network_type == RDMA_NETWORK_IPV4 ||
network_type == RDMA_NETWORK_IPV6) &&
test_bit(IB_GID_TYPE_ROCE_UDP_ENCAP, &supported_gids))
return IB_GID_TYPE_ROCE_UDP_ENCAP;
return default_gid;
}
static int cma_resolve_iboe_route(struct rdma_id_private *id_priv) static int cma_resolve_iboe_route(struct rdma_id_private *id_priv)
{ {
struct rdma_route *route = &id_priv->id.route; struct rdma_route *route = &id_priv->id.route;
...@@ -2541,8 +2581,6 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv) ...@@ -2541,8 +2581,6 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv)
struct cma_work *work; struct cma_work *work;
int ret; int ret;
struct net_device *ndev; struct net_device *ndev;
enum ib_gid_type gid_type = IB_GID_TYPE_ROCE;
unsigned long supported_gids;
u8 default_roce_tos = id_priv->cma_dev->default_roce_tos[id_priv->id.port_num - u8 default_roce_tos = id_priv->cma_dev->default_roce_tos[id_priv->id.port_num -
rdma_start_port(id_priv->cma_dev->device)]; rdma_start_port(id_priv->cma_dev->device)];
...@@ -2561,32 +2599,12 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv) ...@@ -2561,32 +2599,12 @@ static int cma_resolve_iboe_route(struct rdma_id_private *id_priv)
route->num_paths = 1; route->num_paths = 1;
if (!addr->dev_addr.bound_dev_if) { ndev = cma_iboe_set_path_rec_l2_fields(id_priv);
ret = -ENODEV;
goto err2;
}
ndev = dev_get_by_index(addr->dev_addr.net,
addr->dev_addr.bound_dev_if);
if (!ndev) { if (!ndev) {
ret = -ENODEV; ret = -ENODEV;
goto err2; goto err2;
} }
supported_gids = roce_gid_type_mask_support(id_priv->id.device,
id_priv->id.port_num);
gid_type = cma_route_gid_type(addr->dev_addr.network,
supported_gids,
id_priv->gid_type);
/* Use the hint from IP Stack to select GID Type */
if (gid_type < ib_network_to_gid_type(addr->dev_addr.network))
gid_type = ib_network_to_gid_type(addr->dev_addr.network);
route->path_rec->rec_type = sa_conv_gid_to_pathrec_type(gid_type);
sa_path_set_ndev(route->path_rec, addr->dev_addr.net);
sa_path_set_ifindex(route->path_rec, ndev->ifindex);
sa_path_set_dmac(route->path_rec, addr->dev_addr.dst_dev_addr);
rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr, rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.src_addr,
&route->path_rec->sgid); &route->path_rec->sgid);
rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.dst_addr, rdma_ip2gid((struct sockaddr *)&id_priv->id.route.addr.dst_addr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment