src/dpdk/drivers/common/mlx5/linux/mlx5_nl.c
unsigned int
mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex)
{
	struct mlx5_nl_ifindex_data data = {
		.name = name,
		.flags = 0,
		.ibindex = 0, /* Determined during first pass. */
		.ifindex = 0, /* Determined during second pass. */
	};
	union {
		struct nlmsghdr nh;
		uint8_t buf[NLMSG_HDRLEN +
			    NLA_HDRLEN + NLA_ALIGN(sizeof(data.ibindex)) +
			    NLA_HDRLEN + NLA_ALIGN(sizeof(pindex))];
	} req = {
		.nh = {
			.nlmsg_len = NLMSG_LENGTH(0),
			.nlmsg_type = RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
						       RDMA_NLDEV_CMD_GET),
			.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP,
		},
	};
	struct nlattr *na;
	uint32_t sn = MLX5_NL_SN_GENERATE;
	int ret;

	ret = mlx5_nl_send(nl, &req.nh, sn);
	if (ret < 0)
		return 0;
	ret = mlx5_nl_recv(nl, sn, mlx5_nl_cmdget_cb, &data);
	if (ret < 0)
		return 0;
	if (!(data.flags & MLX5_NL_CMD_GET_IB_NAME) ||
	    !(data.flags & MLX5_NL_CMD_GET_IB_INDEX))
		goto error;
	data.flags = 0;
	sn = MLX5_NL_SN_GENERATE;
	req.nh.nlmsg_type = RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
					     RDMA_NLDEV_CMD_PORT_GET);
	req.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
	req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.buf) - NLMSG_HDRLEN);
	na = (void *)((uintptr_t)req.buf + NLMSG_HDRLEN);
	na->nla_len = NLA_HDRLEN + sizeof(data.ibindex);
	na->nla_type = RDMA_NLDEV_ATTR_DEV_INDEX;
	memcpy((void *)((uintptr_t)na + NLA_HDRLEN),
	       &data.ibindex, sizeof(data.ibindex));
	na = (void *)((uintptr_t)na + NLA_ALIGN(na->nla_len));
	na->nla_len = NLA_HDRLEN + sizeof(pindex);
	na->nla_type = RDMA_NLDEV_ATTR_PORT_INDEX;
	memcpy((void *)((uintptr_t)na + NLA_HDRLEN),
	       &pindex, sizeof(pindex));
	ret = mlx5_nl_send(nl, &req.nh, sn);
	if (ret < 0)
		return 0;
	ret = mlx5_nl_recv(nl, sn, mlx5_nl_cmdget_cb, &data);
	if (ret < 0)
		return 0;
	if (!(data.flags & MLX5_NL_CMD_GET_IB_NAME) ||
	    !(data.flags & MLX5_NL_CMD_GET_IB_INDEX) ||
	    !(data.flags & MLX5_NL_CMD_GET_NET_INDEX) ||
	    !data.ifindex)
		goto error;
	return data.ifindex;
error:
	rte_errno = ENODEV;
	return 0;
}
/**
 * Get index of network interface associated with some IB device.
 *
 * This is the only somewhat safe method to avoid resorting to heuristics
 * when faced with port representors. Unfortunately it requires at least
 * Linux 4.17.
 *
 * @param nl
 *   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.
 */
Get index of network interface associated with some IB device.
This is the only somewhat safe method to avoid resorting to heuristics
when faced with port representors. Unfortunately it requires at least
Linux 4.17.

@param nl
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.
Get index of network interface associated with some IB device . This is the only somewhat safe method to avoid resorting to heuristics when faced with port representors . Unfortunately it requires at least Linux 4 . 17 . @param nl 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, uint32_t pindex)
{
	struct mlx5_nl_ifindex_data data = {
		.name = name,
		.flags = 0,
		.ibindex = 0, 
		.ifindex = 0, 
	};
	union {
		struct nlmsghdr nh;
		uint8_t buf[NLMSG_HDRLEN +
			    NLA_HDRLEN + NLA_ALIGN(sizeof(data.ibindex)) +
			    NLA_HDRLEN + NLA_ALIGN(sizeof(pindex))];
	} req = {
		.nh = {
			.nlmsg_len = NLMSG_LENGTH(0),
			.nlmsg_type = RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
						       RDMA_NLDEV_CMD_GET),
			.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP,
		},
	};
	struct nlattr *na;
	uint32_t sn = MLX5_NL_SN_GENERATE;
	int ret;
	ret = mlx5_nl_send(nl, &req.nh, sn);
	if (ret < 0)
		return 0;
	ret = mlx5_nl_recv(nl, sn, mlx5_nl_cmdget_cb, &data);
	if (ret < 0)
		return 0;
	if (!(data.flags & MLX5_NL_CMD_GET_IB_NAME) ||
	    !(data.flags & MLX5_NL_CMD_GET_IB_INDEX))
		goto error;
	data.flags = 0;
	sn = MLX5_NL_SN_GENERATE;
	req.nh.nlmsg_type = RDMA_NL_GET_TYPE(RDMA_NL_NLDEV,
					     RDMA_NLDEV_CMD_PORT_GET);
	req.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
	req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.buf) - NLMSG_HDRLEN);
	na = (void *)((uintptr_t)req.buf + NLMSG_HDRLEN);
	na->nla_len = NLA_HDRLEN + sizeof(data.ibindex);
	na->nla_type = RDMA_NLDEV_ATTR_DEV_INDEX;
	memcpy((void *)((uintptr_t)na + NLA_HDRLEN),
	       &data.ibindex, sizeof(data.ibindex));
	na = (void *)((uintptr_t)na + NLA_ALIGN(na->nla_len));
	na->nla_len = NLA_HDRLEN + sizeof(pindex);
	na->nla_type = RDMA_NLDEV_ATTR_PORT_INDEX;
	memcpy((void *)((uintptr_t)na + NLA_HDRLEN),
	       &pindex, sizeof(pindex));
	ret = mlx5_nl_send(nl, &req.nh, sn);
	if (ret < 0)
		return 0;
	ret = mlx5_nl_recv(nl, sn, mlx5_nl_cmdget_cb, &data);
	if (ret < 0)
		return 0;
	if (!(data.flags & MLX5_NL_CMD_GET_IB_NAME) ||
	    !(data.flags & MLX5_NL_CMD_GET_IB_INDEX) ||
	    !(data.flags & MLX5_NL_CMD_GET_NET_INDEX) ||
	    !data.ifindex)
		goto error;
	return data.ifindex;
error:
	rte_errno = ENODEV;
	return 0;
}
unsigned int mlx5_nl_ifindex ( int nl , const char * name , uint32_t pindex ) { struct mlx5_nl_ifindex_data data = { . name = name , . flags = 0 , . ibindex = 0 , . ifindex = 0 , } ; union { struct nlmsghdr nh ; uint8_t buf [ NLMSG_HDRLEN + NLA_HDRLEN + NLA_ALIGN ( sizeof ( data . ibindex ) ) + NLA_HDRLEN + NLA_ALIGN ( sizeof ( pindex ) ) ] ; } req = { . nh = { . nlmsg_len = NLMSG_LENGTH ( 0 ) , . nlmsg_type = RDMA_NL_GET_TYPE ( RDMA_NL_NLDEV , RDMA_NLDEV_CMD_GET ) , . nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP , } , } ; struct nlattr * na ; uint32_t sn = MLX5_NL_SN_GENERATE ; int ret ; ret = mlx5_nl_send ( nl , & req . nh , sn ) ; if ( ret < 0 ) return 0 ; ret = mlx5_nl_recv ( nl , sn , mlx5_nl_cmdget_cb , & data ) ; if ( ret < 0 ) return 0 ; if ( ! ( data . flags & MLX5_NL_CMD_GET_IB_NAME ) || ! ( data . flags & MLX5_NL_CMD_GET_IB_INDEX ) ) goto error ; data . flags = 0 ; sn = MLX5_NL_SN_GENERATE ; req . nh . nlmsg_type = RDMA_NL_GET_TYPE ( RDMA_NL_NLDEV , RDMA_NLDEV_CMD_PORT_GET ) ; req . nh . nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK ; req . nh . nlmsg_len = NLMSG_LENGTH ( sizeof ( req . buf ) - NLMSG_HDRLEN ) ; na = ( void * ) ( ( uintptr_t ) req . buf + NLMSG_HDRLEN ) ; na -> nla_len = NLA_HDRLEN + sizeof ( data . ibindex ) ; na -> nla_type = RDMA_NLDEV_ATTR_DEV_INDEX ; memcpy ( ( void * ) ( ( uintptr_t ) na + NLA_HDRLEN ) , & data . ibindex , sizeof ( data . ibindex ) ) ; na = ( void * ) ( ( uintptr_t ) na + NLA_ALIGN ( na -> nla_len ) ) ; na -> nla_len = NLA_HDRLEN + sizeof ( pindex ) ; na -> nla_type = RDMA_NLDEV_ATTR_PORT_INDEX ; memcpy ( ( void * ) ( ( uintptr_t ) na + NLA_HDRLEN ) , & pindex , sizeof ( pindex ) ) ; ret = mlx5_nl_send ( nl , & req . nh , sn ) ; if ( ret < 0 ) return 0 ; ret = mlx5_nl_recv ( nl , sn , mlx5_nl_cmdget_cb , & data ) ; if ( ret < 0 ) return 0 ; if ( ! ( data . flags & MLX5_NL_CMD_GET_IB_NAME ) || ! ( data . flags & MLX5_NL_CMD_GET_IB_INDEX ) || ! ( data . flags & MLX5_NL_CMD_GET_NET_INDEX ) || ! data . ifindex ) goto error ; return data . ifindex ; error : rte_errno = ENODEV ; return 0 ; }
Get index of network interface associated with some IB device.
Get index of network interface associated with some IB device .
/* Determined during first pass. */ /* Determined during second pass. */