dev: add change_max_rx_frame_size capability

Type: improvement
Change-Id: I922e216818b78f2fe7689c21a1d27d74a0ae28b8
Signed-off-by: Damjan Marion <damarion@cisco.com>
diff --git a/src/plugins/dev_iavf/iavf.c b/src/plugins/dev_iavf/iavf.c
index f45bea0..1a17f46 100644
--- a/src/plugins/dev_iavf/iavf.c
+++ b/src/plugins/dev_iavf/iavf.c
@@ -160,7 +160,8 @@
         .type = VNET_DEV_PORT_TYPE_ETHERNET,
         .max_rx_queues = res.num_queue_pairs,
         .max_tx_queues = res.num_queue_pairs,
-        .max_supported_frame_size = res.max_mtu,
+        .max_supported_rx_frame_size = res.max_mtu,
+        .caps.change_max_rx_frame_size = 1,
       },
       .ops = {
         .init = iavf_port_init,
diff --git a/src/plugins/dev_iavf/port.c b/src/plugins/dev_iavf/port.c
index 7888fce..c2dd13b 100644
--- a/src/plugins/dev_iavf/port.c
+++ b/src/plugins/dev_iavf/port.c
@@ -132,7 +132,7 @@
   virtchnl_queue_pair_info_t *qpi;
   u16 vsi_id = ap->vsi_id;
   u16 data_size = vlib_buffer_get_default_data_size (vm);
-  u16 max_frame_size = port->max_frame_size;
+  u16 max_frame_size = port->max_rx_frame_size;
   u8 buffer[VIRTCHNL_MSG_SZ (virtchnl_vsi_queue_config_info_t, qpair,
 			     ap->num_qp)];
   virtchnl_vsi_queue_config_info_t *ci =
@@ -388,7 +388,7 @@
 
   switch (req->type)
     {
-    case VNET_DEV_PORT_CFG_MAX_FRAME_SIZE:
+    case VNET_DEV_PORT_CFG_MAX_RX_FRAME_SIZE:
       if (port->started)
 	rv = VNET_DEV_ERR_PORT_STARTED;
       break;
@@ -520,7 +520,7 @@
 				       /* is_primary */ 0);
       break;
 
-    case VNET_DEV_PORT_CFG_MAX_FRAME_SIZE:
+    case VNET_DEV_PORT_CFG_MAX_RX_FRAME_SIZE:
       break;
 
     case VNET_DEV_PORT_CFG_RXQ_INTR_MODE_ENABLE:
diff --git a/src/vnet/dev/config.c b/src/vnet/dev/config.c
index c98524c..091d83e 100644
--- a/src/vnet/dev/config.c
+++ b/src/vnet/dev/config.c
@@ -148,7 +148,7 @@
       else
 	{
 	  err = clib_error_return (0, "unknown input '%U'",
-				   format_unformat_error, input);
+				   format_unformat_error, &input);
 	  break;
 	}
     }
diff --git a/src/vnet/dev/dev.c b/src/vnet/dev/dev.c
index bedc7fb..9b99fe4 100644
--- a/src/vnet/dev/dev.c
+++ b/src/vnet/dev/dev.c
@@ -92,14 +92,18 @@
   if ((rv = bus->ops.device_open (vm, dev)) != VNET_DEV_OK)
     return rv;
 
-  if ((rv = dev->ops.alloc (vm, dev)) != VNET_DEV_OK)
+  if (dev->ops.alloc)
     {
-      log_err (dev, "device init failed [rv %d]", rv);
-      if (dev->ops.deinit)
-	dev->ops.deinit (vm, dev);
-      if (dev->ops.free)
-	dev->ops.free (vm, dev);
-      return rv;
+      rv = dev->ops.alloc (vm, dev);
+      if (rv != VNET_DEV_OK)
+	{
+	  log_err (dev, "device init failed [rv %d]", rv);
+	  if (dev->ops.deinit)
+	    dev->ops.deinit (vm, dev);
+	  if (dev->ops.free)
+	    dev->ops.free (vm, dev);
+	  return rv;
+	}
     }
 
   if ((rv = dev->ops.init (vm, dev)) != VNET_DEV_OK)
diff --git a/src/vnet/dev/dev.h b/src/vnet/dev/dev.h
index dc42666..e3421b9 100644
--- a/src/vnet/dev/dev.h
+++ b/src/vnet/dev/dev.h
@@ -28,7 +28,8 @@
 
 #define foreach_vnet_dev_port_caps                                            \
   _ (interrupt_mode)                                                          \
-  _ (rss)
+  _ (rss)                                                                     \
+  _ (change_max_rx_frame_size)
 
 typedef union
 {
@@ -107,7 +108,7 @@
 
 #define foreach_vnet_dev_port_cfg_type                                        \
   _ (PROMISC_MODE)                                                            \
-  _ (MAX_FRAME_SIZE)                                                          \
+  _ (MAX_RX_FRAME_SIZE)                                                       \
   _ (CHANGE_PRIMARY_HW_ADDR)                                                  \
   _ (ADD_SECONDARY_HW_ADDR)                                                   \
   _ (REMOVE_SECONDARY_HW_ADDR)                                                \
@@ -132,7 +133,7 @@
   {
     u8 promisc : 1;
     vnet_dev_hw_addr_t addr;
-    u16 max_frame_size;
+    u16 max_rx_frame_size;
     vnet_dev_queue_id_t queue_id;
   };
 
@@ -143,7 +144,7 @@
   vnet_dev_hw_addr_t hw_addr;
   u16 max_rx_queues;
   u16 max_tx_queues;
-  u16 max_supported_frame_size;
+  u16 max_supported_rx_frame_size;
   vnet_dev_port_type_t type;
   vnet_dev_port_caps_t caps;
 } vnet_dev_port_attr_t;
@@ -278,7 +279,7 @@
   vnet_dev_queue_config_t rx_queue_config;
   vnet_dev_queue_config_t tx_queue_config;
   vnet_dev_port_attr_t attr;
-  u32 max_frame_size;
+  u32 max_rx_frame_size;
   vnet_dev_hw_addr_t primary_hw_addr;
   vnet_dev_hw_addr_t *secondary_hw_addr;
   u32 index;
diff --git a/src/vnet/dev/dev_funcs.h b/src/vnet/dev/dev_funcs.h
index e725dd4..33159ff 100644
--- a/src/vnet/dev/dev_funcs.h
+++ b/src/vnet/dev/dev_funcs.h
@@ -195,6 +195,14 @@
   return rxq->buffer_template.buffer_pool_index;
 }
 
+static_always_inline u32
+vnet_dev_get_rx_queue_buffer_data_size (vlib_main_t *vm,
+					vnet_dev_rx_queue_t *rxq)
+{
+  u8 bpi = vnet_dev_get_rx_queue_buffer_pool_index (rxq);
+  return vlib_get_buffer_pool (vm, bpi)->data_size;
+}
+
 static_always_inline void
 vnet_dev_rx_queue_rt_request (vlib_main_t *vm, vnet_dev_rx_queue_t *rxq,
 			      vnet_dev_rx_queue_rt_req_t req)
diff --git a/src/vnet/dev/format.c b/src/vnet/dev/format.c
index 2c95e3a..8816c0e 100644
--- a/src/vnet/dev/format.c
+++ b/src/vnet/dev/format.c
@@ -117,9 +117,9 @@
 	  s = format (s, " %U", format_vnet_dev_hw_addr, a);
 	}
     }
-  s = format (s, "\n%UMax frame size is %u (max supported %u)",
-	      format_white_space, indent, port->max_frame_size,
-	      port->attr.max_supported_frame_size);
+  s = format (s, "\n%UMax RX frame size is %u (max supported %u)",
+	      format_white_space, indent, port->max_rx_frame_size,
+	      port->attr.max_supported_rx_frame_size);
   if (port->port_ops.format_status)
     s = format (s, "\n%U%U", format_white_space, indent,
 		port->port_ops.format_status, a, port);
diff --git a/src/vnet/dev/handlers.c b/src/vnet/dev/handlers.c
index 41d4cba..fcaef14 100644
--- a/src/vnet/dev/handlers.c
+++ b/src/vnet/dev/handlers.c
@@ -23,8 +23,8 @@
   vnet_dev_rv_t rv;
 
   vnet_dev_port_cfg_change_req_t req = {
-    .type = VNET_DEV_PORT_CFG_MAX_FRAME_SIZE,
-    .max_frame_size = frame_size,
+    .type = VNET_DEV_PORT_CFG_MAX_RX_FRAME_SIZE,
+    .max_rx_frame_size = frame_size,
   };
 
   log_debug (p->dev, "size %u", frame_size);
diff --git a/src/vnet/dev/port.c b/src/vnet/dev/port.c
index b3de37d..350c1d8 100644
--- a/src/vnet/dev/port.c
+++ b/src/vnet/dev/port.c
@@ -246,7 +246,7 @@
   vnet_dev_rv_t rv = VNET_DEV_OK;
 
   ASSERT (args->port.attr.type != VNET_DEV_PORT_TYPE_UNKNOWN);
-  ASSERT (args->port.attr.max_supported_frame_size);
+  ASSERT (args->port.attr.max_supported_rx_frame_size);
 
   port =
     vnet_dev_alloc_with_data (sizeof (vnet_dev_port_t), args->port.data_size);
@@ -267,9 +267,16 @@
   port->tx_node = *args->tx_node;
 
   /* defaults out of port attributes */
-  port->max_frame_size = args->port.attr.max_supported_frame_size;
+  port->max_rx_frame_size = args->port.attr.max_supported_rx_frame_size;
   port->primary_hw_addr = args->port.attr.hw_addr;
 
+  if (port->attr.type == VNET_DEV_PORT_TYPE_ETHERNET)
+    {
+      if (port->max_rx_frame_size > 1514 &&
+	  port->attr.caps.change_max_rx_frame_size)
+	port->max_rx_frame_size = 1514;
+    }
+
   if (port->port_ops.alloc)
     rv = port->port_ops.alloc (vm, port);
 
@@ -292,10 +299,10 @@
 
   switch (req->type)
     {
-    case VNET_DEV_PORT_CFG_MAX_FRAME_SIZE:
-      if (req->max_frame_size > port->attr.max_supported_frame_size)
+    case VNET_DEV_PORT_CFG_MAX_RX_FRAME_SIZE:
+      if (req->max_rx_frame_size > port->attr.max_supported_rx_frame_size)
 	return VNET_DEV_ERR_INVALID_VALUE;
-      if (req->max_frame_size == port->max_frame_size)
+      if (req->max_rx_frame_size == port->max_rx_frame_size)
 	return VNET_DEV_ERR_NO_CHANGE;
       break;
 
@@ -335,6 +342,8 @@
       if (rv != VNET_DEV_OK)
 	return rv;
     }
+  else
+    return VNET_DEV_ERR_NOT_SUPPORTED;
 
   req->validated = 1;
   return VNET_DEV_OK;
@@ -367,14 +376,16 @@
 
   if (port->port_ops.config_change)
     rv = port->port_ops.config_change (vm, port, req);
+  else
+    return VNET_DEV_ERR_NOT_SUPPORTED;
 
   if (rv != VNET_DEV_OK)
     return rv;
 
   switch (req->type)
     {
-    case VNET_DEV_PORT_CFG_MAX_FRAME_SIZE:
-      port->max_frame_size = req->max_frame_size;
+    case VNET_DEV_PORT_CFG_MAX_RX_FRAME_SIZE:
+      port->max_rx_frame_size = req->max_rx_frame_size;
       break;
 
     case VNET_DEV_PORT_CFG_PROMISC_MODE:
@@ -572,7 +583,7 @@
       port->intf.hw_if_index = vnet_eth_register_interface (
 	vnm, &(vnet_eth_interface_registration_t){
 	       .address = port->primary_hw_addr.eth_mac,
-	       .max_frame_size = port->max_frame_size,
+	       .max_frame_size = port->max_rx_frame_size,
 	       .dev_class_index = driver->dev_class_index,
 	       .dev_instance = port->intf.dev_instance,
 	       .cb.set_max_frame_size = vnet_dev_port_set_max_frame_size,