From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-SN1-obe.outbound.protection.outlook.com (mail-eopbgr700055.outbound.protection.outlook.com [40.107.70.55]) by dpdk.org (Postfix) with ESMTP id 3240D1BB10 for ; Fri, 8 Jun 2018 18:49:15 +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=6+HztQsTXnfrRwH7S3OregZO/fAFXHtdTQyLc0ne1D0=; b=mgId9S6Rjs3U+cRHAyEtyIidbVVIe+QpqHgjlunDDxLYdRB/NXThm+NlQRuXQeIt9auZjTLVzfG0fZATIj4XXRnCP9tTpiSeX3ycHoKdM/LStgjumWOz1hFUtTfaAGOw2PZ2FnYp1AI8BNH30lpmLAWcogLcsDR4fxcEbX/zmFI= 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:10 +0000 From: Anoob Joseph To: Akhil Goyal , Pablo de Lara , Thomas Monjalon Cc: Murthy NSSR , Ankur Dwivedi , Jerin Jacob , Narayana Prasad , Nithin Dabilpuram , Ragothaman Jayaraman , Srisivasubramanian Srinivasan , dev@dpdk.org Date: Fri, 8 Jun 2018 22:15:17 +0530 Message-Id: <1528476325-15585-9-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:tYpj+fiYJKY0HYTmcEIoaa0K/CgdYH7wnc/5b+or+pdDZK2ilZz3nmPRXR+lvMhdo9/1+s1SecZKdlLBDsonO9U7+N3H4Yh4a/BVUEyIF7aTfOkhYLleK48jCthZVDboZZX5jjhcZNbFiQBOUVlJPjQLiTTx4LqxIN97D1yth6HjICimPDaFMaSuwamfyQSegifFgfEQsJFxNqP/DkwFMD90EOgxY3McnQQnFX9GrvtVQYGD6L8dHnqd6uIaiDLZ; 25:mG9jX1aKAsSTX/p4mogNaJ1PK2GIeg644/Mdv8z+c4+VgpUvPZzjiFbGXlFAZBbktPWgP98X2HfAbbjmyI2fYduVNuBzoKEeB+TllbEfapVxflrxKfDE2sDZL66xq1MTNwoqC/ltmlf93hUBwDTy4xyVGkPqCd2iGXTJCRfORUEPjoAWZgwnzRLq5sgvbIEWSR8UV7ljABYEORj4jLq844CKTfHJS7805ayu606ybwkN+PgtvWLzJbK17ISc1eU/kHv23YL/jh47FQJan8s8i7Lizwm87h5ppMnqm2njeDuzYzlCklDWMhq9WJUTcoXio9ppUMS5IYsj3+gIMu/4iw==; 31:IpsbquqFqvWiESVkEEs0gGVCHO7wfKhAwkHNwunkt/9x9YrXMHdwNASVQLgk+1TlJyesL9Jdw9qA7cPX3uhy+H6INlITyOFtH/6timH2HLCw+unYj27gHsiTXnCmnKG2TOkyWVYRLkhTOfIVuxop6fznGO2l3fTBT7Iot+Jxt92GUo0Jd8Og8MYoI0jdU8DRkCUruK1XhRFdM8Px4oV1rc9DXB7iC0Gss7BH0svG/gc= X-MS-TrafficTypeDiagnostic: SN6PR07MB4911: X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 20:+xOoeIkPELV6IY+ZUIdV7Y4GiPXnie1skCYY9i5PpEWsiiZ8ZSRIQsSQvbl8I32z62L88JhtUaJxHCmmVvNPg9toJ+/460z1APcL9r3MJwyhAoqO+Ohcs4OXujAJEdYD8Jp25uEuMo07x4z5VMOcraL97L4KJNWNTy0h5azvF1t7Sjo2iJamOedD5TuFBvK43lMqhtl/ArNuIFXWgJdSyCJMdUVINUTmNU9tb3ZHAB8eSSGm53kB9m08yTi26+ts0c/EXqTxyWeo0WY2pF3ouH0i3//fKX5PFPe68tYIlU3aIpajhpwXGtHteZhqlGT+0ifx7VyRrWiOuxT927nJiDSjjldKMBjB9DvFP7bUKJvUlGMLHqWuKdz46X0QIpNVIUamnIaffErHSO6R/izhSgKYY7kYrE4lFi87cGnVjjMA7/iv984wtT0xXOoHBJlbC6/wO8U85+Cynb4ma1KElpjSj7AbAaepQtOUfdMHgbMX1YUwymlEJJlJyP3OJ2w7UmFObuXSOry34cN/pCmYR8wsDTB8+G7NAzZoTBbbIBEE+oimSHg9Wt1cyDXCnk7Vee4tupYpPcguwxwmq9eEzfIUoBtBKsPvINhzgJ0vcY4=; 4:SrZFF6p9OFdS+Ov+VO1nGTrXXsfMH0xE+a/RFHYZFYV2ulkfmCh6wIL4cIDIfD4R4xEDt9GCX6fDPZbpRs6/CaGHHjgzzXCVn/hU4piOu9Munre1tnHii6rZsqtvRIowPJUOq3mCa7cfSVT1r1VXd//bcfZ67hL0zKHbyFJsA6igzTk9a19okdkJ5PHiKvjzyGxQgSbnPkDLSSOg7cV1C0+hnLdZBU1DhfniccOmmLGckMC+ut3ySgDeFJyinCPKRe/ZQZA6n2tFEYRaVMOkUg== 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)(53936002)(47776003)(486006)(25786009)(5660300001)(50466002)(48376002)(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:bcR/ylBYBnEHZmL2hzlxVOnLz75RkpZRe+BfUvL8R?= =?us-ascii?Q?CISsmFWn2Fd6/stAtrxHfiVzm011FsD+NrlbjAt7OI4+vU9WyhmJBT3Rz+eU?= =?us-ascii?Q?wToCEBtn/q2eqPC6YXIBroXGNzywDIIMKrpXseNocyc5mR2XWVjU1kOT/QPS?= =?us-ascii?Q?L1tRVJyNPdtZueniHQO7b+y5H2xfkXlUkI5W+iQPDvj8QNPIm7pekeL5s52l?= =?us-ascii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Clb5e9ZHWxG7sCQSeVJ5029jY1/hule6x6rzCCa375ClHR/ijxyMLOo0iIgM=; 24:PnK+ixKDu1gtdfisK7KLzkuDExTj9osYLS2sVwj/P4YJXAfU8LzCMA47qwP6sq4yeJ9tNaH5tWZKNn9ertS6Hg6WrT/UK7SqJwy1jyWWoR4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN6PR07MB4911; 7:sNRt6gvb2QwBHhUGYv7m0HUgFflkme6LZ9+e8/fGjdHYP1sicd1ZQna5krZoLswsFp0poWFNBktZnp+M7DpWeP4jq3jGygKxCOaZDAXu1IgEvCH/EcNRoZ1++gAUpOf8DMRwWVgg1YSBUMFFo+Ev/FWbjTC4PPq1+ZLWH3qx/tPtpnyD6O9h2Tc/dI9cjV14ES09z8pBoBTVVh+sI1V47+bHMM+Zkdd5s2bk19uPPbnPe4mwAwPQ02U8aACHqSSD X-MS-Office365-Filtering-Correlation-Id: 2024047b-88dd-4cd9-0940-08d5cd5fc3f8 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2018 16:49:10.0965 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2024047b-88dd-4cd9-0940-08d5cd5fc3f8 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 08/16] crypto/cpt/base: add request prepare API for Kasumi 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:15 -0000 From: Murthy NSSR These functions help in preparing symmetric crypto request for Kasumi of both cipher and auth but not cipher+auth in single xform. 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_ops.c | 545 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 545 insertions(+) diff --git a/drivers/crypto/cpt/base/cpt_ops.c b/drivers/crypto/cpt/base/cpt_ops.c index ff7522a..15c3413 100644 --- a/drivers/crypto/cpt/base/cpt_ops.c +++ b/drivers/crypto/cpt/base/cpt_ops.c @@ -1933,6 +1933,545 @@ static inline int __attribute__((always_inline)) return 0; } +static int +cpt_kasumi_enc_prep(uint32_t req_flags, + uint64_t d_offs, + uint64_t d_lens, + fc_params_t *params, + void *op, + void **prep_req) +{ + uint32_t size; + int32_t inputlen = 0, outputlen = 0; + struct cpt_ctx *cpt_ctx; + uint32_t mac_len = 0; + uint8_t i = 0; + cpt_request_info_t *req; + buf_ptr_t *buf_p; + uint32_t encr_offset, auth_offset; + uint32_t encr_data_len, auth_data_len; + int flags, m_size; + uint8_t *iv_s, *iv_d, iv_len = 8; + uint8_t dir = 0; + void *m_vaddr, *c_vaddr; + uint64_t m_dma, c_dma; + uint64_t *offset_vaddr, offset_dma; + vq_cmd_word0_t vq_cmd_w0; + vq_cmd_word3_t vq_cmd_w3; + opcode_info_t opcode; + uint8_t *in_buffer; + uint32_t g_size_bytes, s_size_bytes; + uint64_t dptr_dma, rptr_dma; + sg_comp_t *gather_comp; + sg_comp_t *scatter_comp; + + buf_p = ¶ms->meta_buf; +#ifdef CPTVF_STRICT_PARAM_CHECK + if (!params || !buf_p->vaddr || !buf_p->size) + return ERR_BAD_INPUT_ARG; +#endif + m_vaddr = buf_p->vaddr; + m_dma = buf_p->dma_addr; + m_size = buf_p->size; + + encr_offset = ENCR_OFFSET(d_offs) / 8; + auth_offset = AUTH_OFFSET(d_offs) / 8; + encr_data_len = ENCR_DLEN(d_lens); + auth_data_len = AUTH_DLEN(d_lens); + + cpt_ctx = params->ctx_buf.vaddr; + flags = cpt_ctx->zsk_flags; + mac_len = cpt_ctx->mac_len; + +#ifdef CPTVF_STRICT_PARAM_CHECK + if (flags == 0x0) { + /* F8 Mode */ + if (auth_offset || auth_data_len) + return ERR_BAD_INPUT_ARG; + + if (!params->iv_buf) + return ERR_BAD_INPUT_ARG; + } else if (flags == 0x1) { + /* F9 mode */ + if (encr_offset || encr_data_len) + return ERR_BAD_INPUT_ARG; + + if (!params->auth_iv_buf) + return ERR_BAD_INPUT_ARG; + } else { + return ERR_EIO; + } +#endif + if (flags == 0x0) + iv_s = params->iv_buf; + else + iv_s = params->auth_iv_buf; + + dir = iv_s[8] & 0x1; + + /* + * 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; + + /* Reserve memory for cpt request info */ + req = m_vaddr; + + size = sizeof(cpt_request_info_t); + m_vaddr = (uint8_t *)m_vaddr + size; + m_dma += size; + m_size -= size; + + /* Initialising ctrl and opcode + * fields for cpt request + */ + + req->se_req = SE_CORE_REQ; + req->dma_mode = CTRL_DMA_MODE_SGIO; + + opcode.s.major = MAJOR_OP_KASUMI | DMA_MODE; + + /* indicates ECB/CBC, direction, ctx from cptr, iv from dptr */ + opcode.s.minor = ((1 << 6) | (cpt_ctx->k_ecb << 5) | + (dir << 4) | (0 << 3) | (flags & 0x7)); + + /* + * GP op header, lengths are expected in bits. + */ + vq_cmd_w0.u64 = 0; + vq_cmd_w0.s.param1 = htobe16(encr_data_len); + vq_cmd_w0.s.param2 = htobe16(auth_data_len); + vq_cmd_w0.s.opcode = htobe16(opcode.flags); + + /* consider iv len */ + if (flags == 0x0) { + encr_offset += iv_len; + auth_offset += iv_len; + } + + /* save space for offset ctrl and iv */ + offset_vaddr = m_vaddr; + offset_dma = m_dma; + + m_vaddr = (uint8_t *)m_vaddr + OFF_CTRL_LEN + iv_len; + m_dma += OFF_CTRL_LEN + iv_len; + m_size -= OFF_CTRL_LEN + iv_len; + + /* 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 followed by iv */ + + if (flags == 0x0) { + inputlen = encr_offset + + (RTE_ALIGN(encr_data_len, 8) / 8); + outputlen = inputlen; + /* iv offset is 0 */ + *offset_vaddr = htobe64((uint64_t)encr_offset << 16); + } else { + inputlen = auth_offset + + (RTE_ALIGN(auth_data_len, 8) / 8); + outputlen = mac_len; + /* iv offset is 0 */ + *offset_vaddr = htobe64((uint64_t)auth_offset); + } + + i = fill_sg_comp(gather_comp, i, offset_dma, + offset_vaddr, OFF_CTRL_LEN + iv_len); + + /* IV */ + iv_d = (uint8_t *)offset_vaddr + OFF_CTRL_LEN; + memcpy(iv_d, iv_s, iv_len); + + /* input data */ + size = inputlen - iv_len; + if (size) { +#ifdef CPTVF_STRICT_PARAM_CHECK + if (!params->src_iov) + return ERR_BAD_INPUT_ARG; +#endif + i = fill_sg_comp_from_iov(gather_comp, i, + params->src_iov, 0, + &size, NULL, 0); + + 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); + + if (flags == 0x1) { + /* IV in SLIST only for F8 */ + iv_len = 0; + } + + /* 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 */ + if (req_flags & VALID_MAC_BUF) { + size = outputlen - iv_len - mac_len; + if (size) { +#ifdef CPTVF_STRICT_PARAM_CHECK + if (!params->dst_iov) + return ERR_BAD_INPUT_ARG; +#endif + i = fill_sg_comp_from_iov(scatter_comp, i, + params->dst_iov, 0, + &size, NULL, 0); + + if (size) + return ERR_BAD_INPUT_ARG; + } + + /* mac data */ + if (mac_len) { + i = fill_sg_comp_from_buf(scatter_comp, i, + ¶ms->mac_buf); + } + } else { + /* Output including mac */ + size = outputlen - iv_len; + if (size) { +#ifdef CPTVF_STRICT_PARAM_CHECK + if (!params->dst_iov) + return ERR_BAD_INPUT_ARG; +#endif + i = fill_sg_comp_from_iov(scatter_comp, i, + params->dst_iov, 0, + &size, NULL, 0); + + if (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); + + /* vq command w3 */ + vq_cmd_w3.u64 = 0; + vq_cmd_w3.s.grp = 0; + vq_cmd_w3.s.cptr = params->ctx_buf.dma_addr + + offsetof(struct cpt_ctx, k_ctx); + + /* 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_kasumi_dec_prep(uint32_t req_flags, + uint64_t d_offs, + uint64_t d_lens, + fc_params_t *params, + void *op, + void **prep_req) +{ + uint32_t size; + int32_t inputlen = 0, outputlen; + struct cpt_ctx *cpt_ctx; + uint8_t i = 0, iv_len = 8; + cpt_request_info_t *req; + buf_ptr_t *buf_p; + uint32_t encr_offset; + uint32_t encr_data_len; + int flags, m_size; + uint8_t dir = 0; + void *m_vaddr, *c_vaddr; + uint64_t m_dma, c_dma; + uint64_t *offset_vaddr, offset_dma; + vq_cmd_word0_t vq_cmd_w0; + vq_cmd_word3_t vq_cmd_w3; + opcode_info_t opcode; + uint8_t *in_buffer; + uint32_t g_size_bytes, s_size_bytes; + uint64_t dptr_dma, rptr_dma; + sg_comp_t *gather_comp; + sg_comp_t *scatter_comp; + + (void)req_flags; + buf_p = ¶ms->meta_buf; +#ifdef CPTVF_STRICT_PARAM_CHECK + if (!params || !buf_p->vaddr || !buf_p->size) + return ERR_BAD_INPUT_ARG; +#endif + m_vaddr = buf_p->vaddr; + m_dma = buf_p->dma_addr; + m_size = buf_p->size; + + encr_offset = ENCR_OFFSET(d_offs) / 8; + encr_data_len = ENCR_DLEN(d_lens); + + cpt_ctx = params->ctx_buf.vaddr; + flags = cpt_ctx->zsk_flags; +#ifdef CPTVF_STRICT_PARAM_CHECK + if (!params->iv_buf) + return ERR_BAD_INPUT_ARG; +#endif +#ifdef CPTVF_STRICT_PARAM_CHECK + if (flags != 0) { + /* Dec not supported for F9 */ + return ERR_BAD_INPUT_ARG; + } +#endif + /* + * 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; + + /* Reserve memory for cpt request info */ + req = m_vaddr; + + size = sizeof(cpt_request_info_t); + m_vaddr = (uint8_t *)m_vaddr + size; + m_dma += size; + m_size -= size; + + /* Initialising ctrl and opcode + * fields for cpt req + */ + + req->se_req = SE_CORE_REQ; + req->dma_mode = CTRL_DMA_MODE_SGIO; + + opcode.s.major = MAJOR_OP_KASUMI | DMA_MODE; + + /* indicates ECB/CBC, direction, ctx from cptr, iv from dptr */ + opcode.s.minor = ((1 << 6) | (cpt_ctx->k_ecb << 5) | + (dir << 4) | (0 << 3) | (flags & 0x7)); + + /* + * GP op header, lengths are expected in bits. + */ + vq_cmd_w0.u64 = 0; + vq_cmd_w0.s.param1 = htobe16(encr_data_len); + vq_cmd_w0.s.opcode = htobe16(opcode.flags); + + /* consider iv len */ + encr_offset += iv_len; + + inputlen = iv_len + (RTE_ALIGN(encr_data_len, 8) / 8); + outputlen = inputlen; + + /* save space for offset ctrl & iv */ + offset_vaddr = m_vaddr; + offset_dma = m_dma; + + m_vaddr = (uint8_t *)m_vaddr + OFF_CTRL_LEN + iv_len; + m_dma += OFF_CTRL_LEN + iv_len; + m_size -= OFF_CTRL_LEN + iv_len; + + /* 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 followed by iv */ + *offset_vaddr = htobe64((uint64_t)encr_offset << 16); + + i = fill_sg_comp(gather_comp, i, offset_dma, offset_vaddr, + OFF_CTRL_LEN + iv_len); + + + /* IV */ + memcpy((uint8_t *)offset_vaddr + OFF_CTRL_LEN, + params->iv_buf, iv_len); + + /* Add input data */ + size = inputlen - iv_len; + if (size) { +#ifdef CPTVF_STRICT_PARAM_CHECK + if (!params->src_iov) + return ERR_BAD_INPUT_ARG; +#endif + i = fill_sg_comp_from_iov(gather_comp, i, + params->src_iov, + 0, &size, NULL, 0); + 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); + + /* IV */ + 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) { +#ifdef CPTVF_STRICT_PARAM_CHECK + if (!params->dst_iov) + return ERR_BAD_INPUT_ARG; +#endif + i = fill_sg_comp_from_iov(scatter_comp, i, + params->dst_iov, 0, + &size, NULL, 0); + if (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); + + /* vq command w3 */ + vq_cmd_w3.u64 = 0; + vq_cmd_w3.s.grp = 0; + vq_cmd_w3.s.cptr = params->ctx_buf.dma_addr + + offsetof(struct cpt_ctx, k_ctx); + + /* 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)) + abort(); +#endif + *prep_req = req; + return 0; +} + void * cpt_fc_dec_hmac_prep(uint32_t flags, uint64_t d_offs, @@ -1953,6 +2492,9 @@ static inline int __attribute__((always_inline)) } else if (fc_type == ZUC_SNOW3G) { ret = cpt_zuc_snow3g_dec_prep(flags, d_offs, d_lens, fc_params, op, &prep_req); + } else if (fc_type == KASUMI) { + ret = cpt_kasumi_dec_prep(flags, d_offs, d_lens, + fc_params, op, &prep_req); } else { /* * For AUTH_ONLY case, @@ -1986,6 +2528,9 @@ static inline int __attribute__((always_inline)) } else if (fc_type == ZUC_SNOW3G) { ret = cpt_zuc_snow3g_enc_prep(flags, d_offs, d_lens, fc_params, op, &prep_req); + } else if (fc_type == KASUMI) { + ret = cpt_kasumi_enc_prep(flags, d_offs, d_lens, + fc_params, op, &prep_req); } else { ret = ERR_EIO; } -- 1.9.3