From patchwork Mon Jun 24 16:21:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13709802 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 11DB1C2BD09 for ; Mon, 24 Jun 2024 16:22:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SNRZatXFYSvT7dWA5Z47QsnQSl5EsRqGGJzSsqaHcYY=; b=Xebayp+EwElV1q5Ttij+K4wDUG rS7kgX8CjgILW08w+2ryjvegw4lMVFTXMN4oXQel70lCf6Oqt8YRQ5n6fi5zf86ylsQKHEhP3aDxx 5q+y4HBeqWGRpI/992w58t8fo7HSErMgbMn8SKQil/a8MVPyBD94AjPORkFQTqDNdfxccWWprjZpy 1akL5Ge1SAoRuXzs8V9UnM7k3IFi3Mi0p/hsR1FF05QHDlQ2UzaP47N39I/oUuB120uL2CM6Bybsg Y6wZaVesjXGeKsrUf5a2BjL6AkYwo8OJOnCWr0Iiti2EhoUTnPefx0LHvj+TONGiGnXi7eI6wdEZJ xjtLUxMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLmSQ-0000000HThv-0UVZ; Mon, 24 Jun 2024 16:22:18 +0000 Received: from mail-ej1-f48.google.com ([209.85.218.48]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLmS9-0000000HTXX-26dX for linux-arm-kernel@lists.infradead.org; Mon, 24 Jun 2024 16:22:03 +0000 Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a689ad8d1f6so574145166b.2 for ; Mon, 24 Jun 2024 09:22:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719246120; x=1719850920; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SNRZatXFYSvT7dWA5Z47QsnQSl5EsRqGGJzSsqaHcYY=; b=fgxump8ds89bg4tHH6pq0EHd6XTnCLAN/4O4zVWkzglm64H8ObdVbQpq4QbijFqce6 QNcFbWPSx8Nyr+o7vv2wtY0QJLkeFLNZcfzXjQBvqIa3f3x0j6MG6w902ATmDYBoYxSd At0VCYgDkoRYjo0rrDpTpy8nKQXeIImUtvo7e4kEf+fFyG2QjpUzF0Dyzuwk/nRBvgqJ b5d9BQeqZMiCITsa6bZdAgrKMNLRvHdvx8C5mWbgmleLKfQLmuTIs4li1t78Y7QAFaRj rUe6EhpPozPAFEd9rR3NXfTGguieDE1oPUEH+oddF25F8bJvGjzFExE1HUslYkccvWgQ Uj4Q== X-Forwarded-Encrypted: i=1; AJvYcCUaj7bMIs6ghbeCFD8a41yUnEkapmsafSY8blOyEGx3cNWUGGMXcrgzAsi111ow3PX6RlltlCEZiO14hyMl8H5I4z/RMwTpJ+kCUxzOaSIg9Dcqe78= X-Gm-Message-State: AOJu0Yw5n/ZILIy6ypuhXD49vWfy+Dc/FY+Hd1l19RXDJThEcOn2kMeb 35uK4m9CcCZdaGG4Com344DUKVSJkVO8bAcKQLYzzUmjSXCglgsr X-Google-Smtp-Source: AGHT+IGzJL+qgZxR9ubJMoPUs7gDPXfWNurJaThSzu++EbZAe9YtGjEOTHF/GkySo3VJEwJszmtBpw== X-Received: by 2002:a17:907:d509:b0:a6f:27e6:8892 with SMTP id a640c23a62f3a-a7245dc9697mr402052666b.60.1719246116948; Mon, 24 Jun 2024 09:21:56 -0700 (PDT) Received: from localhost (fwdproxy-lla-003.fbsv.net. [2a03:2880:30ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72541fc49asm132301866b.74.2024.06.24.09.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 09:21:56 -0700 (PDT) From: Breno Leitao To: linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, =?utf-8?q?Horia_Geant=C4=83?= , Pankaj Gupta , Gaurav Jain , Herbert Xu , "David S. Miller" Cc: kuba@kernel.org, horms@kernel.org, Roy.Pledge@nxp.com, linux-crypto@vger.kernel.org (open list:FREESCALE CAAM (Cryptographic Acceleration and...), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 3/4] crypto: caam: Unembed net_dev structure from qi Date: Mon, 24 Jun 2024 09:21:21 -0700 Message-ID: <20240624162128.1665620-3-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240624162128.1665620-1-leitao@debian.org> References: <20240624162128.1665620-1-leitao@debian.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240624_092201_692723_9621B95F X-CRM114-Status: GOOD ( 17.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Embedding net_device into structures prohibits the usage of flexible arrays in the net_device structure. For more details, see the discussion at [1]. Un-embed the net_devices from struct caam_qi_pcpu_priv by converting them into pointers, and allocating them dynamically. Use the leverage alloc_netdev_dummy() to allocate the net_device object at caam_qi_init(). The free of the device occurs at caam_qi_shutdown(). Link: https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ [1] Signed-off-by: Breno Leitao --- PS: Unfortunately due to lack of hardware, this was not tested in real hardware. drivers/crypto/caam/qi.c | 43 ++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/caam/qi.c b/drivers/crypto/caam/qi.c index 46a083849a8e..0c13ffc81862 100644 --- a/drivers/crypto/caam/qi.c +++ b/drivers/crypto/caam/qi.c @@ -57,7 +57,7 @@ struct caam_napi { */ struct caam_qi_pcpu_priv { struct caam_napi caam_napi; - struct net_device net_dev; + struct net_device *net_dev; struct qman_fq *rsp_fq; } ____cacheline_aligned; @@ -144,7 +144,7 @@ static void caam_fq_ern_cb(struct qman_portal *qm, struct qman_fq *fq, { const struct qm_fd *fd; struct caam_drv_req *drv_req; - struct device *qidev = &(raw_cpu_ptr(&pcpu_qipriv)->net_dev.dev); + struct device *qidev = &(raw_cpu_ptr(&pcpu_qipriv)->net_dev->dev); struct caam_drv_private *priv = dev_get_drvdata(qidev); fd = &msg->ern.fd; @@ -530,6 +530,7 @@ static void caam_qi_shutdown(void *data) if (kill_fq(qidev, per_cpu(pcpu_qipriv.rsp_fq, i))) dev_err(qidev, "Rsp FQ kill failed, cpu: %d\n", i); + free_netdev(pcpu_qipriv.net_dev); } qman_delete_cgr_safe(&priv->cgr); @@ -573,7 +574,7 @@ static enum qman_cb_dqrr_result caam_rsp_fq_dqrr_cb(struct qman_portal *p, struct caam_napi *caam_napi = raw_cpu_ptr(&pcpu_qipriv.caam_napi); struct caam_drv_req *drv_req; const struct qm_fd *fd; - struct device *qidev = &(raw_cpu_ptr(&pcpu_qipriv)->net_dev.dev); + struct device *qidev = &(raw_cpu_ptr(&pcpu_qipriv)->net_dev->dev); struct caam_drv_private *priv = dev_get_drvdata(qidev); u32 status; @@ -718,12 +719,24 @@ static void free_rsp_fqs(void) kfree(per_cpu(pcpu_qipriv.rsp_fq, i)); } +static void free_caam_qi_pcpu_netdev(const cpumask_t *cpus) +{ + struct caam_qi_pcpu_priv *priv; + int i; + + for_each_cpu(i, cpus) { + priv = per_cpu_ptr(&pcpu_qipriv, i); + free_netdev(priv->net_dev); + } +} + int caam_qi_init(struct platform_device *caam_pdev) { int err, i; struct device *ctrldev = &caam_pdev->dev, *qidev; struct caam_drv_private *ctrlpriv; const cpumask_t *cpus = qman_affine_cpus(); + cpumask_t clean_mask; ctrlpriv = dev_get_drvdata(ctrldev); qidev = ctrldev; @@ -743,6 +756,8 @@ int caam_qi_init(struct platform_device *caam_pdev) return err; } + cpumask_clear(&clean_mask); + /* * Enable the NAPI contexts on each of the core which has an affine * portal. @@ -751,10 +766,16 @@ int caam_qi_init(struct platform_device *caam_pdev) struct caam_qi_pcpu_priv *priv = per_cpu_ptr(&pcpu_qipriv, i); struct caam_napi *caam_napi = &priv->caam_napi; struct napi_struct *irqtask = &caam_napi->irqtask; - struct net_device *net_dev = &priv->net_dev; + struct net_device *net_dev; + net_dev = alloc_netdev_dummy(0); + if (!net_dev) { + err = -ENOMEM; + goto fail; + } + cpumask_set_cpu(i, &clean_mask); + priv->net_dev = net_dev; net_dev->dev = *qidev; - INIT_LIST_HEAD(&net_dev->napi_list); netif_napi_add_tx_weight(net_dev, irqtask, caam_qi_poll, CAAM_NAPI_WEIGHT); @@ -766,16 +787,22 @@ int caam_qi_init(struct platform_device *caam_pdev) dma_get_cache_alignment(), 0, NULL); if (!qi_cache) { dev_err(qidev, "Can't allocate CAAM cache\n"); - free_rsp_fqs(); - return -ENOMEM; + err = -ENOMEM; + goto fail2; } caam_debugfs_qi_init(ctrlpriv); err = devm_add_action_or_reset(qidev, caam_qi_shutdown, ctrlpriv); if (err) - return err; + goto fail2; dev_info(qidev, "Linux CAAM Queue I/F driver initialised\n"); return 0; + +fail2: + free_rsp_fqs(); +fail: + free_caam_qi_pcpu_netdev(&clean_mask); + return err; }