event/cnxk: add event queue config
[dpdk.git] / drivers / event / cnxk / cn10k_eventdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #include "cnxk_eventdev.h"
6
7 static void
8 cn10k_sso_set_rsrc(void *arg)
9 {
10         struct cnxk_sso_evdev *dev = arg;
11
12         dev->max_event_ports = dev->sso.max_hws;
13         dev->max_event_queues =
14                 dev->sso.max_hwgrp > RTE_EVENT_MAX_QUEUES_PER_DEV ?
15                               RTE_EVENT_MAX_QUEUES_PER_DEV :
16                               dev->sso.max_hwgrp;
17 }
18
19 static int
20 cn10k_sso_rsrc_init(void *arg, uint8_t hws, uint8_t hwgrp)
21 {
22         struct cnxk_sso_evdev *dev = arg;
23
24         return roc_sso_rsrc_init(&dev->sso, hws, hwgrp);
25 }
26
27 static void
28 cn10k_sso_info_get(struct rte_eventdev *event_dev,
29                    struct rte_event_dev_info *dev_info)
30 {
31         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
32
33         dev_info->driver_name = RTE_STR(EVENTDEV_NAME_CN10K_PMD);
34         cnxk_sso_info_get(dev, dev_info);
35 }
36
37 static int
38 cn10k_sso_dev_configure(const struct rte_eventdev *event_dev)
39 {
40         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
41         int rc;
42
43         rc = cnxk_sso_dev_validate(event_dev);
44         if (rc < 0) {
45                 plt_err("Invalid event device configuration");
46                 return -EINVAL;
47         }
48
49         roc_sso_rsrc_fini(&dev->sso);
50
51         rc = cn10k_sso_rsrc_init(dev, dev->nb_event_ports,
52                                  dev->nb_event_queues);
53         if (rc < 0) {
54                 plt_err("Failed to initialize SSO resources");
55                 return -ENODEV;
56         }
57
58         return rc;
59 }
60
61 static struct rte_eventdev_ops cn10k_sso_dev_ops = {
62         .dev_infos_get = cn10k_sso_info_get,
63         .dev_configure = cn10k_sso_dev_configure,
64         .queue_def_conf = cnxk_sso_queue_def_conf,
65         .queue_setup = cnxk_sso_queue_setup,
66         .queue_release = cnxk_sso_queue_release,
67         .port_def_conf = cnxk_sso_port_def_conf,
68 };
69
70 static int
71 cn10k_sso_init(struct rte_eventdev *event_dev)
72 {
73         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
74         int rc;
75
76         if (RTE_CACHE_LINE_SIZE != 64) {
77                 plt_err("Driver not compiled for CN9K");
78                 return -EFAULT;
79         }
80
81         rc = roc_plt_init();
82         if (rc < 0) {
83                 plt_err("Failed to initialize platform model");
84                 return rc;
85         }
86
87         event_dev->dev_ops = &cn10k_sso_dev_ops;
88         /* For secondary processes, the primary has done all the work */
89         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
90                 return 0;
91
92         rc = cnxk_sso_init(event_dev);
93         if (rc < 0)
94                 return rc;
95
96         cn10k_sso_set_rsrc(cnxk_sso_pmd_priv(event_dev));
97         if (!dev->max_event_ports || !dev->max_event_queues) {
98                 plt_err("Not enough eventdev resource queues=%d ports=%d",
99                         dev->max_event_queues, dev->max_event_ports);
100                 cnxk_sso_fini(event_dev);
101                 return -ENODEV;
102         }
103
104         plt_sso_dbg("Initializing %s max_queues=%d max_ports=%d",
105                     event_dev->data->name, dev->max_event_queues,
106                     dev->max_event_ports);
107
108         return 0;
109 }
110
111 static int
112 cn10k_sso_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
113 {
114         return rte_event_pmd_pci_probe(pci_drv, pci_dev,
115                                        sizeof(struct cnxk_sso_evdev),
116                                        cn10k_sso_init);
117 }
118
119 static const struct rte_pci_id cn10k_pci_sso_map[] = {
120         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN10KA, PCI_DEVID_CNXK_RVU_SSO_TIM_PF),
121         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN10KAS, PCI_DEVID_CNXK_RVU_SSO_TIM_PF),
122         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN10KA, PCI_DEVID_CNXK_RVU_SSO_TIM_VF),
123         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN10KAS, PCI_DEVID_CNXK_RVU_SSO_TIM_VF),
124         {
125                 .vendor_id = 0,
126         },
127 };
128
129 static struct rte_pci_driver cn10k_pci_sso = {
130         .id_table = cn10k_pci_sso_map,
131         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA,
132         .probe = cn10k_sso_probe,
133         .remove = cnxk_sso_remove,
134 };
135
136 RTE_PMD_REGISTER_PCI(event_cn10k, cn10k_pci_sso);
137 RTE_PMD_REGISTER_PCI_TABLE(event_cn10k, cn10k_pci_sso_map);
138 RTE_PMD_REGISTER_KMOD_DEP(event_cn10k, "vfio-pci");