1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
8 #include <rte_bus_pci.h>
10 #include <octeontx_mbox.h>
12 #include "ssovf_evdev.h"
13 #include "timvf_evdev.h"
15 #ifndef PCI_VENDOR_ID_CAVIUM
16 #define PCI_VENDOR_ID_CAVIUM (0x177D)
19 #define PCI_DEVICE_ID_OCTEONTX_TIM_VF (0xA051)
20 #define TIM_MAX_RINGS (64)
32 struct timvf_res rings
[TIM_MAX_RINGS
];
35 static struct timdev tdev
;
38 timvf_info(struct timvf_info
*tinfo
)
41 struct ssovf_info info
;
46 if (!tdev
.total_timvfs
)
49 if (ssovf_info(&info
) < 0)
52 for (i
= 0; i
< tdev
.total_timvfs
; i
++) {
53 if (info
.domain
!= tdev
.rings
[i
].domain
) {
54 timvf_log_err("GRP error, vfid=%d/%d domain=%d/%d %p",
55 i
, tdev
.rings
[i
].vfid
,
56 info
.domain
, tdev
.rings
[i
].domain
,
62 tinfo
->total_timvfs
= tdev
.total_timvfs
;
63 tinfo
->domain
= info
.domain
;
68 timvf_bar(uint8_t id
, uint8_t bar
)
70 if (rte_eal_process_type() != RTE_PROC_PRIMARY
)
73 if (id
> tdev
.total_timvfs
)
78 return tdev
.rings
[id
].bar0
;
80 return tdev
.rings
[id
].bar4
;
87 timvf_probe(struct rte_pci_driver
*pci_drv
, struct rte_pci_device
*pci_dev
)
91 struct timvf_res
*res
;
93 RTE_SET_USED(pci_drv
);
95 /* For secondary processes, the primary has done all the work */
96 if (rte_eal_process_type() != RTE_PROC_PRIMARY
)
99 if (pci_dev
->mem_resource
[0].addr
== NULL
||
100 pci_dev
->mem_resource
[4].addr
== NULL
) {
101 timvf_log_err("Empty bars %p %p",
102 pci_dev
->mem_resource
[0].addr
,
103 pci_dev
->mem_resource
[4].addr
);
107 val
= rte_read64((uint8_t *)pci_dev
->mem_resource
[0].addr
+
108 0x100 /* TIM_VRINGX_BASE */);
109 vfid
= (val
>> 23) & 0xff;
110 if (vfid
>= TIM_MAX_RINGS
) {
111 timvf_log_err("Invalid vfid(%d/%d)", vfid
, TIM_MAX_RINGS
);
115 res
= &tdev
.rings
[tdev
.total_timvfs
];
117 res
->bar0
= pci_dev
->mem_resource
[0].addr
;
118 res
->bar2
= pci_dev
->mem_resource
[2].addr
;
119 res
->bar4
= pci_dev
->mem_resource
[4].addr
;
120 res
->domain
= (val
>> 7) & 0xffff;
124 timvf_log_dbg("Domain=%d VFid=%d bar0 %p total_timvfs=%d", res
->domain
,
125 res
->vfid
, pci_dev
->mem_resource
[0].addr
,
131 static const struct rte_pci_id pci_timvf_map
[] = {
133 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM
,
134 PCI_DEVICE_ID_OCTEONTX_TIM_VF
)
141 static struct rte_pci_driver pci_timvf
= {
142 .id_table
= pci_timvf_map
,
143 .drv_flags
= RTE_PCI_DRV_NEED_MAPPING
| RTE_PCI_DRV_IOVA_AS_VA
,
144 .probe
= timvf_probe
,
148 RTE_PMD_REGISTER_PCI(octeontx_timvf
, pci_timvf
);