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> 35*c752998bSGaetan Rivet #include <rte_bus_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 566d28968eSJerin Jacob octeontx_pki_port_hash_config(int port, pki_hash_cfg_t *hash_cfg) 576d28968eSJerin Jacob { 586d28968eSJerin Jacob struct octeontx_mbox_hdr hdr; 596d28968eSJerin Jacob int res; 606d28968eSJerin Jacob 616d28968eSJerin Jacob mbox_pki_hash_cfg_t h_cfg = *(mbox_pki_hash_cfg_t *)hash_cfg; 626d28968eSJerin Jacob int len = sizeof(mbox_pki_hash_cfg_t); 636d28968eSJerin Jacob 646d28968eSJerin Jacob hdr.coproc = OCTEONTX_PKI_COPROC; 656d28968eSJerin Jacob hdr.msg = MBOX_PKI_PORT_HASH_CONFIG; 666d28968eSJerin Jacob hdr.vfid = port; 676d28968eSJerin Jacob 686d28968eSJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, &h_cfg, len, NULL, 0); 696d28968eSJerin Jacob if (res < 0) 706d28968eSJerin Jacob return -EACCES; 716d28968eSJerin Jacob 726d28968eSJerin Jacob return res; 736d28968eSJerin Jacob } 746d28968eSJerin Jacob 756d28968eSJerin Jacob int 766d28968eSJerin Jacob octeontx_pki_port_pktbuf_config(int port, pki_pktbuf_cfg_t *buf_cfg) 776d28968eSJerin Jacob { 786d28968eSJerin Jacob struct octeontx_mbox_hdr hdr; 796d28968eSJerin Jacob int res; 806d28968eSJerin Jacob 816d28968eSJerin Jacob mbox_pki_pktbuf_cfg_t b_cfg = *(mbox_pki_pktbuf_cfg_t *)buf_cfg; 826d28968eSJerin Jacob int len = sizeof(mbox_pki_pktbuf_cfg_t); 836d28968eSJerin Jacob 846d28968eSJerin Jacob hdr.coproc = OCTEONTX_PKI_COPROC; 856d28968eSJerin Jacob hdr.msg = MBOX_PKI_PORT_PKTBUF_CONFIG; 866d28968eSJerin Jacob hdr.vfid = port; 876d28968eSJerin Jacob 886d28968eSJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, &b_cfg, len, NULL, 0); 896d28968eSJerin Jacob if (res < 0) 906d28968eSJerin Jacob return -EACCES; 916d28968eSJerin Jacob return res; 926d28968eSJerin Jacob } 936d28968eSJerin Jacob 946d28968eSJerin Jacob int 956d28968eSJerin Jacob octeontx_pki_port_create_qos(int port, pki_qos_cfg_t *qos_cfg) 966d28968eSJerin Jacob { 976d28968eSJerin Jacob struct octeontx_mbox_hdr hdr; 986d28968eSJerin Jacob int res; 996d28968eSJerin Jacob 1006d28968eSJerin Jacob mbox_pki_qos_cfg_t q_cfg = *(mbox_pki_qos_cfg_t *)qos_cfg; 1016d28968eSJerin Jacob int len = sizeof(mbox_pki_qos_cfg_t); 1026d28968eSJerin Jacob 1036d28968eSJerin Jacob hdr.coproc = OCTEONTX_PKI_COPROC; 1046d28968eSJerin Jacob hdr.msg = MBOX_PKI_PORT_CREATE_QOS; 1056d28968eSJerin Jacob hdr.vfid = port; 1066d28968eSJerin Jacob 1076d28968eSJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, &q_cfg, len, NULL, 0); 1086d28968eSJerin Jacob if (res < 0) 1096d28968eSJerin Jacob return -EACCES; 1106d28968eSJerin Jacob 1116d28968eSJerin Jacob return res; 1126d28968eSJerin Jacob } 1136d28968eSJerin Jacob 114b95c3413SJerin Jacob 1156d28968eSJerin Jacob int 1166d28968eSJerin Jacob octeontx_pki_port_errchk_config(int port, pki_errchk_cfg_t *cfg) 1176d28968eSJerin Jacob { 1186d28968eSJerin Jacob struct octeontx_mbox_hdr hdr; 1196d28968eSJerin Jacob int res; 1206d28968eSJerin Jacob 1216d28968eSJerin Jacob mbox_pki_errcheck_cfg_t e_cfg; 1226d28968eSJerin Jacob e_cfg = *((mbox_pki_errcheck_cfg_t *)(cfg)); 1236d28968eSJerin Jacob int len = sizeof(mbox_pki_errcheck_cfg_t); 1246d28968eSJerin Jacob 1256d28968eSJerin Jacob hdr.coproc = OCTEONTX_PKI_COPROC; 1266d28968eSJerin Jacob hdr.msg = MBOX_PKI_PORT_ERRCHK_CONFIG; 1276d28968eSJerin Jacob hdr.vfid = port; 1286d28968eSJerin Jacob 1296d28968eSJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, &e_cfg, len, NULL, 0); 1306d28968eSJerin Jacob if (res < 0) 1316d28968eSJerin Jacob return -EACCES; 1326d28968eSJerin Jacob 1336d28968eSJerin Jacob return res; 1346d28968eSJerin Jacob } 1356d28968eSJerin Jacob 136445371e8SJerin Jacob #define PCI_VENDOR_ID_CAVIUM 0x177D 137445371e8SJerin Jacob #define PCI_DEVICE_ID_OCTEONTX_PKI_VF 0xA0DD 138445371e8SJerin Jacob 139445371e8SJerin Jacob /* PKIVF pcie device */ 140445371e8SJerin Jacob static int 141445371e8SJerin Jacob pkivf_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) 142445371e8SJerin Jacob { 143445371e8SJerin Jacob RTE_SET_USED(pci_drv); 144445371e8SJerin Jacob RTE_SET_USED(pci_dev); 145445371e8SJerin Jacob 146445371e8SJerin Jacob /* For secondary processes, the primary has done all the work */ 147445371e8SJerin Jacob if (rte_eal_process_type() != RTE_PROC_PRIMARY) 148445371e8SJerin Jacob return 0; 149445371e8SJerin Jacob 150445371e8SJerin Jacob return 0; 151445371e8SJerin Jacob } 152445371e8SJerin Jacob 153445371e8SJerin Jacob static const struct rte_pci_id pci_pkivf_map[] = { 154445371e8SJerin Jacob { 155445371e8SJerin Jacob RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 156445371e8SJerin Jacob PCI_DEVICE_ID_OCTEONTX_PKI_VF) 157445371e8SJerin Jacob }, 158445371e8SJerin Jacob { 159445371e8SJerin Jacob .vendor_id = 0, 160445371e8SJerin Jacob }, 161445371e8SJerin Jacob }; 162445371e8SJerin Jacob 163445371e8SJerin Jacob static struct rte_pci_driver pci_pkivf = { 164445371e8SJerin Jacob .id_table = pci_pkivf_map, 165445371e8SJerin Jacob .drv_flags = RTE_PCI_DRV_NEED_MAPPING, 166445371e8SJerin Jacob .probe = pkivf_probe, 167445371e8SJerin Jacob }; 168445371e8SJerin Jacob 169445371e8SJerin Jacob RTE_PMD_REGISTER_PCI(octeontx_pkivf, pci_pkivf); 170