X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fsoftnic%2Frte_eth_softnic.c;h=148b82ecb29362ce9e45147485f34ca2de31d74b;hb=8364aa4734210806aced02525c06d52bc3162375;hp=f89a1058bd4500c46d3a4b038cc4117036583acf;hpb=bd2fbb6252f91afb0e5c35e248ad48d6d6e42733;p=dpdk.git diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c index f89a1058bd..148b82ecb2 100644 --- a/drivers/net/softnic/rte_eth_softnic.c +++ b/drivers/net/softnic/rte_eth_softnic.c @@ -19,8 +19,6 @@ #include "rte_eth_softnic_internals.h" #define PMD_PARAM_FIRMWARE "firmware" -#define PMD_PARAM_CPU_ID "cpu_id" -#define PMD_PARAM_SCRIPT "script" #define PMD_PARAM_CONN_PORT "conn_port" #define PMD_PARAM_CPU_ID "cpu_id" #define PMD_PARAM_TM_N_QUEUES "tm_n_queues" @@ -31,6 +29,7 @@ static const char *pmd_valid_args[] = { PMD_PARAM_FIRMWARE, + PMD_PARAM_CONN_PORT, PMD_PARAM_CPU_ID, PMD_PARAM_TM_N_QUEUES, PMD_PARAM_TM_QSIZE0, @@ -40,6 +39,25 @@ static const char *pmd_valid_args[] = { NULL }; +static const char welcome[] = + "\n" + "Welcome to Soft NIC!\n" + "\n"; + +static const char prompt[] = "softnic> "; + +struct softnic_conn_params conn_params_default = { + .welcome = welcome, + .prompt = prompt, + .addr = "0.0.0.0", + .port = 0, + .buf_size = 1024 * 1024, + .msg_in_len_max = 1024, + .msg_out_len_max = 1024 * 1024, + .msg_handle = softnic_cli_process, + .msg_handle_arg = NULL, +}; + static const struct rte_eth_dev_info pmd_dev_info = { .min_rx_bufsize = 0, .max_rx_pktlen = UINT32_MAX, @@ -55,7 +73,6 @@ static const struct rte_eth_dev_info pmd_dev_info = { .nb_min = 0, .nb_align = 1, }, - .rx_offload_capa = DEV_RX_OFFLOAD_CRC_STRIP, }; static int pmd_softnic_logtype; @@ -81,26 +98,27 @@ static int pmd_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id, uint16_t nb_rx_desc, - unsigned int socket_id, + unsigned int socket_id __rte_unused, const struct rte_eth_rxconf *rx_conf __rte_unused, struct rte_mempool *mb_pool __rte_unused) { - uint32_t size = RTE_ETH_NAME_MAX_LEN + strlen("_rxq") + 4; - char name[size]; - struct rte_ring *r; - - snprintf(name, sizeof(name), "%s_rxq%04x", - dev->data->name, - rx_queue_id); - - r = rte_ring_create(name, - nb_rx_desc, - socket_id, - RING_F_SP_ENQ | RING_F_SC_DEQ); - if (r == NULL) + char name[NAME_SIZE]; + struct pmd_internals *p = dev->data->dev_private; + struct softnic_swq *swq; + + struct softnic_swq_params params = { + .size = nb_rx_desc, + }; + + snprintf(name, sizeof(name), "RXQ%u", rx_queue_id); + + swq = softnic_swq_create(p, + name, + ¶ms); + if (swq == NULL) return -1; - dev->data->rx_queues[rx_queue_id] = r; + dev->data->rx_queues[rx_queue_id] = swq->r; return 0; } @@ -108,31 +126,44 @@ static int pmd_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id, uint16_t nb_tx_desc, - unsigned int socket_id, + unsigned int socket_id __rte_unused, const struct rte_eth_txconf *tx_conf __rte_unused) { - uint32_t size = RTE_ETH_NAME_MAX_LEN + strlen("_txq") + 4; - char name[size]; - struct rte_ring *r; - - snprintf(name, sizeof(name), "%s_txq%04x", - dev->data->name, - tx_queue_id); - - r = rte_ring_create(name, - nb_tx_desc, - socket_id, - RING_F_SP_ENQ | RING_F_SC_DEQ); - if (r == NULL) + char name[NAME_SIZE]; + struct pmd_internals *p = dev->data->dev_private; + struct softnic_swq *swq; + + struct softnic_swq_params params = { + .size = nb_tx_desc, + }; + + snprintf(name, sizeof(name), "TXQ%u", tx_queue_id); + + swq = softnic_swq_create(p, + name, + ¶ms); + if (swq == NULL) return -1; - dev->data->tx_queues[tx_queue_id] = r; + dev->data->tx_queues[tx_queue_id] = swq->r; return 0; } static int pmd_dev_start(struct rte_eth_dev *dev) { + struct pmd_internals *p = dev->data->dev_private; + int status; + + /* Firmware */ + status = softnic_cli_script_process(p, + p->params.firmware, + conn_params_default.msg_in_len_max, + conn_params_default.msg_out_len_max); + if (status) + return status; + + /* Link UP */ dev->data->dev_link.link_status = ETH_LINK_UP; return 0; @@ -141,21 +172,29 @@ pmd_dev_start(struct rte_eth_dev *dev) static void pmd_dev_stop(struct rte_eth_dev *dev) { + struct pmd_internals *p = dev->data->dev_private; + + /* Link DOWN */ dev->data->dev_link.link_status = ETH_LINK_DOWN; + + /* Firmware */ + softnic_pipeline_disable_all(p); + softnic_pipeline_free(p); + softnic_table_action_profile_free(p); + softnic_port_in_action_profile_free(p); + softnic_tap_free(p); + softnic_tmgr_free(p); + softnic_link_free(p); + softnic_softnic_swq_free_keep_rxq_txq(p); + softnic_mempool_free(p); + + tm_hierarchy_free(p); } static void -pmd_dev_close(struct rte_eth_dev *dev) +pmd_dev_close(struct rte_eth_dev *dev __rte_unused) { - uint32_t i; - - /* RX queues */ - for (i = 0; i < dev->data->nb_rx_queues; i++) - rte_ring_free((struct rte_ring *)dev->data->rx_queues[i]); - - /* TX queues */ - for (i = 0; i < dev->data->nb_tx_queues; i++) - rte_ring_free((struct rte_ring *)dev->data->tx_queues[i]); + return; } static int @@ -165,6 +204,21 @@ pmd_link_update(struct rte_eth_dev *dev __rte_unused, return 0; } +static int +pmd_filter_ctrl(struct rte_eth_dev *dev __rte_unused, + enum rte_filter_type filter_type, + enum rte_filter_op filter_op, + void *arg) +{ + if (filter_type == RTE_ETH_FILTER_GENERIC && + filter_op == RTE_ETH_FILTER_GET) { + *(const void **)arg = &pmd_flow_ops; + return 0; + } + + return -ENOTSUP; +} + static int pmd_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg) { @@ -182,6 +236,7 @@ static const struct eth_dev_ops pmd_ops = { .dev_infos_get = pmd_dev_infos_get, .rx_queue_setup = pmd_rx_queue_setup, .tx_queue_setup = pmd_tx_queue_setup, + .filter_ctrl = pmd_filter_ctrl, .tm_ops_get = pmd_tm_ops_get, }; @@ -207,12 +262,6 @@ pmd_tx_pkt_burst(void *txq, NULL); } -int -rte_pmd_softnic_run(uint16_t port_id __rte_unused) -{ - return 0; -} - static void * pmd_init(struct pmd_params *params) { @@ -230,10 +279,11 @@ pmd_init(struct pmd_params *params) memcpy(&p->params, params, sizeof(p->params)); /* Resources */ + tm_hierarchy_init(p); + softnic_mempool_init(p); softnic_swq_init(p); softnic_link_init(p); - tm_init(p); softnic_tmgr_init(p); softnic_tap_init(p); softnic_port_in_action_profile_init(p); @@ -246,6 +296,21 @@ pmd_init(struct pmd_params *params) return NULL; } + if (params->conn_port) { + struct softnic_conn_params conn_params; + + memcpy(&conn_params, &conn_params_default, sizeof(conn_params)); + conn_params.port = p->params.conn_port; + conn_params.msg_handle_arg = p; + + p->conn = softnic_conn_init(&conn_params); + if (p->conn == NULL) { + softnic_thread_free(p); + rte_free(p); + return NULL; + } + } + return p; } @@ -255,17 +320,21 @@ pmd_free(struct pmd_internals *p) if (p == NULL) return; + if (p->params.conn_port) + softnic_conn_free(p->conn); + softnic_thread_free(p); softnic_pipeline_free(p); softnic_table_action_profile_free(p); softnic_port_in_action_profile_free(p); softnic_tap_free(p); softnic_tmgr_free(p); - tm_free(p); softnic_link_free(p); softnic_swq_free(p); softnic_mempool_free(p); + tm_hierarchy_free(p); + rte_free(p); } @@ -333,6 +402,17 @@ get_uint32(const char *key __rte_unused, const char *value, void *extra_args) return 0; } +static int +get_uint16(const char *key __rte_unused, const char *value, void *extra_args) +{ + if (!value || !extra_args) + return -EINVAL; + + *(uint16_t *)extra_args = strtoull(value, NULL, 0); + + return 0; +} + static int pmd_parse_args(struct pmd_params *p, const char *params) { @@ -361,6 +441,14 @@ pmd_parse_args(struct pmd_params *p, const char *params) goto out_free; } + /* Connection listening port (optional) */ + if (rte_kvargs_count(kvlist, PMD_PARAM_CONN_PORT) == 1) { + ret = rte_kvargs_process(kvlist, PMD_PARAM_CONN_PORT, + &get_uint16, &p->conn_port); + if (ret < 0) + goto out_free; + } + /* CPU ID (optional) */ if (rte_kvargs_count(kvlist, PMD_PARAM_CPU_ID) == 1) { ret = rte_kvargs_process(kvlist, PMD_PARAM_CPU_ID, @@ -484,6 +572,7 @@ static struct rte_vdev_driver pmd_softnic_drv = { RTE_PMD_REGISTER_VDEV(net_softnic, pmd_softnic_drv); RTE_PMD_REGISTER_PARAM_STRING(net_softnic, PMD_PARAM_FIRMWARE "= " + PMD_PARAM_CONN_PORT "= " PMD_PARAM_CPU_ID "= " PMD_PARAM_TM_N_QUEUES "= " PMD_PARAM_TM_QSIZE0 "= " @@ -499,3 +588,22 @@ RTE_INIT(pmd_softnic_init_log) if (pmd_softnic_logtype >= 0) rte_log_set_level(pmd_softnic_logtype, RTE_LOG_NOTICE); } + +int +rte_pmd_softnic_manage(uint16_t port_id) +{ + struct rte_eth_dev *dev = &rte_eth_devices[port_id]; + struct pmd_internals *softnic; + +#ifdef RTE_LIBRTE_ETHDEV_DEBUG + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0); +#endif + + softnic = dev->data->dev_private; + + softnic_conn_poll_for_conn(softnic->conn); + + softnic_conn_poll_for_msg(softnic->conn); + + return 0; +}