vmxnet3: multiple TX queues support
[vpp.git] / src / plugins / vmxnet3 / output.c
index d6b7aaa..5c48549 100644 (file)
@@ -59,25 +59,22 @@ vmxnet3_txq_release (vlib_main_t * vm, vmxnet3_device_t * vd,
                     vmxnet3_txq_t * txq)
 {
   vmxnet3_tx_comp *tx_comp;
-  u32 bi0;
   vmxnet3_tx_comp_ring *comp_ring;
-  u16 eop_idx, desc_idx;
 
   comp_ring = &txq->tx_comp_ring;
   tx_comp = &txq->tx_comp[comp_ring->next];
 
   while ((tx_comp->flags & VMXNET3_TXCF_GEN) == comp_ring->gen)
     {
-      eop_idx = tx_comp->index & VMXNET3_TXC_INDEX;
-      do
+      u16 eop_idx = tx_comp->index & VMXNET3_TXC_INDEX;
+      u32 bi0 = txq->tx_ring.bufs[txq->tx_ring.consume];
+
+      vlib_buffer_free_one (vm, bi0);
+      while (txq->tx_ring.consume != eop_idx)
        {
-         desc_idx = txq->tx_ring.consume;
-         bi0 = txq->tx_ring.bufs[desc_idx];
-         txq->tx_ring.bufs[desc_idx] = ~0;
-         vlib_buffer_free_no_next (vm, &bi0, 1);
          vmxnet3_tx_ring_advance_consume (txq);
        }
-      while (desc_idx != eop_idx);
+      vmxnet3_tx_ring_advance_consume (txq);
 
       vmxnet3_tx_comp_ring_advance_next (txq);
       tx_comp = &txq->tx_comp[comp_ring->next];
@@ -103,7 +100,7 @@ VNET_DEVICE_CLASS_TX_FN (vmxnet3_device_class) (vlib_main_t * vm,
   vmxnet3_main_t *vmxm = &vmxnet3_main;
   vnet_interface_output_runtime_t *rd = (void *) node->runtime_data;
   vmxnet3_device_t *vd = pool_elt_at_index (vmxm->devices, rd->dev_instance);
-  u32 *buffers = vlib_frame_args (frame);
+  u32 *buffers = vlib_frame_vector_args (frame);
   u32 bi0;
   vlib_buffer_t *b0;
   vmxnet3_tx_desc *txd = 0;
@@ -111,8 +108,7 @@ VNET_DEVICE_CLASS_TX_FN (vmxnet3_device_class) (vlib_main_t * vm,
   u16 space_left;
   u16 n_left = frame->n_vectors;
   vmxnet3_txq_t *txq;
-  u32 thread_index = vm->thread_index;
-  u16 qid = thread_index;
+  u16 qid = vm->thread_index % vd->num_tx_queues, produce;
 
   if (PREDICT_FALSE (!(vd->flags & VMXNET3_DEVICE_F_LINK_UP)))
     {
@@ -122,12 +118,13 @@ VNET_DEVICE_CLASS_TX_FN (vmxnet3_device_class) (vlib_main_t * vm,
       return (0);
     }
 
-  txq = vec_elt_at_index (vd->txqs, qid % vd->num_tx_queues);
+  txq = vec_elt_at_index (vd->txqs, qid);
   clib_spinlock_lock_if_init (&txq->lock);
 
   vmxnet3_txq_release (vm, vd, txq);
 
-  while (n_left)
+  produce = txq->tx_ring.produce;
+  while (PREDICT_TRUE (n_left))
     {
       u16 space_needed = 1, i;
       vlib_buffer_t *b;
@@ -146,15 +143,22 @@ VNET_DEVICE_CLASS_TX_FN (vmxnet3_device_class) (vlib_main_t * vm,
        }
       if (PREDICT_FALSE (space_left < space_needed))
        {
-         vlib_buffer_free_one (vm, bi0);
-         vlib_error_count (vm, node->node_index,
-                           VMXNET3_TX_ERROR_NO_FREE_SLOTS, 1);
-         buffers++;
-         n_left--;
-         /*
-          * Drop this packet. But we may have enough room for the next packet
-          */
-         continue;
+         vmxnet3_txq_release (vm, vd, txq);
+         space_left = vmxnet3_tx_ring_space_left (txq);
+
+         if (PREDICT_FALSE (space_left < space_needed))
+           {
+             vlib_buffer_free_one (vm, bi0);
+             vlib_error_count (vm, node->node_index,
+                               VMXNET3_TX_ERROR_NO_FREE_SLOTS, 1);
+             buffers++;
+             n_left--;
+             /*
+              * Drop this packet. But we may have enough room for the next
+              * packet
+              */
+             continue;
+           }
        }
 
       /*
@@ -174,9 +178,7 @@ VNET_DEVICE_CLASS_TX_FN (vmxnet3_device_class) (vlib_main_t * vm,
          txq->tx_ring.bufs[desc_idx] = bi0;
 
          txd = &txq->tx_desc[desc_idx];
-         txd->address =
-           vlib_get_buffer_data_physical_address (vm,
-                                                  bi0) + b0->current_data;
+         txd->address = vlib_buffer_get_current_pa (vm, b0);
 
          txd->flags[0] = generation | b0->current_length;
 
@@ -193,12 +195,14 @@ VNET_DEVICE_CLASS_TX_FN (vmxnet3_device_class) (vlib_main_t * vm,
        * Device can start reading the packet
        */
       txq->tx_desc[first_idx].flags[0] ^= VMXNET3_TXF_GEN;
-      vmxnet3_reg_write (vd, 0, VMXNET3_REG_TXPROD, txq->tx_ring.produce);
 
       buffers++;
       n_left--;
     }
 
+  if (PREDICT_TRUE (produce != txq->tx_ring.produce))
+    vmxnet3_reg_write_inline (vd, 0, txq->reg_txprod, txq->tx_ring.produce);
+
   clib_spinlock_unlock_if_init (&txq->lock);
 
   return (frame->n_vectors - n_left);