Use link speed from device capability instead of negotiated speeda
[samplevnf.git] / VNFs / DPPD-PROX / handle_gen.c
index 0e5164b..000d017 100644 (file)
@@ -642,6 +642,8 @@ static int handle_gen_bulk(struct task_base *tbase, struct rte_mbuf **mbufs, uin
 
        int i, j;
 
+#if RTE_VERSION < RTE_VERSION_NUM(16,4,0,0)
+       // On more recent DPDK, we use the speed_capa of the port, and not the negotiated speed
        // If link is down, link_speed is 0
        if (unlikely(task->link_speed == 0)) {
                if (task->port && task->port->link_speed != 0) {
@@ -651,6 +653,7 @@ static int handle_gen_bulk(struct task_base *tbase, struct rte_mbuf **mbufs, uin
                } else
                        return 0;
        }
+#endif
 
        task_gen_update_config(task);
 
@@ -1005,15 +1008,20 @@ static struct rte_mempool *task_gen_create_mempool(struct task_args *targ, uint1
        const int sock_id = rte_lcore_to_socket_id(targ->lconf->id);
 
        name[0]++;
-       uint32_t mbuf_size = MBUF_SIZE;
+       uint32_t mbuf_size = TX_MBUF_SIZE;
        if (max_frame_size + (unsigned)sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM > mbuf_size)
                mbuf_size = max_frame_size + (unsigned)sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM;
+       plog_info("\t\tCreating mempool with name '%s'\n", name);
        ret = rte_mempool_create(name, targ->nb_mbuf - 1, mbuf_size,
                                 targ->nb_cache_mbuf, sizeof(struct rte_pktmbuf_pool_private),
                                 rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, 0,
                                 sock_id, 0);
        PROX_PANIC(ret == NULL, "Failed to allocate dummy memory pool on socket %u with %u elements\n",
                   sock_id, targ->nb_mbuf - 1);
+
+        plog_info("\t\tMempool %p size = %u * %u cache %u, socket %d\n", ret,
+                  targ->nb_mbuf - 1, mbuf_size, targ->nb_cache_mbuf, sock_id);
+
        return ret;
 }
 
@@ -1192,6 +1200,7 @@ static void start(struct task_base *tbase)
        if (task->port) {
                // task->port->link_speed reports the link speed in Mbps e.g. 40k for a 40 Gbps NIC.
                // task->link_speed reports link speed in Bytes per sec.
+#if RTE_VERSION < RTE_VERSION_NUM(16,4,0,0)
                // It can be 0 if link is down, and must hence be updated in fast path.
                task->link_speed = task->port->link_speed * 125000L;
                if (task->link_speed)
@@ -1200,6 +1209,15 @@ static void start(struct task_base *tbase)
                else
                        plog_info("\tPort %u: link speed is %ld Mbps - link might be down\n",
                                (uint8_t)(task->port - prox_port_cfg), 8 * task->link_speed / 1000000);
+#else
+               if (task->port->link_speed == UINT32_MAX)
+                       task->link_speed = UINT64_MAX;
+               else {
+                       task->link_speed = task->port->link_speed * 125000L;
+                       plog_info("\tPort %u: link max speed is %ld Mbps\n",
+                               (uint8_t)(task->port - prox_port_cfg), 8 * task->link_speed / 1000000);
+               }
+#endif
        }
        /* TODO
           Handle the case when two tasks transmit to the same port
@@ -1241,7 +1259,7 @@ static void init_task_gen(struct task_base *tbase, struct task_args *targ)
        struct prox_port_cfg *port = find_reachable_port(targ);
        // TODO: check that all reachable ports have the same mtu...
        if (port) {
-               task->cksum_offload = port->capabilities.tx_offload_cksum;
+               task->cksum_offload = port->requested_tx_offload & (DEV_TX_OFFLOAD_IPV4_CKSUM | DEV_TX_OFFLOAD_UDP_CKSUM);
                task->port = port;
                task->max_frame_size = port->mtu + ETHER_HDR_LEN + 2 * PROX_VLAN_TAG_SIZE;
        } else {
@@ -1296,7 +1314,8 @@ static void init_task_gen(struct task_base *tbase, struct task_args *targ)
                task_init_gen_load_pcap(task, targ);
        }
 
-       if ((targ->flags & DSF_KEEP_SRC_MAC) == 0 && (targ->nb_txrings || targ->nb_txports)) {
+       PROX_PANIC(((targ->nb_txrings == 0) && (targ->nb_txports == 0)), "Gen mode requires a tx ring or a tx port");
+       if ((targ->flags & DSF_KEEP_SRC_MAC) == 0) {
                uint8_t *src_addr = prox_port_cfg[tbase->tx_params_hw.tx_port_queue->port].eth_addr.addr_bytes;
                for (uint32_t i = 0; i < task->n_pkts; ++i) {
                        rte_memcpy(&task->pkt_template[i].buf[6], src_addr, 6);
@@ -1318,7 +1337,7 @@ static struct task_init task_init_gen = {
 #ifdef SOFT_CRC
        // For SOFT_CRC, no offload is needed. If both NOOFFLOADS and NOMULTSEGS flags are set the
        // vector mode is used by DPDK, resulting (theoretically) in higher performance.
-       .flag_features = TASK_FEATURE_NEVER_DISCARDS | TASK_FEATURE_NO_RX | TASK_FEATURE_TXQ_FLAGS_NOOFFLOADS | TASK_FEATURE_TXQ_FLAGS_NOMULTSEGS,
+       .flag_features = TASK_FEATURE_NEVER_DISCARDS | TASK_FEATURE_NO_RX | TASK_FEATURE_TXQ_FLAGS_NOOFFLOADS,
 #else
        .flag_features = TASK_FEATURE_NEVER_DISCARDS | TASK_FEATURE_NO_RX,
 #endif
@@ -1335,7 +1354,7 @@ static struct task_init task_init_gen_l3 = {
 #ifdef SOFT_CRC
        // For SOFT_CRC, no offload is needed. If both NOOFFLOADS and NOMULTSEGS flags are set the
        // vector mode is used by DPDK, resulting (theoretically) in higher performance.
-       .flag_features = TASK_FEATURE_NEVER_DISCARDS | TASK_FEATURE_NO_RX | TASK_FEATURE_TXQ_FLAGS_NOOFFLOADS | TASK_FEATURE_TXQ_FLAGS_NOMULTSEGS,
+       .flag_features = TASK_FEATURE_NEVER_DISCARDS | TASK_FEATURE_NO_RX | TASK_FEATURE_TXQ_FLAGS_NOOFFLOADS,
 #else
        .flag_features = TASK_FEATURE_NEVER_DISCARDS | TASK_FEATURE_NO_RX,
 #endif
@@ -1350,7 +1369,7 @@ static struct task_init task_init_gen_pcap = {
        .start = start_pcap,
        .early_init = init_task_gen_early,
 #ifdef SOFT_CRC
-       .flag_features = TASK_FEATURE_NEVER_DISCARDS | TASK_FEATURE_NO_RX | TASK_FEATURE_TXQ_FLAGS_NOOFFLOADS | TASK_FEATURE_TXQ_FLAGS_NOMULTSEGS,
+       .flag_features = TASK_FEATURE_NEVER_DISCARDS | TASK_FEATURE_NO_RX | TASK_FEATURE_TXQ_FLAGS_NOOFFLOADS,
 #else
        .flag_features = TASK_FEATURE_NEVER_DISCARDS | TASK_FEATURE_NO_RX,
 #endif