api: binary api cleanup
[vpp.git] / src / plugins / vmxnet3 / vmxnet3_api.c
index b41866b..8afc40e 100644 (file)
 
 /* instantiate all the print functions we know about */
 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define vl_printfun
-#include <vmxnet3/vmxnet3_all_api_h.h>
-#undef vl_printfun
 
 /* get the API version number */
 #define vl_api_version(n,v) static u32 api_version=(v);
 #include <vmxnet3/vmxnet3_all_api_h.h>
 #undef vl_api_version
 
+/* Macro to finish up custom dump fns */
+#define FINISH                                  \
+    vec_add1 (s, 0);                            \
+    vl_print (handle, (char *)s);               \
+    vec_free (s);                               \
+    return handle;
+
 #include <vlibapi/api_helper_macros.h>
 
 #define foreach_vmxnet3_plugin_api_msg \
@@ -71,6 +75,9 @@ vl_api_vmxnet3_create_t_handler (vl_api_vmxnet3_create_t * mp)
   args.addr.as_u32 = ntohl (mp->pci_addr);
   args.rxq_size = ntohs (mp->rxq_size);
   args.txq_size = ntohs (mp->txq_size);
+  args.txq_num = ntohs (mp->txq_num);
+  args.rxq_num = ntohs (mp->rxq_num);
+  args.bind = mp->bind;
 
   vmxnet3_create_if (vm, &args);
   rv = args.rv;
@@ -83,6 +90,30 @@ vl_api_vmxnet3_create_t_handler (vl_api_vmxnet3_create_t * mp)
   /* *INDENT-ON* */
 }
 
+static void *
+vl_api_vmxnet3_create_t_print (vl_api_vmxnet3_create_t * mp, void *handle)
+{
+  u8 *s;
+  u32 pci_addr = ntohl (mp->pci_addr);
+
+  s = format (0, "SCRIPT: vmxnet3_create ");
+  s = format (s, "%U ", format_vlib_pci_addr, &pci_addr);
+  if (mp->enable_elog)
+    s = format (s, "elog ");
+  if (mp->bind)
+    s = format (s, "bind ");
+  if (mp->rxq_size)
+    s = format (s, "rx-queue-size %u ", ntohs (mp->rxq_size));
+  if (mp->txq_size)
+    s = format (s, "tx-queue-size %u ", ntohs (mp->txq_size));
+  if (mp->rxq_num)
+    s = format (s, "num-rx-queues %u ", ntohs (mp->rxq_num));
+  if (mp->txq_num)
+    s = format (s, "num-tx-queues %u ", ntohs (mp->txq_num));
+
+  FINISH;
+}
+
 static void
 vl_api_vmxnet3_delete_t_handler (vl_api_vmxnet3_delete_t * mp)
 {
@@ -94,10 +125,12 @@ vl_api_vmxnet3_delete_t_handler (vl_api_vmxnet3_delete_t * mp)
   vnet_hw_interface_t *hw;
   int rv = 0;
 
-  hw = vnet_get_sup_hw_interface (vnm, htonl (mp->sw_if_index));
+  hw =
+    vnet_get_sup_hw_interface_api_visible_or_null (vnm,
+                                                  htonl (mp->sw_if_index));
   if (hw == NULL || vmxnet3_device_class.index != hw->dev_class_index)
     {
-      rv = VNET_API_ERROR_INVALID_INTERFACE;
+      rv = VNET_API_ERROR_INVALID_SW_IF_INDEX;
       goto reply;
     }
 
@@ -109,18 +142,28 @@ reply:
   REPLY_MACRO (VL_API_VMXNET3_DELETE_REPLY + vmxm->msg_id_base);
 }
 
+static void *
+vl_api_vmxnet3_delete_t_print (vl_api_vmxnet3_delete_t * mp, void *handle)
+{
+  u8 *s;
+
+  s = format (0, "SCRIPT: vmxnet3_delete ");
+  s = format (s, "sw_if_index %d ", ntohl (mp->sw_if_index));
+
+  FINISH;
+}
+
 static void
 send_vmxnet3_details (vl_api_registration_t * reg, vmxnet3_device_t * vd,
-                     u16 rx_qid, vmxnet3_rxq_t * rxq, u16 tx_qid,
-                     vmxnet3_txq_t * txq, vnet_sw_interface_t * swif,
-                     u8 * interface_name, u32 context)
+                     vnet_sw_interface_t * swif, u8 * interface_name,
+                     u32 context)
 {
   vl_api_vmxnet3_details_t *mp;
   vnet_main_t *vnm = vnet_get_main ();
   vmxnet3_main_t *vmxm = &vmxnet3_main;
   vnet_hw_interface_t *hwif;
   vmxnet3_rx_ring *ring;
-  u16 rid;
+  u16 rid, qid;
 
   hwif = vnet_get_sup_hw_interface (vnm, swif->sw_if_index);
 
@@ -139,23 +182,39 @@ send_vmxnet3_details (vl_api_registration_t * reg, vmxnet3_device_t * vd,
 
   mp->version = vd->version;
   mp->pci_addr = ntohl (vd->pci_addr.as_u32);
-
-  mp->rx_qsize = htons (rxq->size);
-  mp->rx_next = htons (rxq->rx_comp_ring.next);
-  for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
-    {
-      ring = &rxq->rx_ring[rid];
-      mp->rx_fill[rid] = htons (ring->fill);
-      mp->rx_produce[rid] = htons (ring->produce);
-      mp->rx_consume[rid] = htons (ring->consume);
-    }
-  mp->tx_qsize = htons (txq->size);
-  mp->tx_next = htons (txq->tx_comp_ring.next);
-  mp->tx_produce = htons (txq->tx_ring.produce);
-  mp->tx_consume = htons (txq->tx_ring.consume);
-
   mp->admin_up_down = (swif->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? 1 : 0;
 
+  mp->rx_count = clib_min (vec_len (vd->rxqs), VMXNET3_RXQ_MAX);
+  vec_foreach_index (qid, vd->rxqs)
+  {
+    vmxnet3_rxq_t *rxq = vec_elt_at_index (vd->rxqs, qid);
+    vl_api_vmxnet3_rx_list_t *rx_list = &mp->rx_list[qid];
+
+    ASSERT (qid < VMXNET3_RXQ_MAX);
+    rx_list->rx_qsize = htons (rxq->size);
+    rx_list->rx_next = htons (rxq->rx_comp_ring.next);
+    for (rid = 0; rid < VMXNET3_RX_RING_SIZE; rid++)
+      {
+       ring = &rxq->rx_ring[rid];
+       rx_list->rx_fill[rid] = htons (ring->fill);
+       rx_list->rx_produce[rid] = htons (ring->produce);
+       rx_list->rx_consume[rid] = htons (ring->consume);
+      }
+  }
+
+  mp->tx_count = clib_min (vec_len (vd->txqs), VMXNET3_TXQ_MAX);
+  vec_foreach_index (qid, vd->txqs)
+  {
+    vmxnet3_txq_t *txq = vec_elt_at_index (vd->txqs, qid);
+    vl_api_vmxnet3_tx_list_t *tx_list = &mp->tx_list[qid];
+
+    ASSERT (qid < VMXNET3_TXQ_MAX);
+    tx_list->tx_qsize = htons (txq->size);
+    tx_list->tx_next = htons (txq->tx_comp_ring.next);
+    tx_list->tx_produce = htons (txq->tx_ring.produce);
+    tx_list->tx_consume = htons (txq->tx_ring.consume);
+  }
+
   vl_api_send_msg (reg, (u8 *) mp);
 }
 
@@ -172,9 +231,6 @@ vl_api_vmxnet3_dump_t_handler (vl_api_vmxnet3_dump_t * mp)
   vmxnet3_device_t *vd;
   u8 *if_name = 0;
   vl_api_registration_t *reg;
-  vmxnet3_rxq_t *rxq;
-  vmxnet3_txq_t *txq;
-  u16 qid = 0;
 
   reg = vl_api_client_index_to_registration (mp->client_index);
   if (!reg)
@@ -186,10 +242,7 @@ vl_api_vmxnet3_dump_t_handler (vl_api_vmxnet3_dump_t * mp)
       swif = vnet_get_sw_interface (vnm, vd->sw_if_index);
       if_name = format (if_name, "%U%c", format_vnet_sw_interface_name, vnm,
                        swif, 0);
-      rxq = vec_elt_at_index (vd->rxqs, qid);
-      txq = vec_elt_at_index (vd->txqs, qid);
-      send_vmxnet3_details (reg, vd, qid, rxq, qid, txq, swif, if_name,
-                           mp->context);
+      send_vmxnet3_details (reg, vd, swif, if_name, mp->context);
       _vec_len (if_name) = 0;
     }));
   /* *INDENT-ON* */
@@ -197,6 +250,16 @@ vl_api_vmxnet3_dump_t_handler (vl_api_vmxnet3_dump_t * mp)
   vec_free (if_name);
 }
 
+static void *
+vl_api_vmxnet3_dump_t_print (vl_api_vmxnet3_create_t * mp, void *handle)
+{
+  u8 *s;
+
+  s = format (0, "SCRIPT: vmxnet3_dump ");
+
+  FINISH;
+}
+
 #define vl_msg_name_crc_list
 #include <vmxnet3/vmxnet3_all_api_h.h>
 #undef vl_msg_name_crc_list
@@ -210,6 +273,16 @@ setup_message_id_table (vmxnet3_main_t * vmxm, api_main_t * am)
 #undef _
 }
 
+static void
+plugin_custom_dump_configure (vmxnet3_main_t * vmxm)
+{
+#define _(n,f) api_main.msg_print_handlers \
+  [VL_API_##n + vmxm->msg_id_base]                \
+    = (void *) vl_api_##f##_t_print;
+  foreach_vmxnet3_plugin_api_msg;
+#undef _
+}
+
 /* set tup the API message handling tables */
 clib_error_t *
 vmxnet3_plugin_api_hookup (vlib_main_t * vm)
@@ -239,6 +312,8 @@ vmxnet3_plugin_api_hookup (vlib_main_t * vm)
   /* set up the (msg_name, crc, message-id) table */
   setup_message_id_table (vmxm, am);
 
+  plugin_custom_dump_configure (vmxm);
+
   vec_free (name);
   return 0;
 }