From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0066.outbound.protection.outlook.com [104.47.40.66]) by dpdk.org (Postfix) with ESMTP id 6389C2C1A for ; Fri, 31 Mar 2017 21:35:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=fdyR0ODMCF4dolf2isDrr9k8u0hQSmqPwk/40v5vXHo=; b=KYe2aB/e8oGE5HfLVOlIBECFPZq92EadQ2pKEj22xTCCjYpJ67ifr83QLTDO+68cWrqoyMq7hxmIE3EOu5yx7xefgZKw11M3mteQdg2Nt7ihQPfVoIAA2ApavzP5qfFLU9MmLVrNgCF+AwUkoKOdZkdG2cBqiQvQB6oHBIOWpek= Authentication-Results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=caviumnetworks.com; Received: from localhost.localdomain (14.140.2.178) by BY1PR0701MB1723.namprd07.prod.outlook.com (10.162.111.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.991.14; Fri, 31 Mar 2017 19:35:54 +0000 From: Jerin Jacob To: dev@dpdk.org Cc: thomas.monjalon@6wind.com, bruce.richardson@intel.com, harry.van.haaren@intel.com, hemant.agrawal@nxp.com, gage.eads@intel.com, nipun.gupta@nxp.com, santosh.shukla@caviumnetworks.com, Jerin Jacob Date: Sat, 1 Apr 2017 01:04:32 +0530 Message-Id: <1490988905-12584-6-git-send-email-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1490988905-12584-1-git-send-email-jerin.jacob@caviumnetworks.com> References: <1488562101-6658-1-git-send-email-jerin.jacob@caviumnetworks.com> <1490988905-12584-1-git-send-email-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [14.140.2.178] X-ClientProxiedBy: MAXPR01CA0058.INDPRD01.PROD.OUTLOOK.COM (10.164.146.158) To BY1PR0701MB1723.namprd07.prod.outlook.com (10.162.111.142) X-MS-Office365-Filtering-Correlation-Id: 5fde4611-60e9-4d20-130b-08d4786d2766 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:BY1PR0701MB1723; X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1723; 3:Tk64xHIH4CFxKXeJgKOFCwcMw6Yk5VjC0SgT6DmFmf9K2+HF+ChJAlKLuGd75OBo1XEKvZuQrR8savIywbPdA1Zj8zsP/khT6aVWaSEoPi54DgEMNvTmEDEB6zJCh6uBjDSkom1EMsUjwhSZqkDNSI/0YgbRie0kq9q0z33R2uVelm9QNePYna/xzzOvULG/UGYj5r3uFj8JiW0h08ejOY9Bl2AJ/Ty6l68KYNQy5RZUEidScefsznPov/jzJa56lZbpQGtOWNnIv7sDQ4k4aONlnbjbQyRArNCh22KRf+Eyy+33VJzS1yB3RI88q3n5wBe5SbbIdC5mWBLREcoh6Q==; 25:K5e3DwaEXRQzR0bdOZI8WG+ym2tnEJG0VfkG1PfBPlLm4Z8axkfTyq+Zw8hK+DaSshn9VeTweW79hUXb//31LlJmjbO90QdeJfPkvg2rOLSepIV9/pbnTXAZQMBOIplI5FjSvQ9QV6mrleREu9wu0B+9RTAbFlDsyc28RJD5FuVmlOLsJRmzFnqv4QDhM/StWdRN5RkeEhV12Tsbi1eIJ7ZouHcDWR9Gcxs38wfQD8P6oI8ANcQLj+eQf2TJkhYt8rPfuoOYWuNak4uKEuKrV/VOsQtfW1h8rM6l1ysVm2uByvYVdQVzLeJvQnSQGu0A+wv901L7APWkKmrfY/pZnUl6axqfSQZkBTGs+foAJFKGXvU5evkZUjj6QPfMsnqVRNlPFkBJuLYyv2sDurwGKf5xcR+WkvpxRWdi7qXb79xSm7fuboW8BKZWVtjsebPK1Kmf2YDdSm/4xRJ9NhiH+A== X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1723; 31:I7gO0xkSPa1QEbWv8U93BIBHDIL1r75E6gZ/hNDcJQNXATnzG73C1m5GdxhLXmb/SmAIVlxv604hVr3x7vwDIiszJ2oqmUITaJJ9chGgcMjmV31V3xsnQmzKe8kHvZ6r4JHkqUboWU7BF62diZQpAQhi0ovs4wXbGMVT2H2PlFafqIWrjg4CCO7RektuALe+hXiGFWa9B2Kn+i7IuP4ufG+VbrcW17MMiqVGF3zw2UaZcjFqtrn0kEbS5X1NGXMM; 20:bjAFrhMlglUa2RDy3HKcD8K1G6TBUQeGveK5r1qlZAHegRJcRs0zqmMZlYHi5+ztoq9vdrmsEtkbHvWuFxsOhkL8K3hp5rsF3x8PWJPG645dwVHw1W3FFMyO9EXpOIW7ClyYdhcmNozjBTUjnfvrisO4PdG3jStQYzuy5eWGdP5anRAwWCckF6/NnO+FYIeAMGpUQfC7UxNQ9hCKhYrcG57+WngtdSQHoUe2hZddr6sSzUs4Zkqr85MaOwER9GNLJ+dlIEbrIdcdrQh3rOipcxpy4BFmZe4Aa4uqa8yxH4/KN2mnWrmIwvDDEwetQhtN6Zi9xHWsw9fKU6Hafrm2qo6h8fqGvJeeQFVyfO3+ITogYplllZJlkPmdVU3b8Gn4+d/G2Jitwv7/xMehqx3TdWBON1XNBG96rTOR8Om84f5JMZN1hLUfFO59JEt2470HrtftFBCg7v0WeugG5q2mzHqkDNWV2YM91yM3pviE1NPkcjviRDqxOllwod7mWvM/gYtxlcDel1aq9Dc9RvCLW2ep5vtRAPyXYAj+qPQx4HObLYQA0kMNp2EzvBGpO7I1sYAjvDRqjuTR1HdJiOay0ZfNgfFYuvMsnerIvxyelUc= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(93006095)(3002001)(6041248)(20161123555025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(20161123560025)(20161123564025)(6072148); SRVR:BY1PR0701MB1723; BCL:0; PCL:0; RULEID:; SRVR:BY1PR0701MB1723; X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1723; 4:Jj0VgM3oQDO4tqSrKdpN+YOupAA3ZZxv8hQZkB5j0EuFpkCfCR2rUMH/AYNIonthqpT3H4G1tN3UnBsuTRN3uAJUwGq4PKuS0Fg8blZQssP1FFVpBs/NdLQG5KuSis5cYZXyIekuNZtU5INABo7u6KtvKJp9zqY71/fuSTLU2bvw06VArRBvyrQdENaU3oXJ3RZAKVJ/F78yUzp3K0bgnR9VQrzRGKStric4OcH1vI0/lAQfThcHUjFX/Q7xCA/ynz+4abjA9/xpIC0ADjTRHs/gLBULwGKZFsAhphRCfkjg+IfVJPhXon8chB+l5fawmvx65o5zO8wWlx2inx5FuRMTyQZ+XzcGl6jZbiyMwL9BKT00qGvCezcrmjhY/xJUWlfZpHYYW9csMs8axw60OoDCBg4BbRRxW3mtGfv7zAP4lsP22pfssyQWID/GQxLy4pLHsS0w8GSDamzYycg/QQO0v5A6QlkV9CeQvrF8kliptqfe08E+fSfxtggUS/WL1pSUyebrNR9RNWma/6kqfaAAjuATByey8bMJ/O6R1eIcG9Com+MGrQqiDo39pQytNpkcr9FyWZgK1Rrpc/QbZf1NaR6DQuIoltdnpj6aQDJBbDhU+cmJnll/m7wVo/+bADgbKsWJNdY38ZF0GLiKg0M8ZMQp56YsOqXoPvji1DdHOcI21DYXeAIxof+sm0qFO///CbK39+pcoSWXOfF09A== X-Forefront-PRVS: 02638D901B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(39450400003)(39410400002)(39400400002)(39850400002)(39840400002)(38730400002)(8676002)(53376002)(107886003)(110136004)(50466002)(189998001)(7110500001)(305945005)(6506006)(36756003)(50226002)(25786009)(48376002)(6666003)(966004)(8656002)(6486002)(7736002)(2950100002)(5660300001)(53936002)(81156014)(81166006)(3846002)(42882006)(6916009)(6306002)(6116002)(6512007)(42186005)(33646002)(15650500001)(2361001)(2420400007)(2351001)(76176999)(50986999)(5003940100001)(47776003)(2906002)(5009440100003)(4326008)(66066001)(10710500007)(110426004); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR0701MB1723; H:localhost.localdomain; FPR:; SPF:None; MLV:nov; PTR:InfoNoRecords; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY1PR0701MB1723; 23:Zfl7uN9qC22epkbyenlSzY0hC7JAPEEplo6SKiG?= =?us-ascii?Q?UHaNq7q5VV0UDMDFD+6G/WbHKso424iFCyym3K6IvJdrGJjmjzLKo7uOTRGR?= =?us-ascii?Q?6d2ZXqCZ3vxhSBVE/u3tJbVdhtWL9ha6anKOKsScWq8nnUKTOsU3I2E0Z5Jg?= =?us-ascii?Q?A2KmEwkFrkev71eJL2D+jkjVFMMQPolUoeKHme5o9aM9c1oj41GRMDlSVsZR?= =?us-ascii?Q?rDxjbU97HE+hAo+oUh1uVjeRVfENgxq23T01FXtoyU01AlkmqNUUIG12rAed?= =?us-ascii?Q?WoZoOYwFJtt1uQS91O41eiYJIAmxhQWjqliL5iYtLtML8f47yc8AF9uatZUF?= =?us-ascii?Q?8hv6vSA43rgxk0eSw3CGNoacXqjokMR5mzpSbMXZzunKjUh0zxoQBLIEIIqc?= =?us-ascii?Q?zO1G1TLtITHGM1vefT1EAHjt7foFcFp1knkl0uDcZ5fyUqR6gbdXkdlT6zIY?= =?us-ascii?Q?Mu3F3cMENrAdLamzADLEKMHtAgZjVdlyRgb+CdfHDmhaGUjRvxOlRUi1uuMM?= =?us-ascii?Q?yUlNcSBsZJHgMguNInex8Th3b1RFIIeU4C3NYUjp3XELu6ISiB9BwJxF0eEi?= =?us-ascii?Q?LBQEiRsLV+4wxaji6BYtu7vrEbty8hVkq9Y9jFm0aEdfYP1eXJEoqfGhJjJe?= =?us-ascii?Q?m2FZCiJXOh2J3kIAS07ysFLZEpPIs0eo7WBEe9iK0GVHMUdHCF45fAlvBAf2?= =?us-ascii?Q?IvaOUGkhXZQ8HVSJLFR0/mSjoJXRaWV2xfQ6h/rFjHhYTaJe9aXH2dLzqMdZ?= =?us-ascii?Q?EPE31Inlrv4ZzJjYPXf/igKX8l7ujs+Z0wTMBH1jYSxPGsOPEtqKMw23MZEi?= =?us-ascii?Q?TKnWv8Xpy2TfY8B1uMyIMhMdyiPwFA0sM33ERhzHa/v7CkDCkNM1JR1mITML?= =?us-ascii?Q?EfNMdCJw3YNRgVdMhiTkBwWCyFWp3PNCY3evE7re/UxvcCBc1gFLJtPDO0Xd?= =?us-ascii?Q?d+ZNWIZnXxmCrIbtKCnc3h0vmW1t/39Sx8DtSFFnPA0+uZajpiwjlJ3Irdt1?= =?us-ascii?Q?y6lsUX6+VfAl/cmdGP9J9zJ5l/SjQce/N8vurcW4uoV6wiYdCFODIWyRZoYz?= =?us-ascii?Q?jW8+Z/M7fFjAB68alQBJ3n0YbU1ItTPPg6XojKCjnIuTqhGKB8hn0iXlxgUu?= =?us-ascii?Q?Edd3O1orTkK7PoDEUqrq75dSOK2tQx5FEaHb/x7EbSjjceKossrQZCgW7fJc?= =?us-ascii?Q?idaaMS0PQx/ZBsBolsEOQv2dLR/gkR/UUd6D4od5fgTQPogaDmcfAfUh8f9B?= =?us-ascii?Q?KIhuRLqstaTeuwPGSk4p6Ew2hH9mSn/4+kQafNfGX/NlC9RKDdTpCw4A09UG?= =?us-ascii?Q?YJuzNzs4a5NjUuZHxiSmKSwGPLfTnBiRj3VgNGuquMs+i?= X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1723; 6:fKKTuHW/5eYuFG4YmOUmRcMsvD6WLehBpiTVgQpBcku4LwRBWiAVKxTu+0Qdy1D+HqnFKud859KgYuKDGtp9SUEr7GO7LkkgUQ66j2kunD3RgBebI1toHDKPvk7VY3NzTZEGxDqSd54Gx+w7Xuo1OFNqUq5akGMV7o3jq863EhgJRuKt6+rAgY/Z28WXMnQR07yGn3yLHYsSMQGcKPFO2w1ZagSTu8n2JIQYRuhaSYJgAT8fumcQ2B8vTSmO+srvRj6b14md0MCh6eOy7Y68R7LwBBTbG4lrVjnzxcHvKhqjPZD/D6FTeJ06fPW8buhrPabN1zOmydRmhI6a6kLrwH3GzTvsHH8Bwnqc57iyzOK/oNKhAc7SDTLeGxhn4q2cNUwxlMVcSrNtEYqb3Z+aQw==; 5:nDhTU7kR0D4kmLrlekIqLal64IYvizp2X+n6LF4WAU6BWv3dpTcsdDHsAvFw9seGRpnFFQkKRdw2BdJVmwEdqYi+SJy97kcKmpPsR0g/H4KOREIB03Og22EWpMvJEQNuQmnGIYVIIItx792dyjTaLiDqYiUYM4F602YjZfHssTE=; 24:evHEAq/MPk6dC3u0XOOw+Omv1/VtXEmNz6+0JLAwq5K84EsLaVPcKFoIkS/q6ywV2mLb5nKe+X1n4E394dNAwHTPlmpeZVU6i8a03Yal+Zk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1723; 7:En0553JtZ9Q22JQyqQOtJgA0gwi3Oij2XgRFncoVPzFIYRk2ZpQBt572U7lnTa8yx/NQ6AsG22Ngz2OuMt+PPajftnNK9KuZaFX3C82a8n4qltfOIRNJXedyJl8/Wq+EMTEiH1faXZ67eHbnH/cXCSv5JwlAwCG4Qj47YWk6K9e073CcgViX5ADPH2j9Pw25HeOi2EzKcaAt7QeTNtrXxVgg59i97pmRIN3ESxGO3BMiZnMXhnGEzkIz4MroN1ikCLm3WBl62QgVandHZr3zzwN+LuBsWBWpCOwpLtM35x3xGXUiqC0z6wxYfsOjWd9zhwiqapRtE8SHUjbHWeG6mQ== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Mar 2017 19:35:54.1422 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1723 Subject: [dpdk-dev] [PATCH v2 05/38] event/octeontx: add mailbox support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Mar 2017 19:36:00 -0000 ssovf VF device has mailbox mechanism to communicate with PF device. This patch adds support for a mbox API to send the mailbox request to PF device. The ssovf VF device will be used as the communication channel to talk to PF devices of all the network accelerated co-processors in Octeontx. Exposing as shared function to use it from pool, crypto, network devices. Signed-off-by: Jerin Jacob Signed-off-by: Santosh Shukla --- v2: - Fixed incorrect mbox wait time(Gage) http://dpdk.org/dev/patchwork/patch/21366/ - Improved the mbox timeout handling(Gage) http://dpdk.org/dev/patchwork/patch/21366/ - fix free bsd and clang build issues --- drivers/event/octeontx/Makefile | 1 + drivers/event/octeontx/rte_pmd_octeontx_ssovf.h | 8 + .../octeontx/rte_pmd_octeontx_ssovf_version.map | 1 + drivers/event/octeontx/ssovf_mbox.c | 232 +++++++++++++++++++++ 4 files changed, 242 insertions(+) create mode 100644 drivers/event/octeontx/ssovf_mbox.c diff --git a/drivers/event/octeontx/Makefile b/drivers/event/octeontx/Makefile index 896e556..3076b85 100644 --- a/drivers/event/octeontx/Makefile +++ b/drivers/event/octeontx/Makefile @@ -47,6 +47,7 @@ LIBABIVER := 1 # all source are stored in SRCS-y # SRCS-$(CONFIG_RTE_LIBRTE_PMD_OCTEONTX_SSOVF) += ssovf_probe.c +SRCS-$(CONFIG_RTE_LIBRTE_PMD_OCTEONTX_SSOVF) += ssovf_mbox.c # install this header file SYMLINK-$(CONFIG_RTE_LIBRTE_PMD_OCTEONTX_SSOVF)-include := rte_pmd_octeontx_ssovf.h diff --git a/drivers/event/octeontx/rte_pmd_octeontx_ssovf.h b/drivers/event/octeontx/rte_pmd_octeontx_ssovf.h index e92a61f..3da7cfd 100644 --- a/drivers/event/octeontx/rte_pmd_octeontx_ssovf.h +++ b/drivers/event/octeontx/rte_pmd_octeontx_ssovf.h @@ -46,8 +46,16 @@ enum octeontx_ssovf_type { OCTEONTX_SSO_HWS, /* SSO hardware workslot vf */ }; +struct octeontx_mbox_hdr { + uint16_t vfid; /* VF index or pf resource index local to the domain */ + uint8_t coproc; /* Coprocessor id */ + uint8_t msg; /* Message id */ + uint8_t res_code; /* Functional layer response code */ +}; int octeontx_ssovf_info(struct octeontx_ssovf_info *info); void *octeontx_ssovf_bar(enum octeontx_ssovf_type, uint8_t id, uint8_t bar); +int octeontx_ssovf_mbox_send(struct octeontx_mbox_hdr *hdr, + void *txdata, uint16_t txlen, void *rxdata, uint16_t rxlen); #endif /* __RTE_PMD_OCTEONTX_SSOVF_H__ */ diff --git a/drivers/event/octeontx/rte_pmd_octeontx_ssovf_version.map b/drivers/event/octeontx/rte_pmd_octeontx_ssovf_version.map index c71d4c7..3810a03 100644 --- a/drivers/event/octeontx/rte_pmd_octeontx_ssovf_version.map +++ b/drivers/event/octeontx/rte_pmd_octeontx_ssovf_version.map @@ -3,6 +3,7 @@ DPDK_17.05 { octeontx_ssovf_info; octeontx_ssovf_bar; + octeontx_ssovf_mbox_send; local: *; }; diff --git a/drivers/event/octeontx/ssovf_mbox.c b/drivers/event/octeontx/ssovf_mbox.c new file mode 100644 index 0000000..0435f6d --- /dev/null +++ b/drivers/event/octeontx/ssovf_mbox.c @@ -0,0 +1,232 @@ +/* + * BSD LICENSE + * + * Copyright (C) Cavium networks Ltd. 2017. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Cavium networks nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include +#include +#include +#include +#include + +#include "ssovf_evdev.h" + +/* Mbox operation timeout in seconds */ +#define MBOX_WAIT_TIME_SEC 3 +#define MAX_RAM_MBOX_LEN ((SSOW_BAR4_LEN >> 1) - 8 /* Mbox header */) + +/* Mbox channel state */ +enum { + MBOX_CHAN_STATE_REQ = 1, + MBOX_CHAN_STATE_RES = 0, +}; + +/* Response messages */ +enum { + MBOX_RET_SUCCESS, + MBOX_RET_INVALID, + MBOX_RET_INTERNAL_ERR, +}; + +struct mbox { + int init_once; + uint8_t *ram_mbox_base; /* Base address of mbox message stored in ram */ + uint8_t *reg; /* Store to this register triggers PF mbox interrupt */ + uint16_t tag_own; /* Last tag which was written to own channel */ + rte_spinlock_t lock; +}; + +static struct mbox octeontx_mbox; + +/* + * Structure used for mbox synchronization + * This structure sits at the begin of Mbox RAM and used as main + * synchronization point for channel communication + */ +struct mbox_ram_hdr { + union { + uint64_t u64; + struct { + uint8_t chan_state : 1; + uint8_t coproc : 7; + uint8_t msg; + uint8_t vfid; + uint8_t res_code; + uint16_t tag; + uint16_t len; + }; + }; +}; + +static inline void +mbox_send_request(struct mbox *m, struct octeontx_mbox_hdr *hdr, + const void *txmsg, uint16_t txsize) +{ + struct mbox_ram_hdr old_hdr; + struct mbox_ram_hdr new_hdr = {.u64 = 0}; + uint64_t *ram_mbox_hdr = (uint64_t *)m->ram_mbox_base; + uint8_t *ram_mbox_msg = m->ram_mbox_base + sizeof(struct mbox_ram_hdr); + + /* + * Initialize the channel with the tag left by last send. + * On success full mbox send complete, PF increments the tag by one. + * The sender can validate integrity of PF message with this scheme + */ + old_hdr.u64 = rte_read64(ram_mbox_hdr); + m->tag_own = (old_hdr.tag + 2) & (~0x1ul); /* next even number */ + + /* Copy msg body */ + if (txmsg) + memcpy(ram_mbox_msg, txmsg, txsize); + + /* Prepare new hdr */ + new_hdr.chan_state = MBOX_CHAN_STATE_REQ; + new_hdr.coproc = hdr->coproc; + new_hdr.msg = hdr->msg; + new_hdr.vfid = hdr->vfid; + new_hdr.tag = m->tag_own; + new_hdr.len = txsize; + + /* Write the msg header */ + rte_write64(new_hdr.u64, ram_mbox_hdr); + rte_io_wmb(); + /* Notify PF about the new msg - write to MBOX reg generates PF IRQ */ + rte_write64(0, m->reg); +} + +static inline int +mbox_wait_response(struct mbox *m, struct octeontx_mbox_hdr *hdr, + void *rxmsg, uint16_t rxsize) +{ + int res = 0, wait; + uint16_t len; + struct mbox_ram_hdr rx_hdr; + uint64_t *ram_mbox_hdr = (uint64_t *)m->ram_mbox_base; + uint8_t *ram_mbox_msg = m->ram_mbox_base + sizeof(struct mbox_ram_hdr); + + /* Wait for response */ + wait = MBOX_WAIT_TIME_SEC * 1000 * 10; + while (wait > 0) { + rte_delay_us(100); + rx_hdr.u64 = rte_read64(ram_mbox_hdr); + if (rx_hdr.chan_state == MBOX_CHAN_STATE_RES) + break; + --wait; + } + + hdr->res_code = rx_hdr.res_code; + m->tag_own++; + + /* Timeout */ + if (wait <= 0) { + res = -ETIMEDOUT; + goto error; + } + + /* Tag mismatch */ + if (m->tag_own != rx_hdr.tag) { + res = -EINVAL; + goto error; + } + + /* PF nacked the msg */ + if (rx_hdr.res_code != MBOX_RET_SUCCESS) { + res = -EBADMSG; + goto error; + } + + len = RTE_MIN(rx_hdr.len, rxsize); + if (rxmsg) + memcpy(rxmsg, ram_mbox_msg, len); + + return len; + +error: + ssovf_log_err("Failed to send mbox(%d/%d) coproc=%d msg=%d ret=(%d,%d)", + m->tag_own, rx_hdr.tag, hdr->msg, hdr->coproc, res, + hdr->res_code); + return res; +} + +static inline int +mbox_send(struct mbox *m, struct octeontx_mbox_hdr *hdr, const void *txmsg, + uint16_t txsize, void *rxmsg, uint16_t rxsize) +{ + int res = -EINVAL; + + if (m->init_once == 0 || hdr == NULL || + txsize > MAX_RAM_MBOX_LEN || rxsize > MAX_RAM_MBOX_LEN) { + ssovf_log_err("Invalid init_once=%d hdr=%p txsz=%d rxsz=%d", + m->init_once, hdr, txsize, rxsize); + return res; + } + + rte_spinlock_lock(&m->lock); + + mbox_send_request(m, hdr, txmsg, txsize); + res = mbox_wait_response(m, hdr, rxmsg, rxsize); + + rte_spinlock_unlock(&m->lock); + return res; +} + +static inline int +mbox_setup(struct mbox *m) +{ + if (unlikely(m->init_once == 0)) { + rte_spinlock_init(&m->lock); + m->ram_mbox_base = octeontx_ssovf_bar(OCTEONTX_SSO_HWS, 0, 4); + m->reg = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, 0, 0); + m->reg += SSO_VHGRP_PF_MBOX(1); + + if (m->ram_mbox_base == NULL || m->reg == NULL) { + ssovf_log_err("Invalid ram_mbox_base=%p or reg=%p", + m->ram_mbox_base, m->reg); + return -EINVAL; + } + m->init_once = 1; + } + return 0; +} + +int +octeontx_ssovf_mbox_send(struct octeontx_mbox_hdr *hdr, void *txdata, + uint16_t txlen, void *rxdata, uint16_t rxlen) +{ + struct mbox *m = &octeontx_mbox; + + RTE_BUILD_BUG_ON(sizeof(struct mbox_ram_hdr) != 8); + if (rte_eal_process_type() != RTE_PROC_PRIMARY || mbox_setup(m)) + return -EINVAL; + + return mbox_send(m, hdr, txdata, txlen, rxdata, rxlen); +} -- 2.5.5