event/cnxk: add platform specific device probe
[dpdk.git] / drivers / event / cnxk / cn9k_eventdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #include "cnxk_eventdev.h"
6
7 #define CN9K_DUAL_WS_NB_WS          2
8 #define CN9K_DUAL_WS_PAIR_ID(x, id) (((x)*CN9K_DUAL_WS_NB_WS) + id)
9
10 static void
11 cn9k_sso_set_rsrc(void *arg)
12 {
13         struct cnxk_sso_evdev *dev = arg;
14
15         if (dev->dual_ws)
16                 dev->max_event_ports = dev->sso.max_hws / CN9K_DUAL_WS_NB_WS;
17         else
18                 dev->max_event_ports = dev->sso.max_hws;
19         dev->max_event_queues =
20                 dev->sso.max_hwgrp > RTE_EVENT_MAX_QUEUES_PER_DEV ?
21                               RTE_EVENT_MAX_QUEUES_PER_DEV :
22                               dev->sso.max_hwgrp;
23 }
24
25 static void
26 cn9k_sso_info_get(struct rte_eventdev *event_dev,
27                   struct rte_event_dev_info *dev_info)
28 {
29         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
30
31         dev_info->driver_name = RTE_STR(EVENTDEV_NAME_CN9K_PMD);
32         cnxk_sso_info_get(dev, dev_info);
33 }
34
35 static struct rte_eventdev_ops cn9k_sso_dev_ops = {
36         .dev_infos_get = cn9k_sso_info_get,
37 };
38
39 static int
40 cn9k_sso_init(struct rte_eventdev *event_dev)
41 {
42         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
43         int rc;
44
45         if (RTE_CACHE_LINE_SIZE != 128) {
46                 plt_err("Driver not compiled for CN9K");
47                 return -EFAULT;
48         }
49
50         rc = roc_plt_init();
51         if (rc < 0) {
52                 plt_err("Failed to initialize platform model");
53                 return rc;
54         }
55
56         event_dev->dev_ops = &cn9k_sso_dev_ops;
57         /* For secondary processes, the primary has done all the work */
58         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
59                 return 0;
60
61         rc = cnxk_sso_init(event_dev);
62         if (rc < 0)
63                 return rc;
64
65         cn9k_sso_set_rsrc(cnxk_sso_pmd_priv(event_dev));
66         if (!dev->max_event_ports || !dev->max_event_queues) {
67                 plt_err("Not enough eventdev resource queues=%d ports=%d",
68                         dev->max_event_queues, dev->max_event_ports);
69                 cnxk_sso_fini(event_dev);
70                 return -ENODEV;
71         }
72
73         plt_sso_dbg("Initializing %s max_queues=%d max_ports=%d",
74                     event_dev->data->name, dev->max_event_queues,
75                     dev->max_event_ports);
76
77         return 0;
78 }
79
80 static int
81 cn9k_sso_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
82 {
83         return rte_event_pmd_pci_probe(
84                 pci_drv, pci_dev, sizeof(struct cnxk_sso_evdev), cn9k_sso_init);
85 }
86
87 static const struct rte_pci_id cn9k_pci_sso_map[] = {
88         {
89                 .vendor_id = 0,
90         },
91 };
92
93 static struct rte_pci_driver cn9k_pci_sso = {
94         .id_table = cn9k_pci_sso_map,
95         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA,
96         .probe = cn9k_sso_probe,
97         .remove = cnxk_sso_remove,
98 };
99
100 RTE_PMD_REGISTER_PCI(event_cn9k, cn9k_pci_sso);
101 RTE_PMD_REGISTER_PCI_TABLE(event_cn9k, cn9k_pci_sso_map);
102 RTE_PMD_REGISTER_KMOD_DEP(event_cn9k, "vfio-pci");