net/mlx5: remove configuration variable
[dpdk.git] / examples / ip_pipeline / init.c
index b2eafe3..cd167f6 100644 (file)
@@ -1176,6 +1176,111 @@ app_init_tm(struct app_params *app)
        }
 }
 
+#ifdef RTE_LIBRTE_KNI
+static int
+kni_config_network_interface(uint8_t port_id, uint8_t if_up) {
+       int ret = 0;
+
+       if (port_id >= rte_eth_dev_count())
+               return -EINVAL;
+
+       ret = (if_up) ?
+               rte_eth_dev_set_link_up(port_id) :
+               rte_eth_dev_set_link_down(port_id);
+
+       return ret;
+}
+
+static int
+kni_change_mtu(uint8_t port_id, unsigned new_mtu) {
+       int ret;
+
+       if (port_id >= rte_eth_dev_count())
+               return -EINVAL;
+
+       if (new_mtu > ETHER_MAX_LEN)
+               return -EINVAL;
+
+       /* Set new MTU */
+       ret = rte_eth_dev_set_mtu(port_id, new_mtu);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+#endif /* RTE_LIBRTE_KNI */
+
+#ifndef RTE_LIBRTE_KNI
+static void
+app_init_kni(struct app_params *app) {
+       if (app->n_pktq_kni == 0)
+               return;
+
+       rte_panic("Can not init KNI without librte_kni support.\n");
+}
+#else
+static void
+app_init_kni(struct app_params *app) {
+       uint32_t i;
+
+       if (app->n_pktq_kni == 0)
+               return;
+
+       rte_kni_init(app->n_pktq_kni);
+
+       for (i = 0; i < app->n_pktq_kni; i++) {
+               struct app_pktq_kni_params *p_kni = &app->kni_params[i];
+               struct app_link_params *p_link;
+               struct rte_eth_dev_info dev_info;
+               struct app_mempool_params *mempool_params;
+               struct rte_mempool *mempool;
+               struct rte_kni_conf conf;
+               struct rte_kni_ops ops;
+
+               /* LINK */
+               p_link = app_get_link_for_kni(app, p_kni);
+               memset(&dev_info, 0, sizeof(dev_info));
+               rte_eth_dev_info_get(p_link->pmd_id, &dev_info);
+
+               /* MEMPOOL */
+               mempool_params = &app->mempool_params[p_kni->mempool_id];
+               mempool = app->mempool[p_kni->mempool_id];
+
+               /* KNI */
+               memset(&conf, 0, sizeof(conf));
+               snprintf(conf.name, RTE_KNI_NAMESIZE, "%s", p_kni->name);
+               conf.force_bind = p_kni->force_bind;
+               if (conf.force_bind) {
+                       int lcore_id;
+
+                       lcore_id = cpu_core_map_get_lcore_id(app->core_map,
+                               p_kni->socket_id,
+                               p_kni->core_id,
+                               p_kni->hyper_th_id);
+
+                       if (lcore_id < 0)
+                               rte_panic("%s invalid CPU core\n", p_kni->name);
+
+                       conf.core_id = (uint32_t) lcore_id;
+               }
+               conf.group_id = p_link->pmd_id;
+               conf.mbuf_size = mempool_params->buffer_size;
+               conf.addr = dev_info.pci_dev->addr;
+               conf.id = dev_info.pci_dev->id;
+
+               memset(&ops, 0, sizeof(ops));
+               ops.port_id = (uint8_t) p_link->pmd_id;
+               ops.change_mtu = kni_change_mtu;
+               ops.config_network_if = kni_config_network_interface;
+
+               APP_LOG(app, HIGH, "Initializing %s ...", p_kni->name);
+               app->kni[i] = rte_kni_alloc(mempool, &conf, &ops);
+               if (!app->kni[i])
+                       rte_panic("%s init error\n", p_kni->name);
+       }
+}
+#endif /* RTE_LIBRTE_KNI */
+
 static void
 app_init_msgq(struct app_params *app)
 {
@@ -1196,7 +1301,7 @@ app_init_msgq(struct app_params *app)
        }
 }
 
-static void app_pipeline_params_get(struct app_params *app,
+void app_pipeline_params_get(struct app_params *app,
        struct app_pipeline_params *p_in,
        struct pipeline_params *p_out)
 {
@@ -1204,6 +1309,8 @@ static void app_pipeline_params_get(struct app_params *app,
 
        snprintf(p_out->name, PIPELINE_NAME_SIZE, "%s", p_in->name);
 
+       snprintf(p_out->type, PIPELINE_TYPE_SIZE, "%s", p_in->type);
+
        p_out->socket_id = (int) p_in->socket_id;
 
        p_out->log_level = app->log_level;
@@ -1279,10 +1386,21 @@ static void app_pipeline_params_get(struct app_params *app,
                        break;
                }
                case APP_PKTQ_IN_TM:
+               {
                        out->type = PIPELINE_PORT_IN_SCHED_READER;
                        out->params.sched.sched = app->tm[in->id];
                        out->burst_size = app->tm_params[in->id].burst_read;
                        break;
+               }
+#ifdef RTE_LIBRTE_KNI
+               case APP_PKTQ_IN_KNI:
+               {
+                       out->type = PIPELINE_PORT_IN_KNI_READER;
+                       out->params.kni.kni = app->kni[in->id];
+                       out->burst_size = app->kni_params[in->id].burst_read;
+                       break;
+               }
+#endif /* RTE_LIBRTE_KNI */
                case APP_PKTQ_IN_SOURCE:
                {
                        uint32_t mempool_id =
@@ -1407,7 +1525,8 @@ static void app_pipeline_params_get(struct app_params *app,
                        }
                        break;
                }
-               case APP_PKTQ_OUT_TM: {
+               case APP_PKTQ_OUT_TM:
+               {
                        struct rte_port_sched_writer_params *params =
                                &out->params.sched;
 
@@ -1417,6 +1536,34 @@ static void app_pipeline_params_get(struct app_params *app,
                                app->tm_params[in->id].burst_write;
                        break;
                }
+#ifdef RTE_LIBRTE_KNI
+               case APP_PKTQ_OUT_KNI:
+               {
+                       struct app_pktq_kni_params *p_kni =
+                               &app->kni_params[in->id];
+
+                       if (p_kni->dropless == 0) {
+                               struct rte_port_kni_writer_params *params =
+                                       &out->params.kni;
+
+                               out->type = PIPELINE_PORT_OUT_KNI_WRITER;
+                               params->kni = app->kni[in->id];
+                               params->tx_burst_sz =
+                                       app->kni_params[in->id].burst_write;
+                       } else {
+                               struct rte_port_kni_writer_nodrop_params
+                                       *params = &out->params.kni_nodrop;
+
+                               out->type = PIPELINE_PORT_OUT_KNI_WRITER_NODROP;
+                               params->kni = app->kni[in->id];
+                               params->tx_burst_sz =
+                                       app->kni_params[in->id].burst_write;
+                               params->n_retries =
+                                       app->kni_params[in->id].n_retries;
+                       }
+                       break;
+               }
+#endif /* RTE_LIBRTE_KNI */
                case APP_PKTQ_OUT_SINK:
                {
                        out->type = PIPELINE_PORT_OUT_SINK;
@@ -1498,6 +1645,27 @@ app_init_pipelines(struct app_params *app)
        }
 }
 
+static void
+app_post_init_pipelines(struct app_params *app)
+{
+       uint32_t p_id;
+
+       for (p_id = 0; p_id < app->n_pipelines; p_id++) {
+               struct app_pipeline_params *params =
+                       &app->pipeline_params[p_id];
+               struct app_pipeline_data *data = &app->pipeline_data[p_id];
+               int status;
+
+               if (data->ptype->fe_ops->f_post_init == NULL)
+                       continue;
+
+               status = data->ptype->fe_ops->f_post_init(data->fe);
+               if (status)
+                       rte_panic("Pipeline instance \"%s\" front-end "
+                               "post-init error\n", params->name);
+       }
+}
+
 static void
 app_init_threads(struct app_params *app)
 {
@@ -1584,6 +1752,7 @@ int app_init(struct app_params *app)
        app_init_link(app);
        app_init_swq(app);
        app_init_tm(app);
+       app_init_kni(app);
        app_init_msgq(app);
 
        app_pipeline_common_cmd_push(app);
@@ -1601,6 +1770,13 @@ int app_init(struct app_params *app)
        return 0;
 }
 
+int app_post_init(struct app_params *app)
+{
+       app_post_init_pipelines(app);
+
+       return 0;
+}
+
 static int
 app_pipeline_type_cmd_push(struct app_params *app,
        struct pipeline_type *ptype)