Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1238299rdb; Wed, 24 Jan 2024 08:47:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4UsDrGfNXKvRVl6CljD151P7hXA5qRr1KgIzWZjhDjNVaxHVkto2PcUvC9Rjq61c4bWbz X-Received: by 2002:a05:6870:3288:b0:206:c65c:82fb with SMTP id q8-20020a056870328800b00206c65c82fbmr3623725oac.87.1706114868654; Wed, 24 Jan 2024 08:47:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706114868; cv=pass; d=google.com; s=arc-20160816; b=xaQieC6E1XGVfV1XcRsMVYwe3oGglaE7qvrwxVv6Lrc/TkyKAQEIlD0q2bPXfSxAHE X94X6ZDKeIPMpz4iX8v922nupIsGkhTbqHXOrx3EGJEo90IAD6WKsEzTunGdcv/II3db i5zCXUJ5iXwV+7ohS0qBNVbODp3SfeE1e8qfskiD+Trb5U3OCWNYiI/PO3jk/OhJH4a7 6ImAzOv+DgaC+q7i3kk/G069WUkr1vSSLkXYrTQ/Yt+ibAzjWe722EMP98bKRSy6bHlQ iaGqvsaLSrv6t4E3h46IyXtQF0geqoNcXt/kLzxa36xxw1E/pJxIdTabt/v7NKD9EBhx lNuA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature:message-id; bh=T7nuOJoOmUuNlLsb7W1RUqVrxhJT9IAhy3vPZcivD/I=; fh=Q6WVAWZfQTNbBJKENHKPzeqTTnV7BJ9R3VwGEOXFegw=; b=ztdiHfUFQHGP448M0eC6A5MG5POLLuPI8tjL/uEntyGZQq7QGakVjxyBUPOfPFCmKT LKIfqolZyjydCB6+Z9HPgx5uze5u3Gh9Wt7ms5kQrWnbWZDxKmnCdqW+ck5lw0+Iaw8t Os1cQeIr1/HVg4G4J+vWuK+MO6z/uYPb9QCY9tnWtm0qbjCs1FJpE5kejy5I+lkh8Nwt ajYqidcRPYzienX38D9dzJsD+0tb08v+HIvp2wG/TdFC9ENa9blh/oHoC96BqD/Wf6pD kAP5kU0PevAUziR/ccowP55iNVQ8U3+aw5BidIdd1Nbk48sDTO3/LBNwSbZPZs9ZBMLx J3SA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=MZuIvdus; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-37322-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37322-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f5-20020a631f05000000b00573f94e8b83si11705253pgf.265.2024.01.24.08.47.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 08:47:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37322-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=MZuIvdus; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-37322-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37322-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 1DC32B318E2 for ; Wed, 24 Jan 2024 16:19:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C5167CF37; Wed, 24 Jan 2024 16:19:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="MZuIvdus" Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 576121A702 for ; Wed, 24 Jan 2024 16:19:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706113155; cv=none; b=eDlcdEWA+JHyX3JtVhT0mKNEcp7I4eys+ftFA5X9Vk00p4ZX9tNP1GouJ2J41xmWbaJ4uwWfl+A4/DUZusdB+qIV1LvGyUXlERUEM7tVP+9wxVF20pj1JjG7iWAW3F6CTjkrq6i2nc+JTZ92tb1OsFpRgr3hwVJNHaMhA7LBkSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706113155; c=relaxed/simple; bh=40XQOYtPCjyB1xPaE3CSwJD38yBvVKSwSOB/CBE/KqE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=S/HgY2tVGWPBHlUa/aMcwkvE1xUGzMplZsuP+/w5ZagBIcEIQG9hbuNWlkLxBRqEEDx91TyS1VQIDTe3TzHayvkPsTTUbaPLvirt19iR7H/pKIofUSiNHzZXpSHYLdG8bNg/pll4YemhqljAvUqLsRl+Mfx8ky0BOQMm58TWfKA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=MZuIvdus; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1706113150; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T7nuOJoOmUuNlLsb7W1RUqVrxhJT9IAhy3vPZcivD/I=; b=MZuIvdus+xtMhzYerD1BMQmgJbGcBrj5pn4Z0ucLu1/71jxF5Cscc8r/KuSfTEpRSm1nSW H1LF8UzaGhvZYjGnOGoRJKeRBNW4h3ZGETfUWj/DUvjdpcD2EOPetvR0xBWhn4+GKkzOG4 mYRsBNdeKut6M/thnO7yA83MG+7raEA= Date: Wed, 24 Jan 2024 16:19:03 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH 3/4] net: wan: fsl_qmc_hdlc: Add runtime timeslots changes support Content-Language: en-US To: Herve Codina Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Andrew Lunn , Mark Brown , Christophe Leroy , Thomas Petazzoni References: <20240123164912.249540-1-herve.codina@bootlin.com> <20240123164912.249540-4-herve.codina@bootlin.com> <20240124162646.24bf9235@bootlin.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Vadim Fedorenko In-Reply-To: <20240124162646.24bf9235@bootlin.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 24/01/2024 15:26, Herve Codina wrote: > Hi Vadim, > > On Wed, 24 Jan 2024 10:10:46 +0000 > Vadim Fedorenko wrote: > > [...] >>> +static int qmc_hdlc_xlate_slot_map(struct qmc_hdlc *qmc_hdlc, >>> + u32 slot_map, struct qmc_chan_ts_info *ts_info) >>> +{ >>> + u64 ts_mask_avail; >>> + unsigned int bit; >>> + unsigned int i; >>> + u64 ts_mask; >>> + u64 map; >>> + >>> + /* Tx and Rx 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; >>> + } >>> + >>> + ts_mask_avail = ts_info->rx_ts_mask_avail; >>> + ts_mask = 0; >>> + map = slot_map; >>> + bit = 0; >>> + for (i = 0; i < 64; i++) { >>> + if (ts_mask_avail & BIT_ULL(i)) { >>> + if (map & BIT_ULL(bit)) >>> + ts_mask |= BIT_ULL(i); >>> + bit++; >>> + } >>> + } >>> + >>> + if (hweight64(ts_mask) != hweight64(map)) { >>> + dev_err(qmc_hdlc->dev, "Cannot translate timeslots 0x%llx -> (0x%llx,0x%llx)\n", >>> + map, ts_mask_avail, ts_mask); >>> + return -EINVAL; >>> + } >>> + >>> + ts_info->tx_ts_mask = ts_mask; >>> + ts_info->rx_ts_mask = 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) >>> +{ >>> + u64 ts_mask_avail; >>> + unsigned int bit; >>> + unsigned int i; >>> + u64 ts_mask; >>> + u64 map; >>> + >> >> Starting from here ... >> >>> + /* Tx and Rx 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; >>> + } >>> + >>> + ts_mask_avail = ts_info->rx_ts_mask_avail; >>> + ts_mask = ts_info->rx_ts_mask; >>> + map = 0; >>> + bit = 0; >>> + for (i = 0; i < 64; i++) { >>> + if (ts_mask_avail & BIT_ULL(i)) { >>> + if (ts_mask & BIT_ULL(i)) >>> + map |= BIT_ULL(bit); >>> + bit++; >>> + } >>> + } >>> + >>> + if (hweight64(ts_mask) != hweight64(map)) { >>> + dev_err(qmc_hdlc->dev, "Cannot translate timeslots (0x%llx,0x%llx) -> 0x%llx\n", >>> + ts_mask_avail, ts_mask, map); >>> + return -EINVAL; >>> + } >>> + >> >> till here the block looks like copy of the block from previous function. >> It worth to make a separate function for it, I think. >> >>> + if (map >= BIT_ULL(32)) { >>> + dev_err(qmc_hdlc->dev, "Slot map out of 32bit (0x%llx,0x%llx) -> 0x%llx\n", >>> + ts_mask_avail, ts_mask, map); >>> + return -EINVAL; >>> + } >>> + >>> + *slot_map = map; >>> + return 0; >>> +} >>> + > [...] > > I am not so sure. There are slighty differences between the two functions. > The error messages and, in particular, the loop in qmc_hdlc_xlate_slot_map() is: > --- 8< --- > ts_mask_avail = ts_info->rx_ts_mask_avail; > ts_mask = 0; > map = slot_map; > bit = 0; > for (i = 0; i < 64; i++) { > if (ts_mask_avail & BIT_ULL(i)) { > if (map & BIT_ULL(bit)) > ts_mask |= BIT_ULL(i); > bit++; > } > } > --- 8< --- > > whereas it is the following in qmc_hdlc_xlate_ts_info(): > --- 8< --- > ts_mask_avail = ts_info->rx_ts_mask_avail; > ts_mask = ts_info->rx_ts_mask; > map = 0; > bit = 0; > for (i = 0; i < 64; i++) { > if (ts_mask_avail & BIT_ULL(i)) { > if (ts_mask & BIT_ULL(i)) > map |= BIT_ULL(bit); > bit++; > } > } > --- 8< --- > > ts_map and map initializations are not the same, i and bit are not used for > the same purpose and the computed value is not computed based on the same > information. > > With that pointed, I am not sure that having some common code for both > function will be relevant. Your opinion ? I see. I'm just thinking if it's possible to use helpers from bitops.h and bitmap.h here to avoid open-coding common parts of the code. > Best regards, > Hervé