xref: /dpdk/drivers/net/octeontx/base/octeontx_pkivf.c (revision aaf4363e1e9e518c034c7ff9938a2faefde9854d)
1*aaf4363eSJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause
2*aaf4363eSJerin Jacob  * Copyright(c) 2017 Cavium, Inc
3445371e8SJerin Jacob  */
4*aaf4363eSJerin Jacob 
5445371e8SJerin Jacob #include <string.h>
6445371e8SJerin Jacob 
7445371e8SJerin Jacob #include <rte_eal.h>
8c752998bSGaetan Rivet #include <rte_bus_pci.h>
9445371e8SJerin Jacob 
10b95c3413SJerin Jacob #include "octeontx_pkivf.h"
11b95c3413SJerin Jacob 
12b95c3413SJerin Jacob int
13b95c3413SJerin Jacob octeontx_pki_port_open(int port)
14b95c3413SJerin Jacob {
15b95c3413SJerin Jacob 	struct octeontx_mbox_hdr hdr;
16b95c3413SJerin Jacob 	int res;
17b95c3413SJerin Jacob 
18b95c3413SJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
19b95c3413SJerin Jacob 	hdr.msg = MBOX_PKI_PORT_OPEN;
20b95c3413SJerin Jacob 	hdr.vfid = port;
21b95c3413SJerin Jacob 
22b95c3413SJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0);
23b95c3413SJerin Jacob 	if (res < 0)
24b95c3413SJerin Jacob 		return -EACCES;
25b95c3413SJerin Jacob 	return res;
26b95c3413SJerin Jacob }
27b95c3413SJerin Jacob 
28b95c3413SJerin Jacob int
296d28968eSJerin Jacob octeontx_pki_port_hash_config(int port, pki_hash_cfg_t *hash_cfg)
306d28968eSJerin Jacob {
316d28968eSJerin Jacob 	struct octeontx_mbox_hdr hdr;
326d28968eSJerin Jacob 	int res;
336d28968eSJerin Jacob 
346d28968eSJerin Jacob 	mbox_pki_hash_cfg_t h_cfg = *(mbox_pki_hash_cfg_t *)hash_cfg;
356d28968eSJerin Jacob 	int len = sizeof(mbox_pki_hash_cfg_t);
366d28968eSJerin Jacob 
376d28968eSJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
386d28968eSJerin Jacob 	hdr.msg = MBOX_PKI_PORT_HASH_CONFIG;
396d28968eSJerin Jacob 	hdr.vfid = port;
406d28968eSJerin Jacob 
416d28968eSJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, &h_cfg, len, NULL, 0);
426d28968eSJerin Jacob 	if (res < 0)
436d28968eSJerin Jacob 		return -EACCES;
446d28968eSJerin Jacob 
456d28968eSJerin Jacob 	return res;
466d28968eSJerin Jacob }
476d28968eSJerin Jacob 
486d28968eSJerin Jacob int
496d28968eSJerin Jacob octeontx_pki_port_pktbuf_config(int port, pki_pktbuf_cfg_t *buf_cfg)
506d28968eSJerin Jacob {
516d28968eSJerin Jacob 	struct octeontx_mbox_hdr hdr;
526d28968eSJerin Jacob 	int res;
536d28968eSJerin Jacob 
546d28968eSJerin Jacob 	mbox_pki_pktbuf_cfg_t b_cfg = *(mbox_pki_pktbuf_cfg_t *)buf_cfg;
556d28968eSJerin Jacob 	int len = sizeof(mbox_pki_pktbuf_cfg_t);
566d28968eSJerin Jacob 
576d28968eSJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
586d28968eSJerin Jacob 	hdr.msg = MBOX_PKI_PORT_PKTBUF_CONFIG;
596d28968eSJerin Jacob 	hdr.vfid = port;
606d28968eSJerin Jacob 
616d28968eSJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, &b_cfg, len, NULL, 0);
626d28968eSJerin Jacob 	if (res < 0)
636d28968eSJerin Jacob 		return -EACCES;
646d28968eSJerin Jacob 	return res;
656d28968eSJerin Jacob }
666d28968eSJerin Jacob 
676d28968eSJerin Jacob int
686d28968eSJerin Jacob octeontx_pki_port_create_qos(int port, pki_qos_cfg_t *qos_cfg)
696d28968eSJerin Jacob {
706d28968eSJerin Jacob 	struct octeontx_mbox_hdr hdr;
716d28968eSJerin Jacob 	int res;
726d28968eSJerin Jacob 
736d28968eSJerin Jacob 	mbox_pki_qos_cfg_t q_cfg = *(mbox_pki_qos_cfg_t *)qos_cfg;
746d28968eSJerin Jacob 	int len = sizeof(mbox_pki_qos_cfg_t);
756d28968eSJerin Jacob 
766d28968eSJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
776d28968eSJerin Jacob 	hdr.msg = MBOX_PKI_PORT_CREATE_QOS;
786d28968eSJerin Jacob 	hdr.vfid = port;
796d28968eSJerin Jacob 
806d28968eSJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, &q_cfg, len, NULL, 0);
816d28968eSJerin Jacob 	if (res < 0)
826d28968eSJerin Jacob 		return -EACCES;
836d28968eSJerin Jacob 
846d28968eSJerin Jacob 	return res;
856d28968eSJerin Jacob }
866d28968eSJerin Jacob 
87b95c3413SJerin Jacob 
886d28968eSJerin Jacob int
896d28968eSJerin Jacob octeontx_pki_port_errchk_config(int port, pki_errchk_cfg_t *cfg)
906d28968eSJerin Jacob {
916d28968eSJerin Jacob 	struct octeontx_mbox_hdr hdr;
926d28968eSJerin Jacob 	int res;
936d28968eSJerin Jacob 
946d28968eSJerin Jacob 	mbox_pki_errcheck_cfg_t e_cfg;
956d28968eSJerin Jacob 	e_cfg = *((mbox_pki_errcheck_cfg_t *)(cfg));
966d28968eSJerin Jacob 	int len = sizeof(mbox_pki_errcheck_cfg_t);
976d28968eSJerin Jacob 
986d28968eSJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
996d28968eSJerin Jacob 	hdr.msg = MBOX_PKI_PORT_ERRCHK_CONFIG;
1006d28968eSJerin Jacob 	hdr.vfid = port;
1016d28968eSJerin Jacob 
1026d28968eSJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, &e_cfg, len, NULL, 0);
1036d28968eSJerin Jacob 	if (res < 0)
1046d28968eSJerin Jacob 		return -EACCES;
1056d28968eSJerin Jacob 
1066d28968eSJerin Jacob 	return res;
1076d28968eSJerin Jacob }
1086d28968eSJerin Jacob 
109445371e8SJerin Jacob #define PCI_VENDOR_ID_CAVIUM               0x177D
110445371e8SJerin Jacob #define PCI_DEVICE_ID_OCTEONTX_PKI_VF      0xA0DD
111445371e8SJerin Jacob 
112445371e8SJerin Jacob /* PKIVF pcie device */
113445371e8SJerin Jacob static int
114445371e8SJerin Jacob pkivf_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
115445371e8SJerin Jacob {
116445371e8SJerin Jacob 	RTE_SET_USED(pci_drv);
117445371e8SJerin Jacob 	RTE_SET_USED(pci_dev);
118445371e8SJerin Jacob 
119445371e8SJerin Jacob 	/* For secondary processes, the primary has done all the work */
120445371e8SJerin Jacob 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
121445371e8SJerin Jacob 		return 0;
122445371e8SJerin Jacob 
123445371e8SJerin Jacob 	return 0;
124445371e8SJerin Jacob }
125445371e8SJerin Jacob 
126445371e8SJerin Jacob static const struct rte_pci_id pci_pkivf_map[] = {
127445371e8SJerin Jacob 	{
128445371e8SJerin Jacob 		RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
129445371e8SJerin Jacob 				PCI_DEVICE_ID_OCTEONTX_PKI_VF)
130445371e8SJerin Jacob 	},
131445371e8SJerin Jacob 	{
132445371e8SJerin Jacob 		.vendor_id = 0,
133445371e8SJerin Jacob 	},
134445371e8SJerin Jacob };
135445371e8SJerin Jacob 
136445371e8SJerin Jacob static struct rte_pci_driver pci_pkivf = {
137445371e8SJerin Jacob 	.id_table = pci_pkivf_map,
138445371e8SJerin Jacob 	.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
139445371e8SJerin Jacob 	.probe = pkivf_probe,
140445371e8SJerin Jacob };
141445371e8SJerin Jacob 
142445371e8SJerin Jacob RTE_PMD_REGISTER_PCI(octeontx_pkivf, pci_pkivf);
143