1f7be70e5SJerin Jacob /* 2f7be70e5SJerin Jacob * BSD LICENSE 3f7be70e5SJerin Jacob * 4f7be70e5SJerin Jacob * Copyright (C) Cavium Inc. 2017. All rights reserved. 5f7be70e5SJerin Jacob * 6f7be70e5SJerin Jacob * Redistribution and use in source and binary forms, with or without 7f7be70e5SJerin Jacob * modification, are permitted provided that the following conditions 8f7be70e5SJerin Jacob * are met: 9f7be70e5SJerin Jacob * 10f7be70e5SJerin Jacob * * Redistributions of source code must retain the above copyright 11f7be70e5SJerin Jacob * notice, this list of conditions and the following disclaimer. 12f7be70e5SJerin Jacob * * Redistributions in binary form must reproduce the above copyright 13f7be70e5SJerin Jacob * notice, this list of conditions and the following disclaimer in 14f7be70e5SJerin Jacob * the documentation and/or other materials provided with the 15f7be70e5SJerin Jacob * distribution. 16f7be70e5SJerin Jacob * * Neither the name of Cavium networks nor the names of its 17f7be70e5SJerin Jacob * contributors may be used to endorse or promote products derived 18f7be70e5SJerin Jacob * from this software without specific prior written permission. 19f7be70e5SJerin Jacob * 20f7be70e5SJerin Jacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21f7be70e5SJerin Jacob * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22f7be70e5SJerin Jacob * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23f7be70e5SJerin Jacob * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24f7be70e5SJerin Jacob * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25f7be70e5SJerin Jacob * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26f7be70e5SJerin Jacob * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27f7be70e5SJerin Jacob * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28f7be70e5SJerin Jacob * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29f7be70e5SJerin Jacob * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30f7be70e5SJerin Jacob * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31f7be70e5SJerin Jacob */ 32f7be70e5SJerin Jacob #include <stdio.h> 33f7be70e5SJerin Jacob #include <stdarg.h> 34f7be70e5SJerin Jacob #include <stdbool.h> 35f7be70e5SJerin Jacob #include <stdint.h> 36f7be70e5SJerin Jacob #include <string.h> 37f7be70e5SJerin Jacob #include <unistd.h> 38f7be70e5SJerin Jacob 39f7be70e5SJerin Jacob #include <rte_alarm.h> 40f7be70e5SJerin Jacob #include <rte_branch_prediction.h> 41f7be70e5SJerin Jacob #include <rte_debug.h> 42f7be70e5SJerin Jacob #include <rte_devargs.h> 43f7be70e5SJerin Jacob #include <rte_dev.h> 44f7be70e5SJerin Jacob #include <rte_kvargs.h> 45f7be70e5SJerin Jacob #include <rte_malloc.h> 46f7be70e5SJerin Jacob #include <rte_prefetch.h> 47f7be70e5SJerin Jacob #include <rte_vdev.h> 48f7be70e5SJerin Jacob 49f7be70e5SJerin Jacob #include "octeontx_ethdev.h" 50f7be70e5SJerin Jacob #include "octeontx_logs.h" 51f7be70e5SJerin Jacob 52f7be70e5SJerin Jacob struct octeontx_vdev_init_params { 53f7be70e5SJerin Jacob uint8_t nr_port; 54f7be70e5SJerin Jacob }; 55f7be70e5SJerin Jacob 564fac7c0aSJerin Jacob enum octeontx_link_speed { 574fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_SGMII, 584fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_XAUI, 594fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_RXAUI, 604fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_10G_R, 614fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_40G_R, 624fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_RESERVE1, 634fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_QSGMII, 644fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_RESERVE2 654fac7c0aSJerin Jacob }; 664fac7c0aSJerin Jacob 67f7be70e5SJerin Jacob /* Parse integer from integer argument */ 68f7be70e5SJerin Jacob static int 69f7be70e5SJerin Jacob parse_integer_arg(const char *key __rte_unused, 70f7be70e5SJerin Jacob const char *value, void *extra_args) 71f7be70e5SJerin Jacob { 72f7be70e5SJerin Jacob int *i = (int *)extra_args; 73f7be70e5SJerin Jacob 74f7be70e5SJerin Jacob *i = atoi(value); 75f7be70e5SJerin Jacob if (*i < 0) { 76f7be70e5SJerin Jacob octeontx_log_err("argument has to be positive."); 77f7be70e5SJerin Jacob return -1; 78f7be70e5SJerin Jacob } 79f7be70e5SJerin Jacob 80f7be70e5SJerin Jacob return 0; 81f7be70e5SJerin Jacob } 82f7be70e5SJerin Jacob 83f7be70e5SJerin Jacob static int 84f7be70e5SJerin Jacob octeontx_parse_vdev_init_params(struct octeontx_vdev_init_params *params, 85f7be70e5SJerin Jacob struct rte_vdev_device *dev) 86f7be70e5SJerin Jacob { 87f7be70e5SJerin Jacob struct rte_kvargs *kvlist = NULL; 88f7be70e5SJerin Jacob int ret = 0; 89f7be70e5SJerin Jacob 90f7be70e5SJerin Jacob static const char * const octeontx_vdev_valid_params[] = { 91f7be70e5SJerin Jacob OCTEONTX_VDEV_NR_PORT_ARG, 92f7be70e5SJerin Jacob NULL 93f7be70e5SJerin Jacob }; 94f7be70e5SJerin Jacob 95f7be70e5SJerin Jacob const char *input_args = rte_vdev_device_args(dev); 96f7be70e5SJerin Jacob if (params == NULL) 97f7be70e5SJerin Jacob return -EINVAL; 98f7be70e5SJerin Jacob 99f7be70e5SJerin Jacob 100f7be70e5SJerin Jacob if (input_args) { 101f7be70e5SJerin Jacob kvlist = rte_kvargs_parse(input_args, 102f7be70e5SJerin Jacob octeontx_vdev_valid_params); 103f7be70e5SJerin Jacob if (kvlist == NULL) 104f7be70e5SJerin Jacob return -1; 105f7be70e5SJerin Jacob 106f7be70e5SJerin Jacob ret = rte_kvargs_process(kvlist, 107f7be70e5SJerin Jacob OCTEONTX_VDEV_NR_PORT_ARG, 108f7be70e5SJerin Jacob &parse_integer_arg, 109f7be70e5SJerin Jacob ¶ms->nr_port); 110f7be70e5SJerin Jacob if (ret < 0) 111f7be70e5SJerin Jacob goto free_kvlist; 112f7be70e5SJerin Jacob } 113f7be70e5SJerin Jacob 114f7be70e5SJerin Jacob free_kvlist: 115f7be70e5SJerin Jacob rte_kvargs_free(kvlist); 116f7be70e5SJerin Jacob return ret; 117f7be70e5SJerin Jacob } 118f7be70e5SJerin Jacob 119f18b146cSJerin Jacob static int 120f18b146cSJerin Jacob octeontx_port_open(struct octeontx_nic *nic) 121f18b146cSJerin Jacob { 122f18b146cSJerin Jacob octeontx_mbox_bgx_port_conf_t bgx_port_conf; 123f18b146cSJerin Jacob int res; 124f18b146cSJerin Jacob 125f18b146cSJerin Jacob res = 0; 126f18b146cSJerin Jacob 127f18b146cSJerin Jacob PMD_INIT_FUNC_TRACE(); 128f18b146cSJerin Jacob 129f18b146cSJerin Jacob res = octeontx_bgx_port_open(nic->port_id, &bgx_port_conf); 130f18b146cSJerin Jacob if (res < 0) { 131f18b146cSJerin Jacob octeontx_log_err("failed to open port %d", res); 132f18b146cSJerin Jacob return res; 133f18b146cSJerin Jacob } 134f18b146cSJerin Jacob 135f18b146cSJerin Jacob nic->node = bgx_port_conf.node; 136f18b146cSJerin Jacob nic->port_ena = bgx_port_conf.enable; 137f18b146cSJerin Jacob nic->base_ichan = bgx_port_conf.base_chan; 138f18b146cSJerin Jacob nic->base_ochan = bgx_port_conf.base_chan; 139f18b146cSJerin Jacob nic->num_ichans = bgx_port_conf.num_chans; 140f18b146cSJerin Jacob nic->num_ochans = bgx_port_conf.num_chans; 141f18b146cSJerin Jacob nic->mtu = bgx_port_conf.mtu; 142f18b146cSJerin Jacob nic->bpen = bgx_port_conf.bpen; 143f18b146cSJerin Jacob nic->fcs_strip = bgx_port_conf.fcs_strip; 144f18b146cSJerin Jacob nic->bcast_mode = bgx_port_conf.bcast_mode; 145f18b146cSJerin Jacob nic->mcast_mode = bgx_port_conf.mcast_mode; 146f18b146cSJerin Jacob nic->speed = bgx_port_conf.mode; 147f18b146cSJerin Jacob 148f18b146cSJerin Jacob memcpy(&nic->mac_addr[0], &bgx_port_conf.macaddr[0], ETHER_ADDR_LEN); 149f18b146cSJerin Jacob 150f18b146cSJerin Jacob octeontx_log_dbg("port opened %d", nic->port_id); 151f18b146cSJerin Jacob return res; 152f18b146cSJerin Jacob } 153f18b146cSJerin Jacob 154f18b146cSJerin Jacob static void 155f18b146cSJerin Jacob octeontx_port_close(struct octeontx_nic *nic) 156f18b146cSJerin Jacob { 157f18b146cSJerin Jacob PMD_INIT_FUNC_TRACE(); 158f18b146cSJerin Jacob 159f18b146cSJerin Jacob octeontx_bgx_port_close(nic->port_id); 160f18b146cSJerin Jacob octeontx_log_dbg("port closed %d", nic->port_id); 161f18b146cSJerin Jacob } 162f18b146cSJerin Jacob 1637fe7c98fSJerin Jacob static int 1647fe7c98fSJerin Jacob octeontx_port_stop(struct octeontx_nic *nic) 1657fe7c98fSJerin Jacob { 1667fe7c98fSJerin Jacob PMD_INIT_FUNC_TRACE(); 1677fe7c98fSJerin Jacob 1687fe7c98fSJerin Jacob return octeontx_bgx_port_stop(nic->port_id); 1697fe7c98fSJerin Jacob } 1707fe7c98fSJerin Jacob 17115bce35bSJerin Jacob static void 17215bce35bSJerin Jacob octeontx_port_promisc_set(struct octeontx_nic *nic, int en) 17315bce35bSJerin Jacob { 17415bce35bSJerin Jacob struct rte_eth_dev *dev; 17515bce35bSJerin Jacob int res; 17615bce35bSJerin Jacob 17715bce35bSJerin Jacob res = 0; 17815bce35bSJerin Jacob PMD_INIT_FUNC_TRACE(); 17915bce35bSJerin Jacob dev = nic->dev; 18015bce35bSJerin Jacob 18115bce35bSJerin Jacob res = octeontx_bgx_port_promisc_set(nic->port_id, en); 18215bce35bSJerin Jacob if (res < 0) 18315bce35bSJerin Jacob octeontx_log_err("failed to set promiscuous mode %d", 18415bce35bSJerin Jacob nic->port_id); 18515bce35bSJerin Jacob 18615bce35bSJerin Jacob /* Set proper flag for the mode */ 18715bce35bSJerin Jacob dev->data->promiscuous = (en != 0) ? 1 : 0; 18815bce35bSJerin Jacob 18915bce35bSJerin Jacob octeontx_log_dbg("port %d : promiscuous mode %s", 19015bce35bSJerin Jacob nic->port_id, en ? "set" : "unset"); 19115bce35bSJerin Jacob } 19215bce35bSJerin Jacob 19355389909SJerin Jacob static void 19455389909SJerin Jacob octeontx_port_stats(struct octeontx_nic *nic, struct rte_eth_stats *stats) 19555389909SJerin Jacob { 19655389909SJerin Jacob octeontx_mbox_bgx_port_stats_t bgx_stats; 19755389909SJerin Jacob int res; 19855389909SJerin Jacob 19955389909SJerin Jacob PMD_INIT_FUNC_TRACE(); 20055389909SJerin Jacob 20155389909SJerin Jacob res = octeontx_bgx_port_stats(nic->port_id, &bgx_stats); 20255389909SJerin Jacob if (res < 0) 20355389909SJerin Jacob octeontx_log_err("failed to get port stats %d", nic->port_id); 20455389909SJerin Jacob 20555389909SJerin Jacob stats->ipackets = bgx_stats.rx_packets; 20655389909SJerin Jacob stats->ibytes = bgx_stats.rx_bytes; 20755389909SJerin Jacob stats->imissed = bgx_stats.rx_dropped; 20855389909SJerin Jacob stats->ierrors = bgx_stats.rx_errors; 20955389909SJerin Jacob stats->opackets = bgx_stats.tx_packets; 21055389909SJerin Jacob stats->obytes = bgx_stats.tx_bytes; 21155389909SJerin Jacob stats->oerrors = bgx_stats.tx_errors; 21255389909SJerin Jacob 21355389909SJerin Jacob octeontx_log_dbg("port%d stats inpkts=%" PRIx64 " outpkts=%" PRIx64 "", 21455389909SJerin Jacob nic->port_id, stats->ipackets, stats->opackets); 21555389909SJerin Jacob } 21655389909SJerin Jacob 21755389909SJerin Jacob static void 21855389909SJerin Jacob octeontx_port_stats_clr(struct octeontx_nic *nic) 21955389909SJerin Jacob { 22055389909SJerin Jacob PMD_INIT_FUNC_TRACE(); 22155389909SJerin Jacob 22255389909SJerin Jacob octeontx_bgx_port_stats_clr(nic->port_id); 22355389909SJerin Jacob } 22455389909SJerin Jacob 225f7be70e5SJerin Jacob static inline void 226f7be70e5SJerin Jacob devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf, 227f7be70e5SJerin Jacob struct rte_event_dev_info *info) 228f7be70e5SJerin Jacob { 229f7be70e5SJerin Jacob memset(dev_conf, 0, sizeof(struct rte_event_dev_config)); 230f7be70e5SJerin Jacob dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns; 231f7be70e5SJerin Jacob 232f7be70e5SJerin Jacob dev_conf->nb_event_ports = info->max_event_ports; 233f7be70e5SJerin Jacob dev_conf->nb_event_queues = info->max_event_queues; 234f7be70e5SJerin Jacob 235f7be70e5SJerin Jacob dev_conf->nb_event_queue_flows = info->max_event_queue_flows; 236f7be70e5SJerin Jacob dev_conf->nb_event_port_dequeue_depth = 237f7be70e5SJerin Jacob info->max_event_port_dequeue_depth; 238f7be70e5SJerin Jacob dev_conf->nb_event_port_enqueue_depth = 239f7be70e5SJerin Jacob info->max_event_port_enqueue_depth; 240f7be70e5SJerin Jacob dev_conf->nb_event_port_enqueue_depth = 241f7be70e5SJerin Jacob info->max_event_port_enqueue_depth; 242f7be70e5SJerin Jacob dev_conf->nb_events_limit = 243f7be70e5SJerin Jacob info->max_num_events; 244f7be70e5SJerin Jacob } 245f7be70e5SJerin Jacob 2467742c55aSJerin Jacob static int 2477742c55aSJerin Jacob octeontx_dev_configure(struct rte_eth_dev *dev) 2487742c55aSJerin Jacob { 2497742c55aSJerin Jacob struct rte_eth_dev_data *data = dev->data; 2507742c55aSJerin Jacob struct rte_eth_conf *conf = &data->dev_conf; 2517742c55aSJerin Jacob struct rte_eth_rxmode *rxmode = &conf->rxmode; 2527742c55aSJerin Jacob struct rte_eth_txmode *txmode = &conf->txmode; 2537742c55aSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 2547742c55aSJerin Jacob int ret; 2557742c55aSJerin Jacob 2567742c55aSJerin Jacob PMD_INIT_FUNC_TRACE(); 2577742c55aSJerin Jacob RTE_SET_USED(conf); 2587742c55aSJerin Jacob 2597742c55aSJerin Jacob if (!rte_eal_has_hugepages()) { 2607742c55aSJerin Jacob octeontx_log_err("huge page is not configured"); 2617742c55aSJerin Jacob return -EINVAL; 2627742c55aSJerin Jacob } 2637742c55aSJerin Jacob 2647742c55aSJerin Jacob if (txmode->mq_mode) { 2657742c55aSJerin Jacob octeontx_log_err("tx mq_mode DCB or VMDq not supported"); 2667742c55aSJerin Jacob return -EINVAL; 2677742c55aSJerin Jacob } 2687742c55aSJerin Jacob 2697742c55aSJerin Jacob if (rxmode->mq_mode != ETH_MQ_RX_NONE && 2707742c55aSJerin Jacob rxmode->mq_mode != ETH_MQ_RX_RSS) { 2717742c55aSJerin Jacob octeontx_log_err("unsupported rx qmode %d", rxmode->mq_mode); 2727742c55aSJerin Jacob return -EINVAL; 2737742c55aSJerin Jacob } 2747742c55aSJerin Jacob 2757742c55aSJerin Jacob if (!rxmode->hw_strip_crc) { 2767742c55aSJerin Jacob PMD_INIT_LOG(NOTICE, "can't disable hw crc strip"); 2777742c55aSJerin Jacob rxmode->hw_strip_crc = 1; 2787742c55aSJerin Jacob } 2797742c55aSJerin Jacob 2807742c55aSJerin Jacob if (rxmode->hw_ip_checksum) { 2817742c55aSJerin Jacob PMD_INIT_LOG(NOTICE, "rxcksum not supported"); 2827742c55aSJerin Jacob rxmode->hw_ip_checksum = 0; 2837742c55aSJerin Jacob } 2847742c55aSJerin Jacob 2857742c55aSJerin Jacob if (rxmode->split_hdr_size) { 2867742c55aSJerin Jacob octeontx_log_err("rxmode does not support split header"); 2877742c55aSJerin Jacob return -EINVAL; 2887742c55aSJerin Jacob } 2897742c55aSJerin Jacob 2907742c55aSJerin Jacob if (rxmode->hw_vlan_filter) { 2917742c55aSJerin Jacob octeontx_log_err("VLAN filter not supported"); 2927742c55aSJerin Jacob return -EINVAL; 2937742c55aSJerin Jacob } 2947742c55aSJerin Jacob 2957742c55aSJerin Jacob if (rxmode->hw_vlan_extend) { 2967742c55aSJerin Jacob octeontx_log_err("VLAN extended not supported"); 2977742c55aSJerin Jacob return -EINVAL; 2987742c55aSJerin Jacob } 2997742c55aSJerin Jacob 3007742c55aSJerin Jacob if (rxmode->enable_lro) { 3017742c55aSJerin Jacob octeontx_log_err("LRO not supported"); 3027742c55aSJerin Jacob return -EINVAL; 3037742c55aSJerin Jacob } 3047742c55aSJerin Jacob 3057742c55aSJerin Jacob if (conf->link_speeds & ETH_LINK_SPEED_FIXED) { 3067742c55aSJerin Jacob octeontx_log_err("setting link speed/duplex not supported"); 3077742c55aSJerin Jacob return -EINVAL; 3087742c55aSJerin Jacob } 3097742c55aSJerin Jacob 3107742c55aSJerin Jacob if (conf->dcb_capability_en) { 3117742c55aSJerin Jacob octeontx_log_err("DCB enable not supported"); 3127742c55aSJerin Jacob return -EINVAL; 3137742c55aSJerin Jacob } 3147742c55aSJerin Jacob 3157742c55aSJerin Jacob if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) { 3167742c55aSJerin Jacob octeontx_log_err("flow director not supported"); 3177742c55aSJerin Jacob return -EINVAL; 3187742c55aSJerin Jacob } 3197742c55aSJerin Jacob 3207742c55aSJerin Jacob nic->num_tx_queues = dev->data->nb_tx_queues; 3217742c55aSJerin Jacob 3227742c55aSJerin Jacob ret = octeontx_pko_channel_open(nic->port_id * PKO_VF_NUM_DQ, 3237742c55aSJerin Jacob nic->num_tx_queues, 3247742c55aSJerin Jacob nic->base_ochan); 3257742c55aSJerin Jacob if (ret) { 3267742c55aSJerin Jacob octeontx_log_err("failed to open channel %d no-of-txq %d", 3277742c55aSJerin Jacob nic->base_ochan, nic->num_tx_queues); 3287742c55aSJerin Jacob return -EFAULT; 3297742c55aSJerin Jacob } 3307742c55aSJerin Jacob 3317742c55aSJerin Jacob nic->pki.classifier_enable = false; 3327742c55aSJerin Jacob nic->pki.hash_enable = true; 3337742c55aSJerin Jacob nic->pki.initialized = false; 3347742c55aSJerin Jacob 3357742c55aSJerin Jacob return 0; 3367742c55aSJerin Jacob } 3377742c55aSJerin Jacob 33815bce35bSJerin Jacob static void 33915bce35bSJerin Jacob octeontx_dev_promisc_enable(struct rte_eth_dev *dev) 34015bce35bSJerin Jacob { 34115bce35bSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 34215bce35bSJerin Jacob 34315bce35bSJerin Jacob PMD_INIT_FUNC_TRACE(); 34415bce35bSJerin Jacob octeontx_port_promisc_set(nic, 1); 34515bce35bSJerin Jacob } 34615bce35bSJerin Jacob 34715bce35bSJerin Jacob static void 34815bce35bSJerin Jacob octeontx_dev_promisc_disable(struct rte_eth_dev *dev) 34915bce35bSJerin Jacob { 35015bce35bSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 35115bce35bSJerin Jacob 35215bce35bSJerin Jacob PMD_INIT_FUNC_TRACE(); 35315bce35bSJerin Jacob octeontx_port_promisc_set(nic, 0); 35415bce35bSJerin Jacob } 35515bce35bSJerin Jacob 3564fac7c0aSJerin Jacob static inline int 3574fac7c0aSJerin Jacob octeontx_atomic_write_link_status(struct rte_eth_dev *dev, 3584fac7c0aSJerin Jacob struct rte_eth_link *link) 3594fac7c0aSJerin Jacob { 3604fac7c0aSJerin Jacob struct rte_eth_link *dst = &dev->data->dev_link; 3614fac7c0aSJerin Jacob struct rte_eth_link *src = link; 3624fac7c0aSJerin Jacob 3634fac7c0aSJerin Jacob if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst, 3644fac7c0aSJerin Jacob *(uint64_t *)src) == 0) 3654fac7c0aSJerin Jacob return -1; 3664fac7c0aSJerin Jacob 3674fac7c0aSJerin Jacob return 0; 3684fac7c0aSJerin Jacob } 3694fac7c0aSJerin Jacob 3704fac7c0aSJerin Jacob static int 3714fac7c0aSJerin Jacob octeontx_port_link_status(struct octeontx_nic *nic) 3724fac7c0aSJerin Jacob { 3734fac7c0aSJerin Jacob int res; 3744fac7c0aSJerin Jacob 3754fac7c0aSJerin Jacob PMD_INIT_FUNC_TRACE(); 3764fac7c0aSJerin Jacob res = octeontx_bgx_port_link_status(nic->port_id); 3774fac7c0aSJerin Jacob if (res < 0) { 3784fac7c0aSJerin Jacob octeontx_log_err("failed to get port %d link status", 3794fac7c0aSJerin Jacob nic->port_id); 3804fac7c0aSJerin Jacob return res; 3814fac7c0aSJerin Jacob } 3824fac7c0aSJerin Jacob 3834fac7c0aSJerin Jacob nic->link_up = (uint8_t)res; 3844fac7c0aSJerin Jacob octeontx_log_dbg("port %d link status %d", nic->port_id, nic->link_up); 3854fac7c0aSJerin Jacob 3864fac7c0aSJerin Jacob return res; 3874fac7c0aSJerin Jacob } 3884fac7c0aSJerin Jacob 3894fac7c0aSJerin Jacob /* 3904fac7c0aSJerin Jacob * Return 0 means link status changed, -1 means not changed 3914fac7c0aSJerin Jacob */ 3924fac7c0aSJerin Jacob static int 3934fac7c0aSJerin Jacob octeontx_dev_link_update(struct rte_eth_dev *dev, 3944fac7c0aSJerin Jacob int wait_to_complete __rte_unused) 3954fac7c0aSJerin Jacob { 3964fac7c0aSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 3974fac7c0aSJerin Jacob struct rte_eth_link link; 3984fac7c0aSJerin Jacob int res; 3994fac7c0aSJerin Jacob 4004fac7c0aSJerin Jacob res = 0; 4014fac7c0aSJerin Jacob PMD_INIT_FUNC_TRACE(); 4024fac7c0aSJerin Jacob 4034fac7c0aSJerin Jacob res = octeontx_port_link_status(nic); 4044fac7c0aSJerin Jacob if (res < 0) { 4054fac7c0aSJerin Jacob octeontx_log_err("failed to request link status %d", res); 4064fac7c0aSJerin Jacob return res; 4074fac7c0aSJerin Jacob } 4084fac7c0aSJerin Jacob 4094fac7c0aSJerin Jacob link.link_status = nic->link_up; 4104fac7c0aSJerin Jacob 4114fac7c0aSJerin Jacob switch (nic->speed) { 4124fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_SGMII: 4134fac7c0aSJerin Jacob link.link_speed = ETH_SPEED_NUM_1G; 4144fac7c0aSJerin Jacob break; 4154fac7c0aSJerin Jacob 4164fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_XAUI: 4174fac7c0aSJerin Jacob link.link_speed = ETH_SPEED_NUM_10G; 4184fac7c0aSJerin Jacob break; 4194fac7c0aSJerin Jacob 4204fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_RXAUI: 4214fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_10G_R: 4224fac7c0aSJerin Jacob link.link_speed = ETH_SPEED_NUM_10G; 4234fac7c0aSJerin Jacob break; 4244fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_QSGMII: 4254fac7c0aSJerin Jacob link.link_speed = ETH_SPEED_NUM_5G; 4264fac7c0aSJerin Jacob break; 4274fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_40G_R: 4284fac7c0aSJerin Jacob link.link_speed = ETH_SPEED_NUM_40G; 4294fac7c0aSJerin Jacob break; 4304fac7c0aSJerin Jacob 4314fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_RESERVE1: 4324fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_RESERVE2: 4334fac7c0aSJerin Jacob default: 4344fac7c0aSJerin Jacob octeontx_log_err("incorrect link speed %d", nic->speed); 4354fac7c0aSJerin Jacob break; 4364fac7c0aSJerin Jacob } 4374fac7c0aSJerin Jacob 4384fac7c0aSJerin Jacob link.link_duplex = ETH_LINK_AUTONEG; 4394fac7c0aSJerin Jacob link.link_autoneg = ETH_LINK_SPEED_AUTONEG; 4404fac7c0aSJerin Jacob 4414fac7c0aSJerin Jacob return octeontx_atomic_write_link_status(dev, &link); 4424fac7c0aSJerin Jacob } 4434fac7c0aSJerin Jacob 4447c0347a2SJerin Jacob static void 44555389909SJerin Jacob octeontx_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) 44655389909SJerin Jacob { 44755389909SJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 44855389909SJerin Jacob 44955389909SJerin Jacob PMD_INIT_FUNC_TRACE(); 45055389909SJerin Jacob octeontx_port_stats(nic, stats); 45155389909SJerin Jacob } 45255389909SJerin Jacob 45355389909SJerin Jacob static void 45455389909SJerin Jacob octeontx_dev_stats_reset(struct rte_eth_dev *dev) 45555389909SJerin Jacob { 45655389909SJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 45755389909SJerin Jacob 45855389909SJerin Jacob PMD_INIT_FUNC_TRACE(); 45955389909SJerin Jacob octeontx_port_stats_clr(nic); 46055389909SJerin Jacob } 46155389909SJerin Jacob 46255389909SJerin Jacob static void 463ef7308fcSJerin Jacob octeontx_dev_default_mac_addr_set(struct rte_eth_dev *dev, 464ef7308fcSJerin Jacob struct ether_addr *addr) 465ef7308fcSJerin Jacob { 466ef7308fcSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 467ef7308fcSJerin Jacob int ret; 468ef7308fcSJerin Jacob 469ef7308fcSJerin Jacob ret = octeontx_bgx_port_mac_set(nic->port_id, addr->addr_bytes); 470ef7308fcSJerin Jacob if (ret != 0) 471ef7308fcSJerin Jacob octeontx_log_err("failed to set MAC address on port %d", 472ef7308fcSJerin Jacob nic->port_id); 473ef7308fcSJerin Jacob } 474ef7308fcSJerin Jacob 475ef7308fcSJerin Jacob static void 4767c0347a2SJerin Jacob octeontx_dev_info(struct rte_eth_dev *dev, 4777c0347a2SJerin Jacob struct rte_eth_dev_info *dev_info) 4787c0347a2SJerin Jacob { 4797c0347a2SJerin Jacob RTE_SET_USED(dev); 4807c0347a2SJerin Jacob 4817c0347a2SJerin Jacob /* Autonegotiation may be disabled */ 4827c0347a2SJerin Jacob dev_info->speed_capa = ETH_LINK_SPEED_FIXED; 4837c0347a2SJerin Jacob dev_info->speed_capa |= ETH_LINK_SPEED_10M | ETH_LINK_SPEED_100M | 4847c0347a2SJerin Jacob ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G | 4857c0347a2SJerin Jacob ETH_LINK_SPEED_40G; 4867c0347a2SJerin Jacob 4877c0347a2SJerin Jacob dev_info->driver_name = RTE_STR(rte_octeontx_pmd); 4887c0347a2SJerin Jacob dev_info->max_mac_addrs = 1; 4897c0347a2SJerin Jacob dev_info->max_rx_pktlen = PKI_MAX_PKTLEN; 4907c0347a2SJerin Jacob dev_info->max_rx_queues = 1; 4917c0347a2SJerin Jacob dev_info->max_tx_queues = PKO_MAX_NUM_DQ; 4927c0347a2SJerin Jacob dev_info->min_rx_bufsize = 0; 4937c0347a2SJerin Jacob dev_info->pci_dev = NULL; 4947c0347a2SJerin Jacob 4957c0347a2SJerin Jacob dev_info->default_rxconf = (struct rte_eth_rxconf) { 4967c0347a2SJerin Jacob .rx_free_thresh = 0, 4977c0347a2SJerin Jacob .rx_drop_en = 0, 4987c0347a2SJerin Jacob }; 4997c0347a2SJerin Jacob 5007c0347a2SJerin Jacob dev_info->default_txconf = (struct rte_eth_txconf) { 5017c0347a2SJerin Jacob .tx_free_thresh = 0, 5027c0347a2SJerin Jacob .txq_flags = 5037c0347a2SJerin Jacob ETH_TXQ_FLAGS_NOMULTSEGS | 5047c0347a2SJerin Jacob ETH_TXQ_FLAGS_NOOFFLOADS | 5057c0347a2SJerin Jacob ETH_TXQ_FLAGS_NOXSUMS, 5067c0347a2SJerin Jacob }; 5077c0347a2SJerin Jacob 5087c0347a2SJerin Jacob dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MT_LOCKFREE; 5097c0347a2SJerin Jacob } 5107c0347a2SJerin Jacob 5117fe7c98fSJerin Jacob static void 5127fe7c98fSJerin Jacob octeontx_dq_info_getter(octeontx_dq_t *dq, void *out) 5137fe7c98fSJerin Jacob { 5147fe7c98fSJerin Jacob ((octeontx_dq_t *)out)->lmtline_va = dq->lmtline_va; 5157fe7c98fSJerin Jacob ((octeontx_dq_t *)out)->ioreg_va = dq->ioreg_va; 5167fe7c98fSJerin Jacob ((octeontx_dq_t *)out)->fc_status_va = dq->fc_status_va; 5177fe7c98fSJerin Jacob } 5187fe7c98fSJerin Jacob 5197fe7c98fSJerin Jacob static int 5207fe7c98fSJerin Jacob octeontx_vf_start_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic, 5217fe7c98fSJerin Jacob uint16_t qidx) 5227fe7c98fSJerin Jacob { 5237fe7c98fSJerin Jacob struct octeontx_txq *txq; 5247fe7c98fSJerin Jacob int res; 5257fe7c98fSJerin Jacob 5267fe7c98fSJerin Jacob PMD_INIT_FUNC_TRACE(); 5277fe7c98fSJerin Jacob 5287fe7c98fSJerin Jacob if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED) 5297fe7c98fSJerin Jacob return 0; 5307fe7c98fSJerin Jacob 5317fe7c98fSJerin Jacob txq = dev->data->tx_queues[qidx]; 5327fe7c98fSJerin Jacob 5337fe7c98fSJerin Jacob res = octeontx_pko_channel_query_dqs(nic->base_ochan, 5347fe7c98fSJerin Jacob &txq->dq, 5357fe7c98fSJerin Jacob sizeof(octeontx_dq_t), 5367fe7c98fSJerin Jacob txq->queue_id, 5377fe7c98fSJerin Jacob octeontx_dq_info_getter); 5387fe7c98fSJerin Jacob if (res < 0) { 5397fe7c98fSJerin Jacob res = -EFAULT; 5407fe7c98fSJerin Jacob goto close_port; 5417fe7c98fSJerin Jacob } 5427fe7c98fSJerin Jacob 5437fe7c98fSJerin Jacob dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED; 5447fe7c98fSJerin Jacob return res; 5457fe7c98fSJerin Jacob 5467fe7c98fSJerin Jacob close_port: 5477fe7c98fSJerin Jacob (void)octeontx_port_stop(nic); 5487fe7c98fSJerin Jacob octeontx_pko_channel_stop(nic->base_ochan); 5497fe7c98fSJerin Jacob octeontx_pko_channel_close(nic->base_ochan); 5507fe7c98fSJerin Jacob dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED; 5517fe7c98fSJerin Jacob return res; 5527fe7c98fSJerin Jacob } 5537fe7c98fSJerin Jacob 5547fe7c98fSJerin Jacob static int 5557fe7c98fSJerin Jacob octeontx_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx) 5567fe7c98fSJerin Jacob { 5577fe7c98fSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 5587fe7c98fSJerin Jacob 5597fe7c98fSJerin Jacob PMD_INIT_FUNC_TRACE(); 5607fe7c98fSJerin Jacob qidx = qidx % PKO_VF_NUM_DQ; 5617fe7c98fSJerin Jacob return octeontx_vf_start_tx_queue(dev, nic, qidx); 5627fe7c98fSJerin Jacob } 5637fe7c98fSJerin Jacob 5647fe7c98fSJerin Jacob static inline int 5657fe7c98fSJerin Jacob octeontx_vf_stop_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic, 5667fe7c98fSJerin Jacob uint16_t qidx) 5677fe7c98fSJerin Jacob { 5687fe7c98fSJerin Jacob int ret = 0; 5697fe7c98fSJerin Jacob 5707fe7c98fSJerin Jacob RTE_SET_USED(nic); 5717fe7c98fSJerin Jacob PMD_INIT_FUNC_TRACE(); 5727fe7c98fSJerin Jacob 5737fe7c98fSJerin Jacob if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED) 5747fe7c98fSJerin Jacob return 0; 5757fe7c98fSJerin Jacob 5767fe7c98fSJerin Jacob dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED; 5777fe7c98fSJerin Jacob return ret; 5787fe7c98fSJerin Jacob } 5797fe7c98fSJerin Jacob 5807fe7c98fSJerin Jacob static int 5817fe7c98fSJerin Jacob octeontx_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx) 5827fe7c98fSJerin Jacob { 5837fe7c98fSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 5847fe7c98fSJerin Jacob 5857fe7c98fSJerin Jacob PMD_INIT_FUNC_TRACE(); 5867fe7c98fSJerin Jacob qidx = qidx % PKO_VF_NUM_DQ; 5877fe7c98fSJerin Jacob 5887fe7c98fSJerin Jacob return octeontx_vf_stop_tx_queue(dev, nic, qidx); 5897fe7c98fSJerin Jacob } 5907fe7c98fSJerin Jacob 591*150cbc84SJerin Jacob static void 592*150cbc84SJerin Jacob octeontx_dev_tx_queue_release(void *tx_queue) 593*150cbc84SJerin Jacob { 594*150cbc84SJerin Jacob struct octeontx_txq *txq = tx_queue; 595*150cbc84SJerin Jacob int res; 596*150cbc84SJerin Jacob 597*150cbc84SJerin Jacob PMD_INIT_FUNC_TRACE(); 598*150cbc84SJerin Jacob 599*150cbc84SJerin Jacob if (txq) { 600*150cbc84SJerin Jacob res = octeontx_dev_tx_queue_stop(txq->eth_dev, txq->queue_id); 601*150cbc84SJerin Jacob if (res < 0) 602*150cbc84SJerin Jacob octeontx_log_err("failed stop tx_queue(%d)\n", 603*150cbc84SJerin Jacob txq->queue_id); 604*150cbc84SJerin Jacob 605*150cbc84SJerin Jacob rte_free(txq); 606*150cbc84SJerin Jacob } 607*150cbc84SJerin Jacob } 608*150cbc84SJerin Jacob 609*150cbc84SJerin Jacob static int 610*150cbc84SJerin Jacob octeontx_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx, 611*150cbc84SJerin Jacob uint16_t nb_desc, unsigned int socket_id, 612*150cbc84SJerin Jacob const struct rte_eth_txconf *tx_conf) 613*150cbc84SJerin Jacob { 614*150cbc84SJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 615*150cbc84SJerin Jacob struct octeontx_txq *txq = NULL; 616*150cbc84SJerin Jacob uint16_t dq_num; 617*150cbc84SJerin Jacob int res = 0; 618*150cbc84SJerin Jacob 619*150cbc84SJerin Jacob RTE_SET_USED(nb_desc); 620*150cbc84SJerin Jacob RTE_SET_USED(socket_id); 621*150cbc84SJerin Jacob RTE_SET_USED(tx_conf); 622*150cbc84SJerin Jacob 623*150cbc84SJerin Jacob dq_num = (nic->port_id * PKO_VF_NUM_DQ) + qidx; 624*150cbc84SJerin Jacob 625*150cbc84SJerin Jacob /* Socket id check */ 626*150cbc84SJerin Jacob if (socket_id != (unsigned int)SOCKET_ID_ANY && 627*150cbc84SJerin Jacob socket_id != (unsigned int)nic->node) 628*150cbc84SJerin Jacob PMD_TX_LOG(INFO, "socket_id expected %d, configured %d", 629*150cbc84SJerin Jacob socket_id, nic->node); 630*150cbc84SJerin Jacob 631*150cbc84SJerin Jacob /* Free memory prior to re-allocation if needed. */ 632*150cbc84SJerin Jacob if (dev->data->tx_queues[qidx] != NULL) { 633*150cbc84SJerin Jacob PMD_TX_LOG(DEBUG, "freeing memory prior to re-allocation %d", 634*150cbc84SJerin Jacob qidx); 635*150cbc84SJerin Jacob octeontx_dev_tx_queue_release(dev->data->tx_queues[qidx]); 636*150cbc84SJerin Jacob dev->data->tx_queues[qidx] = NULL; 637*150cbc84SJerin Jacob } 638*150cbc84SJerin Jacob 639*150cbc84SJerin Jacob /* Allocating tx queue data structure */ 640*150cbc84SJerin Jacob txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct octeontx_txq), 641*150cbc84SJerin Jacob RTE_CACHE_LINE_SIZE, nic->node); 642*150cbc84SJerin Jacob if (txq == NULL) { 643*150cbc84SJerin Jacob octeontx_log_err("failed to allocate txq=%d", qidx); 644*150cbc84SJerin Jacob res = -ENOMEM; 645*150cbc84SJerin Jacob goto err; 646*150cbc84SJerin Jacob } 647*150cbc84SJerin Jacob 648*150cbc84SJerin Jacob txq->eth_dev = dev; 649*150cbc84SJerin Jacob txq->queue_id = dq_num; 650*150cbc84SJerin Jacob dev->data->tx_queues[qidx] = txq; 651*150cbc84SJerin Jacob dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED; 652*150cbc84SJerin Jacob 653*150cbc84SJerin Jacob res = octeontx_pko_channel_query_dqs(nic->base_ochan, 654*150cbc84SJerin Jacob &txq->dq, 655*150cbc84SJerin Jacob sizeof(octeontx_dq_t), 656*150cbc84SJerin Jacob txq->queue_id, 657*150cbc84SJerin Jacob octeontx_dq_info_getter); 658*150cbc84SJerin Jacob if (res < 0) { 659*150cbc84SJerin Jacob res = -EFAULT; 660*150cbc84SJerin Jacob goto err; 661*150cbc84SJerin Jacob } 662*150cbc84SJerin Jacob 663*150cbc84SJerin Jacob PMD_TX_LOG(DEBUG, "[%d]:[%d] txq=%p nb_desc=%d lmtline=%p ioreg_va=%p fc_status_va=%p", 664*150cbc84SJerin Jacob qidx, txq->queue_id, txq, nb_desc, txq->dq.lmtline_va, 665*150cbc84SJerin Jacob txq->dq.ioreg_va, 666*150cbc84SJerin Jacob txq->dq.fc_status_va); 667*150cbc84SJerin Jacob 668*150cbc84SJerin Jacob return res; 669*150cbc84SJerin Jacob 670*150cbc84SJerin Jacob err: 671*150cbc84SJerin Jacob if (txq) 672*150cbc84SJerin Jacob rte_free(txq); 673*150cbc84SJerin Jacob 674*150cbc84SJerin Jacob return res; 675*150cbc84SJerin Jacob } 676*150cbc84SJerin Jacob 677197438eeSJerin Jacob static int 678197438eeSJerin Jacob octeontx_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx, 679197438eeSJerin Jacob uint16_t nb_desc, unsigned int socket_id, 680197438eeSJerin Jacob const struct rte_eth_rxconf *rx_conf, 681197438eeSJerin Jacob struct rte_mempool *mb_pool) 682197438eeSJerin Jacob { 683197438eeSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 684197438eeSJerin Jacob struct rte_mempool_ops *mp_ops = NULL; 685197438eeSJerin Jacob struct octeontx_rxq *rxq = NULL; 686197438eeSJerin Jacob pki_pktbuf_cfg_t pktbuf_conf; 687197438eeSJerin Jacob pki_hash_cfg_t pki_hash; 688197438eeSJerin Jacob pki_qos_cfg_t pki_qos; 689197438eeSJerin Jacob uintptr_t pool; 690197438eeSJerin Jacob int ret, port; 691197438eeSJerin Jacob uint8_t gaura; 692197438eeSJerin Jacob unsigned int ev_queues = (nic->ev_queues * nic->port_id) + qidx; 693197438eeSJerin Jacob unsigned int ev_ports = (nic->ev_ports * nic->port_id) + qidx; 694197438eeSJerin Jacob 695197438eeSJerin Jacob RTE_SET_USED(nb_desc); 696197438eeSJerin Jacob 697197438eeSJerin Jacob memset(&pktbuf_conf, 0, sizeof(pktbuf_conf)); 698197438eeSJerin Jacob memset(&pki_hash, 0, sizeof(pki_hash)); 699197438eeSJerin Jacob memset(&pki_qos, 0, sizeof(pki_qos)); 700197438eeSJerin Jacob 701197438eeSJerin Jacob mp_ops = rte_mempool_get_ops(mb_pool->ops_index); 702197438eeSJerin Jacob if (strcmp(mp_ops->name, "octeontx_fpavf")) { 703197438eeSJerin Jacob octeontx_log_err("failed to find octeontx_fpavf mempool"); 704197438eeSJerin Jacob return -ENOTSUP; 705197438eeSJerin Jacob } 706197438eeSJerin Jacob 707197438eeSJerin Jacob /* Handle forbidden configurations */ 708197438eeSJerin Jacob if (nic->pki.classifier_enable) { 709197438eeSJerin Jacob octeontx_log_err("cannot setup queue %d. " 710197438eeSJerin Jacob "Classifier option unsupported", qidx); 711197438eeSJerin Jacob return -EINVAL; 712197438eeSJerin Jacob } 713197438eeSJerin Jacob 714197438eeSJerin Jacob port = nic->port_id; 715197438eeSJerin Jacob 716197438eeSJerin Jacob /* Rx deferred start is not supported */ 717197438eeSJerin Jacob if (rx_conf->rx_deferred_start) { 718197438eeSJerin Jacob octeontx_log_err("rx deferred start not supported"); 719197438eeSJerin Jacob return -EINVAL; 720197438eeSJerin Jacob } 721197438eeSJerin Jacob 722197438eeSJerin Jacob /* Verify queue index */ 723197438eeSJerin Jacob if (qidx >= dev->data->nb_rx_queues) { 724197438eeSJerin Jacob octeontx_log_err("QID %d not supporteded (0 - %d available)\n", 725197438eeSJerin Jacob qidx, (dev->data->nb_rx_queues - 1)); 726197438eeSJerin Jacob return -ENOTSUP; 727197438eeSJerin Jacob } 728197438eeSJerin Jacob 729197438eeSJerin Jacob /* Socket id check */ 730197438eeSJerin Jacob if (socket_id != (unsigned int)SOCKET_ID_ANY && 731197438eeSJerin Jacob socket_id != (unsigned int)nic->node) 732197438eeSJerin Jacob PMD_RX_LOG(INFO, "socket_id expected %d, configured %d", 733197438eeSJerin Jacob socket_id, nic->node); 734197438eeSJerin Jacob 735197438eeSJerin Jacob /* Allocating rx queue data structure */ 736197438eeSJerin Jacob rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct octeontx_rxq), 737197438eeSJerin Jacob RTE_CACHE_LINE_SIZE, nic->node); 738197438eeSJerin Jacob if (rxq == NULL) { 739197438eeSJerin Jacob octeontx_log_err("failed to allocate rxq=%d", qidx); 740197438eeSJerin Jacob return -ENOMEM; 741197438eeSJerin Jacob } 742197438eeSJerin Jacob 743197438eeSJerin Jacob if (!nic->pki.initialized) { 744197438eeSJerin Jacob pktbuf_conf.port_type = 0; 745197438eeSJerin Jacob pki_hash.port_type = 0; 746197438eeSJerin Jacob pki_qos.port_type = 0; 747197438eeSJerin Jacob 748197438eeSJerin Jacob pktbuf_conf.mmask.f_wqe_skip = 1; 749197438eeSJerin Jacob pktbuf_conf.mmask.f_first_skip = 1; 750197438eeSJerin Jacob pktbuf_conf.mmask.f_later_skip = 1; 751197438eeSJerin Jacob pktbuf_conf.mmask.f_mbuff_size = 1; 752197438eeSJerin Jacob pktbuf_conf.mmask.f_cache_mode = 1; 753197438eeSJerin Jacob 754197438eeSJerin Jacob pktbuf_conf.wqe_skip = OCTTX_PACKET_WQE_SKIP; 755197438eeSJerin Jacob pktbuf_conf.first_skip = OCTTX_PACKET_FIRST_SKIP; 756197438eeSJerin Jacob pktbuf_conf.later_skip = OCTTX_PACKET_LATER_SKIP; 757197438eeSJerin Jacob pktbuf_conf.mbuff_size = (mb_pool->elt_size - 758197438eeSJerin Jacob RTE_PKTMBUF_HEADROOM - 759197438eeSJerin Jacob sizeof(struct rte_mbuf)); 760197438eeSJerin Jacob 761197438eeSJerin Jacob pktbuf_conf.cache_mode = PKI_OPC_MODE_STF2_STT; 762197438eeSJerin Jacob 763197438eeSJerin Jacob ret = octeontx_pki_port_pktbuf_config(port, &pktbuf_conf); 764197438eeSJerin Jacob if (ret != 0) { 765197438eeSJerin Jacob octeontx_log_err("fail to configure pktbuf for port %d", 766197438eeSJerin Jacob port); 767197438eeSJerin Jacob rte_free(rxq); 768197438eeSJerin Jacob return ret; 769197438eeSJerin Jacob } 770197438eeSJerin Jacob PMD_RX_LOG(DEBUG, "Port %d Rx pktbuf configured:\n" 771197438eeSJerin Jacob "\tmbuf_size:\t0x%0x\n" 772197438eeSJerin Jacob "\twqe_skip:\t0x%0x\n" 773197438eeSJerin Jacob "\tfirst_skip:\t0x%0x\n" 774197438eeSJerin Jacob "\tlater_skip:\t0x%0x\n" 775197438eeSJerin Jacob "\tcache_mode:\t%s\n", 776197438eeSJerin Jacob port, 777197438eeSJerin Jacob pktbuf_conf.mbuff_size, 778197438eeSJerin Jacob pktbuf_conf.wqe_skip, 779197438eeSJerin Jacob pktbuf_conf.first_skip, 780197438eeSJerin Jacob pktbuf_conf.later_skip, 781197438eeSJerin Jacob (pktbuf_conf.cache_mode == 782197438eeSJerin Jacob PKI_OPC_MODE_STT) ? 783197438eeSJerin Jacob "STT" : 784197438eeSJerin Jacob (pktbuf_conf.cache_mode == 785197438eeSJerin Jacob PKI_OPC_MODE_STF) ? 786197438eeSJerin Jacob "STF" : 787197438eeSJerin Jacob (pktbuf_conf.cache_mode == 788197438eeSJerin Jacob PKI_OPC_MODE_STF1_STT) ? 789197438eeSJerin Jacob "STF1_STT" : "STF2_STT"); 790197438eeSJerin Jacob 791197438eeSJerin Jacob if (nic->pki.hash_enable) { 792197438eeSJerin Jacob pki_hash.tag_dlc = 1; 793197438eeSJerin Jacob pki_hash.tag_slc = 1; 794197438eeSJerin Jacob pki_hash.tag_dlf = 1; 795197438eeSJerin Jacob pki_hash.tag_slf = 1; 796197438eeSJerin Jacob octeontx_pki_port_hash_config(port, &pki_hash); 797197438eeSJerin Jacob } 798197438eeSJerin Jacob 799197438eeSJerin Jacob pool = (uintptr_t)mb_pool->pool_id; 800197438eeSJerin Jacob 801197438eeSJerin Jacob /* Get the gpool Id */ 802197438eeSJerin Jacob gaura = octeontx_fpa_bufpool_gpool(pool); 803197438eeSJerin Jacob 804197438eeSJerin Jacob pki_qos.qpg_qos = PKI_QPG_QOS_NONE; 805197438eeSJerin Jacob pki_qos.num_entry = 1; 806197438eeSJerin Jacob pki_qos.drop_policy = 0; 807197438eeSJerin Jacob pki_qos.tag_type = 2L; 808197438eeSJerin Jacob pki_qos.qos_entry[0].port_add = 0; 809197438eeSJerin Jacob pki_qos.qos_entry[0].gaura = gaura; 810197438eeSJerin Jacob pki_qos.qos_entry[0].ggrp_ok = ev_queues; 811197438eeSJerin Jacob pki_qos.qos_entry[0].ggrp_bad = ev_queues; 812197438eeSJerin Jacob pki_qos.qos_entry[0].grptag_bad = 0; 813197438eeSJerin Jacob pki_qos.qos_entry[0].grptag_ok = 0; 814197438eeSJerin Jacob 815197438eeSJerin Jacob ret = octeontx_pki_port_create_qos(port, &pki_qos); 816197438eeSJerin Jacob if (ret < 0) { 817197438eeSJerin Jacob octeontx_log_err("failed to create QOS port=%d, q=%d", 818197438eeSJerin Jacob port, qidx); 819197438eeSJerin Jacob rte_free(rxq); 820197438eeSJerin Jacob return ret; 821197438eeSJerin Jacob } 822197438eeSJerin Jacob nic->pki.initialized = true; 823197438eeSJerin Jacob } 824197438eeSJerin Jacob 825197438eeSJerin Jacob rxq->port_id = nic->port_id; 826197438eeSJerin Jacob rxq->eth_dev = dev; 827197438eeSJerin Jacob rxq->queue_id = qidx; 828197438eeSJerin Jacob rxq->evdev = nic->evdev; 829197438eeSJerin Jacob rxq->ev_queues = ev_queues; 830197438eeSJerin Jacob rxq->ev_ports = ev_ports; 831197438eeSJerin Jacob 832197438eeSJerin Jacob dev->data->rx_queues[qidx] = rxq; 833197438eeSJerin Jacob dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED; 834197438eeSJerin Jacob return 0; 835197438eeSJerin Jacob } 836197438eeSJerin Jacob 837197438eeSJerin Jacob static void 838197438eeSJerin Jacob octeontx_dev_rx_queue_release(void *rxq) 839197438eeSJerin Jacob { 840197438eeSJerin Jacob rte_free(rxq); 841197438eeSJerin Jacob } 842197438eeSJerin Jacob 843f18b146cSJerin Jacob /* Initialize and register driver with DPDK Application */ 844f18b146cSJerin Jacob static const struct eth_dev_ops octeontx_dev_ops = { 8457742c55aSJerin Jacob .dev_configure = octeontx_dev_configure, 8467c0347a2SJerin Jacob .dev_infos_get = octeontx_dev_info, 84715bce35bSJerin Jacob .promiscuous_enable = octeontx_dev_promisc_enable, 84815bce35bSJerin Jacob .promiscuous_disable = octeontx_dev_promisc_disable, 8494fac7c0aSJerin Jacob .link_update = octeontx_dev_link_update, 85055389909SJerin Jacob .stats_get = octeontx_dev_stats_get, 85155389909SJerin Jacob .stats_reset = octeontx_dev_stats_reset, 852ef7308fcSJerin Jacob .mac_addr_set = octeontx_dev_default_mac_addr_set, 8537fe7c98fSJerin Jacob .tx_queue_start = octeontx_dev_tx_queue_start, 8547fe7c98fSJerin Jacob .tx_queue_stop = octeontx_dev_tx_queue_stop, 855*150cbc84SJerin Jacob .tx_queue_setup = octeontx_dev_tx_queue_setup, 856*150cbc84SJerin Jacob .tx_queue_release = octeontx_dev_tx_queue_release, 857197438eeSJerin Jacob .rx_queue_setup = octeontx_dev_rx_queue_setup, 858197438eeSJerin Jacob .rx_queue_release = octeontx_dev_rx_queue_release, 859f18b146cSJerin Jacob }; 860f18b146cSJerin Jacob 861f7be70e5SJerin Jacob /* Create Ethdev interface per BGX LMAC ports */ 862f7be70e5SJerin Jacob static int 863f7be70e5SJerin Jacob octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev, 864f7be70e5SJerin Jacob int socket_id) 865f7be70e5SJerin Jacob { 866f18b146cSJerin Jacob int res; 867f18b146cSJerin Jacob char octtx_name[OCTEONTX_MAX_NAME_LEN]; 868f18b146cSJerin Jacob struct octeontx_nic *nic = NULL; 869f18b146cSJerin Jacob struct rte_eth_dev *eth_dev = NULL; 870f18b146cSJerin Jacob struct rte_eth_dev_data *data = NULL; 871f18b146cSJerin Jacob const char *name = rte_vdev_device_name(dev); 872f7be70e5SJerin Jacob 873f18b146cSJerin Jacob PMD_INIT_FUNC_TRACE(); 874f18b146cSJerin Jacob 875f18b146cSJerin Jacob sprintf(octtx_name, "%s_%d", name, port); 876f18b146cSJerin Jacob if (rte_eal_process_type() != RTE_PROC_PRIMARY) { 877f18b146cSJerin Jacob eth_dev = rte_eth_dev_attach_secondary(octtx_name); 878f18b146cSJerin Jacob if (eth_dev == NULL) 879f7be70e5SJerin Jacob return -ENODEV; 880f18b146cSJerin Jacob 881f18b146cSJerin Jacob return 0; 882f18b146cSJerin Jacob } 883f18b146cSJerin Jacob 884f18b146cSJerin Jacob data = rte_zmalloc_socket(octtx_name, sizeof(*data), 0, socket_id); 885f18b146cSJerin Jacob if (data == NULL) { 886f18b146cSJerin Jacob octeontx_log_err("failed to allocate devdata"); 887f18b146cSJerin Jacob res = -ENOMEM; 888f18b146cSJerin Jacob goto err; 889f18b146cSJerin Jacob } 890f18b146cSJerin Jacob 891f18b146cSJerin Jacob nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id); 892f18b146cSJerin Jacob if (nic == NULL) { 893f18b146cSJerin Jacob octeontx_log_err("failed to allocate nic structure"); 894f18b146cSJerin Jacob res = -ENOMEM; 895f18b146cSJerin Jacob goto err; 896f18b146cSJerin Jacob } 897f18b146cSJerin Jacob 898f18b146cSJerin Jacob nic->port_id = port; 899f18b146cSJerin Jacob nic->evdev = evdev; 900f18b146cSJerin Jacob 901f18b146cSJerin Jacob res = octeontx_port_open(nic); 902f18b146cSJerin Jacob if (res < 0) 903f18b146cSJerin Jacob goto err; 904f18b146cSJerin Jacob 905f18b146cSJerin Jacob /* Rx side port configuration */ 906f18b146cSJerin Jacob res = octeontx_pki_port_open(port); 907f18b146cSJerin Jacob if (res != 0) { 908f18b146cSJerin Jacob octeontx_log_err("failed to open PKI port %d", port); 909f18b146cSJerin Jacob res = -ENODEV; 910f18b146cSJerin Jacob goto err; 911f18b146cSJerin Jacob } 912f18b146cSJerin Jacob 913f18b146cSJerin Jacob /* Reserve an ethdev entry */ 914f18b146cSJerin Jacob eth_dev = rte_eth_dev_allocate(octtx_name); 915f18b146cSJerin Jacob if (eth_dev == NULL) { 916f18b146cSJerin Jacob octeontx_log_err("failed to allocate rte_eth_dev"); 917f18b146cSJerin Jacob res = -ENOMEM; 918f18b146cSJerin Jacob goto err; 919f18b146cSJerin Jacob } 920f18b146cSJerin Jacob 921f18b146cSJerin Jacob eth_dev->device = &dev->device; 922f18b146cSJerin Jacob eth_dev->intr_handle = NULL; 923f18b146cSJerin Jacob eth_dev->data->kdrv = RTE_KDRV_NONE; 924f18b146cSJerin Jacob eth_dev->data->numa_node = dev->device.numa_node; 925f18b146cSJerin Jacob 926f18b146cSJerin Jacob rte_memcpy(data, (eth_dev)->data, sizeof(*data)); 927f18b146cSJerin Jacob data->dev_private = nic; 928f18b146cSJerin Jacob 929f18b146cSJerin Jacob data->port_id = eth_dev->data->port_id; 930f18b146cSJerin Jacob snprintf(data->name, sizeof(data->name), "%s", eth_dev->data->name); 931f18b146cSJerin Jacob 932f18b146cSJerin Jacob nic->ev_queues = 1; 933f18b146cSJerin Jacob nic->ev_ports = 1; 934f18b146cSJerin Jacob 935f18b146cSJerin Jacob data->dev_link.link_status = ETH_LINK_DOWN; 936f18b146cSJerin Jacob data->dev_started = 0; 937f18b146cSJerin Jacob data->promiscuous = 0; 938f18b146cSJerin Jacob data->all_multicast = 0; 939f18b146cSJerin Jacob data->scattered_rx = 0; 940f18b146cSJerin Jacob 941f18b146cSJerin Jacob data->mac_addrs = rte_zmalloc_socket(octtx_name, ETHER_ADDR_LEN, 0, 942f18b146cSJerin Jacob socket_id); 943f18b146cSJerin Jacob if (data->mac_addrs == NULL) { 944f18b146cSJerin Jacob octeontx_log_err("failed to allocate memory for mac_addrs"); 945f18b146cSJerin Jacob res = -ENOMEM; 946f18b146cSJerin Jacob goto err; 947f18b146cSJerin Jacob } 948f18b146cSJerin Jacob 949f18b146cSJerin Jacob eth_dev->data = data; 950f18b146cSJerin Jacob eth_dev->dev_ops = &octeontx_dev_ops; 951f18b146cSJerin Jacob 952f18b146cSJerin Jacob /* Finally save ethdev pointer to the NIC structure */ 953f18b146cSJerin Jacob nic->dev = eth_dev; 954f18b146cSJerin Jacob 955f18b146cSJerin Jacob if (nic->port_id != data->port_id) { 956f18b146cSJerin Jacob octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)", 957f18b146cSJerin Jacob data->port_id, nic->port_id); 958f18b146cSJerin Jacob res = -EINVAL; 959f18b146cSJerin Jacob goto err; 960f18b146cSJerin Jacob } 961f18b146cSJerin Jacob 962f18b146cSJerin Jacob /* Update port_id mac to eth_dev */ 963f18b146cSJerin Jacob memcpy(data->mac_addrs, nic->mac_addr, ETHER_ADDR_LEN); 964f18b146cSJerin Jacob 965f18b146cSJerin Jacob PMD_INIT_LOG(DEBUG, "ethdev info: "); 966f18b146cSJerin Jacob PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d", 967f18b146cSJerin Jacob nic->port_id, nic->port_ena, 968f18b146cSJerin Jacob nic->base_ochan, nic->num_ochans, 969f18b146cSJerin Jacob nic->num_tx_queues); 970f18b146cSJerin Jacob PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->mtu); 971f18b146cSJerin Jacob 972f18b146cSJerin Jacob return data->port_id; 973f18b146cSJerin Jacob 974f18b146cSJerin Jacob err: 975f18b146cSJerin Jacob if (port) 976f18b146cSJerin Jacob octeontx_port_close(nic); 977f18b146cSJerin Jacob 978f18b146cSJerin Jacob if (eth_dev != NULL) { 979f18b146cSJerin Jacob rte_free(eth_dev->data->mac_addrs); 980f18b146cSJerin Jacob rte_free(data); 981f18b146cSJerin Jacob rte_free(nic); 982f18b146cSJerin Jacob rte_eth_dev_release_port(eth_dev); 983f18b146cSJerin Jacob } 984f18b146cSJerin Jacob 985f18b146cSJerin Jacob return res; 986f7be70e5SJerin Jacob } 987f7be70e5SJerin Jacob 988f7be70e5SJerin Jacob /* Un initialize octeontx device */ 989f7be70e5SJerin Jacob static int 990f7be70e5SJerin Jacob octeontx_remove(struct rte_vdev_device *dev) 991f7be70e5SJerin Jacob { 992f7be70e5SJerin Jacob char octtx_name[OCTEONTX_MAX_NAME_LEN]; 993f7be70e5SJerin Jacob struct rte_eth_dev *eth_dev = NULL; 994f7be70e5SJerin Jacob struct octeontx_nic *nic = NULL; 995f7be70e5SJerin Jacob int i; 996f7be70e5SJerin Jacob 997f7be70e5SJerin Jacob if (dev == NULL) 998f7be70e5SJerin Jacob return -EINVAL; 999f7be70e5SJerin Jacob 1000f7be70e5SJerin Jacob for (i = 0; i < OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT; i++) { 1001f7be70e5SJerin Jacob sprintf(octtx_name, "eth_octeontx_%d", i); 1002f7be70e5SJerin Jacob 1003f7be70e5SJerin Jacob /* reserve an ethdev entry */ 1004f7be70e5SJerin Jacob eth_dev = rte_eth_dev_allocated(octtx_name); 1005f7be70e5SJerin Jacob if (eth_dev == NULL) 1006f7be70e5SJerin Jacob return -ENODEV; 1007f7be70e5SJerin Jacob 1008f7be70e5SJerin Jacob nic = octeontx_pmd_priv(eth_dev); 1009f7be70e5SJerin Jacob rte_event_dev_stop(nic->evdev); 1010f7be70e5SJerin Jacob PMD_INIT_LOG(INFO, "Closing octeontx device %s", octtx_name); 1011f7be70e5SJerin Jacob 1012f7be70e5SJerin Jacob rte_free(eth_dev->data->mac_addrs); 1013f7be70e5SJerin Jacob rte_free(eth_dev->data->dev_private); 1014f7be70e5SJerin Jacob rte_free(eth_dev->data); 1015f7be70e5SJerin Jacob rte_eth_dev_release_port(eth_dev); 1016f7be70e5SJerin Jacob rte_event_dev_close(nic->evdev); 1017f7be70e5SJerin Jacob } 1018f7be70e5SJerin Jacob 1019f7be70e5SJerin Jacob /* Free FC resource */ 1020f7be70e5SJerin Jacob octeontx_pko_fc_free(); 1021f7be70e5SJerin Jacob 1022f7be70e5SJerin Jacob return 0; 1023f7be70e5SJerin Jacob } 1024f7be70e5SJerin Jacob 1025f7be70e5SJerin Jacob /* Initialize octeontx device */ 1026f7be70e5SJerin Jacob static int 1027f7be70e5SJerin Jacob octeontx_probe(struct rte_vdev_device *dev) 1028f7be70e5SJerin Jacob { 1029f7be70e5SJerin Jacob const char *dev_name; 1030f7be70e5SJerin Jacob static int probe_once; 1031f7be70e5SJerin Jacob uint8_t socket_id, qlist; 1032f7be70e5SJerin Jacob int tx_vfcnt, port_id, evdev, qnum, pnum, res, i; 1033f7be70e5SJerin Jacob struct rte_event_dev_config dev_conf; 1034f7be70e5SJerin Jacob const char *eventdev_name = "event_octeontx"; 1035f7be70e5SJerin Jacob struct rte_event_dev_info info; 1036f7be70e5SJerin Jacob 1037f7be70e5SJerin Jacob struct octeontx_vdev_init_params init_params = { 1038f7be70e5SJerin Jacob OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT 1039f7be70e5SJerin Jacob }; 1040f7be70e5SJerin Jacob 1041f7be70e5SJerin Jacob dev_name = rte_vdev_device_name(dev); 1042f7be70e5SJerin Jacob res = octeontx_parse_vdev_init_params(&init_params, dev); 1043f7be70e5SJerin Jacob if (res < 0) 1044f7be70e5SJerin Jacob return -EINVAL; 1045f7be70e5SJerin Jacob 1046f7be70e5SJerin Jacob if (init_params.nr_port > OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT) { 1047f7be70e5SJerin Jacob octeontx_log_err("nr_port (%d) > max (%d)", init_params.nr_port, 1048f7be70e5SJerin Jacob OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT); 1049f7be70e5SJerin Jacob return -ENOTSUP; 1050f7be70e5SJerin Jacob } 1051f7be70e5SJerin Jacob 1052f7be70e5SJerin Jacob PMD_INIT_LOG(DEBUG, "initializing %s pmd", dev_name); 1053f7be70e5SJerin Jacob 1054f7be70e5SJerin Jacob socket_id = rte_socket_id(); 1055f7be70e5SJerin Jacob 1056f7be70e5SJerin Jacob tx_vfcnt = octeontx_pko_vf_count(); 1057f7be70e5SJerin Jacob 1058f7be70e5SJerin Jacob if (tx_vfcnt < init_params.nr_port) { 1059f7be70e5SJerin Jacob octeontx_log_err("not enough PKO (%d) for port number (%d)", 1060f7be70e5SJerin Jacob tx_vfcnt, init_params.nr_port); 1061f7be70e5SJerin Jacob return -EINVAL; 1062f7be70e5SJerin Jacob } 1063f7be70e5SJerin Jacob evdev = rte_event_dev_get_dev_id(eventdev_name); 1064f7be70e5SJerin Jacob if (evdev < 0) { 1065f7be70e5SJerin Jacob octeontx_log_err("eventdev %s not found", eventdev_name); 1066f7be70e5SJerin Jacob return -ENODEV; 1067f7be70e5SJerin Jacob } 1068f7be70e5SJerin Jacob 1069f7be70e5SJerin Jacob res = rte_event_dev_info_get(evdev, &info); 1070f7be70e5SJerin Jacob if (res < 0) { 1071f7be70e5SJerin Jacob octeontx_log_err("failed to eventdev info %d", res); 1072f7be70e5SJerin Jacob return -EINVAL; 1073f7be70e5SJerin Jacob } 1074f7be70e5SJerin Jacob 1075f7be70e5SJerin Jacob PMD_INIT_LOG(DEBUG, "max_queue %d max_port %d", 1076f7be70e5SJerin Jacob info.max_event_queues, info.max_event_ports); 1077f7be70e5SJerin Jacob 1078f7be70e5SJerin Jacob if (octeontx_pko_init_fc(tx_vfcnt)) 1079f7be70e5SJerin Jacob return -ENOMEM; 1080f7be70e5SJerin Jacob 1081f7be70e5SJerin Jacob devconf_set_default_sane_values(&dev_conf, &info); 1082f7be70e5SJerin Jacob res = rte_event_dev_configure(evdev, &dev_conf); 1083f7be70e5SJerin Jacob if (res < 0) 1084f7be70e5SJerin Jacob goto parse_error; 1085f7be70e5SJerin Jacob 1086f7be70e5SJerin Jacob rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT, 1087f7be70e5SJerin Jacob (uint32_t *)&pnum); 1088f7be70e5SJerin Jacob rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT, 1089f7be70e5SJerin Jacob (uint32_t *)&qnum); 1090f7be70e5SJerin Jacob if (pnum < qnum) { 1091f7be70e5SJerin Jacob octeontx_log_err("too few event ports (%d) for event_q(%d)", 1092f7be70e5SJerin Jacob pnum, qnum); 1093f7be70e5SJerin Jacob res = -EINVAL; 1094f7be70e5SJerin Jacob goto parse_error; 1095f7be70e5SJerin Jacob } 1096f7be70e5SJerin Jacob if (pnum > qnum) { 1097f7be70e5SJerin Jacob /* 1098f7be70e5SJerin Jacob * We don't poll on event ports 1099f7be70e5SJerin Jacob * that do not have any queues assigned. 1100f7be70e5SJerin Jacob */ 1101f7be70e5SJerin Jacob pnum = qnum; 1102f7be70e5SJerin Jacob PMD_INIT_LOG(INFO, 1103f7be70e5SJerin Jacob "reducing number of active event ports to %d", pnum); 1104f7be70e5SJerin Jacob } 1105f7be70e5SJerin Jacob for (i = 0; i < qnum; i++) { 1106f7be70e5SJerin Jacob res = rte_event_queue_setup(evdev, i, NULL); 1107f7be70e5SJerin Jacob if (res < 0) { 1108f7be70e5SJerin Jacob octeontx_log_err("failed to setup event_q(%d): res %d", 1109f7be70e5SJerin Jacob i, res); 1110f7be70e5SJerin Jacob goto parse_error; 1111f7be70e5SJerin Jacob } 1112f7be70e5SJerin Jacob } 1113f7be70e5SJerin Jacob 1114f7be70e5SJerin Jacob for (i = 0; i < pnum; i++) { 1115f7be70e5SJerin Jacob res = rte_event_port_setup(evdev, i, NULL); 1116f7be70e5SJerin Jacob if (res < 0) { 1117f7be70e5SJerin Jacob res = -ENODEV; 1118f7be70e5SJerin Jacob octeontx_log_err("failed to setup ev port(%d) res=%d", 1119f7be70e5SJerin Jacob i, res); 1120f7be70e5SJerin Jacob goto parse_error; 1121f7be70e5SJerin Jacob } 1122f7be70e5SJerin Jacob /* Link one queue to one event port */ 1123f7be70e5SJerin Jacob qlist = i; 1124f7be70e5SJerin Jacob res = rte_event_port_link(evdev, i, &qlist, NULL, 1); 1125f7be70e5SJerin Jacob if (res < 0) { 1126f7be70e5SJerin Jacob res = -ENODEV; 1127f7be70e5SJerin Jacob octeontx_log_err("failed to link port (%d): res=%d", 1128f7be70e5SJerin Jacob i, res); 1129f7be70e5SJerin Jacob goto parse_error; 1130f7be70e5SJerin Jacob } 1131f7be70e5SJerin Jacob } 1132f7be70e5SJerin Jacob 1133f7be70e5SJerin Jacob /* Create ethdev interface */ 1134f7be70e5SJerin Jacob for (i = 0; i < init_params.nr_port; i++) { 1135f7be70e5SJerin Jacob port_id = octeontx_create(dev, i, evdev, socket_id); 1136f7be70e5SJerin Jacob if (port_id < 0) { 1137f7be70e5SJerin Jacob octeontx_log_err("failed to create device %s", 1138f7be70e5SJerin Jacob dev_name); 1139f7be70e5SJerin Jacob res = -ENODEV; 1140f7be70e5SJerin Jacob goto parse_error; 1141f7be70e5SJerin Jacob } 1142f7be70e5SJerin Jacob 1143f7be70e5SJerin Jacob PMD_INIT_LOG(INFO, "created ethdev %s for port %d", dev_name, 1144f7be70e5SJerin Jacob port_id); 1145f7be70e5SJerin Jacob } 1146f7be70e5SJerin Jacob 1147f7be70e5SJerin Jacob if (probe_once) { 1148f7be70e5SJerin Jacob octeontx_log_err("interface %s not supported", dev_name); 1149f7be70e5SJerin Jacob octeontx_remove(dev); 1150f7be70e5SJerin Jacob res = -ENOTSUP; 1151f7be70e5SJerin Jacob goto parse_error; 1152f7be70e5SJerin Jacob } 1153f7be70e5SJerin Jacob probe_once = 1; 1154f7be70e5SJerin Jacob 1155f7be70e5SJerin Jacob return 0; 1156f7be70e5SJerin Jacob 1157f7be70e5SJerin Jacob parse_error: 1158f7be70e5SJerin Jacob octeontx_pko_fc_free(); 1159f7be70e5SJerin Jacob return res; 1160f7be70e5SJerin Jacob } 1161f7be70e5SJerin Jacob 1162f7be70e5SJerin Jacob static struct rte_vdev_driver octeontx_pmd_drv = { 1163f7be70e5SJerin Jacob .probe = octeontx_probe, 1164f7be70e5SJerin Jacob .remove = octeontx_remove, 1165f7be70e5SJerin Jacob }; 1166f7be70e5SJerin Jacob 1167f7be70e5SJerin Jacob RTE_PMD_REGISTER_VDEV(OCTEONTX_PMD, octeontx_pmd_drv); 1168f7be70e5SJerin Jacob RTE_PMD_REGISTER_ALIAS(OCTEONTX_PMD, eth_octeontx); 1169f7be70e5SJerin Jacob RTE_PMD_REGISTER_PARAM_STRING(OCTEONTX_PMD, "nr_port=<int> "); 1170