app/testpmd: separate forward config setup from display
[dpdk.git] / app / test-pmd / config.c
index 7088f6f..24eac3c 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -750,7 +750,7 @@ ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
                printf("%s ring memory zoneof (port %d, queue %d) not"
                       "found (zone name = %s\n",
                       ring_name, port_id, q_id, mz_name);
-       return (mz);
+       return mz;
 }
 
 union igb_ring_dword {
@@ -1381,7 +1381,7 @@ fwd_config_setup(void)
                simple_fwd_config_setup();
 }
 
-static void
+void
 pkt_fwd_config_display(struct fwd_config *cfg)
 {
        struct fwd_stream *fs;
@@ -1420,14 +1420,6 @@ pkt_fwd_config_display(struct fwd_config *cfg)
        printf("\n");
 }
 
-
-void
-fwd_config_display(void)
-{
-       fwd_config_setup();
-       pkt_fwd_config_display(&cur_fwd_config);
-}
-
 int
 set_fwd_lcores_list(unsigned int *lcorelist, unsigned int nb_lc)
 {
@@ -1565,6 +1557,22 @@ set_fwd_ports_number(uint16_t nb_pt)
               (unsigned int) nb_fwd_ports);
 }
 
+int
+port_is_forwarding(portid_t port_id)
+{
+       unsigned int i;
+
+       if (port_id_is_invalid(port_id, ENABLED_WARN))
+               return -1;
+
+       for (i = 0; i < nb_fwd_ports; i++) {
+               if (fwd_ports_ids[i] == port_id)
+                       return 1;
+       }
+
+       return 0;
+}
+
 void
 set_nb_pkt_per_burst(uint16_t nb)
 {
@@ -1673,8 +1681,10 @@ list_pkt_forwarding_modes(void)
 
        if (strlen (fwd_modes) == 0) {
                while ((fwd_eng = fwd_engines[i++]) != NULL) {
-                       strcat(fwd_modes, fwd_eng->fwd_mode_name);
-                       strcat(fwd_modes, separator);
+                       strncat(fwd_modes, fwd_eng->fwd_mode_name,
+                                       sizeof(fwd_modes) - strlen(fwd_modes) - 1);
+                       strncat(fwd_modes, separator,
+                                       sizeof(fwd_modes) - strlen(fwd_modes) - 1);
                }
                fwd_modes[strlen(fwd_modes) - strlen(separator)] = '\0';
        }
@@ -1821,28 +1831,37 @@ rx_vlan_all_filter_set(portid_t port_id, int on)
 }
 
 void
-vlan_tpid_set(portid_t port_id, uint16_t tp_id)
+vlan_tpid_set(portid_t port_id, enum rte_vlan_type vlan_type, uint16_t tp_id)
 {
        int diag;
+
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
 
-       diag = rte_eth_dev_set_vlan_ether_type(port_id, tp_id);
+       diag = rte_eth_dev_set_vlan_ether_type(port_id, vlan_type, tp_id);
        if (diag == 0)
                return;
 
-       printf("tx_vlan_tpid_set(port_pi=%d, tpid=%d) failed "
+       printf("tx_vlan_tpid_set(port_pi=%d, vlan_type=%d, tpid=%d) failed "
               "diag=%d\n",
-              port_id, tp_id, diag);
+              port_id, vlan_type, tp_id, diag);
 }
 
 void
 tx_vlan_set(portid_t port_id, uint16_t vlan_id)
 {
+       int vlan_offload;
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
        if (vlan_id_is_invalid(vlan_id))
                return;
+
+       vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
+       if (vlan_offload & ETH_VLAN_EXTEND_OFFLOAD) {
+               printf("Error, as QinQ has been enabled.\n");
+               return;
+       }
+
        tx_vlan_reset(port_id);
        ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_VLAN;
        ports[port_id].tx_vlan_id = vlan_id;
@@ -1851,12 +1870,20 @@ tx_vlan_set(portid_t port_id, uint16_t vlan_id)
 void
 tx_qinq_set(portid_t port_id, uint16_t vlan_id, uint16_t vlan_id_outer)
 {
+       int vlan_offload;
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
        if (vlan_id_is_invalid(vlan_id))
                return;
        if (vlan_id_is_invalid(vlan_id_outer))
                return;
+
+       vlan_offload = rte_eth_dev_get_vlan_offload(port_id);
+       if (!(vlan_offload & ETH_VLAN_EXTEND_OFFLOAD)) {
+               printf("Error, as QinQ hasn't been enabled.\n");
+               return;
+       }
+
        tx_vlan_reset(port_id);
        ports[port_id].tx_ol_flags |= TESTPMD_TX_OFFLOAD_INSERT_QINQ;
        ports[port_id].tx_vlan_id = vlan_id;