event/cnxk: add option to control SSO HWGRP QoS
[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 int
26 cn9k_sso_rsrc_init(void *arg, uint8_t hws, uint8_t hwgrp)
27 {
28         struct cnxk_sso_evdev *dev = arg;
29
30         if (dev->dual_ws)
31                 hws = hws * CN9K_DUAL_WS_NB_WS;
32
33         return roc_sso_rsrc_init(&dev->sso, hws, hwgrp);
34 }
35
36 static void
37 cn9k_sso_info_get(struct rte_eventdev *event_dev,
38                   struct rte_event_dev_info *dev_info)
39 {
40         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
41
42         dev_info->driver_name = RTE_STR(EVENTDEV_NAME_CN9K_PMD);
43         cnxk_sso_info_get(dev, dev_info);
44 }
45
46 static int
47 cn9k_sso_dev_configure(const struct rte_eventdev *event_dev)
48 {
49         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
50         int rc;
51
52         rc = cnxk_sso_dev_validate(event_dev);
53         if (rc < 0) {
54                 plt_err("Invalid event device configuration");
55                 return -EINVAL;
56         }
57
58         roc_sso_rsrc_fini(&dev->sso);
59
60         rc = cn9k_sso_rsrc_init(dev, dev->nb_event_ports, dev->nb_event_queues);
61         if (rc < 0) {
62                 plt_err("Failed to initialize SSO resources");
63                 return -ENODEV;
64         }
65
66         rc = cnxk_sso_xaq_allocate(dev);
67         if (rc < 0)
68                 goto cnxk_rsrc_fini;
69
70         return 0;
71 cnxk_rsrc_fini:
72         roc_sso_rsrc_fini(&dev->sso);
73         return rc;
74 }
75
76 static struct rte_eventdev_ops cn9k_sso_dev_ops = {
77         .dev_infos_get = cn9k_sso_info_get,
78         .dev_configure = cn9k_sso_dev_configure,
79         .queue_def_conf = cnxk_sso_queue_def_conf,
80         .queue_setup = cnxk_sso_queue_setup,
81         .queue_release = cnxk_sso_queue_release,
82         .port_def_conf = cnxk_sso_port_def_conf,
83 };
84
85 static int
86 cn9k_sso_init(struct rte_eventdev *event_dev)
87 {
88         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
89         int rc;
90
91         if (RTE_CACHE_LINE_SIZE != 128) {
92                 plt_err("Driver not compiled for CN9K");
93                 return -EFAULT;
94         }
95
96         rc = roc_plt_init();
97         if (rc < 0) {
98                 plt_err("Failed to initialize platform model");
99                 return rc;
100         }
101
102         event_dev->dev_ops = &cn9k_sso_dev_ops;
103         /* For secondary processes, the primary has done all the work */
104         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
105                 return 0;
106
107         rc = cnxk_sso_init(event_dev);
108         if (rc < 0)
109                 return rc;
110
111         cn9k_sso_set_rsrc(cnxk_sso_pmd_priv(event_dev));
112         if (!dev->max_event_ports || !dev->max_event_queues) {
113                 plt_err("Not enough eventdev resource queues=%d ports=%d",
114                         dev->max_event_queues, dev->max_event_ports);
115                 cnxk_sso_fini(event_dev);
116                 return -ENODEV;
117         }
118
119         plt_sso_dbg("Initializing %s max_queues=%d max_ports=%d",
120                     event_dev->data->name, dev->max_event_queues,
121                     dev->max_event_ports);
122
123         return 0;
124 }
125
126 static int
127 cn9k_sso_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
128 {
129         return rte_event_pmd_pci_probe(
130                 pci_drv, pci_dev, sizeof(struct cnxk_sso_evdev), cn9k_sso_init);
131 }
132
133 static const struct rte_pci_id cn9k_pci_sso_map[] = {
134         {
135                 .vendor_id = 0,
136         },
137 };
138
139 static struct rte_pci_driver cn9k_pci_sso = {
140         .id_table = cn9k_pci_sso_map,
141         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA,
142         .probe = cn9k_sso_probe,
143         .remove = cnxk_sso_remove,
144 };
145
146 RTE_PMD_REGISTER_PCI(event_cn9k, cn9k_pci_sso);
147 RTE_PMD_REGISTER_PCI_TABLE(event_cn9k, cn9k_pci_sso_map);
148 RTE_PMD_REGISTER_KMOD_DEP(event_cn9k, "vfio-pci");
149 RTE_PMD_REGISTER_PARAM_STRING(event_cn9k, CNXK_SSO_XAE_CNT "=<int>"
150                               CNXK_SSO_GGRP_QOS "=<string>");