xref: /dpdk/drivers/net/octeontx/base/octeontx_pkivf.c (revision 6d28968ed16fd47e158c69b14d35512066becd09)
1445371e8SJerin Jacob /*
2445371e8SJerin Jacob  *   BSD LICENSE
3445371e8SJerin Jacob  *
4445371e8SJerin Jacob  *   Copyright (C) Cavium Inc. 2017. All rights reserved.
5445371e8SJerin Jacob  *
6445371e8SJerin Jacob  *   Redistribution and use in source and binary forms, with or without
7445371e8SJerin Jacob  *   modification, are permitted provided that the following conditions
8445371e8SJerin Jacob  *   are met:
9445371e8SJerin Jacob  *
10445371e8SJerin Jacob  *     * Redistributions of source code must retain the above copyright
11445371e8SJerin Jacob  *       notice, this list of conditions and the following disclaimer.
12445371e8SJerin Jacob  *     * Redistributions in binary form must reproduce the above copyright
13445371e8SJerin Jacob  *       notice, this list of conditions and the following disclaimer in
14445371e8SJerin Jacob  *       the documentation and/or other materials provided with the
15445371e8SJerin Jacob  *       distribution.
16445371e8SJerin Jacob  *     * Neither the name of Cavium networks nor the names of its
17445371e8SJerin Jacob  *       contributors may be used to endorse or promote products derived
18445371e8SJerin Jacob  *       from this software without specific prior written permission.
19445371e8SJerin Jacob  *
20445371e8SJerin Jacob  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21445371e8SJerin Jacob  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22445371e8SJerin Jacob  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23445371e8SJerin Jacob  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24445371e8SJerin Jacob  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25445371e8SJerin Jacob  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26445371e8SJerin Jacob  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27445371e8SJerin Jacob  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28445371e8SJerin Jacob  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29445371e8SJerin Jacob  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30445371e8SJerin Jacob  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31445371e8SJerin Jacob  */
32445371e8SJerin Jacob #include <string.h>
33445371e8SJerin Jacob 
34445371e8SJerin Jacob #include <rte_eal.h>
35445371e8SJerin Jacob #include <rte_pci.h>
36445371e8SJerin Jacob 
37b95c3413SJerin Jacob #include "octeontx_pkivf.h"
38b95c3413SJerin Jacob 
39b95c3413SJerin Jacob int
40b95c3413SJerin Jacob octeontx_pki_port_open(int port)
41b95c3413SJerin Jacob {
42b95c3413SJerin Jacob 	struct octeontx_mbox_hdr hdr;
43b95c3413SJerin Jacob 	int res;
44b95c3413SJerin Jacob 
45b95c3413SJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
46b95c3413SJerin Jacob 	hdr.msg = MBOX_PKI_PORT_OPEN;
47b95c3413SJerin Jacob 	hdr.vfid = port;
48b95c3413SJerin Jacob 
49b95c3413SJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0);
50b95c3413SJerin Jacob 	if (res < 0)
51b95c3413SJerin Jacob 		return -EACCES;
52b95c3413SJerin Jacob 	return res;
53b95c3413SJerin Jacob }
54b95c3413SJerin Jacob 
55b95c3413SJerin Jacob int
56*6d28968eSJerin Jacob octeontx_pki_port_hash_config(int port, pki_hash_cfg_t *hash_cfg)
57*6d28968eSJerin Jacob {
58*6d28968eSJerin Jacob 	struct octeontx_mbox_hdr hdr;
59*6d28968eSJerin Jacob 	int res;
60*6d28968eSJerin Jacob 
61*6d28968eSJerin Jacob 	mbox_pki_hash_cfg_t h_cfg = *(mbox_pki_hash_cfg_t *)hash_cfg;
62*6d28968eSJerin Jacob 	int len = sizeof(mbox_pki_hash_cfg_t);
63*6d28968eSJerin Jacob 
64*6d28968eSJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
65*6d28968eSJerin Jacob 	hdr.msg = MBOX_PKI_PORT_HASH_CONFIG;
66*6d28968eSJerin Jacob 	hdr.vfid = port;
67*6d28968eSJerin Jacob 
68*6d28968eSJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, &h_cfg, len, NULL, 0);
69*6d28968eSJerin Jacob 	if (res < 0)
70*6d28968eSJerin Jacob 		return -EACCES;
71*6d28968eSJerin Jacob 
72*6d28968eSJerin Jacob 	return res;
73*6d28968eSJerin Jacob }
74*6d28968eSJerin Jacob 
75*6d28968eSJerin Jacob int
76*6d28968eSJerin Jacob octeontx_pki_port_pktbuf_config(int port, pki_pktbuf_cfg_t *buf_cfg)
77*6d28968eSJerin Jacob {
78*6d28968eSJerin Jacob 	struct octeontx_mbox_hdr hdr;
79*6d28968eSJerin Jacob 	int res;
80*6d28968eSJerin Jacob 
81*6d28968eSJerin Jacob 	mbox_pki_pktbuf_cfg_t b_cfg = *(mbox_pki_pktbuf_cfg_t *)buf_cfg;
82*6d28968eSJerin Jacob 	int len = sizeof(mbox_pki_pktbuf_cfg_t);
83*6d28968eSJerin Jacob 
84*6d28968eSJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
85*6d28968eSJerin Jacob 	hdr.msg = MBOX_PKI_PORT_PKTBUF_CONFIG;
86*6d28968eSJerin Jacob 	hdr.vfid = port;
87*6d28968eSJerin Jacob 
88*6d28968eSJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, &b_cfg, len, NULL, 0);
89*6d28968eSJerin Jacob 	if (res < 0)
90*6d28968eSJerin Jacob 		return -EACCES;
91*6d28968eSJerin Jacob 	return res;
92*6d28968eSJerin Jacob }
93*6d28968eSJerin Jacob 
94*6d28968eSJerin Jacob int
95*6d28968eSJerin Jacob octeontx_pki_port_create_qos(int port, pki_qos_cfg_t *qos_cfg)
96*6d28968eSJerin Jacob {
97*6d28968eSJerin Jacob 	struct octeontx_mbox_hdr hdr;
98*6d28968eSJerin Jacob 	int res;
99*6d28968eSJerin Jacob 
100*6d28968eSJerin Jacob 	mbox_pki_qos_cfg_t q_cfg = *(mbox_pki_qos_cfg_t *)qos_cfg;
101*6d28968eSJerin Jacob 	int len = sizeof(mbox_pki_qos_cfg_t);
102*6d28968eSJerin Jacob 
103*6d28968eSJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
104*6d28968eSJerin Jacob 	hdr.msg = MBOX_PKI_PORT_CREATE_QOS;
105*6d28968eSJerin Jacob 	hdr.vfid = port;
106*6d28968eSJerin Jacob 
107*6d28968eSJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, &q_cfg, len, NULL, 0);
108*6d28968eSJerin Jacob 	if (res < 0)
109*6d28968eSJerin Jacob 		return -EACCES;
110*6d28968eSJerin Jacob 
111*6d28968eSJerin Jacob 	return res;
112*6d28968eSJerin Jacob }
113*6d28968eSJerin Jacob 
114*6d28968eSJerin Jacob int
115b95c3413SJerin Jacob octeontx_pki_port_close(int port)
116b95c3413SJerin Jacob {
117b95c3413SJerin Jacob 	struct octeontx_mbox_hdr hdr;
118b95c3413SJerin Jacob 	int res;
119b95c3413SJerin Jacob 
120b95c3413SJerin Jacob 	mbox_pki_port_t ptype;
121b95c3413SJerin Jacob 	int len = sizeof(mbox_pki_port_t);
122b95c3413SJerin Jacob 	memset(&ptype, 0, len);
123b95c3413SJerin Jacob 	ptype.port_type = OCTTX_PORT_TYPE_NET;
124b95c3413SJerin Jacob 
125b95c3413SJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
126b95c3413SJerin Jacob 	hdr.msg = MBOX_PKI_PORT_CLOSE;
127b95c3413SJerin Jacob 	hdr.vfid = port;
128b95c3413SJerin Jacob 
129b95c3413SJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, &ptype, len, NULL, 0);
130b95c3413SJerin Jacob 	if (res < 0)
131b95c3413SJerin Jacob 		return -EACCES;
132b95c3413SJerin Jacob 
133b95c3413SJerin Jacob 	return res;
134b95c3413SJerin Jacob }
135b95c3413SJerin Jacob 
136b95c3413SJerin Jacob int
137b95c3413SJerin Jacob octeontx_pki_port_start(int port)
138b95c3413SJerin Jacob {
139b95c3413SJerin Jacob 	struct octeontx_mbox_hdr hdr;
140b95c3413SJerin Jacob 	int res;
141b95c3413SJerin Jacob 
142b95c3413SJerin Jacob 	mbox_pki_port_t ptype;
143b95c3413SJerin Jacob 	int len = sizeof(mbox_pki_port_t);
144b95c3413SJerin Jacob 	memset(&ptype, 0, len);
145b95c3413SJerin Jacob 	ptype.port_type = OCTTX_PORT_TYPE_NET;
146b95c3413SJerin Jacob 
147b95c3413SJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
148b95c3413SJerin Jacob 	hdr.msg = MBOX_PKI_PORT_START;
149b95c3413SJerin Jacob 	hdr.vfid = port;
150b95c3413SJerin Jacob 
151b95c3413SJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, &ptype, len, NULL, 0);
152b95c3413SJerin Jacob 	if (res < 0)
153b95c3413SJerin Jacob 		return -EACCES;
154b95c3413SJerin Jacob 
155b95c3413SJerin Jacob 	return res;
156b95c3413SJerin Jacob }
157b95c3413SJerin Jacob 
158b95c3413SJerin Jacob int
159b95c3413SJerin Jacob octeontx_pki_port_stop(int port)
160b95c3413SJerin Jacob {
161b95c3413SJerin Jacob 	struct octeontx_mbox_hdr hdr;
162b95c3413SJerin Jacob 	int res;
163b95c3413SJerin Jacob 
164b95c3413SJerin Jacob 	mbox_pki_port_t ptype;
165b95c3413SJerin Jacob 	int len = sizeof(mbox_pki_port_t);
166b95c3413SJerin Jacob 	memset(&ptype, 0, len);
167b95c3413SJerin Jacob 	ptype.port_type = OCTTX_PORT_TYPE_NET;
168b95c3413SJerin Jacob 
169b95c3413SJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
170b95c3413SJerin Jacob 	hdr.msg = MBOX_PKI_PORT_STOP;
171b95c3413SJerin Jacob 	hdr.vfid = port;
172b95c3413SJerin Jacob 
173b95c3413SJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, &ptype, len, NULL, 0);
174b95c3413SJerin Jacob 	if (res < 0)
175b95c3413SJerin Jacob 		return -EACCES;
176b95c3413SJerin Jacob 
177b95c3413SJerin Jacob 	return res;
178b95c3413SJerin Jacob }
179b95c3413SJerin Jacob 
180*6d28968eSJerin Jacob int
181*6d28968eSJerin Jacob octeontx_pki_port_errchk_config(int port, pki_errchk_cfg_t *cfg)
182*6d28968eSJerin Jacob {
183*6d28968eSJerin Jacob 	struct octeontx_mbox_hdr hdr;
184*6d28968eSJerin Jacob 	int res;
185*6d28968eSJerin Jacob 
186*6d28968eSJerin Jacob 	mbox_pki_errcheck_cfg_t e_cfg;
187*6d28968eSJerin Jacob 	e_cfg = *((mbox_pki_errcheck_cfg_t *)(cfg));
188*6d28968eSJerin Jacob 	int len = sizeof(mbox_pki_errcheck_cfg_t);
189*6d28968eSJerin Jacob 
190*6d28968eSJerin Jacob 	hdr.coproc = OCTEONTX_PKI_COPROC;
191*6d28968eSJerin Jacob 	hdr.msg = MBOX_PKI_PORT_ERRCHK_CONFIG;
192*6d28968eSJerin Jacob 	hdr.vfid = port;
193*6d28968eSJerin Jacob 
194*6d28968eSJerin Jacob 	res = octeontx_ssovf_mbox_send(&hdr, &e_cfg, len, NULL, 0);
195*6d28968eSJerin Jacob 	if (res < 0)
196*6d28968eSJerin Jacob 		return -EACCES;
197*6d28968eSJerin Jacob 
198*6d28968eSJerin Jacob 	return res;
199*6d28968eSJerin Jacob }
200*6d28968eSJerin Jacob 
201445371e8SJerin Jacob #define PCI_VENDOR_ID_CAVIUM               0x177D
202445371e8SJerin Jacob #define PCI_DEVICE_ID_OCTEONTX_PKI_VF      0xA0DD
203445371e8SJerin Jacob 
204445371e8SJerin Jacob /* PKIVF pcie device */
205445371e8SJerin Jacob static int
206445371e8SJerin Jacob pkivf_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
207445371e8SJerin Jacob {
208445371e8SJerin Jacob 	RTE_SET_USED(pci_drv);
209445371e8SJerin Jacob 	RTE_SET_USED(pci_dev);
210445371e8SJerin Jacob 
211445371e8SJerin Jacob 	/* For secondary processes, the primary has done all the work */
212445371e8SJerin Jacob 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
213445371e8SJerin Jacob 		return 0;
214445371e8SJerin Jacob 
215445371e8SJerin Jacob 	return 0;
216445371e8SJerin Jacob }
217445371e8SJerin Jacob 
218445371e8SJerin Jacob static const struct rte_pci_id pci_pkivf_map[] = {
219445371e8SJerin Jacob 	{
220445371e8SJerin Jacob 		RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM,
221445371e8SJerin Jacob 				PCI_DEVICE_ID_OCTEONTX_PKI_VF)
222445371e8SJerin Jacob 	},
223445371e8SJerin Jacob 	{
224445371e8SJerin Jacob 		.vendor_id = 0,
225445371e8SJerin Jacob 	},
226445371e8SJerin Jacob };
227445371e8SJerin Jacob 
228445371e8SJerin Jacob static struct rte_pci_driver pci_pkivf = {
229445371e8SJerin Jacob 	.id_table = pci_pkivf_map,
230445371e8SJerin Jacob 	.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
231445371e8SJerin Jacob 	.probe = pkivf_probe,
232445371e8SJerin Jacob };
233445371e8SJerin Jacob 
234445371e8SJerin Jacob RTE_PMD_REGISTER_PCI(octeontx_pkivf, pci_pkivf);
235