From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0081.outbound.protection.outlook.com [104.47.36.81]) by dpdk.org (Postfix) with ESMTP id 305A9D326 for ; Sat, 25 Mar 2017 07:27:22 +0100 (CET) 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=1Iesj1BIkodb0hbifytqaov5g2LX79SOz8jo2sgti4I=; b=JqR2oHvHLoh5We7ktFn86I8G75DjzddepmiveDYKKlx/FJ4wqgQGI5awNRXNvNnp4FIGDaSTonBk47Iizol6rIkYBNeFLx6jo+p8onOsk9om6Cm9+Nr0MAJ5p+igZ3vNIwtRkMaBQMRV1p3/gZC8SWip3ttVcQzizb1sOM3Keyw= Authentication-Results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=caviumnetworks.com; Received: from lio357.in.caveonetworks.com (14.140.2.178) by CY1PR07MB2280.namprd07.prod.outlook.com (10.164.112.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.977.11; Sat, 25 Mar 2017 06:27:18 +0000 From: Shijith Thotton To: Ferruh Yigit Cc: dev@dpdk.org, Jerin Jacob , Derek Chickles , Venkat Koppula , Srisivasubramanian S , Mallesham Jatharakonda Date: Sat, 25 Mar 2017 11:54:20 +0530 Message-Id: <1490423097-6797-10-git-send-email-shijith.thotton@caviumnetworks.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1490423097-6797-1-git-send-email-shijith.thotton@caviumnetworks.com> References: <1488454371-3342-1-git-send-email-shijith.thotton@caviumnetworks.com> <1490423097-6797-1-git-send-email-shijith.thotton@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [14.140.2.178] X-ClientProxiedBy: BM1PR01CA0117.INDPRD01.PROD.OUTLOOK.COM (10.174.208.33) To CY1PR07MB2280.namprd07.prod.outlook.com (10.164.112.158) X-MS-Office365-Filtering-Correlation-Id: 4fcbe021-1df5-48f8-8312-08d47347fe6d X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:CY1PR07MB2280; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2280; 3:wRZY77fMwmlRBpbSGfH6/su3SEz5KIRhj+bLw0MWLouPhxN7pD+lO1+JNnh9bMX0vCcPdoaAo5LZMaCo44yDqpW2glLbt24hApvgHNmYeEZ+yxGdhyQuARP0m5+eAhSJACF4CH1mMBdfoFW9o6rtTednAyO5t8yMmPAeSrCLrnmKF5aVwg5VYY/Uk7HqLcvTEWUmm3vCn6cH4sKNPuqpzOViLj4CBMx9OEhZPqFq9fFAEW4Itw4Xl6r0aFu7eWAzc41VCJ7J/28zGF9Dk+amPA==; 25:kNNQlWsaYHEltL+1lzURQPdKCOXe5x8TeD1u2E/3OrpvGlKA+98FPuIetvbj1NzNBLEpKrzyY4h7Dj7xMpnDP0wVME8Y+QDCwkYtGGrj/bhpIuFtAbMw3GAVWSbafrdKevQqTXVUT4qPZXlSGSCYmxLAjvmz2a5Zywv2OIkXejeUefRHYYCnbCbT9bi+TVmCDjLkGGJXTtnDDpHI9oEkunrpVAu43l6Nt4E6t+8TtZ/PTOgmU3/fozFfSn+XzzC+tlMgEEi2CWzN7q9VLlZobQ1K75RFH1ezGZO+i8YBxIkGBOgzU6kZy+x4WtKYV32VEpdPFLp4IYuHcHySpX8ajVcRhP3eYLkk+qZgiXdSSg5KmPKiyoX4sKAtTg3z5aU24MTenKhF3S1BgSYbhlvXI0F0Ca5WhYdZUbGih4KoVhvBZ0b8H2nc04A+6ROHaWM8/Eof9UBlzhfGc/kNO47jyQ== X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2280; 31:rXGZVrs7OemJvsD76QBhiP1HeGG++AQdyzCKp8xKS8obEAZ7hZovSEy/0kuLakZJT41GcfXp06jkBAAlJf981D1CD6z5XuS/fAUzg8Ls0/pDAr3V1wmM4PNnlE6uEvD48yfZ1IEO/TiNArsGuW4B2yfgho0v3veTjGQWkM4A9PXrIlmivFDxHdOCSNlhopoGsqCHm+0QkfJ106aKuc2jJmtBMyAYCunMrZ1cbjMq5BiJGoWcsFiyL+ZrbyPASlqX; 20:IS6hUa4xr32Ush2aU8LUtu/oUT8FrbGvlA8MgZbuFJboEM/WIm5gHbIgp4aYo0VVWVyv/iekXV8mxSeHDzNtfvM4NeSj2vyqZsfOIP2QRK5lC21tYRgjAUl7On8jAsLRKpb7+/O9Kb1UIoPG62KJ0yQkdh2f11qNKEnrelheWFm9OkhWcWMT3q9LClU7h90YHet/QAcBr17s0jxWnrghBlXN/ErENAU5pPDApDkCJD90pQdnOYjf9N5i5ie5ZzqhJucnzDM3sGNM9Qx+m1G7dKNWdhR4Ry+eG9JooAmKPoMylkTRSRTo3z5/dmIvvSXyd8/pXy5siXzROaSiUDSKnqoeHkg8tVhVclXgRxG1DuTZGsgYdND5RNHE+aunhZmzLv82A/bTjx9C0ikr5lMhystGJni62CtjjfIkqV+ZMAsykgBa73oJqrAoHrxEz2aal2FY0el8bPrqyTwrrllP7LbvhFbVfu8NxVTVLFZPCsiiI1t0WosgBBxkYUOIrCazUkE+P5EytOgDPsc0OZSoplhZzivl1LUPhOxoH2kyaou5MUPCeC8b2iSLYFPwYV0ILfcv0c9NQsgy4/tZH16Dw9Ln9cIfk1JT6BHX1iKHzgY= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6041248)(20161123564025)(20161123560025)(20161123562025)(20161123558025)(20161123555025)(6072148); SRVR:CY1PR07MB2280; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2280; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2280; 4:X37ZCr1XIkvytI3jc78CuBmhyOFbTStfmxeEXYu8EHXl2cHJVT4iU60S37kVbY194fiqd6N0yRHCGTytYw85ivET78B5mdQjVa2x9BnrErhuPc7LJ/5eH8oX4M25JG9TkClHjcsOPJN7sHNnMzMnF03cU9T7JNAYuzt6b3NVUKs1Btt7zL/BMGMr/dSYikjXW+ONZ7WkeFNdS6tDqSm3trR/cOlmXNPAQ0YW34rrXLjh9GQj3Tp+K7KDlkKhWizFtg/3v7ETRBgyH8cNa77A1ZnNlnEHDBkBvgufrDkfgPxzwhqBzEJNAqKv1YsnhtJtbJD1ErqyBAYm++O5IY1feYgF49S6bkyOVnsjsR1aB6JC2ydvklFZ6CbW8YIzI7EeU2tIwneaNNUoH8+oSmeeyZGEeB2FDFtVXJm4Z6ogYqMrDLDrNU5Y+ZsG/H3Fhh47Flztgh7J1cqvNdYS6ciq5gxzAYzkUUV0kj/yw4moWE97sptOwopdGMbWJLAhazMPfoh/vdFRJYtvFBhxOTd1BET6JGDrGaSFjxN6rZKUyedHqZzR7RuoLZ1lE7ALJcLV+wm5uWnOdtTmtGIOsz5VmAhLLmsOpDzNwMMVHJg30aI= X-Forefront-PRVS: 025796F161 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39450400003)(39410400002)(39830400002)(2906002)(2950100002)(5003940100001)(66066001)(42882006)(6916009)(50466002)(48376002)(47776003)(42186005)(53936002)(6512007)(68736007)(5009440100003)(54906002)(50226002)(38730400002)(6486002)(6666003)(25786009)(305945005)(81166006)(7736002)(6116002)(3846002)(4326008)(8676002)(6506006)(189998001)(36756003)(50986999)(76176999)(33646002)(4720700003)(5660300001)(110136004)(110426004); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR07MB2280; H:lio357.in.caveonetworks.com; FPR:; SPF:None; MLV:nov; PTR:InfoNoRecords; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR07MB2280; 23:3nFtyzHmxus5HABSvaujIWYNaSp2mYyTxug2NBN+o?= =?us-ascii?Q?OTvFBwKNoGTmUEfHse/mI9bSYFJqdqossWCOcoZUjWTbHV3nG5cVu3APqJfN?= =?us-ascii?Q?66ozU4cpZy7etEVk8GcuHaC+ScH67TVG7EM5vfkAhQOzaXyqCoxChZhsEa67?= =?us-ascii?Q?KKqLQ2aloEARpYIq/QkL53J9E8unTWQPfTiHyeVGPQ2drNozi6lMkSIyDre8?= =?us-ascii?Q?lCJfpX/st+A0KMmJJUMaJAdqI0hlO91XkkZfON5XK8S+rNmJbhz/SrfkDlb3?= =?us-ascii?Q?WZwR1shW5oav6Y6mI5M7vro0gKUxys/5tWI2V/H4qMskCebgFby7wQqvXPhZ?= =?us-ascii?Q?4YNbCcYfFxcJbAstYUk9sot8gLE9TCS1r9NWGRZmg1gjuDFTMQ5zGrxdNhxY?= =?us-ascii?Q?VmOwRBpESQQJ0QhySdQQNtyKeWaVccssNDuc7OXAQYL6HcYkn24qUDF76U5f?= =?us-ascii?Q?tv22Mdr6+h7P7Xq52UCEL3dlHp82yrvLTWM0SS3bmrkpdwuRbWIa9R6zkjC2?= =?us-ascii?Q?JFGELJdLL4m3tAt3My9F8xOK5nAPAFPx5QspEYN85R5sglRrUfQ3cw6nkOeG?= =?us-ascii?Q?F+wRkVspxjdPrFbzBQN9Mp6yjIT/fMwi00ZOcVyBFn3E8aTjE2GEasozfl0Y?= =?us-ascii?Q?CgJ31A8qtZNza6kuWOgdUVokyAFpKsaRo1jd0BgbrfPZLZEF5vunUjqu2B/k?= =?us-ascii?Q?m1x5ZnLbE0geFY53YJSUGehaJTe6BjZcAtavw/8dNaxu9sWsr3ojvqautQsH?= =?us-ascii?Q?TSUmVoqgxDoL9/4UzipZqi0Xs8a0CXPdtoF+xIlyrVWs+z2SDFiU02xM+AaB?= =?us-ascii?Q?fUD8vAsL94x8saBoR9Ry9NKgbNE3AMKliUoXMwwziVwAQ057GHLAm+nt1i9L?= =?us-ascii?Q?2c807JdWytMcpemV6GP+vqKnt39K5liWYJgUlTVQ1+CQ2IqsDR7OeMWuS8S4?= =?us-ascii?Q?UPIgwmqW4da3bf0mda/54AYxVwGdoXousykmPF0jb38nM6EAfRNN4lyI2U1c?= =?us-ascii?Q?KixVg/2grJoyNJ4zBZ1wVj6fhgK5Kkbmzng6kVKDtnH8FWiROSW2nnNWMT84?= =?us-ascii?Q?yAUHm3busD7lEbF3C6ClLPdIw21?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2280; 6:LOFFoCGBySHOFKwumRPtzTW1DvifNSMy2SAzZximQxzAScfKsM/+s0ClYdoGNG9RPrX+b3fUNBSeDHpjhe7vqfu9QfTU/ntKcoyqkQF60RgzZtdR7TIsh7nWu6UsLqHm+25uj5ZbRrwl4lAFSXA41WSXviPclWC6F8L54wg/FFFn7OfudTKIaRMhT02ksvaNW8FGsYUdJ1sQ4EjjiBts0KulKXDLCA92lbS0MgqCNzqhBtbCct4f3+4chRHO3QSt5SIFX5loWc3xaFSyS/EdF47V/V8htpV9ed9w1HVvGtfCT4jkn69kCzbtBrMmoY+uQ/h5FVmtek+jDv7tZDg+SfhnrEUmPwOYkxQJn+2cCiha0dL6x0oEm7GJimgnGC5xxkI+0meHwAAHKEscnKCElQ==; 5:EY0YFLIz2vug/kAmY8rLWRnfcnS+4A1XiwZkOTOgZTpumTWY/3gzctN8YfseVSyuEt7ZMpYBDmvYb/MQ9Uhe2/WqoR4sJnP6MbcfRvkcgVvKTMp5DYFD9Fyep1Hlkr5ZTbvsGpi2ADQKI0xEgxlNZw==; 24:0rBqCASmqAHMmmx2VK8kGhamKQDXiPFGBFTJrCS2pHDaW8HJgCAcDlcnZ5tH8HWXjvO9HcTQU5N2eHS5FG2dx2YKjZCg9TzAMc9/7MMKqw8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2280; 7:FB6u6O9UNP0+F3HMjEn4swl6/uvWkA5OxsnQxQ9FDuq9KcoXbDCfLRD2FQFEbj/yTjR0OKjk1tmpzL9g43D7od1aPx/o+xsCnvV1FE/w9PbcDDTh7LWn6yA+ORYv60X3l5a1lNIl4oNpfz4NVG78OejJ22DFMG9It18SqnOW1AGWu21Xe7qCJkPsEcOLA5AjGXXy2V/HtEOl7BjUbvyjSolmwEso1CJoWfFZADEu5/zN34j2BRZea4ZpP9FZeZZN9+CVQ9H0OTd+kxsnnFIstOoivgJc115UKUUFxx2zV30/8TSdgP/3Irp2HDoxPlbG+9/mLzXDh0uWgUHIpZ+8lQ== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Mar 2017 06:27:18.8193 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2280 Subject: [dpdk-dev] [PATCH v3 09/46] net/liquidio: add mbox APIs for PF VF communication 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: Sat, 25 Mar 2017 06:27:23 -0000 Signed-off-by: Shijith Thotton Signed-off-by: Jerin Jacob Signed-off-by: Derek Chickles Signed-off-by: Venkat Koppula Signed-off-by: Srisivasubramanian S Signed-off-by: Mallesham Jatharakonda --- drivers/net/liquidio/Makefile | 1 + drivers/net/liquidio/base/lio_mbox.c | 275 +++++++++++++++++++++++++++++++++++ drivers/net/liquidio/base/lio_mbox.h | 129 ++++++++++++++++ drivers/net/liquidio/lio_struct.h | 3 + 4 files changed, 408 insertions(+) create mode 100644 drivers/net/liquidio/base/lio_mbox.c create mode 100644 drivers/net/liquidio/base/lio_mbox.h diff --git a/drivers/net/liquidio/Makefile b/drivers/net/liquidio/Makefile index 8880a10..451f49d 100644 --- a/drivers/net/liquidio/Makefile +++ b/drivers/net/liquidio/Makefile @@ -52,6 +52,7 @@ VPATH += $(RTE_SDK)/drivers/net/liquidio/base # SRCS-$(CONFIG_RTE_LIBRTE_LIO_PMD) += lio_ethdev.c SRCS-$(CONFIG_RTE_LIBRTE_LIO_PMD) += lio_23xx_vf.c +SRCS-$(CONFIG_RTE_LIBRTE_LIO_PMD) += lio_mbox.c # this lib depends upon: DEPDIRS-$(CONFIG_RTE_LIBRTE_LIO_PMD) += lib/librte_eal lib/librte_ether diff --git a/drivers/net/liquidio/base/lio_mbox.c b/drivers/net/liquidio/base/lio_mbox.c new file mode 100644 index 0000000..b4abc62 --- /dev/null +++ b/drivers/net/liquidio/base/lio_mbox.c @@ -0,0 +1,275 @@ +/* + * BSD LICENSE + * + * Copyright(c) 2017 Cavium, Inc.. All rights reserved. + * All rights reserved. + * + * 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, Inc. 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(S) 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 "lio_logs.h" +#include "lio_struct.h" +#include "lio_mbox.h" + +/** + * lio_mbox_read: + * @mbox: Pointer mailbox + * + * Reads the 8-bytes of data from the mbox register + * Writes back the acknowledgment indicating completion of read + */ +int +lio_mbox_read(struct lio_mbox *mbox) +{ + union lio_mbox_message msg; + int ret = 0; + + msg.mbox_msg64 = rte_read64(mbox->mbox_read_reg); + + if ((msg.mbox_msg64 == LIO_PFVFACK) || (msg.mbox_msg64 == LIO_PFVFSIG)) + return 0; + + if (mbox->state & LIO_MBOX_STATE_REQ_RECEIVING) { + mbox->mbox_req.data[mbox->mbox_req.recv_len - 1] = + msg.mbox_msg64; + mbox->mbox_req.recv_len++; + } else { + if (mbox->state & LIO_MBOX_STATE_RES_RECEIVING) { + mbox->mbox_resp.data[mbox->mbox_resp.recv_len - 1] = + msg.mbox_msg64; + mbox->mbox_resp.recv_len++; + } else { + if ((mbox->state & LIO_MBOX_STATE_IDLE) && + (msg.s.type == LIO_MBOX_REQUEST)) { + mbox->state &= ~LIO_MBOX_STATE_IDLE; + mbox->state |= LIO_MBOX_STATE_REQ_RECEIVING; + mbox->mbox_req.msg.mbox_msg64 = msg.mbox_msg64; + mbox->mbox_req.q_no = mbox->q_no; + mbox->mbox_req.recv_len = 1; + } else { + if ((mbox->state & + LIO_MBOX_STATE_RES_PENDING) && + (msg.s.type == LIO_MBOX_RESPONSE)) { + mbox->state &= + ~LIO_MBOX_STATE_RES_PENDING; + mbox->state |= + LIO_MBOX_STATE_RES_RECEIVING; + mbox->mbox_resp.msg.mbox_msg64 = + msg.mbox_msg64; + mbox->mbox_resp.q_no = mbox->q_no; + mbox->mbox_resp.recv_len = 1; + } else { + rte_write64(LIO_PFVFERR, + mbox->mbox_read_reg); + mbox->state |= LIO_MBOX_STATE_ERROR; + return -1; + } + } + } + } + + if (mbox->state & LIO_MBOX_STATE_REQ_RECEIVING) { + if (mbox->mbox_req.recv_len < msg.s.len) { + ret = 0; + } else { + mbox->state &= ~LIO_MBOX_STATE_REQ_RECEIVING; + mbox->state |= LIO_MBOX_STATE_REQ_RECEIVED; + ret = 1; + } + } else { + if (mbox->state & LIO_MBOX_STATE_RES_RECEIVING) { + if (mbox->mbox_resp.recv_len < msg.s.len) { + ret = 0; + } else { + mbox->state &= ~LIO_MBOX_STATE_RES_RECEIVING; + mbox->state |= LIO_MBOX_STATE_RES_RECEIVED; + ret = 1; + } + } else { + RTE_ASSERT(0); + } + } + + rte_write64(LIO_PFVFACK, mbox->mbox_read_reg); + + return ret; +} + +/** + * lio_mbox_write: + * @lio_dev: Pointer lio device + * @mbox_cmd: Cmd to send to mailbox. + * + * Populates the queue specific mbox structure + * with cmd information. + * Write the cmd to mbox register + */ +int +lio_mbox_write(struct lio_device *lio_dev, + struct lio_mbox_cmd *mbox_cmd) +{ + struct lio_mbox *mbox = lio_dev->mbox[mbox_cmd->q_no]; + uint32_t count, i, ret = LIO_MBOX_STATUS_SUCCESS; + + if ((mbox_cmd->msg.s.type == LIO_MBOX_RESPONSE) && + !(mbox->state & LIO_MBOX_STATE_REQ_RECEIVED)) + return LIO_MBOX_STATUS_FAILED; + + if ((mbox_cmd->msg.s.type == LIO_MBOX_REQUEST) && + !(mbox->state & LIO_MBOX_STATE_IDLE)) + return LIO_MBOX_STATUS_BUSY; + + if (mbox_cmd->msg.s.type == LIO_MBOX_REQUEST) { + rte_memcpy(&mbox->mbox_resp, mbox_cmd, + sizeof(struct lio_mbox_cmd)); + mbox->state = LIO_MBOX_STATE_RES_PENDING; + } + + count = 0; + + while (rte_read64(mbox->mbox_write_reg) != LIO_PFVFSIG) { + rte_delay_ms(1); + if (count++ == 1000) { + ret = LIO_MBOX_STATUS_FAILED; + break; + } + } + + if (ret == LIO_MBOX_STATUS_SUCCESS) { + rte_write64(mbox_cmd->msg.mbox_msg64, mbox->mbox_write_reg); + for (i = 0; i < (uint32_t)(mbox_cmd->msg.s.len - 1); i++) { + count = 0; + while (rte_read64(mbox->mbox_write_reg) != + LIO_PFVFACK) { + rte_delay_ms(1); + if (count++ == 1000) { + ret = LIO_MBOX_STATUS_FAILED; + break; + } + } + rte_write64(mbox_cmd->data[i], mbox->mbox_write_reg); + } + } + + if (mbox_cmd->msg.s.type == LIO_MBOX_RESPONSE) { + mbox->state = LIO_MBOX_STATE_IDLE; + rte_write64(LIO_PFVFSIG, mbox->mbox_read_reg); + } else { + if ((!mbox_cmd->msg.s.resp_needed) || + (ret == LIO_MBOX_STATUS_FAILED)) { + mbox->state &= ~LIO_MBOX_STATE_RES_PENDING; + if (!(mbox->state & (LIO_MBOX_STATE_REQ_RECEIVING | + LIO_MBOX_STATE_REQ_RECEIVED))) + mbox->state = LIO_MBOX_STATE_IDLE; + } + } + + return ret; +} + +/** + * lio_mbox_process_cmd: + * @mbox: Pointer mailbox + * @mbox_cmd: Pointer to command received + * + * Process the cmd received in mbox + */ +static int +lio_mbox_process_cmd(struct lio_mbox *mbox, + struct lio_mbox_cmd *mbox_cmd) +{ + struct lio_device *lio_dev = mbox->lio_dev; + + if (mbox_cmd->msg.s.cmd == LIO_CORES_CRASHED) + lio_dev_err(lio_dev, "Octeon core(s) crashed or got stuck!\n"); + + return 0; +} + +/** + * Process the received mbox message. + */ +int +lio_mbox_process_message(struct lio_mbox *mbox) +{ + struct lio_mbox_cmd mbox_cmd; + + if (mbox->state & LIO_MBOX_STATE_ERROR) { + if (mbox->state & (LIO_MBOX_STATE_RES_PENDING | + LIO_MBOX_STATE_RES_RECEIVING)) { + rte_memcpy(&mbox_cmd, &mbox->mbox_resp, + sizeof(struct lio_mbox_cmd)); + mbox->state = LIO_MBOX_STATE_IDLE; + rte_write64(LIO_PFVFSIG, mbox->mbox_read_reg); + mbox_cmd.recv_status = 1; + if (mbox_cmd.fn) + mbox_cmd.fn(mbox->lio_dev, &mbox_cmd, + mbox_cmd.fn_arg); + + return 0; + } + + mbox->state = LIO_MBOX_STATE_IDLE; + rte_write64(LIO_PFVFSIG, mbox->mbox_read_reg); + + return 0; + } + + if (mbox->state & LIO_MBOX_STATE_RES_RECEIVED) { + rte_memcpy(&mbox_cmd, &mbox->mbox_resp, + sizeof(struct lio_mbox_cmd)); + mbox->state = LIO_MBOX_STATE_IDLE; + rte_write64(LIO_PFVFSIG, mbox->mbox_read_reg); + mbox_cmd.recv_status = 0; + if (mbox_cmd.fn) + mbox_cmd.fn(mbox->lio_dev, &mbox_cmd, mbox_cmd.fn_arg); + + return 0; + } + + if (mbox->state & LIO_MBOX_STATE_REQ_RECEIVED) { + rte_memcpy(&mbox_cmd, &mbox->mbox_req, + sizeof(struct lio_mbox_cmd)); + if (!mbox_cmd.msg.s.resp_needed) { + mbox->state &= ~LIO_MBOX_STATE_REQ_RECEIVED; + if (!(mbox->state & LIO_MBOX_STATE_RES_PENDING)) + mbox->state = LIO_MBOX_STATE_IDLE; + rte_write64(LIO_PFVFSIG, mbox->mbox_read_reg); + } + + lio_mbox_process_cmd(mbox, &mbox_cmd); + + return 0; + } + + RTE_ASSERT(0); + + return 0; +} diff --git a/drivers/net/liquidio/base/lio_mbox.h b/drivers/net/liquidio/base/lio_mbox.h new file mode 100644 index 0000000..28c9e1a --- /dev/null +++ b/drivers/net/liquidio/base/lio_mbox.h @@ -0,0 +1,129 @@ +/* + * BSD LICENSE + * + * Copyright(c) 2017 Cavium, Inc.. All rights reserved. + * All rights reserved. + * + * 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, Inc. 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(S) 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. + */ + +#ifndef _LIO_MBOX_H_ +#define _LIO_MBOX_H_ + +#include + +#include + +/* Macros for Mail Box Communication */ + +#define LIO_MBOX_DATA_MAX 32 + +#define LIO_CORES_CRASHED 0x3 + +/* Macro for Read acknowledgment */ +#define LIO_PFVFACK 0xffffffffffffffff +#define LIO_PFVFSIG 0x1122334455667788 +#define LIO_PFVFERR 0xDEADDEADDEADDEAD + +enum lio_mbox_cmd_status { + LIO_MBOX_STATUS_SUCCESS = 0, + LIO_MBOX_STATUS_FAILED = 1, + LIO_MBOX_STATUS_BUSY = 2 +}; + +enum lio_mbox_message_type { + LIO_MBOX_REQUEST = 0, + LIO_MBOX_RESPONSE = 1 +}; + +union lio_mbox_message { + uint64_t mbox_msg64; + struct { + uint16_t type : 1; + uint16_t resp_needed : 1; + uint16_t cmd : 6; + uint16_t len : 8; + uint8_t params[6]; + } s; +}; + +typedef void (*lio_mbox_callback)(void *, void *, void *); + +struct lio_mbox_cmd { + union lio_mbox_message msg; + uint64_t data[LIO_MBOX_DATA_MAX]; + uint32_t q_no; + uint32_t recv_len; + uint32_t recv_status; + lio_mbox_callback fn; + void *fn_arg; +}; + +enum lio_mbox_state { + LIO_MBOX_STATE_IDLE = 1, + LIO_MBOX_STATE_REQ_RECEIVING = 2, + LIO_MBOX_STATE_REQ_RECEIVED = 4, + LIO_MBOX_STATE_RES_PENDING = 8, + LIO_MBOX_STATE_RES_RECEIVING = 16, + LIO_MBOX_STATE_RES_RECEIVED = 16, + LIO_MBOX_STATE_ERROR = 32 +}; + +struct lio_mbox { + /* A spinlock to protect access to this q_mbox. */ + rte_spinlock_t lock; + + struct lio_device *lio_dev; + + uint32_t q_no; + + enum lio_mbox_state state; + + /* SLI_MAC_PF_MBOX_INT for PF, SLI_PKT_MBOX_INT for VF. */ + void *mbox_int_reg; + + /* SLI_PKT_PF_VF_MBOX_SIG(0) for PF, + * SLI_PKT_PF_VF_MBOX_SIG(1) for VF. + */ + void *mbox_write_reg; + + /* SLI_PKT_PF_VF_MBOX_SIG(1) for PF, + * SLI_PKT_PF_VF_MBOX_SIG(0) for VF. + */ + void *mbox_read_reg; + + struct lio_mbox_cmd mbox_req; + + struct lio_mbox_cmd mbox_resp; + +}; + +int lio_mbox_read(struct lio_mbox *mbox); +int lio_mbox_write(struct lio_device *lio_dev, + struct lio_mbox_cmd *mbox_cmd); +int lio_mbox_process_message(struct lio_mbox *mbox); +#endif /* _LIO_MBOX_H_ */ diff --git a/drivers/net/liquidio/lio_struct.h b/drivers/net/liquidio/lio_struct.h index 577ea49..0af4fe3 100644 --- a/drivers/net/liquidio/lio_struct.h +++ b/drivers/net/liquidio/lio_struct.h @@ -126,6 +126,9 @@ struct lio_device { struct lio_sriov_info sriov_info; + /** Mail Box details of each lio queue. */ + struct lio_mbox **mbox; + char dev_string[LIO_DEVICE_NAME_LEN]; /* Device print string */ const struct lio_config *default_config; -- 1.8.3.1