1aaf4363eSJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause 2aaf4363eSJerin Jacob * Copyright(c) 2017 Cavium, Inc 3f7be70e5SJerin Jacob */ 4aaf4363eSJerin Jacob 5f7be70e5SJerin Jacob #include <stdio.h> 6f7be70e5SJerin Jacob #include <stdarg.h> 7f7be70e5SJerin Jacob #include <stdbool.h> 8f7be70e5SJerin Jacob #include <stdint.h> 9f7be70e5SJerin Jacob #include <string.h> 10f7be70e5SJerin Jacob #include <unistd.h> 11f7be70e5SJerin Jacob 12f7be70e5SJerin Jacob #include <rte_alarm.h> 13f7be70e5SJerin Jacob #include <rte_branch_prediction.h> 14f7be70e5SJerin Jacob #include <rte_debug.h> 15f7be70e5SJerin Jacob #include <rte_devargs.h> 16f7be70e5SJerin Jacob #include <rte_dev.h> 17f7be70e5SJerin Jacob #include <rte_kvargs.h> 18f7be70e5SJerin Jacob #include <rte_malloc.h> 19f7be70e5SJerin Jacob #include <rte_prefetch.h> 20d4a586d2SJianfeng Tan #include <rte_bus_vdev.h> 21f7be70e5SJerin Jacob 22f7be70e5SJerin Jacob #include "octeontx_ethdev.h" 2320186d43SJerin Jacob #include "octeontx_rxtx.h" 24f7be70e5SJerin Jacob #include "octeontx_logs.h" 25f7be70e5SJerin Jacob 26f7be70e5SJerin Jacob struct octeontx_vdev_init_params { 27f7be70e5SJerin Jacob uint8_t nr_port; 28f7be70e5SJerin Jacob }; 29f7be70e5SJerin Jacob 304fac7c0aSJerin Jacob enum octeontx_link_speed { 314fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_SGMII, 324fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_XAUI, 334fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_RXAUI, 344fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_10G_R, 354fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_40G_R, 364fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_RESERVE1, 374fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_QSGMII, 384fac7c0aSJerin Jacob OCTEONTX_LINK_SPEED_RESERVE2 394fac7c0aSJerin Jacob }; 404fac7c0aSJerin Jacob 41*4d35a276SPavan Nikhilesh int otx_net_logtype_mbox; 42*4d35a276SPavan Nikhilesh int otx_net_logtype_init; 43*4d35a276SPavan Nikhilesh int otx_net_logtype_driver; 44*4d35a276SPavan Nikhilesh 45*4d35a276SPavan Nikhilesh RTE_INIT(otx_net_init_log); 46*4d35a276SPavan Nikhilesh static void 47*4d35a276SPavan Nikhilesh otx_net_init_log(void) 48*4d35a276SPavan Nikhilesh { 49*4d35a276SPavan Nikhilesh otx_net_logtype_mbox = rte_log_register("pmd.otx.ethdev.mbox"); 50*4d35a276SPavan Nikhilesh if (otx_net_logtype_mbox >= 0) 51*4d35a276SPavan Nikhilesh rte_log_set_level(otx_net_logtype_mbox, RTE_LOG_NOTICE); 52*4d35a276SPavan Nikhilesh 53*4d35a276SPavan Nikhilesh otx_net_logtype_init = rte_log_register("pmd.otx.ethdev.init"); 54*4d35a276SPavan Nikhilesh if (otx_net_logtype_init >= 0) 55*4d35a276SPavan Nikhilesh rte_log_set_level(otx_net_logtype_init, RTE_LOG_NOTICE); 56*4d35a276SPavan Nikhilesh 57*4d35a276SPavan Nikhilesh otx_net_logtype_driver = rte_log_register("pmd.otx.ethdev.driver"); 58*4d35a276SPavan Nikhilesh if (otx_net_logtype_driver >= 0) 59*4d35a276SPavan Nikhilesh rte_log_set_level(otx_net_logtype_driver, RTE_LOG_NOTICE); 60*4d35a276SPavan Nikhilesh } 61*4d35a276SPavan Nikhilesh 62f7be70e5SJerin Jacob /* Parse integer from integer argument */ 63f7be70e5SJerin Jacob static int 64f7be70e5SJerin Jacob parse_integer_arg(const char *key __rte_unused, 65f7be70e5SJerin Jacob const char *value, void *extra_args) 66f7be70e5SJerin Jacob { 67f7be70e5SJerin Jacob int *i = (int *)extra_args; 68f7be70e5SJerin Jacob 69f7be70e5SJerin Jacob *i = atoi(value); 70f7be70e5SJerin Jacob if (*i < 0) { 71f7be70e5SJerin Jacob octeontx_log_err("argument has to be positive."); 72f7be70e5SJerin Jacob return -1; 73f7be70e5SJerin Jacob } 74f7be70e5SJerin Jacob 75f7be70e5SJerin Jacob return 0; 76f7be70e5SJerin Jacob } 77f7be70e5SJerin Jacob 78f7be70e5SJerin Jacob static int 79f7be70e5SJerin Jacob octeontx_parse_vdev_init_params(struct octeontx_vdev_init_params *params, 80f7be70e5SJerin Jacob struct rte_vdev_device *dev) 81f7be70e5SJerin Jacob { 82f7be70e5SJerin Jacob struct rte_kvargs *kvlist = NULL; 83f7be70e5SJerin Jacob int ret = 0; 84f7be70e5SJerin Jacob 85f7be70e5SJerin Jacob static const char * const octeontx_vdev_valid_params[] = { 86f7be70e5SJerin Jacob OCTEONTX_VDEV_NR_PORT_ARG, 87f7be70e5SJerin Jacob NULL 88f7be70e5SJerin Jacob }; 89f7be70e5SJerin Jacob 90f7be70e5SJerin Jacob const char *input_args = rte_vdev_device_args(dev); 91f7be70e5SJerin Jacob if (params == NULL) 92f7be70e5SJerin Jacob return -EINVAL; 93f7be70e5SJerin Jacob 94f7be70e5SJerin Jacob 95f7be70e5SJerin Jacob if (input_args) { 96f7be70e5SJerin Jacob kvlist = rte_kvargs_parse(input_args, 97f7be70e5SJerin Jacob octeontx_vdev_valid_params); 98f7be70e5SJerin Jacob if (kvlist == NULL) 99f7be70e5SJerin Jacob return -1; 100f7be70e5SJerin Jacob 101f7be70e5SJerin Jacob ret = rte_kvargs_process(kvlist, 102f7be70e5SJerin Jacob OCTEONTX_VDEV_NR_PORT_ARG, 103f7be70e5SJerin Jacob &parse_integer_arg, 104f7be70e5SJerin Jacob ¶ms->nr_port); 105f7be70e5SJerin Jacob if (ret < 0) 106f7be70e5SJerin Jacob goto free_kvlist; 107f7be70e5SJerin Jacob } 108f7be70e5SJerin Jacob 109f7be70e5SJerin Jacob free_kvlist: 110f7be70e5SJerin Jacob rte_kvargs_free(kvlist); 111f7be70e5SJerin Jacob return ret; 112f7be70e5SJerin Jacob } 113f7be70e5SJerin Jacob 114f18b146cSJerin Jacob static int 115f18b146cSJerin Jacob octeontx_port_open(struct octeontx_nic *nic) 116f18b146cSJerin Jacob { 117f18b146cSJerin Jacob octeontx_mbox_bgx_port_conf_t bgx_port_conf; 118f18b146cSJerin Jacob int res; 119f18b146cSJerin Jacob 120f18b146cSJerin Jacob res = 0; 121f18b146cSJerin Jacob 122f18b146cSJerin Jacob PMD_INIT_FUNC_TRACE(); 123f18b146cSJerin Jacob 124f18b146cSJerin Jacob res = octeontx_bgx_port_open(nic->port_id, &bgx_port_conf); 125f18b146cSJerin Jacob if (res < 0) { 126f18b146cSJerin Jacob octeontx_log_err("failed to open port %d", res); 127f18b146cSJerin Jacob return res; 128f18b146cSJerin Jacob } 129f18b146cSJerin Jacob 130f18b146cSJerin Jacob nic->node = bgx_port_conf.node; 131f18b146cSJerin Jacob nic->port_ena = bgx_port_conf.enable; 132f18b146cSJerin Jacob nic->base_ichan = bgx_port_conf.base_chan; 133f18b146cSJerin Jacob nic->base_ochan = bgx_port_conf.base_chan; 134f18b146cSJerin Jacob nic->num_ichans = bgx_port_conf.num_chans; 135f18b146cSJerin Jacob nic->num_ochans = bgx_port_conf.num_chans; 136f18b146cSJerin Jacob nic->mtu = bgx_port_conf.mtu; 137f18b146cSJerin Jacob nic->bpen = bgx_port_conf.bpen; 138f18b146cSJerin Jacob nic->fcs_strip = bgx_port_conf.fcs_strip; 139f18b146cSJerin Jacob nic->bcast_mode = bgx_port_conf.bcast_mode; 140f18b146cSJerin Jacob nic->mcast_mode = bgx_port_conf.mcast_mode; 141f18b146cSJerin Jacob nic->speed = bgx_port_conf.mode; 142f18b146cSJerin Jacob 143f18b146cSJerin Jacob memcpy(&nic->mac_addr[0], &bgx_port_conf.macaddr[0], ETHER_ADDR_LEN); 144f18b146cSJerin Jacob 145f18b146cSJerin Jacob octeontx_log_dbg("port opened %d", nic->port_id); 146f18b146cSJerin Jacob return res; 147f18b146cSJerin Jacob } 148f18b146cSJerin Jacob 149f18b146cSJerin Jacob static void 150f18b146cSJerin Jacob octeontx_port_close(struct octeontx_nic *nic) 151f18b146cSJerin Jacob { 152f18b146cSJerin Jacob PMD_INIT_FUNC_TRACE(); 153f18b146cSJerin Jacob 154f18b146cSJerin Jacob octeontx_bgx_port_close(nic->port_id); 155f18b146cSJerin Jacob octeontx_log_dbg("port closed %d", nic->port_id); 156f18b146cSJerin Jacob } 157f18b146cSJerin Jacob 1587fe7c98fSJerin Jacob static int 159da6c6874SJerin Jacob octeontx_port_start(struct octeontx_nic *nic) 160da6c6874SJerin Jacob { 161da6c6874SJerin Jacob PMD_INIT_FUNC_TRACE(); 162da6c6874SJerin Jacob 163da6c6874SJerin Jacob return octeontx_bgx_port_start(nic->port_id); 164da6c6874SJerin Jacob } 165da6c6874SJerin Jacob 166da6c6874SJerin Jacob static int 1677fe7c98fSJerin Jacob octeontx_port_stop(struct octeontx_nic *nic) 1687fe7c98fSJerin Jacob { 1697fe7c98fSJerin Jacob PMD_INIT_FUNC_TRACE(); 1707fe7c98fSJerin Jacob 1717fe7c98fSJerin Jacob return octeontx_bgx_port_stop(nic->port_id); 1727fe7c98fSJerin Jacob } 1737fe7c98fSJerin Jacob 17415bce35bSJerin Jacob static void 17515bce35bSJerin Jacob octeontx_port_promisc_set(struct octeontx_nic *nic, int en) 17615bce35bSJerin Jacob { 17715bce35bSJerin Jacob struct rte_eth_dev *dev; 17815bce35bSJerin Jacob int res; 17915bce35bSJerin Jacob 18015bce35bSJerin Jacob res = 0; 18115bce35bSJerin Jacob PMD_INIT_FUNC_TRACE(); 18215bce35bSJerin Jacob dev = nic->dev; 18315bce35bSJerin Jacob 18415bce35bSJerin Jacob res = octeontx_bgx_port_promisc_set(nic->port_id, en); 18515bce35bSJerin Jacob if (res < 0) 18615bce35bSJerin Jacob octeontx_log_err("failed to set promiscuous mode %d", 18715bce35bSJerin Jacob nic->port_id); 18815bce35bSJerin Jacob 18915bce35bSJerin Jacob /* Set proper flag for the mode */ 19015bce35bSJerin Jacob dev->data->promiscuous = (en != 0) ? 1 : 0; 19115bce35bSJerin Jacob 19215bce35bSJerin Jacob octeontx_log_dbg("port %d : promiscuous mode %s", 19315bce35bSJerin Jacob nic->port_id, en ? "set" : "unset"); 19415bce35bSJerin Jacob } 19515bce35bSJerin Jacob 196d5b0924bSMatan Azrad static int 19755389909SJerin Jacob octeontx_port_stats(struct octeontx_nic *nic, struct rte_eth_stats *stats) 19855389909SJerin Jacob { 19955389909SJerin Jacob octeontx_mbox_bgx_port_stats_t bgx_stats; 20055389909SJerin Jacob int res; 20155389909SJerin Jacob 20255389909SJerin Jacob PMD_INIT_FUNC_TRACE(); 20355389909SJerin Jacob 20455389909SJerin Jacob res = octeontx_bgx_port_stats(nic->port_id, &bgx_stats); 205d5b0924bSMatan Azrad if (res < 0) { 20655389909SJerin Jacob octeontx_log_err("failed to get port stats %d", nic->port_id); 207d5b0924bSMatan Azrad return res; 208d5b0924bSMatan Azrad } 20955389909SJerin Jacob 21055389909SJerin Jacob stats->ipackets = bgx_stats.rx_packets; 21155389909SJerin Jacob stats->ibytes = bgx_stats.rx_bytes; 21255389909SJerin Jacob stats->imissed = bgx_stats.rx_dropped; 21355389909SJerin Jacob stats->ierrors = bgx_stats.rx_errors; 21455389909SJerin Jacob stats->opackets = bgx_stats.tx_packets; 21555389909SJerin Jacob stats->obytes = bgx_stats.tx_bytes; 21655389909SJerin Jacob stats->oerrors = bgx_stats.tx_errors; 21755389909SJerin Jacob 21855389909SJerin Jacob octeontx_log_dbg("port%d stats inpkts=%" PRIx64 " outpkts=%" PRIx64 "", 21955389909SJerin Jacob nic->port_id, stats->ipackets, stats->opackets); 220d5b0924bSMatan Azrad 221d5b0924bSMatan Azrad return 0; 22255389909SJerin Jacob } 22355389909SJerin Jacob 22455389909SJerin Jacob static void 22555389909SJerin Jacob octeontx_port_stats_clr(struct octeontx_nic *nic) 22655389909SJerin Jacob { 22755389909SJerin Jacob PMD_INIT_FUNC_TRACE(); 22855389909SJerin Jacob 22955389909SJerin Jacob octeontx_bgx_port_stats_clr(nic->port_id); 23055389909SJerin Jacob } 23155389909SJerin Jacob 232f7be70e5SJerin Jacob static inline void 233f7be70e5SJerin Jacob devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf, 234f7be70e5SJerin Jacob struct rte_event_dev_info *info) 235f7be70e5SJerin Jacob { 236f7be70e5SJerin Jacob memset(dev_conf, 0, sizeof(struct rte_event_dev_config)); 237f7be70e5SJerin Jacob dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns; 238f7be70e5SJerin Jacob 239f7be70e5SJerin Jacob dev_conf->nb_event_ports = info->max_event_ports; 240f7be70e5SJerin Jacob dev_conf->nb_event_queues = info->max_event_queues; 241f7be70e5SJerin Jacob 242f7be70e5SJerin Jacob dev_conf->nb_event_queue_flows = info->max_event_queue_flows; 243f7be70e5SJerin Jacob dev_conf->nb_event_port_dequeue_depth = 244f7be70e5SJerin Jacob info->max_event_port_dequeue_depth; 245f7be70e5SJerin Jacob dev_conf->nb_event_port_enqueue_depth = 246f7be70e5SJerin Jacob info->max_event_port_enqueue_depth; 247f7be70e5SJerin Jacob dev_conf->nb_event_port_enqueue_depth = 248f7be70e5SJerin Jacob info->max_event_port_enqueue_depth; 249f7be70e5SJerin Jacob dev_conf->nb_events_limit = 250f7be70e5SJerin Jacob info->max_num_events; 251f7be70e5SJerin Jacob } 252f7be70e5SJerin Jacob 2537742c55aSJerin Jacob static int 2547742c55aSJerin Jacob octeontx_dev_configure(struct rte_eth_dev *dev) 2557742c55aSJerin Jacob { 2567742c55aSJerin Jacob struct rte_eth_dev_data *data = dev->data; 2577742c55aSJerin Jacob struct rte_eth_conf *conf = &data->dev_conf; 2587742c55aSJerin Jacob struct rte_eth_rxmode *rxmode = &conf->rxmode; 2597742c55aSJerin Jacob struct rte_eth_txmode *txmode = &conf->txmode; 2607742c55aSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 2617742c55aSJerin Jacob int ret; 2627742c55aSJerin Jacob 2637742c55aSJerin Jacob PMD_INIT_FUNC_TRACE(); 2647742c55aSJerin Jacob RTE_SET_USED(conf); 2657742c55aSJerin Jacob 2667742c55aSJerin Jacob if (!rte_eal_has_hugepages()) { 2677742c55aSJerin Jacob octeontx_log_err("huge page is not configured"); 2687742c55aSJerin Jacob return -EINVAL; 2697742c55aSJerin Jacob } 2707742c55aSJerin Jacob 2717742c55aSJerin Jacob if (txmode->mq_mode) { 2727742c55aSJerin Jacob octeontx_log_err("tx mq_mode DCB or VMDq not supported"); 2737742c55aSJerin Jacob return -EINVAL; 2747742c55aSJerin Jacob } 2757742c55aSJerin Jacob 2767742c55aSJerin Jacob if (rxmode->mq_mode != ETH_MQ_RX_NONE && 2777742c55aSJerin Jacob rxmode->mq_mode != ETH_MQ_RX_RSS) { 2787742c55aSJerin Jacob octeontx_log_err("unsupported rx qmode %d", rxmode->mq_mode); 2797742c55aSJerin Jacob return -EINVAL; 2807742c55aSJerin Jacob } 2817742c55aSJerin Jacob 2827742c55aSJerin Jacob if (!rxmode->hw_strip_crc) { 2837742c55aSJerin Jacob PMD_INIT_LOG(NOTICE, "can't disable hw crc strip"); 2847742c55aSJerin Jacob rxmode->hw_strip_crc = 1; 2857742c55aSJerin Jacob } 2867742c55aSJerin Jacob 2877742c55aSJerin Jacob if (rxmode->hw_ip_checksum) { 2887742c55aSJerin Jacob PMD_INIT_LOG(NOTICE, "rxcksum not supported"); 2897742c55aSJerin Jacob rxmode->hw_ip_checksum = 0; 2907742c55aSJerin Jacob } 2917742c55aSJerin Jacob 2927742c55aSJerin Jacob if (rxmode->split_hdr_size) { 2937742c55aSJerin Jacob octeontx_log_err("rxmode does not support split header"); 2947742c55aSJerin Jacob return -EINVAL; 2957742c55aSJerin Jacob } 2967742c55aSJerin Jacob 2977742c55aSJerin Jacob if (rxmode->hw_vlan_filter) { 2987742c55aSJerin Jacob octeontx_log_err("VLAN filter not supported"); 2997742c55aSJerin Jacob return -EINVAL; 3007742c55aSJerin Jacob } 3017742c55aSJerin Jacob 3027742c55aSJerin Jacob if (rxmode->hw_vlan_extend) { 3037742c55aSJerin Jacob octeontx_log_err("VLAN extended not supported"); 3047742c55aSJerin Jacob return -EINVAL; 3057742c55aSJerin Jacob } 3067742c55aSJerin Jacob 3077742c55aSJerin Jacob if (rxmode->enable_lro) { 3087742c55aSJerin Jacob octeontx_log_err("LRO not supported"); 3097742c55aSJerin Jacob return -EINVAL; 3107742c55aSJerin Jacob } 3117742c55aSJerin Jacob 3127742c55aSJerin Jacob if (conf->link_speeds & ETH_LINK_SPEED_FIXED) { 3137742c55aSJerin Jacob octeontx_log_err("setting link speed/duplex not supported"); 3147742c55aSJerin Jacob return -EINVAL; 3157742c55aSJerin Jacob } 3167742c55aSJerin Jacob 3177742c55aSJerin Jacob if (conf->dcb_capability_en) { 3187742c55aSJerin Jacob octeontx_log_err("DCB enable not supported"); 3197742c55aSJerin Jacob return -EINVAL; 3207742c55aSJerin Jacob } 3217742c55aSJerin Jacob 3227742c55aSJerin Jacob if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) { 3237742c55aSJerin Jacob octeontx_log_err("flow director not supported"); 3247742c55aSJerin Jacob return -EINVAL; 3257742c55aSJerin Jacob } 3267742c55aSJerin Jacob 3277742c55aSJerin Jacob nic->num_tx_queues = dev->data->nb_tx_queues; 3287742c55aSJerin Jacob 3297742c55aSJerin Jacob ret = octeontx_pko_channel_open(nic->port_id * PKO_VF_NUM_DQ, 3307742c55aSJerin Jacob nic->num_tx_queues, 3317742c55aSJerin Jacob nic->base_ochan); 3327742c55aSJerin Jacob if (ret) { 3337742c55aSJerin Jacob octeontx_log_err("failed to open channel %d no-of-txq %d", 3347742c55aSJerin Jacob nic->base_ochan, nic->num_tx_queues); 3357742c55aSJerin Jacob return -EFAULT; 3367742c55aSJerin Jacob } 3377742c55aSJerin Jacob 3387742c55aSJerin Jacob nic->pki.classifier_enable = false; 3397742c55aSJerin Jacob nic->pki.hash_enable = true; 3407742c55aSJerin Jacob nic->pki.initialized = false; 3417742c55aSJerin Jacob 3427742c55aSJerin Jacob return 0; 3437742c55aSJerin Jacob } 3447742c55aSJerin Jacob 34515bce35bSJerin Jacob static void 346da6c6874SJerin Jacob octeontx_dev_close(struct rte_eth_dev *dev) 347da6c6874SJerin Jacob { 348da6c6874SJerin Jacob struct octeontx_txq *txq = NULL; 349da6c6874SJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 350da6c6874SJerin Jacob unsigned int i; 351da6c6874SJerin Jacob int ret; 352da6c6874SJerin Jacob 353da6c6874SJerin Jacob PMD_INIT_FUNC_TRACE(); 354da6c6874SJerin Jacob 355da6c6874SJerin Jacob rte_event_dev_close(nic->evdev); 356da6c6874SJerin Jacob 357da6c6874SJerin Jacob ret = octeontx_pko_channel_close(nic->base_ochan); 358da6c6874SJerin Jacob if (ret < 0) { 359da6c6874SJerin Jacob octeontx_log_err("failed to close channel %d VF%d %d %d", 360da6c6874SJerin Jacob nic->base_ochan, nic->port_id, nic->num_tx_queues, 361da6c6874SJerin Jacob ret); 362da6c6874SJerin Jacob } 363da6c6874SJerin Jacob /* Free txq resources for this port */ 364da6c6874SJerin Jacob for (i = 0; i < nic->num_tx_queues; i++) { 365da6c6874SJerin Jacob txq = dev->data->tx_queues[i]; 366da6c6874SJerin Jacob if (!txq) 367da6c6874SJerin Jacob continue; 368da6c6874SJerin Jacob 369da6c6874SJerin Jacob rte_free(txq); 370da6c6874SJerin Jacob } 371da6c6874SJerin Jacob } 372da6c6874SJerin Jacob 373da6c6874SJerin Jacob static int 374da6c6874SJerin Jacob octeontx_dev_start(struct rte_eth_dev *dev) 375da6c6874SJerin Jacob { 376da6c6874SJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 377da6c6874SJerin Jacob int ret; 378da6c6874SJerin Jacob 379da6c6874SJerin Jacob ret = 0; 380da6c6874SJerin Jacob 381da6c6874SJerin Jacob PMD_INIT_FUNC_TRACE(); 382da6c6874SJerin Jacob /* 383da6c6874SJerin Jacob * Tx start 384da6c6874SJerin Jacob */ 385da6c6874SJerin Jacob dev->tx_pkt_burst = octeontx_xmit_pkts; 386da6c6874SJerin Jacob ret = octeontx_pko_channel_start(nic->base_ochan); 387da6c6874SJerin Jacob if (ret < 0) { 388da6c6874SJerin Jacob octeontx_log_err("fail to conf VF%d no. txq %d chan %d ret %d", 389da6c6874SJerin Jacob nic->port_id, nic->num_tx_queues, nic->base_ochan, 390da6c6874SJerin Jacob ret); 391da6c6874SJerin Jacob goto error; 392da6c6874SJerin Jacob } 393da6c6874SJerin Jacob 394da6c6874SJerin Jacob /* 395da6c6874SJerin Jacob * Rx start 396da6c6874SJerin Jacob */ 397da6c6874SJerin Jacob dev->rx_pkt_burst = octeontx_recv_pkts; 398da6c6874SJerin Jacob ret = octeontx_pki_port_start(nic->port_id); 399da6c6874SJerin Jacob if (ret < 0) { 400da6c6874SJerin Jacob octeontx_log_err("fail to start Rx on port %d", nic->port_id); 401da6c6874SJerin Jacob goto channel_stop_error; 402da6c6874SJerin Jacob } 403da6c6874SJerin Jacob 404da6c6874SJerin Jacob /* 405da6c6874SJerin Jacob * Start port 406da6c6874SJerin Jacob */ 407da6c6874SJerin Jacob ret = octeontx_port_start(nic); 408da6c6874SJerin Jacob if (ret < 0) { 409da6c6874SJerin Jacob octeontx_log_err("failed start port %d", ret); 410da6c6874SJerin Jacob goto pki_port_stop_error; 411da6c6874SJerin Jacob } 412da6c6874SJerin Jacob 413da6c6874SJerin Jacob PMD_TX_LOG(DEBUG, "pko: start channel %d no.of txq %d port %d", 414da6c6874SJerin Jacob nic->base_ochan, nic->num_tx_queues, nic->port_id); 415da6c6874SJerin Jacob 416da6c6874SJerin Jacob ret = rte_event_dev_start(nic->evdev); 417da6c6874SJerin Jacob if (ret < 0) { 418da6c6874SJerin Jacob octeontx_log_err("failed to start evdev: ret (%d)", ret); 419da6c6874SJerin Jacob goto pki_port_stop_error; 420da6c6874SJerin Jacob } 421da6c6874SJerin Jacob 422da6c6874SJerin Jacob /* Success */ 423da6c6874SJerin Jacob return ret; 424da6c6874SJerin Jacob 425da6c6874SJerin Jacob pki_port_stop_error: 426da6c6874SJerin Jacob octeontx_pki_port_stop(nic->port_id); 427da6c6874SJerin Jacob channel_stop_error: 428da6c6874SJerin Jacob octeontx_pko_channel_stop(nic->base_ochan); 429da6c6874SJerin Jacob error: 430da6c6874SJerin Jacob return ret; 431da6c6874SJerin Jacob } 432da6c6874SJerin Jacob 433da6c6874SJerin Jacob static void 434da6c6874SJerin Jacob octeontx_dev_stop(struct rte_eth_dev *dev) 435da6c6874SJerin Jacob { 436da6c6874SJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 437da6c6874SJerin Jacob int ret; 438da6c6874SJerin Jacob 439da6c6874SJerin Jacob PMD_INIT_FUNC_TRACE(); 440da6c6874SJerin Jacob 441da6c6874SJerin Jacob rte_event_dev_stop(nic->evdev); 442da6c6874SJerin Jacob 443da6c6874SJerin Jacob ret = octeontx_port_stop(nic); 444da6c6874SJerin Jacob if (ret < 0) { 445da6c6874SJerin Jacob octeontx_log_err("failed to req stop port %d res=%d", 446da6c6874SJerin Jacob nic->port_id, ret); 447da6c6874SJerin Jacob return; 448da6c6874SJerin Jacob } 449da6c6874SJerin Jacob 450da6c6874SJerin Jacob ret = octeontx_pki_port_stop(nic->port_id); 451da6c6874SJerin Jacob if (ret < 0) { 452da6c6874SJerin Jacob octeontx_log_err("failed to stop pki port %d res=%d", 453da6c6874SJerin Jacob nic->port_id, ret); 454da6c6874SJerin Jacob return; 455da6c6874SJerin Jacob } 456da6c6874SJerin Jacob 457da6c6874SJerin Jacob ret = octeontx_pko_channel_stop(nic->base_ochan); 458da6c6874SJerin Jacob if (ret < 0) { 459da6c6874SJerin Jacob octeontx_log_err("failed to stop channel %d VF%d %d %d", 460da6c6874SJerin Jacob nic->base_ochan, nic->port_id, nic->num_tx_queues, 461da6c6874SJerin Jacob ret); 462da6c6874SJerin Jacob return; 463da6c6874SJerin Jacob } 464da6c6874SJerin Jacob 465da6c6874SJerin Jacob dev->tx_pkt_burst = NULL; 466da6c6874SJerin Jacob dev->rx_pkt_burst = NULL; 467da6c6874SJerin Jacob } 468da6c6874SJerin Jacob 469da6c6874SJerin Jacob static void 47015bce35bSJerin Jacob octeontx_dev_promisc_enable(struct rte_eth_dev *dev) 47115bce35bSJerin Jacob { 47215bce35bSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 47315bce35bSJerin Jacob 47415bce35bSJerin Jacob PMD_INIT_FUNC_TRACE(); 47515bce35bSJerin Jacob octeontx_port_promisc_set(nic, 1); 47615bce35bSJerin Jacob } 47715bce35bSJerin Jacob 47815bce35bSJerin Jacob static void 47915bce35bSJerin Jacob octeontx_dev_promisc_disable(struct rte_eth_dev *dev) 48015bce35bSJerin Jacob { 48115bce35bSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 48215bce35bSJerin Jacob 48315bce35bSJerin Jacob PMD_INIT_FUNC_TRACE(); 48415bce35bSJerin Jacob octeontx_port_promisc_set(nic, 0); 48515bce35bSJerin Jacob } 48615bce35bSJerin Jacob 4874fac7c0aSJerin Jacob static inline int 4884fac7c0aSJerin Jacob octeontx_atomic_write_link_status(struct rte_eth_dev *dev, 4894fac7c0aSJerin Jacob struct rte_eth_link *link) 4904fac7c0aSJerin Jacob { 4914fac7c0aSJerin Jacob struct rte_eth_link *dst = &dev->data->dev_link; 4924fac7c0aSJerin Jacob struct rte_eth_link *src = link; 4934fac7c0aSJerin Jacob 4944fac7c0aSJerin Jacob if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst, 4954fac7c0aSJerin Jacob *(uint64_t *)src) == 0) 4964fac7c0aSJerin Jacob return -1; 4974fac7c0aSJerin Jacob 4984fac7c0aSJerin Jacob return 0; 4994fac7c0aSJerin Jacob } 5004fac7c0aSJerin Jacob 5014fac7c0aSJerin Jacob static int 5024fac7c0aSJerin Jacob octeontx_port_link_status(struct octeontx_nic *nic) 5034fac7c0aSJerin Jacob { 5044fac7c0aSJerin Jacob int res; 5054fac7c0aSJerin Jacob 5064fac7c0aSJerin Jacob PMD_INIT_FUNC_TRACE(); 5074fac7c0aSJerin Jacob res = octeontx_bgx_port_link_status(nic->port_id); 5084fac7c0aSJerin Jacob if (res < 0) { 5094fac7c0aSJerin Jacob octeontx_log_err("failed to get port %d link status", 5104fac7c0aSJerin Jacob nic->port_id); 5114fac7c0aSJerin Jacob return res; 5124fac7c0aSJerin Jacob } 5134fac7c0aSJerin Jacob 5144fac7c0aSJerin Jacob nic->link_up = (uint8_t)res; 5154fac7c0aSJerin Jacob octeontx_log_dbg("port %d link status %d", nic->port_id, nic->link_up); 5164fac7c0aSJerin Jacob 5174fac7c0aSJerin Jacob return res; 5184fac7c0aSJerin Jacob } 5194fac7c0aSJerin Jacob 5204fac7c0aSJerin Jacob /* 5214fac7c0aSJerin Jacob * Return 0 means link status changed, -1 means not changed 5224fac7c0aSJerin Jacob */ 5234fac7c0aSJerin Jacob static int 5244fac7c0aSJerin Jacob octeontx_dev_link_update(struct rte_eth_dev *dev, 5254fac7c0aSJerin Jacob int wait_to_complete __rte_unused) 5264fac7c0aSJerin Jacob { 5274fac7c0aSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 5284fac7c0aSJerin Jacob struct rte_eth_link link; 5294fac7c0aSJerin Jacob int res; 5304fac7c0aSJerin Jacob 5314fac7c0aSJerin Jacob res = 0; 5324fac7c0aSJerin Jacob PMD_INIT_FUNC_TRACE(); 5334fac7c0aSJerin Jacob 5344fac7c0aSJerin Jacob res = octeontx_port_link_status(nic); 5354fac7c0aSJerin Jacob if (res < 0) { 5364fac7c0aSJerin Jacob octeontx_log_err("failed to request link status %d", res); 5374fac7c0aSJerin Jacob return res; 5384fac7c0aSJerin Jacob } 5394fac7c0aSJerin Jacob 5404fac7c0aSJerin Jacob link.link_status = nic->link_up; 5414fac7c0aSJerin Jacob 5424fac7c0aSJerin Jacob switch (nic->speed) { 5434fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_SGMII: 5444fac7c0aSJerin Jacob link.link_speed = ETH_SPEED_NUM_1G; 5454fac7c0aSJerin Jacob break; 5464fac7c0aSJerin Jacob 5474fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_XAUI: 5484fac7c0aSJerin Jacob link.link_speed = ETH_SPEED_NUM_10G; 5494fac7c0aSJerin Jacob break; 5504fac7c0aSJerin Jacob 5514fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_RXAUI: 5524fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_10G_R: 5534fac7c0aSJerin Jacob link.link_speed = ETH_SPEED_NUM_10G; 5544fac7c0aSJerin Jacob break; 5554fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_QSGMII: 5564fac7c0aSJerin Jacob link.link_speed = ETH_SPEED_NUM_5G; 5574fac7c0aSJerin Jacob break; 5584fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_40G_R: 5594fac7c0aSJerin Jacob link.link_speed = ETH_SPEED_NUM_40G; 5604fac7c0aSJerin Jacob break; 5614fac7c0aSJerin Jacob 5624fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_RESERVE1: 5634fac7c0aSJerin Jacob case OCTEONTX_LINK_SPEED_RESERVE2: 5644fac7c0aSJerin Jacob default: 5654fac7c0aSJerin Jacob octeontx_log_err("incorrect link speed %d", nic->speed); 5664fac7c0aSJerin Jacob break; 5674fac7c0aSJerin Jacob } 5684fac7c0aSJerin Jacob 5694fac7c0aSJerin Jacob link.link_duplex = ETH_LINK_AUTONEG; 5704fac7c0aSJerin Jacob link.link_autoneg = ETH_LINK_SPEED_AUTONEG; 5714fac7c0aSJerin Jacob 5724fac7c0aSJerin Jacob return octeontx_atomic_write_link_status(dev, &link); 5734fac7c0aSJerin Jacob } 5744fac7c0aSJerin Jacob 575d5b0924bSMatan Azrad static int 57655389909SJerin Jacob octeontx_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) 57755389909SJerin Jacob { 57855389909SJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 57955389909SJerin Jacob 58055389909SJerin Jacob PMD_INIT_FUNC_TRACE(); 581d5b0924bSMatan Azrad return octeontx_port_stats(nic, stats); 58255389909SJerin Jacob } 58355389909SJerin Jacob 58455389909SJerin Jacob static void 58555389909SJerin Jacob octeontx_dev_stats_reset(struct rte_eth_dev *dev) 58655389909SJerin Jacob { 58755389909SJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 58855389909SJerin Jacob 58955389909SJerin Jacob PMD_INIT_FUNC_TRACE(); 59055389909SJerin Jacob octeontx_port_stats_clr(nic); 59155389909SJerin Jacob } 59255389909SJerin Jacob 59355389909SJerin Jacob static void 594ef7308fcSJerin Jacob octeontx_dev_default_mac_addr_set(struct rte_eth_dev *dev, 595ef7308fcSJerin Jacob struct ether_addr *addr) 596ef7308fcSJerin Jacob { 597ef7308fcSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 598ef7308fcSJerin Jacob int ret; 599ef7308fcSJerin Jacob 600ef7308fcSJerin Jacob ret = octeontx_bgx_port_mac_set(nic->port_id, addr->addr_bytes); 601ef7308fcSJerin Jacob if (ret != 0) 602ef7308fcSJerin Jacob octeontx_log_err("failed to set MAC address on port %d", 603ef7308fcSJerin Jacob nic->port_id); 604ef7308fcSJerin Jacob } 605ef7308fcSJerin Jacob 606ef7308fcSJerin Jacob static void 6077c0347a2SJerin Jacob octeontx_dev_info(struct rte_eth_dev *dev, 6087c0347a2SJerin Jacob struct rte_eth_dev_info *dev_info) 6097c0347a2SJerin Jacob { 6107c0347a2SJerin Jacob RTE_SET_USED(dev); 6117c0347a2SJerin Jacob 6127c0347a2SJerin Jacob /* Autonegotiation may be disabled */ 6137c0347a2SJerin Jacob dev_info->speed_capa = ETH_LINK_SPEED_FIXED; 6147c0347a2SJerin Jacob dev_info->speed_capa |= ETH_LINK_SPEED_10M | ETH_LINK_SPEED_100M | 6157c0347a2SJerin Jacob ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G | 6167c0347a2SJerin Jacob ETH_LINK_SPEED_40G; 6177c0347a2SJerin Jacob 6187c0347a2SJerin Jacob dev_info->driver_name = RTE_STR(rte_octeontx_pmd); 6197c0347a2SJerin Jacob dev_info->max_mac_addrs = 1; 6207c0347a2SJerin Jacob dev_info->max_rx_pktlen = PKI_MAX_PKTLEN; 6217c0347a2SJerin Jacob dev_info->max_rx_queues = 1; 6227c0347a2SJerin Jacob dev_info->max_tx_queues = PKO_MAX_NUM_DQ; 6237c0347a2SJerin Jacob dev_info->min_rx_bufsize = 0; 6247c0347a2SJerin Jacob dev_info->pci_dev = NULL; 6257c0347a2SJerin Jacob 6267c0347a2SJerin Jacob dev_info->default_rxconf = (struct rte_eth_rxconf) { 6277c0347a2SJerin Jacob .rx_free_thresh = 0, 6287c0347a2SJerin Jacob .rx_drop_en = 0, 6297c0347a2SJerin Jacob }; 6307c0347a2SJerin Jacob 6317c0347a2SJerin Jacob dev_info->default_txconf = (struct rte_eth_txconf) { 6327c0347a2SJerin Jacob .tx_free_thresh = 0, 6337c0347a2SJerin Jacob .txq_flags = 6347c0347a2SJerin Jacob ETH_TXQ_FLAGS_NOMULTSEGS | 6357c0347a2SJerin Jacob ETH_TXQ_FLAGS_NOOFFLOADS | 6367c0347a2SJerin Jacob ETH_TXQ_FLAGS_NOXSUMS, 6377c0347a2SJerin Jacob }; 6387c0347a2SJerin Jacob 6397c0347a2SJerin Jacob dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MT_LOCKFREE; 6407c0347a2SJerin Jacob } 6417c0347a2SJerin Jacob 6427fe7c98fSJerin Jacob static void 6437fe7c98fSJerin Jacob octeontx_dq_info_getter(octeontx_dq_t *dq, void *out) 6447fe7c98fSJerin Jacob { 6457fe7c98fSJerin Jacob ((octeontx_dq_t *)out)->lmtline_va = dq->lmtline_va; 6467fe7c98fSJerin Jacob ((octeontx_dq_t *)out)->ioreg_va = dq->ioreg_va; 6477fe7c98fSJerin Jacob ((octeontx_dq_t *)out)->fc_status_va = dq->fc_status_va; 6487fe7c98fSJerin Jacob } 6497fe7c98fSJerin Jacob 6507fe7c98fSJerin Jacob static int 6517fe7c98fSJerin Jacob octeontx_vf_start_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic, 6527fe7c98fSJerin Jacob uint16_t qidx) 6537fe7c98fSJerin Jacob { 6547fe7c98fSJerin Jacob struct octeontx_txq *txq; 6557fe7c98fSJerin Jacob int res; 6567fe7c98fSJerin Jacob 6577fe7c98fSJerin Jacob PMD_INIT_FUNC_TRACE(); 6587fe7c98fSJerin Jacob 6597fe7c98fSJerin Jacob if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED) 6607fe7c98fSJerin Jacob return 0; 6617fe7c98fSJerin Jacob 6627fe7c98fSJerin Jacob txq = dev->data->tx_queues[qidx]; 6637fe7c98fSJerin Jacob 6647fe7c98fSJerin Jacob res = octeontx_pko_channel_query_dqs(nic->base_ochan, 6657fe7c98fSJerin Jacob &txq->dq, 6667fe7c98fSJerin Jacob sizeof(octeontx_dq_t), 6677fe7c98fSJerin Jacob txq->queue_id, 6687fe7c98fSJerin Jacob octeontx_dq_info_getter); 6697fe7c98fSJerin Jacob if (res < 0) { 6707fe7c98fSJerin Jacob res = -EFAULT; 6717fe7c98fSJerin Jacob goto close_port; 6727fe7c98fSJerin Jacob } 6737fe7c98fSJerin Jacob 6747fe7c98fSJerin Jacob dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED; 6757fe7c98fSJerin Jacob return res; 6767fe7c98fSJerin Jacob 6777fe7c98fSJerin Jacob close_port: 6787fe7c98fSJerin Jacob (void)octeontx_port_stop(nic); 6797fe7c98fSJerin Jacob octeontx_pko_channel_stop(nic->base_ochan); 6807fe7c98fSJerin Jacob octeontx_pko_channel_close(nic->base_ochan); 6817fe7c98fSJerin Jacob dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED; 6827fe7c98fSJerin Jacob return res; 6837fe7c98fSJerin Jacob } 6847fe7c98fSJerin Jacob 6857fe7c98fSJerin Jacob static int 6867fe7c98fSJerin Jacob octeontx_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx) 6877fe7c98fSJerin Jacob { 6887fe7c98fSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 6897fe7c98fSJerin Jacob 6907fe7c98fSJerin Jacob PMD_INIT_FUNC_TRACE(); 6917fe7c98fSJerin Jacob qidx = qidx % PKO_VF_NUM_DQ; 6927fe7c98fSJerin Jacob return octeontx_vf_start_tx_queue(dev, nic, qidx); 6937fe7c98fSJerin Jacob } 6947fe7c98fSJerin Jacob 6957fe7c98fSJerin Jacob static inline int 6967fe7c98fSJerin Jacob octeontx_vf_stop_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic, 6977fe7c98fSJerin Jacob uint16_t qidx) 6987fe7c98fSJerin Jacob { 6997fe7c98fSJerin Jacob int ret = 0; 7007fe7c98fSJerin Jacob 7017fe7c98fSJerin Jacob RTE_SET_USED(nic); 7027fe7c98fSJerin Jacob PMD_INIT_FUNC_TRACE(); 7037fe7c98fSJerin Jacob 7047fe7c98fSJerin Jacob if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED) 7057fe7c98fSJerin Jacob return 0; 7067fe7c98fSJerin Jacob 7077fe7c98fSJerin Jacob dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED; 7087fe7c98fSJerin Jacob return ret; 7097fe7c98fSJerin Jacob } 7107fe7c98fSJerin Jacob 7117fe7c98fSJerin Jacob static int 7127fe7c98fSJerin Jacob octeontx_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx) 7137fe7c98fSJerin Jacob { 7147fe7c98fSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 7157fe7c98fSJerin Jacob 7167fe7c98fSJerin Jacob PMD_INIT_FUNC_TRACE(); 7177fe7c98fSJerin Jacob qidx = qidx % PKO_VF_NUM_DQ; 7187fe7c98fSJerin Jacob 7197fe7c98fSJerin Jacob return octeontx_vf_stop_tx_queue(dev, nic, qidx); 7207fe7c98fSJerin Jacob } 7217fe7c98fSJerin Jacob 722150cbc84SJerin Jacob static void 723150cbc84SJerin Jacob octeontx_dev_tx_queue_release(void *tx_queue) 724150cbc84SJerin Jacob { 725150cbc84SJerin Jacob struct octeontx_txq *txq = tx_queue; 726150cbc84SJerin Jacob int res; 727150cbc84SJerin Jacob 728150cbc84SJerin Jacob PMD_INIT_FUNC_TRACE(); 729150cbc84SJerin Jacob 730150cbc84SJerin Jacob if (txq) { 731150cbc84SJerin Jacob res = octeontx_dev_tx_queue_stop(txq->eth_dev, txq->queue_id); 732150cbc84SJerin Jacob if (res < 0) 733150cbc84SJerin Jacob octeontx_log_err("failed stop tx_queue(%d)\n", 734150cbc84SJerin Jacob txq->queue_id); 735150cbc84SJerin Jacob 736150cbc84SJerin Jacob rte_free(txq); 737150cbc84SJerin Jacob } 738150cbc84SJerin Jacob } 739150cbc84SJerin Jacob 740150cbc84SJerin Jacob static int 741150cbc84SJerin Jacob octeontx_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx, 742150cbc84SJerin Jacob uint16_t nb_desc, unsigned int socket_id, 743150cbc84SJerin Jacob const struct rte_eth_txconf *tx_conf) 744150cbc84SJerin Jacob { 745150cbc84SJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 746150cbc84SJerin Jacob struct octeontx_txq *txq = NULL; 747150cbc84SJerin Jacob uint16_t dq_num; 748150cbc84SJerin Jacob int res = 0; 749150cbc84SJerin Jacob 750150cbc84SJerin Jacob RTE_SET_USED(nb_desc); 751150cbc84SJerin Jacob RTE_SET_USED(socket_id); 752150cbc84SJerin Jacob RTE_SET_USED(tx_conf); 753150cbc84SJerin Jacob 754150cbc84SJerin Jacob dq_num = (nic->port_id * PKO_VF_NUM_DQ) + qidx; 755150cbc84SJerin Jacob 756150cbc84SJerin Jacob /* Socket id check */ 757150cbc84SJerin Jacob if (socket_id != (unsigned int)SOCKET_ID_ANY && 758150cbc84SJerin Jacob socket_id != (unsigned int)nic->node) 759150cbc84SJerin Jacob PMD_TX_LOG(INFO, "socket_id expected %d, configured %d", 760150cbc84SJerin Jacob socket_id, nic->node); 761150cbc84SJerin Jacob 762150cbc84SJerin Jacob /* Free memory prior to re-allocation if needed. */ 763150cbc84SJerin Jacob if (dev->data->tx_queues[qidx] != NULL) { 764150cbc84SJerin Jacob PMD_TX_LOG(DEBUG, "freeing memory prior to re-allocation %d", 765150cbc84SJerin Jacob qidx); 766150cbc84SJerin Jacob octeontx_dev_tx_queue_release(dev->data->tx_queues[qidx]); 767150cbc84SJerin Jacob dev->data->tx_queues[qidx] = NULL; 768150cbc84SJerin Jacob } 769150cbc84SJerin Jacob 770150cbc84SJerin Jacob /* Allocating tx queue data structure */ 771150cbc84SJerin Jacob txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct octeontx_txq), 772150cbc84SJerin Jacob RTE_CACHE_LINE_SIZE, nic->node); 773150cbc84SJerin Jacob if (txq == NULL) { 774150cbc84SJerin Jacob octeontx_log_err("failed to allocate txq=%d", qidx); 775150cbc84SJerin Jacob res = -ENOMEM; 776150cbc84SJerin Jacob goto err; 777150cbc84SJerin Jacob } 778150cbc84SJerin Jacob 779150cbc84SJerin Jacob txq->eth_dev = dev; 780150cbc84SJerin Jacob txq->queue_id = dq_num; 781150cbc84SJerin Jacob dev->data->tx_queues[qidx] = txq; 782150cbc84SJerin Jacob dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED; 783150cbc84SJerin Jacob 784150cbc84SJerin Jacob res = octeontx_pko_channel_query_dqs(nic->base_ochan, 785150cbc84SJerin Jacob &txq->dq, 786150cbc84SJerin Jacob sizeof(octeontx_dq_t), 787150cbc84SJerin Jacob txq->queue_id, 788150cbc84SJerin Jacob octeontx_dq_info_getter); 789150cbc84SJerin Jacob if (res < 0) { 790150cbc84SJerin Jacob res = -EFAULT; 791150cbc84SJerin Jacob goto err; 792150cbc84SJerin Jacob } 793150cbc84SJerin Jacob 794150cbc84SJerin Jacob PMD_TX_LOG(DEBUG, "[%d]:[%d] txq=%p nb_desc=%d lmtline=%p ioreg_va=%p fc_status_va=%p", 795150cbc84SJerin Jacob qidx, txq->queue_id, txq, nb_desc, txq->dq.lmtline_va, 796150cbc84SJerin Jacob txq->dq.ioreg_va, 797150cbc84SJerin Jacob txq->dq.fc_status_va); 798150cbc84SJerin Jacob 799150cbc84SJerin Jacob return res; 800150cbc84SJerin Jacob 801150cbc84SJerin Jacob err: 802150cbc84SJerin Jacob if (txq) 803150cbc84SJerin Jacob rte_free(txq); 804150cbc84SJerin Jacob 805150cbc84SJerin Jacob return res; 806150cbc84SJerin Jacob } 807150cbc84SJerin Jacob 808197438eeSJerin Jacob static int 809197438eeSJerin Jacob octeontx_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx, 810197438eeSJerin Jacob uint16_t nb_desc, unsigned int socket_id, 811197438eeSJerin Jacob const struct rte_eth_rxconf *rx_conf, 812197438eeSJerin Jacob struct rte_mempool *mb_pool) 813197438eeSJerin Jacob { 814197438eeSJerin Jacob struct octeontx_nic *nic = octeontx_pmd_priv(dev); 815197438eeSJerin Jacob struct rte_mempool_ops *mp_ops = NULL; 816197438eeSJerin Jacob struct octeontx_rxq *rxq = NULL; 817197438eeSJerin Jacob pki_pktbuf_cfg_t pktbuf_conf; 818197438eeSJerin Jacob pki_hash_cfg_t pki_hash; 819197438eeSJerin Jacob pki_qos_cfg_t pki_qos; 820197438eeSJerin Jacob uintptr_t pool; 821197438eeSJerin Jacob int ret, port; 822197438eeSJerin Jacob uint8_t gaura; 823197438eeSJerin Jacob unsigned int ev_queues = (nic->ev_queues * nic->port_id) + qidx; 824197438eeSJerin Jacob unsigned int ev_ports = (nic->ev_ports * nic->port_id) + qidx; 825197438eeSJerin Jacob 826197438eeSJerin Jacob RTE_SET_USED(nb_desc); 827197438eeSJerin Jacob 828197438eeSJerin Jacob memset(&pktbuf_conf, 0, sizeof(pktbuf_conf)); 829197438eeSJerin Jacob memset(&pki_hash, 0, sizeof(pki_hash)); 830197438eeSJerin Jacob memset(&pki_qos, 0, sizeof(pki_qos)); 831197438eeSJerin Jacob 832197438eeSJerin Jacob mp_ops = rte_mempool_get_ops(mb_pool->ops_index); 833197438eeSJerin Jacob if (strcmp(mp_ops->name, "octeontx_fpavf")) { 834197438eeSJerin Jacob octeontx_log_err("failed to find octeontx_fpavf mempool"); 835197438eeSJerin Jacob return -ENOTSUP; 836197438eeSJerin Jacob } 837197438eeSJerin Jacob 838197438eeSJerin Jacob /* Handle forbidden configurations */ 839197438eeSJerin Jacob if (nic->pki.classifier_enable) { 840197438eeSJerin Jacob octeontx_log_err("cannot setup queue %d. " 841197438eeSJerin Jacob "Classifier option unsupported", qidx); 842197438eeSJerin Jacob return -EINVAL; 843197438eeSJerin Jacob } 844197438eeSJerin Jacob 845197438eeSJerin Jacob port = nic->port_id; 846197438eeSJerin Jacob 847197438eeSJerin Jacob /* Rx deferred start is not supported */ 848197438eeSJerin Jacob if (rx_conf->rx_deferred_start) { 849197438eeSJerin Jacob octeontx_log_err("rx deferred start not supported"); 850197438eeSJerin Jacob return -EINVAL; 851197438eeSJerin Jacob } 852197438eeSJerin Jacob 853197438eeSJerin Jacob /* Verify queue index */ 854197438eeSJerin Jacob if (qidx >= dev->data->nb_rx_queues) { 855197438eeSJerin Jacob octeontx_log_err("QID %d not supporteded (0 - %d available)\n", 856197438eeSJerin Jacob qidx, (dev->data->nb_rx_queues - 1)); 857197438eeSJerin Jacob return -ENOTSUP; 858197438eeSJerin Jacob } 859197438eeSJerin Jacob 860197438eeSJerin Jacob /* Socket id check */ 861197438eeSJerin Jacob if (socket_id != (unsigned int)SOCKET_ID_ANY && 862197438eeSJerin Jacob socket_id != (unsigned int)nic->node) 863197438eeSJerin Jacob PMD_RX_LOG(INFO, "socket_id expected %d, configured %d", 864197438eeSJerin Jacob socket_id, nic->node); 865197438eeSJerin Jacob 866197438eeSJerin Jacob /* Allocating rx queue data structure */ 867197438eeSJerin Jacob rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct octeontx_rxq), 868197438eeSJerin Jacob RTE_CACHE_LINE_SIZE, nic->node); 869197438eeSJerin Jacob if (rxq == NULL) { 870197438eeSJerin Jacob octeontx_log_err("failed to allocate rxq=%d", qidx); 871197438eeSJerin Jacob return -ENOMEM; 872197438eeSJerin Jacob } 873197438eeSJerin Jacob 874197438eeSJerin Jacob if (!nic->pki.initialized) { 875197438eeSJerin Jacob pktbuf_conf.port_type = 0; 876197438eeSJerin Jacob pki_hash.port_type = 0; 877197438eeSJerin Jacob pki_qos.port_type = 0; 878197438eeSJerin Jacob 879197438eeSJerin Jacob pktbuf_conf.mmask.f_wqe_skip = 1; 880197438eeSJerin Jacob pktbuf_conf.mmask.f_first_skip = 1; 881197438eeSJerin Jacob pktbuf_conf.mmask.f_later_skip = 1; 882197438eeSJerin Jacob pktbuf_conf.mmask.f_mbuff_size = 1; 883197438eeSJerin Jacob pktbuf_conf.mmask.f_cache_mode = 1; 884197438eeSJerin Jacob 885197438eeSJerin Jacob pktbuf_conf.wqe_skip = OCTTX_PACKET_WQE_SKIP; 886197438eeSJerin Jacob pktbuf_conf.first_skip = OCTTX_PACKET_FIRST_SKIP; 887197438eeSJerin Jacob pktbuf_conf.later_skip = OCTTX_PACKET_LATER_SKIP; 888197438eeSJerin Jacob pktbuf_conf.mbuff_size = (mb_pool->elt_size - 889197438eeSJerin Jacob RTE_PKTMBUF_HEADROOM - 890197438eeSJerin Jacob sizeof(struct rte_mbuf)); 891197438eeSJerin Jacob 892197438eeSJerin Jacob pktbuf_conf.cache_mode = PKI_OPC_MODE_STF2_STT; 893197438eeSJerin Jacob 894197438eeSJerin Jacob ret = octeontx_pki_port_pktbuf_config(port, &pktbuf_conf); 895197438eeSJerin Jacob if (ret != 0) { 896197438eeSJerin Jacob octeontx_log_err("fail to configure pktbuf for port %d", 897197438eeSJerin Jacob port); 898197438eeSJerin Jacob rte_free(rxq); 899197438eeSJerin Jacob return ret; 900197438eeSJerin Jacob } 901197438eeSJerin Jacob PMD_RX_LOG(DEBUG, "Port %d Rx pktbuf configured:\n" 902197438eeSJerin Jacob "\tmbuf_size:\t0x%0x\n" 903197438eeSJerin Jacob "\twqe_skip:\t0x%0x\n" 904197438eeSJerin Jacob "\tfirst_skip:\t0x%0x\n" 905197438eeSJerin Jacob "\tlater_skip:\t0x%0x\n" 906197438eeSJerin Jacob "\tcache_mode:\t%s\n", 907197438eeSJerin Jacob port, 908197438eeSJerin Jacob pktbuf_conf.mbuff_size, 909197438eeSJerin Jacob pktbuf_conf.wqe_skip, 910197438eeSJerin Jacob pktbuf_conf.first_skip, 911197438eeSJerin Jacob pktbuf_conf.later_skip, 912197438eeSJerin Jacob (pktbuf_conf.cache_mode == 913197438eeSJerin Jacob PKI_OPC_MODE_STT) ? 914197438eeSJerin Jacob "STT" : 915197438eeSJerin Jacob (pktbuf_conf.cache_mode == 916197438eeSJerin Jacob PKI_OPC_MODE_STF) ? 917197438eeSJerin Jacob "STF" : 918197438eeSJerin Jacob (pktbuf_conf.cache_mode == 919197438eeSJerin Jacob PKI_OPC_MODE_STF1_STT) ? 920197438eeSJerin Jacob "STF1_STT" : "STF2_STT"); 921197438eeSJerin Jacob 922197438eeSJerin Jacob if (nic->pki.hash_enable) { 923197438eeSJerin Jacob pki_hash.tag_dlc = 1; 924197438eeSJerin Jacob pki_hash.tag_slc = 1; 925197438eeSJerin Jacob pki_hash.tag_dlf = 1; 926197438eeSJerin Jacob pki_hash.tag_slf = 1; 927d0d65498SPavan Nikhilesh pki_hash.tag_prt = 1; 928197438eeSJerin Jacob octeontx_pki_port_hash_config(port, &pki_hash); 929197438eeSJerin Jacob } 930197438eeSJerin Jacob 931197438eeSJerin Jacob pool = (uintptr_t)mb_pool->pool_id; 932197438eeSJerin Jacob 933197438eeSJerin Jacob /* Get the gpool Id */ 934197438eeSJerin Jacob gaura = octeontx_fpa_bufpool_gpool(pool); 935197438eeSJerin Jacob 936197438eeSJerin Jacob pki_qos.qpg_qos = PKI_QPG_QOS_NONE; 937197438eeSJerin Jacob pki_qos.num_entry = 1; 938197438eeSJerin Jacob pki_qos.drop_policy = 0; 939d0d65498SPavan Nikhilesh pki_qos.tag_type = 0L; 940197438eeSJerin Jacob pki_qos.qos_entry[0].port_add = 0; 941197438eeSJerin Jacob pki_qos.qos_entry[0].gaura = gaura; 942197438eeSJerin Jacob pki_qos.qos_entry[0].ggrp_ok = ev_queues; 943197438eeSJerin Jacob pki_qos.qos_entry[0].ggrp_bad = ev_queues; 944197438eeSJerin Jacob pki_qos.qos_entry[0].grptag_bad = 0; 945197438eeSJerin Jacob pki_qos.qos_entry[0].grptag_ok = 0; 946197438eeSJerin Jacob 947197438eeSJerin Jacob ret = octeontx_pki_port_create_qos(port, &pki_qos); 948197438eeSJerin Jacob if (ret < 0) { 949197438eeSJerin Jacob octeontx_log_err("failed to create QOS port=%d, q=%d", 950197438eeSJerin Jacob port, qidx); 951197438eeSJerin Jacob rte_free(rxq); 952197438eeSJerin Jacob return ret; 953197438eeSJerin Jacob } 954197438eeSJerin Jacob nic->pki.initialized = true; 955197438eeSJerin Jacob } 956197438eeSJerin Jacob 957197438eeSJerin Jacob rxq->port_id = nic->port_id; 958197438eeSJerin Jacob rxq->eth_dev = dev; 959197438eeSJerin Jacob rxq->queue_id = qidx; 960197438eeSJerin Jacob rxq->evdev = nic->evdev; 961197438eeSJerin Jacob rxq->ev_queues = ev_queues; 962197438eeSJerin Jacob rxq->ev_ports = ev_ports; 963197438eeSJerin Jacob 964197438eeSJerin Jacob dev->data->rx_queues[qidx] = rxq; 965197438eeSJerin Jacob dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED; 966197438eeSJerin Jacob return 0; 967197438eeSJerin Jacob } 968197438eeSJerin Jacob 969197438eeSJerin Jacob static void 970197438eeSJerin Jacob octeontx_dev_rx_queue_release(void *rxq) 971197438eeSJerin Jacob { 972197438eeSJerin Jacob rte_free(rxq); 973197438eeSJerin Jacob } 974197438eeSJerin Jacob 97520186d43SJerin Jacob static const uint32_t * 97620186d43SJerin Jacob octeontx_dev_supported_ptypes_get(struct rte_eth_dev *dev) 97720186d43SJerin Jacob { 97820186d43SJerin Jacob static const uint32_t ptypes[] = { 97920186d43SJerin Jacob RTE_PTYPE_L3_IPV4, 98020186d43SJerin Jacob RTE_PTYPE_L3_IPV4_EXT, 98120186d43SJerin Jacob RTE_PTYPE_L3_IPV6, 98220186d43SJerin Jacob RTE_PTYPE_L3_IPV6_EXT, 98320186d43SJerin Jacob RTE_PTYPE_L4_TCP, 98420186d43SJerin Jacob RTE_PTYPE_L4_UDP, 98520186d43SJerin Jacob RTE_PTYPE_L4_FRAG, 98620186d43SJerin Jacob RTE_PTYPE_UNKNOWN 98720186d43SJerin Jacob }; 98820186d43SJerin Jacob 98920186d43SJerin Jacob if (dev->rx_pkt_burst == octeontx_recv_pkts) 99020186d43SJerin Jacob return ptypes; 99120186d43SJerin Jacob 99220186d43SJerin Jacob return NULL; 99320186d43SJerin Jacob } 99420186d43SJerin Jacob 9955452a17dSPavan Nikhilesh static int 9965452a17dSPavan Nikhilesh octeontx_pool_ops(struct rte_eth_dev *dev, const char *pool) 9975452a17dSPavan Nikhilesh { 9985452a17dSPavan Nikhilesh RTE_SET_USED(dev); 9995452a17dSPavan Nikhilesh 10005452a17dSPavan Nikhilesh if (!strcmp(pool, "octeontx_fpavf")) 10015452a17dSPavan Nikhilesh return 0; 10025452a17dSPavan Nikhilesh 10035452a17dSPavan Nikhilesh return -ENOTSUP; 10045452a17dSPavan Nikhilesh } 10055452a17dSPavan Nikhilesh 1006f18b146cSJerin Jacob /* Initialize and register driver with DPDK Application */ 1007f18b146cSJerin Jacob static const struct eth_dev_ops octeontx_dev_ops = { 10087742c55aSJerin Jacob .dev_configure = octeontx_dev_configure, 10097c0347a2SJerin Jacob .dev_infos_get = octeontx_dev_info, 1010da6c6874SJerin Jacob .dev_close = octeontx_dev_close, 1011da6c6874SJerin Jacob .dev_start = octeontx_dev_start, 1012da6c6874SJerin Jacob .dev_stop = octeontx_dev_stop, 101315bce35bSJerin Jacob .promiscuous_enable = octeontx_dev_promisc_enable, 101415bce35bSJerin Jacob .promiscuous_disable = octeontx_dev_promisc_disable, 10154fac7c0aSJerin Jacob .link_update = octeontx_dev_link_update, 101655389909SJerin Jacob .stats_get = octeontx_dev_stats_get, 101755389909SJerin Jacob .stats_reset = octeontx_dev_stats_reset, 1018ef7308fcSJerin Jacob .mac_addr_set = octeontx_dev_default_mac_addr_set, 10197fe7c98fSJerin Jacob .tx_queue_start = octeontx_dev_tx_queue_start, 10207fe7c98fSJerin Jacob .tx_queue_stop = octeontx_dev_tx_queue_stop, 1021150cbc84SJerin Jacob .tx_queue_setup = octeontx_dev_tx_queue_setup, 1022150cbc84SJerin Jacob .tx_queue_release = octeontx_dev_tx_queue_release, 1023197438eeSJerin Jacob .rx_queue_setup = octeontx_dev_rx_queue_setup, 1024197438eeSJerin Jacob .rx_queue_release = octeontx_dev_rx_queue_release, 102520186d43SJerin Jacob .dev_supported_ptypes_get = octeontx_dev_supported_ptypes_get, 10265452a17dSPavan Nikhilesh .pool_ops_supported = octeontx_pool_ops, 1027f18b146cSJerin Jacob }; 1028f18b146cSJerin Jacob 1029f7be70e5SJerin Jacob /* Create Ethdev interface per BGX LMAC ports */ 1030f7be70e5SJerin Jacob static int 1031f7be70e5SJerin Jacob octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev, 1032f7be70e5SJerin Jacob int socket_id) 1033f7be70e5SJerin Jacob { 1034f18b146cSJerin Jacob int res; 1035f18b146cSJerin Jacob char octtx_name[OCTEONTX_MAX_NAME_LEN]; 1036f18b146cSJerin Jacob struct octeontx_nic *nic = NULL; 1037f18b146cSJerin Jacob struct rte_eth_dev *eth_dev = NULL; 1038f18b146cSJerin Jacob struct rte_eth_dev_data *data = NULL; 1039f18b146cSJerin Jacob const char *name = rte_vdev_device_name(dev); 1040f7be70e5SJerin Jacob 1041f18b146cSJerin Jacob PMD_INIT_FUNC_TRACE(); 1042f18b146cSJerin Jacob 1043f18b146cSJerin Jacob sprintf(octtx_name, "%s_%d", name, port); 1044f18b146cSJerin Jacob if (rte_eal_process_type() != RTE_PROC_PRIMARY) { 1045f18b146cSJerin Jacob eth_dev = rte_eth_dev_attach_secondary(octtx_name); 1046f18b146cSJerin Jacob if (eth_dev == NULL) 1047f7be70e5SJerin Jacob return -ENODEV; 1048f18b146cSJerin Jacob 1049da6c6874SJerin Jacob eth_dev->tx_pkt_burst = octeontx_xmit_pkts; 1050da6c6874SJerin Jacob eth_dev->rx_pkt_burst = octeontx_recv_pkts; 1051f18b146cSJerin Jacob return 0; 1052f18b146cSJerin Jacob } 1053f18b146cSJerin Jacob 1054f18b146cSJerin Jacob data = rte_zmalloc_socket(octtx_name, sizeof(*data), 0, socket_id); 1055f18b146cSJerin Jacob if (data == NULL) { 1056f18b146cSJerin Jacob octeontx_log_err("failed to allocate devdata"); 1057f18b146cSJerin Jacob res = -ENOMEM; 1058f18b146cSJerin Jacob goto err; 1059f18b146cSJerin Jacob } 1060f18b146cSJerin Jacob 1061f18b146cSJerin Jacob nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id); 1062f18b146cSJerin Jacob if (nic == NULL) { 1063f18b146cSJerin Jacob octeontx_log_err("failed to allocate nic structure"); 1064f18b146cSJerin Jacob res = -ENOMEM; 1065f18b146cSJerin Jacob goto err; 1066f18b146cSJerin Jacob } 1067f18b146cSJerin Jacob 1068f18b146cSJerin Jacob nic->port_id = port; 1069f18b146cSJerin Jacob nic->evdev = evdev; 1070f18b146cSJerin Jacob 1071f18b146cSJerin Jacob res = octeontx_port_open(nic); 1072f18b146cSJerin Jacob if (res < 0) 1073f18b146cSJerin Jacob goto err; 1074f18b146cSJerin Jacob 1075f18b146cSJerin Jacob /* Rx side port configuration */ 1076f18b146cSJerin Jacob res = octeontx_pki_port_open(port); 1077f18b146cSJerin Jacob if (res != 0) { 1078f18b146cSJerin Jacob octeontx_log_err("failed to open PKI port %d", port); 1079f18b146cSJerin Jacob res = -ENODEV; 1080f18b146cSJerin Jacob goto err; 1081f18b146cSJerin Jacob } 1082f18b146cSJerin Jacob 1083f18b146cSJerin Jacob /* Reserve an ethdev entry */ 1084f18b146cSJerin Jacob eth_dev = rte_eth_dev_allocate(octtx_name); 1085f18b146cSJerin Jacob if (eth_dev == NULL) { 1086f18b146cSJerin Jacob octeontx_log_err("failed to allocate rte_eth_dev"); 1087f18b146cSJerin Jacob res = -ENOMEM; 1088f18b146cSJerin Jacob goto err; 1089f18b146cSJerin Jacob } 1090f18b146cSJerin Jacob 1091f18b146cSJerin Jacob eth_dev->device = &dev->device; 1092f18b146cSJerin Jacob eth_dev->intr_handle = NULL; 1093f18b146cSJerin Jacob eth_dev->data->kdrv = RTE_KDRV_NONE; 1094f18b146cSJerin Jacob eth_dev->data->numa_node = dev->device.numa_node; 1095f18b146cSJerin Jacob 1096f18b146cSJerin Jacob rte_memcpy(data, (eth_dev)->data, sizeof(*data)); 1097f18b146cSJerin Jacob data->dev_private = nic; 1098f18b146cSJerin Jacob 1099f18b146cSJerin Jacob data->port_id = eth_dev->data->port_id; 1100f18b146cSJerin Jacob snprintf(data->name, sizeof(data->name), "%s", eth_dev->data->name); 1101f18b146cSJerin Jacob 1102f18b146cSJerin Jacob nic->ev_queues = 1; 1103f18b146cSJerin Jacob nic->ev_ports = 1; 1104f18b146cSJerin Jacob 1105f18b146cSJerin Jacob data->dev_link.link_status = ETH_LINK_DOWN; 1106f18b146cSJerin Jacob data->dev_started = 0; 1107f18b146cSJerin Jacob data->promiscuous = 0; 1108f18b146cSJerin Jacob data->all_multicast = 0; 1109f18b146cSJerin Jacob data->scattered_rx = 0; 1110f18b146cSJerin Jacob 1111f18b146cSJerin Jacob data->mac_addrs = rte_zmalloc_socket(octtx_name, ETHER_ADDR_LEN, 0, 1112f18b146cSJerin Jacob socket_id); 1113f18b146cSJerin Jacob if (data->mac_addrs == NULL) { 1114f18b146cSJerin Jacob octeontx_log_err("failed to allocate memory for mac_addrs"); 1115f18b146cSJerin Jacob res = -ENOMEM; 1116f18b146cSJerin Jacob goto err; 1117f18b146cSJerin Jacob } 1118f18b146cSJerin Jacob 1119f18b146cSJerin Jacob eth_dev->data = data; 1120f18b146cSJerin Jacob eth_dev->dev_ops = &octeontx_dev_ops; 1121f18b146cSJerin Jacob 1122f18b146cSJerin Jacob /* Finally save ethdev pointer to the NIC structure */ 1123f18b146cSJerin Jacob nic->dev = eth_dev; 1124f18b146cSJerin Jacob 1125f18b146cSJerin Jacob if (nic->port_id != data->port_id) { 1126f18b146cSJerin Jacob octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)", 1127f18b146cSJerin Jacob data->port_id, nic->port_id); 1128f18b146cSJerin Jacob res = -EINVAL; 1129f18b146cSJerin Jacob goto err; 1130f18b146cSJerin Jacob } 1131f18b146cSJerin Jacob 1132f18b146cSJerin Jacob /* Update port_id mac to eth_dev */ 1133f18b146cSJerin Jacob memcpy(data->mac_addrs, nic->mac_addr, ETHER_ADDR_LEN); 1134f18b146cSJerin Jacob 1135f18b146cSJerin Jacob PMD_INIT_LOG(DEBUG, "ethdev info: "); 1136f18b146cSJerin Jacob PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d", 1137f18b146cSJerin Jacob nic->port_id, nic->port_ena, 1138f18b146cSJerin Jacob nic->base_ochan, nic->num_ochans, 1139f18b146cSJerin Jacob nic->num_tx_queues); 1140f18b146cSJerin Jacob PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->mtu); 1141f18b146cSJerin Jacob 1142f18b146cSJerin Jacob return data->port_id; 1143f18b146cSJerin Jacob 1144f18b146cSJerin Jacob err: 1145f18b146cSJerin Jacob if (port) 1146f18b146cSJerin Jacob octeontx_port_close(nic); 1147f18b146cSJerin Jacob 1148f18b146cSJerin Jacob if (eth_dev != NULL) { 1149f18b146cSJerin Jacob rte_free(eth_dev->data->mac_addrs); 1150f18b146cSJerin Jacob rte_free(data); 1151f18b146cSJerin Jacob rte_free(nic); 1152f18b146cSJerin Jacob rte_eth_dev_release_port(eth_dev); 1153f18b146cSJerin Jacob } 1154f18b146cSJerin Jacob 1155f18b146cSJerin Jacob return res; 1156f7be70e5SJerin Jacob } 1157f7be70e5SJerin Jacob 1158f7be70e5SJerin Jacob /* Un initialize octeontx device */ 1159f7be70e5SJerin Jacob static int 1160f7be70e5SJerin Jacob octeontx_remove(struct rte_vdev_device *dev) 1161f7be70e5SJerin Jacob { 1162f7be70e5SJerin Jacob char octtx_name[OCTEONTX_MAX_NAME_LEN]; 1163f7be70e5SJerin Jacob struct rte_eth_dev *eth_dev = NULL; 1164f7be70e5SJerin Jacob struct octeontx_nic *nic = NULL; 1165f7be70e5SJerin Jacob int i; 1166f7be70e5SJerin Jacob 1167f7be70e5SJerin Jacob if (dev == NULL) 1168f7be70e5SJerin Jacob return -EINVAL; 1169f7be70e5SJerin Jacob 1170f7be70e5SJerin Jacob for (i = 0; i < OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT; i++) { 1171f7be70e5SJerin Jacob sprintf(octtx_name, "eth_octeontx_%d", i); 1172f7be70e5SJerin Jacob 1173f7be70e5SJerin Jacob /* reserve an ethdev entry */ 1174f7be70e5SJerin Jacob eth_dev = rte_eth_dev_allocated(octtx_name); 1175f7be70e5SJerin Jacob if (eth_dev == NULL) 1176f7be70e5SJerin Jacob return -ENODEV; 1177f7be70e5SJerin Jacob 1178f7be70e5SJerin Jacob nic = octeontx_pmd_priv(eth_dev); 1179f7be70e5SJerin Jacob rte_event_dev_stop(nic->evdev); 1180f7be70e5SJerin Jacob PMD_INIT_LOG(INFO, "Closing octeontx device %s", octtx_name); 1181f7be70e5SJerin Jacob 1182f7be70e5SJerin Jacob rte_free(eth_dev->data->mac_addrs); 1183f7be70e5SJerin Jacob rte_free(eth_dev->data->dev_private); 1184f7be70e5SJerin Jacob rte_free(eth_dev->data); 1185f7be70e5SJerin Jacob rte_eth_dev_release_port(eth_dev); 1186f7be70e5SJerin Jacob rte_event_dev_close(nic->evdev); 1187f7be70e5SJerin Jacob } 1188f7be70e5SJerin Jacob 1189f7be70e5SJerin Jacob /* Free FC resource */ 1190f7be70e5SJerin Jacob octeontx_pko_fc_free(); 1191f7be70e5SJerin Jacob 1192f7be70e5SJerin Jacob return 0; 1193f7be70e5SJerin Jacob } 1194f7be70e5SJerin Jacob 1195f7be70e5SJerin Jacob /* Initialize octeontx device */ 1196f7be70e5SJerin Jacob static int 1197f7be70e5SJerin Jacob octeontx_probe(struct rte_vdev_device *dev) 1198f7be70e5SJerin Jacob { 1199f7be70e5SJerin Jacob const char *dev_name; 1200f7be70e5SJerin Jacob static int probe_once; 1201f7be70e5SJerin Jacob uint8_t socket_id, qlist; 1202f7be70e5SJerin Jacob int tx_vfcnt, port_id, evdev, qnum, pnum, res, i; 1203f7be70e5SJerin Jacob struct rte_event_dev_config dev_conf; 1204f7be70e5SJerin Jacob const char *eventdev_name = "event_octeontx"; 1205f7be70e5SJerin Jacob struct rte_event_dev_info info; 1206f7be70e5SJerin Jacob 1207f7be70e5SJerin Jacob struct octeontx_vdev_init_params init_params = { 1208f7be70e5SJerin Jacob OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT 1209f7be70e5SJerin Jacob }; 1210f7be70e5SJerin Jacob 1211f7be70e5SJerin Jacob dev_name = rte_vdev_device_name(dev); 1212f7be70e5SJerin Jacob res = octeontx_parse_vdev_init_params(&init_params, dev); 1213f7be70e5SJerin Jacob if (res < 0) 1214f7be70e5SJerin Jacob return -EINVAL; 1215f7be70e5SJerin Jacob 1216f7be70e5SJerin Jacob if (init_params.nr_port > OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT) { 1217f7be70e5SJerin Jacob octeontx_log_err("nr_port (%d) > max (%d)", init_params.nr_port, 1218f7be70e5SJerin Jacob OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT); 1219f7be70e5SJerin Jacob return -ENOTSUP; 1220f7be70e5SJerin Jacob } 1221f7be70e5SJerin Jacob 1222f7be70e5SJerin Jacob PMD_INIT_LOG(DEBUG, "initializing %s pmd", dev_name); 1223f7be70e5SJerin Jacob 1224f7be70e5SJerin Jacob socket_id = rte_socket_id(); 1225f7be70e5SJerin Jacob 1226f7be70e5SJerin Jacob tx_vfcnt = octeontx_pko_vf_count(); 1227f7be70e5SJerin Jacob 1228f7be70e5SJerin Jacob if (tx_vfcnt < init_params.nr_port) { 1229f7be70e5SJerin Jacob octeontx_log_err("not enough PKO (%d) for port number (%d)", 1230f7be70e5SJerin Jacob tx_vfcnt, init_params.nr_port); 1231f7be70e5SJerin Jacob return -EINVAL; 1232f7be70e5SJerin Jacob } 1233f7be70e5SJerin Jacob evdev = rte_event_dev_get_dev_id(eventdev_name); 1234f7be70e5SJerin Jacob if (evdev < 0) { 1235f7be70e5SJerin Jacob octeontx_log_err("eventdev %s not found", eventdev_name); 1236f7be70e5SJerin Jacob return -ENODEV; 1237f7be70e5SJerin Jacob } 1238f7be70e5SJerin Jacob 1239f7be70e5SJerin Jacob res = rte_event_dev_info_get(evdev, &info); 1240f7be70e5SJerin Jacob if (res < 0) { 1241f7be70e5SJerin Jacob octeontx_log_err("failed to eventdev info %d", res); 1242f7be70e5SJerin Jacob return -EINVAL; 1243f7be70e5SJerin Jacob } 1244f7be70e5SJerin Jacob 1245f7be70e5SJerin Jacob PMD_INIT_LOG(DEBUG, "max_queue %d max_port %d", 1246f7be70e5SJerin Jacob info.max_event_queues, info.max_event_ports); 1247f7be70e5SJerin Jacob 1248f7be70e5SJerin Jacob if (octeontx_pko_init_fc(tx_vfcnt)) 1249f7be70e5SJerin Jacob return -ENOMEM; 1250f7be70e5SJerin Jacob 1251f7be70e5SJerin Jacob devconf_set_default_sane_values(&dev_conf, &info); 1252f7be70e5SJerin Jacob res = rte_event_dev_configure(evdev, &dev_conf); 1253f7be70e5SJerin Jacob if (res < 0) 1254f7be70e5SJerin Jacob goto parse_error; 1255f7be70e5SJerin Jacob 1256f7be70e5SJerin Jacob rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT, 1257f7be70e5SJerin Jacob (uint32_t *)&pnum); 1258f7be70e5SJerin Jacob rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT, 1259f7be70e5SJerin Jacob (uint32_t *)&qnum); 1260f7be70e5SJerin Jacob if (pnum < qnum) { 1261f7be70e5SJerin Jacob octeontx_log_err("too few event ports (%d) for event_q(%d)", 1262f7be70e5SJerin Jacob pnum, qnum); 1263f7be70e5SJerin Jacob res = -EINVAL; 1264f7be70e5SJerin Jacob goto parse_error; 1265f7be70e5SJerin Jacob } 1266f7be70e5SJerin Jacob if (pnum > qnum) { 1267f7be70e5SJerin Jacob /* 1268f7be70e5SJerin Jacob * We don't poll on event ports 1269f7be70e5SJerin Jacob * that do not have any queues assigned. 1270f7be70e5SJerin Jacob */ 1271f7be70e5SJerin Jacob pnum = qnum; 1272f7be70e5SJerin Jacob PMD_INIT_LOG(INFO, 1273f7be70e5SJerin Jacob "reducing number of active event ports to %d", pnum); 1274f7be70e5SJerin Jacob } 1275f7be70e5SJerin Jacob for (i = 0; i < qnum; i++) { 1276f7be70e5SJerin Jacob res = rte_event_queue_setup(evdev, i, NULL); 1277f7be70e5SJerin Jacob if (res < 0) { 1278f7be70e5SJerin Jacob octeontx_log_err("failed to setup event_q(%d): res %d", 1279f7be70e5SJerin Jacob i, res); 1280f7be70e5SJerin Jacob goto parse_error; 1281f7be70e5SJerin Jacob } 1282f7be70e5SJerin Jacob } 1283f7be70e5SJerin Jacob 1284f7be70e5SJerin Jacob for (i = 0; i < pnum; i++) { 1285f7be70e5SJerin Jacob res = rte_event_port_setup(evdev, i, NULL); 1286f7be70e5SJerin Jacob if (res < 0) { 1287f7be70e5SJerin Jacob res = -ENODEV; 1288f7be70e5SJerin Jacob octeontx_log_err("failed to setup ev port(%d) res=%d", 1289f7be70e5SJerin Jacob i, res); 1290f7be70e5SJerin Jacob goto parse_error; 1291f7be70e5SJerin Jacob } 1292f7be70e5SJerin Jacob /* Link one queue to one event port */ 1293f7be70e5SJerin Jacob qlist = i; 1294f7be70e5SJerin Jacob res = rte_event_port_link(evdev, i, &qlist, NULL, 1); 1295f7be70e5SJerin Jacob if (res < 0) { 1296f7be70e5SJerin Jacob res = -ENODEV; 1297f7be70e5SJerin Jacob octeontx_log_err("failed to link port (%d): res=%d", 1298f7be70e5SJerin Jacob i, res); 1299f7be70e5SJerin Jacob goto parse_error; 1300f7be70e5SJerin Jacob } 1301f7be70e5SJerin Jacob } 1302f7be70e5SJerin Jacob 1303f7be70e5SJerin Jacob /* Create ethdev interface */ 1304f7be70e5SJerin Jacob for (i = 0; i < init_params.nr_port; i++) { 1305f7be70e5SJerin Jacob port_id = octeontx_create(dev, i, evdev, socket_id); 1306f7be70e5SJerin Jacob if (port_id < 0) { 1307f7be70e5SJerin Jacob octeontx_log_err("failed to create device %s", 1308f7be70e5SJerin Jacob dev_name); 1309f7be70e5SJerin Jacob res = -ENODEV; 1310f7be70e5SJerin Jacob goto parse_error; 1311f7be70e5SJerin Jacob } 1312f7be70e5SJerin Jacob 1313f7be70e5SJerin Jacob PMD_INIT_LOG(INFO, "created ethdev %s for port %d", dev_name, 1314f7be70e5SJerin Jacob port_id); 1315f7be70e5SJerin Jacob } 1316f7be70e5SJerin Jacob 1317f7be70e5SJerin Jacob if (probe_once) { 1318f7be70e5SJerin Jacob octeontx_log_err("interface %s not supported", dev_name); 1319f7be70e5SJerin Jacob octeontx_remove(dev); 1320f7be70e5SJerin Jacob res = -ENOTSUP; 1321f7be70e5SJerin Jacob goto parse_error; 1322f7be70e5SJerin Jacob } 1323f7be70e5SJerin Jacob probe_once = 1; 1324f7be70e5SJerin Jacob 1325f7be70e5SJerin Jacob return 0; 1326f7be70e5SJerin Jacob 1327f7be70e5SJerin Jacob parse_error: 1328f7be70e5SJerin Jacob octeontx_pko_fc_free(); 1329f7be70e5SJerin Jacob return res; 1330f7be70e5SJerin Jacob } 1331f7be70e5SJerin Jacob 1332f7be70e5SJerin Jacob static struct rte_vdev_driver octeontx_pmd_drv = { 1333f7be70e5SJerin Jacob .probe = octeontx_probe, 1334f7be70e5SJerin Jacob .remove = octeontx_remove, 1335f7be70e5SJerin Jacob }; 1336f7be70e5SJerin Jacob 1337f7be70e5SJerin Jacob RTE_PMD_REGISTER_VDEV(OCTEONTX_PMD, octeontx_pmd_drv); 1338f7be70e5SJerin Jacob RTE_PMD_REGISTER_ALIAS(OCTEONTX_PMD, eth_octeontx); 1339f7be70e5SJerin Jacob RTE_PMD_REGISTER_PARAM_STRING(OCTEONTX_PMD, "nr_port=<int> "); 1340