ethdev: fix max Rx packet length
[dpdk.git] / app / test-pmd / config.c
index 7221644..333d3dd 100644 (file)
@@ -175,6 +175,65 @@ print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
        printf("%s%s", name, buf);
 }
 
+static void
+nic_xstats_display_periodic(portid_t port_id)
+{
+       struct xstat_display_info *xstats_info;
+       uint64_t *prev_values, *curr_values;
+       uint64_t diff_value, value_rate;
+       struct timespec cur_time;
+       uint64_t *ids_supp;
+       size_t ids_supp_sz;
+       uint64_t diff_ns;
+       unsigned int i;
+       int rc;
+
+       xstats_info = &ports[port_id].xstats_info;
+
+       ids_supp_sz = xstats_info->ids_supp_sz;
+       if (ids_supp_sz == 0)
+               return;
+
+       printf("\n");
+
+       ids_supp = xstats_info->ids_supp;
+       prev_values = xstats_info->prev_values;
+       curr_values = xstats_info->curr_values;
+
+       rc = rte_eth_xstats_get_by_id(port_id, ids_supp, curr_values,
+                                     ids_supp_sz);
+       if (rc != (int)ids_supp_sz) {
+               fprintf(stderr,
+                       "Failed to get values of %zu xstats for port %u - return code %d\n",
+                       ids_supp_sz, port_id, rc);
+               return;
+       }
+
+       diff_ns = 0;
+       if (clock_gettime(CLOCK_TYPE_ID, &cur_time) == 0) {
+               uint64_t ns;
+
+               ns = cur_time.tv_sec * NS_PER_SEC;
+               ns += cur_time.tv_nsec;
+
+               if (xstats_info->prev_ns != 0)
+                       diff_ns = ns - xstats_info->prev_ns;
+               xstats_info->prev_ns = ns;
+       }
+
+       printf("%-31s%-17s%s\n", " ", "Value", "Rate (since last show)");
+       for (i = 0; i < ids_supp_sz; i++) {
+               diff_value = (curr_values[i] > prev_values[i]) ?
+                            (curr_values[i] - prev_values[i]) : 0;
+               prev_values[i] = curr_values[i];
+               value_rate = diff_ns > 0 ?
+                               (double)diff_value / diff_ns * NS_PER_SEC : 0;
+
+               printf("  %-25s%12"PRIu64" %15"PRIu64"\n",
+                      xstats_display[i].name, curr_values[i], value_rate);
+       }
+}
+
 void
 nic_stats_display(portid_t port_id)
 {
@@ -245,6 +304,9 @@ nic_stats_display(portid_t port_id)
               PRIu64"          Tx-bps: %12"PRIu64"\n", mpps_rx, mbps_rx * 8,
               mpps_tx, mbps_tx * 8);
 
+       if (xstats_display_num > 0)
+               nic_xstats_display_periodic(port_id);
+
        printf("  %s############################%s\n",
               nic_stats_border, nic_stats_border);
 }
@@ -1147,7 +1209,6 @@ port_mtu_set(portid_t port_id, uint16_t mtu)
        int diag;
        struct rte_port *rte_port = &ports[port_id];
        struct rte_eth_dev_info dev_info;
-       uint16_t eth_overhead;
        int ret;
 
        if (port_id_is_invalid(port_id, ENABLED_WARN))
@@ -1164,21 +1225,18 @@ port_mtu_set(portid_t port_id, uint16_t mtu)
                return;
        }
        diag = rte_eth_dev_set_mtu(port_id, mtu);
-       if (diag)
+       if (diag != 0) {
                fprintf(stderr, "Set MTU failed. diag=%d\n", diag);
-       else if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) {
-               /*
-                * Ether overhead in driver is equal to the difference of
-                * max_rx_pktlen and max_mtu in rte_eth_dev_info when the
-                * device supports jumbo frame.
-                */
-               eth_overhead = dev_info.max_rx_pktlen - dev_info.max_mtu;
-               if (mtu > RTE_ETHER_MTU) {
+               return;
+       }
+
+       rte_port->dev_conf.rxmode.mtu = mtu;
+
+       if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) {
+               if (mtu > RTE_ETHER_MTU)
                        rte_port->dev_conf.rxmode.offloads |=
                                                DEV_RX_OFFLOAD_JUMBO_FRAME;
-                       rte_port->dev_conf.rxmode.max_rx_pkt_len =
-                                               mtu + eth_overhead;
-               } else
+               else
                        rte_port->dev_conf.rxmode.offloads &=
                                                ~DEV_RX_OFFLOAD_JUMBO_FRAME;
        }
@@ -1505,10 +1563,25 @@ port_action_handle_create(portid_t port_id, uint32_t id,
        struct port_indirect_action *pia;
        int ret;
        struct rte_flow_error error;
+       struct rte_port *port;
+
+       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+           port_id == (portid_t)RTE_PORT_ALL)
+               return -EINVAL;
 
        ret = action_alloc(port_id, id, &pia);
        if (ret)
                return ret;
+
+       port = &ports[port_id];
+
+       if (conf->transfer)
+               port_id = port->flow_transfer_proxy;
+
+       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+           port_id == (portid_t)RTE_PORT_ALL)
+               return -EINVAL;
+
        if (action->type == RTE_FLOW_ACTION_TYPE_AGE) {
                struct rte_flow_action_age *age =
                        (struct rte_flow_action_age *)(uintptr_t)(action->conf);
@@ -1531,6 +1604,7 @@ port_action_handle_create(portid_t port_id, uint32_t id,
                return port_flow_complain(&error);
        }
        pia->type = action->type;
+       pia->transfer = conf->transfer;
        printf("Indirect action #%u created\n", pia->id);
        return 0;
 }
@@ -1557,9 +1631,18 @@ port_action_handle_destroy(portid_t port_id,
                for (i = 0; i != n; ++i) {
                        struct rte_flow_error error;
                        struct port_indirect_action *pia = *tmp;
+                       portid_t port_id_eff = port_id;
 
                        if (actions[i] != pia->id)
                                continue;
+
+                       if (pia->transfer)
+                               port_id_eff = port->flow_transfer_proxy;
+
+                       if (port_id_is_invalid(port_id_eff, ENABLED_WARN) ||
+                           port_id_eff == (portid_t)RTE_PORT_ALL)
+                               return -EINVAL;
+
                        /*
                         * Poisoning to make sure PMDs update it in case
                         * of error.
@@ -1567,7 +1650,7 @@ port_action_handle_destroy(portid_t port_id,
                        memset(&error, 0x33, sizeof(error));
 
                        if (pia->handle && rte_flow_action_handle_destroy(
-                                       port_id, pia->handle, &error)) {
+                                       port_id_eff, pia->handle, &error)) {
                                ret = port_flow_complain(&error);
                                continue;
                        }
@@ -1602,8 +1685,15 @@ port_action_handle_update(portid_t port_id, uint32_t id,
        struct rte_flow_error error;
        struct rte_flow_action_handle *action_handle;
        struct port_indirect_action *pia;
+       struct rte_port *port;
        const void *update;
 
+       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+           port_id == (portid_t)RTE_PORT_ALL)
+               return -EINVAL;
+
+       port = &ports[port_id];
+
        action_handle = port_action_handle_get_by_id(port_id, id);
        if (!action_handle)
                return -EINVAL;
@@ -1618,6 +1708,14 @@ port_action_handle_update(portid_t port_id, uint32_t id,
                update = action;
                break;
        }
+
+       if (pia->transfer)
+               port_id = port->flow_transfer_proxy;
+
+       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+           port_id == (portid_t)RTE_PORT_ALL)
+               return -EINVAL;
+
        if (rte_flow_action_handle_update(port_id, action_handle, update,
                                          &error)) {
                return port_flow_complain(&error);
@@ -1636,6 +1734,14 @@ port_action_handle_query(portid_t port_id, uint32_t id)
                struct rte_flow_query_age age;
                struct rte_flow_action_conntrack ct;
        } query;
+       portid_t port_id_eff = port_id;
+       struct rte_port *port;
+
+       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+           port_id == (portid_t)RTE_PORT_ALL)
+               return -EINVAL;
+
+       port = &ports[port_id];
 
        pia = action_get_by_id(port_id, id);
        if (!pia)
@@ -1650,10 +1756,19 @@ port_action_handle_query(portid_t port_id, uint32_t id)
                        id, pia->type, port_id);
                return -ENOTSUP;
        }
+
+       if (pia->transfer)
+               port_id_eff = port->flow_transfer_proxy;
+
+       if (port_id_is_invalid(port_id_eff, ENABLED_WARN) ||
+           port_id_eff == (portid_t)RTE_PORT_ALL)
+               return -EINVAL;
+
        /* Poisoning to make sure PMDs update it in case of error. */
        memset(&error, 0x55, sizeof(error));
        memset(&query, 0, sizeof(query));
-       if (rte_flow_action_handle_query(port_id, pia->handle, &query, &error))
+       if (rte_flow_action_handle_query(port_id_eff, pia->handle, &query,
+                                        &error))
                return port_flow_complain(&error);
        switch (pia->type) {
        case RTE_FLOW_ACTION_TYPE_AGE:
@@ -1872,6 +1987,20 @@ port_flow_validate(portid_t port_id,
 {
        struct rte_flow_error error;
        struct port_flow_tunnel *pft = NULL;
+       struct rte_port *port;
+
+       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+           port_id == (portid_t)RTE_PORT_ALL)
+               return -EINVAL;
+
+       port = &ports[port_id];
+
+       if (attr->transfer)
+               port_id = port->flow_transfer_proxy;
+
+       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+           port_id == (portid_t)RTE_PORT_ALL)
+               return -EINVAL;
 
        /* Poisoning to make sure PMDs update it in case of error. */
        memset(&error, 0x11, sizeof(error));
@@ -1925,7 +2054,19 @@ port_flow_create(portid_t port_id,
        struct port_flow_tunnel *pft = NULL;
        struct rte_flow_action_age *age = age_action_get(actions);
 
+       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+           port_id == (portid_t)RTE_PORT_ALL)
+               return -EINVAL;
+
        port = &ports[port_id];
+
+       if (attr->transfer)
+               port_id = port->flow_transfer_proxy;
+
+       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+           port_id == (portid_t)RTE_PORT_ALL)
+               return -EINVAL;
+
        if (port->flow_list) {
                if (port->flow_list->id == UINT32_MAX) {
                        fprintf(stderr,
@@ -1989,6 +2130,7 @@ port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
                uint32_t i;
 
                for (i = 0; i != n; ++i) {
+                       portid_t port_id_eff = port_id;
                        struct rte_flow_error error;
                        struct port_flow *pf = *tmp;
 
@@ -1999,7 +2141,15 @@ port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule)
                         * of error.
                         */
                        memset(&error, 0x33, sizeof(error));
-                       if (rte_flow_destroy(port_id, pf->flow, &error)) {
+
+                       if (pf->rule.attr->transfer)
+                               port_id_eff = port->flow_transfer_proxy;
+
+                       if (port_id_is_invalid(port_id_eff, ENABLED_WARN) ||
+                           port_id_eff == (portid_t)RTE_PORT_ALL)
+                               return -EINVAL;
+
+                       if (rte_flow_destroy(port_id_eff, pf->flow, &error)) {
                                ret = port_flow_complain(&error);
                                continue;
                        }
@@ -2133,6 +2283,14 @@ port_flow_query(portid_t port_id, uint32_t rule,
                fprintf(stderr, "Flow rule #%u not found\n", rule);
                return -ENOENT;
        }
+
+       if (pf->rule.attr->transfer)
+               port_id = port->flow_transfer_proxy;
+
+       if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+           port_id == (portid_t)RTE_PORT_ALL)
+               return -EINVAL;
+
        ret = rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
                            &name, sizeof(name),
                            (void *)(uintptr_t)action->type, &error);