net/hns3: refactor multi-process initialization
[dpdk.git] / drivers / raw / cnxk_bphy / cnxk_bphy_irq.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4 #include <rte_bus_pci.h>
5 #include <rte_pci.h>
6 #include <rte_rawdev.h>
7 #include <rte_rawdev_pmd.h>
8
9 #include <roc_api.h>
10
11 #include "cnxk_bphy_irq.h"
12
13 static struct bphy_device *
14 cnxk_bphy_get_bphy_dev_by_dev_id(uint16_t dev_id)
15 {
16         struct rte_rawdev *rawdev;
17
18         if (!rte_rawdev_pmd_is_valid_dev(dev_id))
19                 return NULL;
20
21         rawdev = &rte_rawdevs[dev_id];
22
23         return (struct bphy_device *)rawdev->dev_private;
24 }
25
26 uint64_t
27 cnxk_bphy_irq_max_get(uint16_t dev_id)
28 {
29         struct roc_bphy_irq_chip *irq_chip;
30         struct bphy_device *bphy_dev;
31
32         bphy_dev = cnxk_bphy_get_bphy_dev_by_dev_id(dev_id);
33         irq_chip = bphy_dev->irq_chip;
34
35         return roc_bphy_intr_max_get(irq_chip);
36 }
37
38 int
39 cnxk_bphy_intr_init(uint16_t dev_id)
40 {
41         struct bphy_device *bphy_dev = cnxk_bphy_get_bphy_dev_by_dev_id(dev_id);
42
43         bphy_dev->irq_chip = roc_bphy_intr_init();
44         if (bphy_dev->irq_chip == NULL)
45                 return -ENOMEM;
46
47         return 0;
48 }
49
50 void
51 cnxk_bphy_intr_fini(uint16_t dev_id)
52 {
53         struct bphy_device *bphy_dev = cnxk_bphy_get_bphy_dev_by_dev_id(dev_id);
54         struct roc_bphy_irq_chip *irq_chip = bphy_dev->irq_chip;
55
56         roc_bphy_intr_fini(irq_chip);
57         bphy_dev->irq_chip = NULL;
58 }
59
60 int
61 cnxk_bphy_intr_register(uint16_t dev_id, int irq_num,
62                         cnxk_bphy_intr_handler_t handler, void *data, int cpu)
63 {
64         struct roc_bphy_intr intr = {
65                 .irq_num = irq_num,
66                 .intr_handler = handler,
67                 .isr_data = data,
68                 .cpu = cpu
69         };
70
71         struct bphy_device *bphy_dev = cnxk_bphy_get_bphy_dev_by_dev_id(dev_id);
72         struct roc_bphy_irq_chip *irq_chip = bphy_dev->irq_chip;
73
74         if (!irq_chip)
75                 return -ENODEV;
76         if (!handler || !data)
77                 return -EINVAL;
78
79         return roc_bphy_intr_register(irq_chip, &intr);
80 }
81
82 void
83 cnxk_bphy_intr_unregister(uint16_t dev_id, int irq_num)
84 {
85         struct bphy_device *bphy_dev = cnxk_bphy_get_bphy_dev_by_dev_id(dev_id);
86
87         if (bphy_dev->irq_chip)
88                 roc_bphy_intr_clear(bphy_dev->irq_chip, irq_num);
89         else
90                 plt_err("Missing irq chip");
91 }
92
93 struct cnxk_bphy_mem *
94 cnxk_bphy_mem_get(uint16_t dev_id)
95 {
96         struct bphy_device *bphy_dev = cnxk_bphy_get_bphy_dev_by_dev_id(dev_id);
97
98         return &bphy_dev->mem;
99 }