From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700058.outbound.protection.outlook.com [40.107.70.58]) by dpdk.org (Postfix) with ESMTP id C9A035F51 for ; Fri, 8 Jun 2018 18:49:07 +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:X-MS-Exchange-SenderADCheck; bh=fq+dCjl+O1Olox7RRGcxN8T0EkwfJrvc/r7vzaR4a84=; b=oWFd46nWez1jW9kUYAmxFuxPZqYJ2GSEsrv6r3IumI67GsK+zqu+AbyO3IRvW/qXmPjrBFSd3kJ4OTcnzKbv/M0F7t0zqNVjxyQgbeJF9YOuSGy7sy7a7rjvdJdy6wpNRcU6PDopdSawmcTLb4+KzWrlumYww8pBa5kuu+gYUv0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Anoob.Joseph@cavium.com; Received: from ajoseph83.caveonetworks.com.caveonetworks.com (115.113.156.2) by SN6PR07MB4911.namprd07.prod.outlook.com (2603:10b6:805:3c::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.820.15; Fri, 8 Jun 2018 16:49:01 +0000 From: Anoob Joseph To: Akhil Goyal , Pablo de Lara , Thomas Monjalon Cc: Ankur Dwivedi , Jerin Jacob , Murthy NSSR , Narayana Prasad , Nithin Dabilpuram , Ragothaman Jayaraman , Srisivasubramanian Srinivasan , dev@dpdk.org Date: Fri, 8 Jun 2018 22:15:15 +0530 Message-Id: <1528476325-15585-7-git-send-email-anoob.joseph@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528476325-15585-1-git-send-email-anoob.joseph@caviumnetworks.com> References: <1528476325-15585-1-git-send-email-anoob.joseph@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [115.113.156.2] X-ClientProxiedBy: BM1PR01CA0071.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:1::11) To SN6PR07MB4911.namprd07.prod.outlook.com (2603:10b6:805:3c::29) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:SN6PR07MB4911; X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 3:4s8CcQtOAtGULlYVYVHuaVd91ZmVkbzMkeIDaqZfE/GfnY1vxkbNMWwh6H88iQsRJfG/26U64qfIyjJKFOqQtrUfjQcS9S5L93oFQo2hVhpqOz9KKpr0+4MIvrs+XB2etIumk7mxg934lzSeeCJhtly6AF5gUhcI75hw04k+kbpg4lf/xZm+j5zUrd+twzeDEWBEsl5uJFJARWWagep3T62roMMGNGxhQEvYmJbnJ6DUtb73VD+WoxdQVJpDecsL; 25:G4DeRYjPFJrVZXS4f4Qr8PM8O6NyKL6ZRTQulVu/XrSgZYqQhfXL6n/H4AhpRCTrlTXEHsKcqgjpA6I9R4naIwDTFbscK6q8lADOFvCl+2sH8fIBqkdeQZlgI6mND5Yp76rDHFRV3qtxliX5lJNQzQFOJmzjPdBHaiYAUOTyEnel+QGMOP+AWQMMVDonHtLYyn2Q6MRNQSxNbj1dduVKxBqXi9ba6kRwQTX5LquwNtkkIgsL1i734beC4sixbWMQhIyasfpfgOWJskJoFVjdK8w/A9vyVJSPhIPy/jXpBI92kE7VehSDhpO2e5NkHIGdIcTZivD7xXh+fiXEcWRQaw==; 31:BFccUIuIjh4cDxAaFGgWtze8HUArxtMQDVrLYl0h7p1DWzIsi83aB4KeFkkWYgluo3QrQ71D/6lOFCUTRzkVMrl8WFSoZpjPqvTG6DJ4huWUhR/QDLhEiw5JqQej9qSfknd6Wpfqhd840j18AWsFSvxpABrqhTaR1OX46gNnHDMiqtfSwHLIyi2f8iB9eq+tMt9kSUeqDgcLqdOSfwIk2g1wJjzGOEKGhMbPI6GHWQI= X-MS-TrafficTypeDiagnostic: SN6PR07MB4911: X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 20:coq6Rhnb16LSW8WDJ/BmKD6NUrEyTxdm7GxHUdnf1QFtlAyaJwB3luq8vj3WiFY5wKSuzAK/sJjPpTWfBoCntSlN+zLlEr4dAvFXrFS6XpbBt2e9FaABaYQCer013DLZMFhNPP1mfpl3rndOICbJs+DzPqFApwGbcgIHz50omJobPWdWN73KuidcYHMXKiJw4Ltiwyj3zOC3jGjf8/DzAQfdEo7z5lqB1/mZk3HZjvhHrQEyh/2hNuTPKhV30WPvvVuXMp77++MXH6oXxZsAxvHB51WbYLJ/hoR+nVsZ7vbXdq3wSG+z5lACQnJgNjnvVcTrR91P0n1kxE1gwcwa0U5bLDwhXE54MmaDyy77/mmCri3CCfq1hD5Fb2fxrND36TemrfMjt7yOCoXEFxD1SpEdIUx1VsEy4Q68k9A9HCJ4yOKVD3yu/8wZBUgC4KnWKDUmz+3z7AGRla++NOS87SFSwaI6NaM+2Gu9RJLJKWssTL//vi9wbaBX/+CkzfP2eo7tfo0Re0dyOqVWThz1dIq/lK10vFQgX96NlU5L8mTnFMSgh6c2VJnD1Zu2SBrudPfUFqXYcUAbanb0tA19H/JseToca4x0vhUZ7rcYKfA=; 4:LJ7w9/6x0WTql8q2iUGBuHukjic4PYv1cs5DGpuop7MRZ6czZYE/o12eC3Awhrm4TKrtvju887kjRL5zQR0Tkt/ik5qrCG0ITLTtenUZaHaPZTMCVLMbSc12DOX36KfMBFV3iPMbYBHdd/4cCZhVMaRC3FsRHSpy7gESigE9WblkWdlXj45nbzU3pqUy1M4pMqeyXuYHylvcLBs8MIabpWrEarTShj3Zr+3mhlXTTwZwFAblCP6hLzQQejnHb0qSZYAT5NRV20rRFVa76HX4xw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(3002001)(3231254)(944501410)(52105095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:SN6PR07MB4911; BCL:0; PCL:0; RULEID:; SRVR:SN6PR07MB4911; X-Forefront-PRVS: 06973FFAD3 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(396003)(346002)(39380400002)(366004)(39860400002)(189003)(199004)(26005)(52116002)(956004)(305945005)(8676002)(81156014)(50226002)(8936002)(81166006)(7736002)(68736007)(105586002)(106356001)(3846002)(6116002)(72206003)(478600001)(6486002)(97736004)(6506007)(16586007)(6512007)(53946003)(53936002)(47776003)(486006)(25786009)(5660300001)(50466002)(48376002)(6666003)(4326008)(54906003)(76176011)(36756003)(110136005)(66066001)(8656006)(2906002)(316002)(55236004)(11346002)(16526019)(386003)(186003)(59450400001)(446003)(476003)(42882007)(44832011)(2616005)(51416003); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR07MB4911; H:ajoseph83.caveonetworks.com.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN6PR07MB4911; 23:Kx0G/7fJngPtODg1mh95CaefuKcTsdKEe8K/H8Bar?= =?us-ascii?Q?S3HXzhzPi3cttpqtkxuix4ikItSSG9+LJ8pS/3dwLaMkkbagET6ZPXSAksuw?= =?us-ascii?Q?DX38VSeBa46acr0rpB3P1UJ2obb7zfUKE+GSmO+mxvstUmWpsaDNdgtB21k5?= =?us-ascii?Q?+UZ0zEdwTOY7Y8ijENXHIaS53ehpXdY8YDKYaX8ZCNv7Re2MpF2AYn+eKFM2?= =?us-ascii?Q?kDTdZrhgKuOK+Zztvv7gHUs6zLIHrRkX+E+VjY1URnSzZO4fWp5rGWAftP+D?= =?us-ascii?Q?cADejMbuSVdlXmGxhZFYu8FpsKhky+KAduP0Fv42znrzxcrVeGKM8l3vLWgX?= =?us-ascii?Q?ul/UbkEjM7qfoWV5T2F3hUo3xrsQpCFuuoiv+TK/i3bnp6wstZXGP5O63Acb?= =?us-ascii?Q?BprreAAVxC3fulVcDjjP3+plO1NE5WVbZf9TXdIyrP5DfUElZNQZ0OI9ERM5?= =?us-ascii?Q?VPkVJ8IbBS8/jk/8jpDiHvv0EgxqjGW3XhRcsSeHqMlD2CxCe5YYpCmAtLOr?= =?us-ascii?Q?YWLOJtwDDJxXDgd4V2dknHpihNFp1pHK8uJGb9tnCO9LN/pHEnNQgCkXq941?= =?us-ascii?Q?TDOOJCBWzCPM91MWOrH+xjahowFdFzE10iP3yEGNFk3brwrwGGxEe0/qVZBw?= =?us-ascii?Q?HCE59jfzFSs1jK1eO1rdX5FESVGUoUKdqVSY9PSgRoPFzxXwrw/MGC1iC8tE?= =?us-ascii?Q?2CtyzrELHcaD1mGLOEZgK53326vZgHwRcLomjZShZYaZiWqC8sbbUHg8spR8?= =?us-ascii?Q?VghQdE1GBYoN3+7023xL9CAv6b23uquh1CcGHUCDIZ8/Ymx1HUF50zGJQ1DB?= =?us-ascii?Q?olfeNmwt2BsEsgAQRjbw5DBpJE+YtzWU9OwVBDzXwRYjSzxEAJGc7guHT9CO?= =?us-ascii?Q?dUz2E+ORh2CHGjDsz8xzgaS3jDWYmT/FZOe+w5cpmLPpG5modV94YHgCRcY3?= =?us-ascii?Q?XSrAKBHP/lS6dm2G2JkhQ5c9UXjaqd7Aa7ZJhnPbSvBzAbMsvL5hnXDu5sj3?= =?us-ascii?Q?kk0LbxXF9RWCuVNwuqdqHBNpYmfydOAPMjFNTgVLS/x8KlWsAxAIe3RbyEiz?= =?us-ascii?Q?mby4De797teYrlK0WXawlOWFSRYB+5JZCLKcr4ufIJ3WRyzrAWTwLah/HM5p?= =?us-ascii?Q?uWcjWFvCWitYUzvJ1s6noXmROJtbTUtJ5YXSGJvZ+SY/bLzHa/ib1Oqmp/Im?= =?us-ascii?Q?V38NxghSeufJzaWQQtNA247qkK94Yeruswd4aRI4n75WQX3sUnqZGHDJovgh?= =?us-ascii?Q?elOgDFPZs09y60rDjiWwzaCNEmH4svaLOLl8A8V3zPoYs16y0wRxaW/0utJY?= =?us-ascii?Q?MZB4Yo9v08nYFGDFe8HnOZ/9k50lFgqziBRrB66dDul?= X-Microsoft-Antispam-Message-Info: qNJW73Mu4dLjqixiitXMXzIyWjgS+K3HcNYG0fMh9EX83Y1Qs16DsSjqOdKLTLu5ilbxrhSRm1tIS7rGPftemiijrolAF9wZ2MvsESobUiU0800HVXFhl+x9uIZWlnkFW0L1TXXIPbr8Xe/mqJLvBBn5rWogmDScm00ug9GXCB4nBfPl1i5e+JjfQurQ94CN X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 6:ZSA1Blf69ctqO9kRJB+Cz3sMkTNFui9PLx7IuPeZzeVkGaRD17kUX6NxmLSIq4TcsYxHB1sdPKxkyWBVTjKCEV8a8utQ01yQ75uit8itJwYLRR8XzIQ1OQe4btNHaPBBN+nVBf0WssR/z30gYFVVi/ymF6UIi0SCWd7xxIMD2TI8nJf+PVBmk6i+iICapL2EuzXtctO9riKZpEK3Ng1HKuaKRbTnOoUsjTLsy7XoOynT8K8eEt38DbbnOL4iPQQrfhcsTA4YY/AK4Ypomh0cjb2tP51sUagPTlFgPdj7HaU7RGbvp2QvXHNPpudk3yMzGIRa3y2y/qXZiqYhTooya9oz7UbtfLU1LjeN866246q50jqzH2MIjSMgQR8d9WI1R/rxQzIZNsnHkoJcoWqvQwVWBLxlSJbrkmfLrygdSHmrNL7l3jGQWTy1KSpdiXf5doRbevHwL/zxEfjvtx6Gag==; 5:RHdgn6bWQUOEL9deQjr/vrObnx+7CsJqg/dimd5mE4ja7gdlC/jz1UG0FX+s90jp7atvQ4T89iySMpOt/MdE2cWQUy78maywUgqS9y/qB94GyJOx3T6bMxl+OmxUp51OGLyabr9GqA7dVOuyeX+vhdTaugHhHJPuwjzfJ17EbCE=; 24:pEaV+Vt4R6HvE3yJZJwdoHpePxQyN209M8S/ONUSF5UjBPBHHqkPYDIEZ1dEvlr0fCSTtsHbWYmtmKQvzk8rh8CO5KdKxUk0s1ODvLaXrWY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 7:XjJjtH0PrJZMSo6dAQqVP2tWbfV1UJQctzy4b4lTF98jvrqIUTgd0m0m0ShFZewpUkcM3T0kAxK97oqR1xm/gkIV/gZm1sWQ/o4uhBBOWxBHGK23/dc8G0anMM3xpnwOzYocQyZT4fvwmqP9sKbFO4Y/tnOFA2LdSLdyU9Wb8K1Wro80OXMi6tUZ4t2PJoYT+rTyGnZAcn+3M+VJxcZw9oQ+Fd3TM3nQIbIQLPw7+Adf4lMW3VKoZ5wEOQ4rSzG0 X-MS-Office365-Filtering-Correlation-Id: 44c76f33-465e-47c1-9dfa-08d5cd5fbefc X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2018 16:49:01.6958 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 44c76f33-465e-47c1-9dfa-08d5cd5fbefc X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR07MB4911 Subject: [dpdk-dev] [PATCH 06/16] crypto/cpt/base: add sym crypto request prepare for CPT 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, 08 Jun 2018 16:49:08 -0000 From: Ankur Dwivedi These functions help in preparing symmetric crypto requests for the supported cipher/auth/aead. This includes all supported algos except Kasumi, Snow3G, Zuc, HMAC_ONLY and HASH_ONLY cases. Signed-off-by: Ankur Dwivedi Signed-off-by: Murthy NSSR Signed-off-by: Nithin Dabilpuram Signed-off-by: Ragothaman Jayaraman Signed-off-by: Srisivasubramanian Srinivasan --- drivers/crypto/cpt/base/cpt.h | 129 +++++ drivers/crypto/cpt/base/cpt_ops.c | 1021 +++++++++++++++++++++++++++++++++++++ 2 files changed, 1150 insertions(+) diff --git a/drivers/crypto/cpt/base/cpt.h b/drivers/crypto/cpt/base/cpt.h index 11407ae..54b1cb6 100644 --- a/drivers/crypto/cpt/base/cpt.h +++ b/drivers/crypto/cpt/base/cpt.h @@ -54,6 +54,135 @@ void *marker; } app_data_t; +/* + * Parameters for Flexi Crypto + * requests + */ +#define VALID_AAD_BUF 0x01 +#define VALID_MAC_BUF 0x02 +#define VALID_IV_BUF 0x04 +#define SINGLE_BUF_INPLACE 0x08 +#define SINGLE_BUF_HEADTAILROOM 0x10 + +#define ENCR_IV_OFFSET(__d_offs) ((__d_offs >> 32) & 0xffff) +#define ENCR_OFFSET(__d_offs) ((__d_offs >> 16) & 0xffff) +#define AUTH_OFFSET(__d_offs) (__d_offs & 0xffff) +#define ENCR_DLEN(__d_lens) (__d_lens >> 32) +#define AUTH_DLEN(__d_lens) (__d_lens & 0xffffffff) + +typedef struct fc_params { + /* 0th cache line */ + union { + buf_ptr_t bufs[1]; + struct { + iov_ptr_t *src_iov; + iov_ptr_t *dst_iov; + }; + }; + void *iv_buf; + void *auth_iv_buf; + buf_ptr_t meta_buf; + buf_ptr_t ctx_buf; + uint64_t rsvd2; + + /* 1st cache line */ + buf_ptr_t aad_buf; + buf_ptr_t mac_buf; + +} fc_params_t; + +/* + * Parameters for digest + * generate requests + * Only src_iov, op, ctx_buf, mac_buf, prep_req + * meta_buf, auth_data_len are used for digest gen. + */ +typedef struct fc_params digest_params_t; + +/* Cipher Algorithms */ +typedef mc_cipher_type_t cipher_type_t; + +/* Auth Algorithms */ +typedef mc_hash_type_t auth_type_t; + +/* Flexi Crypto Operations */ +/* + * Encr | Encr + Hmac | HASH-HMAC generation + */ +/* + * ZUC/SNOW3g enc cipher/cipher+auth/auth-gen operation + */ +/* + * kasumi enc cipher/cipher+auth/auth-gen operation + * F8 iv_buf: 64 bits Bigendian format + * COUNT[63-32] || BEARER[31-27] || + * DIRECTION[26] || 0...0[25-0] + * F9 mac gen auth_iv_buf: 64 bits BE + 8 bits + * COUNT[63-32] || FRESH[31-0] + * 0...0[7-1] || DIRECTION[0] + */ +void *cpt_fc_enc_hmac_prep(uint32_t flags, + uint64_t d_offs, + uint64_t d_lens, + fc_params_t *params, + void *op, + int *ret); +/* + * Decr | Decr + Hmac + */ +/* + * ZUC/SNOW3g dec cipher/cipher+auth operation + */ +/* + * kasumi dec cipher/cipher+auth/ operation + * F8 iv_buf: 64 bits Bigendian format + * COUNT[63-32] || BEARER[31-27] || + * DIRECTION[26] || 0...0[25-0] + */ +void *cpt_fc_dec_hmac_prep(uint32_t flags, + uint64_t d_offs, + uint64_t d_lens, + fc_params_t *params, + void *op, + int *ret); + +/* Flexi Crypto Ctrl Operations */ +int32_t cpt_fc_ciph_set_key(cpt_instance_t *inst, + void *ctx, + cipher_type_t type, + uint8_t *key, + uint16_t key_len, + uint8_t *salt); + +int32_t cpt_fc_ciph_set_iv(cpt_instance_t *inst, + void *ctx, + uint8_t *iv, + uint16_t iv_len); + +int32_t cpt_fc_auth_set_key(cpt_instance_t *inst, + void *ctx, + auth_type_t type, + uint8_t *key, + uint16_t key_len, + uint16_t mac_len); + +void +cpt_fc_salt_update(void *ctx, + uint8_t *salt); +/* + * Get's size of contiguous meta buffer + * to be allocated per op + */ +int32_t cpt_fc_get_op_meta_len(void); + +/* Get context length for a session */ +int32_t cpt_fc_get_ctx_len(void); + +/* Provides meta length required when it is + * direct mode i.e single buf inplace + */ +int32_t cpt_fc_get_op_sb_meta_len(void); + /* Instance operations */ /* Enqueue an SE/AE request */ diff --git a/drivers/crypto/cpt/base/cpt_ops.c b/drivers/crypto/cpt/base/cpt_ops.c index e340006..31f8064 100644 --- a/drivers/crypto/cpt/base/cpt_ops.c +++ b/drivers/crypto/cpt/base/cpt_ops.c @@ -86,6 +86,14 @@ int32_t cpt_fc_get_ctx_len(void) return sizeof(struct cpt_ctx); } +inline void +cpt_fc_salt_update(void *ctx, + uint8_t *salt) +{ + struct cpt_ctx *cpt_ctx = ctx; + memcpy(&cpt_ctx->fctx.enc.encr_iv, salt, 4); +} + int cpt_fc_ciph_set_key(cpt_instance_t *instance, void *ctx, cipher_type_t type, uint8_t *key, @@ -306,3 +314,1016 @@ int32_t cpt_fc_get_ctx_len(void) *ctrl_flags = htobe64(*ctrl_flags); return 0; } + +static inline uint32_t +fill_sg_comp(sg_comp_t *list, + uint32_t i, + phys_addr_t dma_addr, + void *vaddr, + uint32_t size) +{ + sg_comp_t *to = &list[i>>2]; + + to->u.s.len[i%4] = htobe16(size); + to->ptr[i%4] = htobe64(dma_addr); + (void) vaddr; + i++; + return i; +} + +static inline uint32_t +fill_sg_comp_from_buf(sg_comp_t *list, + uint32_t i, + buf_ptr_t *from) +{ + sg_comp_t *to = &list[i>>2]; + + to->u.s.len[i%4] = htobe16(from->size); + to->ptr[i%4] = htobe64(from->dma_addr); + i++; + return i; +} + +static inline uint32_t +fill_sg_comp_from_buf_min(sg_comp_t *list, + uint32_t i, + buf_ptr_t *from, + uint32_t *psize) +{ + sg_comp_t *to = &list[i >> 2]; + uint32_t size = *psize; + uint32_t e_len; + + e_len = (size > from->size) ? from->size : size; + to->u.s.len[i % 4] = htobe16(e_len); + to->ptr[i % 4] = htobe64(from->dma_addr); + *psize -= e_len; + i++; + return i; +} + +/* + * This fills the MC expected SGIO list + * from IOV given by user. + */ +static inline uint32_t +fill_sg_comp_from_iov(sg_comp_t *list, + uint32_t i, + iov_ptr_t *from, uint32_t from_offset, + uint32_t *psize, buf_ptr_t *extra_buf, + uint32_t extra_offset) +{ + int32_t j; + uint32_t extra_len = extra_buf ? extra_buf->size : 0; + uint32_t size = *psize - extra_len; + buf_ptr_t *bufs; + + bufs = from->bufs; + for (j = 0; (j < from->buf_cnt) && size; j++) { + phys_addr_t e_dma_addr; + uint32_t e_len; + sg_comp_t *to = &list[i >> 2]; + + if (!bufs[j].size) + continue; + + if (unlikely(from_offset)) { + if (from_offset >= bufs[j].size) { + from_offset -= bufs[j].size; + continue; + } + e_dma_addr = bufs[j].dma_addr + from_offset; + e_len = (size > (bufs[j].size - from_offset)) ? + (bufs[j].size - from_offset) : size; + from_offset = 0; + } else { + e_dma_addr = bufs[j].dma_addr; + e_len = (size > bufs[j].size) ? + bufs[j].size : size; + } + + to->u.s.len[i % 4] = htobe16(e_len); + to->ptr[i % 4] = htobe64(e_dma_addr); + + if (extra_len && (e_len >= extra_offset)) { + /* Break the data at given offset */ + uint32_t next_len = e_len - extra_offset; + phys_addr_t next_dma = e_dma_addr + extra_offset; + + if (!extra_offset) { + i--; + } else { + e_len = extra_offset; + size -= e_len; + to->u.s.len[i % 4] = htobe16(e_len); + } + + /* Insert extra data ptr */ + if (extra_len) { + i++; + to = &list[i >> 2]; + to->u.s.len[i % 4] = htobe16(extra_buf->size); + to->ptr[i % 4] = htobe64(extra_buf->dma_addr); + + /* size already decremented by extra len */ + } + + /* insert the rest of the data */ + if (next_len) { + i++; + to = &list[i >> 2]; + to->u.s.len[i % 4] = htobe16(next_len); + to->ptr[i % 4] = htobe64(next_dma); + size -= next_len; + } + extra_len = 0; + + } else { + size -= e_len; + } + if (extra_offset) + extra_offset -= size; + i++; + } + + *psize = size; + return (uint32_t)i; +} + +static inline int __attribute__((always_inline)) +cpt_enc_hmac_prep(uint32_t flags, + uint64_t d_offs, + uint64_t d_lens, + fc_params_t *fc_params, + void *op, + void **prep_req) +{ + uint32_t iv_offset = 0; + int32_t inputlen, outputlen, enc_dlen, auth_dlen; + struct cpt_ctx *cpt_ctx; + uint32_t cipher_type, hash_type; + uint32_t mac_len, size; + uint8_t iv_len = 16; + cpt_request_info_t *req; + buf_ptr_t *meta_p, *aad_buf = NULL; + uint32_t encr_offset, auth_offset; + uint32_t encr_data_len, auth_data_len, aad_len = 0; + uint32_t passthrough_len = 0; + void *m_vaddr, *offset_vaddr; + uint64_t m_dma, offset_dma, ctx_dma; + vq_cmd_word0_t vq_cmd_w0; + vq_cmd_word3_t vq_cmd_w3; + void *c_vaddr; + uint64_t c_dma; + int32_t m_size; + opcode_info_t opcode; + + meta_p = &fc_params->meta_buf; +#ifdef CPTVF_STRICT_PARAM_CHECK + if (!fc_params || !meta_p->vaddr || !meta_p->size) + return ERR_BAD_INPUT_ARG; +#endif + m_vaddr = meta_p->vaddr; + m_dma = meta_p->dma_addr; + m_size = meta_p->size; + + encr_offset = ENCR_OFFSET(d_offs); + auth_offset = AUTH_OFFSET(d_offs); + encr_data_len = ENCR_DLEN(d_lens); + auth_data_len = AUTH_DLEN(d_lens); + if (unlikely(flags & VALID_AAD_BUF)) { + /* + * We dont support both aad + * and auth data separately + */ + auth_data_len = 0; + auth_offset = 0; + aad_len = fc_params->aad_buf.size; + aad_buf = &fc_params->aad_buf; + } + cpt_ctx = fc_params->ctx_buf.vaddr; + cipher_type = cpt_ctx->enc_cipher; + hash_type = cpt_ctx->hash_type; + mac_len = cpt_ctx->mac_len; + + /* + * Save initial space that followed app data for completion code & + * alternate completion code to fall in same cache line as app data + */ + m_vaddr = (uint8_t *)m_vaddr + COMPLETION_CODE_SIZE; + m_dma += COMPLETION_CODE_SIZE; + size = (uint8_t *)RTE_PTR_ALIGN((uint8_t *)m_vaddr, 16) - + (uint8_t *)m_vaddr; + + c_vaddr = (uint8_t *)m_vaddr + size; + c_dma = m_dma + size; + size += sizeof(cpt_res_s_t); + + m_vaddr = (uint8_t *)m_vaddr + size; + m_dma += size; + m_size -= size; + + /* start cpt request info struct at 8 byte boundary */ + size = (uint8_t *)RTE_PTR_ALIGN(m_vaddr, 8) - + (uint8_t *)m_vaddr; + + req = (cpt_request_info_t *)((uint8_t *)m_vaddr + size); + + size += sizeof(cpt_request_info_t); + m_vaddr = (uint8_t *)m_vaddr + size; + m_dma += size; + m_size -= size; + + if (hash_type == GMAC_TYPE) + encr_data_len = 0; + + if (unlikely(!(flags & VALID_IV_BUF))) { + iv_len = 0; + iv_offset = ENCR_IV_OFFSET(d_offs); + } + + if (unlikely(flags & VALID_AAD_BUF)) { + /* + * When AAD is given, data above encr_offset is pass through + * Since AAD is given as separate pointer and not as offset, + * this is a special case as we need to fragment input data + * into passthrough + encr_data and then insert AAD in between. + */ + if (hash_type != GMAC_TYPE) { + passthrough_len = encr_offset; + auth_offset = passthrough_len + iv_len; + encr_offset = passthrough_len + aad_len + iv_len; + auth_data_len = aad_len + encr_data_len; + } else { + passthrough_len = 16 + aad_len; + auth_offset = passthrough_len + iv_len; + auth_data_len = aad_len; + } + } else { + encr_offset += iv_len; + auth_offset += iv_len; + } + + /* Initialising ctrl and opcode + * fields in cpt request structure + */ + + req->se_req = SE_CORE_REQ; + /* + * We are using DMA mode but indicate that + * SGIO list is already populated. + */ + req->dma_mode = CTRL_DMA_MODE_SGIO; + + /* Encryption */ + opcode.s.major = MAJOR_OP_FC; + opcode.s.minor = 0; + + auth_dlen = auth_offset + auth_data_len; + enc_dlen = encr_data_len + encr_offset; + if (unlikely(encr_data_len & 0xf)) { + if ((cipher_type == DES3_CBC) || (cipher_type == DES3_ECB)) + enc_dlen = ROUNDUP8(encr_data_len) + encr_offset; + else if (likely((cipher_type == AES_CBC) || + (cipher_type == AES_ECB))) + enc_dlen = ROUNDUP16(encr_data_len) + encr_offset; + } + + /* TODO: MC issue */ + if (unlikely(hash_type == GMAC_TYPE)) { + encr_offset = auth_dlen; + enc_dlen = 0; + } + + if (unlikely(auth_dlen > enc_dlen)) { + inputlen = auth_dlen; + outputlen = auth_dlen + mac_len; + } else { + inputlen = enc_dlen; + outputlen = enc_dlen + mac_len; + } + + /*GP op header */ + vq_cmd_w0.u64 = 0; + vq_cmd_w0.s.param1 = htobe16(encr_data_len); + vq_cmd_w0.s.param2 = htobe16(auth_data_len); + /* + * In 83XX since we have a limitation of + * IV & Offset control word not part of instruction + * and need to be part of Data Buffer, we check if + * head room is there and then only do the Direct mode processing + */ + if (likely((flags & SINGLE_BUF_INPLACE) && + (flags & SINGLE_BUF_HEADTAILROOM))) { + void *dm_vaddr = fc_params->bufs[0].vaddr; + uint64_t dm_dma_addr = fc_params->bufs[0].dma_addr; + /* + * This flag indicates that there is 24 bytes head room and + * 8 bytes tail room available, so that we get to do + * DIRECT MODE with limitation + */ + + offset_vaddr = (uint8_t *)dm_vaddr - OFF_CTRL_LEN - iv_len; + offset_dma = dm_dma_addr - OFF_CTRL_LEN - iv_len; + + /* DPTR */ + req->ist.ei1 = offset_dma; + /* RPTR should just exclude offset control word */ + req->ist.ei2 = dm_dma_addr - iv_len; + req->alternate_caddr = (uint64_t *)((uint8_t *)dm_vaddr + + outputlen - iv_len); + /* *req->alternate_caddr = ((uint64_t)0xdeadbeefdeadbeef) */ + + vq_cmd_w0.s.dlen = htobe16(inputlen + OFF_CTRL_LEN); + + vq_cmd_w0.s.opcode = htobe16(opcode.flags); + + if (likely(iv_len)) { + uint64_t *dest = (uint64_t *)((uint8_t *)offset_vaddr + + OFF_CTRL_LEN); + uint64_t *src = fc_params->iv_buf; + dest[0] = src[0]; + dest[1] = src[1]; + } + + *(uint64_t *)offset_vaddr = + htobe64(((uint64_t)encr_offset << 16) | + ((uint64_t)iv_offset << 8) | + ((uint64_t)auth_offset)); + + } else { + uint32_t i, g_size_bytes, s_size_bytes; + uint64_t dptr_dma, rptr_dma; + sg_comp_t *gather_comp; + sg_comp_t *scatter_comp; + uint8_t *in_buffer; + + /* This falls under strict SG mode */ + offset_vaddr = m_vaddr; + offset_dma = m_dma; + size = OFF_CTRL_LEN + iv_len; + + m_vaddr = (uint8_t *)m_vaddr + size; + m_dma += size; + m_size -= size; + + opcode.s.major |= DMA_MODE; + + vq_cmd_w0.s.opcode = htobe16(opcode.flags); + + if (likely(iv_len)) { + uint64_t *dest = (uint64_t *)((uint8_t *)offset_vaddr + + OFF_CTRL_LEN); + uint64_t *src = fc_params->iv_buf; + dest[0] = src[0]; + dest[1] = src[1]; + } + + *(uint64_t *)offset_vaddr = + htobe64(((uint64_t)encr_offset << 16) | + ((uint64_t)iv_offset << 8) | + ((uint64_t)auth_offset)); + + /* DPTR has SG list */ + in_buffer = m_vaddr; + dptr_dma = m_dma; + + ((uint16_t *)in_buffer)[0] = 0; + ((uint16_t *)in_buffer)[1] = 0; + + /* TODO Add error check if space will be sufficient */ + gather_comp = (sg_comp_t *)((uint8_t *)m_vaddr + 8); + + /* + * Input Gather List + */ + + i = 0; + + /* Offset control word that includes iv */ + i = fill_sg_comp(gather_comp, i, offset_dma, + offset_vaddr, OFF_CTRL_LEN + iv_len); + + /* Add input data */ + size = inputlen - iv_len; + if (likely(size)) { + uint32_t aad_offset = aad_len ? passthrough_len : 0; + + if (unlikely(flags & SINGLE_BUF_INPLACE)) { + i = fill_sg_comp_from_buf_min(gather_comp, i, + fc_params->bufs, + &size); + } else { + + i = fill_sg_comp_from_iov(gather_comp, i, + fc_params->src_iov, + 0, &size, + aad_buf, aad_offset); + } + + if (unlikely(size)) { + PMD_TX_LOG(ERR, "Insufficient buffer space," + " size %d need\n", size); + return ERR_BAD_INPUT_ARG; + } + } + ((uint16_t *)in_buffer)[2] = htobe16(i); + g_size_bytes = ((i + 3) / 4) * sizeof(sg_comp_t); + + /* + * Output Scatter list + */ + i = 0; + scatter_comp = + (sg_comp_t *)((uint8_t *)gather_comp + g_size_bytes); + + /* Add IV */ + if (likely(iv_len)) { + i = fill_sg_comp(scatter_comp, i, + offset_dma + OFF_CTRL_LEN, + (uint8_t *)offset_vaddr + OFF_CTRL_LEN, + iv_len); + } + + /* output data or output data + digest*/ + if (unlikely(flags & VALID_MAC_BUF)) { + size = outputlen - iv_len - mac_len; + if (size) { + uint32_t aad_offset = + aad_len ? passthrough_len : 0; + + if (unlikely(flags & SINGLE_BUF_INPLACE)) { + i = fill_sg_comp_from_buf_min( + scatter_comp, + i, + fc_params->bufs, + &size); + } else { + i = fill_sg_comp_from_iov(scatter_comp, + i, + fc_params->dst_iov, + 0, + &size, + aad_buf, + aad_offset); + } + if (size) + return ERR_BAD_INPUT_ARG; + } + /* mac_data */ + if (mac_len) { + i = fill_sg_comp_from_buf(scatter_comp, i, + &fc_params->mac_buf); + } + } else { + /* Output including mac */ + size = outputlen - iv_len; + if (likely(size)) { + uint32_t aad_offset = + aad_len ? passthrough_len : 0; + + if (unlikely(flags & SINGLE_BUF_INPLACE)) { + i = fill_sg_comp_from_buf_min( + scatter_comp, + i, + fc_params->bufs, + &size); + } else { + i = fill_sg_comp_from_iov(scatter_comp, + i, + fc_params->dst_iov, + 0, + &size, + aad_buf, + aad_offset); + } + if (unlikely(size)) { + PMD_TX_LOG(ERR, "Insufficient buffer" + " space, size %d need\n", size); + return ERR_BAD_INPUT_ARG; + } + } + } + ((uint16_t *)in_buffer)[3] = htobe16(i); + s_size_bytes = ((i + 3) / 4) * sizeof(sg_comp_t); + + size = g_size_bytes + s_size_bytes + SG_LIST_HDR_SIZE; + + /* This is DPTR len incase of SG mode */ + vq_cmd_w0.s.dlen = htobe16(size); + + m_vaddr = (uint8_t *)m_vaddr + size; + m_dma += size; + m_size -= size; + + /* cpt alternate completion address saved earlier */ + req->alternate_caddr = (uint64_t *)((uint8_t *)c_vaddr - 8); + *req->alternate_caddr = ~((uint64_t)COMPLETION_CODE_INIT); + rptr_dma = c_dma - 8; + + req->ist.ei1 = dptr_dma; + req->ist.ei2 = rptr_dma; + } + + /* First 16-bit swap then 64-bit swap */ + /* TODO: HACK: Reverse the vq_cmd and cpt_req bit field definitions + * to eliminate all the swapping + */ + vq_cmd_w0.u64 = htobe64(vq_cmd_w0.u64); + + ctx_dma = fc_params->ctx_buf.dma_addr + + offsetof(struct cpt_ctx, fctx); + /* vq command w3 */ + vq_cmd_w3.u64 = 0; + vq_cmd_w3.s.grp = 0; + vq_cmd_w3.s.cptr = ctx_dma; + + /* 16 byte aligned cpt res address */ + req->completion_addr = (uint64_t *)((uint8_t *)c_vaddr); + *req->completion_addr = COMPLETION_CODE_INIT; + req->comp_baddr = c_dma; + + /* Fill microcode part of instruction */ + req->ist.ei0 = vq_cmd_w0.u64; + req->ist.ei3 = vq_cmd_w3.u64; + + req->op = op; + +#ifdef CPTVF_STRICT_PARAM_CHECK + if (!(m_size >= 0)) { + PMD_TX_LOG(ERR, "!!! Buffer Overflow %d\n", + m_size); + abort(); + } +#endif + *prep_req = req; + return 0; +} + +static inline int +cpt_dec_hmac_prep(uint32_t flags, + uint64_t d_offs, + uint64_t d_lens, + fc_params_t *fc_params, + void *op, + void **prep_req) +{ + uint32_t iv_offset = 0, size; + int32_t inputlen, outputlen, enc_dlen, auth_dlen; + struct cpt_ctx *cpt_ctx; + int32_t hash_type, mac_len, m_size; + uint8_t iv_len = 16; + cpt_request_info_t *req; + buf_ptr_t *meta_p, *aad_buf = NULL; + uint32_t encr_offset, auth_offset; + uint32_t encr_data_len, auth_data_len, aad_len = 0; + uint32_t passthrough_len = 0; + void *m_vaddr, *offset_vaddr; + uint64_t m_dma, offset_dma, ctx_dma; + opcode_info_t opcode; + vq_cmd_word0_t vq_cmd_w0; + vq_cmd_word3_t vq_cmd_w3; + void *c_vaddr; + uint64_t c_dma; + + meta_p = &fc_params->meta_buf; +#ifdef CPTVF_STRICT_PARAM_CHECK + if (!fc_params || !meta_p->vaddr || !meta_p->size) + return ERR_BAD_INPUT_ARG; +#endif + m_vaddr = meta_p->vaddr; + m_dma = meta_p->dma_addr; + m_size = meta_p->size; + + encr_offset = ENCR_OFFSET(d_offs); + auth_offset = AUTH_OFFSET(d_offs); + encr_data_len = ENCR_DLEN(d_lens); + auth_data_len = AUTH_DLEN(d_lens); + + if (unlikely(flags & VALID_AAD_BUF)) { + /* + * We dont support both aad + * and auth data separately + */ + auth_data_len = 0; + auth_offset = 0; + aad_len = fc_params->aad_buf.size; + aad_buf = &fc_params->aad_buf; + } + + cpt_ctx = fc_params->ctx_buf.vaddr; + hash_type = cpt_ctx->hash_type; + mac_len = cpt_ctx->mac_len; + + if (hash_type == GMAC_TYPE) + encr_data_len = 0; + + if (unlikely(!(flags & VALID_IV_BUF))) { + iv_len = 0; + iv_offset = ENCR_IV_OFFSET(d_offs); + } + + if (unlikely(flags & VALID_AAD_BUF)) { + /* + * When AAD is given, data above encr_offset is pass through + * Since AAD is given as separate pointer and not as offset, + * this is a special case as we need to fragment input data + * into passthrough + encr_data and then insert AAD in between. + */ + if (hash_type != GMAC_TYPE) { + passthrough_len = encr_offset; + auth_offset = passthrough_len + iv_len; + encr_offset = passthrough_len + aad_len + iv_len; + auth_data_len = aad_len + encr_data_len; + } else { + passthrough_len = 16 + aad_len; + auth_offset = passthrough_len + iv_len; + auth_data_len = aad_len; + } + } else { + encr_offset += iv_len; + auth_offset += iv_len; + } + + /* + * Save initial space that followed app data for completion code & + * alternate completion code to fall in same cache line as app data + */ + m_vaddr = (uint8_t *)m_vaddr + COMPLETION_CODE_SIZE; + m_dma += COMPLETION_CODE_SIZE; + size = (uint8_t *)RTE_PTR_ALIGN((uint8_t *)m_vaddr, 16) - + (uint8_t *)m_vaddr; + c_vaddr = (uint8_t *)m_vaddr + size; + c_dma = m_dma + size; + size += sizeof(cpt_res_s_t); + + m_vaddr = (uint8_t *)m_vaddr + size; + m_dma += size; + m_size -= size; + + /* start cpt request info structure at 8 byte alignment */ + size = (uint8_t *)RTE_PTR_ALIGN(m_vaddr, 8) - + (uint8_t *)m_vaddr; + + req = (cpt_request_info_t *)((uint8_t *)m_vaddr + size); + + size += sizeof(cpt_request_info_t); + m_vaddr = (uint8_t *)m_vaddr + size; + m_dma += size; + m_size -= size; + + /* Initialising ctrl and opcode + * fields in cpt request structure + */ + + req->se_req = SE_CORE_REQ; + /* + * We are using DMA mode but indicate that + * SGIO list is already populated. + */ + req->dma_mode = CTRL_DMA_MODE_SGIO; + + /* Decryption */ + opcode.s.major = MAJOR_OP_FC; + opcode.s.minor = 1; + + enc_dlen = encr_offset + encr_data_len; + auth_dlen = auth_offset + auth_data_len; + + if (auth_dlen > enc_dlen) { + inputlen = auth_dlen + mac_len; + outputlen = auth_dlen; + } else { + inputlen = enc_dlen + mac_len; + outputlen = enc_dlen; + } + + if (hash_type == GMAC_TYPE) + encr_offset = inputlen; + + vq_cmd_w0.u64 = 0; + vq_cmd_w0.s.param1 = htobe16(encr_data_len); + vq_cmd_w0.s.param2 = htobe16(auth_data_len); + + /* + * In 83XX since we have a limitation of + * IV & Offset control word not part of instruction + * and need to be part of Data Buffer, we check if + * head room is there and then only do the Direct mode processing + */ + if (likely((flags & SINGLE_BUF_INPLACE) && + (flags & SINGLE_BUF_HEADTAILROOM))) { + void *dm_vaddr = fc_params->bufs[0].vaddr; + uint64_t dm_dma_addr = fc_params->bufs[0].dma_addr; + /* + * This flag indicates that there is 24 bytes head room and + * 8 bytes tail room available, so that we get to do + * DIRECT MODE with limitation + */ + + offset_vaddr = (uint8_t *)dm_vaddr - OFF_CTRL_LEN - iv_len; + offset_dma = dm_dma_addr - OFF_CTRL_LEN - iv_len; + req->ist.ei1 = offset_dma; + + /* RPTR should just exclude offset control word */ + req->ist.ei2 = dm_dma_addr - iv_len; + + /* In direct mode,changing the alternate completion code address + * to start of rptr,the assumption is that most auth iv failure + * are reported at first byte only.This will not give the + * correct alternate completion code the auth iv fail is + * reported after some bytes. + * FIXME + */ + req->alternate_caddr = (uint64_t *)((uint8_t *)dm_vaddr - + iv_len); + /* since this is decryption, + * don't touch the content of + * alternate ccode space as it contains + * hmac. + */ + + vq_cmd_w0.s.dlen = htobe16(inputlen + OFF_CTRL_LEN); + + vq_cmd_w0.s.opcode = htobe16(opcode.flags); + + if (likely(iv_len)) { + uint64_t *dest = (uint64_t *)((uint8_t *)offset_vaddr + + OFF_CTRL_LEN); + uint64_t *src = fc_params->iv_buf; + dest[0] = src[0]; + dest[1] = src[1]; + } + + *(uint64_t *)offset_vaddr = + htobe64(((uint64_t)encr_offset << 16) | + ((uint64_t)iv_offset << 8) | + ((uint64_t)auth_offset)); + + } else { + uint64_t dptr_dma, rptr_dma; + uint32_t g_size_bytes, s_size_bytes; + sg_comp_t *gather_comp; + sg_comp_t *scatter_comp; + uint8_t *in_buffer; + uint8_t i = 0; + + /* This falls under strict SG mode */ + offset_vaddr = m_vaddr; + offset_dma = m_dma; + size = OFF_CTRL_LEN + iv_len; + + m_vaddr = (uint8_t *)m_vaddr + size; + m_dma += size; + m_size -= size; + + opcode.s.major |= DMA_MODE; + + vq_cmd_w0.s.opcode = htobe16(opcode.flags); + + if (likely(iv_len)) { + uint64_t *dest = (uint64_t *)((uint8_t *)offset_vaddr + + OFF_CTRL_LEN); + uint64_t *src = fc_params->iv_buf; + dest[0] = src[0]; + dest[1] = src[1]; + } + + *(uint64_t *)offset_vaddr = + htobe64(((uint64_t)encr_offset << 16) | + ((uint64_t)iv_offset << 8) | + ((uint64_t)auth_offset)); + + + /* DPTR has SG list */ + in_buffer = m_vaddr; + dptr_dma = m_dma; + + ((uint16_t *)in_buffer)[0] = 0; + ((uint16_t *)in_buffer)[1] = 0; + + /* TODO Add error check if space will be sufficient */ + gather_comp = (sg_comp_t *)((uint8_t *)m_vaddr + 8); + + /* + * Input Gather List + */ + i = 0; + + /* Offset control word that includes iv */ + i = fill_sg_comp(gather_comp, i, offset_dma, + offset_vaddr, OFF_CTRL_LEN + iv_len); + + /* Add input data */ + if (flags & VALID_MAC_BUF) { + size = inputlen - iv_len - mac_len; + if (size) { + /* input data only */ + if (unlikely(flags & SINGLE_BUF_INPLACE)) { + i = fill_sg_comp_from_buf_min( + gather_comp, i, + fc_params->bufs, + &size); + } else { + uint32_t aad_offset = aad_len ? + passthrough_len : 0; + + i = fill_sg_comp_from_iov(gather_comp, + i, + fc_params->src_iov, + 0, &size, + aad_buf, + aad_offset); + } + if (size) + return ERR_BAD_INPUT_ARG; + } + + /* mac data */ + if (mac_len) { + i = fill_sg_comp_from_buf(gather_comp, i, + &fc_params->mac_buf); + } + } else { + /* input data + mac */ + size = inputlen - iv_len; + if (size) { + if (unlikely(flags & SINGLE_BUF_INPLACE)) { + i = fill_sg_comp_from_buf_min( + gather_comp, i, + fc_params->bufs, + &size); + } else { + uint32_t aad_offset = aad_len ? + passthrough_len : 0; + + if (!fc_params->src_iov) + return ERR_BAD_INPUT_ARG; + + i = fill_sg_comp_from_iov(gather_comp, i, + fc_params->src_iov, + 0, &size, + aad_buf, + aad_offset); + } + + if (size) + return ERR_BAD_INPUT_ARG; + } + } + ((uint16_t *)in_buffer)[2] = htobe16(i); + g_size_bytes = ((i + 3) / 4) * sizeof(sg_comp_t); + + /* + * Output Scatter List + */ + + i = 0; + scatter_comp = + (sg_comp_t *)((uint8_t *)gather_comp + g_size_bytes); + + /* Add iv */ + if (iv_len) { + i = fill_sg_comp(scatter_comp, i, + offset_dma + OFF_CTRL_LEN, + (uint8_t *)offset_vaddr + OFF_CTRL_LEN, + iv_len); + } + + /* Add output data */ + size = outputlen - iv_len; + if (size) { + if (unlikely(flags & SINGLE_BUF_INPLACE)) { + /* handle single buffer here */ + i = fill_sg_comp_from_buf_min(scatter_comp, i, + fc_params->bufs, + &size); + } else { + uint32_t aad_offset = aad_len ? + passthrough_len : 0; + + if (!fc_params->dst_iov) + return ERR_BAD_INPUT_ARG; + + i = fill_sg_comp_from_iov(scatter_comp, i, + fc_params->dst_iov, 0, + &size, aad_buf, + aad_offset); + } + + if (unlikely(size)) + return ERR_BAD_INPUT_ARG; + } + + ((uint16_t *)in_buffer)[3] = htobe16(i); + s_size_bytes = ((i + 3) / 4) * sizeof(sg_comp_t); + + size = g_size_bytes + s_size_bytes + SG_LIST_HDR_SIZE; + + /* This is DPTR len incase of SG mode */ + vq_cmd_w0.s.dlen = htobe16(size); + + m_vaddr = (uint8_t *)m_vaddr + size; + m_dma += size; + m_size -= size; + + /* cpt alternate completion address saved earlier */ + req->alternate_caddr = (uint64_t *)((uint8_t *)c_vaddr - 8); + *req->alternate_caddr = ~((uint64_t)COMPLETION_CODE_INIT); + rptr_dma = c_dma - 8; + size += COMPLETION_CODE_SIZE; + + req->ist.ei1 = dptr_dma; + req->ist.ei2 = rptr_dma; + } + + /* First 16-bit swap then 64-bit swap */ + /* TODO: HACK: Reverse the vq_cmd and cpt_req bit field definitions + * to eliminate all the swapping + */ + vq_cmd_w0.u64 = htobe64(vq_cmd_w0.u64); + + ctx_dma = fc_params->ctx_buf.dma_addr + + offsetof(struct cpt_ctx, fctx); + /* vq command w3 */ + vq_cmd_w3.u64 = 0; + vq_cmd_w3.s.grp = 0; + vq_cmd_w3.s.cptr = ctx_dma; + + /* 16 byte aligned cpt res address */ + req->completion_addr = (uint64_t *)((uint8_t *)c_vaddr); + *req->completion_addr = COMPLETION_CODE_INIT; + req->comp_baddr = c_dma; + + /* Fill microcode part of instruction */ + req->ist.ei0 = vq_cmd_w0.u64; + req->ist.ei3 = vq_cmd_w3.u64; + + req->op = op; + +#ifdef CPTVF_STRICT_PARAM_CHECK + if (!(m_size >= 0)) { + PMD_TX_LOG(ERR, "!!! Buffer Overflow %d\n", + m_size); + abort(); + } +#endif + *prep_req = req; + return 0; +} + +void * +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) +{ + struct cpt_ctx *ctx = fc_params->ctx_buf.vaddr; + uint8_t fc_type; + void *prep_req = NULL; + int ret; + + fc_type = ctx->fc_type; + + if (likely(fc_type == FC_GEN)) { + ret = cpt_dec_hmac_prep(flags, 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 = ERR_EIO; + } + + if (unlikely(!prep_req)) + *ret_val = ret; + return prep_req; +} + +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) +{ + struct cpt_ctx *ctx = fc_params->ctx_buf.vaddr; + uint8_t fc_type; + void *prep_req = NULL; + int ret; + + fc_type = ctx->fc_type; + + /* Common api for rest of the ops */ + if (likely(fc_type == FC_GEN)) { + ret = cpt_enc_hmac_prep(flags, d_offs, d_lens, + fc_params, op, &prep_req); + } else { + ret = ERR_EIO; + } + + if (unlikely(!prep_req)) + *ret_val = ret; + return prep_req; +} -- 1.9.3