app/testpmd: handle RSS offload types ESP and AH
[dpdk.git] / app / test-pmd / config.c
index 9da1ffb..69c5633 100644 (file)
 #include <rte_pmd_bnxt.h>
 #endif
 #include <rte_gro.h>
-#include <rte_config.h>
 
 #include "testpmd.h"
 
+#define ETHDEV_FWVERS_LEN 32
+
 static char *flowtype_to_str(uint16_t flow_type);
 
 static const struct {
@@ -107,6 +108,8 @@ const struct rss_type_info rss_type_table[] = {
        { "l3-dst-only", ETH_RSS_L3_DST_ONLY },
        { "l4-src-only", ETH_RSS_L4_SRC_ONLY },
        { "l4-dst-only", ETH_RSS_L4_DST_ONLY },
+       { "esp", ETH_RSS_ESP },
+       { "ah", ETH_RSS_AH },
        { NULL, 0 },
 };
 
@@ -524,6 +527,7 @@ port_infos_display(portid_t port_id)
        uint16_t mtu;
        char name[RTE_ETH_NAME_MAX_LEN];
        int ret;
+       char fw_version[ETHDEV_FWVERS_LEN];
 
        if (port_id_is_invalid(port_id, ENABLED_WARN)) {
                print_valid_ports();
@@ -545,6 +549,13 @@ port_infos_display(portid_t port_id)
        rte_eth_dev_get_name_by_port(port_id, name);
        printf("\nDevice name: %s", name);
        printf("\nDriver name: %s", dev_info.driver_name);
+
+       if (rte_eth_dev_fw_version_get(port_id, fw_version,
+                                               ETHDEV_FWVERS_LEN) == 0)
+               printf("\nFirmware-version: %s", fw_version);
+       else
+               printf("\nFirmware-version: %s", "not available");
+
        if (dev_info.device->devargs && dev_info.device->devargs->args)
                printf("\nDevargs: %s", dev_info.device->devargs->args);
        printf("\nConnect to socket: %u", port->socket_id);
@@ -1216,7 +1227,9 @@ void
 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))
@@ -1232,8 +1245,25 @@ port_mtu_set(portid_t port_id, uint16_t mtu)
                return;
        }
        diag = rte_eth_dev_set_mtu(port_id, mtu);
-       if (diag == 0)
+       if (diag == 0 &&
+           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_MAX_LEN - eth_overhead) {
+                       rte_port->dev_conf.rxmode.offloads |=
+                                               DEV_RX_OFFLOAD_JUMBO_FRAME;
+                       rte_port->dev_conf.rxmode.max_rx_pkt_len =
+                                               mtu + eth_overhead;
+               } else
+                       rte_port->dev_conf.rxmode.offloads &=
+                                               ~DEV_RX_OFFLOAD_JUMBO_FRAME;
+
                return;
+       }
        printf("Set MTU failed. diag=%d\n", diag);
 }
 
@@ -1303,7 +1333,7 @@ port_flow_complain(struct rte_flow_error *error)
                errstr = "unknown type";
        else
                errstr = errstrlist[error->type];
-       printf("Caught error type %d (%s): %s%s: %s\n",
+       printf("%s(): Caught PMD error type %d (%s): %s%s: %s\n", __func__,
               error->type, errstr,
               error->cause ? (snprintf(buf, sizeof(buf), "cause: %p, ",
                                        error->cause), buf) : "",
@@ -1441,6 +1471,33 @@ port_flow_flush(portid_t port_id)
        return ret;
 }
 
+/** Dump all flow rules. */
+int
+port_flow_dump(portid_t port_id, const char *file_name)
+{
+       int ret = 0;
+       FILE *file = stdout;
+       struct rte_flow_error error;
+
+       if (file_name && strlen(file_name)) {
+               file = fopen(file_name, "w");
+               if (!file) {
+                       printf("Failed to create file %s: %s\n", file_name,
+                              strerror(errno));
+                       return -errno;
+               }
+       }
+       ret = rte_flow_dev_dump(port_id, file, &error);
+       if (ret) {
+               port_flow_complain(&error);
+               printf("Failed to dump flow: %s\n", strerror(-ret));
+       } else
+               printf("Flow dump finished\n");
+       if (file_name && strlen(file_name))
+               fclose(file);
+       return ret;
+}
+
 /** Query a flow rule. */
 int
 port_flow_query(portid_t port_id, uint32_t rule,
@@ -2395,6 +2452,8 @@ mp_alloc_to_str(uint8_t mode)
                return "xmem";
        case MP_ALLOC_XMEM_HUGE:
                return "xmemhuge";
+       case MP_ALLOC_XBUF:
+               return "xbuf";
        default:
                return "invalid";
        }
@@ -2558,6 +2617,112 @@ set_fwd_ports_list(unsigned int *portlist, unsigned int nb_pt)
        }
 }
 
+/**
+ * Parse the user input and obtain the list of forwarding ports
+ *
+ * @param[in] list
+ *   String containing the user input. User can specify
+ *   in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6.
+ *   For example, if the user wants to use all the available
+ *   4 ports in his system, then the input can be 0-3 or 0,1,2,3.
+ *   If the user wants to use only the ports 1,2 then the input
+ *   is 1,2.
+ *   valid characters are '-' and ','
+ * @param[out] values
+ *   This array will be filled with a list of port IDs
+ *   based on the user input
+ *   Note that duplicate entries are discarded and only the first
+ *   count entries in this array are port IDs and all the rest
+ *   will contain default values
+ * @param[in] maxsize
+ *   This parameter denotes 2 things
+ *   1) Number of elements in the values array
+ *   2) Maximum value of each element in the values array
+ * @return
+ *   On success, returns total count of parsed port IDs
+ *   On failure, returns 0
+ */
+static unsigned int
+parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
+{
+       unsigned int count = 0;
+       char *end = NULL;
+       int min, max;
+       int value, i;
+       unsigned int marked[maxsize];
+
+       if (list == NULL || values == NULL)
+               return 0;
+
+       for (i = 0; i < (int)maxsize; i++)
+               marked[i] = 0;
+
+       min = INT_MAX;
+
+       do {
+               /*Remove the blank spaces if any*/
+               while (isblank(*list))
+                       list++;
+               if (*list == '\0')
+                       break;
+               errno = 0;
+               value = strtol(list, &end, 10);
+               if (errno || end == NULL)
+                       return 0;
+               if (value < 0 || value >= (int)maxsize)
+                       return 0;
+               while (isblank(*end))
+                       end++;
+               if (*end == '-' && min == INT_MAX) {
+                       min = value;
+               } else if ((*end == ',') || (*end == '\0')) {
+                       max = value;
+                       if (min == INT_MAX)
+                               min = value;
+                       for (i = min; i <= max; i++) {
+                               if (count < maxsize) {
+                                       if (marked[i])
+                                               continue;
+                                       values[count] = i;
+                                       marked[i] = 1;
+                                       count++;
+                               }
+                       }
+                       min = INT_MAX;
+               } else
+                       return 0;
+               list = end + 1;
+       } while (*end != '\0');
+
+       return count;
+}
+
+void
+parse_fwd_portlist(const char *portlist)
+{
+       unsigned int portcount;
+       unsigned int portindex[RTE_MAX_ETHPORTS];
+       unsigned int i, valid_port_count = 0;
+
+       portcount = parse_port_list(portlist, portindex, RTE_MAX_ETHPORTS);
+       if (!portcount)
+               rte_exit(EXIT_FAILURE, "Invalid fwd port list\n");
+
+       /*
+        * Here we verify the validity of the ports
+        * and thereby calculate the total number of
+        * valid ports
+        */
+       for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) {
+               if (rte_eth_dev_is_valid_port(portindex[i])) {
+                       portindex[valid_port_count] = portindex[i];
+                       valid_port_count++;
+               }
+       }
+
+       set_fwd_ports_list(portindex, valid_port_count);
+}
+
 void
 set_fwd_ports_mask(uint64_t portmask)
 {