net/cnxk: optimize Rx packet size extraction
[dpdk.git] / drivers / net / cnxk / cn9k_ethdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4 #include "cn9k_ethdev.h"
5 #include "cn9k_flow.h"
6 #include "cn9k_rx.h"
7 #include "cn9k_tx.h"
8
9 static uint16_t
10 nix_rx_offload_flags(struct rte_eth_dev *eth_dev)
11 {
12         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
13         struct rte_eth_dev_data *data = eth_dev->data;
14         struct rte_eth_conf *conf = &data->dev_conf;
15         struct rte_eth_rxmode *rxmode = &conf->rxmode;
16         uint16_t flags = 0;
17
18         if (rxmode->mq_mode == RTE_ETH_MQ_RX_RSS &&
19             (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH))
20                 flags |= NIX_RX_OFFLOAD_RSS_F;
21
22         if (dev->rx_offloads &
23             (RTE_ETH_RX_OFFLOAD_TCP_CKSUM | RTE_ETH_RX_OFFLOAD_UDP_CKSUM))
24                 flags |= NIX_RX_OFFLOAD_CHECKSUM_F;
25
26         if (dev->rx_offloads &
27             (RTE_ETH_RX_OFFLOAD_IPV4_CKSUM | RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM))
28                 flags |= NIX_RX_OFFLOAD_CHECKSUM_F;
29
30         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
31                 flags |= NIX_RX_MULTI_SEG_F;
32
33         if ((dev->rx_offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP))
34                 flags |= NIX_RX_OFFLOAD_TSTAMP_F;
35
36         if (!dev->ptype_disable)
37                 flags |= NIX_RX_OFFLOAD_PTYPE_F;
38
39         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)
40                 flags |= NIX_RX_OFFLOAD_SECURITY_F;
41
42         if (dev->rx_mark_update)
43                 flags |= NIX_RX_OFFLOAD_MARK_UPDATE_F;
44
45         return flags;
46 }
47
48 static uint16_t
49 nix_tx_offload_flags(struct rte_eth_dev *eth_dev)
50 {
51         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
52         uint64_t conf = dev->tx_offloads;
53         uint16_t flags = 0;
54
55         /* Fastpath is dependent on these enums */
56         RTE_BUILD_BUG_ON(RTE_MBUF_F_TX_TCP_CKSUM != (1ULL << 52));
57         RTE_BUILD_BUG_ON(RTE_MBUF_F_TX_SCTP_CKSUM != (2ULL << 52));
58         RTE_BUILD_BUG_ON(RTE_MBUF_F_TX_UDP_CKSUM != (3ULL << 52));
59         RTE_BUILD_BUG_ON(RTE_MBUF_F_TX_IP_CKSUM != (1ULL << 54));
60         RTE_BUILD_BUG_ON(RTE_MBUF_F_TX_IPV4 != (1ULL << 55));
61         RTE_BUILD_BUG_ON(RTE_MBUF_F_TX_OUTER_IP_CKSUM != (1ULL << 58));
62         RTE_BUILD_BUG_ON(RTE_MBUF_F_TX_OUTER_IPV4 != (1ULL << 59));
63         RTE_BUILD_BUG_ON(RTE_MBUF_F_TX_OUTER_IPV6 != (1ULL << 60));
64         RTE_BUILD_BUG_ON(RTE_MBUF_F_TX_OUTER_UDP_CKSUM != (1ULL << 41));
65         RTE_BUILD_BUG_ON(RTE_MBUF_L2_LEN_BITS != 7);
66         RTE_BUILD_BUG_ON(RTE_MBUF_L3_LEN_BITS != 9);
67         RTE_BUILD_BUG_ON(RTE_MBUF_OUTL2_LEN_BITS != 7);
68         RTE_BUILD_BUG_ON(RTE_MBUF_OUTL3_LEN_BITS != 9);
69         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) !=
70                          offsetof(struct rte_mbuf, buf_iova) + 8);
71         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, ol_flags) !=
72                          offsetof(struct rte_mbuf, buf_iova) + 16);
73         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=
74                          offsetof(struct rte_mbuf, ol_flags) + 12);
75         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, tx_offload) !=
76                          offsetof(struct rte_mbuf, pool) + 2 * sizeof(void *));
77
78         if (conf & RTE_ETH_TX_OFFLOAD_VLAN_INSERT ||
79             conf & RTE_ETH_TX_OFFLOAD_QINQ_INSERT)
80                 flags |= NIX_TX_OFFLOAD_VLAN_QINQ_F;
81
82         if (conf & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM ||
83             conf & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM)
84                 flags |= NIX_TX_OFFLOAD_OL3_OL4_CSUM_F;
85
86         if (conf & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM ||
87             conf & RTE_ETH_TX_OFFLOAD_TCP_CKSUM ||
88             conf & RTE_ETH_TX_OFFLOAD_UDP_CKSUM || conf & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM)
89                 flags |= NIX_TX_OFFLOAD_L3_L4_CSUM_F;
90
91         if (!(conf & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE))
92                 flags |= NIX_TX_OFFLOAD_MBUF_NOFF_F;
93
94         if (conf & RTE_ETH_TX_OFFLOAD_MULTI_SEGS)
95                 flags |= NIX_TX_MULTI_SEG_F;
96
97         /* Enable Inner checksum for TSO */
98         if (conf & RTE_ETH_TX_OFFLOAD_TCP_TSO)
99                 flags |= (NIX_TX_OFFLOAD_TSO_F | NIX_TX_OFFLOAD_L3_L4_CSUM_F);
100
101         /* Enable Inner and Outer checksum for Tunnel TSO */
102         if (conf & (RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
103                     RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO | RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO))
104                 flags |= (NIX_TX_OFFLOAD_TSO_F | NIX_TX_OFFLOAD_OL3_OL4_CSUM_F |
105                           NIX_TX_OFFLOAD_L3_L4_CSUM_F);
106
107         if ((dev->rx_offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP))
108                 flags |= NIX_TX_OFFLOAD_TSTAMP_F;
109
110         if (dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY)
111                 flags |= NIX_TX_OFFLOAD_SECURITY_F;
112
113         return flags;
114 }
115
116 static int
117 cn9k_nix_ptypes_set(struct rte_eth_dev *eth_dev, uint32_t ptype_mask)
118 {
119         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
120
121         if (ptype_mask) {
122                 dev->rx_offload_flags |= NIX_RX_OFFLOAD_PTYPE_F;
123                 dev->ptype_disable = 0;
124         } else {
125                 dev->rx_offload_flags &= ~NIX_RX_OFFLOAD_PTYPE_F;
126                 dev->ptype_disable = 1;
127         }
128
129         cn9k_eth_set_rx_function(eth_dev);
130         return 0;
131 }
132
133 static void
134 nix_form_default_desc(struct cnxk_eth_dev *dev, struct cn9k_eth_txq *txq,
135                       uint16_t qid)
136 {
137         union nix_send_hdr_w0_u send_hdr_w0;
138
139         /* Initialize the fields based on basic single segment packet */
140         send_hdr_w0.u = 0;
141         if (dev->tx_offload_flags & NIX_TX_NEED_EXT_HDR) {
142                 /* 2(HDR) + 2(EXT_HDR) + 1(SG) + 1(IOVA) = 6/2 - 1 = 2 */
143                 send_hdr_w0.sizem1 = 2;
144                 if (dev->tx_offload_flags & NIX_TX_OFFLOAD_TSTAMP_F) {
145                         /* Default: one seg packet would have:
146                          * 2(HDR) + 2(EXT) + 1(SG) + 1(IOVA) + 2(MEM)
147                          * => 8/2 - 1 = 3
148                          */
149                         send_hdr_w0.sizem1 = 3;
150
151                         /* To calculate the offset for send_mem,
152                          * send_hdr->w0.sizem1 * 2
153                          */
154                         txq->ts_mem = dev->tstamp.tx_tstamp_iova;
155                 }
156         } else {
157                 /* 2(HDR) + 1(SG) + 1(IOVA) = 4/2 - 1 = 1 */
158                 send_hdr_w0.sizem1 = 1;
159         }
160         send_hdr_w0.sq = qid;
161         txq->send_hdr_w0 = send_hdr_w0.u;
162         rte_wmb();
163 }
164
165 static int
166 cn9k_nix_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t qid,
167                         uint16_t nb_desc, unsigned int socket,
168                         const struct rte_eth_txconf *tx_conf)
169 {
170         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
171         struct roc_cpt_lf *inl_lf;
172         struct cn9k_eth_txq *txq;
173         struct roc_nix_sq *sq;
174         uint16_t crypto_qid;
175         int rc;
176
177         RTE_SET_USED(socket);
178
179         /* Common Tx queue setup */
180         rc = cnxk_nix_tx_queue_setup(eth_dev, qid, nb_desc,
181                                      sizeof(struct cn9k_eth_txq), tx_conf);
182         if (rc)
183                 return rc;
184
185         sq = &dev->sqs[qid];
186         /* Update fast path queue */
187         txq = eth_dev->data->tx_queues[qid];
188         txq->fc_mem = sq->fc;
189         txq->lmt_addr = sq->lmt_addr;
190         txq->io_addr = sq->io_addr;
191         txq->nb_sqb_bufs_adj = sq->nb_sqb_bufs_adj;
192         txq->sqes_per_sqb_log2 = sq->sqes_per_sqb_log2;
193
194         /* Fetch CPT LF info for outbound if present */
195         if (dev->outb.lf_base) {
196                 crypto_qid = qid % dev->outb.nb_crypto_qs;
197                 inl_lf = dev->outb.lf_base + crypto_qid;
198
199                 txq->cpt_io_addr = inl_lf->io_addr;
200                 txq->cpt_fc = inl_lf->fc_addr;
201                 txq->cpt_desc = inl_lf->nb_desc * 0.7;
202                 txq->sa_base = (uint64_t)dev->outb.sa_base;
203                 txq->sa_base |= eth_dev->data->port_id;
204                 PLT_STATIC_ASSERT(BIT_ULL(16) == ROC_NIX_INL_SA_BASE_ALIGN);
205         }
206
207         nix_form_default_desc(dev, txq, qid);
208         txq->lso_tun_fmt = dev->lso_tun_fmt;
209         return 0;
210 }
211
212 static int
213 cn9k_nix_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t qid,
214                         uint16_t nb_desc, unsigned int socket,
215                         const struct rte_eth_rxconf *rx_conf,
216                         struct rte_mempool *mp)
217 {
218         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
219         struct cn9k_eth_rxq *rxq;
220         struct roc_nix_rq *rq;
221         struct roc_nix_cq *cq;
222         int rc;
223
224         RTE_SET_USED(socket);
225
226         /* CQ Errata needs min 4K ring */
227         if (dev->cq_min_4k && nb_desc < 4096)
228                 nb_desc = 4096;
229
230         /* Common Rx queue setup */
231         rc = cnxk_nix_rx_queue_setup(eth_dev, qid, nb_desc,
232                                      sizeof(struct cn9k_eth_rxq), rx_conf, mp);
233         if (rc)
234                 return rc;
235
236         rq = &dev->rqs[qid];
237         cq = &dev->cqs[qid];
238
239         /* Update fast path queue */
240         rxq = eth_dev->data->rx_queues[qid];
241         rxq->rq = qid;
242         rxq->desc = (uintptr_t)cq->desc_base;
243         rxq->cq_door = cq->door;
244         rxq->cq_status = cq->status;
245         rxq->wdata = cq->wdata;
246         rxq->head = cq->head;
247         rxq->qmask = cq->qmask;
248         rxq->tstamp = &dev->tstamp;
249
250         /* Data offset from data to start of mbuf is first_skip */
251         rxq->data_off = rq->first_skip;
252         rxq->mbuf_initializer = cnxk_nix_rxq_mbuf_setup(dev);
253
254         /* Lookup mem */
255         rxq->lookup_mem = cnxk_nix_fastpath_lookup_mem_get();
256         return 0;
257 }
258
259 static int
260 cn9k_nix_tx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qidx)
261 {
262         struct cn9k_eth_txq *txq = eth_dev->data->tx_queues[qidx];
263         int rc;
264
265         rc = cnxk_nix_tx_queue_stop(eth_dev, qidx);
266         if (rc)
267                 return rc;
268
269         /* Clear fc cache pkts to trigger worker stop */
270         txq->fc_cache_pkts = 0;
271         return 0;
272 }
273
274 static int
275 cn9k_nix_configure(struct rte_eth_dev *eth_dev)
276 {
277         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
278         struct rte_eth_conf *conf = &eth_dev->data->dev_conf;
279         struct rte_eth_txmode *txmode = &conf->txmode;
280         int rc;
281
282         /* Platform specific checks */
283         if ((roc_model_is_cn96_a0() || roc_model_is_cn95_a0()) &&
284             (txmode->offloads & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) &&
285             ((txmode->offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) ||
286              (txmode->offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM))) {
287                 plt_err("Outer IP and SCTP checksum unsupported");
288                 return -EINVAL;
289         }
290
291         /* Common nix configure */
292         rc = cnxk_nix_configure(eth_dev);
293         if (rc)
294                 return rc;
295
296         /* Update offload flags */
297         dev->rx_offload_flags = nix_rx_offload_flags(eth_dev);
298         dev->tx_offload_flags = nix_tx_offload_flags(eth_dev);
299
300         plt_nix_dbg("Configured port%d platform specific rx_offload_flags=%x"
301                     " tx_offload_flags=0x%x",
302                     eth_dev->data->port_id, dev->rx_offload_flags,
303                     dev->tx_offload_flags);
304         return 0;
305 }
306
307 /* Function to enable ptp config for VFs */
308 static void
309 nix_ptp_enable_vf(struct rte_eth_dev *eth_dev)
310 {
311         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
312
313         if (nix_recalc_mtu(eth_dev))
314                 plt_err("Failed to set MTU size for ptp");
315
316         dev->rx_offload_flags |= NIX_RX_OFFLOAD_TSTAMP_F;
317
318         /* Setting up the function pointers as per new offload flags */
319         cn9k_eth_set_rx_function(eth_dev);
320         cn9k_eth_set_tx_function(eth_dev);
321 }
322
323 static uint16_t
324 nix_ptp_vf_burst(void *queue, struct rte_mbuf **mbufs, uint16_t pkts)
325 {
326         struct cn9k_eth_rxq *rxq = queue;
327         struct cnxk_eth_rxq_sp *rxq_sp;
328         struct rte_eth_dev *eth_dev;
329
330         RTE_SET_USED(mbufs);
331         RTE_SET_USED(pkts);
332
333         rxq_sp = cnxk_eth_rxq_to_sp(rxq);
334         eth_dev = rxq_sp->dev->eth_dev;
335         nix_ptp_enable_vf(eth_dev);
336
337         return 0;
338 }
339
340 static int
341 cn9k_nix_ptp_info_update_cb(struct roc_nix *nix, bool ptp_en)
342 {
343         struct cnxk_eth_dev *dev = (struct cnxk_eth_dev *)nix;
344         struct rte_eth_dev *eth_dev;
345         struct cn9k_eth_rxq *rxq;
346         int i;
347
348         if (!dev)
349                 return -EINVAL;
350
351         eth_dev = dev->eth_dev;
352         if (!eth_dev)
353                 return -EINVAL;
354
355         dev->ptp_en = ptp_en;
356
357         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
358                 rxq = eth_dev->data->rx_queues[i];
359                 rxq->mbuf_initializer = cnxk_nix_rxq_mbuf_setup(dev);
360         }
361
362         if (roc_nix_is_vf_or_sdp(nix) && !(roc_nix_is_sdp(nix)) &&
363             !(roc_nix_is_lbk(nix))) {
364                 /* In case of VF, setting of MTU cannot be done directly in this
365                  * function as this is running as part of MBOX request(PF->VF)
366                  * and MTU setting also requires MBOX message to be
367                  * sent(VF->PF)
368                  */
369                 eth_dev->rx_pkt_burst = nix_ptp_vf_burst;
370                 rte_mb();
371         }
372
373         return 0;
374 }
375
376 static int
377 cn9k_nix_timesync_enable(struct rte_eth_dev *eth_dev)
378 {
379         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
380         int i, rc;
381
382         rc = cnxk_nix_timesync_enable(eth_dev);
383         if (rc)
384                 return rc;
385
386         dev->rx_offload_flags |= NIX_RX_OFFLOAD_TSTAMP_F;
387         dev->tx_offload_flags |= NIX_TX_OFFLOAD_TSTAMP_F;
388
389         for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
390                 nix_form_default_desc(dev, eth_dev->data->tx_queues[i], i);
391
392         /* Setting up the rx[tx]_offload_flags due to change
393          * in rx[tx]_offloads.
394          */
395         cn9k_eth_set_rx_function(eth_dev);
396         cn9k_eth_set_tx_function(eth_dev);
397         return 0;
398 }
399
400 static int
401 cn9k_nix_timesync_disable(struct rte_eth_dev *eth_dev)
402 {
403         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
404         int i, rc;
405
406         rc = cnxk_nix_timesync_disable(eth_dev);
407         if (rc)
408                 return rc;
409
410         dev->rx_offload_flags &= ~NIX_RX_OFFLOAD_TSTAMP_F;
411         dev->tx_offload_flags &= ~NIX_TX_OFFLOAD_TSTAMP_F;
412
413         for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
414                 nix_form_default_desc(dev, eth_dev->data->tx_queues[i], i);
415
416         /* Setting up the rx[tx]_offload_flags due to change
417          * in rx[tx]_offloads.
418          */
419         cn9k_eth_set_rx_function(eth_dev);
420         cn9k_eth_set_tx_function(eth_dev);
421         return 0;
422 }
423
424 static int
425 cn9k_nix_dev_start(struct rte_eth_dev *eth_dev)
426 {
427         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
428         struct roc_nix *nix = &dev->nix;
429         int rc;
430
431         /* Common eth dev start */
432         rc = cnxk_nix_dev_start(eth_dev);
433         if (rc)
434                 return rc;
435
436         /* Update VF about data off shifted by 8 bytes if PTP already
437          * enabled in PF owning this VF
438          */
439         if (dev->ptp_en && (!roc_nix_is_pf(nix) && (!roc_nix_is_sdp(nix))))
440                 nix_ptp_enable_vf(eth_dev);
441
442         /* Setting up the rx[tx]_offload_flags due to change
443          * in rx[tx]_offloads.
444          */
445         dev->rx_offload_flags |= nix_rx_offload_flags(eth_dev);
446         dev->tx_offload_flags |= nix_tx_offload_flags(eth_dev);
447
448         cn9k_eth_set_tx_function(eth_dev);
449         cn9k_eth_set_rx_function(eth_dev);
450         return 0;
451 }
452
453 static int
454 cn9k_nix_timesync_read_tx_timestamp(struct rte_eth_dev *eth_dev,
455                                     struct timespec *timestamp)
456 {
457         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
458         struct cnxk_timesync_info *tstamp = &dev->tstamp;
459         uint64_t ns;
460
461         if (*tstamp->tx_tstamp == 0)
462                 return -EINVAL;
463
464         ns = rte_timecounter_update(&dev->tx_tstamp_tc, *tstamp->tx_tstamp);
465         *timestamp = rte_ns_to_timespec(ns);
466         *tstamp->tx_tstamp = 0;
467         rte_wmb();
468
469         return 0;
470 }
471
472 static int
473 cn9k_nix_rx_metadata_negotiate(struct rte_eth_dev *eth_dev, uint64_t *features)
474 {
475         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
476
477         *features &=
478                 (RTE_ETH_RX_METADATA_USER_FLAG | RTE_ETH_RX_METADATA_USER_MARK);
479
480         if (*features) {
481                 dev->rx_offload_flags |= NIX_RX_OFFLOAD_MARK_UPDATE_F;
482                 dev->rx_mark_update = true;
483         } else {
484                 dev->rx_offload_flags &= ~NIX_RX_OFFLOAD_MARK_UPDATE_F;
485                 dev->rx_mark_update = false;
486         }
487
488         cn9k_eth_set_rx_function(eth_dev);
489
490         return 0;
491 }
492
493 /* Update platform specific eth dev ops */
494 static void
495 nix_eth_dev_ops_override(void)
496 {
497         static int init_once;
498
499         if (init_once)
500                 return;
501         init_once = 1;
502
503         /* Update platform specific ops */
504         cnxk_eth_dev_ops.dev_configure = cn9k_nix_configure;
505         cnxk_eth_dev_ops.tx_queue_setup = cn9k_nix_tx_queue_setup;
506         cnxk_eth_dev_ops.rx_queue_setup = cn9k_nix_rx_queue_setup;
507         cnxk_eth_dev_ops.tx_queue_stop = cn9k_nix_tx_queue_stop;
508         cnxk_eth_dev_ops.dev_start = cn9k_nix_dev_start;
509         cnxk_eth_dev_ops.dev_ptypes_set = cn9k_nix_ptypes_set;
510         cnxk_eth_dev_ops.timesync_enable = cn9k_nix_timesync_enable;
511         cnxk_eth_dev_ops.timesync_disable = cn9k_nix_timesync_disable;
512         cnxk_eth_dev_ops.mtr_ops_get = NULL;
513         cnxk_eth_dev_ops.rx_metadata_negotiate = cn9k_nix_rx_metadata_negotiate;
514         cnxk_eth_dev_ops.timesync_read_tx_timestamp =
515                 cn9k_nix_timesync_read_tx_timestamp;
516 }
517
518 static void
519 npc_flow_ops_override(void)
520 {
521         static int init_once;
522
523         if (init_once)
524                 return;
525         init_once = 1;
526
527         /* Update platform specific ops */
528         cnxk_flow_ops.create = cn9k_flow_create;
529         cnxk_flow_ops.destroy = cn9k_flow_destroy;
530 }
531
532 static int
533 cn9k_nix_remove(struct rte_pci_device *pci_dev)
534 {
535         return cnxk_nix_remove(pci_dev);
536 }
537
538 static int
539 cn9k_nix_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
540 {
541         struct rte_eth_dev *eth_dev;
542         struct cnxk_eth_dev *dev;
543         int rc;
544
545         if (RTE_CACHE_LINE_SIZE != 128) {
546                 plt_err("Driver not compiled for CN9K");
547                 return -EFAULT;
548         }
549
550         rc = roc_plt_init();
551         if (rc) {
552                 plt_err("Failed to initialize platform model, rc=%d", rc);
553                 return rc;
554         }
555
556         nix_eth_dev_ops_override();
557         npc_flow_ops_override();
558
559         cn9k_eth_sec_ops_override();
560
561         /* Common probe */
562         rc = cnxk_nix_probe(pci_drv, pci_dev);
563         if (rc)
564                 return rc;
565
566         /* Find eth dev allocated */
567         eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
568         if (!eth_dev)
569                 return -ENOENT;
570
571         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
572                 /* Setup callbacks for secondary process */
573                 cn9k_eth_set_tx_function(eth_dev);
574                 cn9k_eth_set_rx_function(eth_dev);
575                 return 0;
576         }
577
578         dev = cnxk_eth_pmd_priv(eth_dev);
579         /* Update capabilities already set for TSO.
580          * TSO not supported for earlier chip revisions
581          */
582         if (roc_model_is_cn96_a0() || roc_model_is_cn95_a0())
583                 dev->tx_offload_capa &= ~(RTE_ETH_TX_OFFLOAD_TCP_TSO |
584                                           RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
585                                           RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
586                                           RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO);
587
588         /* 50G and 100G to be supported for board version C0
589          * and above of CN9K.
590          */
591         if (roc_model_is_cn96_a0() || roc_model_is_cn95_a0()) {
592                 dev->speed_capa &= ~(uint64_t)RTE_ETH_LINK_SPEED_50G;
593                 dev->speed_capa &= ~(uint64_t)RTE_ETH_LINK_SPEED_100G;
594         }
595
596         dev->hwcap = 0;
597
598         /* Register up msg callbacks for PTP information */
599         roc_nix_ptp_info_cb_register(&dev->nix, cn9k_nix_ptp_info_update_cb);
600
601         /* Update HW erratas */
602         if (roc_model_is_cn96_a0() || roc_model_is_cn95_a0())
603                 dev->cq_min_4k = 1;
604         return 0;
605 }
606
607 static const struct rte_pci_id cn9k_pci_nix_map[] = {
608         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KA, PCI_DEVID_CNXK_RVU_PF),
609         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KB, PCI_DEVID_CNXK_RVU_PF),
610         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KC, PCI_DEVID_CNXK_RVU_PF),
611         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KD, PCI_DEVID_CNXK_RVU_PF),
612         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KE, PCI_DEVID_CNXK_RVU_PF),
613         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KA, PCI_DEVID_CNXK_RVU_VF),
614         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KB, PCI_DEVID_CNXK_RVU_VF),
615         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KC, PCI_DEVID_CNXK_RVU_VF),
616         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KD, PCI_DEVID_CNXK_RVU_VF),
617         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KE, PCI_DEVID_CNXK_RVU_VF),
618         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KA, PCI_DEVID_CNXK_RVU_AF_VF),
619         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KB, PCI_DEVID_CNXK_RVU_AF_VF),
620         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KC, PCI_DEVID_CNXK_RVU_AF_VF),
621         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KD, PCI_DEVID_CNXK_RVU_AF_VF),
622         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN9KE, PCI_DEVID_CNXK_RVU_AF_VF),
623         {
624                 .vendor_id = 0,
625         },
626 };
627
628 static struct rte_pci_driver cn9k_pci_nix = {
629         .id_table = cn9k_pci_nix_map,
630         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA |
631                      RTE_PCI_DRV_INTR_LSC,
632         .probe = cn9k_nix_probe,
633         .remove = cn9k_nix_remove,
634 };
635
636 RTE_PMD_REGISTER_PCI(net_cn9k, cn9k_pci_nix);
637 RTE_PMD_REGISTER_PCI_TABLE(net_cn9k, cn9k_pci_nix_map);
638 RTE_PMD_REGISTER_KMOD_DEP(net_cn9k, "vfio-pci");