[03/14] net/mlx5: modify get ifindex routine for multiport IB

Message ID 1553155888-27498-4-git-send-email-viacheslavo@mellanox.com
State Superseded, archived
Delegated to: Shahaf Shuler
Headers show
Series
  • net/mlx5: add support for multiport IB devices
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Viacheslav Ovsiienko March 21, 2019, 8:11 a.m.
There is the routine mlx5_nl_ifindex() returning the
network interface index associated with Infiniband device.
We are going to support multiport IB devices, now function
takes the IB port as argument and returns ifindex associated
with tuple <IB device, IB port>

Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 drivers/net/mlx5/mlx5.c        |  2 +-
 drivers/net/mlx5/mlx5.h        |  2 +-
 drivers/net/mlx5/mlx5_ethdev.c |  2 +-
 drivers/net/mlx5/mlx5_nl.c     | 20 +++++++++++++-------
 4 files changed, 16 insertions(+), 10 deletions(-)

Comments

Shahaf Shuler March 21, 2019, 12:14 p.m. | #1
Thursday, March 21, 2019 10:11 AM, Viacheslav Ovsiienko:
> Subject: [PATCH 03/14] net/mlx5: modify get ifindex routine for multiport IB
> 
> There is the routine mlx5_nl_ifindex() returning the network interface index
> associated with Infiniband device.
> We are going to support multiport IB devices, now function takes the IB port
> as argument and returns ifindex associated with tuple <IB device, IB port>
> 
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
> ---
>  drivers/net/mlx5/mlx5.c        |  2 +-
>  drivers/net/mlx5/mlx5.h        |  2 +-
>  drivers/net/mlx5/mlx5_ethdev.c |  2 +-
>  drivers/net/mlx5/mlx5_nl.c     | 20 +++++++++++++-------
>  4 files changed, 16 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index
> ea3d00c..89c30af 100644
> --- a/drivers/net/mlx5/mlx5.c
> +++ b/drivers/net/mlx5/mlx5.c
> @@ -1441,7 +1441,7 @@ struct mlx5_dev_spawn_data {
>  			list[i].ifindex = 0;
>  		else
>  			list[i].ifindex = mlx5_nl_ifindex
> -				(nl_rdma, list[i].ibv_dev->name);
> +				(nl_rdma, list[i].ibv_dev->name, 1);

Why hardcoded to 1?

>  		if (nl_route < 0 ||
>  		    !list[i].ifindex ||
>  		    mlx5_nl_switch_info(nl_route, list[i].ifindex, diff --git
> a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index
> 1716cd1..f5e29ca 100644
> --- a/drivers/net/mlx5/mlx5.h
> +++ b/drivers/net/mlx5/mlx5.h
> @@ -470,7 +470,7 @@ int mlx5_nl_mac_addr_remove(struct rte_eth_dev
> *dev, struct ether_addr *mac,  void mlx5_nl_mac_addr_flush(struct
> rte_eth_dev *dev);  int mlx5_nl_promisc(struct rte_eth_dev *dev, int
> enable);  int mlx5_nl_allmulti(struct rte_eth_dev *dev, int enable); -
> unsigned int mlx5_nl_ifindex(int nl, const char *name);
> +unsigned int mlx5_nl_ifindex(int nl, const char *name, uint32_t
> +pindex);
>  int mlx5_nl_switch_info(int nl, unsigned int ifindex,
>  			struct mlx5_switch_info *info);
> 
> diff --git a/drivers/net/mlx5/mlx5_ethdev.c
> b/drivers/net/mlx5/mlx5_ethdev.c index 81f2a42..5b44889 100644
> --- a/drivers/net/mlx5/mlx5_ethdev.c
> +++ b/drivers/net/mlx5/mlx5_ethdev.c
> @@ -222,7 +222,7 @@ struct ethtool_link_settings {
>  	struct mlx5_priv *priv = dev->data->dev_private;
>  	unsigned int ifindex =
>  		priv->nl_socket_rdma >= 0 ?
> -		mlx5_nl_ifindex(priv->nl_socket_rdma, priv->ibdev_name) :
> 0;
> +		mlx5_nl_ifindex(priv->nl_socket_rdma, priv->ibdev_name,
> 1) : 0;
> 
>  	if (!ifindex) {
>  		if (!priv->representor)
> diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c index
> aa49cb4..6e9145a 100644
> --- a/drivers/net/mlx5/mlx5_nl.c
> +++ b/drivers/net/mlx5/mlx5_nl.c
> @@ -85,11 +85,12 @@ struct mlx5_nl_mac_addr {
>  	int mac_n; /**< Number of addresses in the array. */  };
> 
> -/** Data structure used by mlx5_nl_ifindex_cb(). */
> +/** Data structure used by mlx5_nl_cmdget_cb(). */
>  struct mlx5_nl_ifindex_data {
>  	const char *name; /**< IB device name (in). */
>  	uint32_t ibindex; /**< IB device index (out). */
>  	uint32_t ifindex; /**< Network interface index (out). */
> +	uint32_t portnum; /**< IB device max port number. */

What happen w/ old kernel which don't support it? the portnum is ignored? 

>  };
> 
>  /**
> @@ -695,12 +696,13 @@ struct mlx5_nl_ifindex_data {
>   *   0 on success, a negative errno value otherwise and rte_errno is set.
>   */
>  static int
> -mlx5_nl_ifindex_cb(struct nlmsghdr *nh, void *arg)
> +mlx5_nl_cmdget_cb(struct nlmsghdr *nh, void *arg)
>  {
>  	struct mlx5_nl_ifindex_data *data = arg;
>  	size_t off = NLMSG_HDRLEN;
>  	uint32_t ibindex = 0;
>  	uint32_t ifindex = 0;
> +	uint32_t portnum = 0;
>  	int found = 0;
> 
>  	if (nh->nlmsg_type !=
> @@ -725,6 +727,9 @@ struct mlx5_nl_ifindex_data {
>  		case RDMA_NLDEV_ATTR_NDEV_INDEX:
>  			ifindex = *(uint32_t *)payload;
>  			break;
> +		case RDMA_NLDEV_ATTR_PORT_INDEX:
> +			portnum = *(uint32_t *)payload;
> +			break;
>  		default:
>  			break;
>  		}
> @@ -733,6 +738,7 @@ struct mlx5_nl_ifindex_data {
>  	if (found) {
>  		data->ibindex = ibindex;
>  		data->ifindex = ifindex;
> +		data->portnum = portnum;
>  	}
>  	return 0;
>  error:
> @@ -751,15 +757,15 @@ struct mlx5_nl_ifindex_data {
>   *   Netlink socket of the RDMA kind (NETLINK_RDMA).
>   * @param[in] name
>   *   IB device name.
> - *
> + * @param[in] pindex
> + *   IB device port index, starting from 1
>   * @return
>   *   A valid (nonzero) interface index on success, 0 otherwise and rte_errno
>   *   is set.
>   */
>  unsigned int
> -mlx5_nl_ifindex(int nl, const char *name)
> +mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex)
>  {
> -	static const uint32_t pindex = 1;
>  	uint32_t seq = random();
>  	struct mlx5_nl_ifindex_data data = {
>  		.name = name,
> @@ -785,7 +791,7 @@ struct mlx5_nl_ifindex_data {
>  	ret = mlx5_nl_send(nl, &req.nh, seq);
>  	if (ret < 0)
>  		return 0;
> -	ret = mlx5_nl_recv(nl, seq, mlx5_nl_ifindex_cb, &data);
> +	ret = mlx5_nl_recv(nl, seq, mlx5_nl_cmdget_cb, &data);
>  	if (ret < 0)
>  		return 0;
>  	if (!data.ibindex)
> @@ -808,7 +814,7 @@ struct mlx5_nl_ifindex_data {
>  	ret = mlx5_nl_send(nl, &req.nh, seq);
>  	if (ret < 0)
>  		return 0;
> -	ret = mlx5_nl_recv(nl, seq, mlx5_nl_ifindex_cb, &data);
> +	ret = mlx5_nl_recv(nl, seq, mlx5_nl_cmdget_cb, &data);
>  	if (ret < 0)
>  		return 0;
>  	if (!data.ifindex)
> --
> 1.8.3.1
Viacheslav Ovsiienko March 21, 2019, 12:58 p.m. | #2
> -----Original Message-----
> From: Shahaf Shuler
> Sent: Thursday, March 21, 2019 14:14
> To: Slava Ovsiienko <viacheslavo@mellanox.com>; dev@dpdk.org
> Subject: RE: [PATCH 03/14] net/mlx5: modify get ifindex routine for multiport
> IB
> 
> Thursday, March 21, 2019 10:11 AM, Viacheslav Ovsiienko:
> > Subject: [PATCH 03/14] net/mlx5: modify get ifindex routine for
> > multiport IB
> >
> > There is the routine mlx5_nl_ifindex() returning the network interface
> > index associated with Infiniband device.
> > We are going to support multiport IB devices, now function takes the
> > IB port as argument and returns ifindex associated with tuple <IB
> > device, IB port>
> >
> > Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
> > ---
> >  drivers/net/mlx5/mlx5.c        |  2 +-
> >  drivers/net/mlx5/mlx5.h        |  2 +-
> >  drivers/net/mlx5/mlx5_ethdev.c |  2 +-
> >  drivers/net/mlx5/mlx5_nl.c     | 20 +++++++++++++-------
> >  4 files changed, 16 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index
> > ea3d00c..89c30af 100644
> > --- a/drivers/net/mlx5/mlx5.c
> > +++ b/drivers/net/mlx5/mlx5.c
> > @@ -1441,7 +1441,7 @@ struct mlx5_dev_spawn_data {
> >  			list[i].ifindex = 0;
> >  		else
> >  			list[i].ifindex = mlx5_nl_ifindex
> > -				(nl_rdma, list[i].ibv_dev->name);
> > +				(nl_rdma, list[i].ibv_dev->name, 1);
> 
> Why hardcoded to 1?

Because the given part of patchset regards only mlx5_nl_ifindex() change.
We are not introducing the multiport Infiniband device right now and here,
it is coming in the next parts of the patchset. This "hardcoded 1"
will be replaced by actual index (please, see the next parts).

> 
> >  		if (nl_route < 0 ||
> >  		    !list[i].ifindex ||
> >  		    mlx5_nl_switch_info(nl_route, list[i].ifindex, diff --git
> > a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index
> > 1716cd1..f5e29ca 100644
> > --- a/drivers/net/mlx5/mlx5.h
> > +++ b/drivers/net/mlx5/mlx5.h
> > @@ -470,7 +470,7 @@ int mlx5_nl_mac_addr_remove(struct rte_eth_dev
> > *dev, struct ether_addr *mac,  void mlx5_nl_mac_addr_flush(struct
> > rte_eth_dev *dev);  int mlx5_nl_promisc(struct rte_eth_dev *dev, int
> > enable);  int mlx5_nl_allmulti(struct rte_eth_dev *dev, int enable); -
> > unsigned int mlx5_nl_ifindex(int nl, const char *name);
> > +unsigned int mlx5_nl_ifindex(int nl, const char *name, uint32_t
> > +pindex);
> >  int mlx5_nl_switch_info(int nl, unsigned int ifindex,
> >  			struct mlx5_switch_info *info);
> >
> > diff --git a/drivers/net/mlx5/mlx5_ethdev.c
> > b/drivers/net/mlx5/mlx5_ethdev.c index 81f2a42..5b44889 100644
> > --- a/drivers/net/mlx5/mlx5_ethdev.c
> > +++ b/drivers/net/mlx5/mlx5_ethdev.c
> > @@ -222,7 +222,7 @@ struct ethtool_link_settings {
> >  	struct mlx5_priv *priv = dev->data->dev_private;
> >  	unsigned int ifindex =
> >  		priv->nl_socket_rdma >= 0 ?
> > -		mlx5_nl_ifindex(priv->nl_socket_rdma, priv->ibdev_name) :
> > 0;
> > +		mlx5_nl_ifindex(priv->nl_socket_rdma, priv->ibdev_name,
> > 1) : 0;
> >
> >  	if (!ifindex) {
> >  		if (!priv->representor)
> > diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c
> > index aa49cb4..6e9145a 100644
> > --- a/drivers/net/mlx5/mlx5_nl.c
> > +++ b/drivers/net/mlx5/mlx5_nl.c
> > @@ -85,11 +85,12 @@ struct mlx5_nl_mac_addr {
> >  	int mac_n; /**< Number of addresses in the array. */  };
> >
> > -/** Data structure used by mlx5_nl_ifindex_cb(). */
> > +/** Data structure used by mlx5_nl_cmdget_cb(). */
> >  struct mlx5_nl_ifindex_data {
> >  	const char *name; /**< IB device name (in). */
> >  	uint32_t ibindex; /**< IB device index (out). */
> >  	uint32_t ifindex; /**< Network interface index (out). */
> > +	uint32_t portnum; /**< IB device max port number. */
> 
> What happen w/ old kernel which don't support it? the portnum is ignored?

On old kernels there is always port 1 exists. So, it os OK to use 1 for this only port.

> 
> >  };
> >
> >  /**
> > @@ -695,12 +696,13 @@ struct mlx5_nl_ifindex_data {
> >   *   0 on success, a negative errno value otherwise and rte_errno is set.
> >   */
> >  static int
> > -mlx5_nl_ifindex_cb(struct nlmsghdr *nh, void *arg)
> > +mlx5_nl_cmdget_cb(struct nlmsghdr *nh, void *arg)
> >  {
> >  	struct mlx5_nl_ifindex_data *data = arg;
> >  	size_t off = NLMSG_HDRLEN;
> >  	uint32_t ibindex = 0;
> >  	uint32_t ifindex = 0;
> > +	uint32_t portnum = 0;
> >  	int found = 0;
> >
> >  	if (nh->nlmsg_type !=
> > @@ -725,6 +727,9 @@ struct mlx5_nl_ifindex_data {
> >  		case RDMA_NLDEV_ATTR_NDEV_INDEX:
> >  			ifindex = *(uint32_t *)payload;
> >  			break;
> > +		case RDMA_NLDEV_ATTR_PORT_INDEX:
> > +			portnum = *(uint32_t *)payload;
> > +			break;
> >  		default:
> >  			break;
> >  		}
> > @@ -733,6 +738,7 @@ struct mlx5_nl_ifindex_data {
> >  	if (found) {
> >  		data->ibindex = ibindex;
> >  		data->ifindex = ifindex;
> > +		data->portnum = portnum;
> >  	}
> >  	return 0;
> >  error:
> > @@ -751,15 +757,15 @@ struct mlx5_nl_ifindex_data {
> >   *   Netlink socket of the RDMA kind (NETLINK_RDMA).
> >   * @param[in] name
> >   *   IB device name.
> > - *
> > + * @param[in] pindex
> > + *   IB device port index, starting from 1
> >   * @return
> >   *   A valid (nonzero) interface index on success, 0 otherwise and rte_errno
> >   *   is set.
> >   */
> >  unsigned int
> > -mlx5_nl_ifindex(int nl, const char *name)
> > +mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex)
> >  {
> > -	static const uint32_t pindex = 1;
> >  	uint32_t seq = random();
> >  	struct mlx5_nl_ifindex_data data = {
> >  		.name = name,
> > @@ -785,7 +791,7 @@ struct mlx5_nl_ifindex_data {
> >  	ret = mlx5_nl_send(nl, &req.nh, seq);
> >  	if (ret < 0)
> >  		return 0;
> > -	ret = mlx5_nl_recv(nl, seq, mlx5_nl_ifindex_cb, &data);
> > +	ret = mlx5_nl_recv(nl, seq, mlx5_nl_cmdget_cb, &data);
> >  	if (ret < 0)
> >  		return 0;
> >  	if (!data.ibindex)
> > @@ -808,7 +814,7 @@ struct mlx5_nl_ifindex_data {
> >  	ret = mlx5_nl_send(nl, &req.nh, seq);
> >  	if (ret < 0)
> >  		return 0;
> > -	ret = mlx5_nl_recv(nl, seq, mlx5_nl_ifindex_cb, &data);
> > +	ret = mlx5_nl_recv(nl, seq, mlx5_nl_cmdget_cb, &data);
> >  	if (ret < 0)
> >  		return 0;
> >  	if (!data.ifindex)
> > --
> > 1.8.3.1

Patch

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index ea3d00c..89c30af 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -1441,7 +1441,7 @@  struct mlx5_dev_spawn_data {
 			list[i].ifindex = 0;
 		else
 			list[i].ifindex = mlx5_nl_ifindex
-				(nl_rdma, list[i].ibv_dev->name);
+				(nl_rdma, list[i].ibv_dev->name, 1);
 		if (nl_route < 0 ||
 		    !list[i].ifindex ||
 		    mlx5_nl_switch_info(nl_route, list[i].ifindex,
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 1716cd1..f5e29ca 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -470,7 +470,7 @@  int mlx5_nl_mac_addr_remove(struct rte_eth_dev *dev, struct ether_addr *mac,
 void mlx5_nl_mac_addr_flush(struct rte_eth_dev *dev);
 int mlx5_nl_promisc(struct rte_eth_dev *dev, int enable);
 int mlx5_nl_allmulti(struct rte_eth_dev *dev, int enable);
-unsigned int mlx5_nl_ifindex(int nl, const char *name);
+unsigned int mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex);
 int mlx5_nl_switch_info(int nl, unsigned int ifindex,
 			struct mlx5_switch_info *info);
 
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 81f2a42..5b44889 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -222,7 +222,7 @@  struct ethtool_link_settings {
 	struct mlx5_priv *priv = dev->data->dev_private;
 	unsigned int ifindex =
 		priv->nl_socket_rdma >= 0 ?
-		mlx5_nl_ifindex(priv->nl_socket_rdma, priv->ibdev_name) : 0;
+		mlx5_nl_ifindex(priv->nl_socket_rdma, priv->ibdev_name, 1) : 0;
 
 	if (!ifindex) {
 		if (!priv->representor)
diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c
index aa49cb4..6e9145a 100644
--- a/drivers/net/mlx5/mlx5_nl.c
+++ b/drivers/net/mlx5/mlx5_nl.c
@@ -85,11 +85,12 @@  struct mlx5_nl_mac_addr {
 	int mac_n; /**< Number of addresses in the array. */
 };
 
-/** Data structure used by mlx5_nl_ifindex_cb(). */
+/** Data structure used by mlx5_nl_cmdget_cb(). */
 struct mlx5_nl_ifindex_data {
 	const char *name; /**< IB device name (in). */
 	uint32_t ibindex; /**< IB device index (out). */
 	uint32_t ifindex; /**< Network interface index (out). */
+	uint32_t portnum; /**< IB device max port number. */
 };
 
 /**
@@ -695,12 +696,13 @@  struct mlx5_nl_ifindex_data {
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 static int
-mlx5_nl_ifindex_cb(struct nlmsghdr *nh, void *arg)
+mlx5_nl_cmdget_cb(struct nlmsghdr *nh, void *arg)
 {
 	struct mlx5_nl_ifindex_data *data = arg;
 	size_t off = NLMSG_HDRLEN;
 	uint32_t ibindex = 0;
 	uint32_t ifindex = 0;
+	uint32_t portnum = 0;
 	int found = 0;
 
 	if (nh->nlmsg_type !=
@@ -725,6 +727,9 @@  struct mlx5_nl_ifindex_data {
 		case RDMA_NLDEV_ATTR_NDEV_INDEX:
 			ifindex = *(uint32_t *)payload;
 			break;
+		case RDMA_NLDEV_ATTR_PORT_INDEX:
+			portnum = *(uint32_t *)payload;
+			break;
 		default:
 			break;
 		}
@@ -733,6 +738,7 @@  struct mlx5_nl_ifindex_data {
 	if (found) {
 		data->ibindex = ibindex;
 		data->ifindex = ifindex;
+		data->portnum = portnum;
 	}
 	return 0;
 error:
@@ -751,15 +757,15 @@  struct mlx5_nl_ifindex_data {
  *   Netlink socket of the RDMA kind (NETLINK_RDMA).
  * @param[in] name
  *   IB device name.
- *
+ * @param[in] pindex
+ *   IB device port index, starting from 1
  * @return
  *   A valid (nonzero) interface index on success, 0 otherwise and rte_errno
  *   is set.
  */
 unsigned int
-mlx5_nl_ifindex(int nl, const char *name)
+mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex)
 {
-	static const uint32_t pindex = 1;
 	uint32_t seq = random();
 	struct mlx5_nl_ifindex_data data = {
 		.name = name,
@@ -785,7 +791,7 @@  struct mlx5_nl_ifindex_data {
 	ret = mlx5_nl_send(nl, &req.nh, seq);
 	if (ret < 0)
 		return 0;
-	ret = mlx5_nl_recv(nl, seq, mlx5_nl_ifindex_cb, &data);
+	ret = mlx5_nl_recv(nl, seq, mlx5_nl_cmdget_cb, &data);
 	if (ret < 0)
 		return 0;
 	if (!data.ibindex)
@@ -808,7 +814,7 @@  struct mlx5_nl_ifindex_data {
 	ret = mlx5_nl_send(nl, &req.nh, seq);
 	if (ret < 0)
 		return 0;
-	ret = mlx5_nl_recv(nl, seq, mlx5_nl_ifindex_cb, &data);
+	ret = mlx5_nl_recv(nl, seq, mlx5_nl_cmdget_cb, &data);
 	if (ret < 0)
 		return 0;
 	if (!data.ifindex)