X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=VNFs%2FDPPD-PROX%2Fcommands.c;h=a8953a68ab306754ef043503e183a2d45e2acc4c;hb=090efc9c81c8b1943d162249d965a3e40502d50e;hp=9f0be145b311cf91f1ff583b592154ea69c4246d;hpb=2c437c3c5c75d78a0adb4f2ebfa454943b8063ad;p=samplevnf.git diff --git a/VNFs/DPPD-PROX/commands.c b/VNFs/DPPD-PROX/commands.c index 9f0be145..a8953a68 100644 --- a/VNFs/DPPD-PROX/commands.c +++ b/VNFs/DPPD-PROX/commands.c @@ -1,5 +1,5 @@ /* -// Copyright (c) 2010-2017 Intel Corporation +// Copyright (c) 2010-2020 Intel Corporation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -18,6 +18,9 @@ #include #include #include +#if RTE_VERSION >= RTE_VERSION_NUM(18,5,0,0) +#include +#endif #include "prox_malloc.h" #include "display.h" @@ -110,8 +113,8 @@ static inline int wait_command_handled(struct lcore_cfg *lconf) static inline void start_l3(struct task_args *targ) { if (!task_is_master(targ)) { - if ((targ->nb_txrings != 0) || (targ->nb_txports != 0)) { - if (targ->flags & TASK_ARG_L3) + if ((targ->nb_txports != 0)) { + if (targ->flags & (TASK_ARG_L3|TASK_ARG_NDP)) task_start_l3(targ->tbase, targ); } } @@ -134,10 +137,14 @@ void start_cores(uint32_t *cores, int count, int task_id) targ = &lconf->targs[tid]; start_l3(targ); } - } else { + } else if (task_id < lconf->n_tasks_all) { targ = &lconf->targs[task_id]; start_l3(targ); + } else { + plog_warn("Invalid task id %d on core %u\n", task_id, cores[i]); + continue; } + if (wait_command_handled(lconf) == -1) return; lconf->msg.type = LCONF_MSG_START; lconf->msg.task_id = task_id; lconf_set_req(lconf); @@ -174,6 +181,10 @@ void stop_cores(uint32_t *cores, int count, int task_id) for (int i = 0; i < count; ++i) { struct lcore_cfg *lconf = &lcore_cfg[cores[i]]; + if (task_id >= lconf->n_tasks_all) { + plog_warn("Trying to stop invalid task id %d on core %u\n", task_id, cores[i]); + continue; + } if (lconf->n_tasks_run) { if (wait_command_handled(lconf) == -1) return; @@ -235,6 +246,61 @@ static struct size_unit to_size_unit(uint64_t bytes) return ret; } +static int add_multicast_addr(uint8_t port_id, prox_rte_ether_addr *addr) +{ + unsigned int i; + int rc = 0; + + struct prox_port_cfg* port_cfg = &prox_port_cfg[port_id]; + + if (port_cfg->nb_mc_addr >= NB_MCAST_ADDR) { + plog_err("Already reached maximum number (%d) of mcast addr on port %u\n", NB_MCAST_ADDR, port_id); + return -1; + } + for (i = 0; i < port_cfg->nb_mc_addr; i++) { + if (prox_rte_is_same_ether_addr(addr, &port_cfg->mc_addr[i])) { + plog_info("multicast address already added to port\n"); + return -1; + } + } + + prox_rte_ether_addr_copy(addr, &port_cfg->mc_addr[port_cfg->nb_mc_addr]); + if ((rc = rte_eth_dev_set_mc_addr_list(port_id, port_cfg->mc_addr, port_cfg->nb_mc_addr + 1)) != 0) { + plog_err("rte_eth_dev_set_mc_addr_list returns %d on port %u\n", rc, port_id); + return rc; + } + + port_cfg->nb_mc_addr++; + plog_info("rte_eth_dev_set_mc_addr_list(%d addr) on port %u\n", port_cfg->nb_mc_addr, port_id); + return rc; +} + +static int del_multicast_addr(uint8_t port_id, prox_rte_ether_addr *addr) +{ + unsigned int i; + int rc = 0; + + struct prox_port_cfg* port_cfg = &prox_port_cfg[port_id]; + + for (i = 0; i < port_cfg->nb_mc_addr; i++) { + if (prox_rte_is_same_ether_addr(addr, &port_cfg->mc_addr[i])) { + // Copy last address to the slot to be deleted + prox_rte_ether_addr_copy(&port_cfg->mc_addr[port_cfg->nb_mc_addr-1], &port_cfg->mc_addr[i]); + + if ((rc = rte_eth_dev_set_mc_addr_list(port_id, port_cfg->mc_addr, port_cfg->nb_mc_addr - 1)) != 0) { + plog_err("rte_eth_dev_set_mc_addr_list returns %d on port %u\n", rc, port_id); + // When set failed, let restore the situation we were before calling the function... + prox_rte_ether_addr_copy(addr, &port_cfg->mc_addr[i]); + return rc; + } + port_cfg->nb_mc_addr--; + plog_info("rte_eth_dev_set_mc_addr_list(%d addr) on port %u\n", port_cfg->nb_mc_addr, port_id); + return 0; + } + } + plog_err("multicast address not found on port %u\n", port_id); + return -1; +} void cmd_mem_stats(void) { struct rte_malloc_socket_stats sock_stats; @@ -259,8 +325,101 @@ void cmd_mem_stats(void) } } +static void get_hp_sz_string(char *sz_str, uint64_t hp_sz) +{ + switch (hp_sz >> 20) { + case 0: + strcpy(sz_str, " 0 "); + break; + case 2: + strcpy(sz_str, "2MB"); + break; + case 1024: + strcpy(sz_str, "1GB"); + break; + default: + strcpy(sz_str, "??"); + } +} + +#if RTE_VERSION >= RTE_VERSION_NUM(18,5,0,0) +// Print all segments, 1 by 1 +// Unused for now, keep for reference +static int print_all_segments(const struct rte_memseg_list *memseg_list, const struct rte_memseg *memseg, void *arg) +{ + int memseg_list_idx = 0, memseg_idx; + int n = (*(int *)arg)++; + +#if RTE_VERSION < RTE_VERSION_NUM(19,8,0,0) + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; + memseg_list_idx = memseg_list - mcfg->memsegs; + if ((memseg_list_idx < 0) || (memseg_list_idx >= RTE_MAX_MEMSEG_LISTS)) { + plog_err("Invalid memseg_list_idx = %d; memseg_list = %p, mcfg->memsegs = %p\n", memseg_list_idx, memseg_list, mcfg->memsegs); + return -1; + } +#endif + memseg_idx = rte_fbarray_find_idx(&memseg_list->memseg_arr, memseg); + if (memseg_idx < 0) { + plog_err("Invalid memseg_idx = %d; memseg_list = %p, memseg = %p\n", memseg_idx, memseg_list, memseg); + return -1; + } + + char sz_str[5]; + get_hp_sz_string(sz_str, memseg->hugepage_sz); + plog_info("Segment %u (sock %d): [%i-%i] [%#lx-%#lx] at %p using %zu pages of %s\n", + n, + memseg->socket_id, + memseg_list_idx, + memseg_idx, + memseg->iova, + memseg->iova+memseg->len, + memseg->addr, + memseg->len/memseg->hugepage_sz, sz_str); + + return 0; +} + +// Print memory segments +// Contiguous segments are shown as 1 big segment +static int print_segments(const struct rte_memseg_list *memseg_list, const struct rte_memseg *memseg, size_t len, void *arg) +{ + int memseg_list_idx = 0, memseg_idx; + static int n = 0; + +#if RTE_VERSION < RTE_VERSION_NUM(19,8,0,0) + struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config; + memseg_list_idx = memseg_list - mcfg->memsegs; + if ((memseg_list_idx < 0) || (memseg_list_idx >= RTE_MAX_MEMSEG_LISTS)) { + plog_err("Invalid memseg_list_idx = %d; memseg_list = %p, mcfg->memsegs = %p\n", memseg_list_idx, memseg_list, mcfg->memsegs); + return -1; + } +#endif + memseg_idx = rte_fbarray_find_idx(&memseg_list->memseg_arr, memseg); + if (memseg_idx < 0) { + plog_err("Invalid memseg_idx = %d; memseg_list = %p, memseg = %p\n", memseg_idx, memseg_list, memseg); + return -1; + } + + char sz_str[5]; + get_hp_sz_string(sz_str, memseg->hugepage_sz); + plog_info("Segment %u (sock %d): [%i-%i] [%#lx-%#lx] at %p using %zu pages of %s\n", + n++, + memseg->socket_id, + memseg_list_idx, + memseg_idx, + memseg->iova, + memseg->iova+len, + memseg->addr, + memseg->hugepage_sz?len/memseg->hugepage_sz:0, sz_str); + + return 0; +} + +#endif + void cmd_mem_layout(void) { +#if RTE_VERSION < RTE_VERSION_NUM(18,5,0,0) const struct rte_memseg* memseg = rte_eal_get_physmem_layout(); plog_info("Memory layout:\n"); @@ -268,17 +427,8 @@ void cmd_mem_layout(void) if (memseg[i].addr == NULL) break; - const char *sz_str; - switch (memseg[i].hugepage_sz >> 20) { - case 2: - sz_str = "2MB"; - break; - case 1024: - sz_str = "1GB"; - break; - default: - sz_str = "??"; - } + char sz_str[5]; + get_hp_sz_string(sz_str, memseg[i].hugepage_sz); plog_info("Segment %u: [%#lx-%#lx] at %p using %zu pages of %s\n", i, @@ -287,6 +437,11 @@ void cmd_mem_layout(void) memseg[i].addr, memseg[i].len/memseg[i].hugepage_sz, sz_str); } +#else + int segment_number = 0; + //rte_memseg_walk(print_all_segments, &segment_number); + rte_memseg_contig_walk(print_segments, &segment_number); +#endif } void cmd_dump(uint8_t lcore_id, uint8_t task_id, uint32_t nb_packets, struct input *input, int rx, int tx) @@ -740,7 +895,7 @@ void cmd_portinfo(int port_id, char *dst, size_t max_len) dst += snprintf(dst, end - dst, "%2d:%10s; "MAC_BYTES_FMT"; %s\n", port_id, - port_cfg->name, + port_cfg->names[0], MAC_BYTES(port_cfg->eth_addr.addr_bytes), port_cfg->pci_addr); } @@ -754,14 +909,18 @@ void cmd_portinfo(int port_id, char *dst, size_t max_len) struct prox_port_cfg* port_cfg = &prox_port_cfg[port_id]; dst += snprintf(dst, end - dst, "Port info for port %u\n", port_id); - dst += snprintf(dst, end - dst, "\tName: %s\n", port_cfg->name); + dst += snprintf(dst, end - dst, "\tName: %s\n", port_cfg->names[0]); dst += snprintf(dst, end - dst, "\tDriver: %s\n", port_cfg->driver_name); dst += snprintf(dst, end - dst, "\tMac address: "MAC_BYTES_FMT"\n", MAC_BYTES(port_cfg->eth_addr.addr_bytes)); dst += snprintf(dst, end - dst, "\tLink speed: %u Mbps\n", port_cfg->link_speed); + dst += snprintf(dst, end - dst, "\tLink max speed: %u Mbps\n", port_cfg->max_link_speed); dst += snprintf(dst, end - dst, "\tLink status: %s\n", port_cfg->link_up? "up" : "down"); dst += snprintf(dst, end - dst, "\tSocket: %u\n", port_cfg->socket); dst += snprintf(dst, end - dst, "\tPCI address: %s\n", port_cfg->pci_addr); dst += snprintf(dst, end - dst, "\tPromiscuous: %s\n", port_cfg->promiscuous? "yes" : "no"); + for (unsigned int i = 0; i < port_cfg->nb_mc_addr; i++) { + dst += snprintf(dst, end - dst, "\tmcast address: "MAC_BYTES_FMT"\n", MAC_BYTES(port_cfg->mc_addr[i].addr_bytes)); + } dst += snprintf(dst, end - dst, "\tNumber of RX/TX descriptors: %u/%u\n", port_cfg->n_rxd, port_cfg->n_txd); dst += snprintf(dst, end - dst, "\tNumber of RX/TX queues: %u/%u (max: %u/%u)\n", port_cfg->n_rxq, port_cfg->n_txq, port_cfg->max_rxq, port_cfg->max_txq); dst += snprintf(dst, end - dst, "\tMemory pools:\n"); @@ -802,6 +961,32 @@ void cmd_reset_port(uint8_t portid) plog_warn("Failed to restart port %d\n", portid); } } + +void cmd_multicast(uint8_t port_id, unsigned int val, prox_rte_ether_addr *mac) +{ + if (!port_is_active(port_id)) { + return; + } + struct prox_port_cfg* port_cfg = &prox_port_cfg[port_id]; + if (val == 1) { + if (port_cfg->nb_mc_addr == 0) { + rte_eth_allmulticast_enable(port_id); + } + if (add_multicast_addr(port_id, mac) != 0) { + if (port_cfg->nb_mc_addr == 0) + rte_eth_allmulticast_disable(port_id); + } + } else if (val == 0) { + if (del_multicast_addr(port_id, mac) == 0) { + if (port_cfg->nb_mc_addr == 0) { + rte_eth_allmulticast_disable(port_id); + } + } + } else { + plog_err("Unexpected value in cmd_multicast on port %d\n", port_id); + } +} + void cmd_write_reg(uint8_t port_id, unsigned int id, unsigned int val) { if (!port_is_active(port_id)) { @@ -819,7 +1004,7 @@ void cmd_set_vlan_offload(uint8_t port_id, unsigned int val) } plog_info("setting vlan offload to %d\n", val); - if (val & ~(ETH_VLAN_STRIP_OFFLOAD | ETH_VLAN_FILTER_OFFLOAD | ETH_VLAN_EXTEND_OFFLOAD)) { + if (val & ~(RTE_ETH_VLAN_STRIP_OFFLOAD | RTE_ETH_VLAN_FILTER_OFFLOAD | RTE_ETH_VLAN_EXTEND_OFFLOAD)) { plog_info("wrong vlan offload value\n"); } int ret = rte_eth_dev_set_vlan_offload(port_id, val);