dpdk: limit number of TX queues to max supported
[vpp.git] / src / plugins / dpdk / device / init.c
index 5e06e48..6c34981 100644 (file)
@@ -21,6 +21,7 @@
 #include <vlib/unix/unix.h>
 #include <vlib/log.h>
 
+#include <vnet/vnet.h>
 #include <vnet/ethernet/ethernet.h>
 #include <vnet/interface/rx_queue_funcs.h>
 #include <dpdk/buffer.h>
@@ -68,6 +69,46 @@ const struct
   { ETH_LINK_SPEED_1G, "GigabitEthernet" },
 };
 
+static clib_error_t *
+dpdk_set_max_frame_size (vnet_main_t *vnm, vnet_hw_interface_t *hi,
+                        u32 frame_size)
+{
+  dpdk_main_t *dm = &dpdk_main;
+  dpdk_device_t *xd = vec_elt_at_index (dm->devices, hi->dev_instance);
+  int rv;
+  u32 mtu;
+
+  mtu = frame_size - xd->driver_frame_overhead;
+
+  rv = rte_eth_dev_set_mtu (xd->port_id, mtu);
+
+  if (rv < 0)
+    {
+      dpdk_log_err ("[%u] rte_eth_dev_set_mtu failed (mtu %u, rv %d)",
+                   xd->port_id, mtu, rv);
+      switch (rv)
+       {
+       case -ENOTSUP:
+         return vnet_error (VNET_ERR_UNSUPPORTED,
+                            "dpdk driver doesn't support MTU change");
+       case -EBUSY:
+         return vnet_error (VNET_ERR_BUSY, "port is running");
+       case -EINVAL:
+         return vnet_error (VNET_ERR_INVALID_VALUE, "invalid MTU");
+       default:
+         return vnet_error (VNET_ERR_BUG,
+                            "unexpected return value %d returned from "
+                            "rte_eth_dev_set_mtu(...)",
+                            rv);
+       }
+    }
+  else
+    dpdk_log_debug ("[%u] max_frame_size set to %u by setting MTU to %u",
+                   xd->port_id, frame_size, mtu);
+
+  return 0;
+}
+
 static u32
 dpdk_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
 {
@@ -84,15 +125,6 @@ dpdk_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
     case ETHERNET_INTERFACE_FLAG_ACCEPT_ALL:
       dpdk_device_flag_set (xd, DPDK_DEVICE_FLAG_PROMISC, 1);
       break;
-    case ETHERNET_INTERFACE_FLAG_MTU:
-      if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
-       rte_eth_dev_stop (xd->port_id);
-      rte_eth_dev_set_mtu (xd->port_id, hi->max_packet_bytes);
-      if (xd->flags & DPDK_DEVICE_FLAG_ADMIN_UP)
-       rte_eth_dev_start (xd->port_id);
-      dpdk_log_debug ("[%u] mtu changed to %u", xd->port_id,
-                     hi->max_packet_bytes);
-      return 0;
     default:
       return ~0;
     }
@@ -328,9 +360,16 @@ dpdk_lib_init (dpdk_main_t * dm)
        xd->name = format (xd->name, "/%d", di.switch_info.port_id);
 
       /* number of RX and TX queues */
-      if (devconf->num_tx_queues > 0 &&
-         devconf->num_tx_queues < xd->conf.n_tx_queues)
-       xd->conf.n_tx_queues = devconf->num_tx_queues;
+      if (devconf->num_tx_queues > 0)
+       {
+         if (di.max_tx_queues < devconf->num_tx_queues)
+           dpdk_log_warn ("[%u] Configured number of TX queues (%u) is "
+                          "bigger than maximum supported (%u)",
+                          port_id, devconf->num_tx_queues, di.max_tx_queues);
+         xd->conf.n_tx_queues = devconf->num_tx_queues;
+       }
+
+      xd->conf.n_tx_queues = clib_min (di.max_tx_queues, xd->conf.n_tx_queues);
 
       if (devconf->num_rx_queues > 1 &&
          di.max_rx_queues >= devconf->num_rx_queues)
@@ -347,8 +386,25 @@ dpdk_lib_init (dpdk_main_t * dm)
                               format_dpdk_rss_hf_name, unsupported_bits);
            }
          xd->conf.rss_hf &= di.flow_type_rss_offloads;
+         dpdk_log_debug ("[%u] rss_hf: %U", port_id, format_dpdk_rss_hf_name,
+                         xd->conf.rss_hf);
        }
 
+      xd->driver_frame_overhead =
+       RTE_ETHER_HDR_LEN + 2 * RTE_VLAN_HLEN + RTE_ETHER_CRC_LEN;
+#if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0)
+      q = di.max_rx_pktlen - di.max_mtu;
+
+      if (q < xd->driver_frame_overhead && q > 0)
+       xd->driver_frame_overhead = q;
+      dpdk_log_debug ("[%u] min_mtu: %u, max_mtu: %u, min_rx_bufsize: %u, "
+                     "max_rx_pktlen: %u, max_lro_pkt_size: %u",
+                     xd->port_id, di.min_mtu, di.max_mtu, di.min_rx_bufsize,
+                     di.max_rx_pktlen, di.max_lro_pkt_size);
+#endif
+      dpdk_log_debug ("[%u] driver frame overhead is %u", port_id,
+                     xd->driver_frame_overhead);
+
       /* number of RX and TX tescriptors */
       if (devconf->num_rx_desc)
        xd->conf.n_rx_desc = devconf->num_rx_desc;
@@ -360,6 +416,11 @@ dpdk_lib_init (dpdk_main_t * dm)
       else if (dr && dr->n_tx_desc)
        xd->conf.n_tx_desc = dr->n_tx_desc;
 
+      dpdk_log_debug (
+       "[%u] n_rx_queues: %u n_tx_queues: %u n_rx_desc: %u n_tx_desc: %u",
+       port_id, xd->conf.n_rx_queues, xd->conf.n_tx_queues,
+       xd->conf.n_rx_desc, xd->conf.n_tx_desc);
+
       vec_validate_aligned (xd->rx_queues, xd->conf.n_rx_queues - 1,
                            CLIB_CACHE_LINE_BYTES);
 
@@ -370,6 +431,7 @@ dpdk_lib_init (dpdk_main_t * dm)
       eir.dev_instance = xd->device_index;
       eir.address = addr;
       eir.cb.flag_change = dpdk_flag_change;
+      eir.cb.set_max_frame_size = dpdk_set_max_frame_size;
       xd->hw_if_index = vnet_eth_register_interface (vnm, &eir);
       hi = vnet_get_hw_interface (vnm, xd->hw_if_index);
       hi->numa_node = xd->cpu_socket = (i8) rte_eth_dev_socket_id (port_id);