From 654810b56828eb5138a86db395e5cafcef3d70dd Mon Sep 17 00:00:00 2001 From: Matan Azrad Date: Wed, 29 Jan 2020 12:38:49 +0000 Subject: [PATCH] common/mlx5: share Netlink commands Move Netlink mechanism and its dependencies from net/mlx5 to common/mlx5 in order to be ready to use by other mlx5 drivers. The dependencies are BITFIELD defines, the ppc64 compilation workaround for bool type and the function mlx5_translate_port_name. Update build mechanism accordingly. Signed-off-by: Matan Azrad Acked-by: Viacheslav Ovsiienko --- drivers/common/mlx5/Makefile | 3 +- drivers/common/mlx5/meson.build | 1 + drivers/common/mlx5/mlx5_common.c | 55 +++++++++++++++++ drivers/common/mlx5/mlx5_common.h | 59 +++++++++++++++++++ drivers/{net => common}/mlx5/mlx5_nl.c | 4 +- drivers/{net => common}/mlx5/mlx5_nl.h | 19 +----- .../common/mlx5/rte_common_mlx5_version.map | 16 +++++ drivers/net/mlx5/Makefile | 1 - drivers/net/mlx5/meson.build | 1 - drivers/net/mlx5/mlx5.h | 2 +- drivers/net/mlx5/mlx5_defs.h | 8 --- drivers/net/mlx5/mlx5_ethdev.c | 55 ----------------- drivers/net/mlx5/mlx5_vlan.c | 2 +- 13 files changed, 138 insertions(+), 88 deletions(-) rename drivers/{net => common}/mlx5/mlx5_nl.c (99%) rename drivers/{net => common}/mlx5/mlx5_nl.h (68%) diff --git a/drivers/common/mlx5/Makefile b/drivers/common/mlx5/Makefile index b9e9803167..6a14b7d695 100644 --- a/drivers/common/mlx5/Makefile +++ b/drivers/common/mlx5/Makefile @@ -15,6 +15,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_glue.c endif SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_devx_cmds.c SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_common.c +SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_nl.c ifeq ($(CONFIG_RTE_IBVERBS_LINK_DLOPEN),y) INSTALL-$(CONFIG_RTE_LIBRTE_MLX5_PMD)-lib += $(LIB_GLUE) @@ -41,7 +42,7 @@ else LDLIBS += -libverbs -lmlx5 endif -LDLIBS += -lrte_eal -lrte_pci -lrte_kvargs +LDLIBS += -lrte_eal -lrte_pci -lrte_kvargs -lrte_net # A few warnings cannot be avoided in external headers. CFLAGS += -Wno-error=cast-qual -DNDEBUG -UPEDANTIC diff --git a/drivers/common/mlx5/meson.build b/drivers/common/mlx5/meson.build index b88822ef00..34cb7b9e0d 100644 --- a/drivers/common/mlx5/meson.build +++ b/drivers/common/mlx5/meson.build @@ -42,6 +42,7 @@ if build sources = files( 'mlx5_devx_cmds.c', 'mlx5_common.c', + 'mlx5_nl.c', ) if not pmd_dlopen sources += files('mlx5_glue.c') diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c index 57d72b4af9..99d15cdd9f 100644 --- a/drivers/common/mlx5/mlx5_common.c +++ b/drivers/common/mlx5/mlx5_common.c @@ -105,6 +105,61 @@ mlx5_class_get(struct rte_devargs *devargs) return ret; } +/** + * Extract port name, as a number, from sysfs or netlink information. + * + * @param[in] port_name_in + * String representing the port name. + * @param[out] port_info_out + * Port information, including port name as a number and port name + * type if recognized + * + * @return + * port_name field set according to recognized name format. + */ +void +mlx5_translate_port_name(const char *port_name_in, + struct mlx5_switch_info *port_info_out) +{ + char pf_c1, pf_c2, vf_c1, vf_c2; + char *end; + int sc_items; + + /* + * Check for port-name as a string of the form pf0vf0 + * (support kernel ver >= 5.0 or OFED ver >= 4.6). + */ + sc_items = sscanf(port_name_in, "%c%c%d%c%c%d", + &pf_c1, &pf_c2, &port_info_out->pf_num, + &vf_c1, &vf_c2, &port_info_out->port_name); + if (sc_items == 6 && + pf_c1 == 'p' && pf_c2 == 'f' && + vf_c1 == 'v' && vf_c2 == 'f') { + port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_PFVF; + return; + } + /* + * Check for port-name as a string of the form p0 + * (support kernel ver >= 5.0, or OFED ver >= 4.6). + */ + sc_items = sscanf(port_name_in, "%c%d", + &pf_c1, &port_info_out->port_name); + if (sc_items == 2 && pf_c1 == 'p') { + port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_UPLINK; + return; + } + /* Check for port-name as a number (support kernel ver < 5.0 */ + errno = 0; + port_info_out->port_name = strtol(port_name_in, &end, 0); + if (!errno && + (size_t)(end - port_name_in) == strlen(port_name_in)) { + port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_LEGACY; + return; + } + port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN; + return; +} + #ifdef RTE_IBVERBS_LINK_DLOPEN /** diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h index 2988f4b26a..d9c2d262a0 100644 --- a/drivers/common/mlx5/mlx5_common.h +++ b/drivers/common/mlx5/mlx5_common.h @@ -17,6 +17,35 @@ #include "mlx5_prm.h" +/* + * Compilation workaround for PPC64 when AltiVec is fully enabled, e.g. std=c11. + * Otherwise there would be a type conflict between stdbool and altivec. + */ +#if defined(__PPC64__) && !defined(__APPLE_ALTIVEC__) +#undef bool +/* redefine as in stdbool.h */ +#define bool _Bool +#endif + +/* Bit-field manipulation. */ +#define BITFIELD_DECLARE(bf, type, size) \ + type bf[(((size_t)(size) / (sizeof(type) * CHAR_BIT)) + \ + !!((size_t)(size) % (sizeof(type) * CHAR_BIT)))] +#define BITFIELD_DEFINE(bf, type, size) \ + BITFIELD_DECLARE((bf), type, (size)) = { 0 } +#define BITFIELD_SET(bf, b) \ + (assert((size_t)(b) < (sizeof(bf) * CHAR_BIT)), \ + (void)((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] |= \ + ((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT))))) +#define BITFIELD_RESET(bf, b) \ + (assert((size_t)(b) < (sizeof(bf) * CHAR_BIT)), \ + (void)((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] &= \ + ~((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT))))) +#define BITFIELD_ISSET(bf, b) \ + (assert((size_t)(b) < (sizeof(bf) * CHAR_BIT)), \ + !!(((bf)[((b) / (sizeof((bf)[0]) * CHAR_BIT))] & \ + ((size_t)1 << ((b) % (sizeof((bf)[0]) * CHAR_BIT)))))) + /* * Helper macros to work around __VA_ARGS__ limitations in a C99 compliant * manner. @@ -112,6 +141,33 @@ enum { PCI_DEVICE_ID_MELLANOX_CONNECTX6DXVF = 0x101e, }; +/* Maximum number of simultaneous unicast MAC addresses. */ +#define MLX5_MAX_UC_MAC_ADDRESSES 128 +/* Maximum number of simultaneous Multicast MAC addresses. */ +#define MLX5_MAX_MC_MAC_ADDRESSES 128 +/* Maximum number of simultaneous MAC addresses. */ +#define MLX5_MAX_MAC_ADDRESSES \ + (MLX5_MAX_UC_MAC_ADDRESSES + MLX5_MAX_MC_MAC_ADDRESSES) + +/* Recognized Infiniband device physical port name types. */ +enum mlx5_nl_phys_port_name_type { + MLX5_PHYS_PORT_NAME_TYPE_NOTSET = 0, /* Not set. */ + MLX5_PHYS_PORT_NAME_TYPE_LEGACY, /* before kernel ver < 5.0 */ + MLX5_PHYS_PORT_NAME_TYPE_UPLINK, /* p0, kernel ver >= 5.0 */ + MLX5_PHYS_PORT_NAME_TYPE_PFVF, /* pf0vf0, kernel ver >= 5.0 */ + MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN, /* Unrecognized. */ +}; + +/** Switch information returned by mlx5_nl_switch_info(). */ +struct mlx5_switch_info { + uint32_t master:1; /**< Master device. */ + uint32_t representor:1; /**< Representor device. */ + enum mlx5_nl_phys_port_name_type name_type; /** < Port name type. */ + int32_t pf_num; /**< PF number (valid for pfxvfx format only). */ + int32_t port_name; /**< Representor port name. */ + uint64_t switch_id; /**< Switch identifier. */ +}; + /* CQE status. */ enum mlx5_cqe_status { MLX5_CQE_STATUS_SW_OWN = -1, @@ -159,6 +215,9 @@ enum mlx5_class { MLX5_CLASS_VDPA, MLX5_CLASS_INVALID, }; + enum mlx5_class mlx5_class_get(struct rte_devargs *devargs); +void mlx5_translate_port_name(const char *port_name_in, + struct mlx5_switch_info *port_info_out); #endif /* RTE_PMD_MLX5_COMMON_H_ */ diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/common/mlx5/mlx5_nl.c similarity index 99% rename from drivers/net/mlx5/mlx5_nl.c rename to drivers/common/mlx5/mlx5_nl.c index 6b8ca00418..31627436c9 100644 --- a/drivers/net/mlx5/mlx5_nl.c +++ b/drivers/common/mlx5/mlx5_nl.c @@ -18,11 +18,9 @@ #include #include -#include -#include "mlx5.h" #include "mlx5_nl.h" -#include "mlx5_utils.h" +#include "mlx5_common_utils.h" /* Size of the buffer to receive kernel messages */ #define MLX5_NL_BUF_SIZE (32 * 1024) diff --git a/drivers/net/mlx5/mlx5_nl.h b/drivers/common/mlx5/mlx5_nl.h similarity index 68% rename from drivers/net/mlx5/mlx5_nl.h rename to drivers/common/mlx5/mlx5_nl.h index 9be87c016e..8e66a98c66 100644 --- a/drivers/net/mlx5/mlx5_nl.h +++ b/drivers/common/mlx5/mlx5_nl.h @@ -7,25 +7,10 @@ #include +#include -/* Recognized Infiniband device physical port name types. */ -enum mlx5_nl_phys_port_name_type { - MLX5_PHYS_PORT_NAME_TYPE_NOTSET = 0, /* Not set. */ - MLX5_PHYS_PORT_NAME_TYPE_LEGACY, /* before kernel ver < 5.0 */ - MLX5_PHYS_PORT_NAME_TYPE_UPLINK, /* p0, kernel ver >= 5.0 */ - MLX5_PHYS_PORT_NAME_TYPE_PFVF, /* pf0vf0, kernel ver >= 5.0 */ - MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN, /* Unrecognized. */ -}; +#include "mlx5_common.h" -/** Switch information returned by mlx5_nl_switch_info(). */ -struct mlx5_switch_info { - uint32_t master:1; /**< Master device. */ - uint32_t representor:1; /**< Representor device. */ - enum mlx5_nl_phys_port_name_type name_type; /** < Port name type. */ - int32_t pf_num; /**< PF number (valid for pfxvfx format only). */ - int32_t port_name; /**< Representor port name. */ - uint64_t switch_id; /**< Switch identifier. */ -}; /* VLAN netdev for VLAN workaround. */ struct mlx5_nl_vlan_dev { diff --git a/drivers/common/mlx5/rte_common_mlx5_version.map b/drivers/common/mlx5/rte_common_mlx5_version.map index 3e7038bdc3..f93f5cb315 100644 --- a/drivers/common/mlx5/rte_common_mlx5_version.map +++ b/drivers/common/mlx5/rte_common_mlx5_version.map @@ -28,4 +28,20 @@ DPDK_20.02 { mlx5_devx_get_out_command_status; mlx5_dev_to_pci_addr; + + mlx5_nl_allmulti; + mlx5_nl_ifindex; + mlx5_nl_init; + mlx5_nl_mac_addr_add; + mlx5_nl_mac_addr_flush; + mlx5_nl_mac_addr_remove; + mlx5_nl_mac_addr_sync; + mlx5_nl_portnum; + mlx5_nl_promisc; + mlx5_nl_switch_info; + mlx5_nl_vf_mac_addr_modify; + mlx5_nl_vlan_vmwa_create; + mlx5_nl_vlan_vmwa_delete; + + mlx5_translate_port_name; }; diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile index dc6b3c8c38..d26afbb5b1 100644 --- a/drivers/net/mlx5/Makefile +++ b/drivers/net/mlx5/Makefile @@ -30,7 +30,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_flow_meter.c SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_flow_dv.c SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_flow_verbs.c SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_mp.c -SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_nl.c SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_utils.c SRCS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += mlx5_socket.c diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build index e10ef3ab2d..d45be00a68 100644 --- a/drivers/net/mlx5/meson.build +++ b/drivers/net/mlx5/meson.build @@ -19,7 +19,6 @@ sources = files( 'mlx5_flow_verbs.c', 'mlx5_mac.c', 'mlx5_mr.c', - 'mlx5_nl.c', 'mlx5_rss.c', 'mlx5_rxmode.c', 'mlx5_rxq.c', diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 9864aa7342..a7e70895e1 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -35,11 +35,11 @@ #include #include #include +#include #include "mlx5_defs.h" #include "mlx5_utils.h" #include "mlx5_mr.h" -#include "mlx5_nl.h" #include "mlx5_autoconf.h" /* Request types for IPC. */ diff --git a/drivers/net/mlx5/mlx5_defs.h b/drivers/net/mlx5/mlx5_defs.h index dc9b965c37..9b392ed036 100644 --- a/drivers/net/mlx5/mlx5_defs.h +++ b/drivers/net/mlx5/mlx5_defs.h @@ -14,14 +14,6 @@ /* Reported driver name. */ #define MLX5_DRIVER_NAME "net_mlx5" -/* Maximum number of simultaneous unicast MAC addresses. */ -#define MLX5_MAX_UC_MAC_ADDRESSES 128 -/* Maximum number of simultaneous Multicast MAC addresses. */ -#define MLX5_MAX_MC_MAC_ADDRESSES 128 -/* Maximum number of simultaneous MAC addresses. */ -#define MLX5_MAX_MAC_ADDRESSES \ - (MLX5_MAX_UC_MAC_ADDRESSES + MLX5_MAX_MC_MAC_ADDRESSES) - /* Maximum number of simultaneous VLAN filters. */ #define MLX5_MAX_VLAN_IDS 128 diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c index 5484104cb6..b765636620 100644 --- a/drivers/net/mlx5/mlx5_ethdev.c +++ b/drivers/net/mlx5/mlx5_ethdev.c @@ -1939,61 +1939,6 @@ mlx5_sysfs_check_switch_info(bool device_dir, } } -/** - * Extract port name, as a number, from sysfs or netlink information. - * - * @param[in] port_name_in - * String representing the port name. - * @param[out] port_info_out - * Port information, including port name as a number and port name - * type if recognized - * - * @return - * port_name field set according to recognized name format. - */ -void -mlx5_translate_port_name(const char *port_name_in, - struct mlx5_switch_info *port_info_out) -{ - char pf_c1, pf_c2, vf_c1, vf_c2; - char *end; - int sc_items; - - /* - * Check for port-name as a string of the form pf0vf0 - * (support kernel ver >= 5.0 or OFED ver >= 4.6). - */ - sc_items = sscanf(port_name_in, "%c%c%d%c%c%d", - &pf_c1, &pf_c2, &port_info_out->pf_num, - &vf_c1, &vf_c2, &port_info_out->port_name); - if (sc_items == 6 && - pf_c1 == 'p' && pf_c2 == 'f' && - vf_c1 == 'v' && vf_c2 == 'f') { - port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_PFVF; - return; - } - /* - * Check for port-name as a string of the form p0 - * (support kernel ver >= 5.0, or OFED ver >= 4.6). - */ - sc_items = sscanf(port_name_in, "%c%d", - &pf_c1, &port_info_out->port_name); - if (sc_items == 2 && pf_c1 == 'p') { - port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_UPLINK; - return; - } - /* Check for port-name as a number (support kernel ver < 5.0 */ - errno = 0; - port_info_out->port_name = strtol(port_name_in, &end, 0); - if (!errno && - (size_t)(end - port_name_in) == strlen(port_name_in)) { - port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_LEGACY; - return; - } - port_info_out->name_type = MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN; - return; -} - /** * DPDK callback to retrieve plug-in module EEPROM information (type and size). * diff --git a/drivers/net/mlx5/mlx5_vlan.c b/drivers/net/mlx5/mlx5_vlan.c index fc1a91c303..8e63b674ee 100644 --- a/drivers/net/mlx5/mlx5_vlan.c +++ b/drivers/net/mlx5/mlx5_vlan.c @@ -33,11 +33,11 @@ #include #include +#include #include "mlx5.h" #include "mlx5_autoconf.h" #include "mlx5_rxtx.h" -#include "mlx5_nl.h" #include "mlx5_utils.h" /** -- 2.20.1