From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 061103CAE66 for ; Sun, 17 May 2026 18:07:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779041228; cv=none; b=BhxkwS5XXSxm8mhnpPE4aZ1kw4ACCaIwZs3MkK+iqVvN3orudJd564foEzYyZQw4LNyeEGc/ezYxyuktZM/U89teW0YjZ3A4RelwsxJtodhUtY1cGC9+tdbGyxeup6hUzZG3+gpoFqhkc6lRaQJy+ZHcBVwj6a3f5/e7ic8I0dQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779041228; c=relaxed/simple; bh=q9vahDLeF0paWqfekbQjBqfdEH/373Mc1f3Pd2pMUUY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lmOIgeVc38Ojd6CGYN6nDsyLSa7E/ioGg5QQXQqWSOjPrsRd8ae8k7XYAOl16dLqEkULgw9WuIwkQ6k9zNUGZ7dobulDGfReDLe0CTOdKvioyRJjKqa97ZgiQMKyg1Kyj51d52CxU3Nk+0Nevhc1ZsIpnrmEqmxNDpG1nWvfsAw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dKuh9FhI; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dKuh9FhI" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-48e72b02bf6so2319265e9.3 for ; Sun, 17 May 2026 11:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779041220; x=1779646020; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UnEz4kb5yNtR6Ed+ZspZs0azXccaDtFZKA7zrYYeQpw=; b=dKuh9FhIzz4XizwKw+FsPfOH3Br6zOu+c8EYdmVrxGFV/JkVWv8GECL75gA1MbXoqk wiiuT02KBR4McjN9nw76hkYaXSfS0ZK+Q8QKWSSnN8ZJ8Y9LyDuBhfha7PoFOQErVXE9 2GtyJI863PkYH08upvx0FTM2hkxh84s/Z5EwgsuN3O466uaM0pzjjlpPQxEV4RLWsVUa xpfqAFJC61EzYwoi3XXHgGnHW5164fUtQ1nAniTBlwEv3e0po/N7ulchDv8WYmErReMx j93YqN6MFMNXOCAm0JE1jZB2JTh5oJmnDFaYpfOhQGNfqYhcIA0My9ebGfoj/UjKKdz2 cF/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779041220; x=1779646020; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UnEz4kb5yNtR6Ed+ZspZs0azXccaDtFZKA7zrYYeQpw=; b=XxCmHG9KqZky7wlMYUCRVvbwinJBtqipQE2oI22IJVPGans106npO3eFZE800KVobm GnWMT+Ek3kt1jX/VDXX/rPgFKLQZzxyFacADgDcxmhpdK6ElgtZ4GhFh8DOsq6B5c4FI rb98tdmQPQEBB7fwa44tzkM7tTVAHyLi9YYgAPtxsKvctuwaUWKiJLjVNoVK+DMNdb6C wSZzzzdw8LNBEBwpcazLBwi2YBLHSYmu7Z6gbhR01S01bDM0UfCJka2S5ubSmh9ka+yS CPmw1d5ldpwPwvniU2XkDrNtRvwR66Fez+fO1AvDN+gqCrMlkVbExiu64ERNYPZ9HO7h XPQQ== X-Forwarded-Encrypted: i=1; AFNElJ/wOVn2svdeA7w5WQs3sixj3Bv3bAe9JSJN2aGmJyfnFmNP2yT6HbiDya4APRm8k/HWBuirZQluYoavYXE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8elnkXigr5hZClDPRjCO8m55WAadfdCPBPd447MhQRUnH8S+A BDVjEhPdHn5vzjRawvJUvlhxgh0v9FlQWVhiSZ//SbiAp73docj3WS6L X-Gm-Gg: Acq92OHsN8XzMM1+Hi7fyCKiSpBq+pdRRwyIPWU0tD42v5iHQ/C9eqZ8wQeh9Ca0qjj A6dVC0786TVVA+UnBOabrm+W7pJUcDyciPCMPZBJZxaqCR364yyxxE3R/7ACTMRv26syReHV6Dp XFHe+Gnqhj54HlwLlh/K/rFuUcvy09m/aYXYDeq+zGx+AKqnr46KeEeJo14W6/BoBIv3VQGAhDQ x7DNLK81a9uoqm8NJWk6Tbd4Om8tJp9KoNvtQC6yR19eVeaRlaeebr4/N7NVAQV9uiytwxO9rlX n6ozkQi0AvaTPeYZboshsRv+Lsr9A1M47r8fgetfw52jwDel0tK1Er/kqvpEeLqN2+2fbRiHnoD W/eoLlMFS3m6etlnk1kVny9n/cd0dyJSQvmJW7o+sD61UEGl3yJ17xypsgGGAmhDzVL10jPDpmz QHQWrEcewbXxP67drZpcAqJiYQzVkNnE3b1a1rA2Z/1bWpjrc4sNVZCsZgGMS5Gzs= X-Received: by 2002:a05:600c:a48:b0:489:e696:127d with SMTP id 5b1f17b1804b1-48fe63022e8mr80058775e9.5.1779041220235; Sun, 17 May 2026 11:07:00 -0700 (PDT) Received: from menon.v.cablecom.net (84-74-0-139.dclient.hispeed.ch. [84.74.0.139]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45da15a6454sm31766775f8f.34.2026.05.17.11.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2026 11:06:59 -0700 (PDT) From: Lothar Rubusch To: thorsten.blum@linux.dev, herbert@gondor.apana.org.au, davem@davemloft.net, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev Cc: linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, l.rubusch@gmail.com Subject: [PATCH 12/12] crypto: atmel - add capability-based I2C client selection Date: Sun, 17 May 2026 18:06:39 +0000 Message-Id: <20260517180639.9657-14-l.rubusch@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260517180639.9657-1-l.rubusch@gmail.com> References: <20260517180639.9657-1-l.rubusch@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add capability filtering to the I2C client allocator to support feature-aware selection of hardware clients. Each client now exposes supported features via a capability mask. The allocator selects only clients matching the requested capability and still prefers the least-loaded device. ECC marks ECDH support during probe and requests matching clients during tfm setup. SHA204A exposes no capabilities for now. This is preparatory work for upcoming features that will extend hardware usage beyond a single algorithm type. Signed-off-by: Lothar Rubusch --- drivers/crypto/atmel-ecc.c | 4 +++- drivers/crypto/atmel-i2c.c | 5 ++++- drivers/crypto/atmel-i2c.h | 8 +++++++- drivers/crypto/atmel-sha204a.c | 2 ++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/crypto/atmel-ecc.c b/drivers/crypto/atmel-ecc.c index f877f236552f..0eeee9ae6c48 100644 --- a/drivers/crypto/atmel-ecc.c +++ b/drivers/crypto/atmel-ecc.c @@ -214,7 +214,7 @@ static int atmel_ecdh_init_tfm(struct crypto_kpp *tfm) struct atmel_ecdh_ctx *ctx = kpp_tfm_ctx(tfm); ctx->curve_id = ECC_CURVE_NIST_P256; - ctx->client = atmel_i2c_client_alloc(); + ctx->client = atmel_i2c_client_alloc(ATMEL_CAP_ECDH); if (IS_ERR(ctx->client)) { pr_err("tfm - i2c_client binding failed\n"); return PTR_ERR(ctx->client); @@ -286,6 +286,8 @@ static int atmel_ecc_probe(struct i2c_client *client) i2c_priv = i2c_get_clientdata(client); + i2c_priv->caps = BIT(ATMEL_CAP_ECDH); + spin_lock(&atmel_i2c_mgmt.i2c_list_lock); list_add_tail(&i2c_priv->i2c_client_list_node, &atmel_i2c_mgmt.i2c_client_list); diff --git a/drivers/crypto/atmel-i2c.c b/drivers/crypto/atmel-i2c.c index 4beab68997c4..b7ee2ec37531 100644 --- a/drivers/crypto/atmel-i2c.c +++ b/drivers/crypto/atmel-i2c.c @@ -57,7 +57,7 @@ static void atmel_i2c_checksum(struct atmel_i2c_cmd *cmd) *__crc16 = cpu_to_le16(bitrev16(crc16(0, data, len))); } -struct i2c_client *atmel_i2c_client_alloc(void) +struct i2c_client *atmel_i2c_client_alloc(enum atmel_i2c_capability cap) { struct atmel_i2c_client_priv *i2c_priv, *min_i2c_priv = NULL; struct i2c_client *client = ERR_PTR(-ENODEV); @@ -73,6 +73,9 @@ struct i2c_client *atmel_i2c_client_alloc(void) list_for_each_entry(i2c_priv, &atmel_i2c_mgmt.i2c_client_list, i2c_client_list_node) { + if (!(i2c_priv->caps & BIT(cap))) + continue; + tfm_cnt = atomic_read(&i2c_priv->tfm_count); if (tfm_cnt < min_tfm_cnt) { min_tfm_cnt = tfm_cnt; diff --git a/drivers/crypto/atmel-i2c.h b/drivers/crypto/atmel-i2c.h index ba5a860011c8..70579b438256 100644 --- a/drivers/crypto/atmel-i2c.h +++ b/drivers/crypto/atmel-i2c.h @@ -115,6 +115,10 @@ struct atmel_i2c_cmd { #define ECDH_PREFIX_MODE 0x00 /* Used for binding tfm objects to i2c clients. */ +enum atmel_i2c_capability { + ATMEL_CAP_ECDH = 0, +}; + struct atmel_i2c_client_mgmt { struct list_head i2c_client_list; spinlock_t i2c_list_lock; @@ -130,6 +134,7 @@ extern struct atmel_i2c_client_mgmt atmel_i2c_mgmt; * @wake_token_sz : size in bytes of the wake_token * @tfm_count : number of active crypto transformations on i2c client * @hwrng : hold the hardware generated rng + * @caps : feature capability of the particular driver * * Reads and writes from/to the i2c client are sequential. The first byte * transmitted to the device is treated as the byte size. Any attempt to send @@ -146,6 +151,7 @@ struct atmel_i2c_client_priv { size_t wake_token_sz; atomic_t tfm_count ____cacheline_aligned; struct hwrng hwrng; + u32 caps; }; /** @@ -190,7 +196,7 @@ void atmel_i2c_init_genkey_cmd(struct atmel_i2c_cmd *cmd, u16 keyid); int atmel_i2c_init_ecdh_cmd(struct atmel_i2c_cmd *cmd, struct scatterlist *pubkey); -struct i2c_client *atmel_i2c_client_alloc(void); +struct i2c_client *atmel_i2c_client_alloc(enum atmel_i2c_capability cap); void atmel_i2c_unregister_client(struct atmel_i2c_client_priv *i2c_priv); #endif /* __ATMEL_I2C_H__ */ diff --git a/drivers/crypto/atmel-sha204a.c b/drivers/crypto/atmel-sha204a.c index 923e462ff6b0..1a28c6434669 100644 --- a/drivers/crypto/atmel-sha204a.c +++ b/drivers/crypto/atmel-sha204a.c @@ -173,6 +173,8 @@ static int atmel_sha204a_probe(struct i2c_client *client) i2c_priv = i2c_get_clientdata(client); + i2c_priv->caps = 0; + /* add to client list */ spin_lock(&atmel_i2c_mgmt.i2c_list_lock); list_add_tail(&i2c_priv->i2c_client_list_node, -- 2.53.0