net/cnxk: add device configuration operation
[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
6 static int
7 cn9k_nix_configure(struct rte_eth_dev *eth_dev)
8 {
9         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
10         struct rte_eth_conf *conf = &eth_dev->data->dev_conf;
11         struct rte_eth_txmode *txmode = &conf->txmode;
12         int rc;
13
14         /* Platform specific checks */
15         if ((roc_model_is_cn96_a0() || roc_model_is_cn95_a0()) &&
16             (txmode->offloads & DEV_TX_OFFLOAD_SCTP_CKSUM) &&
17             ((txmode->offloads & DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM) ||
18              (txmode->offloads & DEV_TX_OFFLOAD_OUTER_UDP_CKSUM))) {
19                 plt_err("Outer IP and SCTP checksum unsupported");
20                 return -EINVAL;
21         }
22
23         /* Common nix configure */
24         rc = cnxk_nix_configure(eth_dev);
25         if (rc)
26                 return rc;
27
28         plt_nix_dbg("Configured port%d platform specific rx_offload_flags=%x"
29                     " tx_offload_flags=0x%x",
30                     eth_dev->data->port_id, dev->rx_offload_flags,
31                     dev->tx_offload_flags);
32         return 0;
33 }
34
35 /* Update platform specific eth dev ops */
36 static void
37 nix_eth_dev_ops_override(void)
38 {
39         static int init_once;
40
41         if (init_once)
42                 return;
43         init_once = 1;
44
45         /* Update platform specific ops */
46         cnxk_eth_dev_ops.dev_configure = cn9k_nix_configure;
47 }
48
49 static int
50 cn9k_nix_remove(struct rte_pci_device *pci_dev)
51 {
52         return cnxk_nix_remove(pci_dev);
53 }
54
55 static int
56 cn9k_nix_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
57 {
58         struct rte_eth_dev *eth_dev;
59         struct cnxk_eth_dev *dev;
60         int rc;
61
62         if (RTE_CACHE_LINE_SIZE != 128) {
63                 plt_err("Driver not compiled for CN9K");
64                 return -EFAULT;
65         }
66
67         rc = roc_plt_init();
68         if (rc) {
69                 plt_err("Failed to initialize platform model, rc=%d", rc);
70                 return rc;
71         }
72
73         nix_eth_dev_ops_override();
74
75         /* Common probe */
76         rc = cnxk_nix_probe(pci_drv, pci_dev);
77         if (rc)
78                 return rc;
79
80         /* Find eth dev allocated */
81         eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
82         if (!eth_dev)
83                 return -ENOENT;
84
85         dev = cnxk_eth_pmd_priv(eth_dev);
86         /* Update capabilities already set for TSO.
87          * TSO not supported for earlier chip revisions
88          */
89         if (roc_model_is_cn96_a0() || roc_model_is_cn95_a0())
90                 dev->tx_offload_capa &= ~(DEV_TX_OFFLOAD_TCP_TSO |
91                                           DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
92                                           DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
93                                           DEV_TX_OFFLOAD_GRE_TNL_TSO);
94
95         /* 50G and 100G to be supported for board version C0
96          * and above of CN9K.
97          */
98         if (roc_model_is_cn96_a0() || roc_model_is_cn95_a0()) {
99                 dev->speed_capa &= ~(uint64_t)ETH_LINK_SPEED_50G;
100                 dev->speed_capa &= ~(uint64_t)ETH_LINK_SPEED_100G;
101         }
102
103         dev->hwcap = 0;
104
105         /* Update HW erratas */
106         if (roc_model_is_cn96_a0() || roc_model_is_cn95_a0())
107                 dev->cq_min_4k = 1;
108         return 0;
109 }
110
111 static const struct rte_pci_id cn9k_pci_nix_map[] = {
112         {
113                 .vendor_id = 0,
114         },
115 };
116
117 static struct rte_pci_driver cn9k_pci_nix = {
118         .id_table = cn9k_pci_nix_map,
119         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA |
120                      RTE_PCI_DRV_INTR_LSC,
121         .probe = cn9k_nix_probe,
122         .remove = cn9k_nix_remove,
123 };
124
125 RTE_PMD_REGISTER_PCI(net_cn9k, cn9k_pci_nix);
126 RTE_PMD_REGISTER_PCI_TABLE(net_cn9k, cn9k_pci_nix_map);
127 RTE_PMD_REGISTER_KMOD_DEP(net_cn9k, "vfio-pci");