xref: /dpdk/drivers/net/octeontx/base/octeontx_pkivf.c (revision a6d6f0afd0cc48c3a3c2568a971fd6b28daea2fa)
1aaf4363eSJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause
2aaf4363eSJerin Jacob  * Copyright(c) 2017 Cavium, Inc
3445371e8SJerin Jacob  */
4aaf4363eSJerin Jacob 
5445371e8SJerin Jacob #include <string.h>
6445371e8SJerin Jacob 
7445371e8SJerin Jacob #include <rte_eal.h>
8c752998bSGaetan Rivet #include <rte_bus_pci.h>
9445371e8SJerin Jacob 
10*a6d6f0afSPavan Nikhilesh #include "../octeontx_logs.h"
11*a6d6f0afSPavan Nikhilesh #include "octeontx_io.h"
12b95c3413SJerin Jacob #include "octeontx_pkivf.h"
13b95c3413SJerin Jacob 
14*a6d6f0afSPavan Nikhilesh 
15*a6d6f0afSPavan Nikhilesh struct octeontx_pkivf {
16*a6d6f0afSPavan Nikhilesh 	uint8_t		*bar0;
17*a6d6f0afSPavan Nikhilesh 	uint8_t		status;
18*a6d6f0afSPavan Nikhilesh 	uint16_t	domain;
19*a6d6f0afSPavan Nikhilesh 	uint16_t	vfid;
20*a6d6f0afSPavan Nikhilesh };
21*a6d6f0afSPavan Nikhilesh 
22*a6d6f0afSPavan Nikhilesh struct octeontx_pki_vf_ctl_s {
23*a6d6f0afSPavan Nikhilesh 	struct octeontx_pkivf pki[PKI_VF_MAX];
24*a6d6f0afSPavan Nikhilesh };
25*a6d6f0afSPavan Nikhilesh 
26*a6d6f0afSPavan Nikhilesh static struct octeontx_pki_vf_ctl_s pki_vf_ctl;
27*a6d6f0afSPavan Nikhilesh 
28b95c3413SJerin Jacob int
29b95c3413SJerin Jacob octeontx_pki_port_open(int port)
30b95c3413SJerin Jacob {
31*a6d6f0afSPavan Nikhilesh 	uint16_t global_domain = octeontx_get_global_domain();
32b95c3413SJerin Jacob 	struct octeontx_mbox_hdr hdr;
33*a6d6f0afSPavan Nikhilesh 	mbox_pki_port_t port_type = {
34*a6d6f0afSPavan Nikhilesh 		.port_type = OCTTX_PORT_TYPE_NET,
35*a6d6f0afSPavan Nikhilesh 	};
36*a6d6f0afSPavan Nikhilesh 	int i, res;
37*a6d6f0afSPavan Nikhilesh 
38*a6d6f0afSPavan Nikhilesh 	/* Check if atleast one PKI vf is in application domain. */
39*a6d6f0afSPavan Nikhilesh 	for (i = 0; i < PKI_VF_MAX; i++) {
40*a6d6f0afSPavan Nikhilesh 		if (pki_vf_ctl.pki[i].domain != global_domain)
41*a6d6f0afSPavan Nikhilesh 			continue;
42*a6d6f0afSPavan Nikhilesh 		break;
43*a6d6f0afSPavan Nikhilesh 	}
44*a6d6f0afSPavan Nikhilesh 
45*a6d6f0afSPavan Nikhilesh 	if (i == PKI_VF_MAX)
46*a6d6f0afSPavan Nikhilesh 		return -ENODEV;
47b95c3413SJerin Jacob 
48b95c3413SJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
49b95c3413SJerin Jacob 	hdr.msg = MBOX_PKI_PORT_OPEN;
50b95c3413SJerin Jacob 	hdr.vfid = port;
51b95c3413SJerin Jacob 
52*a6d6f0afSPavan Nikhilesh 	res = octeontx_mbox_send(&hdr, &port_type, sizeof(mbox_pki_port_t),
53*a6d6f0afSPavan Nikhilesh 				 NULL, 0);
54b95c3413SJerin Jacob 	if (res < 0)
55b95c3413SJerin Jacob 		return -EACCES;
56b95c3413SJerin Jacob 	return res;
57b95c3413SJerin Jacob }
58b95c3413SJerin Jacob 
59b95c3413SJerin Jacob int
606d28968eSJerin Jacob octeontx_pki_port_hash_config(int port, pki_hash_cfg_t *hash_cfg)
616d28968eSJerin Jacob {
626d28968eSJerin Jacob 	struct octeontx_mbox_hdr hdr;
636d28968eSJerin Jacob 	int res;
646d28968eSJerin Jacob 
656d28968eSJerin Jacob 	mbox_pki_hash_cfg_t h_cfg = *(mbox_pki_hash_cfg_t *)hash_cfg;
666d28968eSJerin Jacob 	int len = sizeof(mbox_pki_hash_cfg_t);
676d28968eSJerin Jacob 
686d28968eSJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
696d28968eSJerin Jacob 	hdr.msg = MBOX_PKI_PORT_HASH_CONFIG;
706d28968eSJerin Jacob 	hdr.vfid = port;
716d28968eSJerin Jacob 
72d8dd3165SPavan Nikhilesh 	res = octeontx_mbox_send(&hdr, &h_cfg, len, NULL, 0);
736d28968eSJerin Jacob 	if (res < 0)
746d28968eSJerin Jacob 		return -EACCES;
756d28968eSJerin Jacob 
766d28968eSJerin Jacob 	return res;
776d28968eSJerin Jacob }
786d28968eSJerin Jacob 
796d28968eSJerin Jacob int
806d28968eSJerin Jacob octeontx_pki_port_pktbuf_config(int port, pki_pktbuf_cfg_t *buf_cfg)
816d28968eSJerin Jacob {
826d28968eSJerin Jacob 	struct octeontx_mbox_hdr hdr;
836d28968eSJerin Jacob 	int res;
846d28968eSJerin Jacob 
856d28968eSJerin Jacob 	mbox_pki_pktbuf_cfg_t b_cfg = *(mbox_pki_pktbuf_cfg_t *)buf_cfg;
866d28968eSJerin Jacob 	int len = sizeof(mbox_pki_pktbuf_cfg_t);
876d28968eSJerin Jacob 
886d28968eSJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
896d28968eSJerin Jacob 	hdr.msg = MBOX_PKI_PORT_PKTBUF_CONFIG;
906d28968eSJerin Jacob 	hdr.vfid = port;
916d28968eSJerin Jacob 
92d8dd3165SPavan Nikhilesh 	res = octeontx_mbox_send(&hdr, &b_cfg, len, NULL, 0);
936d28968eSJerin Jacob 	if (res < 0)
946d28968eSJerin Jacob 		return -EACCES;
956d28968eSJerin Jacob 	return res;
966d28968eSJerin Jacob }
976d28968eSJerin Jacob 
986d28968eSJerin Jacob int
996d28968eSJerin Jacob octeontx_pki_port_create_qos(int port, pki_qos_cfg_t *qos_cfg)
1006d28968eSJerin Jacob {
1016d28968eSJerin Jacob 	struct octeontx_mbox_hdr hdr;
1026d28968eSJerin Jacob 	int res;
1036d28968eSJerin Jacob 
1046d28968eSJerin Jacob 	mbox_pki_qos_cfg_t q_cfg = *(mbox_pki_qos_cfg_t *)qos_cfg;
1056d28968eSJerin Jacob 	int len = sizeof(mbox_pki_qos_cfg_t);
1066d28968eSJerin Jacob 
1076d28968eSJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
1086d28968eSJerin Jacob 	hdr.msg = MBOX_PKI_PORT_CREATE_QOS;
1096d28968eSJerin Jacob 	hdr.vfid = port;
1106d28968eSJerin Jacob 
111d8dd3165SPavan Nikhilesh 	res = octeontx_mbox_send(&hdr, &q_cfg, len, NULL, 0);
1126d28968eSJerin Jacob 	if (res < 0)
1136d28968eSJerin Jacob 		return -EACCES;
1146d28968eSJerin Jacob 
1156d28968eSJerin Jacob 	return res;
1166d28968eSJerin Jacob }
1176d28968eSJerin Jacob 
118b95c3413SJerin Jacob 
1196d28968eSJerin Jacob int
1206d28968eSJerin Jacob octeontx_pki_port_errchk_config(int port, pki_errchk_cfg_t *cfg)
1216d28968eSJerin Jacob {
1226d28968eSJerin Jacob 	struct octeontx_mbox_hdr hdr;
1236d28968eSJerin Jacob 	int res;
1246d28968eSJerin Jacob 
1256d28968eSJerin Jacob 	mbox_pki_errcheck_cfg_t e_cfg;
1266d28968eSJerin Jacob 	e_cfg = *((mbox_pki_errcheck_cfg_t *)(cfg));
1276d28968eSJerin Jacob 	int len = sizeof(mbox_pki_errcheck_cfg_t);
1286d28968eSJerin Jacob 
1296d28968eSJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
1306d28968eSJerin Jacob 	hdr.msg = MBOX_PKI_PORT_ERRCHK_CONFIG;
1316d28968eSJerin Jacob 	hdr.vfid = port;
1326d28968eSJerin Jacob 
133d8dd3165SPavan Nikhilesh 	res = octeontx_mbox_send(&hdr, &e_cfg, len, NULL, 0);
1346d28968eSJerin Jacob 	if (res < 0)
1356d28968eSJerin Jacob 		return -EACCES;
1366d28968eSJerin Jacob 
1376d28968eSJerin Jacob 	return res;
1386d28968eSJerin Jacob }
1396d28968eSJerin Jacob 
140445371e8SJerin Jacob #define PCI_VENDOR_ID_CAVIUM               0x177D
141445371e8SJerin Jacob #define PCI_DEVICE_ID_OCTEONTX_PKI_VF      0xA0DD
142445371e8SJerin Jacob 
143445371e8SJerin Jacob /* PKIVF pcie device */
144445371e8SJerin Jacob static int
145445371e8SJerin Jacob pkivf_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
146445371e8SJerin Jacob {
147*a6d6f0afSPavan Nikhilesh 	struct octeontx_pkivf *res;
148*a6d6f0afSPavan Nikhilesh 	static uint8_t vf_cnt;
149*a6d6f0afSPavan Nikhilesh 	uint16_t domain;
150*a6d6f0afSPavan Nikhilesh 	uint16_t vfid;
151*a6d6f0afSPavan Nikhilesh 	uint8_t *bar0;
152*a6d6f0afSPavan Nikhilesh 	uint64_t val;
153445371e8SJerin Jacob 
154*a6d6f0afSPavan Nikhilesh 	RTE_SET_USED(pci_drv);
155445371e8SJerin Jacob 	/* For secondary processes, the primary has done all the work */
156445371e8SJerin Jacob 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
157445371e8SJerin Jacob 		return 0;
158445371e8SJerin Jacob 
159*a6d6f0afSPavan Nikhilesh 	if (pci_dev->mem_resource[0].addr == NULL) {
160*a6d6f0afSPavan Nikhilesh 		octeontx_log_err("PKI Empty bar[0] %p",
161*a6d6f0afSPavan Nikhilesh 				 pci_dev->mem_resource[0].addr);
162*a6d6f0afSPavan Nikhilesh 		return -ENODEV;
163*a6d6f0afSPavan Nikhilesh 	}
164*a6d6f0afSPavan Nikhilesh 
165*a6d6f0afSPavan Nikhilesh 	bar0 = pci_dev->mem_resource[0].addr;
166*a6d6f0afSPavan Nikhilesh 	val = octeontx_read64(bar0);
167*a6d6f0afSPavan Nikhilesh 	domain = val & 0xffff;
168*a6d6f0afSPavan Nikhilesh 	vfid = (val >> 16) & 0xffff;
169*a6d6f0afSPavan Nikhilesh 
170*a6d6f0afSPavan Nikhilesh 	if (unlikely(vfid >= PKI_VF_MAX)) {
171*a6d6f0afSPavan Nikhilesh 		octeontx_log_err("pki: Invalid vfid %d", vfid);
172*a6d6f0afSPavan Nikhilesh 		return -EINVAL;
173*a6d6f0afSPavan Nikhilesh 	}
174*a6d6f0afSPavan Nikhilesh 
175*a6d6f0afSPavan Nikhilesh 	res = &pki_vf_ctl.pki[vf_cnt++];
176*a6d6f0afSPavan Nikhilesh 	res->vfid = vfid;
177*a6d6f0afSPavan Nikhilesh 	res->domain = domain;
178*a6d6f0afSPavan Nikhilesh 	res->bar0 = bar0;
179*a6d6f0afSPavan Nikhilesh 
180*a6d6f0afSPavan Nikhilesh 	octeontx_log_dbg("PKI Domain=%d vfid=%d", res->domain, res->vfid);
181445371e8SJerin Jacob 	return 0;
182445371e8SJerin Jacob }
183445371e8SJerin Jacob 
184445371e8SJerin Jacob static const struct rte_pci_id pci_pkivf_map[] = {
185445371e8SJerin Jacob 	{
186445371e8SJerin Jacob 		RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
187445371e8SJerin Jacob 				PCI_DEVICE_ID_OCTEONTX_PKI_VF)
188445371e8SJerin Jacob 	},
189445371e8SJerin Jacob 	{
190445371e8SJerin Jacob 		.vendor_id = 0,
191445371e8SJerin Jacob 	},
192445371e8SJerin Jacob };
193445371e8SJerin Jacob 
194445371e8SJerin Jacob static struct rte_pci_driver pci_pkivf = {
195445371e8SJerin Jacob 	.id_table = pci_pkivf_map,
196445371e8SJerin Jacob 	.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
197445371e8SJerin Jacob 	.probe = pkivf_probe,
198445371e8SJerin Jacob };
199445371e8SJerin Jacob 
200445371e8SJerin Jacob RTE_PMD_REGISTER_PCI(octeontx_pkivf, pci_pkivf);
201