net/sfc: support API to negotiate delivery of Rx metadata
[dpdk.git] / app / test-pmd / testpmd.c
index 9061cbf..a7841c5 100644 (file)
@@ -521,6 +521,97 @@ enum rte_eth_rx_mq_mode rx_mq_mode = ETH_MQ_RX_VMDQ_DCB_RSS;
  */
 uint32_t eth_link_speed;
 
+/*
+ * ID of the current process in multi-process, used to
+ * configure the queues to be polled.
+ */
+int proc_id;
+
+/*
+ * Number of processes in multi-process, used to
+ * configure the queues to be polled.
+ */
+unsigned int num_procs = 1;
+
+static void
+eth_rx_metadata_negotiate_mp(uint16_t port_id)
+{
+       uint64_t rx_meta_features = 0;
+       int ret;
+
+       if (!is_proc_primary())
+               return;
+
+       rx_meta_features |= RTE_ETH_RX_METADATA_USER_FLAG;
+       rx_meta_features |= RTE_ETH_RX_METADATA_USER_MARK;
+       rx_meta_features |= RTE_ETH_RX_METADATA_TUNNEL_ID;
+
+       ret = rte_eth_rx_metadata_negotiate(port_id, &rx_meta_features);
+       if (ret == 0) {
+               if (!(rx_meta_features & RTE_ETH_RX_METADATA_USER_FLAG)) {
+                       TESTPMD_LOG(DEBUG, "Flow action FLAG will not affect Rx mbufs on port %u\n",
+                                   port_id);
+               }
+
+               if (!(rx_meta_features & RTE_ETH_RX_METADATA_USER_MARK)) {
+                       TESTPMD_LOG(DEBUG, "Flow action MARK will not affect Rx mbufs on port %u\n",
+                                   port_id);
+               }
+
+               if (!(rx_meta_features & RTE_ETH_RX_METADATA_TUNNEL_ID)) {
+                       TESTPMD_LOG(DEBUG, "Flow tunnel offload support might be limited or unavailable on port %u\n",
+                                   port_id);
+               }
+       } else if (ret != -ENOTSUP) {
+               rte_exit(EXIT_FAILURE, "Error when negotiating Rx meta features on port %u: %s\n",
+                        port_id, rte_strerror(-ret));
+       }
+}
+
+static int
+eth_dev_configure_mp(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
+                     const struct rte_eth_conf *dev_conf)
+{
+       if (is_proc_primary())
+               return rte_eth_dev_configure(port_id, nb_rx_q, nb_tx_q,
+                                       dev_conf);
+       return 0;
+}
+
+static int
+eth_dev_start_mp(uint16_t port_id)
+{
+       if (is_proc_primary())
+               return rte_eth_dev_start(port_id);
+
+       return 0;
+}
+
+static int
+eth_dev_stop_mp(uint16_t port_id)
+{
+       if (is_proc_primary())
+               return rte_eth_dev_stop(port_id);
+
+       return 0;
+}
+
+static void
+mempool_free_mp(struct rte_mempool *mp)
+{
+       if (is_proc_primary())
+               rte_mempool_free(mp);
+}
+
+static int
+eth_dev_set_mtu_mp(uint16_t port_id, uint16_t mtu)
+{
+       if (is_proc_primary())
+               return rte_eth_dev_set_mtu(port_id, mtu);
+
+       return 0;
+}
+
 /* Forward function declarations */
 static void setup_attached_port(portid_t pi);
 static void check_all_ports_link_status(uint32_t port_mask);
@@ -996,6 +1087,14 @@ mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf,
        mb_size = sizeof(struct rte_mbuf) + mbuf_seg_size;
 #endif
        mbuf_poolname_build(socket_id, pool_name, sizeof(pool_name), size_idx);
+       if (!is_proc_primary()) {
+               rte_mp = rte_mempool_lookup(pool_name);
+               if (rte_mp == NULL)
+                       rte_exit(EXIT_FAILURE,
+                               "Get mbuf pool for socket %u failed: %s\n",
+                               socket_id, rte_strerror(rte_errno));
+               return rte_mp;
+       }
 
        TESTPMD_LOG(INFO,
                "create a new mbuf pool <%s>: n=%u, size=%u, socket=%u\n",
@@ -1425,6 +1524,8 @@ init_config_port_offloads(portid_t pid, uint32_t socket_id)
        int ret;
        int i;
 
+       eth_rx_metadata_negotiate_mp(pid);
+
        port->dev_conf.txmode = tx_mode;
        port->dev_conf.rxmode = rx_mode;
 
@@ -1995,6 +2096,11 @@ flush_fwd_rx_queues(void)
        uint64_t prev_tsc = 0, diff_tsc, cur_tsc, timer_tsc = 0;
        uint64_t timer_period;
 
+       if (num_procs > 1) {
+               printf("multi-process not support for flushing fwd Rx queues, skip the below lines and return.\n");
+               return;
+       }
+
        /* convert to number of cycles */
        timer_period = rte_get_timer_hz(); /* 1 second timeout */
 
@@ -2103,16 +2209,10 @@ run_one_txonly_burst_on_core(void *fwd_arg)
 static void
 launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
 {
-       port_fwd_begin_t port_fwd_begin;
        unsigned int i;
        unsigned int lc_id;
        int diag;
 
-       port_fwd_begin = cur_fwd_config.fwd_eng->port_fwd_begin;
-       if (port_fwd_begin != NULL) {
-               for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
-                       (*port_fwd_begin)(fwd_ports_ids[i]);
-       }
        for (i = 0; i < cur_fwd_config.nb_fwd_lcores; i++) {
                lc_id = fwd_lcores_cpuids[i];
                if ((interactive == 0) || (lc_id != rte_lcore_id())) {
@@ -2158,10 +2258,35 @@ start_packet_forwarding(int with_tx_first)
                fprintf(stderr, "Packet forwarding already started\n");
                return;
        }
-       test_done = 0;
 
        fwd_config_setup();
 
+       port_fwd_begin = cur_fwd_config.fwd_eng->port_fwd_begin;
+       if (port_fwd_begin != NULL) {
+               for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
+                       if (port_fwd_begin(fwd_ports_ids[i])) {
+                               fprintf(stderr,
+                                       "Packet forwarding is not ready\n");
+                               return;
+                       }
+               }
+       }
+
+       if (with_tx_first) {
+               port_fwd_begin = tx_only_engine.port_fwd_begin;
+               if (port_fwd_begin != NULL) {
+                       for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) {
+                               if (port_fwd_begin(fwd_ports_ids[i])) {
+                                       fprintf(stderr,
+                                               "Packet forwarding is not ready\n");
+                                       return;
+                               }
+                       }
+               }
+       }
+
+       test_done = 0;
+
        if(!no_flush_rx)
                flush_fwd_rx_queues();
 
@@ -2170,11 +2295,6 @@ start_packet_forwarding(int with_tx_first)
 
        fwd_stats_reset();
        if (with_tx_first) {
-               port_fwd_begin = tx_only_engine.port_fwd_begin;
-               if (port_fwd_begin != NULL) {
-                       for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++)
-                               (*port_fwd_begin)(fwd_ports_ids[i]);
-               }
                while (with_tx_first--) {
                        launch_packet_forwarding(
                                        run_one_txonly_burst_on_core);
@@ -2484,7 +2604,7 @@ start_port(portid_t pid)
                                return -1;
                        }
                        /* configure port */
-                       diag = rte_eth_dev_configure(pi, nb_rxq + nb_hairpinq,
+                       diag = eth_dev_configure_mp(pi, nb_rxq + nb_hairpinq,
                                                     nb_txq + nb_hairpinq,
                                                     &(port->dev_conf));
                        if (diag != 0) {
@@ -2500,7 +2620,7 @@ start_port(portid_t pid)
                                return -1;
                        }
                }
-               if (port->need_reconfig_queues > 0) {
+               if (port->need_reconfig_queues > 0 && is_proc_primary()) {
                        port->need_reconfig_queues = 0;
                        /* setup tx queues */
                        for (qi = 0; qi < nb_txq; qi++) {
@@ -2603,7 +2723,7 @@ start_port(portid_t pid)
                cnt_pi++;
 
                /* start port */
-               diag = rte_eth_dev_start(pi);
+               diag = eth_dev_start_mp(pi);
                if (diag < 0) {
                        fprintf(stderr, "Fail to start port %d: %s\n",
                                pi, rte_strerror(-diag));
@@ -2623,13 +2743,8 @@ start_port(portid_t pid)
                                pi);
 
                if (eth_macaddr_get_print_err(pi, &port->eth_addr) == 0)
-                       printf("Port %d: %02X:%02X:%02X:%02X:%02X:%02X\n", pi,
-                               port->eth_addr.addr_bytes[0],
-                               port->eth_addr.addr_bytes[1],
-                               port->eth_addr.addr_bytes[2],
-                               port->eth_addr.addr_bytes[3],
-                               port->eth_addr.addr_bytes[4],
-                               port->eth_addr.addr_bytes[5]);
+                       printf("Port %d: " RTE_ETHER_ADDR_PRT_FMT "\n", pi,
+                                       RTE_ETHER_ADDR_BYTES(&port->eth_addr));
 
                /* at least one port started, need checking link status */
                need_check_link_status = 1;
@@ -2746,7 +2861,7 @@ stop_port(portid_t pid)
                if (port->flow_list)
                        port_flow_flush(pi);
 
-               if (rte_eth_dev_stop(pi) != 0)
+               if (eth_dev_stop_mp(pi) != 0)
                        RTE_LOG(ERR, EAL, "rte_eth_dev_stop failed for port %u\n",
                                pi);
 
@@ -2820,8 +2935,10 @@ close_port(portid_t pid)
                        continue;
                }
 
-               port_flow_flush(pi);
-               rte_eth_dev_close(pi);
+               if (is_proc_primary()) {
+                       port_flow_flush(pi);
+                       rte_eth_dev_close(pi);
+               }
        }
 
        remove_invalid_ports();
@@ -3106,7 +3223,7 @@ pmd_test_exit(void)
        }
        for (i = 0 ; i < RTE_DIM(mempools) ; i++) {
                if (mempools[i])
-                       rte_mempool_free(mempools[i]);
+                       mempool_free_mp(mempools[i]);
        }
 
        printf("\nBye...\n");
@@ -3447,7 +3564,7 @@ update_jumbo_frame_offload(portid_t portid)
         * if unset do it here
         */
        if ((rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) == 0) {
-               ret = rte_eth_dev_set_mtu(portid,
+               ret = eth_dev_set_mtu_mp(portid,
                                port->dev_conf.rxmode.max_rx_pkt_len - eth_overhead);
                if (ret)
                        fprintf(stderr,
@@ -3643,12 +3760,14 @@ init_port_dcb_config(portid_t pid,
        int retval;
        uint16_t i;
 
+       if (num_procs > 1) {
+               printf("The multi-process feature doesn't support dcb.\n");
+               return -ENOTSUP;
+       }
        rte_port = &ports[pid];
 
-       memset(&port_conf, 0, sizeof(struct rte_eth_conf));
-
-       port_conf.rxmode = rte_port->dev_conf.rxmode;
-       port_conf.txmode = rte_port->dev_conf.txmode;
+       /* retain the original device configuration. */
+       memcpy(&port_conf, &rte_port->dev_conf, sizeof(struct rte_eth_conf));
 
        /*set configuration of DCB in vt mode and DCB in non-vt mode*/
        retval = get_eth_dcb_conf(pid, &port_conf, dcb_mode, num_tcs, pfc_en);
@@ -3812,10 +3931,6 @@ main(int argc, char** argv)
                rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n",
                         rte_strerror(rte_errno));
 
-       if (rte_eal_process_type() == RTE_PROC_SECONDARY)
-               rte_exit(EXIT_FAILURE,
-                        "Secondary process type not supported.\n");
-
        ret = register_eth_event_callback();
        if (ret != 0)
                rte_exit(EXIT_FAILURE, "Cannot register for ethdev events");