ip: remove unnecesary inlining in ip4-rewrite node
[vpp.git] / src / plugins / avf / device.c
index def8a79..70ea446 100644 (file)
@@ -183,7 +183,6 @@ retry:
 done:
   if (ad->flags & AVF_DEVICE_F_ELOG)
     {
-      /* *INDENT-OFF* */
       ELOG_TYPE_DECLARE (el) =
        {
          .format = "avf[%d] aq enq: s_flags 0x%x r_flags 0x%x opcode 0x%x "
@@ -199,14 +198,13 @@ done:
          u16 datalen;
          u16 retval;
        } *ed;
-      ed = ELOG_DATA (&vm->elog_main, el);
-      ed->dev_instance = ad->dev_instance;
-      ed->s_flags = dc.flags;
-      ed->r_flags = d->flags;
-      ed->opcode = dc.opcode;
-      ed->datalen = dc.datalen;
-      ed->retval = d->retval;
-      /* *INDENT-ON* */
+       ed = ELOG_DATA (&vlib_global_main.elog_main, el);
+       ed->dev_instance = ad->dev_instance;
+       ed->s_flags = dc.flags;
+       ed->r_flags = d->flags;
+       ed->opcode = dc.opcode;
+       ed->datalen = dc.datalen;
+       ed->retval = d->retval;
     }
 
   return err;
@@ -222,7 +220,6 @@ avf_cmd_rx_ctl_reg_write (vlib_main_t * vm, avf_device_t * ad, u32 reg,
 
   if (ad->flags & AVF_DEVICE_F_ELOG)
     {
-      /* *INDENT-OFF* */
       ELOG_TYPE_DECLARE (el) =
        {
          .format = "avf[%d] rx ctl reg write: reg 0x%x val 0x%x ",
@@ -234,11 +231,10 @@ avf_cmd_rx_ctl_reg_write (vlib_main_t * vm, avf_device_t * ad, u32 reg,
          u32 reg;
          u32 val;
        } *ed;
-      ed = ELOG_DATA (&vm->elog_main, el);
-      ed->dev_instance = ad->dev_instance;
-      ed->reg = reg;
-      ed->val = val;
-      /* *INDENT-ON* */
+       ed = ELOG_DATA (&vlib_global_main.elog_main, el);
+       ed->dev_instance = ad->dev_instance;
+       ed->reg = reg;
+       ed->val = val;
     }
   return err;
 }
@@ -299,6 +295,7 @@ avf_txq_init (vlib_main_t * vm, avf_device_t * ad, u16 qid, u16 txq_size)
 {
   clib_error_t *err;
   avf_txq_t *txq;
+  u16 n;
   u8 bpi = vlib_buffer_pool_get_default_for_numa (vm,
                                                  ad->numa_node);
 
@@ -317,11 +314,15 @@ avf_txq_init (vlib_main_t * vm, avf_device_t * ad, u16 qid, u16 txq_size)
   txq->size = txq_size;
   txq->next = 0;
 
-  /* Prepare a placeholder buffer to maintain a 1-1
-     relationship between bufs and descs when a context
-     descriptor is added in descs */
-  if (!vlib_buffer_alloc_from_pool
-      (vm, &txq->ctx_desc_placeholder_bi, 1, bpi))
+  /* Prepare a placeholder buffer(s) to maintain a 1-1 relationship between
+   * bufs and descs when a context descriptor is added in descs. Worst case
+   * every second descriptor is context descriptor and due to b->ref_count
+   * being u8 we need one for each block of 510 descriptors */
+
+  n = (txq->size / 510) + 1;
+  vec_validate_aligned (txq->ph_bufs, n, CLIB_CACHE_LINE_BYTES);
+
+  if (!vlib_buffer_alloc_from_pool (vm, txq->ph_bufs, n, bpi))
     return clib_error_return (0, "buffer allocation error");
 
   txq->descs = vlib_physmem_alloc_aligned_on_numa (vm, txq->size *
@@ -340,6 +341,9 @@ avf_txq_init (vlib_main_t * vm, avf_device_t * ad, u16 qid, u16 txq_size)
   /* initialize ring of pending RS slots */
   clib_ring_new_aligned (txq->rs_slots, 32, CLIB_CACHE_LINE_BYTES);
 
+  vec_validate_aligned (txq->tmp_descs, txq->size, CLIB_CACHE_LINE_BYTES);
+  vec_validate_aligned (txq->tmp_bufs, txq->size, CLIB_CACHE_LINE_BYTES);
+
   ad->n_tx_queues = clib_min (ad->num_queue_pairs, qid + 1);
   return 0;
 }
@@ -470,11 +474,10 @@ retry:
 
   if (d->v_opcode != op)
     {
-      err =
-       clib_error_return (0,
-                          "unexpected message receiver [v_opcode = %u, "
-                          "expected %u, v_retval %d]", d->v_opcode, op,
-                          d->v_retval);
+      err = clib_error_return (0,
+                              "unexpected message received [v_opcode = %u, "
+                              "expected %u, v_retval %d]",
+                              d->v_opcode, op, d->v_retval);
       goto done;
     }
 
@@ -500,7 +503,6 @@ done:
 
   if (ad->flags & AVF_DEVICE_F_ELOG)
     {
-      /* *INDENT-OFF* */
       ELOG_TYPE_DECLARE (el) =
        {
          .format = "avf[%d] send to pf: v_opcode %s (%d) v_retval 0x%x",
@@ -519,12 +521,11 @@ done:
          u32 v_opcode_val;
          u32 v_retval;
        } *ed;
-      ed = ELOG_DATA (&vm->elog_main, el);
-      ed->dev_instance = ad->dev_instance;
-      ed->v_opcode = op;
-      ed->v_opcode_val = op;
-      ed->v_retval = d->v_retval;
-      /* *INDENT-ON* */
+       ed = ELOG_DATA (&vlib_global_main.elog_main, el);
+       ed->dev_instance = ad->dev_instance;
+       ed->v_opcode = op;
+       ed->v_opcode_val = op;
+       ed->v_retval = d->v_retval;
     }
   return err;
 }
@@ -556,35 +557,35 @@ avf_op_get_vf_resources (vlib_main_t * vm, avf_device_t * ad,
                         virtchnl_vf_resource_t * res)
 {
   clib_error_t *err = 0;
-  u32 bitmap =
-    (VIRTCHNL_VF_OFFLOAD_L2 | VIRTCHNL_VF_OFFLOAD_RSS_PF |
-     VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | VIRTCHNL_VF_OFFLOAD_VLAN |
-     VIRTCHNL_VF_OFFLOAD_RX_POLLING | VIRTCHNL_VF_CAP_ADV_LINK_SPEED |
-     VIRTCHNL_VF_OFFLOAD_FDIR_PF | VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF);
-
-  avf_log_debug (ad, "get_vf_reqources: bitmap 0x%x", bitmap);
+  u32 bitmap = (VIRTCHNL_VF_OFFLOAD_L2 | VIRTCHNL_VF_OFFLOAD_RSS_PF |
+               VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | VIRTCHNL_VF_OFFLOAD_VLAN |
+               VIRTCHNL_VF_OFFLOAD_RX_POLLING |
+               VIRTCHNL_VF_CAP_ADV_LINK_SPEED | VIRTCHNL_VF_OFFLOAD_FDIR_PF |
+               VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF | VIRTCHNL_VF_OFFLOAD_VLAN_V2);
+
+  avf_log_debug (ad, "get_vf_resources: bitmap 0x%x (%U)", bitmap,
+                format_avf_vf_cap_flags, bitmap);
   err = avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_VF_RESOURCES, &bitmap,
                        sizeof (u32), res, sizeof (virtchnl_vf_resource_t));
 
   if (err == 0)
     {
       int i;
-      avf_log_debug (ad, "get_vf_reqources: num_vsis %u num_queue_pairs %u "
-                    "max_vectors %u max_mtu %u vf_offload_flags 0x%04x "
+      avf_log_debug (ad,
+                    "get_vf_resources: num_vsis %u num_queue_pairs %u "
+                    "max_vectors %u max_mtu %u vf_cap_flags 0x%x (%U) "
                     "rss_key_size %u rss_lut_size %u",
                     res->num_vsis, res->num_queue_pairs, res->max_vectors,
-                    res->max_mtu, res->vf_offload_flags, res->rss_key_size,
-                    res->rss_lut_size);
+                    res->max_mtu, res->vf_cap_flags, format_avf_vf_cap_flags,
+                    res->vf_cap_flags, res->rss_key_size, res->rss_lut_size);
       for (i = 0; i < res->num_vsis; i++)
-       avf_log_debug (ad, "get_vf_reqources_vsi[%u]: vsi_id %u "
-                      "num_queue_pairs %u vsi_type %u qset_handle %u "
-                      "default_mac_addr %U", i,
-                      res->vsi_res[i].vsi_id,
-                      res->vsi_res[i].num_queue_pairs,
-                      res->vsi_res[i].vsi_type,
-                      res->vsi_res[i].qset_handle,
-                      format_ethernet_address,
-                      res->vsi_res[i].default_mac_addr);
+       avf_log_debug (
+         ad,
+         "get_vf_resources_vsi[%u]: vsi_id %u num_queue_pairs %u vsi_type %u "
+         "qset_handle %u default_mac_addr %U",
+         i, res->vsi_res[i].vsi_id, res->vsi_res[i].num_queue_pairs,
+         res->vsi_res[i].vsi_type, res->vsi_res[i].qset_handle,
+         format_ethernet_address, res->vsi_res[i].default_mac_addr);
     }
 
   return err;
@@ -822,6 +823,39 @@ avf_op_get_stats (vlib_main_t * vm, avf_device_t * ad,
                         es, sizeof (virtchnl_eth_stats_t));
 }
 
+clib_error_t *
+avf_op_get_offload_vlan_v2_caps (vlib_main_t *vm, avf_device_t *ad,
+                                virtchnl_vlan_caps_t *vc)
+{
+  clib_error_t *err;
+
+  err = avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS, 0, 0, vc,
+                       sizeof (virtchnl_vlan_caps_t));
+
+  avf_log_debug (ad, "get_offload_vlan_v2_caps:\n%U%U", format_white_space, 16,
+                format_avf_vlan_caps, vc);
+
+  return err;
+}
+
+clib_error_t *
+avf_op_disable_vlan_stripping_v2 (vlib_main_t *vm, avf_device_t *ad, u32 outer,
+                                 u32 inner)
+{
+  virtchnl_vlan_setting_t vs = {
+    .outer_ethertype_setting = outer,
+    .inner_ethertype_setting = inner,
+    .vport_id = ad->vsi_id,
+  };
+
+  avf_log_debug (ad, "disable_vlan_stripping_v2: outer: %U, inner %U",
+                format_avf_vlan_support, outer, format_avf_vlan_support,
+                inner);
+
+  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2, &vs,
+                        sizeof (virtchnl_vlan_setting_t), 0, 0);
+}
+
 clib_error_t *
 avf_device_reset (vlib_main_t * vm, avf_device_t * ad)
 {
@@ -954,20 +988,36 @@ avf_device_init (vlib_main_t * vm, avf_main_t * am, avf_device_t * ad,
     return clib_error_return (0, "unexpected GET_VF_RESOURCE reply received");
 
   ad->vsi_id = res.vsi_res[0].vsi_id;
-  ad->feature_bitmap = res.vf_offload_flags;
+  ad->cap_flags = res.vf_cap_flags;
   ad->num_queue_pairs = res.num_queue_pairs;
   ad->max_vectors = res.max_vectors;
   ad->max_mtu = res.max_mtu;
   ad->rss_key_size = res.rss_key_size;
   ad->rss_lut_size = res.rss_lut_size;
-  wb_on_itr = (ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) != 0;
+  wb_on_itr = (ad->cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) != 0;
 
   clib_memcpy_fast (ad->hwaddr, res.vsi_res[0].default_mac_addr, 6);
 
   /*
    * Disable VLAN stripping
    */
-  if ((error = avf_op_disable_vlan_stripping (vm, ad)))
+  if (ad->cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN_V2)
+    {
+      virtchnl_vlan_caps_t vc = {};
+      u32 outer = VIRTCHNL_VLAN_UNSUPPORTED, inner = VIRTCHNL_VLAN_UNSUPPORTED;
+      u32 mask = VIRTCHNL_VLAN_ETHERTYPE_8100;
+
+      if ((error = avf_op_get_offload_vlan_v2_caps (vm, ad, &vc)))
+       return error;
+
+      outer = vc.offloads.stripping_support.outer & mask;
+      inner = vc.offloads.stripping_support.inner & mask;
+
+      if ((outer || inner) &&
+         (error = avf_op_disable_vlan_stripping_v2 (vm, ad, outer, inner)))
+       return error;
+    }
+  else if ((error = avf_op_disable_vlan_stripping (vm, ad)))
     return error;
 
   /*
@@ -1000,12 +1050,11 @@ avf_device_init (vlib_main_t * vm, avf_main_t * am, avf_device_t * ad,
   else
     ad->n_rx_irqs = 1;
 
-
-  if ((ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
+  if ((ad->cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
       (error = avf_op_config_rss_lut (vm, ad)))
     return error;
 
-  if ((ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
+  if ((ad->cap_flags & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
       (error = avf_op_config_rss_key (vm, ad)))
     return error;
 
@@ -1083,12 +1132,12 @@ avf_process_one_device (vlib_main_t * vm, avf_device_t * ad, int is_irq)
          u32 flags = 0;
          u32 mbps = 0;
 
-         if (ad->feature_bitmap & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
+         if (ad->cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
            link_up = e->event_data.link_event_adv.link_status;
          else
            link_up = e->event_data.link_event.link_status;
 
-         if (ad->feature_bitmap & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
+         if (ad->cap_flags & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
            mbps = e->event_data.link_event_adv.link_speed;
          if (speed == VIRTCHNL_LINK_SPEED_40GB)
            mbps = 40000;
@@ -1138,10 +1187,10 @@ avf_process_one_device (vlib_main_t * vm, avf_device_t * ad, int is_irq)
                  u8 link_status;
                  u32 link_speed;
                } *ed;
-             ed = ELOG_DATA (&vm->elog_main, el);
-              ed->dev_instance = ad->dev_instance;
-             ed->link_status = link_up;
-             ed->link_speed = mbps;
+               ed = ELOG_DATA (&vlib_global_main.elog_main, el);
+               ed->dev_instance = ad->dev_instance;
+               ed->link_status = link_up;
+               ed->link_speed = mbps;
            }
        }
       else
@@ -1159,10 +1208,10 @@ avf_process_one_device (vlib_main_t * vm, avf_device_t * ad, int is_irq)
                  u32 event;
                  u32 severity;
                } *ed;
-             ed = ELOG_DATA (&vm->elog_main, el);
-              ed->dev_instance = ad->dev_instance;
-             ed->event = e->event;
-             ed->severity = e->severity;
+               ed = ELOG_DATA (&vlib_global_main.elog_main, el);
+               ed->dev_instance = ad->dev_instance;
+               ed->event = e->event;
+               ed->severity = e->severity;
            }
        }
     }
@@ -1374,7 +1423,7 @@ avf_irq_0_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
        u32 icr0;
       } *ed;
 
-      ed = ELOG_DATA (&vm->elog_main, el);
+      ed = ELOG_DATA (&vlib_global_main.elog_main, el);
       ed->dev_instance = ad->dev_instance;
       ed->icr0 = icr0;
     }
@@ -1410,7 +1459,7 @@ avf_irq_n_handler (vlib_main_t * vm, vlib_pci_dev_handle_t h, u16 line)
        u16 line;
       } *ed;
 
-      ed = ELOG_DATA (&vm->elog_main, el);
+      ed = ELOG_DATA (&vlib_global_main.elog_main, el);
       ed->dev_instance = ad->dev_instance;
       ed->line = line;
     }
@@ -1428,6 +1477,7 @@ avf_delete_if (vlib_main_t * vm, avf_device_t * ad, int with_barrier)
   vnet_main_t *vnm = vnet_get_main ();
   avf_main_t *am = &avf_main;
   int i;
+  u32 dev_instance;
 
   ad->flags &= ~AVF_DEVICE_F_ADMIN_UP;
 
@@ -1473,17 +1523,21 @@ avf_delete_if (vlib_main_t * vm, avf_device_t * ad, int with_barrier)
                                      txq->n_enqueued);
        }
       /* Free the placeholder buffer */
-      vlib_buffer_free_one(vm, txq->ctx_desc_placeholder_bi);
+      vlib_buffer_free (vm, txq->ph_bufs, vec_len (txq->ph_bufs));
+      vec_free (txq->ph_bufs);
       vec_free (txq->bufs);
       clib_ring_free (txq->rs_slots);
+      vec_free (txq->tmp_bufs);
+      vec_free (txq->tmp_descs);
     }
   /* *INDENT-ON* */
   vec_free (ad->txqs);
   vec_free (ad->name);
 
   clib_error_free (ad->error);
+  dev_instance = ad->dev_instance;
   clib_memset (ad, 0, sizeof (*ad));
-  pool_put_index (am->devices, ad->dev_instance);
+  pool_put_index (am->devices, dev_instance);
   clib_mem_free (ad);
 }
 
@@ -1746,7 +1800,7 @@ avf_interface_rx_mode_change (vnet_main_t * vnm, u32 hw_if_index, u32 qid,
     {
       if (rxq->int_mode == 0)
        return 0;
-      if (ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
+      if (ad->cap_flags & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
        avf_irq_n_set_state (ad, qid, AVF_IRQ_STATE_WB_ON_ITR);
       else
        avf_irq_n_set_state (ad, qid, AVF_IRQ_STATE_ENABLED);