From patchwork Mon Feb 12 07:56:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 199606 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2289339dyd; Mon, 12 Feb 2024 00:00:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXoUaARvKpA1E9nYdWBUy/T2YL+rFt3WEQGB7aAA10n3obNpyVvJqTCkR4Yuwt6siaWkGF9vfSyx9bnxZBzJjxBer032Q== X-Google-Smtp-Source: AGHT+IEwE0/4ZuandCjRm0WFGyJ5fthu7oiFZt7lwiclxJasMngWxvmo/PmdOm3oPJTFlNrcC/42 X-Received: by 2002:a05:622a:1aa7:b0:42c:5947:8f25 with SMTP id s39-20020a05622a1aa700b0042c59478f25mr9413793qtc.0.1707724819140; Mon, 12 Feb 2024 00:00:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707724819; cv=pass; d=google.com; s=arc-20160816; b=N3aN8paMJE0kuIB+qkDMmqx0Cz2Lm55WvrNg2myc0Zv6nMp/wyHI+n5GwQRY3UbrUM OL2UbHjl0Sy8gQxYc7AT9/LzgRoBGd2s2hcjyOo77KfK9zoY8pj4FjL6GapiwN81g/B9 5Zy9NCwbFU6+xZOfHArIa13eFOjXLry9DKuYQQGLi88G8SE6IUCqW8v9X1G3+ku6q0wQ 8xIhebpPN2igKb/ZKkbdCHP0OKsMAHxxCfQDDPRrFAxzJssYDUtSXMzhwy8FvtuiWWTU 7sdQuNP2o4ayPXmoOiZd1AWCvDruJNSljrRKGwe5GQGtoJV+ULnpLYrwKo3u98jbTI3B GBog== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=rcbJ3cHKnMztYZZmMcE9LpMEuSsYp1Ba9+RkjBc7yu4=; fh=T8W0pJPu+kMn9vIKu58EG4VvTgcDjMX6g7U86l9fXaQ=; b=Ls4+JaeQLw0Jp5zrY/wbzuBy/DHueYsCKr9DMhDClMlOx9nKalVbfVoxs8YFnprMF0 /WBaFo+KM4zxsrbDY5IXo/WbKKsVNKpzQLBUa3zBNjgB11i/KZSeT/7WWdX0T9mLWBar GHdhAVvTbVBrHR1LfQ+1yRq1j8nP38rAHFVbXgJKRC4iSBg/jt2VbVNHHW9aYpj4/3qx oZIs/QuU41kHbh/wV/QJeuBlqXtw3zaZ2rAxnmMLfGdeFmxpwJthaw7X7eP8sWhQx1lp hiyIrcbn29M68ewlCiY8BstnuAYZa9kNQnKJ2E/EGDoqFVjG2XGu+XSLvPQPZ4CUQEgN /aIw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=RJQcuwIW; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-61164-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61164-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com X-Forwarded-Encrypted: i=2; AJvYcCXGECrFjhTJ4lpipYvqldHBIMCqlh+sx1MvutDECt9/K+HZ5UoFwnKW/KuSm9SEoSbLzFM67iWGscHCj0SvuzZkInahKA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bb17-20020a05622a1b1100b0042b968cc054si4164537qtb.501.2024.02.12.00.00.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 00:00:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61164-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=RJQcuwIW; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-61164-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61164-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D88E51C211DB for ; Mon, 12 Feb 2024 08:00:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49D79182CC; Mon, 12 Feb 2024 07:57:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="RJQcuwIW" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D29079C3; Mon, 12 Feb 2024 07:57:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724633; cv=none; b=fJvqlrLbsoZ7CLo+NcK8A5gOSxTSzzG/qEME2S8gKBHWM+iRgrmHuL0GMB+l0T9dXurzVqGhMnE1CHIq1A+SdVMwUIq0f3kEnum+CZAzlF2nOWhCm4a/8MM8Jlr/hyjibXAu/bXgfaFi04u1NAs0bMa0WgsenGlrJIeJMNbtYMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724633; c=relaxed/simple; bh=l5k5exQg7xF914Ss5oftZeBv5ngwzECfUQERsNOE8Bs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RzewhEnPzIYJGPkPReUzoLMHZkK8t0Bm4eAxoUUc0rO6gJJ93kWGCIHcfBVmJ+1/w7mhXms7kcyL9IH4cNjA/7FnKxUQDKwjVNHdAqIm3nwCHa3YiMZzoUwKkD6Aw/hhSk2CF8aTEm6QLeXmJrcHdQqO302pczjfzB3O8r6UMVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=RJQcuwIW; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 3812240008; Mon, 12 Feb 2024 07:57:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707724623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rcbJ3cHKnMztYZZmMcE9LpMEuSsYp1Ba9+RkjBc7yu4=; b=RJQcuwIWm0jWrsAyClNgfkFbdIrJ3rr3NOiB4lYqRpyN08XSml04ezLrunLFqML2WY8el4 uPSO4SjHpLAxoHY7D64bdgvlD37aH/gsqCDR0uffS32JbcfJ+2p1OSH/JcprUM9h//RDBT HDoGkUkpMRquEj7/TDnkflvpHQWN8qTuZZ7pZpS8FndztKSTfvv6Ba0UCuw0WRmjueccef h2xeBcZ9WdVSLvPJliRjIsSSzfkeCDxHCW7BDEHomco1MzIHYG+okn6NP3DFWq0aDF8pLR UvRdmHiqyZ8G4WNRbHBSw0w7pvh7sAvUQnBe8k2xPhtO2z7MYRyYHdRHpBYFsQ== From: Herve Codina To: Vadim Fedorenko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Herve Codina , Yury Norov , Andy Shevchenko , Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Andrew Lunn , Mark Brown , Christophe Leroy , Thomas Petazzoni Subject: [PATCH v3 RESEND 1/6] net: wan: Add support for QMC HDLC Date: Mon, 12 Feb 2024 08:56:29 +0100 Message-ID: <20240212075646.19114-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212075646.19114-1-herve.codina@bootlin.com> References: <20240212075646.19114-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790679260029591862 X-GMAIL-MSGID: 1790679260029591862 The QMC HDLC driver provides support for HDLC using the QMC (QUICC Multichannel Controller) to transfer the HDLC data. Signed-off-by: Herve Codina Reviewed-by: Christophe Leroy Acked-by: Jakub Kicinski --- drivers/net/wan/Kconfig | 12 + drivers/net/wan/Makefile | 1 + drivers/net/wan/fsl_qmc_hdlc.c | 426 +++++++++++++++++++++++++++++++++ 3 files changed, 439 insertions(+) create mode 100644 drivers/net/wan/fsl_qmc_hdlc.c diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig index 7dda87756d3f..31ab2136cdf1 100644 --- a/drivers/net/wan/Kconfig +++ b/drivers/net/wan/Kconfig @@ -197,6 +197,18 @@ config FARSYNC To compile this driver as a module, choose M here: the module will be called farsync. +config FSL_QMC_HDLC + tristate "Freescale QMC HDLC support" + depends on HDLC + depends on CPM_QMC + help + HDLC support using the Freescale QUICC Multichannel Controller (QMC). + + To compile this driver as a module, choose M here: the + module will be called fsl_qmc_hdlc. + + If unsure, say N. + config FSL_UCC_HDLC tristate "Freescale QUICC Engine HDLC support" depends on HDLC diff --git a/drivers/net/wan/Makefile b/drivers/net/wan/Makefile index 8119b49d1da9..00e9b7ee1e01 100644 --- a/drivers/net/wan/Makefile +++ b/drivers/net/wan/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_WANXL) += wanxl.o obj-$(CONFIG_PCI200SYN) += pci200syn.o obj-$(CONFIG_PC300TOO) += pc300too.o obj-$(CONFIG_IXP4XX_HSS) += ixp4xx_hss.o +obj-$(CONFIG_FSL_QMC_HDLC) += fsl_qmc_hdlc.o obj-$(CONFIG_FSL_UCC_HDLC) += fsl_ucc_hdlc.o obj-$(CONFIG_SLIC_DS26522) += slic_ds26522.o diff --git a/drivers/net/wan/fsl_qmc_hdlc.c b/drivers/net/wan/fsl_qmc_hdlc.c new file mode 100644 index 000000000000..835500910d1b --- /dev/null +++ b/drivers/net/wan/fsl_qmc_hdlc.c @@ -0,0 +1,426 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Freescale QMC HDLC Device Driver + * + * Copyright 2023 CS GROUP France + * + * Author: Herve Codina + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +struct qmc_hdlc_desc { + struct net_device *netdev; + struct sk_buff *skb; /* NULL if the descriptor is not in use */ + dma_addr_t dma_addr; + size_t dma_size; +}; + +struct qmc_hdlc { + struct device *dev; + struct qmc_chan *qmc_chan; + struct net_device *netdev; + bool is_crc32; + spinlock_t tx_lock; /* Protect tx descriptors */ + struct qmc_hdlc_desc tx_descs[8]; + unsigned int tx_out; + struct qmc_hdlc_desc rx_descs[4]; +}; + +static struct qmc_hdlc *netdev_to_qmc_hdlc(struct net_device *netdev) +{ + return dev_to_hdlc(netdev)->priv; +} + +static int qmc_hdlc_recv_queue(struct qmc_hdlc *qmc_hdlc, struct qmc_hdlc_desc *desc, size_t size); + +#define QMC_HDLC_RX_ERROR_FLAGS (QMC_RX_FLAG_HDLC_OVF | \ + QMC_RX_FLAG_HDLC_UNA | \ + QMC_RX_FLAG_HDLC_ABORT | \ + QMC_RX_FLAG_HDLC_CRC) + +static void qmc_hcld_recv_complete(void *context, size_t length, unsigned int flags) +{ + struct qmc_hdlc_desc *desc = context; + struct net_device *netdev = desc->netdev; + struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev); + int ret; + + dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size, DMA_FROM_DEVICE); + + if (flags & QMC_HDLC_RX_ERROR_FLAGS) { + netdev->stats.rx_errors++; + if (flags & QMC_RX_FLAG_HDLC_OVF) /* Data overflow */ + netdev->stats.rx_over_errors++; + if (flags & QMC_RX_FLAG_HDLC_UNA) /* bits received not multiple of 8 */ + netdev->stats.rx_frame_errors++; + if (flags & QMC_RX_FLAG_HDLC_ABORT) /* Received an abort sequence */ + netdev->stats.rx_frame_errors++; + if (flags & QMC_RX_FLAG_HDLC_CRC) /* CRC error */ + netdev->stats.rx_crc_errors++; + kfree_skb(desc->skb); + } else { + netdev->stats.rx_packets++; + netdev->stats.rx_bytes += length; + + skb_put(desc->skb, length); + desc->skb->protocol = hdlc_type_trans(desc->skb, netdev); + netif_rx(desc->skb); + } + + /* Re-queue a transfer using the same descriptor */ + ret = qmc_hdlc_recv_queue(qmc_hdlc, desc, desc->dma_size); + if (ret) { + dev_err(qmc_hdlc->dev, "queue recv desc failed (%d)\n", ret); + netdev->stats.rx_errors++; + } +} + +static int qmc_hdlc_recv_queue(struct qmc_hdlc *qmc_hdlc, struct qmc_hdlc_desc *desc, size_t size) +{ + int ret; + + desc->skb = dev_alloc_skb(size); + if (!desc->skb) + return -ENOMEM; + + desc->dma_size = size; + desc->dma_addr = dma_map_single(qmc_hdlc->dev, desc->skb->data, + desc->dma_size, DMA_FROM_DEVICE); + ret = dma_mapping_error(qmc_hdlc->dev, desc->dma_addr); + if (ret) + goto free_skb; + + ret = qmc_chan_read_submit(qmc_hdlc->qmc_chan, desc->dma_addr, desc->dma_size, + qmc_hcld_recv_complete, desc); + if (ret) + goto dma_unmap; + + return 0; + +dma_unmap: + dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size, DMA_FROM_DEVICE); +free_skb: + kfree_skb(desc->skb); + desc->skb = NULL; + return ret; +} + +static void qmc_hdlc_xmit_complete(void *context) +{ + struct qmc_hdlc_desc *desc = context; + struct net_device *netdev = desc->netdev; + struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev); + struct sk_buff *skb; + unsigned long flags; + + spin_lock_irqsave(&qmc_hdlc->tx_lock, flags); + dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size, DMA_TO_DEVICE); + skb = desc->skb; + desc->skb = NULL; /* Release the descriptor */ + if (netif_queue_stopped(netdev)) + netif_wake_queue(netdev); + spin_unlock_irqrestore(&qmc_hdlc->tx_lock, flags); + + netdev->stats.tx_packets++; + netdev->stats.tx_bytes += skb->len; + + dev_consume_skb_any(skb); +} + +static int qmc_hdlc_xmit_queue(struct qmc_hdlc *qmc_hdlc, struct qmc_hdlc_desc *desc) +{ + int ret; + + desc->dma_addr = dma_map_single(qmc_hdlc->dev, desc->skb->data, + desc->dma_size, DMA_TO_DEVICE); + ret = dma_mapping_error(qmc_hdlc->dev, desc->dma_addr); + if (ret) { + dev_err(qmc_hdlc->dev, "failed to map skb\n"); + return ret; + } + + ret = qmc_chan_write_submit(qmc_hdlc->qmc_chan, desc->dma_addr, desc->dma_size, + qmc_hdlc_xmit_complete, desc); + if (ret) { + dev_err(qmc_hdlc->dev, "qmc chan write returns %d\n", ret); + dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size, DMA_TO_DEVICE); + return ret; + } + + return 0; +} + +static netdev_tx_t qmc_hdlc_xmit(struct sk_buff *skb, struct net_device *netdev) +{ + struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev); + struct qmc_hdlc_desc *desc; + unsigned long flags; + int err; + int ret; + + spin_lock_irqsave(&qmc_hdlc->tx_lock, flags); + + desc = &qmc_hdlc->tx_descs[qmc_hdlc->tx_out]; + if (WARN_ONCE(desc->skb, "No tx descriptors available\n")) { + /* Should never happen. + * Previous xmit should have already stopped the queue. + */ + netif_stop_queue(netdev); + ret = NETDEV_TX_BUSY; + goto end; + } + + desc->netdev = netdev; + desc->dma_size = skb->len; + desc->skb = skb; + err = qmc_hdlc_xmit_queue(qmc_hdlc, desc); + if (err) { + desc->skb = NULL; /* Release the descriptor */ + if (err == -EBUSY) { + netif_stop_queue(netdev); + ret = NETDEV_TX_BUSY; + goto end; + } + dev_kfree_skb(skb); + netdev->stats.tx_dropped++; + ret = NETDEV_TX_OK; + goto end; + } + + qmc_hdlc->tx_out = (qmc_hdlc->tx_out + 1) % ARRAY_SIZE(qmc_hdlc->tx_descs); + + if (qmc_hdlc->tx_descs[qmc_hdlc->tx_out].skb) + netif_stop_queue(netdev); + + ret = NETDEV_TX_OK; +end: + spin_unlock_irqrestore(&qmc_hdlc->tx_lock, flags); + return ret; +} + +static int qmc_hdlc_open(struct net_device *netdev) +{ + struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev); + struct qmc_chan_param chan_param; + struct qmc_hdlc_desc *desc; + int ret; + int i; + + ret = hdlc_open(netdev); + if (ret) + return ret; + + chan_param.mode = QMC_HDLC; + /* HDLC_MAX_MRU + 4 for the CRC + * HDLC_MAX_MRU + 4 + 8 for the CRC and some extraspace needed by the QMC + */ + chan_param.hdlc.max_rx_buf_size = HDLC_MAX_MRU + 4 + 8; + chan_param.hdlc.max_rx_frame_size = HDLC_MAX_MRU + 4; + chan_param.hdlc.is_crc32 = qmc_hdlc->is_crc32; + ret = qmc_chan_set_param(qmc_hdlc->qmc_chan, &chan_param); + if (ret) { + dev_err(qmc_hdlc->dev, "failed to set param (%d)\n", ret); + goto hdlc_close; + } + + /* Queue as many recv descriptors as possible */ + for (i = 0; i < ARRAY_SIZE(qmc_hdlc->rx_descs); i++) { + desc = &qmc_hdlc->rx_descs[i]; + + desc->netdev = netdev; + ret = qmc_hdlc_recv_queue(qmc_hdlc, desc, chan_param.hdlc.max_rx_buf_size); + if (ret) { + if (ret == -EBUSY && i != 0) + break; /* We use all the QMC chan capability */ + goto free_desc; + } + } + + ret = qmc_chan_start(qmc_hdlc->qmc_chan, QMC_CHAN_ALL); + if (ret) { + dev_err(qmc_hdlc->dev, "qmc chan start failed (%d)\n", ret); + goto free_desc; + } + + netif_start_queue(netdev); + + return 0; + +free_desc: + qmc_chan_reset(qmc_hdlc->qmc_chan, QMC_CHAN_ALL); + for (i = 0; i < ARRAY_SIZE(qmc_hdlc->rx_descs); i++) { + desc = &qmc_hdlc->rx_descs[i]; + if (!desc->skb) + continue; + dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size, + DMA_FROM_DEVICE); + kfree_skb(desc->skb); + desc->skb = NULL; + } +hdlc_close: + hdlc_close(netdev); + return ret; +} + +static int qmc_hdlc_close(struct net_device *netdev) +{ + struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev); + struct qmc_hdlc_desc *desc; + int i; + + qmc_chan_stop(qmc_hdlc->qmc_chan, QMC_CHAN_ALL); + qmc_chan_reset(qmc_hdlc->qmc_chan, QMC_CHAN_ALL); + + netif_stop_queue(netdev); + + for (i = 0; i < ARRAY_SIZE(qmc_hdlc->tx_descs); i++) { + desc = &qmc_hdlc->tx_descs[i]; + if (!desc->skb) + continue; + dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size, + DMA_TO_DEVICE); + kfree_skb(desc->skb); + desc->skb = NULL; + } + + for (i = 0; i < ARRAY_SIZE(qmc_hdlc->rx_descs); i++) { + desc = &qmc_hdlc->rx_descs[i]; + if (!desc->skb) + continue; + dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size, + DMA_FROM_DEVICE); + kfree_skb(desc->skb); + desc->skb = NULL; + } + + hdlc_close(netdev); + return 0; +} + +static int qmc_hdlc_attach(struct net_device *netdev, unsigned short encoding, + unsigned short parity) +{ + struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev); + + if (encoding != ENCODING_NRZ) + return -EINVAL; + + switch (parity) { + case PARITY_CRC16_PR1_CCITT: + qmc_hdlc->is_crc32 = false; + break; + case PARITY_CRC32_PR1_CCITT: + qmc_hdlc->is_crc32 = true; + break; + default: + dev_err(qmc_hdlc->dev, "unsupported parity %u\n", parity); + return -EINVAL; + } + + return 0; +} + +static const struct net_device_ops qmc_hdlc_netdev_ops = { + .ndo_open = qmc_hdlc_open, + .ndo_stop = qmc_hdlc_close, + .ndo_start_xmit = hdlc_start_xmit, + .ndo_siocwandev = hdlc_ioctl, +}; + +static int qmc_hdlc_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct qmc_hdlc *qmc_hdlc; + struct qmc_chan_info info; + hdlc_device *hdlc; + int ret; + + qmc_hdlc = devm_kzalloc(&pdev->dev, sizeof(*qmc_hdlc), GFP_KERNEL); + if (!qmc_hdlc) + return -ENOMEM; + + qmc_hdlc->dev = &pdev->dev; + spin_lock_init(&qmc_hdlc->tx_lock); + + qmc_hdlc->qmc_chan = devm_qmc_chan_get_bychild(qmc_hdlc->dev, np); + if (IS_ERR(qmc_hdlc->qmc_chan)) { + ret = PTR_ERR(qmc_hdlc->qmc_chan); + return dev_err_probe(qmc_hdlc->dev, ret, "get QMC channel failed\n"); + } + + ret = qmc_chan_get_info(qmc_hdlc->qmc_chan, &info); + if (ret) { + dev_err(qmc_hdlc->dev, "get QMC channel info failed %d\n", ret); + return ret; + } + + if (info.mode != QMC_HDLC) { + dev_err(qmc_hdlc->dev, "QMC chan mode %d is not QMC_HDLC\n", + info.mode); + return -EINVAL; + } + + qmc_hdlc->netdev = alloc_hdlcdev(qmc_hdlc); + if (!qmc_hdlc->netdev) { + dev_err(qmc_hdlc->dev, "failed to alloc hdlc dev\n"); + return -ENOMEM; + } + + hdlc = dev_to_hdlc(qmc_hdlc->netdev); + hdlc->attach = qmc_hdlc_attach; + hdlc->xmit = qmc_hdlc_xmit; + SET_NETDEV_DEV(qmc_hdlc->netdev, qmc_hdlc->dev); + qmc_hdlc->netdev->tx_queue_len = ARRAY_SIZE(qmc_hdlc->tx_descs); + qmc_hdlc->netdev->netdev_ops = &qmc_hdlc_netdev_ops; + ret = register_hdlc_device(qmc_hdlc->netdev); + if (ret) { + dev_err(qmc_hdlc->dev, "failed to register hdlc device (%d)\n", ret); + goto free_netdev; + } + + platform_set_drvdata(pdev, qmc_hdlc); + + return 0; + +free_netdev: + free_netdev(qmc_hdlc->netdev); + return ret; +} + +static int qmc_hdlc_remove(struct platform_device *pdev) +{ + struct qmc_hdlc *qmc_hdlc = platform_get_drvdata(pdev); + + unregister_hdlc_device(qmc_hdlc->netdev); + free_netdev(qmc_hdlc->netdev); + + return 0; +} + +static const struct of_device_id qmc_hdlc_id_table[] = { + { .compatible = "fsl,qmc-hdlc" }, + {} /* sentinel */ +}; +MODULE_DEVICE_TABLE(of, qmc_hdlc_driver); + +static struct platform_driver qmc_hdlc_driver = { + .driver = { + .name = "fsl-qmc-hdlc", + .of_match_table = qmc_hdlc_id_table, + }, + .probe = qmc_hdlc_probe, + .remove = qmc_hdlc_remove, +}; +module_platform_driver(qmc_hdlc_driver); + +MODULE_AUTHOR("Herve Codina "); +MODULE_DESCRIPTION("QMC HDLC driver"); +MODULE_LICENSE("GPL"); From patchwork Mon Feb 12 07:56:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 199605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2288868dyd; Sun, 11 Feb 2024 23:59:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU6+6XTgh5O9aqslzAx+bNMp6P5OMEQxZnxAu5rXdUEpZnoWwCWKK6I4N/qJycrrMDUFmzwCGaTDY6/g7yslJdMiaz9DA== X-Google-Smtp-Source: AGHT+IHc0O75wgZfMKlqrAMGZ1gAFgEwm4N4UVABBGUv6/ByqRu7SC51rwQLIdjWX3exQl7ebADo X-Received: by 2002:a05:622a:4717:b0:42c:68db:e7b2 with SMTP id dn23-20020a05622a471700b0042c68dbe7b2mr5077059qtb.25.1707724744199; Sun, 11 Feb 2024 23:59:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707724744; cv=pass; d=google.com; s=arc-20160816; b=mdVSfSgsFDBAuPio6WeIV4rjEMZoiwN0FWkeHgj0BhJa+16myHwKs1J/cPK/jvjqEz RqSnKPEWr3aP244GOWrFIv6w0kvFWSDJsVsB/MLuoJsWbs5z7mUmYeo4UIG9oxYIz+PE DbjUdL9LR1QwrUmRh4x380Hj6E+jtYEQrVoYmWKX1gVN4NaXA3AK2SvilhTw3TVemYsK eICNteOUFnGEmU+AhydZ9BZLguc0O9+mR4DQ/hd1T5Q18cRUUN/gvp7ABuln/6pB9ioC szL9I0cyiGTCHoeHNNcIBpc2WZccpfOX0HJ/1LSvmJfQCD84Rc+zuTLnAcq4F1RGGMsH wQaQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=opmB03pxVbtCj6pvCgp5nhczC3sDrqxdKFiEeY7PEsQ=; fh=+THXjqGGxMHxrBst8cMKt8Iai4e4FzpbAKHC+1uuqfo=; b=L9brXh8l+nb1PYEiC/64IJ/d5w93dXOH81SluVR29fP/+Zp3OuGbTRnUV5YoFiA+jh Bcs0R2dUfH9gdpTm/PdpW8e9IOgd6mjWlRVww0NDBAPJqMYzHL4fSijA9nOD/6bir1id TRwXh0oPb24rpA4PPKjkyQeMR2LVqCBQIa/kNH/aw0XwFK90eFCuznZk8hxum76pawke BZFiuJ518UJA4x+dIb9xzEIfOTzHUlbu+N6ZPXQnpQ/6nMXhhTLd4ZhKn8FCEV+y6JJP Xie8AwIy8XpZPA350hxxT06JvhNBVZiQ+Et6wgSxZRsa4ksehsMR0UIV8Uqx2H7/kVFp X1xw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=MzYU1wXM; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-61165-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61165-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com X-Forwarded-Encrypted: i=2; AJvYcCU9lOICY4EVlu4cth8N3q84ew0jtJQXA1wQLhcWuFYkEHkLJphpNFKhzMfRezE8zGBuVAZQRQZPyso4OXTs1qYId3tvBg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 7-20020ac85747000000b0042c67428c3dsi4767575qtx.784.2024.02.11.23.59.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 23:59:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61165-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=MzYU1wXM; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-61165-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61165-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 031CC1C21209 for ; Mon, 12 Feb 2024 07:59:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 27DDC17577; Mon, 12 Feb 2024 07:57:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="MzYU1wXM" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60E1B79E1; Mon, 12 Feb 2024 07:57:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724634; cv=none; b=cYi/k1nN7O0bu9xfvk3pUOD8bkDFyo1z2sBvYKkBLFbZJ66V3MIgLzvEoSe85BnpYw9TGvTfOKmTDgB6nsFW9o51RsRIbzJ2Lr8s0m8WU1vxGaqBpByMbdxOqFxbX7DC1uz9Zz/3iOhX8j5t31aFNfbByMvJFPPswDqt7xhVfn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724634; c=relaxed/simple; bh=Qvy5YIlLldiX0R7wIDqtJBVKHeubDCELaurFbpCFnp8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B0AfiZvoPoSH5L1tV9hpoGz1CmKmLzX3RCdFPaOkRBKLYIzCwoQz7mFkaQH68+l66tlYmVxiHr0j/7Y/jtyrxZ8O9bMq8C9CZySrLzsSosX/28SAvqAGcoS/DwoUMvq2PXb5rd/B6geELwHUfs//rmxy0zYthChYOQaE7NQC0wg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=MzYU1wXM; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id C8CD140014; Mon, 12 Feb 2024 07:57:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707724629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=opmB03pxVbtCj6pvCgp5nhczC3sDrqxdKFiEeY7PEsQ=; b=MzYU1wXM1GGxq6AOxEnTOcYsLAvdRMfolwWcOEA51YpjcTseBGJm6ExlyHlUxko3+0S4Rv x5vCTulTS8uRZ/8cXIaX7Vox1tb+8rwQ82mdTDybFvYSXQIxEiukf6rIRe7Xxzmg8LBfAK 1OW8d8aHvnhv+glWM26DE51UZFa0r4UL41wOneWRQfY8frUQmvWAF3H6TW/WJJSaaMOGUD gyZyt4/nwowMQNkmp90iQ0I7rV26/4r1jijAfe+bfm9RIfsjczlcunHGXocAd5wnxOUEq+ UAL4sY1ot/paNpNoIQIKbwvUlhtzGci+zDQjyuUWp34XGfA8V0wnMnbv4JHdxA== From: Herve Codina To: Vadim Fedorenko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Herve Codina , Yury Norov , Andy Shevchenko , Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Andrew Lunn , Mark Brown , Christophe Leroy , Thomas Petazzoni Subject: [RESEND PATCH v3 2/6] MAINTAINERS: Add the Freescale QMC HDLC driver entry Date: Mon, 12 Feb 2024 08:56:37 +0100 Message-ID: <20240212075646.19114-10-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212075646.19114-1-herve.codina@bootlin.com> References: <20240212075646.19114-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790679181247002060 X-GMAIL-MSGID: 1790679181247002060 After contributing the driver, add myself as the maintainer for the Freescale QMC HDLC driver. Signed-off-by: Herve Codina --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 8d1052fa6a69..15cd3a8e5866 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8584,6 +8584,13 @@ F: Documentation/devicetree/bindings/soc/fsl/cpm_qe/fsl,cpm1-scc-qmc.yaml F: drivers/soc/fsl/qe/qmc.c F: include/soc/fsl/qe/qmc.h +FREESCALE QUICC ENGINE QMC HDLC DRIVER +M: Herve Codina +L: netdev@vger.kernel.org +L: linuxppc-dev@lists.ozlabs.org +S: Maintained +F: drivers/net/wan/fsl_qmc_hdlc.c + FREESCALE QUICC ENGINE TSA DRIVER M: Herve Codina L: linuxppc-dev@lists.ozlabs.org From patchwork Mon Feb 12 07:56:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 199607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2289480dyd; Mon, 12 Feb 2024 00:00:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsYQ8mSikPGRjpIs2+2oK2UHvmBiiWxWZ3CA+BuqdNZX0/oBDHBaGk8Yg+/hz7ZCUf8lvE X-Received: by 2002:a0c:dd0d:0:b0:68c:da0a:10ef with SMTP id u13-20020a0cdd0d000000b0068cda0a10efmr6159738qvk.57.1707724835028; Mon, 12 Feb 2024 00:00:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707724835; cv=pass; d=google.com; s=arc-20160816; b=dUor0XhV/JL4u6Z9EiB4MrY0SIDbElKnZRbYEFumO2Y6Sq+rIS3C3yZs1RM5gm9y7J u7FUvUiP25E9lxJvaOdVSIjFW76j0Pe4coKdX77H9bj+pK+bingQL78OCmhKhoHU/u3b H2a+gM1HRCyCjRTryQ6pLMZJGCSdjzTJ9S5OGse8CYZcVdiHuNJkDh5wXt5sta3ACjUH sHGZPtmyPxiQ2J/IRq92/fnf/a+hSVAOJwHggBUELX40aNqC30xPmkvYwjWF6i9MjE1X AUcIF9HH7kuxt2zpGgsz9z59E8Dm4zRPZQ15d//IdWcKlDASv8xPDMW7eODYR1Dhjz4d xZQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9ic1ckcjchbcoVTjdKWShBulE5zgYlgBqlicFqMJYpM=; fh=EeLkDcGuS6w//H5aaFtauvTrVBVK6O+P1KLr98j5M/M=; b=d6c9G5q3n7cSum+kG5h61jCVd/boP53O6P4R9+95g8sbLGpkFYkUbpwQ1C6awQ6fwR /xpbyYkh9rvb/ubFIUuyWJH0Y8M8vmK0Nnmaxlb6O7ZUYQN54HM0OUps1MlRp6fHJj++ 7F9V1rTq99jQuQNXhY/6OwU9oKEpl5uK5s4mMnv01LFVJzVYRr9iWSmlKrpZkKgUQX7z 1VORygi25uMenpkwveSOKr4YezoZcNf3pwnV+MqtAO+rjEqWP2eGAo8RYZWnddcjZdQ8 wVF3TUHYPnVvIsrjNI/qahBZy/Y9BlRI/8BaQ0g5A07Nyllc0YiG3YnI2z/5RkJOBBW6 WmnQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ReLx3Y7H; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-61168-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61168-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com X-Forwarded-Encrypted: i=2; AJvYcCWcqqXiQipLXpkO7kk2mnDXJ8myrrI/baLbLoI8UeT7X0n3PTNgmB+Rj0ZylhM9px/bW/VZ7GcAwaVA85d+aXX8fv29fw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jx10-20020a0562142b0a00b0068ccafa97dcsi8014951qvb.245.2024.02.12.00.00.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 00:00:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61168-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ReLx3Y7H; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-61168-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61168-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CB6A91C21272 for ; Mon, 12 Feb 2024 08:00:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D925F1B7FD; Mon, 12 Feb 2024 07:57:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ReLx3Y7H" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3ACFD8BFE; Mon, 12 Feb 2024 07:57:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724635; cv=none; b=UZ0n6a9Qwt4Ct3G323hEtSZbv2Fy/R61HUYm2iHwaGAPAX1REC8scZd/mCsGMMMebHOi/eVGJWJVrDc5qg5ChhEvMOm7Nl6bg9gmxdU5M9f8/9KAwSZcaq9sEl8Qb9F/R7f4xjEtqeBSuQPJnzywJwITH5ocnSOAKmhcYlCK9BM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724635; c=relaxed/simple; bh=Y4mTOkugzPKhkBlTmeRYr77COSSEZXPzeIqX8b/CK74=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GtQRm26pTP7z088paoUSaK3HWPctDhDCAo14jXxUaNeAbJGRKd2i46NCMtue2ElB3GeXyl/qr0GFhak77N/5rhoCjoAGVy3FPWDjeHjDJOesAqfFYVQCSCJX5ePnCgWTHAbmiGAu4S2pvVmoJ6X+b3zVhwm9yCgmLNwEKvNkraQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ReLx3Y7H; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id E37B940002; Mon, 12 Feb 2024 07:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707724624; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9ic1ckcjchbcoVTjdKWShBulE5zgYlgBqlicFqMJYpM=; b=ReLx3Y7H2Z8kXqTURnVOLFHzNHB1i04hX3X050KGh7A+qeS5NOW9IYAQ1yf28bdEnrRcD/ qusAHp5xbftd5wslkTA9JjgbIluCxh/kgU+AsqDNGTJxhz0rNFXtrnEL8IRstR0JCd8PTj 5+0Cm5kSw2U4twA4RX3DSJLhcpZhZRwve4BF8OcrVAAxINednQFmM4jiw+Vw+qF2hh44cx Re+zYfP6LJzt5mIJCds1eSrI3qgN/tcoXtNpVSRbkKTwq9I3E11Rmz/9PtXlwLEO/nQe69 ip3Yl2ggq0QVneSuiqSHFRk3Ctoy64CISO8zY1iaipxbsLgoHteNBPMgi8sewQ== From: Herve Codina To: Vadim Fedorenko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Herve Codina , Yury Norov , Andy Shevchenko , Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Andrew Lunn , Mark Brown , Christophe Leroy , Thomas Petazzoni Subject: [PATCH v3 RESEND 3/6] bitmap: Make bitmap_onto() available to users Date: Mon, 12 Feb 2024 08:56:31 +0100 Message-ID: <20240212075646.19114-4-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212075646.19114-1-herve.codina@bootlin.com> References: <20240212075646.19114-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790679276796879406 X-GMAIL-MSGID: 1790679276796879406 Currently the bitmap_onto() is available only for CONFIG_NUMA=y case, while some users may benefit out of it and being independent to NUMA code. Make it available to users by moving out of ifdeffery and exporting for modules. Signed-off-by: Herve Codina --- lib/bitmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/bitmap.c b/lib/bitmap.c index 09522af227f1..2feccb5047dc 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -547,7 +547,6 @@ int bitmap_bitremap(int oldbit, const unsigned long *old, } EXPORT_SYMBOL(bitmap_bitremap); -#ifdef CONFIG_NUMA /** * bitmap_onto - translate one bitmap relative to another * @dst: resulting translated bitmap @@ -681,7 +680,9 @@ void bitmap_onto(unsigned long *dst, const unsigned long *orig, m++; } } +EXPORT_SYMBOL(bitmap_onto); +#ifdef CONFIG_NUMA /** * bitmap_fold - fold larger bitmap into smaller, modulo specified size * @dst: resulting smaller bitmap From patchwork Mon Feb 12 07:56:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 199609 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2289777dyd; Mon, 12 Feb 2024 00:01:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFzA/HbeiIq2HeFgWtqViFWhew01mgvPfE1kFqx9ASpMzslYfNPW4Yb23pY20/UXi/VriG X-Received: by 2002:aa7:d5c7:0:b0:560:cc04:a96c with SMTP id d7-20020aa7d5c7000000b00560cc04a96cmr3938474eds.24.1707724868465; Mon, 12 Feb 2024 00:01:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707724868; cv=pass; d=google.com; s=arc-20160816; b=UY0QSRkldbEwhMHjFUmSzkH1HK5u49pVCQNZK8UVD3DMNx1Dcez8egOitJaQ8bmot/ 6gM0NRcecSJ4cXfI2OVGgA43jobllUMFlb5jjzE8+XnD+YgBH7tUMvk5g7BVTa1tErc0 VTIOAhGJIj7wTPero2E67PSCaSMzsdclreFCAEXzGUxwAxxSaOkiA9xteNzyV0Yzj6Nj hMWyB4zPnWAtLPvFCfnex7RbO50fPjUDg8BeiyKoUrsVtDoBHZqpnVSOfEf0VxY4pb3z gC0AayWFJnbsoFUqLra5gYqrNTqGmbT4GgEvxH6YTSSPpY1lEkvqNSOmV+zOAeHSewvW ZkVg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dO1lu7mTt2Z5I540dnIACd6uZE/pOpssk6saKJ+PaEA=; fh=28gXzwBqk4XMiXvWBpTwDAE7X2/uvoiZFAMxY48UNfI=; b=F5BNp0x0b5Ep8MaqlHxqTb/rpffxLTs4ike4OfNtO+55bcOjM0wHm01NT3Rlk+waob B9KYZY6H0U8xFh8YLmsCvGho7SFUxCYP/tJCPudbPIimR6mQNiXGTUQ5OsOCzkDfrVwb +AmbhqyAGhZt9cxvnuQufmLIKD2tf13/wDWpycMZiz8dIrwEBkYutPa5V4S7b9IDoE3J qtlpBxqP6MOudvpV04hBkw39XuJjiyF8Y2nERJ2mypLMyABBw4fc+evPhLf9639mN93f NH5uX9rbJIbrU6P5OMgZRJmOEksHRtdXpxPoHnPlznyGptY2sVCGtmPq1tJQiq7nVV2G boEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CpLaACsQ; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-61169-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61169-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com X-Forwarded-Encrypted: i=2; AJvYcCWtzyH6V+EON6W/FhaALvtHlyrydhuOEhhFFc6x87fAhz1RAk73Eac1KJgJUjf8H4tmIXg6VeIV9XnjgUQjWaaKDekdWg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w4-20020a056402268400b00560c0047677si2677063edd.211.2024.02.12.00.01.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 00:01:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61169-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CpLaACsQ; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-61169-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61169-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E183A1F23EAD for ; Mon, 12 Feb 2024 08:01:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3775B200C4; Mon, 12 Feb 2024 07:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="CpLaACsQ" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CD408C11; Mon, 12 Feb 2024 07:57:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724635; cv=none; b=l/+hlOGMwceT3tB+YUL9wMWVOWzrDZZt6MesO7LE1C3AUgOXVn8eSt2PatlReAXXbBnR9unFhlHFW0yXW1dCHKWYXvMd04lkFpP32thIqkOosQ7odbreLX42qZFxpH4enhZteralwC1siG0LBJG91sIIFFOWOlX6RfzvOBVBfxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724635; c=relaxed/simple; bh=o3GCbQ0HDcwCxhsdiMaIWoSqnIsvjGA8R22JTLCknSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YD6tRNyU/fleZuj4d8QRJDnbQMI3xKsYbwpXhzq4332ukeykdwqNK4pPKl3CReEvJk37ognVVzFqPP74UpFGMWkMDfxAZidoq87mP6/+zUGzFRt9HC3ppV7olD7LipI1Tx5kK29s+X2f/vSZ7UazFSc6KZKYwZa6T0j2rOQeXUQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=CpLaACsQ; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id C9FF840004; Mon, 12 Feb 2024 07:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707724625; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dO1lu7mTt2Z5I540dnIACd6uZE/pOpssk6saKJ+PaEA=; b=CpLaACsQqjVCxN1nDvdqzfPxoK1c54PfXjzOH48eWawocztOZXx2gYfUdXnPtLJfD/zwbW HyNy8ENJ/CsO/jjE3/roWYzZWWBqapfQ4ba+cUGTsffzeTPu1l2+H1emZR94NdNXOHqAdF FwqB2GWmv4+usRkdeDTaCDuVVHo48aC3MAS9Ybi5ZljBc3hWkKzsfQRhQdOqq+F1Q38H3k uIKQJ9rAMvXwGYyUDVmR9LgSAbEsR6cts4SuZ7nno8mfI88IyCOc4sgts7peljBefZ0NGC PlgY7J8bO7GSPUtos5sLZGQ8tW6OALCQPUlJVdmAt9LD0zo2hpVLc3C/xQVn6Q== From: Herve Codina To: Vadim Fedorenko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Herve Codina , Yury Norov , Andy Shevchenko , Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Andrew Lunn , Mark Brown , Christophe Leroy , Thomas Petazzoni Subject: [PATCH v3 RESEND 4/6] bitmap: Introduce bitmap_off() Date: Mon, 12 Feb 2024 08:56:32 +0100 Message-ID: <20240212075646.19114-5-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212075646.19114-1-herve.codina@bootlin.com> References: <20240212075646.19114-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790679311357425009 X-GMAIL-MSGID: 1790679311357425009 The bitmap_onto() function translates one bitmap relative to another but no function are present to perform the reverse translation. Introduce bitmap_off() to fill this hole. Signed-off-by: Herve Codina --- include/linux/bitmap.h | 3 +++ lib/bitmap.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 99451431e4d6..5ecfcbbc91f4 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -65,6 +65,7 @@ struct device; * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src) * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit) * bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap + * bitmap_off(dst, orig, relmap, nbits) *dst = bitmap_onto() reverse operation * bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz * bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf * bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf @@ -208,6 +209,8 @@ int bitmap_bitremap(int oldbit, const unsigned long *old, const unsigned long *new, int bits); void bitmap_onto(unsigned long *dst, const unsigned long *orig, const unsigned long *relmap, unsigned int bits); +void bitmap_off(unsigned long *dst, const unsigned long *orig, + const unsigned long *relmap, unsigned int bits); void bitmap_fold(unsigned long *dst, const unsigned long *orig, unsigned int sz, unsigned int nbits); diff --git a/lib/bitmap.c b/lib/bitmap.c index 2feccb5047dc..71343967335e 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -682,6 +682,48 @@ void bitmap_onto(unsigned long *dst, const unsigned long *orig, } EXPORT_SYMBOL(bitmap_onto); +/** + * bitmap_off - revert operation done by bitmap_onto() + * @dst: resulting translated bitmap + * @orig: original untranslated bitmap + * @relmap: bitmap relative to which translated + * @bits: number of bits in each of these bitmaps + * + * Suppose onto computed using bitmap_onto(onto, src, relmap, n) + * The operation bitmap_off(result, onto, relmap, n) leads to a + * result equal or equivalent to src. + * + * The result can be 'equivalent' because bitmap_onto() and + * bitmap_off() are not bijective. + * The result and src values are equivalent in that sense that a + * call to bitmap_onto(onto, src, relmap, n) and a call to + * bitmap_onto(onto, result, relmap, n) will lead to the same onto + * value. + * + * If either of @orig or @relmap is empty (no set bits), then @dst + * will be returned empty. + * + * All bits in @dst not set by the above rule are cleared. + */ +void bitmap_off(unsigned long *dst, const unsigned long *orig, + const unsigned long *relmap, unsigned int bits) +{ + unsigned int n, m; /* same meaning as in above comment */ + + if (dst == orig) /* following doesn't handle inplace mappings */ + return; + bitmap_zero(dst, bits); + + m = 0; + for_each_set_bit(n, relmap, bits) { + /* m == bitmap_pos_to_ord(relmap, n, bits) */ + if (test_bit(n, orig)) + set_bit(m, dst); + m++; + } +} +EXPORT_SYMBOL(bitmap_off); + #ifdef CONFIG_NUMA /** * bitmap_fold - fold larger bitmap into smaller, modulo specified size From patchwork Mon Feb 12 07:56:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 199611 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2290538dyd; Mon, 12 Feb 2024 00:02:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqsBYdfpYO2sQxOd2gy1tQwJodLCkdZ73Hvpl4v+n2CdM0nnLaaWCm5d5BTXjEU1yXhc+2 X-Received: by 2002:aa7:d8c7:0:b0:561:4460:6726 with SMTP id k7-20020aa7d8c7000000b0056144606726mr3793074eds.26.1707724963552; Mon, 12 Feb 2024 00:02:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707724963; cv=pass; d=google.com; s=arc-20160816; b=C0/MYoDfEgp75wn8/Xed60V0S4MVeDg/axkSLVX22UPbB6Sh2L/W5x3lD79dXUvFxt 5C5ixZ3BFNlY/Abm/SyUNhta63fFDFX11SBudTF23FVcMmVIEUjevUygSvx83NTudYNZ ZyFY1d2YoWZHrJdjPDa8XPCDCGg90S0UvX0p8+23iltWKiycJgq1Ssx39YbznQvdZT39 OmI49o2GZddstw/jbdaSOmdFQpVuZFlCT+/DwDY+SI3RC/kEoZ6t5sq5Z98S70BHQXAD uUEsDoerxsQ1Mkt65Ma3PDNK+IPib77Vao5C4o8/kyV6JXAZBRfDazxD5WfPh1GT6MD2 YapA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Mnr/8SaId4TQmwlcsvncrRDg9MKoU24/PP9bl0L71cE=; fh=hln+xUmHVVmSM0cClLt8slFSJ0JWHC9D2VECbbrWy+0=; b=FNllJiJ3aX5ySKjn6tVct/jHJdEk5rs/KK8bqHT2rk5pz5Mq3WkorsJGjA7ZNeqn6I 0xruV3w7Cidw0OWujKtfeMhi29xkjzQtBE0uFJ32zeJY8mVeElaVGK444uh774o0FFuK J4i2txZWs3i7qirK0XCUteWeA8xDobnmls7PMEqlQhinK2LguvVEKCUG582Q1WuID5lY LocjcYuZTqc6S1zLvgc/NpyMJTl0EylPR7ALsPs5QbCKd6wkxiFKLQNnlZvsIJboBjup m13KBA6oXIq4ryYS7Aj+VRWZ9FyjVxLGDIg2KyT1pnRqZa4Mtw6dX0Vd+OX96T+eXyac mn4A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=nr9hfZdB; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-61170-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61170-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com X-Forwarded-Encrypted: i=2; AJvYcCWWyL3CfT5vMF9IVjJm8CDyCy0ODTm6SuP99SYeQOq2eAPZtpqQJVBuTAtOiigdu2iOLikMQ62x6mj2RzvXvFiGkKHN9g== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bc14-20020a056402204e00b00560c3328bd6si2413853edb.419.2024.02.12.00.02.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 00:02:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61170-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=nr9hfZdB; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-61170-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61170-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 77FCD1F23032 for ; Mon, 12 Feb 2024 08:01:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B2F7922329; Mon, 12 Feb 2024 07:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="nr9hfZdB" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B1388C1D; Mon, 12 Feb 2024 07:57:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724635; cv=none; b=owSh6HnBnGldhSo03YU5SO12V05S3/lIfG7Ogd3VM93RSGmYHzmBKPSqfGUr6b1KqRmnibp8Vys3d7CVkIgo2xT51YmZfxVEa6P0PCH+6rDZWzm2oOropE1x6r4KSs2f1iodR72PTbRewKmhVl8hFNYqfgUXoShGnZ/4BaDtZkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724635; c=relaxed/simple; bh=JFtFcS1VHW8uz9WV52OuBJeyIDw8KBqSgMRDBSqSSCA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UjfTMNKR0C0Nf9GHay7shUdNv8yJlxjsr3bH208nl33nMeIvAY/Ne1NJzPrQgoFXAF83+hSkI/JpRI3al9r97ZArbpPdI031Aw8DJcYuV3pHev1naQpDNypaWFFCiioLLOaBUvg3pe7hhvtMXm7UV0PKtaF7CgmPimaC9mG44Yo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=nr9hfZdB; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 907714000D; Mon, 12 Feb 2024 07:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707724626; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mnr/8SaId4TQmwlcsvncrRDg9MKoU24/PP9bl0L71cE=; b=nr9hfZdBszv++wLniFfTFd4DUG08XXRCv8/1ox4hhY9+tLTuwYar7/U8i2j0Kiz3nKgzFI XLKx5NL9ASmbPja7KHtCT8xox/LJ74rfKO0OnhE/R6iqv4a51KgQeikfAGc4xi+YhlPeZA WU9Geiz7LcLHZ/q+wBPAj+aWqK6vPkwAZgwuNpQLy/iEykwdnpUw1s5rnEftHxa03Y1+BU wNIUR/R/faxrxW+zOGPIrhOMO3hic5w6GKXkSlQwku1ZstLyCPdAHFQLs0WZrEuruhm+sS wIl2SZryLhywJ7Si2J0ZB2qw51avHBxlhdhPdLKOzSF0fkBn69mlLGh+m+u5RA== From: Herve Codina To: Vadim Fedorenko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Herve Codina , Yury Norov , Andy Shevchenko , Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Andrew Lunn , Mark Brown , Christophe Leroy , Thomas Petazzoni Subject: [PATCH v3 RESEND 5/6] net: wan: fsl_qmc_hdlc: Add runtime timeslots changes support Date: Mon, 12 Feb 2024 08:56:33 +0100 Message-ID: <20240212075646.19114-6-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212075646.19114-1-herve.codina@bootlin.com> References: <20240212075646.19114-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790679411569123647 X-GMAIL-MSGID: 1790679411569123647 QMC channels support runtime timeslots changes but nothing is done at the QMC HDLC driver to handle these changes. Use existing IFACE ioctl in order to configure the timeslots to use. Signed-off-by: Herve Codina Reviewed-by: Christophe Leroy Acked-by: Jakub Kicinski --- drivers/net/wan/fsl_qmc_hdlc.c | 152 ++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 1 deletion(-) diff --git a/drivers/net/wan/fsl_qmc_hdlc.c b/drivers/net/wan/fsl_qmc_hdlc.c index 835500910d1b..b25d918d5e4e 100644 --- a/drivers/net/wan/fsl_qmc_hdlc.c +++ b/drivers/net/wan/fsl_qmc_hdlc.c @@ -7,6 +7,7 @@ * Author: Herve Codina */ +#include #include #include #include @@ -32,6 +33,7 @@ struct qmc_hdlc { struct qmc_hdlc_desc tx_descs[8]; unsigned int tx_out; struct qmc_hdlc_desc rx_descs[4]; + u32 slot_map; }; static struct qmc_hdlc *netdev_to_qmc_hdlc(struct net_device *netdev) @@ -206,6 +208,144 @@ static netdev_tx_t qmc_hdlc_xmit(struct sk_buff *skb, struct net_device *netdev) return ret; } +static int qmc_hdlc_xlate_slot_map(struct qmc_hdlc *qmc_hdlc, + u32 slot_map, struct qmc_chan_ts_info *ts_info) +{ + DECLARE_BITMAP(ts_mask_avail, 64); + DECLARE_BITMAP(ts_mask, 64); + DECLARE_BITMAP(map, 64); + + /* Tx and Rx available masks must be identical */ + if (ts_info->rx_ts_mask_avail != ts_info->tx_ts_mask_avail) { + dev_err(qmc_hdlc->dev, "tx and rx available timeslots mismatch (0x%llx, 0x%llx)\n", + ts_info->rx_ts_mask_avail, ts_info->tx_ts_mask_avail); + return -EINVAL; + } + + bitmap_from_u64(ts_mask_avail, ts_info->rx_ts_mask_avail); + bitmap_from_u64(map, slot_map); + bitmap_onto(ts_mask, map, ts_mask_avail, 64); + + if (bitmap_weight(ts_mask, 64) != bitmap_weight(map, 64)) { + dev_err(qmc_hdlc->dev, "Cannot translate timeslots %*pb -> (%*pb, %*pb)\n", + 64, map, 64, ts_mask_avail, 64, ts_mask); + return -EINVAL; + } + + bitmap_to_arr64(&ts_info->tx_ts_mask, ts_mask, 64); + ts_info->rx_ts_mask = ts_info->tx_ts_mask; + return 0; +} + +static int qmc_hdlc_xlate_ts_info(struct qmc_hdlc *qmc_hdlc, + const struct qmc_chan_ts_info *ts_info, u32 *slot_map) +{ + DECLARE_BITMAP(ts_mask_avail, 64); + DECLARE_BITMAP(ts_mask, 64); + DECLARE_BITMAP(map, 64); + u32 array32[2]; + + /* Tx and Rx masks and available masks must be identical */ + if (ts_info->rx_ts_mask_avail != ts_info->tx_ts_mask_avail) { + dev_err(qmc_hdlc->dev, "tx and rx available timeslots mismatch (0x%llx, 0x%llx)\n", + ts_info->rx_ts_mask_avail, ts_info->tx_ts_mask_avail); + return -EINVAL; + } + if (ts_info->rx_ts_mask != ts_info->tx_ts_mask) { + dev_err(qmc_hdlc->dev, "tx and rx timeslots mismatch (0x%llx, 0x%llx)\n", + ts_info->rx_ts_mask, ts_info->tx_ts_mask); + return -EINVAL; + } + + bitmap_from_u64(ts_mask_avail, ts_info->rx_ts_mask_avail); + bitmap_from_u64(ts_mask, ts_info->rx_ts_mask); + bitmap_off(map, ts_mask, ts_mask_avail, 64); + + if (bitmap_weight(ts_mask, 64) != bitmap_weight(map, 64)) { + dev_err(qmc_hdlc->dev, "Cannot translate timeslots (%*pb, %*pb) -> %*pb\n", + 64, ts_mask_avail, 64, ts_mask, 64, map); + return -EINVAL; + } + + bitmap_to_arr32(array32, map, 64); + if (array32[1]) { + dev_err(qmc_hdlc->dev, "Slot map out of 32bit (%*pb, %*pb) -> %*pb\n", + 64, ts_mask_avail, 64, ts_mask, 64, map); + return -EINVAL; + } + + *slot_map = array32[0]; + return 0; +} + +static int qmc_hdlc_set_iface(struct qmc_hdlc *qmc_hdlc, int if_iface, const te1_settings *te1) +{ + struct qmc_chan_ts_info ts_info; + int ret; + + ret = qmc_chan_get_ts_info(qmc_hdlc->qmc_chan, &ts_info); + if (ret) { + dev_err(qmc_hdlc->dev, "get QMC channel ts info failed %d\n", ret); + return ret; + } + ret = qmc_hdlc_xlate_slot_map(qmc_hdlc, te1->slot_map, &ts_info); + if (ret) + return ret; + + ret = qmc_chan_set_ts_info(qmc_hdlc->qmc_chan, &ts_info); + if (ret) { + dev_err(qmc_hdlc->dev, "set QMC channel ts info failed %d\n", ret); + return ret; + } + + qmc_hdlc->slot_map = te1->slot_map; + + return 0; +} + +static int qmc_hdlc_ioctl(struct net_device *netdev, struct if_settings *ifs) +{ + struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev); + te1_settings te1; + + switch (ifs->type) { + case IF_GET_IFACE: + ifs->type = IF_IFACE_E1; + if (ifs->size < sizeof(te1)) { + if (!ifs->size) + return 0; /* only type requested */ + + ifs->size = sizeof(te1); /* data size wanted */ + return -ENOBUFS; + } + + memset(&te1, 0, sizeof(te1)); + + /* Update slot_map */ + te1.slot_map = qmc_hdlc->slot_map; + + if (copy_to_user(ifs->ifs_ifsu.te1, &te1, sizeof(te1))) + return -EFAULT; + return 0; + + case IF_IFACE_E1: + case IF_IFACE_T1: + if (!capable(CAP_NET_ADMIN)) + return -EPERM; + + if (netdev->flags & IFF_UP) + return -EBUSY; + + if (copy_from_user(&te1, ifs->ifs_ifsu.te1, sizeof(te1))) + return -EFAULT; + + return qmc_hdlc_set_iface(qmc_hdlc, ifs->type, &te1); + + default: + return hdlc_ioctl(netdev, ifs); + } +} + static int qmc_hdlc_open(struct net_device *netdev) { struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev); @@ -332,13 +472,14 @@ static const struct net_device_ops qmc_hdlc_netdev_ops = { .ndo_open = qmc_hdlc_open, .ndo_stop = qmc_hdlc_close, .ndo_start_xmit = hdlc_start_xmit, - .ndo_siocwandev = hdlc_ioctl, + .ndo_siocwandev = qmc_hdlc_ioctl, }; static int qmc_hdlc_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct qmc_hdlc *qmc_hdlc; + struct qmc_chan_ts_info ts_info; struct qmc_chan_info info; hdlc_device *hdlc; int ret; @@ -368,6 +509,15 @@ static int qmc_hdlc_probe(struct platform_device *pdev) return -EINVAL; } + ret = qmc_chan_get_ts_info(qmc_hdlc->qmc_chan, &ts_info); + if (ret) { + dev_err(qmc_hdlc->dev, "get QMC channel ts info failed %d\n", ret); + return ret; + } + ret = qmc_hdlc_xlate_ts_info(qmc_hdlc, &ts_info, &qmc_hdlc->slot_map); + if (ret) + return ret; + qmc_hdlc->netdev = alloc_hdlcdev(qmc_hdlc); if (!qmc_hdlc->netdev) { dev_err(qmc_hdlc->dev, "failed to alloc hdlc dev\n"); From patchwork Mon Feb 12 07:56:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 199616 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2297524dyd; Mon, 12 Feb 2024 00:22:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHvvhSibhC3dKO5BQEVTyXnfKfUtWeN5CAYlYSi6C49d5qmeghCExi1Ah5lyPLOoHmJWkQP X-Received: by 2002:aa7:8685:0:b0:6df:e85e:ecc6 with SMTP id d5-20020aa78685000000b006dfe85eecc6mr5534103pfo.3.1707726123175; Mon, 12 Feb 2024 00:22:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707726123; cv=pass; d=google.com; s=arc-20160816; b=J1rDafY4TkB6oqpkOLPOBRQujGgJxcjeCmce/1t2ySFtiYynYJrj6yooB4l1BFtEY7 h9BAUCVvtRu41eyqpMilCbjoTffetSFLybuESUFXVz8wkwLe4dYcUIKOo2j5ogNx5V7c DXWz/z/yRQOb0cA6UWTMUNrwpegRjWVdVLEu5zsxnLbYyYVYrSbS60jYLXd3BhoOdRBd EaaZU63+BpiK4Lm95l+ZEux1Q0jIZ2zwWHi5rKWNaHQrS1JGw7g019vpemWllL56Pqjw bPJj1eZsw4yR5wHTIxwLkomNQEkB5+I3UNSIxCXnK3MXf0uVrfInHk17xoo+k+sfNMub /Tcw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=BiEtrlkAacMQ7ZsOH+miZS1Nj46VD4t7KhVmkzLQVRU=; fh=LpmsQ1zLzPb7CAbc1by5zOqbSqtx6MJC4y1sU4ps2ho=; b=Q8sxdLhtwZxARJz3c4vYUWozyp7auVVJRJsO1ZWln1tQQo4yWn72eW2vEOA2UhZ+1C l5EvTd1XhHJphEh353qU+iBFyaq7ROirtvf2rLNeoN6i9ToI0VGVDy3I+CvqebIhOyRh BgPXQ4chYC5CJEeY512ipv3jJqLRP/nobQrirFLLaGF7Ljd1KHQEZJQlrjH8LpuIMtOn 2g2ke7XZX1FOmYoFVQtUnJ5aTODuCdpW3HnhHNAmeCUib55Pc19ynYemiJnXtprtg+Pf WIByGJfeMPwiaWv4bpaSlraNnzWlhMT56bzrgbEUU7L6RaRZQNYSElqkYWb7vGkffqxV RLCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=YTLixMEz; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-61174-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61174-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com X-Forwarded-Encrypted: i=2; AJvYcCV6ToVYfW3m2XwLSpTxdgfowY6ques0ZpV5tbkThItcdc++qUs8t9l3QBV4BCIgTnYrZ4C8QHWrs2+/noL9VlaKvOK5lg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id fn7-20020a056a002fc700b006dfebd23706si4623982pfb.67.2024.02.12.00.22.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 00:22:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61174-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=YTLixMEz; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-61174-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61174-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D5B04B261AF for ; Mon, 12 Feb 2024 08:01:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD04F17C79; Mon, 12 Feb 2024 07:57:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="YTLixMEz" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DA75F9FD; Mon, 12 Feb 2024 07:57:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724636; cv=none; b=UpvhKh/nmtCJrqrgFcNd8JSh4G9FyjjBsbk6jO+rVaJsT2x7vlXoC9PzONTdvMBrW4Z2gsHGan7/3sLA0MJ4aOl90NICV34FL3TlBNafgkpruV759rZLN8AWKKkpWQ/5fpSu9z7Axy8FiWnZA1QkTi1iOO0DLTlHf5UjRouWVRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707724636; c=relaxed/simple; bh=hU4776sYBDi68msbbKmdhIQkHDVJX9tyYRGpSrCg92A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jE0aFGNKZLu6yzOaFGIUOReh7WFjCPwZKns9n9yPLpRa+HB7VLkHFKUTZKjQ8sTx5IoBGkn2bUO9AWTQMzIDUBNf2GRipXiJJHjk6wtyTm0PNuhdYksmlfElvWmg9YQAisX+hPAQiPWDRuMJhgCZi70wdOgjCijtaUH4kqKh9BA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=YTLixMEz; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id 6801840011; Mon, 12 Feb 2024 07:57:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1707724627; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BiEtrlkAacMQ7ZsOH+miZS1Nj46VD4t7KhVmkzLQVRU=; b=YTLixMEzeut5Jpj+DJhJpSiZBGX9OG6gnBQ5t1PW7jinImQt3i5ynTqGMiAj18hDs1xkP/ KI5oEOSXmtGxuMgILH8zIOUqgh0etpj0kBPfmTDmd31Y/fFrOJ+ZSLeIGZM+k3wMi0BS6q +9vakHCwn90Yj0nrY3u97A1rgNiqoJU5qEQBFCp20s2xC3esatNCJa0PzHQgBcU0NXWpCA uc2rQkk8ICbF1dR+YeM6OcO54xQ1+KDTPGR06QklR3+gnN21CLc50w7nTGx13IdyhMR/7P q2KKjCmXAnSILZIXTDN9t3IIidJRawnbkrBj7rnNImbu3E5kFOceumasF8FNpw== From: Herve Codina To: Vadim Fedorenko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Herve Codina , Yury Norov , Andy Shevchenko , Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Andrew Lunn , Mark Brown , Christophe Leroy , Thomas Petazzoni Subject: [PATCH v3 RESEND 6/6] net: wan: fsl_qmc_hdlc: Add framer support Date: Mon, 12 Feb 2024 08:56:34 +0100 Message-ID: <20240212075646.19114-7-herve.codina@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212075646.19114-1-herve.codina@bootlin.com> References: <20240212075646.19114-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790680627223588851 X-GMAIL-MSGID: 1790680627223588851 Add framer support in the fsl_qmc_hdlc driver in order to be able to signal carrier changes to the network stack based on the framer status Also use this framer to provide information related to the E1/T1 line interface on IF_GET_IFACE and configure the line interface according to IF_IFACE_{E1,T1} information. Signed-off-by: Herve Codina Reviewed-by: Christophe Leroy --- drivers/net/wan/fsl_qmc_hdlc.c | 239 ++++++++++++++++++++++++++++++++- 1 file changed, 235 insertions(+), 4 deletions(-) diff --git a/drivers/net/wan/fsl_qmc_hdlc.c b/drivers/net/wan/fsl_qmc_hdlc.c index b25d918d5e4e..432b5111b106 100644 --- a/drivers/net/wan/fsl_qmc_hdlc.c +++ b/drivers/net/wan/fsl_qmc_hdlc.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -28,6 +29,9 @@ struct qmc_hdlc { struct device *dev; struct qmc_chan *qmc_chan; struct net_device *netdev; + struct framer *framer; + spinlock_t carrier_lock; /* Protect carrier detection */ + struct notifier_block nb; bool is_crc32; spinlock_t tx_lock; /* Protect tx descriptors */ struct qmc_hdlc_desc tx_descs[8]; @@ -41,6 +45,195 @@ static struct qmc_hdlc *netdev_to_qmc_hdlc(struct net_device *netdev) return dev_to_hdlc(netdev)->priv; } +static int qmc_hdlc_framer_set_carrier(struct qmc_hdlc *qmc_hdlc) +{ + struct framer_status framer_status; + unsigned long flags; + int ret; + + if (!qmc_hdlc->framer) + return 0; + + spin_lock_irqsave(&qmc_hdlc->carrier_lock, flags); + + ret = framer_get_status(qmc_hdlc->framer, &framer_status); + if (ret) { + dev_err(qmc_hdlc->dev, "get framer status failed (%d)\n", ret); + goto end; + } + if (framer_status.link_is_on) + netif_carrier_on(qmc_hdlc->netdev); + else + netif_carrier_off(qmc_hdlc->netdev); + +end: + spin_unlock_irqrestore(&qmc_hdlc->carrier_lock, flags); + return ret; +} + +static int qmc_hdlc_framer_notifier(struct notifier_block *nb, unsigned long action, + void *data) +{ + struct qmc_hdlc *qmc_hdlc = container_of(nb, struct qmc_hdlc, nb); + int ret; + + if (action != FRAMER_EVENT_STATUS) + return NOTIFY_DONE; + + ret = qmc_hdlc_framer_set_carrier(qmc_hdlc); + return ret ? NOTIFY_DONE : NOTIFY_OK; +} + +static int qmc_hdlc_framer_start(struct qmc_hdlc *qmc_hdlc) +{ + struct framer_status framer_status; + int ret; + + if (!qmc_hdlc->framer) + return 0; + + ret = framer_power_on(qmc_hdlc->framer); + if (ret) { + dev_err(qmc_hdlc->dev, "framer power-on failed (%d)\n", ret); + return ret; + } + + /* Be sure that get_status is supported */ + ret = framer_get_status(qmc_hdlc->framer, &framer_status); + if (ret) { + dev_err(qmc_hdlc->dev, "get framer status failed (%d)\n", ret); + goto framer_power_off; + } + + qmc_hdlc->nb.notifier_call = qmc_hdlc_framer_notifier; + ret = framer_notifier_register(qmc_hdlc->framer, &qmc_hdlc->nb); + if (ret) { + dev_err(qmc_hdlc->dev, "framer notifier register failed (%d)\n", ret); + goto framer_power_off; + } + + return 0; + +framer_power_off: + framer_power_off(qmc_hdlc->framer); + return ret; +} + +static void qmc_hdlc_framer_stop(struct qmc_hdlc *qmc_hdlc) +{ + if (!qmc_hdlc->framer) + return; + + framer_notifier_unregister(qmc_hdlc->framer, &qmc_hdlc->nb); + framer_power_off(qmc_hdlc->framer); +} + +static int qmc_hdlc_framer_set_iface(struct qmc_hdlc *qmc_hdlc, int if_iface, + const te1_settings *te1) +{ + struct framer_config config; + int ret; + + if (!qmc_hdlc->framer) + return 0; + + ret = framer_get_config(qmc_hdlc->framer, &config); + if (ret) + return ret; + + switch (if_iface) { + case IF_IFACE_E1: + config.iface = FRAMER_IFACE_E1; + break; + case IF_IFACE_T1: + config.iface = FRAMER_IFACE_T1; + break; + default: + return -EINVAL; + } + + switch (te1->clock_type) { + case CLOCK_DEFAULT: + /* Keep current value */ + break; + case CLOCK_EXT: + config.clock_type = FRAMER_CLOCK_EXT; + break; + case CLOCK_INT: + config.clock_type = FRAMER_CLOCK_INT; + break; + default: + return -EINVAL; + } + config.line_clock_rate = te1->clock_rate; + + return framer_set_config(qmc_hdlc->framer, &config); +} + +static int qmc_hdlc_framer_get_iface(struct qmc_hdlc *qmc_hdlc, int *if_iface, te1_settings *te1) +{ + struct framer_config config; + int ret; + + if (!qmc_hdlc->framer) { + *if_iface = IF_IFACE_E1; + return 0; + } + + ret = framer_get_config(qmc_hdlc->framer, &config); + if (ret) + return ret; + + switch (config.iface) { + case FRAMER_IFACE_E1: + *if_iface = IF_IFACE_E1; + break; + case FRAMER_IFACE_T1: + *if_iface = IF_IFACE_T1; + break; + } + + if (!te1) + return 0; /* Only iface type requested */ + + switch (config.clock_type) { + case FRAMER_CLOCK_EXT: + te1->clock_type = CLOCK_EXT; + break; + case FRAMER_CLOCK_INT: + te1->clock_type = CLOCK_INT; + break; + default: + return -EINVAL; + } + te1->clock_rate = config.line_clock_rate; + return 0; +} + +static int qmc_hdlc_framer_init(struct qmc_hdlc *qmc_hdlc) +{ + int ret; + + if (!qmc_hdlc->framer) + return 0; + + ret = framer_init(qmc_hdlc->framer); + if (ret) { + dev_err(qmc_hdlc->dev, "framer init failed (%d)\n", ret); + return ret; + } + + return 0; +} + +static void qmc_hdlc_framer_exit(struct qmc_hdlc *qmc_hdlc) +{ + if (!qmc_hdlc->framer) + return; + + framer_exit(qmc_hdlc->framer); +} + static int qmc_hdlc_recv_queue(struct qmc_hdlc *qmc_hdlc, struct qmc_hdlc_desc *desc, size_t size); #define QMC_HDLC_RX_ERROR_FLAGS (QMC_RX_FLAG_HDLC_OVF | \ @@ -300,6 +493,12 @@ static int qmc_hdlc_set_iface(struct qmc_hdlc *qmc_hdlc, int if_iface, const te1 qmc_hdlc->slot_map = te1->slot_map; + ret = qmc_hdlc_framer_set_iface(qmc_hdlc, if_iface, te1); + if (ret) { + dev_err(qmc_hdlc->dev, "framer set iface failed %d\n", ret); + return ret; + } + return 0; } @@ -307,11 +506,16 @@ static int qmc_hdlc_ioctl(struct net_device *netdev, struct if_settings *ifs) { struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev); te1_settings te1; + int ret; switch (ifs->type) { case IF_GET_IFACE: - ifs->type = IF_IFACE_E1; if (ifs->size < sizeof(te1)) { + /* Retrieve type only */ + ret = qmc_hdlc_framer_get_iface(qmc_hdlc, &ifs->type, NULL); + if (ret) + return ret; + if (!ifs->size) return 0; /* only type requested */ @@ -321,6 +525,11 @@ static int qmc_hdlc_ioctl(struct net_device *netdev, struct if_settings *ifs) memset(&te1, 0, sizeof(te1)); + /* Retrieve info from framer */ + ret = qmc_hdlc_framer_get_iface(qmc_hdlc, &ifs->type, &te1); + if (ret) + return ret; + /* Update slot_map */ te1.slot_map = qmc_hdlc->slot_map; @@ -354,10 +563,17 @@ static int qmc_hdlc_open(struct net_device *netdev) int ret; int i; - ret = hdlc_open(netdev); + ret = qmc_hdlc_framer_start(qmc_hdlc); if (ret) return ret; + ret = hdlc_open(netdev); + if (ret) + goto framer_stop; + + /* Update carrier */ + qmc_hdlc_framer_set_carrier(qmc_hdlc); + chan_param.mode = QMC_HDLC; /* HDLC_MAX_MRU + 4 for the CRC * HDLC_MAX_MRU + 4 + 8 for the CRC and some extraspace needed by the QMC @@ -407,6 +623,8 @@ static int qmc_hdlc_open(struct net_device *netdev) } hdlc_close: hdlc_close(netdev); +framer_stop: + qmc_hdlc_framer_stop(qmc_hdlc); return ret; } @@ -442,6 +660,7 @@ static int qmc_hdlc_close(struct net_device *netdev) } hdlc_close(netdev); + qmc_hdlc_framer_stop(qmc_hdlc); return 0; } @@ -490,6 +709,7 @@ static int qmc_hdlc_probe(struct platform_device *pdev) qmc_hdlc->dev = &pdev->dev; spin_lock_init(&qmc_hdlc->tx_lock); + spin_lock_init(&qmc_hdlc->carrier_lock); qmc_hdlc->qmc_chan = devm_qmc_chan_get_bychild(qmc_hdlc->dev, np); if (IS_ERR(qmc_hdlc->qmc_chan)) { @@ -518,10 +738,19 @@ static int qmc_hdlc_probe(struct platform_device *pdev) if (ret) return ret; + qmc_hdlc->framer = devm_framer_optional_get(qmc_hdlc->dev, "fsl,framer"); + if (IS_ERR(qmc_hdlc->framer)) + return PTR_ERR(qmc_hdlc->framer); + + ret = qmc_hdlc_framer_init(qmc_hdlc); + if (ret) + return ret; + qmc_hdlc->netdev = alloc_hdlcdev(qmc_hdlc); if (!qmc_hdlc->netdev) { dev_err(qmc_hdlc->dev, "failed to alloc hdlc dev\n"); - return -ENOMEM; + ret = -ENOMEM; + goto framer_exit; } hdlc = dev_to_hdlc(qmc_hdlc->netdev); @@ -537,11 +766,12 @@ static int qmc_hdlc_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, qmc_hdlc); - return 0; free_netdev: free_netdev(qmc_hdlc->netdev); +framer_exit: + qmc_hdlc_framer_exit(qmc_hdlc); return ret; } @@ -551,6 +781,7 @@ static int qmc_hdlc_remove(struct platform_device *pdev) unregister_hdlc_device(qmc_hdlc->netdev); free_netdev(qmc_hdlc->netdev); + qmc_hdlc_framer_exit(qmc_hdlc); return 0; }