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 37*b95c3413SJerin Jacob #include "octeontx_pkivf.h" 38*b95c3413SJerin Jacob 39*b95c3413SJerin Jacob int 40*b95c3413SJerin Jacob octeontx_pki_port_open(int port) 41*b95c3413SJerin Jacob { 42*b95c3413SJerin Jacob struct octeontx_mbox_hdr hdr; 43*b95c3413SJerin Jacob int res; 44*b95c3413SJerin Jacob 45*b95c3413SJerin Jacob hdr.coproc = OCTEONTX_PKI_COPROC; 46*b95c3413SJerin Jacob hdr.msg = MBOX_PKI_PORT_OPEN; 47*b95c3413SJerin Jacob hdr.vfid = port; 48*b95c3413SJerin Jacob 49*b95c3413SJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, NULL, 0, NULL, 0); 50*b95c3413SJerin Jacob if (res < 0) 51*b95c3413SJerin Jacob return -EACCES; 52*b95c3413SJerin Jacob return res; 53*b95c3413SJerin Jacob } 54*b95c3413SJerin Jacob 55*b95c3413SJerin Jacob int 56*b95c3413SJerin Jacob octeontx_pki_port_close(int port) 57*b95c3413SJerin Jacob { 58*b95c3413SJerin Jacob struct octeontx_mbox_hdr hdr; 59*b95c3413SJerin Jacob int res; 60*b95c3413SJerin Jacob 61*b95c3413SJerin Jacob mbox_pki_port_t ptype; 62*b95c3413SJerin Jacob int len = sizeof(mbox_pki_port_t); 63*b95c3413SJerin Jacob memset(&ptype, 0, len); 64*b95c3413SJerin Jacob ptype.port_type = OCTTX_PORT_TYPE_NET; 65*b95c3413SJerin Jacob 66*b95c3413SJerin Jacob hdr.coproc = OCTEONTX_PKI_COPROC; 67*b95c3413SJerin Jacob hdr.msg = MBOX_PKI_PORT_CLOSE; 68*b95c3413SJerin Jacob hdr.vfid = port; 69*b95c3413SJerin Jacob 70*b95c3413SJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, &ptype, len, NULL, 0); 71*b95c3413SJerin Jacob if (res < 0) 72*b95c3413SJerin Jacob return -EACCES; 73*b95c3413SJerin Jacob 74*b95c3413SJerin Jacob return res; 75*b95c3413SJerin Jacob } 76*b95c3413SJerin Jacob 77*b95c3413SJerin Jacob int 78*b95c3413SJerin Jacob octeontx_pki_port_start(int port) 79*b95c3413SJerin Jacob { 80*b95c3413SJerin Jacob struct octeontx_mbox_hdr hdr; 81*b95c3413SJerin Jacob int res; 82*b95c3413SJerin Jacob 83*b95c3413SJerin Jacob mbox_pki_port_t ptype; 84*b95c3413SJerin Jacob int len = sizeof(mbox_pki_port_t); 85*b95c3413SJerin Jacob memset(&ptype, 0, len); 86*b95c3413SJerin Jacob ptype.port_type = OCTTX_PORT_TYPE_NET; 87*b95c3413SJerin Jacob 88*b95c3413SJerin Jacob hdr.coproc = OCTEONTX_PKI_COPROC; 89*b95c3413SJerin Jacob hdr.msg = MBOX_PKI_PORT_START; 90*b95c3413SJerin Jacob hdr.vfid = port; 91*b95c3413SJerin Jacob 92*b95c3413SJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, &ptype, len, NULL, 0); 93*b95c3413SJerin Jacob if (res < 0) 94*b95c3413SJerin Jacob return -EACCES; 95*b95c3413SJerin Jacob 96*b95c3413SJerin Jacob return res; 97*b95c3413SJerin Jacob } 98*b95c3413SJerin Jacob 99*b95c3413SJerin Jacob int 100*b95c3413SJerin Jacob octeontx_pki_port_stop(int port) 101*b95c3413SJerin Jacob { 102*b95c3413SJerin Jacob struct octeontx_mbox_hdr hdr; 103*b95c3413SJerin Jacob int res; 104*b95c3413SJerin Jacob 105*b95c3413SJerin Jacob mbox_pki_port_t ptype; 106*b95c3413SJerin Jacob int len = sizeof(mbox_pki_port_t); 107*b95c3413SJerin Jacob memset(&ptype, 0, len); 108*b95c3413SJerin Jacob ptype.port_type = OCTTX_PORT_TYPE_NET; 109*b95c3413SJerin Jacob 110*b95c3413SJerin Jacob hdr.coproc = OCTEONTX_PKI_COPROC; 111*b95c3413SJerin Jacob hdr.msg = MBOX_PKI_PORT_STOP; 112*b95c3413SJerin Jacob hdr.vfid = port; 113*b95c3413SJerin Jacob 114*b95c3413SJerin Jacob res = octeontx_ssovf_mbox_send(&hdr, &ptype, len, NULL, 0); 115*b95c3413SJerin Jacob if (res < 0) 116*b95c3413SJerin Jacob return -EACCES; 117*b95c3413SJerin Jacob 118*b95c3413SJerin Jacob return res; 119*b95c3413SJerin Jacob } 120*b95c3413SJerin Jacob 121445371e8SJerin Jacob #define PCI_VENDOR_ID_CAVIUM 0x177D 122445371e8SJerin Jacob #define PCI_DEVICE_ID_OCTEONTX_PKI_VF 0xA0DD 123445371e8SJerin Jacob 124445371e8SJerin Jacob /* PKIVF pcie device */ 125445371e8SJerin Jacob static int 126445371e8SJerin Jacob pkivf_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) 127445371e8SJerin Jacob { 128445371e8SJerin Jacob RTE_SET_USED(pci_drv); 129445371e8SJerin Jacob RTE_SET_USED(pci_dev); 130445371e8SJerin Jacob 131445371e8SJerin Jacob /* For secondary processes, the primary has done all the work */ 132445371e8SJerin Jacob if (rte_eal_process_type() != RTE_PROC_PRIMARY) 133445371e8SJerin Jacob return 0; 134445371e8SJerin Jacob 135445371e8SJerin Jacob return 0; 136445371e8SJerin Jacob } 137445371e8SJerin Jacob 138445371e8SJerin Jacob static const struct rte_pci_id pci_pkivf_map[] = { 139445371e8SJerin Jacob { 140445371e8SJerin Jacob RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 141445371e8SJerin Jacob PCI_DEVICE_ID_OCTEONTX_PKI_VF) 142445371e8SJerin Jacob }, 143445371e8SJerin Jacob { 144445371e8SJerin Jacob .vendor_id = 0, 145445371e8SJerin Jacob }, 146445371e8SJerin Jacob }; 147445371e8SJerin Jacob 148445371e8SJerin Jacob static struct rte_pci_driver pci_pkivf = { 149445371e8SJerin Jacob .id_table = pci_pkivf_map, 150445371e8SJerin Jacob .drv_flags = RTE_PCI_DRV_NEED_MAPPING, 151445371e8SJerin Jacob .probe = pkivf_probe, 152445371e8SJerin Jacob }; 153445371e8SJerin Jacob 154445371e8SJerin Jacob RTE_PMD_REGISTER_PCI(octeontx_pkivf, pci_pkivf); 155