4 * Copyright (C) Cavium Inc. 2017. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium networks nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <rte_alarm.h>
40 #include <rte_branch_prediction.h>
41 #include <rte_debug.h>
42 #include <rte_devargs.h>
44 #include <rte_kvargs.h>
45 #include <rte_malloc.h>
46 #include <rte_prefetch.h>
49 #include "octeontx_ethdev.h"
50 #include "octeontx_rxtx.h"
51 #include "octeontx_logs.h"
53 struct octeontx_vdev_init_params {
57 enum octeontx_link_speed {
58 OCTEONTX_LINK_SPEED_SGMII,
59 OCTEONTX_LINK_SPEED_XAUI,
60 OCTEONTX_LINK_SPEED_RXAUI,
61 OCTEONTX_LINK_SPEED_10G_R,
62 OCTEONTX_LINK_SPEED_40G_R,
63 OCTEONTX_LINK_SPEED_RESERVE1,
64 OCTEONTX_LINK_SPEED_QSGMII,
65 OCTEONTX_LINK_SPEED_RESERVE2
68 /* Parse integer from integer argument */
70 parse_integer_arg(const char *key __rte_unused,
71 const char *value, void *extra_args)
73 int *i = (int *)extra_args;
77 octeontx_log_err("argument has to be positive.");
85 octeontx_parse_vdev_init_params(struct octeontx_vdev_init_params *params,
86 struct rte_vdev_device *dev)
88 struct rte_kvargs *kvlist = NULL;
91 static const char * const octeontx_vdev_valid_params[] = {
92 OCTEONTX_VDEV_NR_PORT_ARG,
96 const char *input_args = rte_vdev_device_args(dev);
102 kvlist = rte_kvargs_parse(input_args,
103 octeontx_vdev_valid_params);
107 ret = rte_kvargs_process(kvlist,
108 OCTEONTX_VDEV_NR_PORT_ARG,
116 rte_kvargs_free(kvlist);
121 octeontx_port_open(struct octeontx_nic *nic)
123 octeontx_mbox_bgx_port_conf_t bgx_port_conf;
128 PMD_INIT_FUNC_TRACE();
130 res = octeontx_bgx_port_open(nic->port_id, &bgx_port_conf);
132 octeontx_log_err("failed to open port %d", res);
136 nic->node = bgx_port_conf.node;
137 nic->port_ena = bgx_port_conf.enable;
138 nic->base_ichan = bgx_port_conf.base_chan;
139 nic->base_ochan = bgx_port_conf.base_chan;
140 nic->num_ichans = bgx_port_conf.num_chans;
141 nic->num_ochans = bgx_port_conf.num_chans;
142 nic->mtu = bgx_port_conf.mtu;
143 nic->bpen = bgx_port_conf.bpen;
144 nic->fcs_strip = bgx_port_conf.fcs_strip;
145 nic->bcast_mode = bgx_port_conf.bcast_mode;
146 nic->mcast_mode = bgx_port_conf.mcast_mode;
147 nic->speed = bgx_port_conf.mode;
149 memcpy(&nic->mac_addr[0], &bgx_port_conf.macaddr[0], ETHER_ADDR_LEN);
151 octeontx_log_dbg("port opened %d", nic->port_id);
156 octeontx_port_close(struct octeontx_nic *nic)
158 PMD_INIT_FUNC_TRACE();
160 octeontx_bgx_port_close(nic->port_id);
161 octeontx_log_dbg("port closed %d", nic->port_id);
165 octeontx_port_stop(struct octeontx_nic *nic)
167 PMD_INIT_FUNC_TRACE();
169 return octeontx_bgx_port_stop(nic->port_id);
173 octeontx_port_promisc_set(struct octeontx_nic *nic, int en)
175 struct rte_eth_dev *dev;
179 PMD_INIT_FUNC_TRACE();
182 res = octeontx_bgx_port_promisc_set(nic->port_id, en);
184 octeontx_log_err("failed to set promiscuous mode %d",
187 /* Set proper flag for the mode */
188 dev->data->promiscuous = (en != 0) ? 1 : 0;
190 octeontx_log_dbg("port %d : promiscuous mode %s",
191 nic->port_id, en ? "set" : "unset");
195 octeontx_port_stats(struct octeontx_nic *nic, struct rte_eth_stats *stats)
197 octeontx_mbox_bgx_port_stats_t bgx_stats;
200 PMD_INIT_FUNC_TRACE();
202 res = octeontx_bgx_port_stats(nic->port_id, &bgx_stats);
204 octeontx_log_err("failed to get port stats %d", nic->port_id);
206 stats->ipackets = bgx_stats.rx_packets;
207 stats->ibytes = bgx_stats.rx_bytes;
208 stats->imissed = bgx_stats.rx_dropped;
209 stats->ierrors = bgx_stats.rx_errors;
210 stats->opackets = bgx_stats.tx_packets;
211 stats->obytes = bgx_stats.tx_bytes;
212 stats->oerrors = bgx_stats.tx_errors;
214 octeontx_log_dbg("port%d stats inpkts=%" PRIx64 " outpkts=%" PRIx64 "",
215 nic->port_id, stats->ipackets, stats->opackets);
219 octeontx_port_stats_clr(struct octeontx_nic *nic)
221 PMD_INIT_FUNC_TRACE();
223 octeontx_bgx_port_stats_clr(nic->port_id);
227 devconf_set_default_sane_values(struct rte_event_dev_config *dev_conf,
228 struct rte_event_dev_info *info)
230 memset(dev_conf, 0, sizeof(struct rte_event_dev_config));
231 dev_conf->dequeue_timeout_ns = info->min_dequeue_timeout_ns;
233 dev_conf->nb_event_ports = info->max_event_ports;
234 dev_conf->nb_event_queues = info->max_event_queues;
236 dev_conf->nb_event_queue_flows = info->max_event_queue_flows;
237 dev_conf->nb_event_port_dequeue_depth =
238 info->max_event_port_dequeue_depth;
239 dev_conf->nb_event_port_enqueue_depth =
240 info->max_event_port_enqueue_depth;
241 dev_conf->nb_event_port_enqueue_depth =
242 info->max_event_port_enqueue_depth;
243 dev_conf->nb_events_limit =
244 info->max_num_events;
248 octeontx_dev_configure(struct rte_eth_dev *dev)
250 struct rte_eth_dev_data *data = dev->data;
251 struct rte_eth_conf *conf = &data->dev_conf;
252 struct rte_eth_rxmode *rxmode = &conf->rxmode;
253 struct rte_eth_txmode *txmode = &conf->txmode;
254 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
257 PMD_INIT_FUNC_TRACE();
260 if (!rte_eal_has_hugepages()) {
261 octeontx_log_err("huge page is not configured");
265 if (txmode->mq_mode) {
266 octeontx_log_err("tx mq_mode DCB or VMDq not supported");
270 if (rxmode->mq_mode != ETH_MQ_RX_NONE &&
271 rxmode->mq_mode != ETH_MQ_RX_RSS) {
272 octeontx_log_err("unsupported rx qmode %d", rxmode->mq_mode);
276 if (!rxmode->hw_strip_crc) {
277 PMD_INIT_LOG(NOTICE, "can't disable hw crc strip");
278 rxmode->hw_strip_crc = 1;
281 if (rxmode->hw_ip_checksum) {
282 PMD_INIT_LOG(NOTICE, "rxcksum not supported");
283 rxmode->hw_ip_checksum = 0;
286 if (rxmode->split_hdr_size) {
287 octeontx_log_err("rxmode does not support split header");
291 if (rxmode->hw_vlan_filter) {
292 octeontx_log_err("VLAN filter not supported");
296 if (rxmode->hw_vlan_extend) {
297 octeontx_log_err("VLAN extended not supported");
301 if (rxmode->enable_lro) {
302 octeontx_log_err("LRO not supported");
306 if (conf->link_speeds & ETH_LINK_SPEED_FIXED) {
307 octeontx_log_err("setting link speed/duplex not supported");
311 if (conf->dcb_capability_en) {
312 octeontx_log_err("DCB enable not supported");
316 if (conf->fdir_conf.mode != RTE_FDIR_MODE_NONE) {
317 octeontx_log_err("flow director not supported");
321 nic->num_tx_queues = dev->data->nb_tx_queues;
323 ret = octeontx_pko_channel_open(nic->port_id * PKO_VF_NUM_DQ,
327 octeontx_log_err("failed to open channel %d no-of-txq %d",
328 nic->base_ochan, nic->num_tx_queues);
332 nic->pki.classifier_enable = false;
333 nic->pki.hash_enable = true;
334 nic->pki.initialized = false;
340 octeontx_dev_promisc_enable(struct rte_eth_dev *dev)
342 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
344 PMD_INIT_FUNC_TRACE();
345 octeontx_port_promisc_set(nic, 1);
349 octeontx_dev_promisc_disable(struct rte_eth_dev *dev)
351 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
353 PMD_INIT_FUNC_TRACE();
354 octeontx_port_promisc_set(nic, 0);
358 octeontx_atomic_write_link_status(struct rte_eth_dev *dev,
359 struct rte_eth_link *link)
361 struct rte_eth_link *dst = &dev->data->dev_link;
362 struct rte_eth_link *src = link;
364 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
365 *(uint64_t *)src) == 0)
372 octeontx_port_link_status(struct octeontx_nic *nic)
376 PMD_INIT_FUNC_TRACE();
377 res = octeontx_bgx_port_link_status(nic->port_id);
379 octeontx_log_err("failed to get port %d link status",
384 nic->link_up = (uint8_t)res;
385 octeontx_log_dbg("port %d link status %d", nic->port_id, nic->link_up);
391 * Return 0 means link status changed, -1 means not changed
394 octeontx_dev_link_update(struct rte_eth_dev *dev,
395 int wait_to_complete __rte_unused)
397 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
398 struct rte_eth_link link;
402 PMD_INIT_FUNC_TRACE();
404 res = octeontx_port_link_status(nic);
406 octeontx_log_err("failed to request link status %d", res);
410 link.link_status = nic->link_up;
412 switch (nic->speed) {
413 case OCTEONTX_LINK_SPEED_SGMII:
414 link.link_speed = ETH_SPEED_NUM_1G;
417 case OCTEONTX_LINK_SPEED_XAUI:
418 link.link_speed = ETH_SPEED_NUM_10G;
421 case OCTEONTX_LINK_SPEED_RXAUI:
422 case OCTEONTX_LINK_SPEED_10G_R:
423 link.link_speed = ETH_SPEED_NUM_10G;
425 case OCTEONTX_LINK_SPEED_QSGMII:
426 link.link_speed = ETH_SPEED_NUM_5G;
428 case OCTEONTX_LINK_SPEED_40G_R:
429 link.link_speed = ETH_SPEED_NUM_40G;
432 case OCTEONTX_LINK_SPEED_RESERVE1:
433 case OCTEONTX_LINK_SPEED_RESERVE2:
435 octeontx_log_err("incorrect link speed %d", nic->speed);
439 link.link_duplex = ETH_LINK_AUTONEG;
440 link.link_autoneg = ETH_LINK_SPEED_AUTONEG;
442 return octeontx_atomic_write_link_status(dev, &link);
446 octeontx_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
448 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
450 PMD_INIT_FUNC_TRACE();
451 octeontx_port_stats(nic, stats);
455 octeontx_dev_stats_reset(struct rte_eth_dev *dev)
457 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
459 PMD_INIT_FUNC_TRACE();
460 octeontx_port_stats_clr(nic);
464 octeontx_dev_default_mac_addr_set(struct rte_eth_dev *dev,
465 struct ether_addr *addr)
467 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
470 ret = octeontx_bgx_port_mac_set(nic->port_id, addr->addr_bytes);
472 octeontx_log_err("failed to set MAC address on port %d",
477 octeontx_dev_info(struct rte_eth_dev *dev,
478 struct rte_eth_dev_info *dev_info)
482 /* Autonegotiation may be disabled */
483 dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
484 dev_info->speed_capa |= ETH_LINK_SPEED_10M | ETH_LINK_SPEED_100M |
485 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
488 dev_info->driver_name = RTE_STR(rte_octeontx_pmd);
489 dev_info->max_mac_addrs = 1;
490 dev_info->max_rx_pktlen = PKI_MAX_PKTLEN;
491 dev_info->max_rx_queues = 1;
492 dev_info->max_tx_queues = PKO_MAX_NUM_DQ;
493 dev_info->min_rx_bufsize = 0;
494 dev_info->pci_dev = NULL;
496 dev_info->default_rxconf = (struct rte_eth_rxconf) {
501 dev_info->default_txconf = (struct rte_eth_txconf) {
504 ETH_TXQ_FLAGS_NOMULTSEGS |
505 ETH_TXQ_FLAGS_NOOFFLOADS |
506 ETH_TXQ_FLAGS_NOXSUMS,
509 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MT_LOCKFREE;
513 octeontx_dq_info_getter(octeontx_dq_t *dq, void *out)
515 ((octeontx_dq_t *)out)->lmtline_va = dq->lmtline_va;
516 ((octeontx_dq_t *)out)->ioreg_va = dq->ioreg_va;
517 ((octeontx_dq_t *)out)->fc_status_va = dq->fc_status_va;
521 octeontx_vf_start_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
524 struct octeontx_txq *txq;
527 PMD_INIT_FUNC_TRACE();
529 if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STARTED)
532 txq = dev->data->tx_queues[qidx];
534 res = octeontx_pko_channel_query_dqs(nic->base_ochan,
536 sizeof(octeontx_dq_t),
538 octeontx_dq_info_getter);
544 dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STARTED;
548 (void)octeontx_port_stop(nic);
549 octeontx_pko_channel_stop(nic->base_ochan);
550 octeontx_pko_channel_close(nic->base_ochan);
551 dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
556 octeontx_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t qidx)
558 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
560 PMD_INIT_FUNC_TRACE();
561 qidx = qidx % PKO_VF_NUM_DQ;
562 return octeontx_vf_start_tx_queue(dev, nic, qidx);
566 octeontx_vf_stop_tx_queue(struct rte_eth_dev *dev, struct octeontx_nic *nic,
572 PMD_INIT_FUNC_TRACE();
574 if (dev->data->tx_queue_state[qidx] == RTE_ETH_QUEUE_STATE_STOPPED)
577 dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
582 octeontx_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t qidx)
584 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
586 PMD_INIT_FUNC_TRACE();
587 qidx = qidx % PKO_VF_NUM_DQ;
589 return octeontx_vf_stop_tx_queue(dev, nic, qidx);
593 octeontx_dev_tx_queue_release(void *tx_queue)
595 struct octeontx_txq *txq = tx_queue;
598 PMD_INIT_FUNC_TRACE();
601 res = octeontx_dev_tx_queue_stop(txq->eth_dev, txq->queue_id);
603 octeontx_log_err("failed stop tx_queue(%d)\n",
611 octeontx_dev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
612 uint16_t nb_desc, unsigned int socket_id,
613 const struct rte_eth_txconf *tx_conf)
615 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
616 struct octeontx_txq *txq = NULL;
620 RTE_SET_USED(nb_desc);
621 RTE_SET_USED(socket_id);
622 RTE_SET_USED(tx_conf);
624 dq_num = (nic->port_id * PKO_VF_NUM_DQ) + qidx;
626 /* Socket id check */
627 if (socket_id != (unsigned int)SOCKET_ID_ANY &&
628 socket_id != (unsigned int)nic->node)
629 PMD_TX_LOG(INFO, "socket_id expected %d, configured %d",
630 socket_id, nic->node);
632 /* Free memory prior to re-allocation if needed. */
633 if (dev->data->tx_queues[qidx] != NULL) {
634 PMD_TX_LOG(DEBUG, "freeing memory prior to re-allocation %d",
636 octeontx_dev_tx_queue_release(dev->data->tx_queues[qidx]);
637 dev->data->tx_queues[qidx] = NULL;
640 /* Allocating tx queue data structure */
641 txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct octeontx_txq),
642 RTE_CACHE_LINE_SIZE, nic->node);
644 octeontx_log_err("failed to allocate txq=%d", qidx);
650 txq->queue_id = dq_num;
651 dev->data->tx_queues[qidx] = txq;
652 dev->data->tx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
654 res = octeontx_pko_channel_query_dqs(nic->base_ochan,
656 sizeof(octeontx_dq_t),
658 octeontx_dq_info_getter);
664 PMD_TX_LOG(DEBUG, "[%d]:[%d] txq=%p nb_desc=%d lmtline=%p ioreg_va=%p fc_status_va=%p",
665 qidx, txq->queue_id, txq, nb_desc, txq->dq.lmtline_va,
667 txq->dq.fc_status_va);
679 octeontx_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qidx,
680 uint16_t nb_desc, unsigned int socket_id,
681 const struct rte_eth_rxconf *rx_conf,
682 struct rte_mempool *mb_pool)
684 struct octeontx_nic *nic = octeontx_pmd_priv(dev);
685 struct rte_mempool_ops *mp_ops = NULL;
686 struct octeontx_rxq *rxq = NULL;
687 pki_pktbuf_cfg_t pktbuf_conf;
688 pki_hash_cfg_t pki_hash;
689 pki_qos_cfg_t pki_qos;
693 unsigned int ev_queues = (nic->ev_queues * nic->port_id) + qidx;
694 unsigned int ev_ports = (nic->ev_ports * nic->port_id) + qidx;
696 RTE_SET_USED(nb_desc);
698 memset(&pktbuf_conf, 0, sizeof(pktbuf_conf));
699 memset(&pki_hash, 0, sizeof(pki_hash));
700 memset(&pki_qos, 0, sizeof(pki_qos));
702 mp_ops = rte_mempool_get_ops(mb_pool->ops_index);
703 if (strcmp(mp_ops->name, "octeontx_fpavf")) {
704 octeontx_log_err("failed to find octeontx_fpavf mempool");
708 /* Handle forbidden configurations */
709 if (nic->pki.classifier_enable) {
710 octeontx_log_err("cannot setup queue %d. "
711 "Classifier option unsupported", qidx);
717 /* Rx deferred start is not supported */
718 if (rx_conf->rx_deferred_start) {
719 octeontx_log_err("rx deferred start not supported");
723 /* Verify queue index */
724 if (qidx >= dev->data->nb_rx_queues) {
725 octeontx_log_err("QID %d not supporteded (0 - %d available)\n",
726 qidx, (dev->data->nb_rx_queues - 1));
730 /* Socket id check */
731 if (socket_id != (unsigned int)SOCKET_ID_ANY &&
732 socket_id != (unsigned int)nic->node)
733 PMD_RX_LOG(INFO, "socket_id expected %d, configured %d",
734 socket_id, nic->node);
736 /* Allocating rx queue data structure */
737 rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct octeontx_rxq),
738 RTE_CACHE_LINE_SIZE, nic->node);
740 octeontx_log_err("failed to allocate rxq=%d", qidx);
744 if (!nic->pki.initialized) {
745 pktbuf_conf.port_type = 0;
746 pki_hash.port_type = 0;
747 pki_qos.port_type = 0;
749 pktbuf_conf.mmask.f_wqe_skip = 1;
750 pktbuf_conf.mmask.f_first_skip = 1;
751 pktbuf_conf.mmask.f_later_skip = 1;
752 pktbuf_conf.mmask.f_mbuff_size = 1;
753 pktbuf_conf.mmask.f_cache_mode = 1;
755 pktbuf_conf.wqe_skip = OCTTX_PACKET_WQE_SKIP;
756 pktbuf_conf.first_skip = OCTTX_PACKET_FIRST_SKIP;
757 pktbuf_conf.later_skip = OCTTX_PACKET_LATER_SKIP;
758 pktbuf_conf.mbuff_size = (mb_pool->elt_size -
759 RTE_PKTMBUF_HEADROOM -
760 sizeof(struct rte_mbuf));
762 pktbuf_conf.cache_mode = PKI_OPC_MODE_STF2_STT;
764 ret = octeontx_pki_port_pktbuf_config(port, &pktbuf_conf);
766 octeontx_log_err("fail to configure pktbuf for port %d",
771 PMD_RX_LOG(DEBUG, "Port %d Rx pktbuf configured:\n"
772 "\tmbuf_size:\t0x%0x\n"
773 "\twqe_skip:\t0x%0x\n"
774 "\tfirst_skip:\t0x%0x\n"
775 "\tlater_skip:\t0x%0x\n"
776 "\tcache_mode:\t%s\n",
778 pktbuf_conf.mbuff_size,
779 pktbuf_conf.wqe_skip,
780 pktbuf_conf.first_skip,
781 pktbuf_conf.later_skip,
782 (pktbuf_conf.cache_mode ==
785 (pktbuf_conf.cache_mode ==
788 (pktbuf_conf.cache_mode ==
789 PKI_OPC_MODE_STF1_STT) ?
790 "STF1_STT" : "STF2_STT");
792 if (nic->pki.hash_enable) {
793 pki_hash.tag_dlc = 1;
794 pki_hash.tag_slc = 1;
795 pki_hash.tag_dlf = 1;
796 pki_hash.tag_slf = 1;
797 octeontx_pki_port_hash_config(port, &pki_hash);
800 pool = (uintptr_t)mb_pool->pool_id;
802 /* Get the gpool Id */
803 gaura = octeontx_fpa_bufpool_gpool(pool);
805 pki_qos.qpg_qos = PKI_QPG_QOS_NONE;
806 pki_qos.num_entry = 1;
807 pki_qos.drop_policy = 0;
808 pki_qos.tag_type = 2L;
809 pki_qos.qos_entry[0].port_add = 0;
810 pki_qos.qos_entry[0].gaura = gaura;
811 pki_qos.qos_entry[0].ggrp_ok = ev_queues;
812 pki_qos.qos_entry[0].ggrp_bad = ev_queues;
813 pki_qos.qos_entry[0].grptag_bad = 0;
814 pki_qos.qos_entry[0].grptag_ok = 0;
816 ret = octeontx_pki_port_create_qos(port, &pki_qos);
818 octeontx_log_err("failed to create QOS port=%d, q=%d",
823 nic->pki.initialized = true;
826 rxq->port_id = nic->port_id;
828 rxq->queue_id = qidx;
829 rxq->evdev = nic->evdev;
830 rxq->ev_queues = ev_queues;
831 rxq->ev_ports = ev_ports;
833 dev->data->rx_queues[qidx] = rxq;
834 dev->data->rx_queue_state[qidx] = RTE_ETH_QUEUE_STATE_STOPPED;
839 octeontx_dev_rx_queue_release(void *rxq)
844 static const uint32_t *
845 octeontx_dev_supported_ptypes_get(struct rte_eth_dev *dev)
847 static const uint32_t ptypes[] = {
849 RTE_PTYPE_L3_IPV4_EXT,
851 RTE_PTYPE_L3_IPV6_EXT,
858 if (dev->rx_pkt_burst == octeontx_recv_pkts)
864 /* Initialize and register driver with DPDK Application */
865 static const struct eth_dev_ops octeontx_dev_ops = {
866 .dev_configure = octeontx_dev_configure,
867 .dev_infos_get = octeontx_dev_info,
868 .promiscuous_enable = octeontx_dev_promisc_enable,
869 .promiscuous_disable = octeontx_dev_promisc_disable,
870 .link_update = octeontx_dev_link_update,
871 .stats_get = octeontx_dev_stats_get,
872 .stats_reset = octeontx_dev_stats_reset,
873 .mac_addr_set = octeontx_dev_default_mac_addr_set,
874 .tx_queue_start = octeontx_dev_tx_queue_start,
875 .tx_queue_stop = octeontx_dev_tx_queue_stop,
876 .tx_queue_setup = octeontx_dev_tx_queue_setup,
877 .tx_queue_release = octeontx_dev_tx_queue_release,
878 .rx_queue_setup = octeontx_dev_rx_queue_setup,
879 .rx_queue_release = octeontx_dev_rx_queue_release,
880 .dev_supported_ptypes_get = octeontx_dev_supported_ptypes_get,
883 /* Create Ethdev interface per BGX LMAC ports */
885 octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
889 char octtx_name[OCTEONTX_MAX_NAME_LEN];
890 struct octeontx_nic *nic = NULL;
891 struct rte_eth_dev *eth_dev = NULL;
892 struct rte_eth_dev_data *data = NULL;
893 const char *name = rte_vdev_device_name(dev);
895 PMD_INIT_FUNC_TRACE();
897 sprintf(octtx_name, "%s_%d", name, port);
898 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
899 eth_dev = rte_eth_dev_attach_secondary(octtx_name);
906 data = rte_zmalloc_socket(octtx_name, sizeof(*data), 0, socket_id);
908 octeontx_log_err("failed to allocate devdata");
913 nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id);
915 octeontx_log_err("failed to allocate nic structure");
923 res = octeontx_port_open(nic);
927 /* Rx side port configuration */
928 res = octeontx_pki_port_open(port);
930 octeontx_log_err("failed to open PKI port %d", port);
935 /* Reserve an ethdev entry */
936 eth_dev = rte_eth_dev_allocate(octtx_name);
937 if (eth_dev == NULL) {
938 octeontx_log_err("failed to allocate rte_eth_dev");
943 eth_dev->device = &dev->device;
944 eth_dev->intr_handle = NULL;
945 eth_dev->data->kdrv = RTE_KDRV_NONE;
946 eth_dev->data->numa_node = dev->device.numa_node;
948 rte_memcpy(data, (eth_dev)->data, sizeof(*data));
949 data->dev_private = nic;
951 data->port_id = eth_dev->data->port_id;
952 snprintf(data->name, sizeof(data->name), "%s", eth_dev->data->name);
957 data->dev_link.link_status = ETH_LINK_DOWN;
958 data->dev_started = 0;
959 data->promiscuous = 0;
960 data->all_multicast = 0;
961 data->scattered_rx = 0;
963 data->mac_addrs = rte_zmalloc_socket(octtx_name, ETHER_ADDR_LEN, 0,
965 if (data->mac_addrs == NULL) {
966 octeontx_log_err("failed to allocate memory for mac_addrs");
971 eth_dev->data = data;
972 eth_dev->dev_ops = &octeontx_dev_ops;
974 /* Finally save ethdev pointer to the NIC structure */
977 if (nic->port_id != data->port_id) {
978 octeontx_log_err("eth_dev->port_id (%d) is diff to orig (%d)",
979 data->port_id, nic->port_id);
984 /* Update port_id mac to eth_dev */
985 memcpy(data->mac_addrs, nic->mac_addr, ETHER_ADDR_LEN);
987 PMD_INIT_LOG(DEBUG, "ethdev info: ");
988 PMD_INIT_LOG(DEBUG, "port %d, port_ena %d ochan %d num_ochan %d tx_q %d",
989 nic->port_id, nic->port_ena,
990 nic->base_ochan, nic->num_ochans,
992 PMD_INIT_LOG(DEBUG, "speed %d mtu %d", nic->speed, nic->mtu);
994 return data->port_id;
998 octeontx_port_close(nic);
1000 if (eth_dev != NULL) {
1001 rte_free(eth_dev->data->mac_addrs);
1004 rte_eth_dev_release_port(eth_dev);
1010 /* Un initialize octeontx device */
1012 octeontx_remove(struct rte_vdev_device *dev)
1014 char octtx_name[OCTEONTX_MAX_NAME_LEN];
1015 struct rte_eth_dev *eth_dev = NULL;
1016 struct octeontx_nic *nic = NULL;
1022 for (i = 0; i < OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT; i++) {
1023 sprintf(octtx_name, "eth_octeontx_%d", i);
1025 /* reserve an ethdev entry */
1026 eth_dev = rte_eth_dev_allocated(octtx_name);
1027 if (eth_dev == NULL)
1030 nic = octeontx_pmd_priv(eth_dev);
1031 rte_event_dev_stop(nic->evdev);
1032 PMD_INIT_LOG(INFO, "Closing octeontx device %s", octtx_name);
1034 rte_free(eth_dev->data->mac_addrs);
1035 rte_free(eth_dev->data->dev_private);
1036 rte_free(eth_dev->data);
1037 rte_eth_dev_release_port(eth_dev);
1038 rte_event_dev_close(nic->evdev);
1041 /* Free FC resource */
1042 octeontx_pko_fc_free();
1047 /* Initialize octeontx device */
1049 octeontx_probe(struct rte_vdev_device *dev)
1051 const char *dev_name;
1052 static int probe_once;
1053 uint8_t socket_id, qlist;
1054 int tx_vfcnt, port_id, evdev, qnum, pnum, res, i;
1055 struct rte_event_dev_config dev_conf;
1056 const char *eventdev_name = "event_octeontx";
1057 struct rte_event_dev_info info;
1059 struct octeontx_vdev_init_params init_params = {
1060 OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT
1063 dev_name = rte_vdev_device_name(dev);
1064 res = octeontx_parse_vdev_init_params(&init_params, dev);
1068 if (init_params.nr_port > OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT) {
1069 octeontx_log_err("nr_port (%d) > max (%d)", init_params.nr_port,
1070 OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT);
1074 PMD_INIT_LOG(DEBUG, "initializing %s pmd", dev_name);
1076 socket_id = rte_socket_id();
1078 tx_vfcnt = octeontx_pko_vf_count();
1080 if (tx_vfcnt < init_params.nr_port) {
1081 octeontx_log_err("not enough PKO (%d) for port number (%d)",
1082 tx_vfcnt, init_params.nr_port);
1085 evdev = rte_event_dev_get_dev_id(eventdev_name);
1087 octeontx_log_err("eventdev %s not found", eventdev_name);
1091 res = rte_event_dev_info_get(evdev, &info);
1093 octeontx_log_err("failed to eventdev info %d", res);
1097 PMD_INIT_LOG(DEBUG, "max_queue %d max_port %d",
1098 info.max_event_queues, info.max_event_ports);
1100 if (octeontx_pko_init_fc(tx_vfcnt))
1103 devconf_set_default_sane_values(&dev_conf, &info);
1104 res = rte_event_dev_configure(evdev, &dev_conf);
1108 rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_PORT_COUNT,
1110 rte_event_dev_attr_get(evdev, RTE_EVENT_DEV_ATTR_QUEUE_COUNT,
1113 octeontx_log_err("too few event ports (%d) for event_q(%d)",
1120 * We don't poll on event ports
1121 * that do not have any queues assigned.
1125 "reducing number of active event ports to %d", pnum);
1127 for (i = 0; i < qnum; i++) {
1128 res = rte_event_queue_setup(evdev, i, NULL);
1130 octeontx_log_err("failed to setup event_q(%d): res %d",
1136 for (i = 0; i < pnum; i++) {
1137 res = rte_event_port_setup(evdev, i, NULL);
1140 octeontx_log_err("failed to setup ev port(%d) res=%d",
1144 /* Link one queue to one event port */
1146 res = rte_event_port_link(evdev, i, &qlist, NULL, 1);
1149 octeontx_log_err("failed to link port (%d): res=%d",
1155 /* Create ethdev interface */
1156 for (i = 0; i < init_params.nr_port; i++) {
1157 port_id = octeontx_create(dev, i, evdev, socket_id);
1159 octeontx_log_err("failed to create device %s",
1165 PMD_INIT_LOG(INFO, "created ethdev %s for port %d", dev_name,
1170 octeontx_log_err("interface %s not supported", dev_name);
1171 octeontx_remove(dev);
1180 octeontx_pko_fc_free();
1184 static struct rte_vdev_driver octeontx_pmd_drv = {
1185 .probe = octeontx_probe,
1186 .remove = octeontx_remove,
1189 RTE_PMD_REGISTER_VDEV(OCTEONTX_PMD, octeontx_pmd_drv);
1190 RTE_PMD_REGISTER_ALIAS(OCTEONTX_PMD, eth_octeontx);
1191 RTE_PMD_REGISTER_PARAM_STRING(OCTEONTX_PMD, "nr_port=<int> ");