From patchwork Mon Oct 22 13:31:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gagandeep Singh X-Patchwork-Id: 149382 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2637468lji; Mon, 22 Oct 2018 06:33:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV61ZhSXutlXwyA2e8ZW4/Y1ioUqsmPY0b8zb623W5AotEABuipXi6w5grKe7+kRm7EoMn5s3 X-Received: by 2002:a05:6000:12c5:: with SMTP id l5mr44491414wrx.215.1540215218724; Mon, 22 Oct 2018 06:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540215218; cv=none; d=google.com; s=arc-20160816; b=URCsvmtqJ51NGwu8q48RnODzDeFsx2Z787jG99nYNtduYUWXjtB5EPpGl+akh9pDSA Xe7Q7N1heR0b1Ds7BMWZzScOXnz6VgA3AQffw00iaazZfAuBtUtnK5athaXR2E/cCNZo ohPzuqm5268O2k168Ojl/hbuq7j8Tc4/UpGtiNI9LY2wPJ1bihghG0aTqQve4SDIaj1W FrjrmHLxY13+y1K6BeutYuzB27+Rpnt15i9zp7V2bq2xg0Qn9dGyERldfAqCK/C2VY63 dER43uGektnCdR2TuS0xU6394pLtERN6+IusTpYglxZ71Ih9SMX9Njj4eUJhscp+J39A /B1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:mime-version :content-transfer-encoding:spamdiagnosticmetadata :spamdiagnosticoutput:content-language:accept-language:in-reply-to :references:message-id:date:thread-index:thread-topic:cc:to:from :dkim-signature; bh=7lO3gD0Ykp0AhoHnbRnl3tQc09p8TFhJZFmwtnuUm+U=; b=lPVaGpBXepnZj81qUQZiaCehnRsjmkSqA9gtg5GV2xg44vCAYmdePmgBkjlGhsFZtv JE1miur6Fg08W3/dxDOBqvj3sSdvuEvVm0HFJkGxTBvMyGisxxtAP3kD2O4MydeHe059 yJJfW/kH4TehcroF6i93M/r/p2jwz9sQNvGNDsTpD15NXFa2AsJ8dnpnIxR9H5xdTGOd EzIt3tY0LfxXhL6M78BE/+yF5YbSPoWv5dlXNt50ByH07G31YwnmqazvZrtaTddCnrym 129FcFzyI+kgMjkHidjPR3zewOn25uJFxU0DMfHMlZV5kbCoGj0EOD7/GLTIYT5hSBxL iN/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nxp.com header.s=selector1 header.b=k7c2quzL; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id z7-v6si26479525wrh.223.2018.10.22.06.33.38; Mon, 22 Oct 2018 06:33:38 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; dkim=fail header.i=@nxp.com header.s=selector1 header.b=k7c2quzL; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7676D7EC7; Mon, 22 Oct 2018 15:31:38 +0200 (CEST) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0084.outbound.protection.outlook.com [104.47.0.84]) by dpdk.org (Postfix) with ESMTP id 1BEBC5F2C for ; Mon, 22 Oct 2018 15:31:31 +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=7lO3gD0Ykp0AhoHnbRnl3tQc09p8TFhJZFmwtnuUm+U=; b=k7c2quzLloAbbNSjI9f7bY/gUuuLllLfoyjC9foctEyPINt7pS8PZr/czzSD2M1gQvsxXz/Oq63cP6tDewr8QFP193ogenGBUzXSAx6oK3aLj0/5519LGfcTQXlgAZsG1m5jpmDG6ZFO4js/ckXigC4E2jS6v6JHhhzVnmK+y88= Received: from HE1PR04MB1530.eurprd04.prod.outlook.com (10.164.48.20) by HE1PR04MB3131.eurprd04.prod.outlook.com (10.171.196.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1250.30; Mon, 22 Oct 2018 13:31:29 +0000 Received: from HE1PR04MB1530.eurprd04.prod.outlook.com ([fe80::95cd:198:d5c5:59a4]) by HE1PR04MB1530.eurprd04.prod.outlook.com ([fe80::95cd:198:d5c5:59a4%5]) with mapi id 15.20.1250.028; Mon, 22 Oct 2018 13:31:29 +0000 From: Gagandeep Singh To: "dev@dpdk.org" , Akhil Goyal CC: Hemant Agrawal Thread-Topic: [PATCH v3 13/15] crypto/caam_jr: add security offload Thread-Index: AQHUaguJSGkRhdD7JEi2gFMl3R8qmA== Date: Mon, 22 Oct 2018 13:31:28 +0000 Message-ID: <20181022133021.11264-14-g.singh@nxp.com> References: <20181012144055.9461-1-g.singh@nxp.com> <20181022133021.11264-1-g.singh@nxp.com> In-Reply-To: <20181022133021.11264-1-g.singh@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BM1PR0101CA0016.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:18::26) To HE1PR04MB1530.eurprd04.prod.outlook.com (2a01:111:e400:59a8::20) authentication-results: spf=none (sender IP is ) smtp.mailfrom=G.Singh@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [14.142.187.166] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; HE1PR04MB3131; 6:5Vlu4eDRQy04fXUwLVIXWLOPtwtPwhDGiArx2uVik1Oo+8CZ3gwrVEMSF6OtZOc5XoI17QxodZLdnC3x6JLuSPhXFIFsRiU8kPRjvWjVZBvBb/yFYgmlDIYsmCs33zpaGCLu959HWfmS64A/LpoO59s5id6OucmIcZD1kznVPusbrIcctXNMYUK5ihPty3UZ0fiOccREdop261KPHXOQXQYakdtD+C0RrE+KjA/2sIczC7wJj/OV786WBCT5i+kQydZtGOvQRpTfP/KfoqNEwBDMC3KZKHUTz4Jlo+tbSRj/sxlE54tHcKdJ/A91AuwkmEaU/sroMCzFQ27mcjglLArX9vKNvEjevr8Pd0dETxF7U2vJ36ODXP1V6JgOvda97oOwK0MMPLqNbFUHVgFPHLWb3fvzpNx3K/m+8KFOPniAHvxslg6vAIfpHC6j1gkAxnSSftD1SXusOCu/qyeYAg==; 5:ebbc1orTopPIE6yQaxkoRgsGPmt/J4pxs5XH7errColIeD7rt8WkgQqq+zd8OFaOAqzQVep2mexGXM2CxmD5vtYfgFzoc/I66mArFFRd7HQ3Rfs7A73jd5l0o+4ge9gHvXemUqPZLrC6kO+QOnOfmKhFVve0B0Q3r5w6pKaaJrI=; 7:Jx4fHnJ3ZcFeRu6zmKp5Ibhoi+Wxzr3EJz/EiRR3sEJSTQPwVR/18dQ0r5XKyKoIKShrQGBlXM2+Z8vEksqjkYwsUjvFSbxw/b0ijxjYM8uJu1zmbIwkaMT4sUrsLVZhqXP4FVpNoK2W2nhb65gcs8UyKKWQEWNqmo1IkABjUdk7kpIKi7QGkKmYBD2F6tkGuKZpvQuGhuTekUQdriztg7teOwchAZLw9ixcFQ99dQbcXhdZg4Mdbg/5ETmtabYC x-ms-office365-filtering-correlation-id: fa89a9d0-1b8e-4e71-e1f2-08d63822abe6 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:HE1PR04MB3131; x-ms-traffictypediagnostic: HE1PR04MB3131: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(192374486261705)(185117386973197); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231355)(944501410)(52105095)(6055026)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:HE1PR04MB3131; BCL:0; PCL:0; RULEID:; SRVR:HE1PR04MB3131; x-forefront-prvs: 08331F819E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(376002)(39860400002)(136003)(346002)(396003)(189003)(199004)(110136005)(99286004)(316002)(81156014)(14454004)(25786009)(72206003)(81166006)(2900100001)(8936002)(106356001)(8676002)(6116002)(3846002)(86362001)(2616005)(476003)(6506007)(386003)(102836004)(1076002)(11346002)(446003)(26005)(186003)(305945005)(478600001)(4326008)(2906002)(76176011)(68736007)(7736002)(6636002)(97736004)(486006)(52116002)(36756003)(55236004)(105586002)(71190400001)(5660300001)(4744004)(6436002)(15650500001)(6486002)(78486010)(53936002)(14444005)(2501003)(256004)(66066001)(71200400001)(5250100002)(53946003)(6512007)(579004); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR04MB3131; H:HE1PR04MB1530.eurprd04.prod.outlook.com; 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-antispam-message-info: Jy0vibL0ECBSMyGXqdMQVSnOiJ+F/LI4zmTJsNlwXKrelWqx7G+QfgbeGha5bSW9OKYjAD9+qlejISjBadROf+uC8qCNl28EibdRXfl93vCdk7MB+Oy2i5fQWdGklxxWHxpVZ7vIe9V3QDZT39HhwJ+Y4+yRyWf/+y8sDXurhCPTN1KG16UA7RMeUxT3MJsTvSfSU3PWgfOK4KaMKnxGK7x5oMpixGJt35cKB/Vho4sghuxNjO3J/SCEzVK44CGgyDyuMY6YDrgb8t/Bi6U2DZ1oDrDhp4o/VIdN6ixSPkgJWH2iWV1KOlRhNSsK3+OSHmaDuJ7jDnNWmv+o7RvBdwWfX4zeU3kNwX6DXi1dlXo= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa89a9d0-1b8e-4e71-e1f2-08d63822abe6 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Oct 2018 13:31:28.9857 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR04MB3131 Subject: [dpdk-dev] [PATCH v3 13/15] crypto/caam_jr: add security offload 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Hemant Agrawal This patch provides the support for protocol offload to the hardware. following security operations are added: - session_create - session_destroy - capabilities_get Signed-off-by: Hemant Agrawal Acked-by: Akhil Goyal --- drivers/crypto/caam_jr/caam_jr.c | 402 +++++++++++++++++- drivers/crypto/caam_jr/caam_jr_capabilities.c | 14 +- drivers/crypto/caam_jr/caam_jr_capabilities.h | 5 +- drivers/crypto/caam_jr/caam_jr_hw.c | 2 + drivers/crypto/caam_jr/caam_jr_pvt.h | 9 + drivers/crypto/caam_jr/caam_jr_uio.c | 2 + 6 files changed, 425 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/drivers/crypto/caam_jr/caam_jr.c b/drivers/crypto/caam_jr/caam_jr.c index e12c8715c..ef5fcb4cb 100644 --- a/drivers/crypto/caam_jr/caam_jr.c +++ b/drivers/crypto/caam_jr/caam_jr.c @@ -14,7 +14,9 @@ #include #include #include +#ifdef RTE_LIBRTE_SECURITY #include +#endif #include #include @@ -27,7 +29,6 @@ /* RTA header files */ #include #include -#include #include #define CAAM_JR_DBG 0 @@ -186,8 +187,21 @@ is_auth_cipher(struct caam_jr_session *ses) { PMD_INIT_FUNC_TRACE(); return ((ses->cipher_alg != RTE_CRYPTO_CIPHER_NULL) && - (ses->auth_alg != RTE_CRYPTO_AUTH_NULL)); + (ses->auth_alg != RTE_CRYPTO_AUTH_NULL) +#ifdef RTE_LIBRTE_SECURITY + && (ses->proto_alg != RTE_SECURITY_PROTOCOL_IPSEC) +#endif + ); +} + +#ifdef RTE_LIBRTE_SECURITY +static inline int +is_proto_ipsec(struct caam_jr_session *ses) +{ + PMD_INIT_FUNC_TRACE(); + return (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC); } +#endif static inline int is_encode(struct caam_jr_session *ses) @@ -212,27 +226,63 @@ caam_auth_alg(struct caam_jr_session *ses, struct alginfo *alginfo_a) ses->digest_length = 0; break; case RTE_CRYPTO_AUTH_MD5_HMAC: +#ifdef RTE_LIBRTE_SECURITY + alginfo_a->algtype = + (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ? + OP_PCL_IPSEC_HMAC_MD5_96 : OP_ALG_ALGSEL_MD5; +#else alginfo_a->algtype = OP_ALG_ALGSEL_MD5; +#endif alginfo_a->algmode = OP_ALG_AAI_HMAC; break; case RTE_CRYPTO_AUTH_SHA1_HMAC: +#ifdef RTE_LIBRTE_SECURITY + alginfo_a->algtype = + (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ? + OP_PCL_IPSEC_HMAC_SHA1_96 : OP_ALG_ALGSEL_SHA1; +#else alginfo_a->algtype = OP_ALG_ALGSEL_SHA1; +#endif alginfo_a->algmode = OP_ALG_AAI_HMAC; break; case RTE_CRYPTO_AUTH_SHA224_HMAC: +#ifdef RTE_LIBRTE_SECURITY + alginfo_a->algtype = + (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ? + OP_PCL_IPSEC_HMAC_SHA1_160 : OP_ALG_ALGSEL_SHA224; +#else alginfo_a->algtype = OP_ALG_ALGSEL_SHA224; +#endif alginfo_a->algmode = OP_ALG_AAI_HMAC; break; case RTE_CRYPTO_AUTH_SHA256_HMAC: +#ifdef RTE_LIBRTE_SECURITY + alginfo_a->algtype = + (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ? + OP_PCL_IPSEC_HMAC_SHA2_256_128 : OP_ALG_ALGSEL_SHA256; +#else alginfo_a->algtype = OP_ALG_ALGSEL_SHA256; +#endif alginfo_a->algmode = OP_ALG_AAI_HMAC; break; case RTE_CRYPTO_AUTH_SHA384_HMAC: +#ifdef RTE_LIBRTE_SECURITY + alginfo_a->algtype = + (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ? + OP_PCL_IPSEC_HMAC_SHA2_384_192 : OP_ALG_ALGSEL_SHA384; +#else alginfo_a->algtype = OP_ALG_ALGSEL_SHA384; +#endif alginfo_a->algmode = OP_ALG_AAI_HMAC; break; case RTE_CRYPTO_AUTH_SHA512_HMAC: +#ifdef RTE_LIBRTE_SECURITY + alginfo_a->algtype = + (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ? + OP_PCL_IPSEC_HMAC_SHA2_512_256 : OP_ALG_ALGSEL_SHA512; +#else alginfo_a->algtype = OP_ALG_ALGSEL_SHA512; +#endif alginfo_a->algmode = OP_ALG_AAI_HMAC; break; default: @@ -248,15 +298,33 @@ caam_cipher_alg(struct caam_jr_session *ses, struct alginfo *alginfo_c) case RTE_CRYPTO_CIPHER_NULL: break; case RTE_CRYPTO_CIPHER_AES_CBC: +#ifdef RTE_LIBRTE_SECURITY + alginfo_c->algtype = + (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ? + OP_PCL_IPSEC_AES_CBC : OP_ALG_ALGSEL_AES; +#else alginfo_c->algtype = OP_ALG_ALGSEL_AES; +#endif alginfo_c->algmode = OP_ALG_AAI_CBC; break; case RTE_CRYPTO_CIPHER_3DES_CBC: +#ifdef RTE_LIBRTE_SECURITY + alginfo_c->algtype = + (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ? + OP_PCL_IPSEC_3DES : OP_ALG_ALGSEL_3DES; +#else alginfo_c->algtype = OP_ALG_ALGSEL_3DES; +#endif alginfo_c->algmode = OP_ALG_AAI_CBC; break; case RTE_CRYPTO_CIPHER_AES_CTR: +#ifdef RTE_LIBRTE_SECURITY + alginfo_c->algtype = + (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ? + OP_PCL_IPSEC_AES_CTR : OP_ALG_ALGSEL_AES; +#else alginfo_c->algtype = OP_ALG_ALGSEL_AES; +#endif alginfo_c->algmode = OP_ALG_AAI_CTR; break; default: @@ -420,6 +488,24 @@ caam_jr_prep_cdb(struct caam_jr_session *ses) cdb->sh_desc[0] = 0; cdb->sh_desc[1] = 0; cdb->sh_desc[2] = 0; +#ifdef RTE_LIBRTE_SECURITY + if (is_proto_ipsec(ses)) { + if (ses->dir == DIR_ENC) { + shared_desc_len = cnstr_shdsc_ipsec_new_encap( + cdb->sh_desc, + true, swap, SHR_SERIAL, + &ses->encap_pdb, + (uint8_t *)&ses->ip4_hdr, + &alginfo_c, &alginfo_a); + } else if (ses->dir == DIR_DEC) { + shared_desc_len = cnstr_shdsc_ipsec_new_decap( + cdb->sh_desc, + true, swap, SHR_SERIAL, + &ses->decap_pdb, + &alginfo_c, &alginfo_a); + } + } else { +#endif /* Auth_only_len is set as 0 here and it will be * overwritten in fd for each packet. */ @@ -427,6 +513,9 @@ caam_jr_prep_cdb(struct caam_jr_session *ses) true, swap, &alginfo_c, &alginfo_a, ses->iv.length, 0, ses->digest_length, ses->dir); +#ifdef RTE_LIBRTE_SECURITY + } +#endif } if (shared_desc_len < 0) { @@ -602,6 +691,7 @@ hw_poll_job_ring(struct sec_job_ring_t *job_ring, } #endif } +#ifdef RTE_LIBRTE_SECURITY if (ctx->op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) { struct ip *ip4_hdr; @@ -622,6 +712,7 @@ hw_poll_job_ring(struct sec_job_ring_t *job_ring, rte_be_to_cpu_16(ip4_hdr->ip_len); } } +#endif *ops = ctx->op; caam_jr_op_ending(ctx); ops++; @@ -1281,6 +1372,50 @@ build_cipher_auth(struct rte_crypto_op *op, struct caam_jr_session *ses) return ctx; } + +static inline struct caam_jr_op_ctx * +build_proto(struct rte_crypto_op *op, struct caam_jr_session *ses) +{ + struct rte_crypto_sym_op *sym = op->sym; + struct caam_jr_op_ctx *ctx = NULL; + phys_addr_t src_start_addr, dst_start_addr; + struct sec_cdb *cdb; + uint64_t sdesc_offset; + struct sec_job_descriptor_t *jobdescr; + + PMD_INIT_FUNC_TRACE(); + ctx = caam_jr_alloc_ctx(ses); + if (!ctx) + return NULL; + ctx->op = op; + + src_start_addr = rte_pktmbuf_iova(sym->m_src); + if (sym->m_dst) + dst_start_addr = rte_pktmbuf_iova(sym->m_dst); + else + dst_start_addr = src_start_addr; + + cdb = ses->cdb; + sdesc_offset = (size_t) ((char *)&cdb->sh_desc - (char *)cdb); + + jobdescr = (struct sec_job_descriptor_t *) ctx->jobdes.desc; + + SEC_JD_INIT(jobdescr); + SEC_JD_SET_SD(jobdescr, + (phys_addr_t)(caam_jr_dma_vtop(cdb)) + sdesc_offset, + cdb->sh_hdr.hi.field.idlen); + + /* output */ + SEC_JD_SET_OUT_PTR(jobdescr, (uint64_t)dst_start_addr, 0, + sym->m_src->buf_len - sym->m_src->data_off); + /* input */ + SEC_JD_SET_IN_PTR(jobdescr, (uint64_t)src_start_addr, 0, + sym->m_src->pkt_len); + sym->m_src->packet_type &= ~RTE_PTYPE_L4_MASK; + + return ctx; +} + static int caam_jr_enqueue_op(struct rte_crypto_op *op, struct caam_jr_qp *qp) { @@ -1296,6 +1431,13 @@ caam_jr_enqueue_op(struct rte_crypto_op *op, struct caam_jr_qp *qp) get_sym_session_private_data(op->sym->session, cryptodev_driver_id); break; +#ifdef RTE_LIBRTE_SECURITY + case RTE_CRYPTO_OP_SECURITY_SESSION: + ses = (struct caam_jr_session *) + get_sec_session_private_data( + op->sym->sec_session); + break; +#endif default: CAAM_JR_DP_ERR("sessionless crypto op not supported"); qp->tx_errs++; @@ -1317,6 +1459,10 @@ caam_jr_enqueue_op(struct rte_crypto_op *op, struct caam_jr_qp *qp) ctx = build_auth_only(op, ses); else if (is_cipher_only(ses)) ctx = build_cipher_only(op, ses); +#ifdef RTE_LIBRTE_SECURITY + else if (is_proto_ipsec(ses)) + ctx = build_proto(op, ses); +#endif } else { if (is_auth_cipher(ses)) ctx = build_cipher_auth_sg(op, ses); @@ -1687,6 +1833,229 @@ caam_jr_sym_session_clear(struct rte_cryptodev *dev, } } +#ifdef RTE_LIBRTE_SECURITY +static int +caam_jr_set_ipsec_session(__rte_unused struct rte_cryptodev *dev, + struct rte_security_session_conf *conf, + void *sess) +{ + struct sec_job_ring_t *internals = dev->data->dev_private; + struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec; + struct rte_crypto_auth_xform *auth_xform; + struct rte_crypto_cipher_xform *cipher_xform; + struct caam_jr_session *session = (struct caam_jr_session *)sess; + + PMD_INIT_FUNC_TRACE(); + + if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) { + cipher_xform = &conf->crypto_xform->cipher; + auth_xform = &conf->crypto_xform->next->auth; + } else { + auth_xform = &conf->crypto_xform->auth; + cipher_xform = &conf->crypto_xform->next->cipher; + } + session->proto_alg = conf->protocol; + session->cipher_key.data = rte_zmalloc(NULL, + cipher_xform->key.length, + RTE_CACHE_LINE_SIZE); + if (session->cipher_key.data == NULL && + cipher_xform->key.length > 0) { + CAAM_JR_ERR("No Memory for cipher key\n"); + return -ENOMEM; + } + + session->cipher_key.length = cipher_xform->key.length; + session->auth_key.data = rte_zmalloc(NULL, + auth_xform->key.length, + RTE_CACHE_LINE_SIZE); + if (session->auth_key.data == NULL && + auth_xform->key.length > 0) { + CAAM_JR_ERR("No Memory for auth key\n"); + rte_free(session->cipher_key.data); + return -ENOMEM; + } + session->auth_key.length = auth_xform->key.length; + memcpy(session->cipher_key.data, cipher_xform->key.data, + cipher_xform->key.length); + memcpy(session->auth_key.data, auth_xform->key.data, + auth_xform->key.length); + + switch (auth_xform->algo) { + case RTE_CRYPTO_AUTH_SHA1_HMAC: + session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC; + break; + case RTE_CRYPTO_AUTH_MD5_HMAC: + session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC; + break; + case RTE_CRYPTO_AUTH_SHA256_HMAC: + session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC; + break; + case RTE_CRYPTO_AUTH_SHA384_HMAC: + session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC; + break; + case RTE_CRYPTO_AUTH_SHA512_HMAC: + session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC; + break; + case RTE_CRYPTO_AUTH_AES_CMAC: + session->auth_alg = RTE_CRYPTO_AUTH_AES_CMAC; + break; + case RTE_CRYPTO_AUTH_NULL: + session->auth_alg = RTE_CRYPTO_AUTH_NULL; + break; + case RTE_CRYPTO_AUTH_SHA224_HMAC: + case RTE_CRYPTO_AUTH_AES_XCBC_MAC: + case RTE_CRYPTO_AUTH_SNOW3G_UIA2: + case RTE_CRYPTO_AUTH_SHA1: + case RTE_CRYPTO_AUTH_SHA256: + case RTE_CRYPTO_AUTH_SHA512: + case RTE_CRYPTO_AUTH_SHA224: + case RTE_CRYPTO_AUTH_SHA384: + case RTE_CRYPTO_AUTH_MD5: + case RTE_CRYPTO_AUTH_AES_GMAC: + case RTE_CRYPTO_AUTH_KASUMI_F9: + case RTE_CRYPTO_AUTH_AES_CBC_MAC: + case RTE_CRYPTO_AUTH_ZUC_EIA3: + CAAM_JR_ERR("Crypto: Unsupported auth alg %u\n", + auth_xform->algo); + goto out; + default: + CAAM_JR_ERR("Crypto: Undefined Auth specified %u\n", + auth_xform->algo); + goto out; + } + + switch (cipher_xform->algo) { + case RTE_CRYPTO_CIPHER_AES_CBC: + session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC; + break; + case RTE_CRYPTO_CIPHER_3DES_CBC: + session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC; + break; + case RTE_CRYPTO_CIPHER_AES_CTR: + session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR; + break; + case RTE_CRYPTO_CIPHER_NULL: + case RTE_CRYPTO_CIPHER_SNOW3G_UEA2: + case RTE_CRYPTO_CIPHER_3DES_ECB: + case RTE_CRYPTO_CIPHER_AES_ECB: + case RTE_CRYPTO_CIPHER_KASUMI_F8: + CAAM_JR_ERR("Crypto: Unsupported Cipher alg %u\n", + cipher_xform->algo); + goto out; + default: + CAAM_JR_ERR("Crypto: Undefined Cipher specified %u\n", + cipher_xform->algo); + goto out; + } + + if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) { + memset(&session->encap_pdb, 0, sizeof(struct ipsec_encap_pdb) + + sizeof(session->ip4_hdr)); + session->ip4_hdr.ip_v = IPVERSION; + session->ip4_hdr.ip_hl = 5; + session->ip4_hdr.ip_len = rte_cpu_to_be_16( + sizeof(session->ip4_hdr)); + session->ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp; + session->ip4_hdr.ip_id = 0; + session->ip4_hdr.ip_off = 0; + session->ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl; + session->ip4_hdr.ip_p = (ipsec_xform->proto == + RTE_SECURITY_IPSEC_SA_PROTO_ESP) ? IPPROTO_ESP + : IPPROTO_AH; + session->ip4_hdr.ip_sum = 0; + session->ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip; + session->ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip; + session->ip4_hdr.ip_sum = calc_chksum((uint16_t *) + (void *)&session->ip4_hdr, + sizeof(struct ip)); + + session->encap_pdb.options = + (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) | + PDBOPTS_ESP_OIHI_PDB_INL | + PDBOPTS_ESP_IVSRC | + PDBHMO_ESP_ENCAP_DTTL; + session->encap_pdb.spi = ipsec_xform->spi; + session->encap_pdb.ip_hdr_len = sizeof(struct ip); + + session->dir = DIR_ENC; + } else if (ipsec_xform->direction == + RTE_SECURITY_IPSEC_SA_DIR_INGRESS) { + memset(&session->decap_pdb, 0, sizeof(struct ipsec_decap_pdb)); + session->decap_pdb.options = sizeof(struct ip) << 16; + session->dir = DIR_DEC; + } else + goto out; + session->ctx_pool = internals->ctx_pool; + + return 0; +out: + rte_free(session->auth_key.data); + rte_free(session->cipher_key.data); + memset(session, 0, sizeof(struct caam_jr_session)); + return -1; +} + +static int +caam_jr_security_session_create(void *dev, + struct rte_security_session_conf *conf, + struct rte_security_session *sess, + struct rte_mempool *mempool) +{ + void *sess_private_data; + struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev; + int ret; + + PMD_INIT_FUNC_TRACE(); + if (rte_mempool_get(mempool, &sess_private_data)) { + CAAM_JR_ERR("Couldn't get object from session mempool"); + return -ENOMEM; + } + + switch (conf->protocol) { + case RTE_SECURITY_PROTOCOL_IPSEC: + ret = caam_jr_set_ipsec_session(cdev, conf, + sess_private_data); + break; + case RTE_SECURITY_PROTOCOL_MACSEC: + return -ENOTSUP; + default: + return -EINVAL; + } + if (ret != 0) { + CAAM_JR_ERR("failed to configure session parameters"); + /* Return session to mempool */ + rte_mempool_put(mempool, sess_private_data); + return ret; + } + + set_sec_session_private_data(sess, sess_private_data); + + return ret; +} + +/* Clear the memory of session so it doesn't leave key material behind */ +static int +caam_jr_security_session_destroy(void *dev __rte_unused, + struct rte_security_session *sess) +{ + PMD_INIT_FUNC_TRACE(); + void *sess_priv = get_sec_session_private_data(sess); + + struct caam_jr_session *s = (struct caam_jr_session *)sess_priv; + + if (sess_priv) { + struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv); + + rte_free(s->cipher_key.data); + rte_free(s->auth_key.data); + memset(sess, 0, sizeof(struct caam_jr_session)); + set_sec_session_private_data(sess, NULL); + rte_mempool_put(sess_mp, sess_priv); + } + return 0; +} +#endif + static int caam_jr_dev_configure(struct rte_cryptodev *dev, struct rte_cryptodev_config *config __rte_unused) @@ -1778,6 +2147,16 @@ static struct rte_cryptodev_ops caam_jr_ops = { .sym_session_clear = caam_jr_sym_session_clear }; +#ifdef RTE_LIBRTE_SECURITY +static struct rte_security_ops caam_jr_security_ops = { + .session_create = caam_jr_security_session_create, + .session_update = NULL, + .session_stats_get = NULL, + .session_destroy = caam_jr_security_session_destroy, + .set_pkt_metadata = NULL, + .capabilities_get = caam_jr_get_security_capabilities +}; +#endif /* @brief Flush job rings of any processed descs. * The processed descs are silently dropped, @@ -1997,6 +2376,9 @@ caam_jr_dev_init(const char *name, struct rte_cryptodev_pmd_init_params *init_params) { struct rte_cryptodev *dev; +#ifdef RTE_LIBRTE_SECURITY + struct rte_security_ctx *security_instance; +#endif struct uio_job_ring *job_ring; char str[RTE_CRYPTODEV_NAME_MAX_LEN]; @@ -2066,6 +2448,22 @@ caam_jr_dev_init(const char *name, return 0; } +#ifdef RTE_LIBRTE_SECURITY + /*TODO free it during teardown*/ + security_instance = rte_malloc("caam_jr", + sizeof(struct rte_security_ctx), 0); + if (security_instance == NULL) { + CAAM_JR_ERR("memory allocation failed\n"); + //todo error handling. + goto cleanup2; + } + + security_instance->device = (void *)dev; + security_instance->ops = &caam_jr_security_ops; + security_instance->sess_cnt = 0; + dev->security_ctx = security_instance; +#endif + RTE_LOG(INFO, PMD, "%s cryptodev init\n", dev->data->name); return 0; diff --git a/drivers/crypto/caam_jr/caam_jr_capabilities.c b/drivers/crypto/caam_jr/caam_jr_capabilities.c index c51593c4b..eacea7db3 100644 --- a/drivers/crypto/caam_jr/caam_jr_capabilities.c +++ b/drivers/crypto/caam_jr/caam_jr_capabilities.c @@ -225,6 +225,7 @@ static const struct rte_cryptodev_capabilities caam_jr_capabilities[] = { RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() }; +#ifdef RTE_LIBRTE_SECURITY static const struct rte_security_capability caam_jr_security_cap[] = { { /* IPsec Lookaside Protocol offload ESP Transport Egress */ .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, @@ -253,14 +254,15 @@ static const struct rte_security_capability caam_jr_security_cap[] = { } }; -const struct rte_cryptodev_capabilities * -caam_jr_get_cryptodev_capabilities(void) -{ - return caam_jr_capabilities; -} - const struct rte_security_capability * caam_jr_get_security_capabilities(void *device __rte_unused) { return caam_jr_security_cap; } +#endif + +const struct rte_cryptodev_capabilities * +caam_jr_get_cryptodev_capabilities(void) +{ + return caam_jr_capabilities; +} diff --git a/drivers/crypto/caam_jr/caam_jr_capabilities.h b/drivers/crypto/caam_jr/caam_jr_capabilities.h index c1e3f305a..d3169b7e9 100644 --- a/drivers/crypto/caam_jr/caam_jr_capabilities.h +++ b/drivers/crypto/caam_jr/caam_jr_capabilities.h @@ -6,13 +6,16 @@ #define CAAM_JR_CAPABILITIES_H #include +#ifdef RTE_LIBRTE_SECURITY #include +#endif /* Get cryptodev capabilities */ const struct rte_cryptodev_capabilities * caam_jr_get_cryptodev_capabilities(void); +#ifdef RTE_LIBRTE_SECURITY /* Get security capabilities */ const struct rte_security_capability * caam_jr_get_security_capabilities(void *device); - +#endif #endif diff --git a/drivers/crypto/caam_jr/caam_jr_hw.c b/drivers/crypto/caam_jr/caam_jr_hw.c index 4a2b08995..c6833185b 100644 --- a/drivers/crypto/caam_jr/caam_jr_hw.c +++ b/drivers/crypto/caam_jr/caam_jr_hw.c @@ -9,7 +9,9 @@ #include #include #include +#ifdef RTE_LIBRTE_SECURITY #include +#endif #include #include diff --git a/drivers/crypto/caam_jr/caam_jr_pvt.h b/drivers/crypto/caam_jr/caam_jr_pvt.h index 58fd257fc..f6200ac8a 100644 --- a/drivers/crypto/caam_jr/caam_jr_pvt.h +++ b/drivers/crypto/caam_jr/caam_jr_pvt.h @@ -5,6 +5,8 @@ #ifndef CAAM_JR_PVT_H #define CAAM_JR_PVT_H +#include + /* NXP CAAM JR PMD device name */ #define CAAM_JR_ALG_UNSUPPORT (-1) @@ -110,6 +112,9 @@ struct caam_jr_session { enum rte_crypto_cipher_algorithm cipher_alg; /* Cipher Algorithm*/ enum rte_crypto_auth_algorithm auth_alg; /* Authentication Algorithm*/ enum rte_crypto_aead_algorithm aead_alg; /* AEAD Algorithm*/ +#ifdef RTE_LIBRTE_SECURITY + enum rte_security_session_protocol proto_alg; /* Security Algorithm*/ +#endif union { struct { uint8_t *data; /* pointer to key data */ @@ -132,7 +137,11 @@ struct caam_jr_session { } iv; /* Initialisation vector parameters */ uint16_t auth_only_len; /* Length of data for Auth only */ uint32_t digest_length; + struct ipsec_encap_pdb encap_pdb; +#ifdef RTE_LIBRTE_SECURITY struct ip ip4_hdr; +#endif + struct ipsec_decap_pdb decap_pdb; struct caam_jr_qp *qp; struct sec_cdb *cdb; /* cmd block associated with qp */ struct rte_mempool *ctx_pool; /* session mempool for caam_jr_op_ctx */ diff --git a/drivers/crypto/caam_jr/caam_jr_uio.c b/drivers/crypto/caam_jr/caam_jr_uio.c index c07d9db01..58d86f961 100644 --- a/drivers/crypto/caam_jr/caam_jr_uio.c +++ b/drivers/crypto/caam_jr/caam_jr_uio.c @@ -16,7 +16,9 @@ #include #include #include +#ifdef RTE_LIBRTE_SECURITY #include +#endif #include #include