From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50071.outbound.protection.outlook.com [40.107.5.71]) by dpdk.org (Postfix) with ESMTP id 0E61B1B910 for ; Fri, 12 Oct 2018 16:41:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZxcCJ9BygXyKUxvcCRE7xGIJH4j4Hu5wFcDLwenC/I8=; b=lGu01MnaXGUDf1MhQ8PaUlviNLlQRLeTm0hCpyjiM8/23RBhLt26vZ4lAH+dPqoCsmCDsVwwBIUedbfDk8XTJso7y6b+CIcoATJdiLfxi7DI2yPXIO+9G0ntDazQOJWNr9QgP26PUoxmMHAzcg4XsyAL1FKQooAf+xc6TDpk9xs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=G.Singh@nxp.com; Received: from Tophie.ap.freescale.net (14.142.187.166) by HE1PR04MB1530.eurprd04.prod.outlook.com (2a01:111:e400:59a8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.23; Fri, 12 Oct 2018 14:41:42 +0000 From: Gagandeep Singh To: dev@dpdk.org, akhil.goyal@nxp.com Cc: Gagandeep Singh , Hemant Agrawal Date: Fri, 12 Oct 2018 20:10:46 +0530 Message-Id: <20181012144055.9461-6-g.singh@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181012144055.9461-1-g.singh@nxp.com> References: <20180913060846.29930-1-g.singh@nxp.com> <20181012144055.9461-1-g.singh@nxp.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [14.142.187.166] X-ClientProxiedBy: PN1PR0101CA0039.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:c::25) To HE1PR04MB1530.eurprd04.prod.outlook.com (2a01:111:e400:59a8::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 390e6628-18f3-4879-ccee-08d63050d3ff X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:HE1PR04MB1530; X-Microsoft-Exchange-Diagnostics: 1; HE1PR04MB1530; 3:CRVoi48JrgPsqZbo14ByyHADFzJ3Xf1F6MLZoQeIjCm8z8X7NXTHpYF40YRh18y9ghP75NbINt0Ux79ZptiXgCXHttbQbYXKOuLJzoUpNW9A/qXHEC2J9aThh9ljLa/aqkaSk2BCWYyvNF/28guLFMQnQnFcCLHZ/JgwKgl9SDGpBQEURe7ejvtNbhFlM0hIrXgBd8aHw3iqf+x3UKuaqdPTgRyQLJey4p7dLJk7suZJxthC1138/RoOZAEL/yyZ; 25:GWnStcgh0qq6j6KoUzOyISD/tHVLGUSXsTehG77yYYELPLTz19Ba8baqwqvuZJanSTqnvPqygVjF12KcApvoc2ZW52QVAcmntidKNTUJtf32bR9m2DD1/Qef9R4nzZs4UGCalwHXNb8BeqOV6cOOFx74UP6+TFSVIjsF8reoFYHuNUh9SXFvblmPUorrOqvkYo3/SBld67x3U3p63uBRABpXYmyvwxLL+4aT2FersmUYNqfhAamXpXcpJE6Xa6ZGchuWCYfeiRG325t+sKVqiQvEgGarDX83PMJKG49dT8+vzI3m6RRbNVeRkwBEqibTIubEWS///Yfu7S3VNj1qaQ==; 31:flgH9qgc2UhELVqogr9El/YtTJS8PDakPYfJkOxUfgD5i4SjmRG0AugwuY6ZQklwfoCe+A1NXioWMSBkun65V3zv1/Oxx+fWcMbgKWabEgNKYBhYmUbMXvq/xUFYrj2b0NveXZkZmiMOb97CwPe3JpjKCVRnSGp/5k2092crvoGeObq5Iz1nRvwImgOVNxAmh0T/O0igCpBKV72R1i4f/27IgxyS9Gs1+DA7lsB/jbQ= X-MS-TrafficTypeDiagnostic: HE1PR04MB1530: X-Microsoft-Exchange-Diagnostics: 1; HE1PR04MB1530; 20:pdXQv0NxvDGRbojUSO/B8SMKxkE+jCWoIKY8r715r92dqmvR/4Vluoo/wC1ut/4EXsVkFyO3LGDYmvU9OfhKpwv0lTukiLVCMT4yBlPGUsl9tcvyZA6+JnhJLbCj9JC3KTjbpaNFbakKpQekUdWnXfJyHxIkT+fd4wvi70uy8kE6qT5lwcL47zaNi5uhc9CyaPt0wJIndHXBaOnWOSLD6hBnQZt5htywGM7nUuWKYwTKHcXXIsHLAg43TBwa6chynTg7yF6dCxP2ewdZav0xuMmMZOV7Bzi81q1JeQK+Z2VwbcYuiEwjWzz4kDyLqwlK/STdOZG441JM8hXOwG2RerHjDQvO+itQrk7gVTrY9JCI28F0Tijv/ZqhpR66X0YEQ4Jj4rI/5OHJLwbGO2pap+KOPvyG/h68j1xkipNlj3oH3zmxfbihfgN+E7FiNEkQo+TUxouUQZ20JqkSMsql+9qT6SshcwiQb2g+Lq8yRBtpGo6mm3rVSgZOSqHGKTOr; 4:TcbwZR3qZPkHXeU6kyNIgK7IsnOpJK4YnryArO7v3W9mYfc5NIG4DAkCO3ZfyXjhQG9qqDwv8Bs2oCPQIbNQaWBYy/4n3R1qBGPtDd7YiaDVb5kmb8quLRsh8SWLAGXRm4JiuXUyK45M8ZGjVFkZasHuHQbM3xXiibudTY6w2iP8auIHYPBuyym0QQWezydWl52Hx5v6dtVaTdnpMNl9MoqV3hexpRqtmdjIGUTbrevjYPYZmYnbnHtJ8QPZ4B3SbQREkxX/Kc1ZvaxIC9txDooUx2JDGtxFX/rPLTJcQN/38NGWfnZZr1/QLGWnMAD8EGBEk9KBQ8FUe0YWUnNj2auzndB1ZtW7Zwp4umQuFSc= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(192374486261705); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(3231355)(944501410)(52105095)(10201501046)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(201708071742011)(7699051); SRVR:HE1PR04MB1530; BCL:0; PCL:0; RULEID:; SRVR:HE1PR04MB1530; X-Forefront-PRVS: 0823A5777B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(376002)(366004)(396003)(136003)(39860400002)(189003)(199004)(316002)(305945005)(8936002)(386003)(55236004)(6636002)(6506007)(106356001)(25786009)(36756003)(4744004)(16586007)(5660300001)(72206003)(52116002)(53936002)(26005)(6512007)(478600001)(54906003)(68736007)(186003)(16526019)(50226002)(7736002)(105586002)(51416003)(97736004)(76176011)(78486009)(3846002)(2906002)(66066001)(1076002)(4326008)(956004)(446003)(2616005)(47776003)(11346002)(1006002)(6116002)(486006)(14444005)(476003)(8676002)(50466002)(48376002)(81156014)(86362001)(81166006)(6486002)(110426005); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR04MB1530; H:Tophie.ap.freescale.net; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR04MB1530; 23:yx/ZS3z5Ff7SitCguAcyuuYWiVwVJkfFibzKqBaK+?= =?us-ascii?Q?TI1247thE1n6d8g6nZQPmlHoMUEI7IT4oB7FSs3u8bAo2zkyPKR+lZ6N91Ou?= =?us-ascii?Q?euJsvd0iWPGU5UpZnE921FXS85mwTovOWo+yLZL0ffNCnCIt/eRmHmb70FvF?= =?us-ascii?Q?oVo5U5kI9Nrv/UeCZhQh6O8fKY+BfRWn+ims/mSouzx+k664AlKK0ZVPItxm?= =?us-ascii?Q?Kn/wIcDnD0jHDUz5u3VCIIGAAgx3xgF4NMCw65yoqtsOWVZfyxo4ePvfw76H?= =?us-ascii?Q?2gvqFnrY/cKsbVYFjPoGK1tKTty/XUtBo35BJMmCRWj05m956gHNbivc2VBc?= =?us-ascii?Q?FPTMgtvVas1GurF08Ge5VKplnuHXbkjmosNq9DCppXKDoD6jSzRqxhTIJVMY?= =?us-ascii?Q?x/WaYJ+Om1iUh7T0QFid5PUJQsq1w7ts667rzdYaYfkx2YkgittbFSnOZ982?= =?us-ascii?Q?T3iBCHNSNRp3NyOcSRVQuZpJgQCDvIKYkOcExfLYLGv+olgC3d2zXmVnYRk+?= =?us-ascii?Q?ymKotgIZgP+hkqBJMi9CgztIEqAWrwlFGfaIRmLlYOXC+zIfThpS1NWCZ8mS?= =?us-ascii?Q?42PxiFJ4IdNHGp52M/HjUQvwmNQZfoqndU38AaAlebn4fN9IOMIEZeFESjEm?= =?us-ascii?Q?KTdWmNV7eoolf7yN5Hkqd4CQG2CCDqkqkd6jNzjLiNKBOKAg+5r4ZkyH2sEj?= =?us-ascii?Q?vVD7gicBJWCF3Xziu4yedxYjd6Uvs7kk2VlPPXr/U90tluvIEkNCSd1pqOTu?= =?us-ascii?Q?mBOXGSfWR5r939a8ibyUX1X6tvZKM6GV07su2UoWCd4Qs+TasnqiEohV2fUi?= =?us-ascii?Q?Pph23cUttN1nj/4AlkdLqtHPaOVb6oa8u8UnCq6H6aHvuARa6O/6qXzsFwEo?= =?us-ascii?Q?fHePAKFveKShA/GZ4HJFB8kjo59HS5XT1efLjHeuMd3Nl+XtTIvXjTVseaR/?= =?us-ascii?Q?7rEdQwmU67GzgKjB677B6IlNV4KlXRsYjSGxGTU26a1dEdiyo1s/uMuVmAo1?= =?us-ascii?Q?ETdxeDerdAql1uycOm8bbw3/N3CxQrmbYsUM227nK5Hwgt27wwM31Ah+8p6u?= =?us-ascii?Q?YIPVTKb1582KqGwzC07HPyKpPNsFcCRhCJprqjzDlZOnOTmjd8nHbDvVyHTc?= =?us-ascii?Q?2Vy12LujsN3HZ7aj0q4yduKlz9NNonCBzRei2sv3j0RRM0zOC9B0R5p1afgx?= =?us-ascii?Q?L9jkB1YrAf7+6n3KYr7esUFa56ORWL5jBIIVBxHlAPPxEYf90C3F4MAwElLp?= =?us-ascii?Q?mRFpJ/bzl2ni5Y3okhCtcYn8axdyRypcQ0xmjtjNs8PcvqGgMEqopTZjfnEq?= =?us-ascii?Q?zoDXbVxzRT7NTUsps+HZHe43sHV6SG0+Ekzi05Yq3IH?= X-Microsoft-Antispam-Message-Info: DtSCPqP3oJSthU3CBEoozuWkI/inTUcJFnRkOiJm0wNiYcW0G70dCygRv0IxqpcPdqTrnvGanXsMkFzidMiWEySEbyz3WNluN3Jou1Gp7BF3bVf3KRHoSflsYG60hwLKEPo0pjfRWwMHJ9fu0u2XlBTdIcOlq65YeFlwERqkdaKQZnw+G1kPv8tHPkN6A64goMPTl4hF6L8oMvY6ep1Aen5rYoTOFGFeiJXEQF8li39qLFHozqu9t0vMO4d8ntXYiom/DMtxETrCTDQWlj4bLNgpGVsoU48YQQRepGPr9lUVKVSJv+BysjQ7+fCciOrtzKDA3+piN8diF+N7l0tEJG+2sij62f6ZyOBi+HBN/us= X-Microsoft-Exchange-Diagnostics: 1; HE1PR04MB1530; 6:c3akjjz2t9tYCMyJ/PLpOJj6h7Fyh8sz11w087GNA6KlQkG59/xrpVUiUPJHmLCuow04+NKnIZl7UvPIysKurUm/ZsA9nCw/fGYqDBGQRe7cmxfx6aqHzGtSbP24Bfips36XFSADRiPB9KbgRmr6QHAZfME9IXiIbaEQufbom6ji0xLRk7xemO4NC2UivmnLv1fy5Dvo6RBzpHViGM/C8SVDiCpM5GYZ8NFMpxkgSRyPa40H3010dLX8nv4wqdc7CZbpr2W8bwCXlKcHBo1NJEz4XrLfRODOk0yw8dF9ZfCkBo/sYYtutTQICkFPeDfW/oBDCy5fIpmyb6lcGcJlmn5+ti8H2RN70X8nsAt/tpNZt03D38q8QieX4N7gggz6r5MvKxQJWd4VIIvUSui1gI/fFi/GtiVRS8ZpVVhcHXalY9GLWdanwLPB+k/7v+u573fNveDgXB2Sd+KuQvmLug==; 5:ZSibFCGnxMTkhcxNqTqxho4gV0k+y8TGl3El4N9m6PACEjz3WaeHjDZlQESoTLwMh/RmWkSl0weWyc1XfvUGq1arTwPzTX0U6BFscm8YCYjFfF9oyaYfPANHjc9B2DvS3WYh7m0C2byCJQRfz5xIMWFIO4jgdo2/ErZftXLMXok=; 7:E2T2Y6qvSFcFpjZkxHkmV7YTyxNg17DYIKX6E/k7oWSxBvpIcNJaBojopZ5DuXyp+h9CI5GlMUrrgu71ENSolo4oXAiQ1LsB6vWXdKnhKHKvQMoqaCGkEuaVIx1jFxiy40G8gF7CTrEsFgZSrjSYJdhetjd8EqbGRng0IM/o16ZYDSOF3Piw+rCJ3XO0q3iIUTuYWuQBoR3MrtQ38XnD60S2VDxBkpQ+Unh9l0LOFcTmy2ZRxRyKxjyy/eCO5UQx SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2018 14:41:42.0058 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 390e6628-18f3-4879-ccee-08d63050d3ff X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR04MB1530 Subject: [dpdk-dev] [PATCH v2 05/14] crypto/caam_jr: add basic job ring routines 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, 12 Oct 2018 14:41:45 -0000 This patch adds following job ring routines - init_job_ring (configure hw/sw resources) - shutdown_job_ring (releases hw/sw resources) - close_job_ring (flush job ring) Signed-off-by: Gagandeep Singh Signed-off-by: Hemant Agrawal --- drivers/crypto/caam_jr/caam_jr.c | 329 ++++++++++++++++++++++++++++++- 1 file changed, 327 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/caam_jr/caam_jr.c b/drivers/crypto/caam_jr/caam_jr.c index 27331194a..cb024a979 100644 --- a/drivers/crypto/caam_jr/caam_jr.c +++ b/drivers/crypto/caam_jr/caam_jr.c @@ -17,12 +17,142 @@ #include #include +#include +#include +#include #include +/* RTA header files */ +#include +#include + #define CRYPTODEV_NAME_CAAM_JR_PMD crypto_caam_jr static uint8_t cryptodev_driver_id; int caam_jr_logtype; +enum rta_sec_era rta_sec_era; + +/* Lists the states possible for the SEC user space driver. */ +enum sec_driver_state_e { + SEC_DRIVER_STATE_IDLE, /* Driver not initialized */ + SEC_DRIVER_STATE_STARTED, /* Driver initialized and can be used*/ + SEC_DRIVER_STATE_RELEASE, /* Driver release is in progress */ +}; + +/* Job rings used for communication with SEC HW */ +static struct sec_job_ring_t g_job_rings[MAX_SEC_JOB_RINGS]; + +/* The current state of SEC user space driver */ +static enum sec_driver_state_e g_driver_state = SEC_DRIVER_STATE_IDLE; + +/* The number of job rings used by SEC user space driver */ +static int g_job_rings_no; +static int g_job_rings_max; + +/* @brief Poll the HW for already processed jobs in the JR + * and silently discard the available jobs or notify them to UA + * with indicated error code. + * + * @param [in,out] job_ring The job ring to poll. + * @param [in] do_notify Can be #TRUE or #FALSE. Indicates if + * descriptors are to be discarded + * or notified to UA with given error_code. + * @param [out] notified_descs Number of notified descriptors. Can be NULL + * if do_notify is #FALSE + */ +static void +hw_flush_job_ring(struct sec_job_ring_t *job_ring, + uint32_t do_notify, + uint32_t *notified_descs) +{ + int32_t jobs_no_to_discard = 0; + int32_t discarded_descs_no = 0; + + PMD_INIT_FUNC_TRACE(); + CAAM_JR_DEBUG("Jr[%p] pi[%d] ci[%d].Flushing jr notify desc=[%d]", + job_ring, job_ring->pidx, job_ring->cidx, do_notify); + + jobs_no_to_discard = hw_get_no_finished_jobs(job_ring); + + /* Discard all jobs */ + CAAM_JR_DEBUG("Jr[%p] pi[%d] ci[%d].Discarding %d descs", + job_ring, job_ring->pidx, job_ring->cidx, + jobs_no_to_discard); + + while (jobs_no_to_discard > discarded_descs_no) { + discarded_descs_no++; + /* Now increment the consumer index for the current job ring, + * AFTER saving job in temporary location! + * Increment the consumer index for the current job ring + */ + job_ring->cidx = SEC_CIRCULAR_COUNTER(job_ring->cidx, + SEC_JOB_RING_SIZE); + + hw_remove_entries(job_ring, 1); + } + + if (do_notify == true) { + ASSERT(notified_descs != NULL); + *notified_descs = discarded_descs_no; + } +} + + +/* @brief Flush job rings of any processed descs. + * The processed descs are silently dropped, + * WITHOUT being notified to UA. + */ +static void +close_job_ring(struct sec_job_ring_t *job_ring) +{ + PMD_INIT_FUNC_TRACE(); + if (job_ring->irq_fd) { + /* Producer index is frozen. If consumer index is not equal + * with producer index, then we have descs to flush. + */ + while (job_ring->pidx != job_ring->cidx) + hw_flush_job_ring(job_ring, false, NULL); + + /* free the uio job ring */ + free_job_ring(job_ring->irq_fd); + job_ring->irq_fd = 0; + caam_jr_dma_free(job_ring->input_ring); + caam_jr_dma_free(job_ring->output_ring); + g_job_rings_no--; + } +} + +/** @brief Release the software and hardware resources tied to a job ring. + * @param [in] job_ring The job ring + * + * @retval 0 for success + * @retval -1 for error + */ +static int +shutdown_job_ring(struct sec_job_ring_t *job_ring) +{ + int ret = 0; + + PMD_INIT_FUNC_TRACE(); + ASSERT(job_ring != NULL); + ret = hw_shutdown_job_ring(job_ring); + SEC_ASSERT(ret == 0, ret, + "Failed to shutdown hardware job ring %p", + job_ring); + + if (job_ring->coalescing_en) + hw_job_ring_disable_coalescing(job_ring); + + if (job_ring->jr_mode != SEC_NOTIFICATION_TYPE_POLL) { + ret = caam_jr_disable_irqs(job_ring->irq_fd); + SEC_ASSERT(ret == 0, ret, + "Failed to disable irqs for job ring %p", + job_ring); + } + + return ret; +} + /* * @brief Release the resources used by the SEC user space driver. * @@ -40,28 +170,195 @@ int caam_jr_logtype; static int caam_jr_dev_uninit(struct rte_cryptodev *dev) { + struct sec_job_ring_t *internals; + + PMD_INIT_FUNC_TRACE(); if (dev == NULL) return -ENODEV; + internals = dev->data->dev_private; + rte_free(dev->security_ctx); + + /* If any descriptors in flight , poll and wait + * until all descriptors are received and silently discarded. + */ + if (internals) { + shutdown_job_ring(internals); + close_job_ring(internals); + rte_mempool_free(internals->ctx_pool); + } + CAAM_JR_INFO("Closing crypto device %s", dev->data->name); - return 0; + /* last caam jr instance) */ + if (g_job_rings_no == 0) + g_driver_state = SEC_DRIVER_STATE_IDLE; + + return SEC_SUCCESS; +} + +/* @brief Initialize the software and hardware resources tied to a job ring. + * @param [in] jr_mode; Model to be used by SEC Driver to receive + * notifications from SEC. Can be either + * of the three: #SEC_NOTIFICATION_TYPE_NAPI + * #SEC_NOTIFICATION_TYPE_IRQ or + * #SEC_NOTIFICATION_TYPE_POLL + * @param [in] NAPI_mode The NAPI work mode to configure a job ring at + * startup. Used only when #SEC_NOTIFICATION_TYPE + * is set to #SEC_NOTIFICATION_TYPE_NAPI. + * @param [in] irq_coalescing_timer This value determines the maximum + * amount of time after processing a + * descriptor before raising an interrupt. + * @param [in] irq_coalescing_count This value determines how many + * descriptors are completed before + * raising an interrupt. + * @param [in] reg_base_addr, The job ring base address register + * @param [in] irq_id The job ring interrupt identification number. + * @retval job_ring_handle for successful job ring configuration + * @retval NULL on error + * + */ +static void * +init_job_ring(void *reg_base_addr, uint32_t irq_id) +{ + struct sec_job_ring_t *job_ring = NULL; + int i, ret = 0; + int jr_mode = SEC_NOTIFICATION_TYPE_POLL; + int napi_mode = 0; + int irq_coalescing_timer = 0; + int irq_coalescing_count = 0; + + for (i = 0; i < MAX_SEC_JOB_RINGS; i++) { + if (g_job_rings[i].irq_fd == 0) { + job_ring = &g_job_rings[i]; + g_job_rings_no++; + break; + } + } + if (job_ring == NULL) { + CAAM_JR_ERR("No free job ring\n"); + return NULL; + } + + job_ring->register_base_addr = reg_base_addr; + job_ring->jr_mode = jr_mode; + job_ring->napi_mode = 0; + job_ring->irq_fd = irq_id; + + /* Allocate mem for input and output ring */ + + /* Allocate memory for input ring */ + job_ring->input_ring = caam_jr_dma_mem_alloc(L1_CACHE_BYTES, + SEC_DMA_MEM_INPUT_RING_SIZE); + memset(job_ring->input_ring, 0, SEC_DMA_MEM_INPUT_RING_SIZE); + + /* Allocate memory for output ring */ + job_ring->output_ring = caam_jr_dma_mem_alloc(L1_CACHE_BYTES, + SEC_DMA_MEM_OUTPUT_RING_SIZE); + memset(job_ring->output_ring, 0, SEC_DMA_MEM_OUTPUT_RING_SIZE); + + /* Reset job ring in SEC hw and configure job ring registers */ + ret = hw_reset_job_ring(job_ring); + if (ret != 0) { + CAAM_JR_ERR("Failed to reset hardware job ring"); + goto cleanup; + } + + if (jr_mode == SEC_NOTIFICATION_TYPE_NAPI) { + /* When SEC US driver works in NAPI mode, the UA can select + * if the driver starts with IRQs on or off. + */ + if (napi_mode == SEC_STARTUP_INTERRUPT_MODE) { + CAAM_JR_INFO("Enabling DONE IRQ generationon job ring - %p", + job_ring); + ret = caam_jr_enable_irqs(job_ring->irq_fd); + if (ret != 0) { + CAAM_JR_ERR("Failed to enable irqs for job ring"); + goto cleanup; + } + } + } else if (jr_mode == SEC_NOTIFICATION_TYPE_IRQ) { + /* When SEC US driver works in pure interrupt mode, + * IRQ's are always enabled. + */ + CAAM_JR_INFO("Enabling DONE IRQ generation on job ring - %p", + job_ring); + ret = caam_jr_enable_irqs(job_ring->irq_fd); + if (ret != 0) { + CAAM_JR_ERR("Failed to enable irqs for job ring"); + goto cleanup; + } + } + if (irq_coalescing_timer || irq_coalescing_count) { + hw_job_ring_set_coalescing_param(job_ring, + irq_coalescing_timer, + irq_coalescing_count); + + hw_job_ring_enable_coalescing(job_ring); + job_ring->coalescing_en = 1; + } + + job_ring->jr_state = SEC_JOB_RING_STATE_STARTED; + job_ring->max_nb_queue_pairs = RTE_CAAM_MAX_NB_SEC_QPS; + job_ring->max_nb_sessions = RTE_CAAM_JR_PMD_MAX_NB_SESSIONS; + + return job_ring; +cleanup: + caam_jr_dma_free(job_ring->output_ring); + caam_jr_dma_free(job_ring->input_ring); + return NULL; } + static int caam_jr_dev_init(const char *name, struct rte_vdev_device *vdev, struct rte_cryptodev_pmd_init_params *init_params) { struct rte_cryptodev *dev; + struct uio_job_ring *job_ring; + char str[RTE_CRYPTODEV_NAME_MAX_LEN]; PMD_INIT_FUNC_TRACE(); + /* Validate driver state */ + if (g_driver_state == SEC_DRIVER_STATE_IDLE) { + g_job_rings_max = sec_configure(); + if (!g_job_rings_max) { + CAAM_JR_ERR("No job ring detected on UIO !!!!"); + return -1; + } + /* Update driver state */ + g_driver_state = SEC_DRIVER_STATE_STARTED; + } + + if (g_job_rings_no >= g_job_rings_max) { + CAAM_JR_ERR("No more job rings available max=%d!!!!", + g_job_rings_max); + return -1; + } + + job_ring = config_job_ring(); + if (job_ring == NULL) { + CAAM_JR_ERR("failed to create job ring"); + goto init_error; + } + + snprintf(str, sizeof(str), "caam_jr%d", job_ring->jr_id); + dev = rte_cryptodev_pmd_create(name, &vdev->device, init_params); if (dev == NULL) { CAAM_JR_ERR("failed to create cryptodev vdev"); goto cleanup; } + /*TODO free it during teardown*/ + dev->data->dev_private = init_job_ring(job_ring->register_base_addr, + job_ring->uio_fd); + + if (!dev->data->dev_private) { + CAAM_JR_ERR("Ring memory allocation failed\n"); + goto cleanup2; + } dev->driver_id = cryptodev_driver_id; dev->dev_ops = NULL; @@ -79,7 +376,12 @@ caam_jr_dev_init(const char *name, return 0; +cleanup2: + caam_jr_dev_uninit(dev); + rte_cryptodev_pmd_release_device(dev); cleanup: + free_job_ring(job_ring->uio_fd); +init_error: CAAM_JR_ERR("driver %s: cryptodev_caam_jr_create failed", init_params->name); @@ -92,7 +394,7 @@ cryptodev_caam_jr_probe(struct rte_vdev_device *vdev) { struct rte_cryptodev_pmd_init_params init_params = { "", - 128, + sizeof(struct sec_job_ring_t), rte_socket_id(), RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS }; @@ -106,6 +408,29 @@ cryptodev_caam_jr_probe(struct rte_vdev_device *vdev) input_args = rte_vdev_device_args(vdev); rte_cryptodev_pmd_parse_input_args(&init_params, input_args); + /* if sec device version is not configured */ + if (!rta_get_sec_era()) { + const struct device_node *caam_node; + + for_each_compatible_node(caam_node, NULL, "fsl,sec-v4.0") { + const uint32_t *prop = of_get_property(caam_node, + "fsl,sec-era", + NULL); + if (prop) { + rta_set_sec_era( + INTL_SEC_ERA(cpu_to_caam32(*prop))); + break; + } + } + } +#ifdef RTE_LIBRTE_PMD_CAAM_JR_BE + if (rta_get_sec_era() > RTA_SEC_ERA_8) { + RTE_LOG(ERR, PMD, + "CAAM is compiled in BE mode for device with sec era > 8???\n"); + return -EINVAL; + } +#endif + return caam_jr_dev_init(name, vdev, &init_params); } -- 2.17.1