From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 6E4C04C8D for ; Fri, 1 Mar 2019 19:42:35 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x21IVLBC020367; Fri, 1 Mar 2019 10:42:34 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=5FNNX9EYFWALoZnVV15nE4YBQ54uYXFxP/5Qg8f0hLw=; b=H5Decix/rNlLC1LCsMSX6Puysy06tdwzEMdtYeF4NDVEf6NqZriZS6EwjnmbSIQIzMof Ees47Gn8vZbiNg1WfmekDoXnAnIrUmRrPwZnsCPiBYj35ZUjeSyKUmt0adbtoktbsbP8 sHGW6cRW1BuwDyF5iB1T+qvP6kti39sKsgd1OUrV3YZv9IrrZl+vtmNPU7a6HsrSCwih ZaC0tbJEzOezEgYp/9VgPS7B9tqCm/B4/KZRRgF8fwES4NMkPfvC/GJ09jjJyPVk4LCj /f9zqZSkOnupLdgkxGRC3wXd+Hc/2Njw+VlSkX2o4tWupeJ/ji9PC/U1GQ4HpHw/9at8 Ig== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 2qxce64ga1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 01 Mar 2019 10:42:34 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 1 Mar 2019 10:42:31 -0800 Received: from NAM05-CO1-obe.outbound.protection.outlook.com (104.47.48.57) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Fri, 1 Mar 2019 10:42:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5FNNX9EYFWALoZnVV15nE4YBQ54uYXFxP/5Qg8f0hLw=; b=ssUqQ83Z2Fef9dLWjrTLDGxmnAhfBfYdfKtFgdZ52Mh1y7kwGb80T6v3RhJxBeLMyKATSHvnmc2y1N0JpzaKgbD6oTSNAtu+7Y7XVi+56iNnu4OFo2XGFp9CnQvaw8ah3KFbvNeCUfFhT2I74zF4rV9vZEEkO28mggKmv2V4CUI= Received: from MN2PR18MB2877.namprd18.prod.outlook.com (20.179.20.218) by MN2PR18MB2605.namprd18.prod.outlook.com (20.179.83.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1665.18; Fri, 1 Mar 2019 18:42:27 +0000 Received: from MN2PR18MB2877.namprd18.prod.outlook.com ([fe80::1905:8cf6:f4a1:5d9a]) by MN2PR18MB2877.namprd18.prod.outlook.com ([fe80::1905:8cf6:f4a1:5d9a%4]) with mapi id 15.20.1665.017; Fri, 1 Mar 2019 18:42:27 +0000 From: Anoob Joseph To: Akhil Goyal , Pablo de Lara CC: Anoob Joseph , Jerin Jacob Kollanukkaran , Narayana Prasad Raju Athreya , Suheil Chandran , Ankur Dwivedi , "dev@dpdk.org" , Archana Muniganti Thread-Topic: [PATCH 2/3] common/cpt: redesign propagation of error Thread-Index: AQHU0F6EswBR3W4jrk2xTqxN2G+FCQ== Date: Fri, 1 Mar 2019 18:42:27 +0000 Message-ID: <1551465683-26721-2-git-send-email-anoobj@marvell.com> References: <1551465683-26721-1-git-send-email-anoobj@marvell.com> In-Reply-To: <1551465683-26721-1-git-send-email-anoobj@marvell.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BMXPR01CA0008.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:d::18) To MN2PR18MB2877.namprd18.prod.outlook.com (2603:10b6:208:3b::26) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.7.4 x-originating-ip: [115.113.156.2] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e1b6208f-0128-4a62-259a-08d69e75a6d1 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(2017052603328)(7153060)(7193020); SRVR:MN2PR18MB2605; x-ms-traffictypediagnostic: MN2PR18MB2605: x-microsoft-exchange-diagnostics: =?iso-8859-1?Q?1; MN2PR18MB2605; 23:K0xnLNhIFCq4sYpAJ09UIhxGuGqPBV9NEbINKDd?= =?iso-8859-1?Q?/Jv0jVxXWrZaPQAI9g1m9DuEPlPw2ZbAUnZrkVeUTPAuOHBXWbiU5nIeOm?= =?iso-8859-1?Q?kmQKvYiP7z02Y9+DHBghMiOS1NHptbJLN2w2Avd/n2LiW/o7h3FSw3oJQr?= =?iso-8859-1?Q?ik8j/Q8V/xtdb15/G05c2/6evnceLml4+RSkz1Gg21uE1cnt0sVQ/q7Aef?= =?iso-8859-1?Q?StF0JDVxp3dEWOMmTnvevwRn3z4Er/VwfeakUXwv/+1uru65/f6J06ZT92?= =?iso-8859-1?Q?h01r6sD39F0nAZ6IwkHZ07TwL4fw90pRv/N3skgbRYnlui6yHxBVCv0D/f?= =?iso-8859-1?Q?7XuEb7FUnXiw2lJiJOGFm3ZoyD1mkWKjW7uw7WLytuYmUUkQPTAFsAGAYm?= =?iso-8859-1?Q?piUdlfBJfG+0Vq0veWIR/9nr/AhFfNRrtaAchPtKtI9MDay/Rz0oCFLKqP?= =?iso-8859-1?Q?+jELI0F0zNA0jLxZOvoBA9h4GML0w38leMqonzgKaDjJoyEpEiHOJ0iLTQ?= =?iso-8859-1?Q?zOefj6zVDVjHGQJwN/ir5xFAgLGm5zdVg72+x3Ecu/9N/WDTj7gqSHSpLT?= =?iso-8859-1?Q?NAFKZZYmZPPdj8Sot3nFHJsh4ubxr6OAnGfou0AF9oL5+I3QC8u2DEBM+U?= =?iso-8859-1?Q?kCXZF+Cvf1DNhki5JLG6AbOWPOZR/uBUDbepdcCES7z4Bx1IflgFRf/FCG?= =?iso-8859-1?Q?6j8yqfPILq5YR7scvMjjn07cGNeeZ7aOsYWkdZakkmDSczjyJHYs8qwcqX?= =?iso-8859-1?Q?09k1NlDo0JY0XFvhXx0hWSi73UmXeGXFT8Mf7o+oxv/qDAtrXUekdQ+TD0?= =?iso-8859-1?Q?caPMfqSOSVmmXzWEo6hED37gbxnnvSNcysf3VepNXO8AX3sIQoxDLTKKUv?= =?iso-8859-1?Q?qTKsF9QbO0KifZ6fPXrzEg27JOv9blB5fylCMF5cp9+OWWINvA3E3wt5ju?= =?iso-8859-1?Q?143zKo8obv8Pd5H+pTfOJdcuQuVt4suOxvwYHa5kw3nbovPl6akqVcrUrR?= =?iso-8859-1?Q?V53ejKVN/lsNFnDAtlJBdqDt6r5pfmfJnrSOpjBApwHnNaUUMBXm0DR+5c?= =?iso-8859-1?Q?5m4AwCmu8kY06eIK8Rminb1FW/Z6oUQFENDfGriuZSR1rQPbLNDSRpJ2K7?= =?iso-8859-1?Q?6H9EA3AbN6q6aic6hmKUWAbnL0/1RfrWwdfE1VyygNgL8rEMDbS8fzg6kT?= =?iso-8859-1?Q?kRORVaDly8eH1f4IMvgwbnE0OLVuLtNNVvaF20D85gbShdF7DS/Jet15Ny?= =?iso-8859-1?Q?vLoExCqn3wmyxRz91eY2imivhrHmK31038+PU8tF3XpS09Dwuel/W0VH2W?= =?iso-8859-1?Q?Ly6H4qttzoJdy7iV4wrmrIpQz5AzRZqcXoNiMMPz6TVNQ=3D=3D?= x-microsoft-antispam-prvs: x-forefront-prvs: 09634B1196 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(136003)(346002)(376002)(39850400004)(396003)(189003)(199004)(6436002)(66066001)(68736007)(71200400001)(25786009)(4326008)(107886003)(6486002)(50226002)(14454004)(53946003)(6512007)(5660300002)(36756003)(71190400001)(305945005)(7736002)(53936002)(478600001)(81166006)(8676002)(8936002)(316002)(81156014)(476003)(2616005)(11346002)(26005)(102836004)(55236004)(106356001)(3846002)(186003)(86362001)(6116002)(110136005)(54906003)(99286004)(256004)(14444005)(76176011)(52116002)(6506007)(105586002)(386003)(486006)(30864003)(446003)(97736004)(2906002); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR18MB2605; H:MN2PR18MB2877.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: +D724BPxQALUvySHd90qTDGRaihGJTPPqudEIJHMHL2qfMLxk31JMRx7prR0AHDsmEVbSCbasTf+EehZ8vJAYH3/0RblDCBRa5epWgm0A+1GqEfoGm0lMBq4ZeB+rPvEAnFPy6LA1t1K1b0t8V5dPQUQFf5O/6DSNFgvgibRFRzac4q1lh6lf+dKo92R5HaAZ7zhCNdaCI4jF07qMoUENBacWgFegs+Um3Nq7eWh13QW1Ujh6lizAg7JWbSjH/cHM32UqXhRxTgfddh0izaWF/vfAaLbQQykkZM6Y49lXEZk8+yEfy1365CyQX/JdhsS1wlH7T0s3xr9/yeOzKMQ9nEP/uPZMHxUDOczBhvtrtBWOi0gMnGx2rE9KCBpVXiWQuE7LzgWJ0HJDuYxQD6+/sK5ylnBVf0j0Ow4fv6uV90= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: e1b6208f-0128-4a62-259a-08d69e75a6d1 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Mar 2019 18:42:27.0763 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR18MB2605 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-03-01_12:, , signatures=0 X-Proofpoint-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903010128 Subject: [dpdk-dev] [PATCH 2/3] common/cpt: redesign propagation of error 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, 01 Mar 2019 18:42:35 -0000 The check for prep_req is good enough to flag error. The return var passed around is redundant. Fixing this. Also making the functions return correct error values in case of various failures. In addition, adding unlikely flag for all error checks. Signed-off-by: Ankur Dwivedi Signed-off-by: Anoob Joseph Signed-off-by: Archana Muniganti --- drivers/common/cpt/cpt_request_mgr.h | 12 +- drivers/common/cpt/cpt_ucode.h | 318 ++++++++++++++++++++-----------= ---- 2 files changed, 189 insertions(+), 141 deletions(-) diff --git a/drivers/common/cpt/cpt_request_mgr.h b/drivers/common/cpt/cpt_= request_mgr.h index 4463cfb..81bddf4 100644 --- a/drivers/common/cpt/cpt_request_mgr.h +++ b/drivers/common/cpt/cpt_request_mgr.h @@ -111,17 +111,17 @@ cpt_pmd_crypto_operation(struct cpt_instance *instanc= e, =20 cpt_op =3D sess->cpt_op; =20 - mdata =3D &(cptvf->meta_info); - if (likely(cpt_op & CPT_OP_CIPHER_MASK)) - prep_req =3D fill_fc_params(op, sess, &mdata, &ret); + ret =3D fill_fc_params(op, sess, &cptvf->meta_info, &mdata, + &prep_req); else - prep_req =3D fill_digest_params(op, sess, &mdata, &ret); + ret =3D fill_digest_params(op, sess, &cptvf->meta_info, + &mdata, &prep_req); =20 - if (unlikely(!prep_req)) { + if (unlikely(ret)) { CPT_LOG_DP_ERR("prep cryto req : op %p, cpt_op 0x%x " "ret 0x%x", op, (unsigned int)cpt_op, ret); - goto req_fail; + return ret; } =20 /* Enqueue prepared instruction to HW */ diff --git a/drivers/common/cpt/cpt_ucode.h b/drivers/common/cpt/cpt_ucode.= h index 5933ea7..37c74f9 100644 --- a/drivers/common/cpt/cpt_ucode.h +++ b/drivers/common/cpt/cpt_ucode.h @@ -458,7 +458,7 @@ fill_sg_comp_from_iov(sg_comp_t *list, return (uint32_t)i; } =20 -static __rte_always_inline int +static __rte_always_inline void cpt_digest_gen_prep(uint32_t flags, uint64_t d_lens, digest_params_t *params, @@ -483,18 +483,9 @@ cpt_digest_gen_prep(uint32_t flags, uint64_t c_dma, m_dma; opcode_info_t opcode; =20 - if (!params || !params->ctx_buf.vaddr) - return ERR_BAD_INPUT_ARG; - ctx =3D params->ctx_buf.vaddr; meta_p =3D ¶ms->meta_buf; =20 - if (!meta_p->vaddr || !meta_p->dma_addr) - return ERR_BAD_INPUT_ARG; - - if (meta_p->size < sizeof(struct cpt_request_info)) - return ERR_BAD_INPUT_ARG; - m_vaddr =3D meta_p->vaddr; m_dma =3D meta_p->dma_addr; m_size =3D meta_p->size; @@ -582,10 +573,10 @@ cpt_digest_gen_prep(uint32_t flags, if (size) { i =3D fill_sg_comp_from_iov(gather_comp, i, params->src_iov, 0, &size, NULL, 0); - if (size) { + if (unlikely(size)) { CPT_LOG_DP_DEBUG("Insufficient dst IOV size, short" " by %dB", size); - return ERR_BAD_INPUT_ARG; + return; } } else { /* @@ -605,8 +596,10 @@ cpt_digest_gen_prep(uint32_t flags, scatter_comp =3D (sg_comp_t *)((uint8_t *)gather_comp + g_size_bytes); =20 if (flags & VALID_MAC_BUF) { - if (params->mac_buf.size < mac_len) - return ERR_BAD_INPUT_ARG; + if (unlikely(params->mac_buf.size < mac_len)) { + CPT_LOG_DP_ERR("Insufficient MAC size"); + return; + } =20 size =3D mac_len; i =3D fill_sg_comp_from_buf_min(scatter_comp, i, @@ -616,10 +609,10 @@ cpt_digest_gen_prep(uint32_t flags, i =3D fill_sg_comp_from_iov(scatter_comp, i, params->src_iov, data_len, &size, NULL, 0); - if (size) { - CPT_LOG_DP_DEBUG("Insufficient dst IOV size, short by" - " %dB", size); - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient dst IOV size, short by" + " %dB", size); + return; } } =20 @@ -663,10 +656,10 @@ cpt_digest_gen_prep(uint32_t flags, req->op =3D op; =20 *prep_req =3D req; - return 0; + return; } =20 -static __rte_always_inline int +static __rte_always_inline void cpt_enc_hmac_prep(uint32_t flags, uint64_t d_offs, uint64_t d_lens, @@ -922,7 +915,7 @@ cpt_enc_hmac_prep(uint32_t flags, if (unlikely(size)) { CPT_LOG_DP_ERR("Insufficient buffer space," " size %d needed", size); - return ERR_BAD_INPUT_ARG; + return; } } ((uint16_t *)in_buffer)[2] =3D rte_cpu_to_be_16(i); @@ -964,8 +957,12 @@ cpt_enc_hmac_prep(uint32_t flags, aad_buf, aad_offset); } - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer" + " space, size %d needed", + size); + return; + } } /* mac_data */ if (mac_len) { @@ -998,7 +995,7 @@ cpt_enc_hmac_prep(uint32_t flags, CPT_LOG_DP_ERR("Insufficient buffer" " space, size %d needed", size); - return ERR_BAD_INPUT_ARG; + return; } } } @@ -1048,10 +1045,10 @@ cpt_enc_hmac_prep(uint32_t flags, req->op =3D op; =20 *prep_req =3D req; - return 0; + return; } =20 -static __rte_always_inline int +static __rte_always_inline void cpt_dec_hmac_prep(uint32_t flags, uint64_t d_offs, uint64_t d_lens, @@ -1303,8 +1300,12 @@ cpt_dec_hmac_prep(uint32_t flags, aad_buf, aad_offset); } - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer" + " space, size %d needed", + size); + return; + } } =20 /* mac data */ @@ -1325,8 +1326,10 @@ cpt_dec_hmac_prep(uint32_t flags, uint32_t aad_offset =3D aad_len ? passthrough_len : 0; =20 - if (!fc_params->src_iov) - return ERR_BAD_INPUT_ARG; + if (unlikely(!fc_params->src_iov)) { + CPT_LOG_DP_ERR("Bad input args"); + return; + } =20 i =3D fill_sg_comp_from_iov( gather_comp, i, @@ -1336,8 +1339,12 @@ cpt_dec_hmac_prep(uint32_t flags, aad_offset); } =20 - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer" + " space, size %d needed", + size); + return; + } } } ((uint16_t *)in_buffer)[2] =3D rte_cpu_to_be_16(i); @@ -1370,8 +1377,10 @@ cpt_dec_hmac_prep(uint32_t flags, uint32_t aad_offset =3D aad_len ? passthrough_len : 0; =20 - if (!fc_params->dst_iov) - return ERR_BAD_INPUT_ARG; + if (unlikely(!fc_params->dst_iov)) { + CPT_LOG_DP_ERR("Bad input args"); + return; + } =20 i =3D fill_sg_comp_from_iov(scatter_comp, i, fc_params->dst_iov, 0, @@ -1379,8 +1388,11 @@ cpt_dec_hmac_prep(uint32_t flags, aad_offset); } =20 - if (unlikely(size)) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer space," + " size %d needed", size); + return; + } } =20 ((uint16_t *)in_buffer)[3] =3D rte_cpu_to_be_16(i); @@ -1430,10 +1442,10 @@ cpt_dec_hmac_prep(uint32_t flags, req->op =3D op; =20 *prep_req =3D req; - return 0; + return; } =20 -static __rte_always_inline int +static __rte_always_inline void cpt_zuc_snow3g_enc_prep(uint32_t req_flags, uint64_t d_offs, uint64_t d_lens, @@ -1654,8 +1666,11 @@ cpt_zuc_snow3g_enc_prep(uint32_t req_flags, i =3D fill_sg_comp_from_iov(gather_comp, i, params->src_iov, 0, &size, NULL, 0); - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer space," + " size %d needed", size); + return; + } } ((uint16_t *)in_buffer)[2] =3D rte_cpu_to_be_16(i); g_size_bytes =3D ((i + 3) / 4) * sizeof(sg_comp_t); @@ -1686,8 +1701,11 @@ cpt_zuc_snow3g_enc_prep(uint32_t req_flags, params->dst_iov, 0, &size, NULL, 0); =20 - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer space," + " size %d needed", size); + return; + } } =20 /* mac data */ @@ -1703,8 +1721,11 @@ cpt_zuc_snow3g_enc_prep(uint32_t req_flags, params->dst_iov, 0, &size, NULL, 0); =20 - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer space," + " size %d needed", size); + return; + } } } ((uint16_t *)in_buffer)[3] =3D rte_cpu_to_be_16(i); @@ -1752,10 +1773,10 @@ cpt_zuc_snow3g_enc_prep(uint32_t req_flags, req->op =3D op; =20 *prep_req =3D req; - return 0; + return; } =20 -static __rte_always_inline int +static __rte_always_inline void cpt_zuc_snow3g_dec_prep(uint32_t req_flags, uint64_t d_offs, uint64_t d_lens, @@ -1946,8 +1967,11 @@ cpt_zuc_snow3g_dec_prep(uint32_t req_flags, i =3D fill_sg_comp_from_iov(gather_comp, i, params->src_iov, 0, &size, NULL, 0); - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer space," + " size %d needed", size); + return; + } } ((uint16_t *)in_buffer)[2] =3D rte_cpu_to_be_16(i); g_size_bytes =3D ((i + 3) / 4) * sizeof(sg_comp_t); @@ -1972,8 +1996,11 @@ cpt_zuc_snow3g_dec_prep(uint32_t req_flags, params->dst_iov, 0, &size, NULL, 0); =20 - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer space," + " size %d needed", size); + return; + } } ((uint16_t *)in_buffer)[3] =3D rte_cpu_to_be_16(i); s_size_bytes =3D ((i + 3) / 4) * sizeof(sg_comp_t); @@ -2020,10 +2047,10 @@ cpt_zuc_snow3g_dec_prep(uint32_t req_flags, req->op =3D op; =20 *prep_req =3D req; - return 0; + return; } =20 -static __rte_always_inline int +static __rte_always_inline void cpt_kasumi_enc_prep(uint32_t req_flags, uint64_t d_offs, uint64_t d_lens, @@ -2171,8 +2198,11 @@ cpt_kasumi_enc_prep(uint32_t req_flags, params->src_iov, 0, &size, NULL, 0); =20 - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer space," + " size %d needed", size); + return; + } } ((uint16_t *)in_buffer)[2] =3D rte_cpu_to_be_16(i); g_size_bytes =3D ((i + 3) / 4) * sizeof(sg_comp_t); @@ -2204,8 +2234,11 @@ cpt_kasumi_enc_prep(uint32_t req_flags, params->dst_iov, 0, &size, NULL, 0); =20 - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer space," + " size %d needed", size); + return; + } } =20 /* mac data */ @@ -2221,8 +2254,11 @@ cpt_kasumi_enc_prep(uint32_t req_flags, params->dst_iov, 0, &size, NULL, 0); =20 - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer space," + " size %d needed", size); + return; + } } } ((uint16_t *)in_buffer)[3] =3D rte_cpu_to_be_16(i); @@ -2269,10 +2305,10 @@ cpt_kasumi_enc_prep(uint32_t req_flags, req->op =3D op; =20 *prep_req =3D req; - return 0; + return; } =20 -static __rte_always_inline int +static __rte_always_inline void cpt_kasumi_dec_prep(uint64_t d_offs, uint64_t d_lens, fc_params_t *params, @@ -2393,8 +2429,11 @@ cpt_kasumi_dec_prep(uint64_t d_offs, i =3D fill_sg_comp_from_iov(gather_comp, i, params->src_iov, 0, &size, NULL, 0); - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer space," + " size %d needed", size); + return; + } } ((uint16_t *)in_buffer)[2] =3D rte_cpu_to_be_16(i); g_size_bytes =3D ((i + 3) / 4) * sizeof(sg_comp_t); @@ -2417,8 +2456,11 @@ cpt_kasumi_dec_prep(uint64_t d_offs, i =3D fill_sg_comp_from_iov(scatter_comp, i, params->dst_iov, 0, &size, NULL, 0); - if (size) - return ERR_BAD_INPUT_ARG; + if (unlikely(size)) { + CPT_LOG_DP_ERR("Insufficient buffer space," + " size %d needed", size); + return; + } } ((uint16_t *)in_buffer)[3] =3D rte_cpu_to_be_16(i); s_size_bytes =3D ((i + 3) / 4) * sizeof(sg_comp_t); @@ -2464,7 +2506,7 @@ cpt_kasumi_dec_prep(uint64_t d_offs, req->op =3D op; =20 *prep_req =3D req; - return 0; + return; } =20 static __rte_always_inline void * @@ -2472,69 +2514,57 @@ cpt_fc_dec_hmac_prep(uint32_t flags, uint64_t d_offs, uint64_t d_lens, fc_params_t *fc_params, - void *op, int *ret_val) + void *op) { struct cpt_ctx *ctx =3D fc_params->ctx_buf.vaddr; uint8_t fc_type; void *prep_req =3D NULL; - int ret; =20 fc_type =3D ctx->fc_type; =20 if (likely(fc_type =3D=3D FC_GEN)) { - ret =3D cpt_dec_hmac_prep(flags, d_offs, d_lens, - fc_params, op, &prep_req); + cpt_dec_hmac_prep(flags, d_offs, d_lens, fc_params, op, + &prep_req); } else if (fc_type =3D=3D ZUC_SNOW3G) { - ret =3D cpt_zuc_snow3g_dec_prep(flags, d_offs, d_lens, - fc_params, op, &prep_req); + cpt_zuc_snow3g_dec_prep(flags, d_offs, d_lens, fc_params, op, + &prep_req); } else if (fc_type =3D=3D KASUMI) { - ret =3D cpt_kasumi_dec_prep(d_offs, d_lens, fc_params, op, - &prep_req); - } else { - /* - * For AUTH_ONLY case, - * MC only supports digest generation and verification - * should be done in software by memcmp() - */ - - ret =3D ERR_EIO; + cpt_kasumi_dec_prep(d_offs, d_lens, fc_params, op, &prep_req); } =20 - if (unlikely(!prep_req)) - *ret_val =3D ret; + /* + * For AUTH_ONLY case, + * MC only supports digest generation and verification + * should be done in software by memcmp() + */ + return prep_req; } =20 static __rte_always_inline void *__hot cpt_fc_enc_hmac_prep(uint32_t flags, uint64_t d_offs, uint64_t d_lens, - fc_params_t *fc_params, void *op, int *ret_val) + fc_params_t *fc_params, void *op) { struct cpt_ctx *ctx =3D fc_params->ctx_buf.vaddr; uint8_t fc_type; void *prep_req =3D NULL; - int ret; =20 fc_type =3D ctx->fc_type; =20 /* Common api for rest of the ops */ if (likely(fc_type =3D=3D FC_GEN)) { - ret =3D cpt_enc_hmac_prep(flags, d_offs, d_lens, - fc_params, op, &prep_req); + cpt_enc_hmac_prep(flags, d_offs, d_lens, fc_params, op, + &prep_req); } else if (fc_type =3D=3D ZUC_SNOW3G) { - ret =3D cpt_zuc_snow3g_enc_prep(flags, d_offs, d_lens, - fc_params, op, &prep_req); + cpt_zuc_snow3g_enc_prep(flags, d_offs, d_lens, fc_params, op, + &prep_req); } else if (fc_type =3D=3D KASUMI) { - ret =3D cpt_kasumi_enc_prep(flags, d_offs, d_lens, - fc_params, op, &prep_req); + cpt_kasumi_enc_prep(flags, d_offs, d_lens, fc_params, op, + &prep_req); } else if (fc_type =3D=3D HASH_HMAC) { - ret =3D cpt_digest_gen_prep(flags, d_lens, fc_params, op, - &prep_req); - } else { - ret =3D ERR_EIO; + cpt_digest_gen_prep(flags, d_lens, fc_params, op, &prep_req); } =20 - if (unlikely(!prep_req)) - *ret_val =3D ret; return prep_req; } =20 @@ -3114,20 +3144,20 @@ prepare_iov_from_pkt_inplace(struct rte_mbuf *pkt, return 0; } =20 -static __rte_always_inline void * +static __rte_always_inline int fill_fc_params(struct rte_crypto_op *cop, struct cpt_sess_misc *sess_misc, + struct cptvf_meta_info *cpt_m_info, void **mdata_ptr, - int *op_ret) + void **prep_req) { uint32_t space =3D 0; struct rte_crypto_sym_op *sym_op =3D cop->sym; - void *mdata; + void *mdata =3D NULL; uintptr_t *op; uint32_t mc_hash_off; uint32_t flags =3D 0; uint64_t d_offs, d_lens; - void *prep_req =3D NULL; struct rte_mbuf *m_src, *m_dst; uint8_t cpt_op =3D sess_misc->cpt_op; uint8_t zsk_flag =3D sess_misc->zsk_flag; @@ -3142,8 +3172,7 @@ fill_fc_params(struct rte_crypto_op *cop, char src[SRC_IOV_SIZE]; char dst[SRC_IOV_SIZE]; uint32_t iv_buf[4]; - struct cptvf_meta_info *cpt_m_info =3D - (struct cptvf_meta_info *)(*mdata_ptr); + int ret; =20 if (likely(sess_misc->iv_length)) { flags |=3D VALID_IV_BUF; @@ -3289,8 +3318,8 @@ fill_fc_params(struct rte_crypto_op *cop, &fc_params, &flags))) { CPT_LOG_DP_ERR("Prepare inplace src iov failed"); - *op_ret =3D -1; - return NULL; + ret =3D -EINVAL; + goto err_exit; } =20 } else { @@ -3301,8 +3330,8 @@ fill_fc_params(struct rte_crypto_op *cop, /* Store SG I/O in the api for reuse */ if (prepare_iov_from_pkt(m_src, fc_params.src_iov, 0)) { CPT_LOG_DP_ERR("Prepare src iov failed"); - *op_ret =3D -1; - return NULL; + ret =3D -EINVAL; + goto err_exit; } =20 if (unlikely(m_dst !=3D NULL)) { @@ -3319,14 +3348,16 @@ fill_fc_params(struct rte_crypto_op *cop, "m_dst %p, need %u" " more", m_dst, pkt_len); - return NULL; + ret =3D -EINVAL; + goto err_exit; } } =20 if (prepare_iov_from_pkt(m_dst, fc_params.dst_iov, 0)) { CPT_LOG_DP_ERR("Prepare dst iov failed for " "m_dst %p", m_dst); - return NULL; + ret =3D -EINVAL; + goto err_exit; } } else { fc_params.dst_iov =3D (void *)src; @@ -3346,7 +3377,8 @@ fill_fc_params(struct rte_crypto_op *cop, =20 if (unlikely(mdata =3D=3D NULL)) { CPT_LOG_DP_ERR("Error allocating meta buffer for request"); - return NULL; + ret =3D -ENOMEM; + goto err_exit; } =20 op =3D (uintptr_t *)((uintptr_t)mdata & (uintptr_t)~1ull); @@ -3361,16 +3393,26 @@ fill_fc_params(struct rte_crypto_op *cop, =20 /* Finally prepare the instruction */ if (cpt_op & CPT_OP_ENCODE) - prep_req =3D cpt_fc_enc_hmac_prep(flags, d_offs, d_lens, - &fc_params, op, op_ret); + *prep_req =3D cpt_fc_enc_hmac_prep(flags, d_offs, d_lens, + &fc_params, op); else - prep_req =3D cpt_fc_dec_hmac_prep(flags, d_offs, d_lens, - &fc_params, op, op_ret); + *prep_req =3D cpt_fc_dec_hmac_prep(flags, d_offs, d_lens, + &fc_params, op); + + if (unlikely(*prep_req =3D=3D NULL)) { + CPT_LOG_DP_ERR("Preparing request failed due to bad input arg"); + ret =3D -EINVAL; + goto free_mdata_and_exit; + } =20 - if (unlikely(!prep_req)) - free_op_meta(mdata, cpt_m_info->cptvf_meta_pool); *mdata_ptr =3D mdata; - return prep_req; + + return 0; + +free_mdata_and_exit: + free_op_meta(mdata, cpt_m_info->cptvf_meta_pool); +err_exit: + return ret; } =20 static __rte_always_inline void @@ -3476,11 +3518,12 @@ find_kasumif9_direction_and_length(uint8_t *src, /* * This handles all auth only except AES_GMAC */ -static __rte_always_inline void * +static __rte_always_inline int fill_digest_params(struct rte_crypto_op *cop, struct cpt_sess_misc *sess, + struct cptvf_meta_info *cpt_m_info, void **mdata_ptr, - int *op_ret) + void **prep_req) { uint32_t space =3D 0; struct rte_crypto_sym_op *sym_op =3D cop->sym; @@ -3490,7 +3533,6 @@ fill_digest_params(struct rte_crypto_op *cop, uint32_t auth_range_off; uint32_t flags =3D 0; uint64_t d_offs =3D 0, d_lens; - void *prep_req =3D NULL; struct rte_mbuf *m_src, *m_dst; uint16_t auth_op =3D sess->cpt_op & CPT_OP_AUTH_MASK; uint8_t zsk_flag =3D sess->zsk_flag; @@ -3498,9 +3540,9 @@ fill_digest_params(struct rte_crypto_op *cop, fc_params_t params; char src[SRC_IOV_SIZE]; uint8_t iv_buf[16]; + int ret; + memset(¶ms, 0, sizeof(fc_params_t)); - struct cptvf_meta_info *cpt_m_info =3D - (struct cptvf_meta_info *)(*mdata_ptr); =20 m_src =3D sym_op->m_src; =20 @@ -3508,9 +3550,8 @@ fill_digest_params(struct rte_crypto_op *cop, mdata =3D alloc_op_meta(NULL, ¶ms.meta_buf, cpt_m_info->cptvf_op_mlen= , cpt_m_info->cptvf_meta_pool); if (mdata =3D=3D NULL) { - CPT_LOG_DP_ERR("Error allocating meta buffer for request"); - *op_ret =3D -ENOMEM; - return NULL; + ret =3D -ENOMEM; + goto err_exit; } =20 mphys =3D params.meta_buf.dma_addr; @@ -3597,7 +3638,8 @@ fill_digest_params(struct rte_crypto_op *cop, if (!rte_pktmbuf_append(m_dst, space)) { CPT_LOG_DP_ERR("Failed to extend " "mbuf by %uB", space); - goto err; + ret =3D -EINVAL; + goto free_mdata_and_exit; } =20 params.mac_buf.vaddr =3D @@ -3626,18 +3668,24 @@ fill_digest_params(struct rte_crypto_op *cop, /*Store SG I/O in the api for reuse */ if (prepare_iov_from_pkt(m_src, params.src_iov, auth_range_off)) { CPT_LOG_DP_ERR("Prepare src iov failed"); - *op_ret =3D -1; - goto err; + ret =3D -EINVAL; + goto free_mdata_and_exit; + } + + *prep_req =3D cpt_fc_enc_hmac_prep(flags, d_offs, d_lens, ¶ms, op); + if (unlikely(*prep_req =3D=3D NULL)) { + ret =3D -EINVAL; + goto free_mdata_and_exit; } =20 - prep_req =3D cpt_fc_enc_hmac_prep(flags, d_offs, d_lens, - ¶ms, op, op_ret); *mdata_ptr =3D mdata; - return prep_req; -err: - if (unlikely(!prep_req)) - free_op_meta(mdata, cpt_m_info->cptvf_meta_pool); - return NULL; + + return 0; + +free_mdata_and_exit: + free_op_meta(mdata, cpt_m_info->cptvf_meta_pool); +err_exit: + return ret; } =20 #endif /*_CPT_UCODE_H_ */ --=20 2.7.4