xref: /dpdk/drivers/net/octeontx/octeontx_ethdev.c (revision 7fe7c98feca5c6bec7eeecbaa31552e9c91ae258)
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 					&params->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 
163*7fe7c98fSJerin Jacob static int
164*7fe7c98fSJerin Jacob octeontx_port_stop(struct octeontx_nic *nic)
165*7fe7c98fSJerin Jacob {
166*7fe7c98fSJerin Jacob 	PMD_INIT_FUNC_TRACE();
167*7fe7c98fSJerin Jacob 
168*7fe7c98fSJerin Jacob 	return octeontx_bgx_port_stop(nic->port_id);
169*7fe7c98fSJerin Jacob }
170*7fe7c98fSJerin 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 
511*7fe7c98fSJerin Jacob static void
512*7fe7c98fSJerin Jacob octeontx_dq_info_getter(octeontx_dq_t *dq, void *out)
513*7fe7c98fSJerin Jacob {
514*7fe7c98fSJerin Jacob 	((octeontx_dq_t *)out)->lmtline_va = dq->lmtline_va;
515*7fe7c98fSJerin Jacob 	((octeontx_dq_t *)out)->ioreg_va = dq->ioreg_va;
516*7fe7c98fSJerin Jacob 	((octeontx_dq_t *)out)->fc_status_va = dq->fc_status_va;
517*7fe7c98fSJerin Jacob }
518*7fe7c98fSJerin Jacob 
519*7fe7c98fSJerin Jacob static int
520*7fe7c98fSJerin Jacob octeontx_vf_start_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
521*7fe7c98fSJerin Jacob 				uint16_t qidx)
522*7fe7c98fSJerin Jacob {
523*7fe7c98fSJerin Jacob 	struct octeontx_txq *txq;
524*7fe7c98fSJerin Jacob 	int res;
525*7fe7c98fSJerin Jacob 
526*7fe7c98fSJerin Jacob 	PMD_INIT_FUNC_TRACE();
527*7fe7c98fSJerin Jacob 
528*7fe7c98fSJerin Jacob 	if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED)
529*7fe7c98fSJerin Jacob 		return 0;
530*7fe7c98fSJerin Jacob 
531*7fe7c98fSJerin Jacob 	txq = dev->data->tx_queues[qidx];
532*7fe7c98fSJerin Jacob 
533*7fe7c98fSJerin Jacob 	res = octeontx_pko_channel_query_dqs(nic->base_ochan,
534*7fe7c98fSJerin Jacob 						&txq->dq,
535*7fe7c98fSJerin Jacob 						sizeof(octeontx_dq_t),
536*7fe7c98fSJerin Jacob 						txq->queue_id,
537*7fe7c98fSJerin Jacob 						octeontx_dq_info_getter);
538*7fe7c98fSJerin Jacob 	if (res < 0) {
539*7fe7c98fSJerin Jacob 		res = -EFAULT;
540*7fe7c98fSJerin Jacob 		goto close_port;
541*7fe7c98fSJerin Jacob 	}
542*7fe7c98fSJerin Jacob 
543*7fe7c98fSJerin Jacob 	dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
544*7fe7c98fSJerin Jacob 	return res;
545*7fe7c98fSJerin Jacob 
546*7fe7c98fSJerin Jacob close_port:
547*7fe7c98fSJerin Jacob 	(void)octeontx_port_stop(nic);
548*7fe7c98fSJerin Jacob 	octeontx_pko_channel_stop(nic->base_ochan);
549*7fe7c98fSJerin Jacob 	octeontx_pko_channel_close(nic->base_ochan);
550*7fe7c98fSJerin Jacob 	dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
551*7fe7c98fSJerin Jacob 	return res;
552*7fe7c98fSJerin Jacob }
553*7fe7c98fSJerin Jacob 
554*7fe7c98fSJerin Jacob static int
555*7fe7c98fSJerin Jacob octeontx_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
556*7fe7c98fSJerin Jacob {
557*7fe7c98fSJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
558*7fe7c98fSJerin Jacob 
559*7fe7c98fSJerin Jacob 	PMD_INIT_FUNC_TRACE();
560*7fe7c98fSJerin Jacob 	qidx = qidx % PKO_VF_NUM_DQ;
561*7fe7c98fSJerin Jacob 	return octeontx_vf_start_tx_queue(dev, nic, qidx);
562*7fe7c98fSJerin Jacob }
563*7fe7c98fSJerin Jacob 
564*7fe7c98fSJerin Jacob static inline int
565*7fe7c98fSJerin Jacob octeontx_vf_stop_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
566*7fe7c98fSJerin Jacob 			  uint16_t qidx)
567*7fe7c98fSJerin Jacob {
568*7fe7c98fSJerin Jacob 	int ret = 0;
569*7fe7c98fSJerin Jacob 
570*7fe7c98fSJerin Jacob 	RTE_SET_USED(nic);
571*7fe7c98fSJerin Jacob 	PMD_INIT_FUNC_TRACE();
572*7fe7c98fSJerin Jacob 
573*7fe7c98fSJerin Jacob 	if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED)
574*7fe7c98fSJerin Jacob 		return 0;
575*7fe7c98fSJerin Jacob 
576*7fe7c98fSJerin Jacob 	dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
577*7fe7c98fSJerin Jacob 	return ret;
578*7fe7c98fSJerin Jacob }
579*7fe7c98fSJerin Jacob 
580*7fe7c98fSJerin Jacob static int
581*7fe7c98fSJerin Jacob octeontx_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
582*7fe7c98fSJerin Jacob {
583*7fe7c98fSJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
584*7fe7c98fSJerin Jacob 
585*7fe7c98fSJerin Jacob 	PMD_INIT_FUNC_TRACE();
586*7fe7c98fSJerin Jacob 	qidx = qidx % PKO_VF_NUM_DQ;
587*7fe7c98fSJerin Jacob 
588*7fe7c98fSJerin Jacob 	return octeontx_vf_stop_tx_queue(dev, nic, qidx);
589*7fe7c98fSJerin Jacob }
590*7fe7c98fSJerin Jacob 
591197438eeSJerin Jacob static int
592197438eeSJerin Jacob octeontx_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
593197438eeSJerin Jacob 				uint16_t nb_desc, unsigned int socket_id,
594197438eeSJerin Jacob 				const struct rte_eth_rxconf *rx_conf,
595197438eeSJerin Jacob 				struct rte_mempool *mb_pool)
596197438eeSJerin Jacob {
597197438eeSJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
598197438eeSJerin Jacob 	struct rte_mempool_ops *mp_ops = NULL;
599197438eeSJerin Jacob 	struct octeontx_rxq *rxq = NULL;
600197438eeSJerin Jacob 	pki_pktbuf_cfg_t pktbuf_conf;
601197438eeSJerin Jacob 	pki_hash_cfg_t pki_hash;
602197438eeSJerin Jacob 	pki_qos_cfg_t pki_qos;
603197438eeSJerin Jacob 	uintptr_t pool;
604197438eeSJerin Jacob 	int ret, port;
605197438eeSJerin Jacob 	uint8_t gaura;
606197438eeSJerin Jacob 	unsigned int ev_queues = (nic->ev_queues * nic->port_id) + qidx;
607197438eeSJerin Jacob 	unsigned int ev_ports = (nic->ev_ports * nic->port_id) + qidx;
608197438eeSJerin Jacob 
609197438eeSJerin Jacob 	RTE_SET_USED(nb_desc);
610197438eeSJerin Jacob 
611197438eeSJerin Jacob 	memset(&pktbuf_conf, 0, sizeof(pktbuf_conf));
612197438eeSJerin Jacob 	memset(&pki_hash, 0, sizeof(pki_hash));
613197438eeSJerin Jacob 	memset(&pki_qos, 0, sizeof(pki_qos));
614197438eeSJerin Jacob 
615197438eeSJerin Jacob 	mp_ops = rte_mempool_get_ops(mb_pool->ops_index);
616197438eeSJerin Jacob 	if (strcmp(mp_ops->name, "octeontx_fpavf")) {
617197438eeSJerin Jacob 		octeontx_log_err("failed to find octeontx_fpavf mempool");
618197438eeSJerin Jacob 		return -ENOTSUP;
619197438eeSJerin Jacob 	}
620197438eeSJerin Jacob 
621197438eeSJerin Jacob 	/* Handle forbidden configurations */
622197438eeSJerin Jacob 	if (nic->pki.classifier_enable) {
623197438eeSJerin Jacob 		octeontx_log_err("cannot setup queue %d. "
624197438eeSJerin Jacob 					"Classifier option unsupported", qidx);
625197438eeSJerin Jacob 		return -EINVAL;
626197438eeSJerin Jacob 	}
627197438eeSJerin Jacob 
628197438eeSJerin Jacob 	port = nic->port_id;
629197438eeSJerin Jacob 
630197438eeSJerin Jacob 	/* Rx deferred start is not supported */
631197438eeSJerin Jacob 	if (rx_conf->rx_deferred_start) {
632197438eeSJerin Jacob 		octeontx_log_err("rx deferred start not supported");
633197438eeSJerin Jacob 		return -EINVAL;
634197438eeSJerin Jacob 	}
635197438eeSJerin Jacob 
636197438eeSJerin Jacob 	/* Verify queue index */
637197438eeSJerin Jacob 	if (qidx >= dev->data->nb_rx_queues) {
638197438eeSJerin Jacob 		octeontx_log_err("QID %d not supporteded (0 - %d available)\n",
639197438eeSJerin Jacob 				qidx, (dev->data->nb_rx_queues - 1));
640197438eeSJerin Jacob 		return -ENOTSUP;
641197438eeSJerin Jacob 	}
642197438eeSJerin Jacob 
643197438eeSJerin Jacob 	/* Socket id check */
644197438eeSJerin Jacob 	if (socket_id != (unsigned int)SOCKET_ID_ANY &&
645197438eeSJerin Jacob 			socket_id != (unsigned int)nic->node)
646197438eeSJerin Jacob 		PMD_RX_LOG(INFO, "socket_id expected %d, configured %d",
647197438eeSJerin Jacob 						socket_id, nic->node);
648197438eeSJerin Jacob 
649197438eeSJerin Jacob 	/* Allocating rx queue data structure */
650197438eeSJerin Jacob 	rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct octeontx_rxq),
651197438eeSJerin Jacob 				 RTE_CACHE_LINE_SIZE, nic->node);
652197438eeSJerin Jacob 	if (rxq == NULL) {
653197438eeSJerin Jacob 		octeontx_log_err("failed to allocate rxq=%d", qidx);
654197438eeSJerin Jacob 		return -ENOMEM;
655197438eeSJerin Jacob 	}
656197438eeSJerin Jacob 
657197438eeSJerin Jacob 	if (!nic->pki.initialized) {
658197438eeSJerin Jacob 		pktbuf_conf.port_type = 0;
659197438eeSJerin Jacob 		pki_hash.port_type = 0;
660197438eeSJerin Jacob 		pki_qos.port_type = 0;
661197438eeSJerin Jacob 
662197438eeSJerin Jacob 		pktbuf_conf.mmask.f_wqe_skip = 1;
663197438eeSJerin Jacob 		pktbuf_conf.mmask.f_first_skip = 1;
664197438eeSJerin Jacob 		pktbuf_conf.mmask.f_later_skip = 1;
665197438eeSJerin Jacob 		pktbuf_conf.mmask.f_mbuff_size = 1;
666197438eeSJerin Jacob 		pktbuf_conf.mmask.f_cache_mode = 1;
667197438eeSJerin Jacob 
668197438eeSJerin Jacob 		pktbuf_conf.wqe_skip = OCTTX_PACKET_WQE_SKIP;
669197438eeSJerin Jacob 		pktbuf_conf.first_skip = OCTTX_PACKET_FIRST_SKIP;
670197438eeSJerin Jacob 		pktbuf_conf.later_skip = OCTTX_PACKET_LATER_SKIP;
671197438eeSJerin Jacob 		pktbuf_conf.mbuff_size = (mb_pool->elt_size -
672197438eeSJerin Jacob 					RTE_PKTMBUF_HEADROOM -
673197438eeSJerin Jacob 					sizeof(struct rte_mbuf));
674197438eeSJerin Jacob 
675197438eeSJerin Jacob 		pktbuf_conf.cache_mode = PKI_OPC_MODE_STF2_STT;
676197438eeSJerin Jacob 
677197438eeSJerin Jacob 		ret = octeontx_pki_port_pktbuf_config(port, &pktbuf_conf);
678197438eeSJerin Jacob 		if (ret != 0) {
679197438eeSJerin Jacob 			octeontx_log_err("fail to configure pktbuf for port %d",
680197438eeSJerin Jacob 					port);
681197438eeSJerin Jacob 			rte_free(rxq);
682197438eeSJerin Jacob 			return ret;
683197438eeSJerin Jacob 		}
684197438eeSJerin Jacob 		PMD_RX_LOG(DEBUG, "Port %d Rx pktbuf configured:\n"
685197438eeSJerin Jacob 				"\tmbuf_size:\t0x%0x\n"
686197438eeSJerin Jacob 				"\twqe_skip:\t0x%0x\n"
687197438eeSJerin Jacob 				"\tfirst_skip:\t0x%0x\n"
688197438eeSJerin Jacob 				"\tlater_skip:\t0x%0x\n"
689197438eeSJerin Jacob 				"\tcache_mode:\t%s\n",
690197438eeSJerin Jacob 				port,
691197438eeSJerin Jacob 				pktbuf_conf.mbuff_size,
692197438eeSJerin Jacob 				pktbuf_conf.wqe_skip,
693197438eeSJerin Jacob 				pktbuf_conf.first_skip,
694197438eeSJerin Jacob 				pktbuf_conf.later_skip,
695197438eeSJerin Jacob 				(pktbuf_conf.cache_mode ==
696197438eeSJerin Jacob 						PKI_OPC_MODE_STT) ?
697197438eeSJerin Jacob 				"STT" :
698197438eeSJerin Jacob 				(pktbuf_conf.cache_mode ==
699197438eeSJerin Jacob 						PKI_OPC_MODE_STF) ?
700197438eeSJerin Jacob 				"STF" :
701197438eeSJerin Jacob 				(pktbuf_conf.cache_mode ==
702197438eeSJerin Jacob 						PKI_OPC_MODE_STF1_STT) ?
703197438eeSJerin Jacob 				"STF1_STT" : "STF2_STT");
704197438eeSJerin Jacob 
705197438eeSJerin Jacob 		if (nic->pki.hash_enable) {
706197438eeSJerin Jacob 			pki_hash.tag_dlc = 1;
707197438eeSJerin Jacob 			pki_hash.tag_slc = 1;
708197438eeSJerin Jacob 			pki_hash.tag_dlf = 1;
709197438eeSJerin Jacob 			pki_hash.tag_slf = 1;
710197438eeSJerin Jacob 			octeontx_pki_port_hash_config(port, &pki_hash);
711197438eeSJerin Jacob 		}
712197438eeSJerin Jacob 
713197438eeSJerin Jacob 		pool = (uintptr_t)mb_pool->pool_id;
714197438eeSJerin Jacob 
715197438eeSJerin Jacob 		/* Get the gpool Id */
716197438eeSJerin Jacob 		gaura = octeontx_fpa_bufpool_gpool(pool);
717197438eeSJerin Jacob 
718197438eeSJerin Jacob 		pki_qos.qpg_qos = PKI_QPG_QOS_NONE;
719197438eeSJerin Jacob 		pki_qos.num_entry = 1;
720197438eeSJerin Jacob 		pki_qos.drop_policy = 0;
721197438eeSJerin Jacob 		pki_qos.tag_type = 2L;
722197438eeSJerin Jacob 		pki_qos.qos_entry[0].port_add = 0;
723197438eeSJerin Jacob 		pki_qos.qos_entry[0].gaura = gaura;
724197438eeSJerin Jacob 		pki_qos.qos_entry[0].ggrp_ok = ev_queues;
725197438eeSJerin Jacob 		pki_qos.qos_entry[0].ggrp_bad = ev_queues;
726197438eeSJerin Jacob 		pki_qos.qos_entry[0].grptag_bad = 0;
727197438eeSJerin Jacob 		pki_qos.qos_entry[0].grptag_ok = 0;
728197438eeSJerin Jacob 
729197438eeSJerin Jacob 		ret = octeontx_pki_port_create_qos(port, &pki_qos);
730197438eeSJerin Jacob 		if (ret < 0) {
731197438eeSJerin Jacob 			octeontx_log_err("failed to create QOS port=%d, q=%d",
732197438eeSJerin Jacob 					port, qidx);
733197438eeSJerin Jacob 			rte_free(rxq);
734197438eeSJerin Jacob 			return ret;
735197438eeSJerin Jacob 		}
736197438eeSJerin Jacob 		nic->pki.initialized = true;
737197438eeSJerin Jacob 	}
738197438eeSJerin Jacob 
739197438eeSJerin Jacob 	rxq->port_id = nic->port_id;
740197438eeSJerin Jacob 	rxq->eth_dev = dev;
741197438eeSJerin Jacob 	rxq->queue_id = qidx;
742197438eeSJerin Jacob 	rxq->evdev = nic->evdev;
743197438eeSJerin Jacob 	rxq->ev_queues = ev_queues;
744197438eeSJerin Jacob 	rxq->ev_ports = ev_ports;
745197438eeSJerin Jacob 
746197438eeSJerin Jacob 	dev->data->rx_queues[qidx] = rxq;
747197438eeSJerin Jacob 	dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
748197438eeSJerin Jacob 	return 0;
749197438eeSJerin Jacob }
750197438eeSJerin Jacob 
751197438eeSJerin Jacob static void
752197438eeSJerin Jacob octeontx_dev_rx_queue_release(void *rxq)
753197438eeSJerin Jacob {
754197438eeSJerin Jacob 	rte_free(rxq);
755197438eeSJerin Jacob }
756197438eeSJerin Jacob 
757f18b146cSJerin Jacob /* Initialize and register driver with DPDK Application */
758f18b146cSJerin Jacob static const struct eth_dev_ops octeontx_dev_ops = {
7597742c55aSJerin Jacob 	.dev_configure		 = octeontx_dev_configure,
7607c0347a2SJerin Jacob 	.dev_infos_get		 = octeontx_dev_info,
76115bce35bSJerin Jacob 	.promiscuous_enable	 = octeontx_dev_promisc_enable,
76215bce35bSJerin Jacob 	.promiscuous_disable	 = octeontx_dev_promisc_disable,
7634fac7c0aSJerin Jacob 	.link_update		 = octeontx_dev_link_update,
76455389909SJerin Jacob 	.stats_get		 = octeontx_dev_stats_get,
76555389909SJerin Jacob 	.stats_reset		 = octeontx_dev_stats_reset,
766ef7308fcSJerin Jacob 	.mac_addr_set		 = octeontx_dev_default_mac_addr_set,
767*7fe7c98fSJerin Jacob 	.tx_queue_start		 = octeontx_dev_tx_queue_start,
768*7fe7c98fSJerin Jacob 	.tx_queue_stop		 = octeontx_dev_tx_queue_stop,
769197438eeSJerin Jacob 	.rx_queue_setup		 = octeontx_dev_rx_queue_setup,
770197438eeSJerin Jacob 	.rx_queue_release	 = octeontx_dev_rx_queue_release,
771f18b146cSJerin Jacob };
772f18b146cSJerin Jacob 
773f7be70e5SJerin Jacob /* Create Ethdev interface per BGX LMAC ports */
774f7be70e5SJerin Jacob static int
775f7be70e5SJerin Jacob octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
776f7be70e5SJerin Jacob 			int socket_id)
777f7be70e5SJerin Jacob {
778f18b146cSJerin Jacob 	int res;
779f18b146cSJerin Jacob 	char octtx_name[OCTEONTX_MAX_NAME_LEN];
780f18b146cSJerin Jacob 	struct octeontx_nic *nic = NULL;
781f18b146cSJerin Jacob 	struct rte_eth_dev *eth_dev = NULL;
782f18b146cSJerin Jacob 	struct rte_eth_dev_data *data = NULL;
783f18b146cSJerin Jacob 	const char *name = rte_vdev_device_name(dev);
784f7be70e5SJerin Jacob 
785f18b146cSJerin Jacob 	PMD_INIT_FUNC_TRACE();
786f18b146cSJerin Jacob 
787f18b146cSJerin Jacob 	sprintf(octtx_name, "%s_%d", name, port);
788f18b146cSJerin Jacob 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
789f18b146cSJerin Jacob 		eth_dev = rte_eth_dev_attach_secondary(octtx_name);
790f18b146cSJerin Jacob 		if (eth_dev == NULL)
791f7be70e5SJerin Jacob 			return -ENODEV;
792f18b146cSJerin Jacob 
793f18b146cSJerin Jacob 		return 0;
794f18b146cSJerin Jacob 	}
795f18b146cSJerin Jacob 
796f18b146cSJerin Jacob 	data = rte_zmalloc_socket(octtx_name, sizeof(*data), 0, socket_id);
797f18b146cSJerin Jacob 	if (data == NULL) {
798f18b146cSJerin Jacob 		octeontx_log_err("failed to allocate devdata");
799f18b146cSJerin Jacob 		res = -ENOMEM;
800f18b146cSJerin Jacob 		goto err;
801f18b146cSJerin Jacob 	}
802f18b146cSJerin Jacob 
803f18b146cSJerin Jacob 	nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id);
804f18b146cSJerin Jacob 	if (nic == NULL) {
805f18b146cSJerin Jacob 		octeontx_log_err("failed to allocate nic structure");
806f18b146cSJerin Jacob 		res = -ENOMEM;
807f18b146cSJerin Jacob 		goto err;
808f18b146cSJerin Jacob 	}
809f18b146cSJerin Jacob 
810f18b146cSJerin Jacob 	nic->port_id = port;
811f18b146cSJerin Jacob 	nic->evdev = evdev;
812f18b146cSJerin Jacob 
813f18b146cSJerin Jacob 	res = octeontx_port_open(nic);
814f18b146cSJerin Jacob 	if (res < 0)
815f18b146cSJerin Jacob 		goto err;
816f18b146cSJerin Jacob 
817f18b146cSJerin Jacob 	/* Rx side port configuration */
818f18b146cSJerin Jacob 	res = octeontx_pki_port_open(port);
819f18b146cSJerin Jacob 	if (res != 0) {
820f18b146cSJerin Jacob 		octeontx_log_err("failed to open PKI port %d", port);
821f18b146cSJerin Jacob 		res = -ENODEV;
822f18b146cSJerin Jacob 		goto err;
823f18b146cSJerin Jacob 	}
824f18b146cSJerin Jacob 
825f18b146cSJerin Jacob 	/* Reserve an ethdev entry */
826f18b146cSJerin Jacob 	eth_dev = rte_eth_dev_allocate(octtx_name);
827f18b146cSJerin Jacob 	if (eth_dev == NULL) {
828f18b146cSJerin Jacob 		octeontx_log_err("failed to allocate rte_eth_dev");
829f18b146cSJerin Jacob 		res = -ENOMEM;
830f18b146cSJerin Jacob 		goto err;
831f18b146cSJerin Jacob 	}
832f18b146cSJerin Jacob 
833f18b146cSJerin Jacob 	eth_dev->device = &dev->device;
834f18b146cSJerin Jacob 	eth_dev->intr_handle = NULL;
835f18b146cSJerin Jacob 	eth_dev->data->kdrv = RTE_KDRV_NONE;
836f18b146cSJerin Jacob 	eth_dev->data->numa_node = dev->device.numa_node;
837f18b146cSJerin Jacob 
838f18b146cSJerin Jacob 	rte_memcpy(data, (eth_dev)->data, sizeof(*data));
839f18b146cSJerin Jacob 	data->dev_private = nic;
840f18b146cSJerin Jacob 
841f18b146cSJerin Jacob 	data->port_id = eth_dev->data->port_id;
842f18b146cSJerin Jacob 	snprintf(data->name, sizeof(data->name), "%s", eth_dev->data->name);
843f18b146cSJerin Jacob 
844f18b146cSJerin Jacob 	nic->ev_queues = 1;
845f18b146cSJerin Jacob 	nic->ev_ports = 1;
846f18b146cSJerin Jacob 
847f18b146cSJerin Jacob 	data->dev_link.link_status = ETH_LINK_DOWN;
848f18b146cSJerin Jacob 	data->dev_started = 0;
849f18b146cSJerin Jacob 	data->promiscuous = 0;
850f18b146cSJerin Jacob 	data->all_multicast = 0;
851f18b146cSJerin Jacob 	data->scattered_rx = 0;
852f18b146cSJerin Jacob 
853f18b146cSJerin Jacob 	data->mac_addrs = rte_zmalloc_socket(octtx_name, ETHER_ADDR_LEN, 0,
854f18b146cSJerin Jacob 							socket_id);
855f18b146cSJerin Jacob 	if (data->mac_addrs == NULL) {
856f18b146cSJerin Jacob 		octeontx_log_err("failed to allocate memory for mac_addrs");
857f18b146cSJerin Jacob 		res = -ENOMEM;
858f18b146cSJerin Jacob 		goto err;
859f18b146cSJerin Jacob 	}
860f18b146cSJerin Jacob 
861f18b146cSJerin Jacob 	eth_dev->data = data;
862f18b146cSJerin Jacob 	eth_dev->dev_ops = &octeontx_dev_ops;
863f18b146cSJerin Jacob 
864f18b146cSJerin Jacob 	/* Finally save ethdev pointer to the NIC structure */
865f18b146cSJerin Jacob 	nic->dev = eth_dev;
866f18b146cSJerin Jacob 
867f18b146cSJerin Jacob 	if (nic->port_id != data->port_id) {
868f18b146cSJerin Jacob 		octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
869f18b146cSJerin Jacob 				data->port_id, nic->port_id);
870f18b146cSJerin Jacob 		res = -EINVAL;
871f18b146cSJerin Jacob 		goto err;
872f18b146cSJerin Jacob 	}
873f18b146cSJerin Jacob 
874f18b146cSJerin Jacob 	/* Update port_id mac to eth_dev */
875f18b146cSJerin Jacob 	memcpy(data->mac_addrs, nic->mac_addr, ETHER_ADDR_LEN);
876f18b146cSJerin Jacob 
877f18b146cSJerin Jacob 	PMD_INIT_LOG(DEBUG, "ethdev info: ");
878f18b146cSJerin Jacob 	PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d",
879f18b146cSJerin Jacob 				nic->port_id, nic->port_ena,
880f18b146cSJerin Jacob 				nic->base_ochan, nic->num_ochans,
881f18b146cSJerin Jacob 				nic->num_tx_queues);
882f18b146cSJerin Jacob 	PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->mtu);
883f18b146cSJerin Jacob 
884f18b146cSJerin Jacob 	return data->port_id;
885f18b146cSJerin Jacob 
886f18b146cSJerin Jacob err:
887f18b146cSJerin Jacob 	if (port)
888f18b146cSJerin Jacob 		octeontx_port_close(nic);
889f18b146cSJerin Jacob 
890f18b146cSJerin Jacob 	if (eth_dev != NULL) {
891f18b146cSJerin Jacob 		rte_free(eth_dev->data->mac_addrs);
892f18b146cSJerin Jacob 		rte_free(data);
893f18b146cSJerin Jacob 		rte_free(nic);
894f18b146cSJerin Jacob 		rte_eth_dev_release_port(eth_dev);
895f18b146cSJerin Jacob 	}
896f18b146cSJerin Jacob 
897f18b146cSJerin Jacob 	return res;
898f7be70e5SJerin Jacob }
899f7be70e5SJerin Jacob 
900f7be70e5SJerin Jacob /* Un initialize octeontx device */
901f7be70e5SJerin Jacob static int
902f7be70e5SJerin Jacob octeontx_remove(struct rte_vdev_device *dev)
903f7be70e5SJerin Jacob {
904f7be70e5SJerin Jacob 	char octtx_name[OCTEONTX_MAX_NAME_LEN];
905f7be70e5SJerin Jacob 	struct rte_eth_dev *eth_dev = NULL;
906f7be70e5SJerin Jacob 	struct octeontx_nic *nic = NULL;
907f7be70e5SJerin Jacob 	int i;
908f7be70e5SJerin Jacob 
909f7be70e5SJerin Jacob 	if (dev == NULL)
910f7be70e5SJerin Jacob 		return -EINVAL;
911f7be70e5SJerin Jacob 
912f7be70e5SJerin Jacob 	for (i = 0; i < OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT; i++) {
913f7be70e5SJerin Jacob 		sprintf(octtx_name, "eth_octeontx_%d", i);
914f7be70e5SJerin Jacob 
915f7be70e5SJerin Jacob 		/* reserve an ethdev entry */
916f7be70e5SJerin Jacob 		eth_dev = rte_eth_dev_allocated(octtx_name);
917f7be70e5SJerin Jacob 		if (eth_dev == NULL)
918f7be70e5SJerin Jacob 			return -ENODEV;
919f7be70e5SJerin Jacob 
920f7be70e5SJerin Jacob 		nic = octeontx_pmd_priv(eth_dev);
921f7be70e5SJerin Jacob 		rte_event_dev_stop(nic->evdev);
922f7be70e5SJerin Jacob 		PMD_INIT_LOG(INFO, "Closing octeontx device %s", octtx_name);
923f7be70e5SJerin Jacob 
924f7be70e5SJerin Jacob 		rte_free(eth_dev->data->mac_addrs);
925f7be70e5SJerin Jacob 		rte_free(eth_dev->data->dev_private);
926f7be70e5SJerin Jacob 		rte_free(eth_dev->data);
927f7be70e5SJerin Jacob 		rte_eth_dev_release_port(eth_dev);
928f7be70e5SJerin Jacob 		rte_event_dev_close(nic->evdev);
929f7be70e5SJerin Jacob 	}
930f7be70e5SJerin Jacob 
931f7be70e5SJerin Jacob 	/* Free FC resource */
932f7be70e5SJerin Jacob 	octeontx_pko_fc_free();
933f7be70e5SJerin Jacob 
934f7be70e5SJerin Jacob 	return 0;
935f7be70e5SJerin Jacob }
936f7be70e5SJerin Jacob 
937f7be70e5SJerin Jacob /* Initialize octeontx device */
938f7be70e5SJerin Jacob static int
939f7be70e5SJerin Jacob octeontx_probe(struct rte_vdev_device *dev)
940f7be70e5SJerin Jacob {
941f7be70e5SJerin Jacob 	const char *dev_name;
942f7be70e5SJerin Jacob 	static int probe_once;
943f7be70e5SJerin Jacob 	uint8_t socket_id, qlist;
944f7be70e5SJerin Jacob 	int tx_vfcnt, port_id, evdev, qnum, pnum, res, i;
945f7be70e5SJerin Jacob 	struct rte_event_dev_config dev_conf;
946f7be70e5SJerin Jacob 	const char *eventdev_name = "event_octeontx";
947f7be70e5SJerin Jacob 	struct rte_event_dev_info info;
948f7be70e5SJerin Jacob 
949f7be70e5SJerin Jacob 	struct octeontx_vdev_init_params init_params = {
950f7be70e5SJerin Jacob 		OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT
951f7be70e5SJerin Jacob 	};
952f7be70e5SJerin Jacob 
953f7be70e5SJerin Jacob 	dev_name = rte_vdev_device_name(dev);
954f7be70e5SJerin Jacob 	res = octeontx_parse_vdev_init_params(&init_params, dev);
955f7be70e5SJerin Jacob 	if (res < 0)
956f7be70e5SJerin Jacob 		return -EINVAL;
957f7be70e5SJerin Jacob 
958f7be70e5SJerin Jacob 	if (init_params.nr_port > OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT) {
959f7be70e5SJerin Jacob 		octeontx_log_err("nr_port (%d) > max (%d)", init_params.nr_port,
960f7be70e5SJerin Jacob 				OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT);
961f7be70e5SJerin Jacob 		return -ENOTSUP;
962f7be70e5SJerin Jacob 	}
963f7be70e5SJerin Jacob 
964f7be70e5SJerin Jacob 	PMD_INIT_LOG(DEBUG, "initializing %s pmd", dev_name);
965f7be70e5SJerin Jacob 
966f7be70e5SJerin Jacob 	socket_id = rte_socket_id();
967f7be70e5SJerin Jacob 
968f7be70e5SJerin Jacob 	tx_vfcnt = octeontx_pko_vf_count();
969f7be70e5SJerin Jacob 
970f7be70e5SJerin Jacob 	if (tx_vfcnt < init_params.nr_port) {
971f7be70e5SJerin Jacob 		octeontx_log_err("not enough PKO (%d) for port number (%d)",
972f7be70e5SJerin Jacob 				tx_vfcnt, init_params.nr_port);
973f7be70e5SJerin Jacob 		return -EINVAL;
974f7be70e5SJerin Jacob 	}
975f7be70e5SJerin Jacob 	evdev = rte_event_dev_get_dev_id(eventdev_name);
976f7be70e5SJerin Jacob 	if (evdev < 0) {
977f7be70e5SJerin Jacob 		octeontx_log_err("eventdev %s not found", eventdev_name);
978f7be70e5SJerin Jacob 		return -ENODEV;
979f7be70e5SJerin Jacob 	}
980f7be70e5SJerin Jacob 
981f7be70e5SJerin Jacob 	res = rte_event_dev_info_get(evdev, &info);
982f7be70e5SJerin Jacob 	if (res < 0) {
983f7be70e5SJerin Jacob 		octeontx_log_err("failed to eventdev info %d", res);
984f7be70e5SJerin Jacob 		return -EINVAL;
985f7be70e5SJerin Jacob 	}
986f7be70e5SJerin Jacob 
987f7be70e5SJerin Jacob 	PMD_INIT_LOG(DEBUG, "max_queue %d max_port %d",
988f7be70e5SJerin Jacob 			info.max_event_queues, info.max_event_ports);
989f7be70e5SJerin Jacob 
990f7be70e5SJerin Jacob 	if (octeontx_pko_init_fc(tx_vfcnt))
991f7be70e5SJerin Jacob 		return -ENOMEM;
992f7be70e5SJerin Jacob 
993f7be70e5SJerin Jacob 	devconf_set_default_sane_values(&dev_conf, &info);
994f7be70e5SJerin Jacob 	res = rte_event_dev_configure(evdev, &dev_conf);
995f7be70e5SJerin Jacob 	if (res < 0)
996f7be70e5SJerin Jacob 		goto parse_error;
997f7be70e5SJerin Jacob 
998f7be70e5SJerin Jacob 	rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT,
999f7be70e5SJerin Jacob 			(uint32_t *)&pnum);
1000f7be70e5SJerin Jacob 	rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT,
1001f7be70e5SJerin Jacob 			(uint32_t *)&qnum);
1002f7be70e5SJerin Jacob 	if (pnum < qnum) {
1003f7be70e5SJerin Jacob 		octeontx_log_err("too few event ports (%d) for event_q(%d)",
1004f7be70e5SJerin Jacob 				pnum, qnum);
1005f7be70e5SJerin Jacob 		res = -EINVAL;
1006f7be70e5SJerin Jacob 		goto parse_error;
1007f7be70e5SJerin Jacob 	}
1008f7be70e5SJerin Jacob 	if (pnum > qnum) {
1009f7be70e5SJerin Jacob 		/*
1010f7be70e5SJerin Jacob 		 * We don't poll on event ports
1011f7be70e5SJerin Jacob 		 * that do not have any queues assigned.
1012f7be70e5SJerin Jacob 		 */
1013f7be70e5SJerin Jacob 		pnum = qnum;
1014f7be70e5SJerin Jacob 		PMD_INIT_LOG(INFO,
1015f7be70e5SJerin Jacob 			"reducing number of active event ports to %d", pnum);
1016f7be70e5SJerin Jacob 	}
1017f7be70e5SJerin Jacob 	for (i = 0; i < qnum; i++) {
1018f7be70e5SJerin Jacob 		res = rte_event_queue_setup(evdev, i, NULL);
1019f7be70e5SJerin Jacob 		if (res < 0) {
1020f7be70e5SJerin Jacob 			octeontx_log_err("failed to setup event_q(%d): res %d",
1021f7be70e5SJerin Jacob 					i, res);
1022f7be70e5SJerin Jacob 			goto parse_error;
1023f7be70e5SJerin Jacob 		}
1024f7be70e5SJerin Jacob 	}
1025f7be70e5SJerin Jacob 
1026f7be70e5SJerin Jacob 	for (i = 0; i < pnum; i++) {
1027f7be70e5SJerin Jacob 		res = rte_event_port_setup(evdev, i, NULL);
1028f7be70e5SJerin Jacob 		if (res < 0) {
1029f7be70e5SJerin Jacob 			res = -ENODEV;
1030f7be70e5SJerin Jacob 			octeontx_log_err("failed to setup ev port(%d) res=%d",
1031f7be70e5SJerin Jacob 						i, res);
1032f7be70e5SJerin Jacob 			goto parse_error;
1033f7be70e5SJerin Jacob 		}
1034f7be70e5SJerin Jacob 		/* Link one queue to one event port */
1035f7be70e5SJerin Jacob 		qlist = i;
1036f7be70e5SJerin Jacob 		res = rte_event_port_link(evdev, i, &qlist, NULL, 1);
1037f7be70e5SJerin Jacob 		if (res < 0) {
1038f7be70e5SJerin Jacob 			res = -ENODEV;
1039f7be70e5SJerin Jacob 			octeontx_log_err("failed to link port (%d): res=%d",
1040f7be70e5SJerin Jacob 					i, res);
1041f7be70e5SJerin Jacob 			goto parse_error;
1042f7be70e5SJerin Jacob 		}
1043f7be70e5SJerin Jacob 	}
1044f7be70e5SJerin Jacob 
1045f7be70e5SJerin Jacob 	/* Create ethdev interface */
1046f7be70e5SJerin Jacob 	for (i = 0; i < init_params.nr_port; i++) {
1047f7be70e5SJerin Jacob 		port_id = octeontx_create(dev, i, evdev, socket_id);
1048f7be70e5SJerin Jacob 		if (port_id < 0) {
1049f7be70e5SJerin Jacob 			octeontx_log_err("failed to create device %s",
1050f7be70e5SJerin Jacob 					dev_name);
1051f7be70e5SJerin Jacob 			res = -ENODEV;
1052f7be70e5SJerin Jacob 			goto parse_error;
1053f7be70e5SJerin Jacob 		}
1054f7be70e5SJerin Jacob 
1055f7be70e5SJerin Jacob 		PMD_INIT_LOG(INFO, "created ethdev %s for port %d", dev_name,
1056f7be70e5SJerin Jacob 					port_id);
1057f7be70e5SJerin Jacob 	}
1058f7be70e5SJerin Jacob 
1059f7be70e5SJerin Jacob 	if (probe_once) {
1060f7be70e5SJerin Jacob 		octeontx_log_err("interface %s not supported", dev_name);
1061f7be70e5SJerin Jacob 		octeontx_remove(dev);
1062f7be70e5SJerin Jacob 		res = -ENOTSUP;
1063f7be70e5SJerin Jacob 		goto parse_error;
1064f7be70e5SJerin Jacob 	}
1065f7be70e5SJerin Jacob 	probe_once = 1;
1066f7be70e5SJerin Jacob 
1067f7be70e5SJerin Jacob 	return 0;
1068f7be70e5SJerin Jacob 
1069f7be70e5SJerin Jacob parse_error:
1070f7be70e5SJerin Jacob 	octeontx_pko_fc_free();
1071f7be70e5SJerin Jacob 	return res;
1072f7be70e5SJerin Jacob }
1073f7be70e5SJerin Jacob 
1074f7be70e5SJerin Jacob static struct rte_vdev_driver octeontx_pmd_drv = {
1075f7be70e5SJerin Jacob 	.probe = octeontx_probe,
1076f7be70e5SJerin Jacob 	.remove = octeontx_remove,
1077f7be70e5SJerin Jacob };
1078f7be70e5SJerin Jacob 
1079f7be70e5SJerin Jacob RTE_PMD_REGISTER_VDEV(OCTEONTX_PMD, octeontx_pmd_drv);
1080f7be70e5SJerin Jacob RTE_PMD_REGISTER_ALIAS(OCTEONTX_PMD, eth_octeontx);
1081f7be70e5SJerin Jacob RTE_PMD_REGISTER_PARAM_STRING(OCTEONTX_PMD, "nr_port=<int> ");
1082