summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsongyanchao <[email protected]>2022-12-09 06:35:43 +0000
committersongyanchao <[email protected]>2022-12-09 06:35:43 +0000
commit06aee2ce41443efec56255732e40f9428d265282 (patch)
tree7eecc15228cdb6f6f59b7b54a0f7177958f190cf
parent15cfb616688016c50e67edfcdb7ab68985e7f59d (diff)
🐞 fix(TSG-13030): 修改因EAL参数错误导致网卡无法被驱动接管的问题v4.5.5-20221209
修改因EAL参数错误导致网卡无法被驱动接管的问题
-rw-r--r--service/src/core.c37
-rw-r--r--service/src/phydev.c56
2 files changed, 49 insertions, 44 deletions
diff --git a/service/src/core.c b/service/src/core.c
index a009468..bf3aec0 100644
--- a/service/src/core.c
+++ b/service/src/core.c
@@ -15,13 +15,13 @@
#include <unistd.h>
#include <MESA_prof_load.h>
+#include <cJSON.h>
#include <ctrlmsg.h>
#include <ldbc.h>
#include <sc_common.h>
#include <sc_mrb.h>
#include <sc_vdev.h>
#include <systemd/sd-daemon.h>
-#include <cJSON.h>
const char * mr_logo = " __ ___ _ _____ ______\n"
" / |/ /___ ___________(_)__/__ / ___ _________ / ____/___ ____ __ __\n"
@@ -61,11 +61,11 @@ const char service_git_version[] = "";
#endif
#ifndef MR_PMD_BASIC_LIB_PATH
-#define MR_PMD_BASIC_LIB_PATH "/opt/tsg/mrzcpd/lib/pmds"
+#define MR_PMD_BASIC_LIB_PATH "/opt/tsg/mrzcpd/lib/pmds"
#endif
#ifndef MR_PMD_FOR_MLX5_DRIVER_PATH
-#define MR_PMD_FOR_MLX5_DRIVER_PATH "/opt/tsg/mrzcpd/lib/pmds/mlx5"
+#define MR_PMD_FOR_MLX5_DRIVER_PATH "/opt/tsg/mrzcpd/lib/pmds/mlx5"
#endif
#ifndef MR_SERVICE_DEFAULT_RX_BURST
@@ -371,10 +371,9 @@ static void sc_eal_init(struct sc_main * sc, const char * cmd)
unsigned int main_core = 0;
MESA_load_profile_uint_def(sc->local_cfgfile, "service", "main_core", &main_core, 0);
- nr_io_cores = MESA_load_profile_uint_range(sc->local_cfgfile,
- "service", "iocore", RTE_DIM(io_cores), io_cores);
- nr_smartoffload_cores = MESA_load_profile_uint_range(sc->local_cfgfile,
- "service", "offload_core", RTE_DIM(smartoffload_cores), smartoffload_cores);
+ nr_io_cores = MESA_load_profile_uint_range(sc->local_cfgfile, "service", "iocore", RTE_DIM(io_cores), io_cores);
+ nr_smartoffload_cores = MESA_load_profile_uint_range(sc->local_cfgfile, "service", "offload_core",
+ RTE_DIM(smartoffload_cores), smartoffload_cores);
if (nr_io_cores < 0)
{
@@ -458,7 +457,8 @@ static void sc_eal_init(struct sc_main * sc, const char * cmd)
}
char str_socket_mem[MR_STRING_MAX];
- ret = MESA_load_profile_string_nodef(sc->local_cfgfile, "eal", "socket-mem", str_socket_mem, sizeof(str_socket_mem));
+ ret =
+ MESA_load_profile_string_nodef(sc->local_cfgfile, "eal", "socket-mem", str_socket_mem, sizeof(str_socket_mem));
if (ret > 0)
{
@@ -482,7 +482,7 @@ static void sc_eal_init(struct sc_main * sc, const char * cmd)
char str_devargs[MR_STRING_MAX];
snprintf(str_devargs, sizeof(str_devargs) - 1, "%s", phydev_wh_iter->pci_addr);
- if(phydev_wh_iter->mlx5_allow_duplicate_pattern == 0)
+ if (phydev_wh_iter->mlx5_allow_duplicate_pattern)
{
strcat(str_devargs, ",allow_duplicate_pattern=0");
}
@@ -840,7 +840,7 @@ cJSON * service_monit_loop(struct sc_main * sc)
}
static int __rte_service_register_helper(const struct rte_service_spec * spec, const cpu_set_t * cpu_set,
- unsigned int * out_service_id)
+ unsigned int * out_service_id)
{
int ret = 0;
uint32_t service_id = 0;
@@ -1043,8 +1043,9 @@ int main(int argc, char * argv[])
if (flow_main_init(sc) != RT_SUCCESS)
{
- MR_ERROR("offload management module initialization failed. ");
- ret = EXIT_FAILURE; goto quit;
+ MR_ERROR("offload management module initialization failed. ");
+ ret = EXIT_FAILURE;
+ goto quit;
}
if (hwinfo_init(sc) != RT_SUCCESS)
@@ -1078,7 +1079,8 @@ int main(int argc, char * argv[])
if (sw_vlan_base_forward_init(sc) != RT_SUCCESS)
{
MR_ERROR("Vlan Base switch module initialization failed. ");
- ret = EXIT_FAILURE; goto quit;
+ ret = EXIT_FAILURE;
+ goto quit;
}
if (smartoffload_init(sc) != RT_SUCCESS)
@@ -1212,8 +1214,9 @@ int main(int argc, char * argv[])
goto quit;
}
- ret = __rte_service_register_helper(&sw_vlan_base_fwd_service_spec, &sc->cpu_set_io, &sw_info_sw_vlan_fwd.service_id);
- if(unlikely(ret < 0))
+ ret =
+ __rte_service_register_helper(&sw_vlan_base_fwd_service_spec, &sc->cpu_set_io, &sw_info_sw_vlan_fwd.service_id);
+ if (unlikely(ret < 0))
{
MR_ERROR("Failed at starting service %s", sw_vlan_base_fwd_service_spec.name);
goto quit;
@@ -1238,14 +1241,14 @@ int main(int argc, char * argv[])
continue;
ret = rte_service_lcore_start(lcore_id);
- if (ret && ret !=-EALREADY)
+ if (ret && ret != -EALREADY)
{
MR_ERROR("Failed at start service core %u: ret = %d", lcore_id, ret);
goto quit;
}
}
- while(true)
+ while (true)
{
sleep(1);
}
diff --git a/service/src/phydev.c b/service/src/phydev.c
index e691651..d556121 100644
--- a/service/src/phydev.c
+++ b/service/src/phydev.c
@@ -1,11 +1,11 @@
/// 物理设备管理器
#include <assert.h>
+#include <net/if.h>
#include <stdio.h>
+#include <sys/ioctl.h>
#include <sys/queue.h>
#include <unistd.h>
-#include <sys/ioctl.h>
-#include <net/if.h>
#include <rte_bus_pci.h>
#include <rte_config.h>
@@ -388,7 +388,7 @@ static int phydev_setup_default_flows(struct sc_main * sc, struct phydev_main *
attr.priority = 3;
memset(&flow_error, 0, sizeof(flow_error));
- //memset(&pattern, 0, sizeof(pattern));
+ // memset(&pattern, 0, sizeof(pattern));
memset(&actions, 0, sizeof(actions));
uint16_t target_queue_id[__QGROUP_MAX_QUEUE] = {};
@@ -410,15 +410,15 @@ static int phydev_setup_default_flows(struct sc_main * sc, struct phydev_main *
}
else if (dev->info.rssmode == MR_DEV_RSSMODE_4TUPLE_SYM)
{
- rss_type = ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_NONFRAG_IPV6_TCP |
- ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_NONFRAG_IPV6_UDP;
+ rss_type =
+ ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_NONFRAG_IPV6_UDP;
rss_key = default_sym_rss_key;
rss_key_len = sizeof(default_sym_rss_key);
}
else if (dev->info.rssmode == MR_DEV_RSSMODE_4TUPLE_ASYM)
{
- rss_type = ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_NONFRAG_IPV6_TCP |
- ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_NONFRAG_IPV6_UDP;
+ rss_type =
+ ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_NONFRAG_IPV6_UDP;
rss_key = NULL;
}
@@ -489,14 +489,14 @@ static int phydev_setup(struct sc_main * sc, struct phydev_main * ctx, struct ph
Check this NIC can support hairpin or not.
The SmartOffload can not use when hairpin mode is unavailable.
*/
- if (dev->en_smartoffload )
+ if (dev->en_smartoffload)
{
struct rte_eth_hairpin_cap hairpin_cap = {};
retval = rte_eth_dev_hairpin_capability_get(dev->port_id, &hairpin_cap);
if (unlikely(retval != 0))
{
- MR_ERROR("device %s hairpin mode is unavliable, SmartOffload can not be enabled: retval = %d, %s", dev->symbol,
- retval, rte_strerror(retval));
+ MR_ERROR("device %s hairpin mode is unavliable, SmartOffload can not be enabled: retval = %d, %s",
+ dev->symbol, retval, rte_strerror(retval));
return RT_ERR;
}
}
@@ -709,7 +709,8 @@ int whitelist_phydev_iterate(struct phydev_main * ctx, struct phydev_whitelist *
}
// 迭代到尾部,返回错误码
- if (*phydev_wh == NULL) return -ENOENT;
+ if (*phydev_wh == NULL)
+ return -ENOENT;
return 0;
}
@@ -804,7 +805,7 @@ void phydev_unuse_queue(struct phydev * dev, enum phydev_qgroup_type q_type, que
#endif
#ifndef PHYDEV_DEFAULT_EN_EARLY_SCAN
-#define PHYDEV_DEFAULT_EN_EARLY_SCAN 1
+#define PHYDEV_DEFAULT_EN_EARLY_SCAN 1
#endif
#ifndef PHYDEV_DEFAULT_EN_LOAD_HWFILE
@@ -920,13 +921,13 @@ int set_virtio_tap_up(const char * virtio_sym)
fd = socket(AF_INET, SOCK_DGRAM, 0);
strncpy(ifr.ifr_name, virtio_sym, IFNAMSIZ - 1);
- if(ioctl(fd, SIOCGIFFLAGS, &ifr) != 0)
+ if (ioctl(fd, SIOCGIFFLAGS, &ifr) != 0)
{
return RT_ERR;
}
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
- if(ioctl(fd, SIOCSIFFLAGS, &ifr) != 0)
+ if (ioctl(fd, SIOCSIFFLAGS, &ifr) != 0)
{
return RT_ERR;
}
@@ -940,8 +941,8 @@ static int phydev_get_pci_info_by_hwfile(struct phydev_main * phydev_main, struc
cJSON * j_hwfile = phydev_main->j_hwfile;
if (j_hwfile == NULL)
{
- MR_ERROR("j_hwfile is NULL \n");
- return RT_SUCCESS;
+ MR_ERROR("j_hwfile is NULL \n");
+ return RT_SUCCESS;
}
/* 在JSON文件中查找设备,根据网卡名称查找 */
@@ -953,8 +954,14 @@ static int phydev_get_pci_info_by_hwfile(struct phydev_main * phydev_main, struc
MR_VERIFY(j_interface != NULL);
/* 如果设备名不匹配则跳过 */
- if (strcmp(j_interface->valuestring,phydev_wh->symbol) !=0)
- continue;
+ if (strcmp(j_interface->valuestring, phydev_wh->symbol) != 0)
+ continue;
+
+ /* 判断是否是mlx设备 */
+ cJSON * j_driver = cJSON_GetObjectItem(j_phydev, "Driver_str");
+ MR_VERIFY(j_driver != NULL);
+ if (strncmp(j_driver->valuestring, "mlx", 3) == 0)
+ phydev_wh->mlx5_allow_duplicate_pattern = 1;
/* 获取PCI号 */
cJSON * j_slot = cJSON_GetObjectItem(j_phydev, "Slot");
@@ -980,9 +987,8 @@ static int phydev_early_scan(struct sc_main * sc, struct phydev_main * phydev_ma
int nr_str_tokens = rte_strsplit(str_device, sizeof(str_device), str_dev_symbol, MR_TOKENS_MAX, ',');
if (nr_str_tokens < 0)
- {
return RT_ERR;
- }
+
/* 遍历所有dev设备 */
for (int i = 0; i < nr_str_tokens; i++)
{
@@ -993,12 +999,7 @@ static int phydev_early_scan(struct sc_main * sc, struct phydev_main * phydev_ma
/* 根据设备名称提取对应的PCI号 */
int ret = phydev_get_pci_info_by_hwfile(phydev_main, phydev_wh);
if (ret == RT_ERR)
- {
return RT_ERR;
- }
-
- /* TODO: */
- phydev_wh->mlx5_allow_duplicate_pattern = 0;
}
return RT_SUCCESS;
@@ -1097,7 +1098,8 @@ static int phydev_scan_virtio_user(struct sc_main * sc, struct phydev_main * phy
snprintf(vdev_name, sizeof(vdev_name) - 1, "virtio_user%d", i);
char vdev_args[MR_STRING_MAX];
- snprintf(vdev_args, sizeof(vdev_args) - 1, "queues=%d,queue_size=1024,path=/dev/vhost-net,iface=%s", sc->nr_io_thread, virtio_syms[i]);
+ snprintf(vdev_args, sizeof(vdev_args) - 1, "queues=%d,queue_size=1024,path=/dev/vhost-net,iface=%s",
+ sc->nr_io_thread, virtio_syms[i]);
int ret = rte_eal_hotplug_add("vdev", vdev_name, vdev_args);
if (ret < 0)
@@ -1109,7 +1111,7 @@ static int phydev_scan_virtio_user(struct sc_main * sc, struct phydev_main * phy
ret = set_virtio_tap_up(virtio_syms[i]);
if (ret < 0)
{
- MR_ERROR("Cannot Set The Tap Dev Up:%s\n",virtio_syms[i]);
+ MR_ERROR("Cannot Set The Tap Dev Up:%s\n", virtio_syms[i]);
return RT_ERR;
}