xref: /dpdk/drivers/net/octeontx/octeontx_ethdev.c (revision 85221a0c7c28e10e6b31504448c37134e8facd55)
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>
19dfb0c75bSPavan Nikhilesh #include <rte_mbuf_pool_ops.h>
20f7be70e5SJerin Jacob #include <rte_prefetch.h>
21d4a586d2SJianfeng Tan #include <rte_bus_vdev.h>
22f7be70e5SJerin Jacob 
23f7be70e5SJerin Jacob #include "octeontx_ethdev.h"
2420186d43SJerin Jacob #include "octeontx_rxtx.h"
25f7be70e5SJerin Jacob #include "octeontx_logs.h"
26f7be70e5SJerin Jacob 
27*85221a0cSHarman Kalra struct evdev_priv_data {
28*85221a0cSHarman Kalra 	OFFLOAD_FLAGS; /*Sequence should not be changed */
29*85221a0cSHarman Kalra } __rte_cache_aligned;
30*85221a0cSHarman Kalra 
31f7be70e5SJerin Jacob struct octeontx_vdev_init_params {
32f7be70e5SJerin Jacob 	uint8_t	nr_port;
33f7be70e5SJerin Jacob };
34f7be70e5SJerin Jacob 
35989d4926SPavan Nikhilesh uint16_t
36989d4926SPavan Nikhilesh rte_octeontx_pchan_map[OCTEONTX_MAX_BGX_PORTS][OCTEONTX_MAX_LMAC_PER_BGX];
37989d4926SPavan Nikhilesh 
384fac7c0aSJerin Jacob enum octeontx_link_speed {
394fac7c0aSJerin Jacob 	OCTEONTX_LINK_SPEED_SGMII,
404fac7c0aSJerin Jacob 	OCTEONTX_LINK_SPEED_XAUI,
414fac7c0aSJerin Jacob 	OCTEONTX_LINK_SPEED_RXAUI,
424fac7c0aSJerin Jacob 	OCTEONTX_LINK_SPEED_10G_R,
434fac7c0aSJerin Jacob 	OCTEONTX_LINK_SPEED_40G_R,
444fac7c0aSJerin Jacob 	OCTEONTX_LINK_SPEED_RESERVE1,
454fac7c0aSJerin Jacob 	OCTEONTX_LINK_SPEED_QSGMII,
464fac7c0aSJerin Jacob 	OCTEONTX_LINK_SPEED_RESERVE2
474fac7c0aSJerin Jacob };
484fac7c0aSJerin Jacob 
494d35a276SPavan Nikhilesh int otx_net_logtype_mbox;
504d35a276SPavan Nikhilesh int otx_net_logtype_init;
514d35a276SPavan Nikhilesh int otx_net_logtype_driver;
524d35a276SPavan Nikhilesh 
53f8e99896SThomas Monjalon RTE_INIT(otx_net_init_log)
544d35a276SPavan Nikhilesh {
551a0eab3aSHarry van Haaren 	otx_net_logtype_mbox = rte_log_register("pmd.net.octeontx.mbox");
564d35a276SPavan Nikhilesh 	if (otx_net_logtype_mbox >= 0)
574d35a276SPavan Nikhilesh 		rte_log_set_level(otx_net_logtype_mbox, RTE_LOG_NOTICE);
584d35a276SPavan Nikhilesh 
591a0eab3aSHarry van Haaren 	otx_net_logtype_init = rte_log_register("pmd.net.octeontx.init");
604d35a276SPavan Nikhilesh 	if (otx_net_logtype_init >= 0)
614d35a276SPavan Nikhilesh 		rte_log_set_level(otx_net_logtype_init, RTE_LOG_NOTICE);
624d35a276SPavan Nikhilesh 
631a0eab3aSHarry van Haaren 	otx_net_logtype_driver = rte_log_register("pmd.net.octeontx.driver");
644d35a276SPavan Nikhilesh 	if (otx_net_logtype_driver >= 0)
654d35a276SPavan Nikhilesh 		rte_log_set_level(otx_net_logtype_driver, RTE_LOG_NOTICE);
664d35a276SPavan Nikhilesh }
674d35a276SPavan Nikhilesh 
68f7be70e5SJerin Jacob /* Parse integer from integer argument */
69f7be70e5SJerin Jacob static int
70f7be70e5SJerin Jacob parse_integer_arg(const char *key __rte_unused,
71f7be70e5SJerin Jacob 		const char *value, void *extra_args)
72f7be70e5SJerin Jacob {
73f7be70e5SJerin Jacob 	int *i = (int *)extra_args;
74f7be70e5SJerin Jacob 
75f7be70e5SJerin Jacob 	*i = atoi(value);
76f7be70e5SJerin Jacob 	if (*i < 0) {
77f7be70e5SJerin Jacob 		octeontx_log_err("argument has to be positive.");
78f7be70e5SJerin Jacob 		return -1;
79f7be70e5SJerin Jacob 	}
80f7be70e5SJerin Jacob 
81f7be70e5SJerin Jacob 	return 0;
82f7be70e5SJerin Jacob }
83f7be70e5SJerin Jacob 
84f7be70e5SJerin Jacob static int
85f7be70e5SJerin Jacob octeontx_parse_vdev_init_params(struct octeontx_vdev_init_params *params,
86f7be70e5SJerin Jacob 				struct rte_vdev_device *dev)
87f7be70e5SJerin Jacob {
88f7be70e5SJerin Jacob 	struct rte_kvargs *kvlist = NULL;
89f7be70e5SJerin Jacob 	int ret = 0;
90f7be70e5SJerin Jacob 
91f7be70e5SJerin Jacob 	static const char * const octeontx_vdev_valid_params[] = {
92f7be70e5SJerin Jacob 		OCTEONTX_VDEV_NR_PORT_ARG,
93f7be70e5SJerin Jacob 		NULL
94f7be70e5SJerin Jacob 	};
95f7be70e5SJerin Jacob 
96f7be70e5SJerin Jacob 	const char *input_args = rte_vdev_device_args(dev);
97f7be70e5SJerin Jacob 	if (params == NULL)
98f7be70e5SJerin Jacob 		return -EINVAL;
99f7be70e5SJerin Jacob 
100f7be70e5SJerin Jacob 
101f7be70e5SJerin Jacob 	if (input_args) {
102f7be70e5SJerin Jacob 		kvlist = rte_kvargs_parse(input_args,
103f7be70e5SJerin Jacob 				octeontx_vdev_valid_params);
104f7be70e5SJerin Jacob 		if (kvlist == NULL)
105f7be70e5SJerin Jacob 			return -1;
106f7be70e5SJerin Jacob 
107f7be70e5SJerin Jacob 		ret = rte_kvargs_process(kvlist,
108f7be70e5SJerin Jacob 					OCTEONTX_VDEV_NR_PORT_ARG,
109f7be70e5SJerin Jacob 					&parse_integer_arg,
110f7be70e5SJerin Jacob 					&params->nr_port);
111f7be70e5SJerin Jacob 		if (ret < 0)
112f7be70e5SJerin Jacob 			goto free_kvlist;
113f7be70e5SJerin Jacob 	}
114f7be70e5SJerin Jacob 
115f7be70e5SJerin Jacob free_kvlist:
116f7be70e5SJerin Jacob 	rte_kvargs_free(kvlist);
117f7be70e5SJerin Jacob 	return ret;
118f7be70e5SJerin Jacob }
119f7be70e5SJerin Jacob 
120f18b146cSJerin Jacob static int
121f18b146cSJerin Jacob octeontx_port_open(struct octeontx_nic *nic)
122f18b146cSJerin Jacob {
123f18b146cSJerin Jacob 	octeontx_mbox_bgx_port_conf_t bgx_port_conf;
124f18b146cSJerin Jacob 	int res;
125f18b146cSJerin Jacob 
126f18b146cSJerin Jacob 	res = 0;
127a371fd79SSantosh Shukla 	memset(&bgx_port_conf, 0x0, sizeof(bgx_port_conf));
128f18b146cSJerin Jacob 	PMD_INIT_FUNC_TRACE();
129f18b146cSJerin Jacob 
130f18b146cSJerin Jacob 	res = octeontx_bgx_port_open(nic->port_id, &bgx_port_conf);
131f18b146cSJerin Jacob 	if (res < 0) {
132f18b146cSJerin Jacob 		octeontx_log_err("failed to open port %d", res);
133f18b146cSJerin Jacob 		return res;
134f18b146cSJerin Jacob 	}
135f18b146cSJerin Jacob 
136f18b146cSJerin Jacob 	nic->node = bgx_port_conf.node;
137f18b146cSJerin Jacob 	nic->port_ena = bgx_port_conf.enable;
138f18b146cSJerin Jacob 	nic->base_ichan = bgx_port_conf.base_chan;
139f18b146cSJerin Jacob 	nic->base_ochan = bgx_port_conf.base_chan;
140f18b146cSJerin Jacob 	nic->num_ichans = bgx_port_conf.num_chans;
141f18b146cSJerin Jacob 	nic->num_ochans = bgx_port_conf.num_chans;
142f18b146cSJerin Jacob 	nic->mtu = bgx_port_conf.mtu;
143f18b146cSJerin Jacob 	nic->bpen = bgx_port_conf.bpen;
144f18b146cSJerin Jacob 	nic->fcs_strip = bgx_port_conf.fcs_strip;
145f18b146cSJerin Jacob 	nic->bcast_mode = bgx_port_conf.bcast_mode;
146f18b146cSJerin Jacob 	nic->mcast_mode = bgx_port_conf.mcast_mode;
147f18b146cSJerin Jacob 	nic->speed	= bgx_port_conf.mode;
148f18b146cSJerin Jacob 
14935b2d13fSOlivier Matz 	memcpy(&nic->mac_addr[0], &bgx_port_conf.macaddr[0],
15035b2d13fSOlivier Matz 		RTE_ETHER_ADDR_LEN);
151f18b146cSJerin Jacob 
152f18b146cSJerin Jacob 	octeontx_log_dbg("port opened %d", nic->port_id);
153f18b146cSJerin Jacob 	return res;
154f18b146cSJerin Jacob }
155f18b146cSJerin Jacob 
156f18b146cSJerin Jacob static void
157f18b146cSJerin Jacob octeontx_port_close(struct octeontx_nic *nic)
158f18b146cSJerin Jacob {
159f18b146cSJerin Jacob 	PMD_INIT_FUNC_TRACE();
160f18b146cSJerin Jacob 
161f18b146cSJerin Jacob 	octeontx_bgx_port_close(nic->port_id);
162f18b146cSJerin Jacob 	octeontx_log_dbg("port closed %d", nic->port_id);
163f18b146cSJerin Jacob }
164f18b146cSJerin Jacob 
1657fe7c98fSJerin Jacob static int
166da6c6874SJerin Jacob octeontx_port_start(struct octeontx_nic *nic)
167da6c6874SJerin Jacob {
168da6c6874SJerin Jacob 	PMD_INIT_FUNC_TRACE();
169da6c6874SJerin Jacob 
170da6c6874SJerin Jacob 	return octeontx_bgx_port_start(nic->port_id);
171da6c6874SJerin Jacob }
172da6c6874SJerin Jacob 
173da6c6874SJerin Jacob static int
1747fe7c98fSJerin Jacob octeontx_port_stop(struct octeontx_nic *nic)
1757fe7c98fSJerin Jacob {
1767fe7c98fSJerin Jacob 	PMD_INIT_FUNC_TRACE();
1777fe7c98fSJerin Jacob 
1787fe7c98fSJerin Jacob 	return octeontx_bgx_port_stop(nic->port_id);
1797fe7c98fSJerin Jacob }
1807fe7c98fSJerin Jacob 
1819039c812SAndrew Rybchenko static int
18215bce35bSJerin Jacob octeontx_port_promisc_set(struct octeontx_nic *nic, int en)
18315bce35bSJerin Jacob {
18415bce35bSJerin Jacob 	struct rte_eth_dev *dev;
18515bce35bSJerin Jacob 	int res;
18615bce35bSJerin Jacob 
18715bce35bSJerin Jacob 	res = 0;
18815bce35bSJerin Jacob 	PMD_INIT_FUNC_TRACE();
18915bce35bSJerin Jacob 	dev = nic->dev;
19015bce35bSJerin Jacob 
19115bce35bSJerin Jacob 	res = octeontx_bgx_port_promisc_set(nic->port_id, en);
1929039c812SAndrew Rybchenko 	if (res < 0) {
19315bce35bSJerin Jacob 		octeontx_log_err("failed to set promiscuous mode %d",
19415bce35bSJerin Jacob 				nic->port_id);
1959039c812SAndrew Rybchenko 		return res;
1969039c812SAndrew Rybchenko 	}
19715bce35bSJerin Jacob 
19815bce35bSJerin Jacob 	/* Set proper flag for the mode */
19915bce35bSJerin Jacob 	dev->data->promiscuous = (en != 0) ? 1 : 0;
20015bce35bSJerin Jacob 
20115bce35bSJerin Jacob 	octeontx_log_dbg("port %d : promiscuous mode %s",
20215bce35bSJerin Jacob 			nic->port_id, en ? "set" : "unset");
2039039c812SAndrew Rybchenko 
2049039c812SAndrew Rybchenko 	return 0;
20515bce35bSJerin Jacob }
20615bce35bSJerin Jacob 
207d5b0924bSMatan Azrad static int
20855389909SJerin Jacob octeontx_port_stats(struct octeontx_nic *nic, struct rte_eth_stats *stats)
20955389909SJerin Jacob {
21055389909SJerin Jacob 	octeontx_mbox_bgx_port_stats_t bgx_stats;
21155389909SJerin Jacob 	int res;
21255389909SJerin Jacob 
21355389909SJerin Jacob 	PMD_INIT_FUNC_TRACE();
21455389909SJerin Jacob 
21555389909SJerin Jacob 	res = octeontx_bgx_port_stats(nic->port_id, &bgx_stats);
216d5b0924bSMatan Azrad 	if (res < 0) {
21755389909SJerin Jacob 		octeontx_log_err("failed to get port stats %d", nic->port_id);
218d5b0924bSMatan Azrad 		return res;
219d5b0924bSMatan Azrad 	}
22055389909SJerin Jacob 
22155389909SJerin Jacob 	stats->ipackets = bgx_stats.rx_packets;
22255389909SJerin Jacob 	stats->ibytes = bgx_stats.rx_bytes;
22355389909SJerin Jacob 	stats->imissed = bgx_stats.rx_dropped;
22455389909SJerin Jacob 	stats->ierrors = bgx_stats.rx_errors;
22555389909SJerin Jacob 	stats->opackets = bgx_stats.tx_packets;
22655389909SJerin Jacob 	stats->obytes = bgx_stats.tx_bytes;
22755389909SJerin Jacob 	stats->oerrors = bgx_stats.tx_errors;
22855389909SJerin Jacob 
22955389909SJerin Jacob 	octeontx_log_dbg("port%d stats inpkts=%" PRIx64 " outpkts=%" PRIx64 "",
23055389909SJerin Jacob 			nic->port_id, stats->ipackets, stats->opackets);
231d5b0924bSMatan Azrad 
232d5b0924bSMatan Azrad 	return 0;
23355389909SJerin Jacob }
23455389909SJerin Jacob 
2359970a9adSIgor Romanov static int
23655389909SJerin Jacob octeontx_port_stats_clr(struct octeontx_nic *nic)
23755389909SJerin Jacob {
23855389909SJerin Jacob 	PMD_INIT_FUNC_TRACE();
23955389909SJerin Jacob 
2409970a9adSIgor Romanov 	return octeontx_bgx_port_stats_clr(nic->port_id);
24155389909SJerin Jacob }
24255389909SJerin Jacob 
243f7be70e5SJerin Jacob static inline void
244f7be70e5SJerin Jacob devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
245f7be70e5SJerin Jacob 				struct rte_event_dev_info *info)
246f7be70e5SJerin Jacob {
247f7be70e5SJerin Jacob 	memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
248f7be70e5SJerin Jacob 	dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
249f7be70e5SJerin Jacob 
250f7be70e5SJerin Jacob 	dev_conf->nb_event_ports = info->max_event_ports;
251f7be70e5SJerin Jacob 	dev_conf->nb_event_queues = info->max_event_queues;
252f7be70e5SJerin Jacob 
253f7be70e5SJerin Jacob 	dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
254f7be70e5SJerin Jacob 	dev_conf->nb_event_port_dequeue_depth =
255f7be70e5SJerin Jacob 			info->max_event_port_dequeue_depth;
256f7be70e5SJerin Jacob 	dev_conf->nb_event_port_enqueue_depth =
257f7be70e5SJerin Jacob 			info->max_event_port_enqueue_depth;
258f7be70e5SJerin Jacob 	dev_conf->nb_event_port_enqueue_depth =
259f7be70e5SJerin Jacob 			info->max_event_port_enqueue_depth;
260f7be70e5SJerin Jacob 	dev_conf->nb_events_limit =
261f7be70e5SJerin Jacob 			info->max_num_events;
262f7be70e5SJerin Jacob }
263f7be70e5SJerin Jacob 
264*85221a0cSHarman Kalra static uint16_t
265*85221a0cSHarman Kalra octeontx_tx_offload_flags(struct rte_eth_dev *eth_dev)
266*85221a0cSHarman Kalra {
267*85221a0cSHarman Kalra 	struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
268*85221a0cSHarman Kalra 	uint16_t flags = 0;
269*85221a0cSHarman Kalra 
270*85221a0cSHarman Kalra 	/* Created function for supoorting future offloads */
271*85221a0cSHarman Kalra 	if (nic->tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS)
272*85221a0cSHarman Kalra 		flags |= OCCTX_TX_MULTI_SEG_F;
273*85221a0cSHarman Kalra 
274*85221a0cSHarman Kalra 	return flags;
275*85221a0cSHarman Kalra }
276*85221a0cSHarman Kalra 
277*85221a0cSHarman Kalra static uint16_t
278*85221a0cSHarman Kalra octeontx_rx_offload_flags(struct rte_eth_dev *eth_dev)
279*85221a0cSHarman Kalra {
280*85221a0cSHarman Kalra 	struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
281*85221a0cSHarman Kalra 	struct rte_eth_dev_data *data = eth_dev->data;
282*85221a0cSHarman Kalra 	struct rte_eth_conf *conf = &data->dev_conf;
283*85221a0cSHarman Kalra 	struct rte_eth_rxmode *rxmode = &conf->rxmode;
284*85221a0cSHarman Kalra 	uint16_t flags = 0;
285*85221a0cSHarman Kalra 
286*85221a0cSHarman Kalra 	if (rxmode->mq_mode == ETH_MQ_RX_RSS)
287*85221a0cSHarman Kalra 		flags |= OCCTX_RX_OFFLOAD_RSS_F;
288*85221a0cSHarman Kalra 
289*85221a0cSHarman Kalra 	if (nic->rx_offloads & DEV_RX_OFFLOAD_SCATTER) {
290*85221a0cSHarman Kalra 		flags |= OCCTX_RX_MULTI_SEG_F;
291*85221a0cSHarman Kalra 		eth_dev->data->scattered_rx = 1;
292*85221a0cSHarman Kalra 		/* If scatter mode is enabled, TX should also be in multi
293*85221a0cSHarman Kalra 		 * seg mode, else memory leak will occur
294*85221a0cSHarman Kalra 		 */
295*85221a0cSHarman Kalra 		nic->tx_offloads |= DEV_TX_OFFLOAD_MULTI_SEGS;
296*85221a0cSHarman Kalra 	}
297*85221a0cSHarman Kalra 
298*85221a0cSHarman Kalra 	return flags;
299*85221a0cSHarman Kalra }
300*85221a0cSHarman Kalra 
3017742c55aSJerin Jacob static int
3027742c55aSJerin Jacob octeontx_dev_configure(struct rte_eth_dev *dev)
3037742c55aSJerin Jacob {
3047742c55aSJerin Jacob 	struct rte_eth_dev_data *data = dev->data;
3057742c55aSJerin Jacob 	struct rte_eth_conf *conf = &data->dev_conf;
3067742c55aSJerin Jacob 	struct rte_eth_rxmode *rxmode = &conf->rxmode;
3077742c55aSJerin Jacob 	struct rte_eth_txmode *txmode = &conf->txmode;
3087742c55aSJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
3097742c55aSJerin Jacob 	int ret;
3107742c55aSJerin Jacob 
3117742c55aSJerin Jacob 	PMD_INIT_FUNC_TRACE();
3127742c55aSJerin Jacob 	RTE_SET_USED(conf);
3137742c55aSJerin Jacob 
3147742c55aSJerin Jacob 	if (!rte_eal_has_hugepages()) {
3157742c55aSJerin Jacob 		octeontx_log_err("huge page is not configured");
3167742c55aSJerin Jacob 		return -EINVAL;
3177742c55aSJerin Jacob 	}
3187742c55aSJerin Jacob 
3197742c55aSJerin Jacob 	if (txmode->mq_mode) {
3207742c55aSJerin Jacob 		octeontx_log_err("tx mq_mode DCB or VMDq not supported");
3217742c55aSJerin Jacob 		return -EINVAL;
3227742c55aSJerin Jacob 	}
3237742c55aSJerin Jacob 
3247742c55aSJerin Jacob 	if (rxmode->mq_mode != ETH_MQ_RX_NONE &&
3257742c55aSJerin Jacob 		rxmode->mq_mode != ETH_MQ_RX_RSS) {
3267742c55aSJerin Jacob 		octeontx_log_err("unsupported rx qmode %d", rxmode->mq_mode);
3277742c55aSJerin Jacob 		return -EINVAL;
3287742c55aSJerin Jacob 	}
3297742c55aSJerin Jacob 
330a4996bd8SWei Dai 	if (!(txmode->offloads & DEV_TX_OFFLOAD_MT_LOCKFREE)) {
331a9287089SPavan Nikhilesh 		PMD_INIT_LOG(NOTICE, "cant disable lockfree tx");
332a4996bd8SWei Dai 		txmode->offloads |= DEV_TX_OFFLOAD_MT_LOCKFREE;
3337742c55aSJerin Jacob 	}
3347742c55aSJerin Jacob 
3357742c55aSJerin Jacob 	if (conf->link_speeds & ETH_LINK_SPEED_FIXED) {
3367742c55aSJerin Jacob 		octeontx_log_err("setting link speed/duplex not supported");
3377742c55aSJerin Jacob 		return -EINVAL;
3387742c55aSJerin Jacob 	}
3397742c55aSJerin Jacob 
3407742c55aSJerin Jacob 	if (conf->dcb_capability_en) {
3417742c55aSJerin Jacob 		octeontx_log_err("DCB enable not supported");
3427742c55aSJerin Jacob 		return -EINVAL;
3437742c55aSJerin Jacob 	}
3447742c55aSJerin Jacob 
3457742c55aSJerin Jacob 	if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
3467742c55aSJerin Jacob 		octeontx_log_err("flow director not supported");
3477742c55aSJerin Jacob 		return -EINVAL;
3487742c55aSJerin Jacob 	}
3497742c55aSJerin Jacob 
3507742c55aSJerin Jacob 	nic->num_tx_queues = dev->data->nb_tx_queues;
3517742c55aSJerin Jacob 
352a6d6f0afSPavan Nikhilesh 	ret = octeontx_pko_channel_open(nic->pko_vfid * PKO_VF_NUM_DQ,
3537742c55aSJerin Jacob 					nic->num_tx_queues,
3547742c55aSJerin Jacob 					nic->base_ochan);
3557742c55aSJerin Jacob 	if (ret) {
3567742c55aSJerin Jacob 		octeontx_log_err("failed to open channel %d no-of-txq %d",
3577742c55aSJerin Jacob 			   nic->base_ochan, nic->num_tx_queues);
3587742c55aSJerin Jacob 		return -EFAULT;
3597742c55aSJerin Jacob 	}
3607742c55aSJerin Jacob 
3617742c55aSJerin Jacob 	nic->pki.classifier_enable = false;
3627742c55aSJerin Jacob 	nic->pki.hash_enable = true;
3637742c55aSJerin Jacob 	nic->pki.initialized = false;
3647742c55aSJerin Jacob 
365*85221a0cSHarman Kalra 	nic->rx_offloads |= rxmode->offloads;
366*85221a0cSHarman Kalra 	nic->tx_offloads |= txmode->offloads;
367*85221a0cSHarman Kalra 	nic->rx_offload_flags |= octeontx_rx_offload_flags(dev);
368*85221a0cSHarman Kalra 	nic->tx_offload_flags |= octeontx_tx_offload_flags(dev);
369*85221a0cSHarman Kalra 
3707742c55aSJerin Jacob 	return 0;
3717742c55aSJerin Jacob }
3727742c55aSJerin Jacob 
37315bce35bSJerin Jacob static void
374da6c6874SJerin Jacob octeontx_dev_close(struct rte_eth_dev *dev)
375da6c6874SJerin Jacob {
376da6c6874SJerin Jacob 	struct octeontx_txq *txq = NULL;
377da6c6874SJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
378da6c6874SJerin Jacob 	unsigned int i;
379da6c6874SJerin Jacob 	int ret;
380da6c6874SJerin Jacob 
381da6c6874SJerin Jacob 	PMD_INIT_FUNC_TRACE();
382da6c6874SJerin Jacob 
383da6c6874SJerin Jacob 	rte_event_dev_close(nic->evdev);
384da6c6874SJerin Jacob 
385da6c6874SJerin Jacob 	ret = octeontx_pko_channel_close(nic->base_ochan);
386da6c6874SJerin Jacob 	if (ret < 0) {
387da6c6874SJerin Jacob 		octeontx_log_err("failed to close channel %d VF%d %d %d",
388da6c6874SJerin Jacob 			     nic->base_ochan, nic->port_id, nic->num_tx_queues,
389da6c6874SJerin Jacob 			     ret);
390da6c6874SJerin Jacob 	}
391da6c6874SJerin Jacob 	/* Free txq resources for this port */
392da6c6874SJerin Jacob 	for (i = 0; i < nic->num_tx_queues; i++) {
393da6c6874SJerin Jacob 		txq = dev->data->tx_queues[i];
394da6c6874SJerin Jacob 		if (!txq)
395da6c6874SJerin Jacob 			continue;
396da6c6874SJerin Jacob 
397da6c6874SJerin Jacob 		rte_free(txq);
398da6c6874SJerin Jacob 	}
399efb9dd14SPavan Nikhilesh 
4009e399b88SSunil Kumar Kori 	/* Free MAC address table */
4019e399b88SSunil Kumar Kori 	rte_free(dev->data->mac_addrs);
4029e399b88SSunil Kumar Kori 	dev->data->mac_addrs = NULL;
4039e399b88SSunil Kumar Kori 
404efb9dd14SPavan Nikhilesh 	dev->tx_pkt_burst = NULL;
405efb9dd14SPavan Nikhilesh 	dev->rx_pkt_burst = NULL;
406da6c6874SJerin Jacob }
407da6c6874SJerin Jacob 
408da6c6874SJerin Jacob static int
409*85221a0cSHarman Kalra octeontx_recheck_rx_offloads(struct octeontx_rxq *rxq)
410*85221a0cSHarman Kalra {
411*85221a0cSHarman Kalra 	struct rte_eth_dev *eth_dev = rxq->eth_dev;
412*85221a0cSHarman Kalra 	struct octeontx_nic *nic = octeontx_pmd_priv(eth_dev);
413*85221a0cSHarman Kalra 	struct rte_eth_dev_data *data = eth_dev->data;
414*85221a0cSHarman Kalra 	struct rte_pktmbuf_pool_private *mbp_priv;
415*85221a0cSHarman Kalra 	struct evdev_priv_data *evdev_priv;
416*85221a0cSHarman Kalra 	struct rte_eventdev *dev;
417*85221a0cSHarman Kalra 	uint32_t buffsz;
418*85221a0cSHarman Kalra 
419*85221a0cSHarman Kalra 	/* Get rx buffer size */
420*85221a0cSHarman Kalra 	mbp_priv = rte_mempool_get_priv(rxq->pool);
421*85221a0cSHarman Kalra 	buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
422*85221a0cSHarman Kalra 
423*85221a0cSHarman Kalra 	/* Setup scatter mode if needed by jumbo */
424*85221a0cSHarman Kalra 	if (data->dev_conf.rxmode.max_rx_pkt_len > buffsz) {
425*85221a0cSHarman Kalra 		nic->rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
426*85221a0cSHarman Kalra 		nic->rx_offload_flags |= octeontx_rx_offload_flags(eth_dev);
427*85221a0cSHarman Kalra 		nic->tx_offload_flags |= octeontx_tx_offload_flags(eth_dev);
428*85221a0cSHarman Kalra 	}
429*85221a0cSHarman Kalra 
430*85221a0cSHarman Kalra 	/* Sharing offload flags via eventdev priv region */
431*85221a0cSHarman Kalra 	dev = &rte_eventdevs[rxq->evdev];
432*85221a0cSHarman Kalra 	evdev_priv = dev->data->dev_private;
433*85221a0cSHarman Kalra 	evdev_priv->rx_offload_flags = nic->rx_offload_flags;
434*85221a0cSHarman Kalra 	evdev_priv->tx_offload_flags = nic->tx_offload_flags;
435*85221a0cSHarman Kalra 
436*85221a0cSHarman Kalra 	return 0;
437*85221a0cSHarman Kalra }
438*85221a0cSHarman Kalra 
439*85221a0cSHarman Kalra static void
440*85221a0cSHarman Kalra octeontx_set_tx_function(struct rte_eth_dev *dev)
441*85221a0cSHarman Kalra {
442*85221a0cSHarman Kalra 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
443*85221a0cSHarman Kalra 
444*85221a0cSHarman Kalra 	const eth_tx_burst_t tx_burst_func[2] = {
445*85221a0cSHarman Kalra 		[0] = octeontx_xmit_pkts,
446*85221a0cSHarman Kalra 		[1] = octeontx_xmit_pkts_mseg,
447*85221a0cSHarman Kalra 	};
448*85221a0cSHarman Kalra 
449*85221a0cSHarman Kalra 	dev->tx_pkt_burst =
450*85221a0cSHarman Kalra 		tx_burst_func[!!(nic->tx_offloads & DEV_TX_OFFLOAD_MULTI_SEGS)];
451*85221a0cSHarman Kalra }
452*85221a0cSHarman Kalra 
453*85221a0cSHarman Kalra static int
454da6c6874SJerin Jacob octeontx_dev_start(struct rte_eth_dev *dev)
455da6c6874SJerin Jacob {
456da6c6874SJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
457da6c6874SJerin Jacob 	int ret;
458da6c6874SJerin Jacob 
459da6c6874SJerin Jacob 	ret = 0;
460da6c6874SJerin Jacob 
461da6c6874SJerin Jacob 	PMD_INIT_FUNC_TRACE();
462da6c6874SJerin Jacob 	/*
463da6c6874SJerin Jacob 	 * Tx start
464da6c6874SJerin Jacob 	 */
465*85221a0cSHarman Kalra 	octeontx_set_tx_function(dev);
466da6c6874SJerin Jacob 	ret = octeontx_pko_channel_start(nic->base_ochan);
467da6c6874SJerin Jacob 	if (ret < 0) {
468da6c6874SJerin Jacob 		octeontx_log_err("fail to conf VF%d no. txq %d chan %d ret %d",
469da6c6874SJerin Jacob 			   nic->port_id, nic->num_tx_queues, nic->base_ochan,
470da6c6874SJerin Jacob 			   ret);
471da6c6874SJerin Jacob 		goto error;
472da6c6874SJerin Jacob 	}
473da6c6874SJerin Jacob 
474da6c6874SJerin Jacob 	/*
475da6c6874SJerin Jacob 	 * Rx start
476da6c6874SJerin Jacob 	 */
477da6c6874SJerin Jacob 	dev->rx_pkt_burst = octeontx_recv_pkts;
478da6c6874SJerin Jacob 	ret = octeontx_pki_port_start(nic->port_id);
479da6c6874SJerin Jacob 	if (ret < 0) {
480da6c6874SJerin Jacob 		octeontx_log_err("fail to start Rx on port %d", nic->port_id);
481da6c6874SJerin Jacob 		goto channel_stop_error;
482da6c6874SJerin Jacob 	}
483da6c6874SJerin Jacob 
484da6c6874SJerin Jacob 	/*
485da6c6874SJerin Jacob 	 * Start port
486da6c6874SJerin Jacob 	 */
487da6c6874SJerin Jacob 	ret = octeontx_port_start(nic);
488da6c6874SJerin Jacob 	if (ret < 0) {
489da6c6874SJerin Jacob 		octeontx_log_err("failed start port %d", ret);
490da6c6874SJerin Jacob 		goto pki_port_stop_error;
491da6c6874SJerin Jacob 	}
492da6c6874SJerin Jacob 
493da6c6874SJerin Jacob 	PMD_TX_LOG(DEBUG, "pko: start channel %d no.of txq %d port %d",
494da6c6874SJerin Jacob 			nic->base_ochan, nic->num_tx_queues, nic->port_id);
495da6c6874SJerin Jacob 
496da6c6874SJerin Jacob 	ret = rte_event_dev_start(nic->evdev);
497da6c6874SJerin Jacob 	if (ret < 0) {
498da6c6874SJerin Jacob 		octeontx_log_err("failed to start evdev: ret (%d)", ret);
499da6c6874SJerin Jacob 		goto pki_port_stop_error;
500da6c6874SJerin Jacob 	}
501da6c6874SJerin Jacob 
502da6c6874SJerin Jacob 	/* Success */
503da6c6874SJerin Jacob 	return ret;
504da6c6874SJerin Jacob 
505da6c6874SJerin Jacob pki_port_stop_error:
506da6c6874SJerin Jacob 	octeontx_pki_port_stop(nic->port_id);
507da6c6874SJerin Jacob channel_stop_error:
508da6c6874SJerin Jacob 	octeontx_pko_channel_stop(nic->base_ochan);
509da6c6874SJerin Jacob error:
510da6c6874SJerin Jacob 	return ret;
511da6c6874SJerin Jacob }
512da6c6874SJerin Jacob 
513da6c6874SJerin Jacob static void
514da6c6874SJerin Jacob octeontx_dev_stop(struct rte_eth_dev *dev)
515da6c6874SJerin Jacob {
516da6c6874SJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
517da6c6874SJerin Jacob 	int ret;
518da6c6874SJerin Jacob 
519da6c6874SJerin Jacob 	PMD_INIT_FUNC_TRACE();
520da6c6874SJerin Jacob 
521da6c6874SJerin Jacob 	rte_event_dev_stop(nic->evdev);
522da6c6874SJerin Jacob 
523da6c6874SJerin Jacob 	ret = octeontx_port_stop(nic);
524da6c6874SJerin Jacob 	if (ret < 0) {
525da6c6874SJerin Jacob 		octeontx_log_err("failed to req stop port %d res=%d",
526da6c6874SJerin Jacob 					nic->port_id, ret);
527da6c6874SJerin Jacob 		return;
528da6c6874SJerin Jacob 	}
529da6c6874SJerin Jacob 
530da6c6874SJerin Jacob 	ret = octeontx_pki_port_stop(nic->port_id);
531da6c6874SJerin Jacob 	if (ret < 0) {
532da6c6874SJerin Jacob 		octeontx_log_err("failed to stop pki port %d res=%d",
533da6c6874SJerin Jacob 					nic->port_id, ret);
534da6c6874SJerin Jacob 		return;
535da6c6874SJerin Jacob 	}
536da6c6874SJerin Jacob 
537da6c6874SJerin Jacob 	ret = octeontx_pko_channel_stop(nic->base_ochan);
538da6c6874SJerin Jacob 	if (ret < 0) {
539da6c6874SJerin Jacob 		octeontx_log_err("failed to stop channel %d VF%d %d %d",
540da6c6874SJerin Jacob 			     nic->base_ochan, nic->port_id, nic->num_tx_queues,
541da6c6874SJerin Jacob 			     ret);
542da6c6874SJerin Jacob 		return;
543da6c6874SJerin Jacob 	}
544da6c6874SJerin Jacob }
545da6c6874SJerin Jacob 
5469039c812SAndrew Rybchenko static int
54715bce35bSJerin Jacob octeontx_dev_promisc_enable(struct rte_eth_dev *dev)
54815bce35bSJerin Jacob {
54915bce35bSJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
55015bce35bSJerin Jacob 
55115bce35bSJerin Jacob 	PMD_INIT_FUNC_TRACE();
5529039c812SAndrew Rybchenko 	return octeontx_port_promisc_set(nic, 1);
55315bce35bSJerin Jacob }
55415bce35bSJerin Jacob 
5559039c812SAndrew Rybchenko static int
55615bce35bSJerin Jacob octeontx_dev_promisc_disable(struct rte_eth_dev *dev)
55715bce35bSJerin Jacob {
55815bce35bSJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
55915bce35bSJerin Jacob 
56015bce35bSJerin Jacob 	PMD_INIT_FUNC_TRACE();
5619039c812SAndrew Rybchenko 	return octeontx_port_promisc_set(nic, 0);
56215bce35bSJerin Jacob }
56315bce35bSJerin Jacob 
5644fac7c0aSJerin Jacob static int
5654fac7c0aSJerin Jacob octeontx_port_link_status(struct octeontx_nic *nic)
5664fac7c0aSJerin Jacob {
5674fac7c0aSJerin Jacob 	int res;
5684fac7c0aSJerin Jacob 
5694fac7c0aSJerin Jacob 	PMD_INIT_FUNC_TRACE();
5704fac7c0aSJerin Jacob 	res = octeontx_bgx_port_link_status(nic->port_id);
5714fac7c0aSJerin Jacob 	if (res < 0) {
5724fac7c0aSJerin Jacob 		octeontx_log_err("failed to get port %d link status",
5734fac7c0aSJerin Jacob 				nic->port_id);
5744fac7c0aSJerin Jacob 		return res;
5754fac7c0aSJerin Jacob 	}
5764fac7c0aSJerin Jacob 
5774fac7c0aSJerin Jacob 	nic->link_up = (uint8_t)res;
5784fac7c0aSJerin Jacob 	octeontx_log_dbg("port %d link status %d", nic->port_id, nic->link_up);
5794fac7c0aSJerin Jacob 
5804fac7c0aSJerin Jacob 	return res;
5814fac7c0aSJerin Jacob }
5824fac7c0aSJerin Jacob 
5834fac7c0aSJerin Jacob /*
5844fac7c0aSJerin Jacob  * Return 0 means link status changed, -1 means not changed
5854fac7c0aSJerin Jacob  */
5864fac7c0aSJerin Jacob static int
5874fac7c0aSJerin Jacob octeontx_dev_link_update(struct rte_eth_dev *dev,
5884fac7c0aSJerin Jacob 			 int wait_to_complete __rte_unused)
5894fac7c0aSJerin Jacob {
5904fac7c0aSJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
5914fac7c0aSJerin Jacob 	struct rte_eth_link link;
5924fac7c0aSJerin Jacob 	int res;
5934fac7c0aSJerin Jacob 
5944fac7c0aSJerin Jacob 	PMD_INIT_FUNC_TRACE();
5954fac7c0aSJerin Jacob 
5964fac7c0aSJerin Jacob 	res = octeontx_port_link_status(nic);
5974fac7c0aSJerin Jacob 	if (res < 0) {
5984fac7c0aSJerin Jacob 		octeontx_log_err("failed to request link status %d", res);
5994fac7c0aSJerin Jacob 		return res;
6004fac7c0aSJerin Jacob 	}
6014fac7c0aSJerin Jacob 
6024fac7c0aSJerin Jacob 	link.link_status = nic->link_up;
6034fac7c0aSJerin Jacob 
6044fac7c0aSJerin Jacob 	switch (nic->speed) {
6054fac7c0aSJerin Jacob 	case OCTEONTX_LINK_SPEED_SGMII:
6064fac7c0aSJerin Jacob 		link.link_speed = ETH_SPEED_NUM_1G;
6074fac7c0aSJerin Jacob 		break;
6084fac7c0aSJerin Jacob 
6094fac7c0aSJerin Jacob 	case OCTEONTX_LINK_SPEED_XAUI:
6104fac7c0aSJerin Jacob 		link.link_speed = ETH_SPEED_NUM_10G;
6114fac7c0aSJerin Jacob 		break;
6124fac7c0aSJerin Jacob 
6134fac7c0aSJerin Jacob 	case OCTEONTX_LINK_SPEED_RXAUI:
6144fac7c0aSJerin Jacob 	case OCTEONTX_LINK_SPEED_10G_R:
6154fac7c0aSJerin Jacob 		link.link_speed = ETH_SPEED_NUM_10G;
6164fac7c0aSJerin Jacob 		break;
6174fac7c0aSJerin Jacob 	case OCTEONTX_LINK_SPEED_QSGMII:
6184fac7c0aSJerin Jacob 		link.link_speed = ETH_SPEED_NUM_5G;
6194fac7c0aSJerin Jacob 		break;
6204fac7c0aSJerin Jacob 	case OCTEONTX_LINK_SPEED_40G_R:
6214fac7c0aSJerin Jacob 		link.link_speed = ETH_SPEED_NUM_40G;
6224fac7c0aSJerin Jacob 		break;
6234fac7c0aSJerin Jacob 
6244fac7c0aSJerin Jacob 	case OCTEONTX_LINK_SPEED_RESERVE1:
6254fac7c0aSJerin Jacob 	case OCTEONTX_LINK_SPEED_RESERVE2:
6264fac7c0aSJerin Jacob 	default:
6273a4b87c8SStephen Hemminger 		link.link_speed = ETH_SPEED_NUM_NONE;
6284fac7c0aSJerin Jacob 		octeontx_log_err("incorrect link speed %d", nic->speed);
6294fac7c0aSJerin Jacob 		break;
6304fac7c0aSJerin Jacob 	}
6314fac7c0aSJerin Jacob 
6321e3a958fSThomas Monjalon 	link.link_duplex = ETH_LINK_FULL_DUPLEX;
6331e3a958fSThomas Monjalon 	link.link_autoneg = ETH_LINK_AUTONEG;
6344fac7c0aSJerin Jacob 
6352b4ab422SStephen Hemminger 	return rte_eth_linkstatus_set(dev, &link);
6364fac7c0aSJerin Jacob }
6374fac7c0aSJerin Jacob 
638d5b0924bSMatan Azrad static int
63955389909SJerin Jacob octeontx_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
64055389909SJerin Jacob {
64155389909SJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
64255389909SJerin Jacob 
64355389909SJerin Jacob 	PMD_INIT_FUNC_TRACE();
644d5b0924bSMatan Azrad 	return octeontx_port_stats(nic, stats);
64555389909SJerin Jacob }
64655389909SJerin Jacob 
6479970a9adSIgor Romanov static int
64855389909SJerin Jacob octeontx_dev_stats_reset(struct rte_eth_dev *dev)
64955389909SJerin Jacob {
65055389909SJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
65155389909SJerin Jacob 
65255389909SJerin Jacob 	PMD_INIT_FUNC_TRACE();
6539970a9adSIgor Romanov 	return octeontx_port_stats_clr(nic);
65455389909SJerin Jacob }
65555389909SJerin Jacob 
656e4373bf1SSunil Kumar Kori static void
657e4373bf1SSunil Kumar Kori octeontx_dev_mac_addr_del(struct rte_eth_dev *dev, uint32_t index)
658e4373bf1SSunil Kumar Kori {
659e4373bf1SSunil Kumar Kori 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
660e4373bf1SSunil Kumar Kori 	int ret;
661e4373bf1SSunil Kumar Kori 
662e4373bf1SSunil Kumar Kori 	ret = octeontx_bgx_port_mac_del(nic->port_id, index);
663e4373bf1SSunil Kumar Kori 	if (ret != 0)
664e4373bf1SSunil Kumar Kori 		octeontx_log_err("failed to del MAC address filter on port %d",
665e4373bf1SSunil Kumar Kori 				 nic->port_id);
666e4373bf1SSunil Kumar Kori }
667e4373bf1SSunil Kumar Kori 
668e4373bf1SSunil Kumar Kori static int
669e4373bf1SSunil Kumar Kori octeontx_dev_mac_addr_add(struct rte_eth_dev *dev,
670e4373bf1SSunil Kumar Kori 			  struct rte_ether_addr *mac_addr,
6719614459bSSunil Kumar Kori 			  uint32_t index,
672e4373bf1SSunil Kumar Kori 			  __rte_unused uint32_t vmdq)
673e4373bf1SSunil Kumar Kori {
674e4373bf1SSunil Kumar Kori 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
675e4373bf1SSunil Kumar Kori 	int ret;
676e4373bf1SSunil Kumar Kori 
6779614459bSSunil Kumar Kori 	ret = octeontx_bgx_port_mac_add(nic->port_id, mac_addr->addr_bytes,
6789614459bSSunil Kumar Kori 					index);
679e4373bf1SSunil Kumar Kori 	if (ret < 0) {
680e4373bf1SSunil Kumar Kori 		octeontx_log_err("failed to add MAC address filter on port %d",
681e4373bf1SSunil Kumar Kori 				 nic->port_id);
682e4373bf1SSunil Kumar Kori 		return ret;
683e4373bf1SSunil Kumar Kori 	}
684e4373bf1SSunil Kumar Kori 
685e4373bf1SSunil Kumar Kori 	return 0;
686e4373bf1SSunil Kumar Kori }
687e4373bf1SSunil Kumar Kori 
688caccf8b3SOlivier Matz static int
689ef7308fcSJerin Jacob octeontx_dev_default_mac_addr_set(struct rte_eth_dev *dev,
6906d13ea8eSOlivier Matz 					struct rte_ether_addr *addr)
691ef7308fcSJerin Jacob {
692ef7308fcSJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
693ef7308fcSJerin Jacob 	int ret;
694ef7308fcSJerin Jacob 
695ef7308fcSJerin Jacob 	ret = octeontx_bgx_port_mac_set(nic->port_id, addr->addr_bytes);
6969614459bSSunil Kumar Kori 	if (ret == 0) {
6979614459bSSunil Kumar Kori 		/* Update same mac address to BGX CAM table */
6989614459bSSunil Kumar Kori 		ret = octeontx_bgx_port_mac_add(nic->port_id, addr->addr_bytes,
6999614459bSSunil Kumar Kori 						0);
7009614459bSSunil Kumar Kori 	}
7019614459bSSunil Kumar Kori 	if (ret < 0) {
702ef7308fcSJerin Jacob 		octeontx_log_err("failed to set MAC address on port %d",
703ef7308fcSJerin Jacob 				 nic->port_id);
7049614459bSSunil Kumar Kori 	}
705caccf8b3SOlivier Matz 
706caccf8b3SOlivier Matz 	return ret;
707ef7308fcSJerin Jacob }
708ef7308fcSJerin Jacob 
709bdad90d1SIvan Ilchenko static int
7107c0347a2SJerin Jacob octeontx_dev_info(struct rte_eth_dev *dev,
7117c0347a2SJerin Jacob 		struct rte_eth_dev_info *dev_info)
7127c0347a2SJerin Jacob {
713e4373bf1SSunil Kumar Kori 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
7147c0347a2SJerin Jacob 
7157c0347a2SJerin Jacob 	/* Autonegotiation may be disabled */
7167c0347a2SJerin Jacob 	dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
7177c0347a2SJerin Jacob 	dev_info->speed_capa |= ETH_LINK_SPEED_10M | ETH_LINK_SPEED_100M |
7187c0347a2SJerin Jacob 			ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
7197c0347a2SJerin Jacob 			ETH_LINK_SPEED_40G;
7207c0347a2SJerin Jacob 
721e4373bf1SSunil Kumar Kori 	dev_info->max_mac_addrs =
722e4373bf1SSunil Kumar Kori 				octeontx_bgx_port_mac_entries_get(nic->port_id);
7237c0347a2SJerin Jacob 	dev_info->max_rx_pktlen = PKI_MAX_PKTLEN;
7247c0347a2SJerin Jacob 	dev_info->max_rx_queues = 1;
7257c0347a2SJerin Jacob 	dev_info->max_tx_queues = PKO_MAX_NUM_DQ;
7267c0347a2SJerin Jacob 	dev_info->min_rx_bufsize = 0;
7277c0347a2SJerin Jacob 
7287c0347a2SJerin Jacob 	dev_info->default_rxconf = (struct rte_eth_rxconf) {
7297c0347a2SJerin Jacob 		.rx_free_thresh = 0,
7307c0347a2SJerin Jacob 		.rx_drop_en = 0,
731a9287089SPavan Nikhilesh 		.offloads = OCTEONTX_RX_OFFLOADS,
7327c0347a2SJerin Jacob 	};
7337c0347a2SJerin Jacob 
7347c0347a2SJerin Jacob 	dev_info->default_txconf = (struct rte_eth_txconf) {
7357c0347a2SJerin Jacob 		.tx_free_thresh = 0,
7362fd41a15SPavan Nikhilesh 		.offloads = OCTEONTX_TX_OFFLOADS,
7377c0347a2SJerin Jacob 	};
7387c0347a2SJerin Jacob 
739a9287089SPavan Nikhilesh 	dev_info->rx_offload_capa = OCTEONTX_RX_OFFLOADS;
740a9287089SPavan Nikhilesh 	dev_info->tx_offload_capa = OCTEONTX_TX_OFFLOADS;
74179c25ae2SPavan Nikhilesh 	dev_info->rx_queue_offload_capa = OCTEONTX_RX_OFFLOADS;
74279c25ae2SPavan Nikhilesh 	dev_info->tx_queue_offload_capa = OCTEONTX_TX_OFFLOADS;
743bdad90d1SIvan Ilchenko 
744bdad90d1SIvan Ilchenko 	return 0;
7457c0347a2SJerin Jacob }
7467c0347a2SJerin Jacob 
7477fe7c98fSJerin Jacob static void
7487fe7c98fSJerin Jacob octeontx_dq_info_getter(octeontx_dq_t *dq, void *out)
7497fe7c98fSJerin Jacob {
7507fe7c98fSJerin Jacob 	((octeontx_dq_t *)out)->lmtline_va = dq->lmtline_va;
7517fe7c98fSJerin Jacob 	((octeontx_dq_t *)out)->ioreg_va = dq->ioreg_va;
7527fe7c98fSJerin Jacob 	((octeontx_dq_t *)out)->fc_status_va = dq->fc_status_va;
7537fe7c98fSJerin Jacob }
7547fe7c98fSJerin Jacob 
7557fe7c98fSJerin Jacob static int
7567fe7c98fSJerin Jacob octeontx_vf_start_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
7577fe7c98fSJerin Jacob 				uint16_t qidx)
7587fe7c98fSJerin Jacob {
7597fe7c98fSJerin Jacob 	struct octeontx_txq *txq;
7607fe7c98fSJerin Jacob 	int res;
7617fe7c98fSJerin Jacob 
7627fe7c98fSJerin Jacob 	PMD_INIT_FUNC_TRACE();
7637fe7c98fSJerin Jacob 
7647fe7c98fSJerin Jacob 	if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED)
7657fe7c98fSJerin Jacob 		return 0;
7667fe7c98fSJerin Jacob 
7677fe7c98fSJerin Jacob 	txq = dev->data->tx_queues[qidx];
7687fe7c98fSJerin Jacob 
7697fe7c98fSJerin Jacob 	res = octeontx_pko_channel_query_dqs(nic->base_ochan,
7707fe7c98fSJerin Jacob 						&txq->dq,
7717fe7c98fSJerin Jacob 						sizeof(octeontx_dq_t),
7727fe7c98fSJerin Jacob 						txq->queue_id,
7737fe7c98fSJerin Jacob 						octeontx_dq_info_getter);
7747fe7c98fSJerin Jacob 	if (res < 0) {
7757fe7c98fSJerin Jacob 		res = -EFAULT;
7767fe7c98fSJerin Jacob 		goto close_port;
7777fe7c98fSJerin Jacob 	}
7787fe7c98fSJerin Jacob 
7797fe7c98fSJerin Jacob 	dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
7807fe7c98fSJerin Jacob 	return res;
7817fe7c98fSJerin Jacob 
7827fe7c98fSJerin Jacob close_port:
7837fe7c98fSJerin Jacob 	(void)octeontx_port_stop(nic);
7847fe7c98fSJerin Jacob 	octeontx_pko_channel_stop(nic->base_ochan);
7857fe7c98fSJerin Jacob 	octeontx_pko_channel_close(nic->base_ochan);
7867fe7c98fSJerin Jacob 	dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
7877fe7c98fSJerin Jacob 	return res;
7887fe7c98fSJerin Jacob }
7897fe7c98fSJerin Jacob 
7907fe7c98fSJerin Jacob static int
7917fe7c98fSJerin Jacob octeontx_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
7927fe7c98fSJerin Jacob {
7937fe7c98fSJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
7947fe7c98fSJerin Jacob 
7957fe7c98fSJerin Jacob 	PMD_INIT_FUNC_TRACE();
7967fe7c98fSJerin Jacob 	qidx = qidx % PKO_VF_NUM_DQ;
7977fe7c98fSJerin Jacob 	return octeontx_vf_start_tx_queue(dev, nic, qidx);
7987fe7c98fSJerin Jacob }
7997fe7c98fSJerin Jacob 
8007fe7c98fSJerin Jacob static inline int
8017fe7c98fSJerin Jacob octeontx_vf_stop_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
8027fe7c98fSJerin Jacob 			  uint16_t qidx)
8037fe7c98fSJerin Jacob {
8047fe7c98fSJerin Jacob 	int ret = 0;
8057fe7c98fSJerin Jacob 
8067fe7c98fSJerin Jacob 	RTE_SET_USED(nic);
8077fe7c98fSJerin Jacob 	PMD_INIT_FUNC_TRACE();
8087fe7c98fSJerin Jacob 
8097fe7c98fSJerin Jacob 	if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED)
8107fe7c98fSJerin Jacob 		return 0;
8117fe7c98fSJerin Jacob 
8127fe7c98fSJerin Jacob 	dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
8137fe7c98fSJerin Jacob 	return ret;
8147fe7c98fSJerin Jacob }
8157fe7c98fSJerin Jacob 
8167fe7c98fSJerin Jacob static int
8177fe7c98fSJerin Jacob octeontx_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
8187fe7c98fSJerin Jacob {
8197fe7c98fSJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
8207fe7c98fSJerin Jacob 
8217fe7c98fSJerin Jacob 	PMD_INIT_FUNC_TRACE();
8227fe7c98fSJerin Jacob 	qidx = qidx % PKO_VF_NUM_DQ;
8237fe7c98fSJerin Jacob 
8247fe7c98fSJerin Jacob 	return octeontx_vf_stop_tx_queue(dev, nic, qidx);
8257fe7c98fSJerin Jacob }
8267fe7c98fSJerin Jacob 
827150cbc84SJerin Jacob static void
828150cbc84SJerin Jacob octeontx_dev_tx_queue_release(void *tx_queue)
829150cbc84SJerin Jacob {
830150cbc84SJerin Jacob 	struct octeontx_txq *txq = tx_queue;
831150cbc84SJerin Jacob 	int res;
832150cbc84SJerin Jacob 
833150cbc84SJerin Jacob 	PMD_INIT_FUNC_TRACE();
834150cbc84SJerin Jacob 
835150cbc84SJerin Jacob 	if (txq) {
836150cbc84SJerin Jacob 		res = octeontx_dev_tx_queue_stop(txq->eth_dev, txq->queue_id);
837150cbc84SJerin Jacob 		if (res < 0)
838150cbc84SJerin Jacob 			octeontx_log_err("failed stop tx_queue(%d)\n",
839150cbc84SJerin Jacob 				   txq->queue_id);
840150cbc84SJerin Jacob 
841150cbc84SJerin Jacob 		rte_free(txq);
842150cbc84SJerin Jacob 	}
843150cbc84SJerin Jacob }
844150cbc84SJerin Jacob 
845150cbc84SJerin Jacob static int
846150cbc84SJerin Jacob octeontx_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
847150cbc84SJerin Jacob 			    uint16_t nb_desc, unsigned int socket_id,
848a4996bd8SWei Dai 			    const struct rte_eth_txconf *tx_conf __rte_unused)
849150cbc84SJerin Jacob {
850150cbc84SJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
851150cbc84SJerin Jacob 	struct octeontx_txq *txq = NULL;
852150cbc84SJerin Jacob 	uint16_t dq_num;
853150cbc84SJerin Jacob 	int res = 0;
854150cbc84SJerin Jacob 
855150cbc84SJerin Jacob 	RTE_SET_USED(nb_desc);
856150cbc84SJerin Jacob 	RTE_SET_USED(socket_id);
857150cbc84SJerin Jacob 
858a6d6f0afSPavan Nikhilesh 	dq_num = (nic->pko_vfid * PKO_VF_NUM_DQ) + qidx;
859150cbc84SJerin Jacob 
860150cbc84SJerin Jacob 	/* Socket id check */
861150cbc84SJerin Jacob 	if (socket_id != (unsigned int)SOCKET_ID_ANY &&
862150cbc84SJerin Jacob 			socket_id != (unsigned int)nic->node)
863150cbc84SJerin Jacob 		PMD_TX_LOG(INFO, "socket_id expected %d, configured %d",
864150cbc84SJerin Jacob 						socket_id, nic->node);
865150cbc84SJerin Jacob 
866150cbc84SJerin Jacob 	/* Free memory prior to re-allocation if needed. */
867150cbc84SJerin Jacob 	if (dev->data->tx_queues[qidx] != NULL) {
868150cbc84SJerin Jacob 		PMD_TX_LOG(DEBUG, "freeing memory prior to re-allocation %d",
869150cbc84SJerin Jacob 				qidx);
870150cbc84SJerin Jacob 		octeontx_dev_tx_queue_release(dev->data->tx_queues[qidx]);
871150cbc84SJerin Jacob 		dev->data->tx_queues[qidx] = NULL;
872150cbc84SJerin Jacob 	}
873150cbc84SJerin Jacob 
874150cbc84SJerin Jacob 	/* Allocating tx queue data structure */
875150cbc84SJerin Jacob 	txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct octeontx_txq),
876150cbc84SJerin Jacob 				 RTE_CACHE_LINE_SIZE, nic->node);
877150cbc84SJerin Jacob 	if (txq == NULL) {
878150cbc84SJerin Jacob 		octeontx_log_err("failed to allocate txq=%d", qidx);
879150cbc84SJerin Jacob 		res = -ENOMEM;
880150cbc84SJerin Jacob 		goto err;
881150cbc84SJerin Jacob 	}
882150cbc84SJerin Jacob 
883150cbc84SJerin Jacob 	txq->eth_dev = dev;
884150cbc84SJerin Jacob 	txq->queue_id = dq_num;
885150cbc84SJerin Jacob 	dev->data->tx_queues[qidx] = txq;
886150cbc84SJerin Jacob 	dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
887150cbc84SJerin Jacob 
888150cbc84SJerin Jacob 	res = octeontx_pko_channel_query_dqs(nic->base_ochan,
889150cbc84SJerin Jacob 						&txq->dq,
890150cbc84SJerin Jacob 						sizeof(octeontx_dq_t),
891150cbc84SJerin Jacob 						txq->queue_id,
892150cbc84SJerin Jacob 						octeontx_dq_info_getter);
893150cbc84SJerin Jacob 	if (res < 0) {
894150cbc84SJerin Jacob 		res = -EFAULT;
895150cbc84SJerin Jacob 		goto err;
896150cbc84SJerin Jacob 	}
897150cbc84SJerin Jacob 
898150cbc84SJerin Jacob 	PMD_TX_LOG(DEBUG, "[%d]:[%d] txq=%p nb_desc=%d lmtline=%p ioreg_va=%p fc_status_va=%p",
899150cbc84SJerin Jacob 			qidx, txq->queue_id, txq, nb_desc, txq->dq.lmtline_va,
900150cbc84SJerin Jacob 			txq->dq.ioreg_va,
901150cbc84SJerin Jacob 			txq->dq.fc_status_va);
902150cbc84SJerin Jacob 
903150cbc84SJerin Jacob 	return res;
904150cbc84SJerin Jacob 
905150cbc84SJerin Jacob err:
906150cbc84SJerin Jacob 	if (txq)
907150cbc84SJerin Jacob 		rte_free(txq);
908150cbc84SJerin Jacob 
909150cbc84SJerin Jacob 	return res;
910150cbc84SJerin Jacob }
911150cbc84SJerin Jacob 
912197438eeSJerin Jacob static int
913197438eeSJerin Jacob octeontx_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
914197438eeSJerin Jacob 				uint16_t nb_desc, unsigned int socket_id,
915197438eeSJerin Jacob 				const struct rte_eth_rxconf *rx_conf,
916197438eeSJerin Jacob 				struct rte_mempool *mb_pool)
917197438eeSJerin Jacob {
918197438eeSJerin Jacob 	struct octeontx_nic *nic = octeontx_pmd_priv(dev);
919197438eeSJerin Jacob 	struct rte_mempool_ops *mp_ops = NULL;
920197438eeSJerin Jacob 	struct octeontx_rxq *rxq = NULL;
921197438eeSJerin Jacob 	pki_pktbuf_cfg_t pktbuf_conf;
922197438eeSJerin Jacob 	pki_hash_cfg_t pki_hash;
923197438eeSJerin Jacob 	pki_qos_cfg_t pki_qos;
924197438eeSJerin Jacob 	uintptr_t pool;
925197438eeSJerin Jacob 	int ret, port;
926179c7e89SPavan Nikhilesh 	uint16_t gaura;
927197438eeSJerin Jacob 	unsigned int ev_queues = (nic->ev_queues * nic->port_id) + qidx;
928197438eeSJerin Jacob 	unsigned int ev_ports = (nic->ev_ports * nic->port_id) + qidx;
929197438eeSJerin Jacob 
930197438eeSJerin Jacob 	RTE_SET_USED(nb_desc);
931197438eeSJerin Jacob 
932197438eeSJerin Jacob 	memset(&pktbuf_conf, 0, sizeof(pktbuf_conf));
933197438eeSJerin Jacob 	memset(&pki_hash, 0, sizeof(pki_hash));
934197438eeSJerin Jacob 	memset(&pki_qos, 0, sizeof(pki_qos));
935197438eeSJerin Jacob 
936197438eeSJerin Jacob 	mp_ops = rte_mempool_get_ops(mb_pool->ops_index);
937197438eeSJerin Jacob 	if (strcmp(mp_ops->name, "octeontx_fpavf")) {
938197438eeSJerin Jacob 		octeontx_log_err("failed to find octeontx_fpavf mempool");
939197438eeSJerin Jacob 		return -ENOTSUP;
940197438eeSJerin Jacob 	}
941197438eeSJerin Jacob 
942197438eeSJerin Jacob 	/* Handle forbidden configurations */
943197438eeSJerin Jacob 	if (nic->pki.classifier_enable) {
944197438eeSJerin Jacob 		octeontx_log_err("cannot setup queue %d. "
945197438eeSJerin Jacob 					"Classifier option unsupported", qidx);
946197438eeSJerin Jacob 		return -EINVAL;
947197438eeSJerin Jacob 	}
948197438eeSJerin Jacob 
949197438eeSJerin Jacob 	port = nic->port_id;
950197438eeSJerin Jacob 
951197438eeSJerin Jacob 	/* Rx deferred start is not supported */
952197438eeSJerin Jacob 	if (rx_conf->rx_deferred_start) {
953197438eeSJerin Jacob 		octeontx_log_err("rx deferred start not supported");
954197438eeSJerin Jacob 		return -EINVAL;
955197438eeSJerin Jacob 	}
956197438eeSJerin Jacob 
957197438eeSJerin Jacob 	/* Verify queue index */
958197438eeSJerin Jacob 	if (qidx >= dev->data->nb_rx_queues) {
959197438eeSJerin Jacob 		octeontx_log_err("QID %d not supporteded (0 - %d available)\n",
960197438eeSJerin Jacob 				qidx, (dev->data->nb_rx_queues - 1));
961197438eeSJerin Jacob 		return -ENOTSUP;
962197438eeSJerin Jacob 	}
963197438eeSJerin Jacob 
964197438eeSJerin Jacob 	/* Socket id check */
965197438eeSJerin Jacob 	if (socket_id != (unsigned int)SOCKET_ID_ANY &&
966197438eeSJerin Jacob 			socket_id != (unsigned int)nic->node)
967197438eeSJerin Jacob 		PMD_RX_LOG(INFO, "socket_id expected %d, configured %d",
968197438eeSJerin Jacob 						socket_id, nic->node);
969197438eeSJerin Jacob 
970197438eeSJerin Jacob 	/* Allocating rx queue data structure */
971197438eeSJerin Jacob 	rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct octeontx_rxq),
972197438eeSJerin Jacob 				 RTE_CACHE_LINE_SIZE, nic->node);
973197438eeSJerin Jacob 	if (rxq == NULL) {
974197438eeSJerin Jacob 		octeontx_log_err("failed to allocate rxq=%d", qidx);
975197438eeSJerin Jacob 		return -ENOMEM;
976197438eeSJerin Jacob 	}
977197438eeSJerin Jacob 
978197438eeSJerin Jacob 	if (!nic->pki.initialized) {
979197438eeSJerin Jacob 		pktbuf_conf.port_type = 0;
980197438eeSJerin Jacob 		pki_hash.port_type = 0;
981197438eeSJerin Jacob 		pki_qos.port_type = 0;
982197438eeSJerin Jacob 
983197438eeSJerin Jacob 		pktbuf_conf.mmask.f_wqe_skip = 1;
984197438eeSJerin Jacob 		pktbuf_conf.mmask.f_first_skip = 1;
985197438eeSJerin Jacob 		pktbuf_conf.mmask.f_later_skip = 1;
986197438eeSJerin Jacob 		pktbuf_conf.mmask.f_mbuff_size = 1;
987197438eeSJerin Jacob 		pktbuf_conf.mmask.f_cache_mode = 1;
988197438eeSJerin Jacob 
989197438eeSJerin Jacob 		pktbuf_conf.wqe_skip = OCTTX_PACKET_WQE_SKIP;
990679dfdc9SNitin Saxena 		pktbuf_conf.first_skip = OCTTX_PACKET_FIRST_SKIP(mb_pool);
991197438eeSJerin Jacob 		pktbuf_conf.later_skip = OCTTX_PACKET_LATER_SKIP;
992197438eeSJerin Jacob 		pktbuf_conf.mbuff_size = (mb_pool->elt_size -
993197438eeSJerin Jacob 					RTE_PKTMBUF_HEADROOM -
994679dfdc9SNitin Saxena 					rte_pktmbuf_priv_size(mb_pool) -
995197438eeSJerin Jacob 					sizeof(struct rte_mbuf));
996197438eeSJerin Jacob 
997197438eeSJerin Jacob 		pktbuf_conf.cache_mode = PKI_OPC_MODE_STF2_STT;
998197438eeSJerin Jacob 
999197438eeSJerin Jacob 		ret = octeontx_pki_port_pktbuf_config(port, &pktbuf_conf);
1000197438eeSJerin Jacob 		if (ret != 0) {
1001197438eeSJerin Jacob 			octeontx_log_err("fail to configure pktbuf for port %d",
1002197438eeSJerin Jacob 					port);
1003197438eeSJerin Jacob 			rte_free(rxq);
1004197438eeSJerin Jacob 			return ret;
1005197438eeSJerin Jacob 		}
1006197438eeSJerin Jacob 		PMD_RX_LOG(DEBUG, "Port %d Rx pktbuf configured:\n"
1007197438eeSJerin Jacob 				"\tmbuf_size:\t0x%0x\n"
1008197438eeSJerin Jacob 				"\twqe_skip:\t0x%0x\n"
1009197438eeSJerin Jacob 				"\tfirst_skip:\t0x%0x\n"
1010197438eeSJerin Jacob 				"\tlater_skip:\t0x%0x\n"
1011197438eeSJerin Jacob 				"\tcache_mode:\t%s\n",
1012197438eeSJerin Jacob 				port,
1013197438eeSJerin Jacob 				pktbuf_conf.mbuff_size,
1014197438eeSJerin Jacob 				pktbuf_conf.wqe_skip,
1015197438eeSJerin Jacob 				pktbuf_conf.first_skip,
1016197438eeSJerin Jacob 				pktbuf_conf.later_skip,
1017197438eeSJerin Jacob 				(pktbuf_conf.cache_mode ==
1018197438eeSJerin Jacob 						PKI_OPC_MODE_STT) ?
1019197438eeSJerin Jacob 				"STT" :
1020197438eeSJerin Jacob 				(pktbuf_conf.cache_mode ==
1021197438eeSJerin Jacob 						PKI_OPC_MODE_STF) ?
1022197438eeSJerin Jacob 				"STF" :
1023197438eeSJerin Jacob 				(pktbuf_conf.cache_mode ==
1024197438eeSJerin Jacob 						PKI_OPC_MODE_STF1_STT) ?
1025197438eeSJerin Jacob 				"STF1_STT" : "STF2_STT");
1026197438eeSJerin Jacob 
1027197438eeSJerin Jacob 		if (nic->pki.hash_enable) {
1028197438eeSJerin Jacob 			pki_hash.tag_dlc = 1;
1029197438eeSJerin Jacob 			pki_hash.tag_slc = 1;
1030197438eeSJerin Jacob 			pki_hash.tag_dlf = 1;
1031197438eeSJerin Jacob 			pki_hash.tag_slf = 1;
1032d0d65498SPavan Nikhilesh 			pki_hash.tag_prt = 1;
1033197438eeSJerin Jacob 			octeontx_pki_port_hash_config(port, &pki_hash);
1034197438eeSJerin Jacob 		}
1035197438eeSJerin Jacob 
1036197438eeSJerin Jacob 		pool = (uintptr_t)mb_pool->pool_id;
1037197438eeSJerin Jacob 
1038179c7e89SPavan Nikhilesh 		/* Get the gaura Id */
1039179c7e89SPavan Nikhilesh 		gaura = octeontx_fpa_bufpool_gaura(pool);
1040197438eeSJerin Jacob 
1041197438eeSJerin Jacob 		pki_qos.qpg_qos = PKI_QPG_QOS_NONE;
1042197438eeSJerin Jacob 		pki_qos.num_entry = 1;
1043197438eeSJerin Jacob 		pki_qos.drop_policy = 0;
1044d0d65498SPavan Nikhilesh 		pki_qos.tag_type = 0L;
1045197438eeSJerin Jacob 		pki_qos.qos_entry[0].port_add = 0;
1046197438eeSJerin Jacob 		pki_qos.qos_entry[0].gaura = gaura;
1047197438eeSJerin Jacob 		pki_qos.qos_entry[0].ggrp_ok = ev_queues;
1048197438eeSJerin Jacob 		pki_qos.qos_entry[0].ggrp_bad = ev_queues;
1049197438eeSJerin Jacob 		pki_qos.qos_entry[0].grptag_bad = 0;
1050197438eeSJerin Jacob 		pki_qos.qos_entry[0].grptag_ok = 0;
1051197438eeSJerin Jacob 
1052197438eeSJerin Jacob 		ret = octeontx_pki_port_create_qos(port, &pki_qos);
1053197438eeSJerin Jacob 		if (ret < 0) {
1054197438eeSJerin Jacob 			octeontx_log_err("failed to create QOS port=%d, q=%d",
1055197438eeSJerin Jacob 					port, qidx);
1056197438eeSJerin Jacob 			rte_free(rxq);
1057197438eeSJerin Jacob 			return ret;
1058197438eeSJerin Jacob 		}
1059197438eeSJerin Jacob 		nic->pki.initialized = true;
1060197438eeSJerin Jacob 	}
1061197438eeSJerin Jacob 
1062197438eeSJerin Jacob 	rxq->port_id = nic->port_id;
1063197438eeSJerin Jacob 	rxq->eth_dev = dev;
1064197438eeSJerin Jacob 	rxq->queue_id = qidx;
1065197438eeSJerin Jacob 	rxq->evdev = nic->evdev;
1066197438eeSJerin Jacob 	rxq->ev_queues = ev_queues;
1067197438eeSJerin Jacob 	rxq->ev_ports = ev_ports;
1068*85221a0cSHarman Kalra 	rxq->pool = mb_pool;
1069197438eeSJerin Jacob 
1070*85221a0cSHarman Kalra 	octeontx_recheck_rx_offloads(rxq);
1071197438eeSJerin Jacob 	dev->data->rx_queues[qidx] = rxq;
1072197438eeSJerin Jacob 	dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
1073197438eeSJerin Jacob 	return 0;
1074197438eeSJerin Jacob }
1075197438eeSJerin Jacob 
1076197438eeSJerin Jacob static void
1077197438eeSJerin Jacob octeontx_dev_rx_queue_release(void *rxq)
1078197438eeSJerin Jacob {
1079197438eeSJerin Jacob 	rte_free(rxq);
1080197438eeSJerin Jacob }
1081197438eeSJerin Jacob 
108220186d43SJerin Jacob static const uint32_t *
108320186d43SJerin Jacob octeontx_dev_supported_ptypes_get(struct rte_eth_dev *dev)
108420186d43SJerin Jacob {
108520186d43SJerin Jacob 	static const uint32_t ptypes[] = {
108620186d43SJerin Jacob 		RTE_PTYPE_L3_IPV4,
108720186d43SJerin Jacob 		RTE_PTYPE_L3_IPV4_EXT,
108820186d43SJerin Jacob 		RTE_PTYPE_L3_IPV6,
108920186d43SJerin Jacob 		RTE_PTYPE_L3_IPV6_EXT,
109020186d43SJerin Jacob 		RTE_PTYPE_L4_TCP,
109120186d43SJerin Jacob 		RTE_PTYPE_L4_UDP,
109220186d43SJerin Jacob 		RTE_PTYPE_L4_FRAG,
109320186d43SJerin Jacob 		RTE_PTYPE_UNKNOWN
109420186d43SJerin Jacob 	};
109520186d43SJerin Jacob 
109620186d43SJerin Jacob 	if (dev->rx_pkt_burst == octeontx_recv_pkts)
109720186d43SJerin Jacob 		return ptypes;
109820186d43SJerin Jacob 
109920186d43SJerin Jacob 	return NULL;
110020186d43SJerin Jacob }
110120186d43SJerin Jacob 
11025452a17dSPavan Nikhilesh static int
11035452a17dSPavan Nikhilesh octeontx_pool_ops(struct rte_eth_dev *dev, const char *pool)
11045452a17dSPavan Nikhilesh {
11055452a17dSPavan Nikhilesh 	RTE_SET_USED(dev);
11065452a17dSPavan Nikhilesh 
11075452a17dSPavan Nikhilesh 	if (!strcmp(pool, "octeontx_fpavf"))
11085452a17dSPavan Nikhilesh 		return 0;
11095452a17dSPavan Nikhilesh 
11105452a17dSPavan Nikhilesh 	return -ENOTSUP;
11115452a17dSPavan Nikhilesh }
11125452a17dSPavan Nikhilesh 
1113f18b146cSJerin Jacob /* Initialize and register driver with DPDK Application */
1114f18b146cSJerin Jacob static const struct eth_dev_ops octeontx_dev_ops = {
11157742c55aSJerin Jacob 	.dev_configure		 = octeontx_dev_configure,
11167c0347a2SJerin Jacob 	.dev_infos_get		 = octeontx_dev_info,
1117da6c6874SJerin Jacob 	.dev_close		 = octeontx_dev_close,
1118da6c6874SJerin Jacob 	.dev_start		 = octeontx_dev_start,
1119da6c6874SJerin Jacob 	.dev_stop		 = octeontx_dev_stop,
112015bce35bSJerin Jacob 	.promiscuous_enable	 = octeontx_dev_promisc_enable,
112115bce35bSJerin Jacob 	.promiscuous_disable	 = octeontx_dev_promisc_disable,
11224fac7c0aSJerin Jacob 	.link_update		 = octeontx_dev_link_update,
112355389909SJerin Jacob 	.stats_get		 = octeontx_dev_stats_get,
112455389909SJerin Jacob 	.stats_reset		 = octeontx_dev_stats_reset,
1125e4373bf1SSunil Kumar Kori 	.mac_addr_remove	 = octeontx_dev_mac_addr_del,
1126e4373bf1SSunil Kumar Kori 	.mac_addr_add		 = octeontx_dev_mac_addr_add,
1127ef7308fcSJerin Jacob 	.mac_addr_set		 = octeontx_dev_default_mac_addr_set,
11287fe7c98fSJerin Jacob 	.tx_queue_start		 = octeontx_dev_tx_queue_start,
11297fe7c98fSJerin Jacob 	.tx_queue_stop		 = octeontx_dev_tx_queue_stop,
1130150cbc84SJerin Jacob 	.tx_queue_setup		 = octeontx_dev_tx_queue_setup,
1131150cbc84SJerin Jacob 	.tx_queue_release	 = octeontx_dev_tx_queue_release,
1132197438eeSJerin Jacob 	.rx_queue_setup		 = octeontx_dev_rx_queue_setup,
1133197438eeSJerin Jacob 	.rx_queue_release	 = octeontx_dev_rx_queue_release,
113420186d43SJerin Jacob 	.dev_supported_ptypes_get = octeontx_dev_supported_ptypes_get,
11355452a17dSPavan Nikhilesh 	.pool_ops_supported      = octeontx_pool_ops,
1136f18b146cSJerin Jacob };
1137f18b146cSJerin Jacob 
1138f7be70e5SJerin Jacob /* Create Ethdev interface per BGX LMAC ports */
1139f7be70e5SJerin Jacob static int
1140f7be70e5SJerin Jacob octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
1141f7be70e5SJerin Jacob 			int socket_id)
1142f7be70e5SJerin Jacob {
1143f18b146cSJerin Jacob 	int res;
1144a6d6f0afSPavan Nikhilesh 	size_t pko_vfid;
1145f18b146cSJerin Jacob 	char octtx_name[OCTEONTX_MAX_NAME_LEN];
1146f18b146cSJerin Jacob 	struct octeontx_nic *nic = NULL;
1147f18b146cSJerin Jacob 	struct rte_eth_dev *eth_dev = NULL;
11485f19dee6SJianfeng Tan 	struct rte_eth_dev_data *data;
1149f18b146cSJerin Jacob 	const char *name = rte_vdev_device_name(dev);
1150e4373bf1SSunil Kumar Kori 	int max_entries;
1151f7be70e5SJerin Jacob 
1152f18b146cSJerin Jacob 	PMD_INIT_FUNC_TRACE();
1153f18b146cSJerin Jacob 
1154f18b146cSJerin Jacob 	sprintf(octtx_name, "%s_%d", name, port);
1155f18b146cSJerin Jacob 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1156f18b146cSJerin Jacob 		eth_dev = rte_eth_dev_attach_secondary(octtx_name);
1157f18b146cSJerin Jacob 		if (eth_dev == NULL)
1158f7be70e5SJerin Jacob 			return -ENODEV;
1159f18b146cSJerin Jacob 
1160d1c3ab22SFerruh Yigit 		eth_dev->dev_ops = &octeontx_dev_ops;
1161d1c3ab22SFerruh Yigit 		eth_dev->device = &dev->device;
1162da6c6874SJerin Jacob 		eth_dev->tx_pkt_burst = octeontx_xmit_pkts;
1163da6c6874SJerin Jacob 		eth_dev->rx_pkt_burst = octeontx_recv_pkts;
1164fbe90cddSThomas Monjalon 		rte_eth_dev_probing_finish(eth_dev);
1165f18b146cSJerin Jacob 		return 0;
1166f18b146cSJerin Jacob 	}
1167f18b146cSJerin Jacob 
1168e16adf08SThomas Monjalon 	/* Reserve an ethdev entry */
1169e16adf08SThomas Monjalon 	eth_dev = rte_eth_dev_allocate(octtx_name);
1170e16adf08SThomas Monjalon 	if (eth_dev == NULL) {
1171e16adf08SThomas Monjalon 		octeontx_log_err("failed to allocate rte_eth_dev");
1172e16adf08SThomas Monjalon 		res = -ENOMEM;
1173e16adf08SThomas Monjalon 		goto err;
1174e16adf08SThomas Monjalon 	}
1175e16adf08SThomas Monjalon 	data = eth_dev->data;
1176e16adf08SThomas Monjalon 
1177f18b146cSJerin Jacob 	nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id);
1178f18b146cSJerin Jacob 	if (nic == NULL) {
1179f18b146cSJerin Jacob 		octeontx_log_err("failed to allocate nic structure");
1180f18b146cSJerin Jacob 		res = -ENOMEM;
1181f18b146cSJerin Jacob 		goto err;
1182f18b146cSJerin Jacob 	}
1183e16adf08SThomas Monjalon 	data->dev_private = nic;
1184a6d6f0afSPavan Nikhilesh 	pko_vfid = octeontx_pko_get_vfid();
1185f18b146cSJerin Jacob 
1186a6d6f0afSPavan Nikhilesh 	if (pko_vfid == SIZE_MAX) {
1187a6d6f0afSPavan Nikhilesh 		octeontx_log_err("failed to get pko vfid");
1188a6d6f0afSPavan Nikhilesh 		res = -ENODEV;
1189a6d6f0afSPavan Nikhilesh 		goto err;
1190a6d6f0afSPavan Nikhilesh 	}
1191a6d6f0afSPavan Nikhilesh 
1192a6d6f0afSPavan Nikhilesh 	nic->pko_vfid = pko_vfid;
1193f18b146cSJerin Jacob 	nic->port_id = port;
1194f18b146cSJerin Jacob 	nic->evdev = evdev;
1195f18b146cSJerin Jacob 
1196f18b146cSJerin Jacob 	res = octeontx_port_open(nic);
1197f18b146cSJerin Jacob 	if (res < 0)
1198f18b146cSJerin Jacob 		goto err;
1199f18b146cSJerin Jacob 
1200f18b146cSJerin Jacob 	/* Rx side port configuration */
1201f18b146cSJerin Jacob 	res = octeontx_pki_port_open(port);
1202f18b146cSJerin Jacob 	if (res != 0) {
1203f18b146cSJerin Jacob 		octeontx_log_err("failed to open PKI port %d", port);
1204f18b146cSJerin Jacob 		res = -ENODEV;
1205f18b146cSJerin Jacob 		goto err;
1206f18b146cSJerin Jacob 	}
1207f18b146cSJerin Jacob 
1208f18b146cSJerin Jacob 	eth_dev->device = &dev->device;
1209f18b146cSJerin Jacob 	eth_dev->intr_handle = NULL;
1210f18b146cSJerin Jacob 	eth_dev->data->kdrv = RTE_KDRV_NONE;
1211f18b146cSJerin Jacob 	eth_dev->data->numa_node = dev->device.numa_node;
1212f18b146cSJerin Jacob 
1213f18b146cSJerin Jacob 	data->port_id = eth_dev->data->port_id;
1214f18b146cSJerin Jacob 
1215f18b146cSJerin Jacob 	nic->ev_queues = 1;
1216f18b146cSJerin Jacob 	nic->ev_ports = 1;
1217f18b146cSJerin Jacob 
1218f18b146cSJerin Jacob 	data->dev_link.link_status = ETH_LINK_DOWN;
1219f18b146cSJerin Jacob 	data->dev_started = 0;
1220f18b146cSJerin Jacob 	data->promiscuous = 0;
1221f18b146cSJerin Jacob 	data->all_multicast = 0;
1222f18b146cSJerin Jacob 	data->scattered_rx = 0;
1223f18b146cSJerin Jacob 
1224e4373bf1SSunil Kumar Kori 	/* Get maximum number of supported MAC entries */
1225e4373bf1SSunil Kumar Kori 	max_entries = octeontx_bgx_port_mac_entries_get(nic->port_id);
1226e4373bf1SSunil Kumar Kori 	if (max_entries < 0) {
1227e4373bf1SSunil Kumar Kori 		octeontx_log_err("Failed to get max entries for mac addr");
1228e4373bf1SSunil Kumar Kori 		res = -ENOTSUP;
1229e4373bf1SSunil Kumar Kori 		goto err;
1230e4373bf1SSunil Kumar Kori 	}
1231e4373bf1SSunil Kumar Kori 
1232e4373bf1SSunil Kumar Kori 	data->mac_addrs = rte_zmalloc_socket(octtx_name, max_entries *
1233e4373bf1SSunil Kumar Kori 					     RTE_ETHER_ADDR_LEN, 0,
1234f18b146cSJerin Jacob 							socket_id);
1235f18b146cSJerin Jacob 	if (data->mac_addrs == NULL) {
1236f18b146cSJerin Jacob 		octeontx_log_err("failed to allocate memory for mac_addrs");
1237f18b146cSJerin Jacob 		res = -ENOMEM;
1238f18b146cSJerin Jacob 		goto err;
1239f18b146cSJerin Jacob 	}
1240f18b146cSJerin Jacob 
1241f18b146cSJerin Jacob 	eth_dev->dev_ops = &octeontx_dev_ops;
1242f18b146cSJerin Jacob 
1243f18b146cSJerin Jacob 	/* Finally save ethdev pointer to the NIC structure */
1244f18b146cSJerin Jacob 	nic->dev = eth_dev;
1245f18b146cSJerin Jacob 
1246f18b146cSJerin Jacob 	if (nic->port_id != data->port_id) {
1247f18b146cSJerin Jacob 		octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
1248f18b146cSJerin Jacob 				data->port_id, nic->port_id);
1249f18b146cSJerin Jacob 		res = -EINVAL;
12509e399b88SSunil Kumar Kori 		goto free_mac_addrs;
1251f18b146cSJerin Jacob 	}
1252f18b146cSJerin Jacob 
1253f18b146cSJerin Jacob 	/* Update port_id mac to eth_dev */
125435b2d13fSOlivier Matz 	memcpy(data->mac_addrs, nic->mac_addr, RTE_ETHER_ADDR_LEN);
1255f18b146cSJerin Jacob 
12569614459bSSunil Kumar Kori 	/* Update same mac address to BGX CAM table at index 0 */
12579614459bSSunil Kumar Kori 	octeontx_bgx_port_mac_add(nic->port_id, nic->mac_addr, 0);
12589614459bSSunil Kumar Kori 
1259f18b146cSJerin Jacob 	PMD_INIT_LOG(DEBUG, "ethdev info: ");
1260f18b146cSJerin Jacob 	PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d",
1261f18b146cSJerin Jacob 				nic->port_id, nic->port_ena,
1262f18b146cSJerin Jacob 				nic->base_ochan, nic->num_ochans,
1263f18b146cSJerin Jacob 				nic->num_tx_queues);
1264f18b146cSJerin Jacob 	PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->mtu);
1265f18b146cSJerin Jacob 
1266989d4926SPavan Nikhilesh 	rte_octeontx_pchan_map[(nic->base_ochan >> 8) & 0x7]
1267989d4926SPavan Nikhilesh 		[(nic->base_ochan >> 4) & 0xF] = data->port_id;
1268989d4926SPavan Nikhilesh 
1269fbe90cddSThomas Monjalon 	rte_eth_dev_probing_finish(eth_dev);
1270f18b146cSJerin Jacob 	return data->port_id;
1271f18b146cSJerin Jacob 
12729e399b88SSunil Kumar Kori free_mac_addrs:
12739e399b88SSunil Kumar Kori 	rte_free(data->mac_addrs);
1274f18b146cSJerin Jacob err:
1275a98122efSSantosh Shukla 	if (nic)
1276f18b146cSJerin Jacob 		octeontx_port_close(nic);
1277f18b146cSJerin Jacob 
1278f18b146cSJerin Jacob 	rte_eth_dev_release_port(eth_dev);
1279f18b146cSJerin Jacob 
1280f18b146cSJerin Jacob 	return res;
1281f7be70e5SJerin Jacob }
1282f7be70e5SJerin Jacob 
1283f7be70e5SJerin Jacob /* Un initialize octeontx device */
1284f7be70e5SJerin Jacob static int
1285f7be70e5SJerin Jacob octeontx_remove(struct rte_vdev_device *dev)
1286f7be70e5SJerin Jacob {
1287f7be70e5SJerin Jacob 	char octtx_name[OCTEONTX_MAX_NAME_LEN];
1288f7be70e5SJerin Jacob 	struct rte_eth_dev *eth_dev = NULL;
1289f7be70e5SJerin Jacob 	struct octeontx_nic *nic = NULL;
1290f7be70e5SJerin Jacob 	int i;
1291f7be70e5SJerin Jacob 
1292f7be70e5SJerin Jacob 	if (dev == NULL)
1293f7be70e5SJerin Jacob 		return -EINVAL;
1294f7be70e5SJerin Jacob 
1295f7be70e5SJerin Jacob 	for (i = 0; i < OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT; i++) {
1296f7be70e5SJerin Jacob 		sprintf(octtx_name, "eth_octeontx_%d", i);
1297f7be70e5SJerin Jacob 
1298f7be70e5SJerin Jacob 		/* reserve an ethdev entry */
1299f7be70e5SJerin Jacob 		eth_dev = rte_eth_dev_allocated(octtx_name);
1300f7be70e5SJerin Jacob 		if (eth_dev == NULL)
1301f7be70e5SJerin Jacob 			return -ENODEV;
1302f7be70e5SJerin Jacob 
13034852aa8fSQi Zhang 		if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1304662dbc32SThomas Monjalon 			rte_eth_dev_release_port(eth_dev);
13054852aa8fSQi Zhang 			continue;
13064852aa8fSQi Zhang 		}
13074852aa8fSQi Zhang 
1308f7be70e5SJerin Jacob 		nic = octeontx_pmd_priv(eth_dev);
1309f7be70e5SJerin Jacob 		rte_event_dev_stop(nic->evdev);
1310f7be70e5SJerin Jacob 		PMD_INIT_LOG(INFO, "Closing octeontx device %s", octtx_name);
1311f7be70e5SJerin Jacob 
1312f7be70e5SJerin Jacob 		rte_eth_dev_release_port(eth_dev);
1313f7be70e5SJerin Jacob 		rte_event_dev_close(nic->evdev);
1314f7be70e5SJerin Jacob 	}
1315f7be70e5SJerin Jacob 
13164852aa8fSQi Zhang 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
13174852aa8fSQi Zhang 		return 0;
13184852aa8fSQi Zhang 
1319f7be70e5SJerin Jacob 	/* Free FC resource */
1320f7be70e5SJerin Jacob 	octeontx_pko_fc_free();
1321f7be70e5SJerin Jacob 
1322f7be70e5SJerin Jacob 	return 0;
1323f7be70e5SJerin Jacob }
1324f7be70e5SJerin Jacob 
1325f7be70e5SJerin Jacob /* Initialize octeontx device */
1326f7be70e5SJerin Jacob static int
1327f7be70e5SJerin Jacob octeontx_probe(struct rte_vdev_device *dev)
1328f7be70e5SJerin Jacob {
1329f7be70e5SJerin Jacob 	const char *dev_name;
1330f7be70e5SJerin Jacob 	static int probe_once;
1331f7be70e5SJerin Jacob 	uint8_t socket_id, qlist;
1332f7be70e5SJerin Jacob 	int tx_vfcnt, port_id, evdev, qnum, pnum, res, i;
1333f7be70e5SJerin Jacob 	struct rte_event_dev_config dev_conf;
1334f7be70e5SJerin Jacob 	const char *eventdev_name = "event_octeontx";
1335f7be70e5SJerin Jacob 	struct rte_event_dev_info info;
1336ee27edbeSJianfeng Tan 	struct rte_eth_dev *eth_dev;
1337f7be70e5SJerin Jacob 
1338f7be70e5SJerin Jacob 	struct octeontx_vdev_init_params init_params = {
1339f7be70e5SJerin Jacob 		OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT
1340f7be70e5SJerin Jacob 	};
1341f7be70e5SJerin Jacob 
1342f7be70e5SJerin Jacob 	dev_name = rte_vdev_device_name(dev);
1343ee27edbeSJianfeng Tan 
1344ee27edbeSJianfeng Tan 	if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
1345ee27edbeSJianfeng Tan 	    strlen(rte_vdev_device_args(dev)) == 0) {
1346ee27edbeSJianfeng Tan 		eth_dev = rte_eth_dev_attach_secondary(dev_name);
1347ee27edbeSJianfeng Tan 		if (!eth_dev) {
1348e6da1f00SStephen Hemminger 			PMD_INIT_LOG(ERR, "Failed to probe %s", dev_name);
1349ee27edbeSJianfeng Tan 			return -1;
1350ee27edbeSJianfeng Tan 		}
1351ee27edbeSJianfeng Tan 		/* TODO: request info from primary to set up Rx and Tx */
1352ee27edbeSJianfeng Tan 		eth_dev->dev_ops = &octeontx_dev_ops;
1353d1c3ab22SFerruh Yigit 		eth_dev->device = &dev->device;
1354fbe90cddSThomas Monjalon 		rte_eth_dev_probing_finish(eth_dev);
1355ee27edbeSJianfeng Tan 		return 0;
1356ee27edbeSJianfeng Tan 	}
1357ee27edbeSJianfeng Tan 
1358f7be70e5SJerin Jacob 	res = octeontx_parse_vdev_init_params(&init_params, dev);
1359f7be70e5SJerin Jacob 	if (res < 0)
1360f7be70e5SJerin Jacob 		return -EINVAL;
1361f7be70e5SJerin Jacob 
1362f7be70e5SJerin Jacob 	if (init_params.nr_port > OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT) {
1363f7be70e5SJerin Jacob 		octeontx_log_err("nr_port (%d) > max (%d)", init_params.nr_port,
1364f7be70e5SJerin Jacob 				OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT);
1365f7be70e5SJerin Jacob 		return -ENOTSUP;
1366f7be70e5SJerin Jacob 	}
1367f7be70e5SJerin Jacob 
1368f7be70e5SJerin Jacob 	PMD_INIT_LOG(DEBUG, "initializing %s pmd", dev_name);
1369f7be70e5SJerin Jacob 
1370f7be70e5SJerin Jacob 	socket_id = rte_socket_id();
1371f7be70e5SJerin Jacob 
1372f7be70e5SJerin Jacob 	tx_vfcnt = octeontx_pko_vf_count();
1373f7be70e5SJerin Jacob 
1374f7be70e5SJerin Jacob 	if (tx_vfcnt < init_params.nr_port) {
1375f7be70e5SJerin Jacob 		octeontx_log_err("not enough PKO (%d) for port number (%d)",
1376f7be70e5SJerin Jacob 				tx_vfcnt, init_params.nr_port);
1377f7be70e5SJerin Jacob 		return -EINVAL;
1378f7be70e5SJerin Jacob 	}
1379f7be70e5SJerin Jacob 	evdev = rte_event_dev_get_dev_id(eventdev_name);
1380f7be70e5SJerin Jacob 	if (evdev < 0) {
1381f7be70e5SJerin Jacob 		octeontx_log_err("eventdev %s not found", eventdev_name);
1382f7be70e5SJerin Jacob 		return -ENODEV;
1383f7be70e5SJerin Jacob 	}
1384f7be70e5SJerin Jacob 
1385f7be70e5SJerin Jacob 	res = rte_event_dev_info_get(evdev, &info);
1386f7be70e5SJerin Jacob 	if (res < 0) {
1387f7be70e5SJerin Jacob 		octeontx_log_err("failed to eventdev info %d", res);
1388f7be70e5SJerin Jacob 		return -EINVAL;
1389f7be70e5SJerin Jacob 	}
1390f7be70e5SJerin Jacob 
1391f7be70e5SJerin Jacob 	PMD_INIT_LOG(DEBUG, "max_queue %d max_port %d",
1392f7be70e5SJerin Jacob 			info.max_event_queues, info.max_event_ports);
1393f7be70e5SJerin Jacob 
1394f7be70e5SJerin Jacob 	if (octeontx_pko_init_fc(tx_vfcnt))
1395f7be70e5SJerin Jacob 		return -ENOMEM;
1396f7be70e5SJerin Jacob 
1397f7be70e5SJerin Jacob 	devconf_set_default_sane_values(&dev_conf, &info);
1398f7be70e5SJerin Jacob 	res = rte_event_dev_configure(evdev, &dev_conf);
1399f7be70e5SJerin Jacob 	if (res < 0)
1400f7be70e5SJerin Jacob 		goto parse_error;
1401f7be70e5SJerin Jacob 
1402f7be70e5SJerin Jacob 	rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT,
1403f7be70e5SJerin Jacob 			(uint32_t *)&pnum);
1404f7be70e5SJerin Jacob 	rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT,
1405f7be70e5SJerin Jacob 			(uint32_t *)&qnum);
1406f7be70e5SJerin Jacob 	if (pnum < qnum) {
1407f7be70e5SJerin Jacob 		octeontx_log_err("too few event ports (%d) for event_q(%d)",
1408f7be70e5SJerin Jacob 				pnum, qnum);
1409f7be70e5SJerin Jacob 		res = -EINVAL;
1410f7be70e5SJerin Jacob 		goto parse_error;
1411f7be70e5SJerin Jacob 	}
14127efd5202SAnoob Joseph 
14137efd5202SAnoob Joseph 	/* Enable all queues available */
1414f7be70e5SJerin Jacob 	for (i = 0; i < qnum; i++) {
1415f7be70e5SJerin Jacob 		res = rte_event_queue_setup(evdev, i, NULL);
1416f7be70e5SJerin Jacob 		if (res < 0) {
1417f7be70e5SJerin Jacob 			octeontx_log_err("failed to setup event_q(%d): res %d",
1418f7be70e5SJerin Jacob 					i, res);
1419f7be70e5SJerin Jacob 			goto parse_error;
1420f7be70e5SJerin Jacob 		}
1421f7be70e5SJerin Jacob 	}
1422f7be70e5SJerin Jacob 
14237efd5202SAnoob Joseph 	/* Enable all ports available */
1424f7be70e5SJerin Jacob 	for (i = 0; i < pnum; i++) {
1425f7be70e5SJerin Jacob 		res = rte_event_port_setup(evdev, i, NULL);
1426f7be70e5SJerin Jacob 		if (res < 0) {
1427f7be70e5SJerin Jacob 			res = -ENODEV;
1428f7be70e5SJerin Jacob 			octeontx_log_err("failed to setup ev port(%d) res=%d",
1429f7be70e5SJerin Jacob 						i, res);
1430f7be70e5SJerin Jacob 			goto parse_error;
1431f7be70e5SJerin Jacob 		}
14327efd5202SAnoob Joseph 	}
14337efd5202SAnoob Joseph 
14347efd5202SAnoob Joseph 	/*
14357efd5202SAnoob Joseph 	 * Do 1:1 links for ports & queues. All queues would be mapped to
14367efd5202SAnoob Joseph 	 * one port. If there are more ports than queues, then some ports
14377efd5202SAnoob Joseph 	 * won't be linked to any queue.
14387efd5202SAnoob Joseph 	 */
14397efd5202SAnoob Joseph 	for (i = 0; i < qnum; i++) {
1440f7be70e5SJerin Jacob 		/* Link one queue to one event port */
1441f7be70e5SJerin Jacob 		qlist = i;
1442f7be70e5SJerin Jacob 		res = rte_event_port_link(evdev, i, &qlist, NULL, 1);
1443f7be70e5SJerin Jacob 		if (res < 0) {
1444f7be70e5SJerin Jacob 			res = -ENODEV;
1445f7be70e5SJerin Jacob 			octeontx_log_err("failed to link port (%d): res=%d",
1446f7be70e5SJerin Jacob 					i, res);
1447f7be70e5SJerin Jacob 			goto parse_error;
1448f7be70e5SJerin Jacob 		}
1449f7be70e5SJerin Jacob 	}
1450f7be70e5SJerin Jacob 
1451f7be70e5SJerin Jacob 	/* Create ethdev interface */
1452f7be70e5SJerin Jacob 	for (i = 0; i < init_params.nr_port; i++) {
1453f7be70e5SJerin Jacob 		port_id = octeontx_create(dev, i, evdev, socket_id);
1454f7be70e5SJerin Jacob 		if (port_id < 0) {
1455f7be70e5SJerin Jacob 			octeontx_log_err("failed to create device %s",
1456f7be70e5SJerin Jacob 					dev_name);
1457f7be70e5SJerin Jacob 			res = -ENODEV;
1458f7be70e5SJerin Jacob 			goto parse_error;
1459f7be70e5SJerin Jacob 		}
1460f7be70e5SJerin Jacob 
1461f7be70e5SJerin Jacob 		PMD_INIT_LOG(INFO, "created ethdev %s for port %d", dev_name,
1462f7be70e5SJerin Jacob 					port_id);
1463f7be70e5SJerin Jacob 	}
1464f7be70e5SJerin Jacob 
1465f7be70e5SJerin Jacob 	if (probe_once) {
1466f7be70e5SJerin Jacob 		octeontx_log_err("interface %s not supported", dev_name);
1467f7be70e5SJerin Jacob 		octeontx_remove(dev);
1468f7be70e5SJerin Jacob 		res = -ENOTSUP;
1469f7be70e5SJerin Jacob 		goto parse_error;
1470f7be70e5SJerin Jacob 	}
1471dfb0c75bSPavan Nikhilesh 	rte_mbuf_set_platform_mempool_ops("octeontx_fpavf");
1472f7be70e5SJerin Jacob 	probe_once = 1;
1473f7be70e5SJerin Jacob 
1474f7be70e5SJerin Jacob 	return 0;
1475f7be70e5SJerin Jacob 
1476f7be70e5SJerin Jacob parse_error:
1477f7be70e5SJerin Jacob 	octeontx_pko_fc_free();
1478f7be70e5SJerin Jacob 	return res;
1479f7be70e5SJerin Jacob }
1480f7be70e5SJerin Jacob 
1481f7be70e5SJerin Jacob static struct rte_vdev_driver octeontx_pmd_drv = {
1482f7be70e5SJerin Jacob 	.probe = octeontx_probe,
1483f7be70e5SJerin Jacob 	.remove = octeontx_remove,
1484f7be70e5SJerin Jacob };
1485f7be70e5SJerin Jacob 
1486f7be70e5SJerin Jacob RTE_PMD_REGISTER_VDEV(OCTEONTX_PMD, octeontx_pmd_drv);
1487f7be70e5SJerin Jacob RTE_PMD_REGISTER_ALIAS(OCTEONTX_PMD, eth_octeontx);
1488f7be70e5SJerin Jacob RTE_PMD_REGISTER_PARAM_STRING(OCTEONTX_PMD, "nr_port=<int> ");
1489