1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
5 #include <rte_atomic.h>
6 #include <rte_common.h>
10 #include <rte_bus_pci.h>
12 #include "octeontx_mbox.h"
13 #include "ssovf_evdev.h"
15 #define PCI_VENDOR_ID_CAVIUM 0x177D
16 #define PCI_DEVICE_ID_OCTEONTX_SSOGRP_VF 0xA04B
17 #define PCI_DEVICE_ID_OCTEONTX_SSOWS_VF 0xA04D
19 #define SSO_MAX_VHGRP (64)
20 #define SSO_MAX_VHWS (32)
22 #define SSO_VHGRP_AQ_THR (0x1E0ULL)
39 struct ssowvf_identify {
46 uint8_t total_ssowvfs;
47 struct ssovf_res grp[SSO_MAX_VHGRP];
48 struct ssowvf_res hws[SSO_MAX_VHWS];
51 static struct ssodev sdev;
53 /* Interface functions */
55 ssovf_info(struct ssovf_info *info)
60 if (rte_eal_process_type() != RTE_PROC_PRIMARY || info == NULL)
63 if (sdev.total_ssovfs == 0 || sdev.total_ssowvfs == 0)
66 domain = sdev.grp[0].domain;
67 for (i = 0; i < sdev.total_ssovfs; i++) {
68 /* Check vfid's are contiguous and belong to same domain */
69 if (sdev.grp[i].vfid != i ||
70 sdev.grp[i].bar0 == NULL ||
71 sdev.grp[i].domain != domain) {
72 mbox_log_err("GRP error, vfid=%d/%d domain=%d/%d %p",
74 domain, sdev.grp[i].domain,
80 for (i = 0; i < sdev.total_ssowvfs; i++) {
81 /* Check vfid's are contiguous and belong to same domain */
82 if (sdev.hws[i].vfid != i ||
83 sdev.hws[i].bar0 == NULL ||
84 sdev.hws[i].domain != domain) {
85 mbox_log_err("HWS error, vfid=%d/%d domain=%d/%d %p",
87 domain, sdev.hws[i].domain,
93 info->domain = domain;
94 info->total_ssovfs = sdev.total_ssovfs;
95 info->total_ssowvfs = sdev.total_ssowvfs;
100 ssovf_bar(enum ssovf_type type, uint8_t id, uint8_t bar)
102 if (rte_eal_process_type() != RTE_PROC_PRIMARY ||
103 type > OCTEONTX_SSO_HWS)
106 if (type == OCTEONTX_SSO_GROUP) {
107 if (id >= sdev.total_ssovfs)
110 if (id >= sdev.total_ssowvfs)
114 if (type == OCTEONTX_SSO_GROUP) {
117 return sdev.grp[id].bar0;
119 return sdev.grp[id].bar2;
126 return sdev.hws[id].bar0;
128 return sdev.hws[id].bar2;
130 return sdev.hws[id].bar4;
137 /* SSOWVF pcie device aka event port probe */
140 ssowvf_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
143 struct ssowvf_res *res;
144 struct ssowvf_identify *id;
145 uint8_t *ram_mbox_base;
147 RTE_SET_USED(pci_drv);
149 /* For secondary processes, the primary has done all the work */
150 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
153 if (pci_dev->mem_resource[0].addr == NULL ||
154 pci_dev->mem_resource[2].addr == NULL ||
155 pci_dev->mem_resource[4].addr == NULL) {
156 mbox_log_err("Empty bars %p %p %p",
157 pci_dev->mem_resource[0].addr,
158 pci_dev->mem_resource[2].addr,
159 pci_dev->mem_resource[4].addr);
163 if (pci_dev->mem_resource[4].len != SSOW_BAR4_LEN) {
164 mbox_log_err("Bar4 len mismatch %d != %d",
165 SSOW_BAR4_LEN, (int)pci_dev->mem_resource[4].len);
169 id = pci_dev->mem_resource[4].addr;
171 if (vfid >= SSO_MAX_VHWS) {
172 mbox_log_err("Invalid vfid(%d/%d)", vfid, SSO_MAX_VHWS);
176 res = &sdev.hws[vfid];
178 res->bar0 = pci_dev->mem_resource[0].addr;
179 res->bar2 = pci_dev->mem_resource[2].addr;
180 res->bar4 = pci_dev->mem_resource[4].addr;
181 res->domain = id->domain;
183 sdev.total_ssowvfs++;
185 ram_mbox_base = ssovf_bar(OCTEONTX_SSO_HWS, 0, 4);
186 if (octeontx_mbox_set_ram_mbox_base(ram_mbox_base)) {
187 mbox_log_err("Invalid Failed to set ram mbox base");
193 mbox_log_dbg("Domain=%d hws=%d total_ssowvfs=%d", res->domain,
194 res->vfid, sdev.total_ssowvfs);
198 static const struct rte_pci_id pci_ssowvf_map[] = {
200 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
201 PCI_DEVICE_ID_OCTEONTX_SSOWS_VF)
208 static struct rte_pci_driver pci_ssowvf = {
209 .id_table = pci_ssowvf_map,
210 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
211 .probe = ssowvf_probe,
214 RTE_PMD_REGISTER_PCI(octeontx_ssowvf, pci_ssowvf);
216 /* SSOVF pcie device aka event queue probe */
219 ssovf_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
224 struct ssovf_res *res;
227 RTE_SET_USED(pci_drv);
229 /* For secondary processes, the primary has done all the work */
230 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
233 if (pci_dev->mem_resource[0].addr == NULL ||
234 pci_dev->mem_resource[2].addr == NULL) {
235 mbox_log_err("Empty bars %p %p",
236 pci_dev->mem_resource[0].addr,
237 pci_dev->mem_resource[2].addr);
240 idreg = pci_dev->mem_resource[0].addr;
241 idreg += SSO_VHGRP_AQ_THR;
242 val = rte_read64(idreg);
244 /* Write back the default value of aq_thr */
245 rte_write64((1ULL << 33) - 1, idreg);
246 vfid = (val >> 16) & 0xffff;
247 if (vfid >= SSO_MAX_VHGRP) {
248 mbox_log_err("Invalid vfid (%d/%d)", vfid, SSO_MAX_VHGRP);
252 res = &sdev.grp[vfid];
254 res->bar0 = pci_dev->mem_resource[0].addr;
255 res->bar2 = pci_dev->mem_resource[2].addr;
256 res->domain = val & 0xffff;
260 reg = ssovf_bar(OCTEONTX_SSO_GROUP, 0, 0);
261 reg += SSO_VHGRP_PF_MBOX(1);
262 if (octeontx_mbox_set_reg(reg)) {
263 mbox_log_err("Invalid Failed to set mbox_reg");
269 mbox_log_dbg("Domain=%d group=%d total_ssovfs=%d", res->domain,
270 res->vfid, sdev.total_ssovfs);
274 static const struct rte_pci_id pci_ssovf_map[] = {
276 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
277 PCI_DEVICE_ID_OCTEONTX_SSOGRP_VF)
284 static struct rte_pci_driver pci_ssovf = {
285 .id_table = pci_ssovf_map,
286 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
287 .probe = ssovf_probe,
290 RTE_PMD_REGISTER_PCI(octeontx_ssovf, pci_ssovf);