1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
4 #include "cn9k_ethdev.h"
9 cn9k_nix_ptypes_set(struct rte_eth_dev *eth_dev, uint32_t ptype_mask)
11 struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
14 dev->rx_offload_flags |= NIX_RX_OFFLOAD_PTYPE_F;
15 dev->ptype_disable = 0;
17 dev->rx_offload_flags &= ~NIX_RX_OFFLOAD_PTYPE_F;
18 dev->ptype_disable = 1;
25 nix_form_default_desc(struct cnxk_eth_dev *dev, struct cn9k_eth_txq *txq,
28 struct nix_send_ext_s *send_hdr_ext;
29 struct nix_send_hdr_s *send_hdr;
30 union nix_send_sg_s *sg;
34 /* Initialize the fields based on basic single segment packet */
35 memset(&txq->cmd, 0, sizeof(txq->cmd));
37 if (dev->tx_offload_flags & NIX_TX_NEED_EXT_HDR) {
38 send_hdr = (struct nix_send_hdr_s *)&txq->cmd[0];
39 /* 2(HDR) + 2(EXT_HDR) + 1(SG) + 1(IOVA) = 6/2 - 1 = 2 */
40 send_hdr->w0.sizem1 = 2;
42 send_hdr_ext = (struct nix_send_ext_s *)&txq->cmd[2];
43 send_hdr_ext->w0.subdc = NIX_SUBDC_EXT;
44 sg = (union nix_send_sg_s *)&txq->cmd[4];
46 send_hdr = (struct nix_send_hdr_s *)&txq->cmd[0];
47 /* 2(HDR) + 1(SG) + 1(IOVA) = 4/2 - 1 = 1 */
48 send_hdr->w0.sizem1 = 1;
49 sg = (union nix_send_sg_s *)&txq->cmd[2];
52 send_hdr->w0.sq = qid;
53 sg->subdc = NIX_SUBDC_SG;
55 sg->ld_type = NIX_SENDLDTYPE_LDD;
61 cn9k_nix_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t qid,
62 uint16_t nb_desc, unsigned int socket,
63 const struct rte_eth_txconf *tx_conf)
65 struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
66 struct cn9k_eth_txq *txq;
67 struct roc_nix_sq *sq;
72 /* Common Tx queue setup */
73 rc = cnxk_nix_tx_queue_setup(eth_dev, qid, nb_desc,
74 sizeof(struct cn9k_eth_txq), tx_conf);
79 /* Update fast path queue */
80 txq = eth_dev->data->tx_queues[qid];
82 txq->lmt_addr = sq->lmt_addr;
83 txq->io_addr = sq->io_addr;
84 txq->nb_sqb_bufs_adj = sq->nb_sqb_bufs_adj;
85 txq->sqes_per_sqb_log2 = sq->sqes_per_sqb_log2;
87 nix_form_default_desc(dev, txq, qid);
88 txq->lso_tun_fmt = dev->lso_tun_fmt;
93 cn9k_nix_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t qid,
94 uint16_t nb_desc, unsigned int socket,
95 const struct rte_eth_rxconf *rx_conf,
96 struct rte_mempool *mp)
98 struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
99 struct cn9k_eth_rxq *rxq;
100 struct roc_nix_rq *rq;
101 struct roc_nix_cq *cq;
104 RTE_SET_USED(socket);
106 /* CQ Errata needs min 4K ring */
107 if (dev->cq_min_4k && nb_desc < 4096)
110 /* Common Rx queue setup */
111 rc = cnxk_nix_rx_queue_setup(eth_dev, qid, nb_desc,
112 sizeof(struct cn9k_eth_rxq), rx_conf, mp);
119 /* Update fast path queue */
120 rxq = eth_dev->data->rx_queues[qid];
122 rxq->desc = (uintptr_t)cq->desc_base;
123 rxq->cq_door = cq->door;
124 rxq->cq_status = cq->status;
125 rxq->wdata = cq->wdata;
126 rxq->head = cq->head;
127 rxq->qmask = cq->qmask;
129 /* Data offset from data to start of mbuf is first_skip */
130 rxq->data_off = rq->first_skip;
131 rxq->mbuf_initializer = cnxk_nix_rxq_mbuf_setup(dev);
134 rxq->lookup_mem = cnxk_nix_fastpath_lookup_mem_get();
139 cn9k_nix_configure(struct rte_eth_dev *eth_dev)
141 struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
142 struct rte_eth_conf *conf = ð_dev->data->dev_conf;
143 struct rte_eth_txmode *txmode = &conf->txmode;
146 /* Platform specific checks */
147 if ((roc_model_is_cn96_a0() || roc_model_is_cn95_a0()) &&
148 (txmode->offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
149 ((txmode->offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ||
150 (txmode->offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM))) {
151 plt_err("Outer IP and SCTP checksum unsupported");
155 /* Common nix configure */
156 rc = cnxk_nix_configure(eth_dev);
160 plt_nix_dbg("Configured port%d platform specific rx_offload_flags=%x"
161 " tx_offload_flags=0x%x",
162 eth_dev->data->port_id, dev->rx_offload_flags,
163 dev->tx_offload_flags);
167 /* Update platform specific eth dev ops */
169 nix_eth_dev_ops_override(void)
171 static int init_once;
177 /* Update platform specific ops */
178 cnxk_eth_dev_ops.dev_configure = cn9k_nix_configure;
179 cnxk_eth_dev_ops.tx_queue_setup = cn9k_nix_tx_queue_setup;
180 cnxk_eth_dev_ops.rx_queue_setup = cn9k_nix_rx_queue_setup;
181 cnxk_eth_dev_ops.dev_ptypes_set = cn9k_nix_ptypes_set;
185 cn9k_nix_remove(struct rte_pci_device *pci_dev)
187 return cnxk_nix_remove(pci_dev);
191 cn9k_nix_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
193 struct rte_eth_dev *eth_dev;
194 struct cnxk_eth_dev *dev;
197 if (RTE_CACHE_LINE_SIZE != 128) {
198 plt_err("Driver not compiled for CN9K");
204 plt_err("Failed to initialize platform model, rc=%d", rc);
208 nix_eth_dev_ops_override();
211 rc = cnxk_nix_probe(pci_drv, pci_dev);
215 /* Find eth dev allocated */
216 eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
220 dev = cnxk_eth_pmd_priv(eth_dev);
221 /* Update capabilities already set for TSO.
222 * TSO not supported for earlier chip revisions
224 if (roc_model_is_cn96_a0() || roc_model_is_cn95_a0())
225 dev->tx_offload_capa &= ~(DEV_TX_OFFLOAD_TCP_TSO |
226 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
227 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
228 DEV_TX_OFFLOAD_GRE_TNL_TSO);
230 /* 50G and 100G to be supported for board version C0
233 if (roc_model_is_cn96_a0() || roc_model_is_cn95_a0()) {
234 dev->speed_capa &= ~(uint64_t)ETH_LINK_SPEED_50G;
235 dev->speed_capa &= ~(uint64_t)ETH_LINK_SPEED_100G;
240 /* Update HW erratas */
241 if (roc_model_is_cn96_a0() || roc_model_is_cn95_a0())
246 static const struct rte_pci_id cn9k_pci_nix_map[] = {
252 static struct rte_pci_driver cn9k_pci_nix = {
253 .id_table = cn9k_pci_nix_map,
254 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA |
255 RTE_PCI_DRV_INTR_LSC,
256 .probe = cn9k_nix_probe,
257 .remove = cn9k_nix_remove,
260 RTE_PMD_REGISTER_PCI(net_cn9k, cn9k_pci_nix);
261 RTE_PMD_REGISTER_PCI_TABLE(net_cn9k, cn9k_pci_nix_map);
262 RTE_PMD_REGISTER_KMOD_DEP(net_cn9k, "vfio-pci");