4 * Copyright (C) Cavium networks Ltd. 2017.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium networks nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <rte_atomic.h>
34 #include <rte_common.h>
39 #include "ssovf_evdev.h"
56 struct ssowvf_identify {
63 uint8_t total_ssowvfs;
64 struct ssovf_res grp[SSO_MAX_VHGRP];
65 struct ssowvf_res hws[SSO_MAX_VHWS];
68 static struct ssodev sdev;
70 /* Interface functions */
72 octeontx_ssovf_info(struct octeontx_ssovf_info *info)
77 if (rte_eal_process_type() != RTE_PROC_PRIMARY || info == NULL)
80 if (sdev.total_ssovfs == 0 || sdev.total_ssowvfs == 0)
83 domain = sdev.grp[0].domain;
84 for (i = 0; i < sdev.total_ssovfs; i++) {
85 /* Check vfid's are contiguous and belong to same domain */
86 if (sdev.grp[i].vfid != i ||
87 sdev.grp[i].bar0 == NULL ||
88 sdev.grp[i].domain != domain) {
89 ssovf_log_err("GRP error, vfid=%d/%d domain=%d/%d %p",
91 domain, sdev.grp[i].domain,
97 for (i = 0; i < sdev.total_ssowvfs; i++) {
98 /* Check vfid's are contiguous and belong to same domain */
99 if (sdev.hws[i].vfid != i ||
100 sdev.hws[i].bar0 == NULL ||
101 sdev.hws[i].domain != domain) {
102 ssovf_log_err("HWS error, vfid=%d/%d domain=%d/%d %p",
104 domain, sdev.hws[i].domain,
110 info->domain = domain;
111 info->total_ssovfs = sdev.total_ssovfs;
112 info->total_ssowvfs = sdev.total_ssowvfs;
117 octeontx_ssovf_bar(enum octeontx_ssovf_type type, uint8_t id, uint8_t bar)
119 if (rte_eal_process_type() != RTE_PROC_PRIMARY ||
120 type > OCTEONTX_SSO_HWS)
123 if (type == OCTEONTX_SSO_GROUP) {
124 if (id >= sdev.total_ssovfs)
127 if (id >= sdev.total_ssowvfs)
131 if (type == OCTEONTX_SSO_GROUP) {
134 return sdev.grp[id].bar0;
136 return sdev.grp[id].bar2;
143 return sdev.hws[id].bar0;
145 return sdev.hws[id].bar2;
147 return sdev.hws[id].bar4;
154 /* SSOWVF pcie device aka event port probe */
157 ssowvf_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
160 struct ssowvf_res *res;
161 struct ssowvf_identify *id;
163 RTE_SET_USED(pci_drv);
165 /* For secondary processes, the primary has done all the work */
166 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
169 if (pci_dev->mem_resource[0].addr == NULL ||
170 pci_dev->mem_resource[2].addr == NULL ||
171 pci_dev->mem_resource[4].addr == NULL) {
172 ssovf_log_err("Empty bars %p %p %p",
173 pci_dev->mem_resource[0].addr,
174 pci_dev->mem_resource[2].addr,
175 pci_dev->mem_resource[4].addr);
179 if (pci_dev->mem_resource[4].len != SSOW_BAR4_LEN) {
180 ssovf_log_err("Bar4 len mismatch %d != %d",
181 SSOW_BAR4_LEN, (int)pci_dev->mem_resource[4].len);
185 id = pci_dev->mem_resource[4].addr;
187 if (vfid >= SSO_MAX_VHWS) {
188 ssovf_log_err("Invalid vfid(%d/%d)", vfid, SSO_MAX_VHWS);
192 res = &sdev.hws[vfid];
194 res->bar0 = pci_dev->mem_resource[0].addr;
195 res->bar2 = pci_dev->mem_resource[2].addr;
196 res->bar4 = pci_dev->mem_resource[4].addr;
197 res->domain = id->domain;
199 sdev.total_ssowvfs++;
201 ssovf_log_dbg("Domain=%d hws=%d total_ssowvfs=%d", res->domain,
202 res->vfid, sdev.total_ssowvfs);
206 static const struct rte_pci_id pci_ssowvf_map[] = {
208 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
209 PCI_DEVICE_ID_OCTEONTX_SSOWS_VF)
216 static struct rte_pci_driver pci_ssowvf = {
217 .id_table = pci_ssowvf_map,
218 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
219 .probe = ssowvf_probe,
222 RTE_PMD_REGISTER_PCI(octeontx_ssowvf, pci_ssowvf);
224 /* SSOVF pcie device aka event queue probe */
227 ssovf_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
232 struct ssovf_res *res;
234 RTE_SET_USED(pci_drv);
236 /* For secondary processes, the primary has done all the work */
237 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
240 if (pci_dev->mem_resource[0].addr == NULL ||
241 pci_dev->mem_resource[2].addr == NULL) {
242 ssovf_log_err("Empty bars %p %p",
243 pci_dev->mem_resource[0].addr,
244 pci_dev->mem_resource[2].addr);
247 idreg = pci_dev->mem_resource[0].addr;
248 idreg += SSO_VHGRP_AQ_THR;
249 val = rte_read64(idreg);
251 /* Write back the default value of aq_thr */
252 rte_write64((1ULL << 33) - 1, idreg);
253 vfid = (val >> 16) & 0xffff;
254 if (vfid >= SSO_MAX_VHGRP) {
255 ssovf_log_err("Invalid vfid (%d/%d)", vfid, SSO_MAX_VHGRP);
259 res = &sdev.grp[vfid];
261 res->bar0 = pci_dev->mem_resource[0].addr;
262 res->bar2 = pci_dev->mem_resource[2].addr;
263 res->domain = val & 0xffff;
267 ssovf_log_dbg("Domain=%d group=%d total_ssovfs=%d", res->domain,
268 res->vfid, sdev.total_ssovfs);
272 static const struct rte_pci_id pci_ssovf_map[] = {
274 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
275 PCI_DEVICE_ID_OCTEONTX_SSOGRP_VF)
282 static struct rte_pci_driver pci_ssovf = {
283 .id_table = pci_ssovf_map,
284 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
285 .probe = ssovf_probe,
288 RTE_PMD_REGISTER_PCI(octeontx_ssovf, pci_ssovf);