app/testpmd: use ethdev iterator to list devices
[dpdk.git] / app / test-pmd / config.c
index 23e0bbf..4d873cd 100644 (file)
@@ -174,7 +174,7 @@ nic_stats_display(portid_t port_id)
 
        if (port_id_is_invalid(port_id, ENABLED_WARN)) {
                printf("Valid port range is [0");
-               FOREACH_PORT(pid, ports)
+               RTE_ETH_FOREACH_DEV(pid)
                        printf(", %d", pid);
                printf("]\n");
                return;
@@ -252,7 +252,7 @@ nic_stats_clear(portid_t port_id)
 
        if (port_id_is_invalid(port_id, ENABLED_WARN)) {
                printf("Valid port range is [0");
-               FOREACH_PORT(pid, ports)
+               RTE_ETH_FOREACH_DEV(pid)
                        printf(", %d", pid);
                printf("]\n");
                return;
@@ -334,7 +334,7 @@ nic_stats_mapping_display(portid_t port_id)
 
        if (port_id_is_invalid(port_id, ENABLED_WARN)) {
                printf("Valid port range is [0");
-               FOREACH_PORT(pid, ports)
+               RTE_ETH_FOREACH_DEV(pid)
                        printf(", %d", pid);
                printf("]\n");
                return;
@@ -449,10 +449,11 @@ port_infos_display(portid_t port_id)
        struct rte_mempool * mp;
        static const char *info_border = "*********************";
        portid_t pid;
+       uint16_t mtu;
 
        if (port_id_is_invalid(port_id, ENABLED_WARN)) {
                printf("Valid port range is [0");
-               FOREACH_PORT(pid, ports)
+               RTE_ETH_FOREACH_DEV(pid)
                        printf(", %d", pid);
                printf("]\n");
                return;
@@ -480,6 +481,10 @@ port_infos_display(portid_t port_id)
        printf("Link speed: %u Mbps\n", (unsigned) link.link_speed);
        printf("Link duplex: %s\n", (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
               ("full-duplex") : ("half-duplex"));
+
+       if (!rte_eth_dev_get_mtu(port_id, &mtu))
+               printf("MTU: %u\n", mtu);
+
        printf("Promiscuous mode: %s\n",
               rte_eth_promiscuous_get(port_id) ? "enabled" : "disabled");
        printf("Allmulticast mode: %s\n",
@@ -543,13 +548,189 @@ port_infos_display(portid_t port_id)
        printf("TXDs number alignment: %hu\n", dev_info.tx_desc_lim.nb_align);
 }
 
+void
+port_offload_cap_display(portid_t port_id)
+{
+       struct rte_eth_dev *dev;
+       struct rte_eth_dev_info dev_info;
+       static const char *info_border = "************";
+
+       if (port_id_is_invalid(port_id, ENABLED_WARN))
+               return;
+
+       dev = &rte_eth_devices[port_id];
+       rte_eth_dev_info_get(port_id, &dev_info);
+
+       printf("\n%s Port %d supported offload features: %s\n",
+               info_border, port_id, info_border);
+
+       if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_VLAN_STRIP) {
+               printf("VLAN stripped:                 ");
+               if (dev->data->dev_conf.rxmode.hw_vlan_strip)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_QINQ_STRIP) {
+               printf("Double VLANs stripped:         ");
+               if (dev->data->dev_conf.rxmode.hw_vlan_extend)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_IPV4_CKSUM) {
+               printf("RX IPv4 checksum:              ");
+               if (dev->data->dev_conf.rxmode.hw_ip_checksum)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_UDP_CKSUM) {
+               printf("RX UDP checksum:               ");
+               if (dev->data->dev_conf.rxmode.hw_ip_checksum)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_CKSUM) {
+               printf("RX TCP checksum:               ");
+               if (dev->data->dev_conf.rxmode.hw_ip_checksum)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM)
+               printf("RX Outer IPv4 checksum:        on");
+
+       if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TCP_LRO) {
+               printf("Large receive offload:         ");
+               if (dev->data->dev_conf.rxmode.enable_lro)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VLAN_INSERT) {
+               printf("VLAN insert:                   ");
+               if (ports[port_id].tx_ol_flags &
+                   TESTPMD_TX_OFFLOAD_INSERT_VLAN)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) {
+               printf("Double VLANs insert:           ");
+               if (ports[port_id].tx_ol_flags &
+                   TESTPMD_TX_OFFLOAD_INSERT_QINQ)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) {
+               printf("TX IPv4 checksum:              ");
+               if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM) {
+               printf("TX UDP checksum:               ");
+               if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_CKSUM) {
+               printf("TX TCP checksum:               ");
+               if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_SCTP_CKSUM) {
+               printf("TX SCTP checksum:              ");
+               if (ports[port_id].tx_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) {
+               printf("TX Outer IPv4 checksum:        ");
+               if (ports[port_id].tx_ol_flags &
+                   TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) {
+               printf("TX TCP segmentation:           ");
+               if (ports[port_id].tso_segsz != 0)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_TSO) {
+               printf("TX UDP segmentation:           ");
+               if (ports[port_id].tso_segsz != 0)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
+               printf("TSO for VXLAN tunnel packet:   ");
+               if (ports[port_id].tunnel_tso_segsz)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GRE_TNL_TSO) {
+               printf("TSO for GRE tunnel packet:     ");
+               if (ports[port_id].tunnel_tso_segsz)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPIP_TNL_TSO) {
+               printf("TSO for IPIP tunnel packet:    ");
+               if (ports[port_id].tunnel_tso_segsz)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+       if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_GENEVE_TNL_TSO) {
+               printf("TSO for GENEVE tunnel packet:  ");
+               if (ports[port_id].tunnel_tso_segsz)
+                       printf("on\n");
+               else
+                       printf("off\n");
+       }
+
+}
+
 int
 port_id_is_invalid(portid_t port_id, enum print_warning warning)
 {
        if (port_id == (portid_t)RTE_PORT_ALL)
                return 0;
 
-       if (port_id < RTE_MAX_ETHPORTS && ports[port_id].enabled)
+       if (rte_eth_dev_is_valid_port(port_id))
                return 0;
 
        if (warning == ENABLED_WARN)
@@ -787,6 +968,8 @@ static const struct {
        MK_FLOW_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
        MK_FLOW_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
        MK_FLOW_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
+       MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)),
+       MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)),
 };
 
 /** Compute storage space needed by item specification. */
@@ -2103,7 +2286,7 @@ set_fwd_ports_mask(uint64_t portmask)
                return;
        }
        nb_pt = 0;
-       for (i = 0; i < (unsigned)RTE_MIN(64, RTE_MAX_ETHPORTS); i++) {
+       RTE_ETH_FOREACH_DEV(i) {
                if (! ((uint64_t)(1ULL << i) & portmask))
                        continue;
                portlist[nb_pt++] = i;
@@ -2831,8 +3014,6 @@ set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
 {
        int diag;
 
-       if (port_id_is_invalid(port_id, ENABLED_WARN))
-               return;
        if (is_rx)
                diag = rte_pmd_ixgbe_set_vf_rx(port_id, vf, on);
        else
@@ -2848,24 +3029,6 @@ set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on)
                        "diag=%d\n", port_id, diag);
 
 }
-
-void
-set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
-{
-       int diag;
-
-       if (port_id_is_invalid(port_id, ENABLED_WARN))
-               return;
-       if (vlan_id_is_invalid(vlan_id))
-               return;
-
-       diag = rte_pmd_ixgbe_set_vf_vlan_filter(port_id, vlan_id, vf_mask, on);
-
-       if (diag == 0)
-               return;
-       printf("rte_pmd_ixgbe_set_vf_vlan_filter for port_id=%d failed "
-              "diag=%d\n", port_id, diag);
-}
 #endif
 
 int
@@ -2895,19 +3058,7 @@ int
 set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
 {
        int diag;
-       struct rte_eth_link link;
-
-       if (q_msk == 0)
-               return 0;
 
-       if (port_id_is_invalid(port_id, ENABLED_WARN))
-               return 1;
-       rte_eth_link_get_nowait(port_id, &link);
-       if (rate > link.link_speed) {
-               printf("Invalid rate value:%u bigger than link speed: %u\n",
-                       rate, link.link_speed);
-               return 1;
-       }
        diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate, q_msk);
        if (diag == 0)
                return diag;
@@ -3101,3 +3252,70 @@ port_dcb_info_display(uint8_t port_id)
                printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue);
        printf("\n");
 }
+
+uint8_t *
+open_ddp_package_file(const char *file_path, uint32_t *size)
+{
+       FILE *fh = fopen(file_path, "rb");
+       uint32_t pkg_size;
+       uint8_t *buf = NULL;
+       int ret = 0;
+
+       if (size)
+               *size = 0;
+
+       if (fh == NULL) {
+               printf("%s: Failed to open %s\n", __func__, file_path);
+               return buf;
+       }
+
+       ret = fseek(fh, 0, SEEK_END);
+       if (ret < 0) {
+               fclose(fh);
+               printf("%s: File operations failed\n", __func__);
+               return buf;
+       }
+
+       pkg_size = ftell(fh);
+
+       buf = (uint8_t *)malloc(pkg_size);
+       if (!buf) {
+               fclose(fh);
+               printf("%s: Failed to malloc memory\n", __func__);
+               return buf;
+       }
+
+       ret = fseek(fh, 0, SEEK_SET);
+       if (ret < 0) {
+               fclose(fh);
+               printf("%s: File seek operation failed\n", __func__);
+               close_ddp_package_file(buf);
+               return NULL;
+       }
+
+       ret = fread(buf, 1, pkg_size, fh);
+       if (ret < 0) {
+               fclose(fh);
+               printf("%s: File read operation failed\n", __func__);
+               close_ddp_package_file(buf);
+               return NULL;
+       }
+
+       if (size)
+               *size = pkg_size;
+
+       fclose(fh);
+
+       return buf;
+}
+
+int
+close_ddp_package_file(uint8_t *buf)
+{
+       if (buf) {
+               free((void *)buf);
+               return 0;
+       }
+
+       return -1;
+}