Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1188876rdb; Wed, 24 Jan 2024 07:27:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzN8lgwlGGrFyEkc7w/iimMV/6vw8lO7108Ld5Uq4K06ryCQ0pUa+ZDwmqOnsE7eO5OHgV X-Received: by 2002:a05:651c:128d:b0:2cc:c794:57c7 with SMTP id 13-20020a05651c128d00b002ccc79457c7mr736623ljc.43.1706110068119; Wed, 24 Jan 2024 07:27:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706110068; cv=pass; d=google.com; s=arc-20160816; b=qr+7tSxhpq5XbiCxFWN1OGxHedtSDGSHJAkdF42MbaVkr2X9Yae6tk9tOhPXljc51U nwKifDWkqdZ/pjurc+fJIrdEK4q7d74IVPMn19cdbmV3t/Co4Bk5EH+xj+3P279UAd79 5EozLSUng757robP/U0r76qTC0VRUWAlMJaF/rhCU6Fl52FMENRA7Rk7ftvkWdhCPCmS py7gEf7HC1Gq1V0d2lsrPjgy7KNDo6/JUaAjxQUIGUN9CccErPyt0xbVioshvG42GJk3 VexO3WFGC5Ux9bB5oEze0VaLyR4CltU0KfXRvGx2cLOxS6GKZwzWbdll1ET05zb7FgvB PkIA== 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:organization:references :in-reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=TGKqb8PfNbcdc7vOG6mzmbB70CQFl8QHgJOa/gqXS78=; fh=KpRe2PBCN+FCgwRoSRg7sgkK/rF3Dvo4HCZrpuZXDfQ=; b=vCM/4IBsZiNGArzLF67eF2qAwkQKjkiabeMFQKu4HphE85J/R+1pzZeQT7hVenG7uD GVdHVRzhherv8QkHZBm9Evae7g4kDEscHS1dGDHfjTPFZUqWpqLTnywH1tSfGF4QQJkB O/HmQPhkRNay7X5MgU1vtKCiwpt2+kV8/kfMuUfGIL6QzVc7QZpWZuEvk21hj13RNRKg 2xMdJFFQ7K84aXslKq5yqqp0Z3Qept1HZvQz9ivBOr5cLvfxxP0iMHWBr4cM/oxBEAnF HLWGnrH8/b8+nwHY12hrArq4us9w9NLRnMau+GUVcoAQuk9i4PttQwXqjcDfF/X/iUQv M28A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=XOOstg60; 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-37249-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37249-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id en13-20020a056402528d00b005581bbd7314si13953184edb.130.2024.01.24.07.27.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 07:27:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37249-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=XOOstg60; 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-37249-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37249-linux.lists.archive=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 3D58F1F23D7C for ; Wed, 24 Jan 2024 15:27:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0093F7C08D; Wed, 24 Jan 2024 15:26:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="XOOstg60" Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 03B7F22085; Wed, 24 Jan 2024 15:26:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706110015; cv=none; b=D3Zfqqq/ZJxSgtmhGp/PQshmEX0OGMYlYVi3hsl2u6w6xNcan6vyFqlJO/9TErlIANNX68NbxiSLhfHVnJO67RFeszZQ4sNzpnXDYKYxe0m4tCYOnGSAIEDgMdenZFsIKYBdm4/8RNs9bab2cqF8G5V1MTldpDSI5lQbtAQ9Abw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706110015; c=relaxed/simple; bh=4P57sBKVCs3MY83Hd0Fp0MqjqaVsRdjUHDjmEhi/6eI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XdLHPPeHW97QED7v3Z2Ks7Lm3vU4JCUckTy7OKjc+n3Hi0NlCK2vc0drO9Ezyr2sCjj4pXjN7S1W4n+d3B75P3xBhPb+cwWH5+ldAE76bK5ymdWlI7B5qeVwe9zBA1m5/kNEj9rjLVG2GVjYslYnNeLqm3eJYUQjLibZa8hwPrU= 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=XOOstg60; arc=none smtp.client-ip=217.70.183.195 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 ESMTPSA id A345160007; Wed, 24 Jan 2024 15:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1706110010; 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=TGKqb8PfNbcdc7vOG6mzmbB70CQFl8QHgJOa/gqXS78=; b=XOOstg60KgIbgyGgmgT6sVR+BznJZGxgtuMaNvi2uKxrvRhNy0pjmLTdmOBWrHpbzQOpxS gUiZyRRXGNu/gasgAWh7ilfgenSA6py0gC5+riKvq+4tO+vAfjwYeezowvUng4cyc4v/Mt oGwBLecvDGt1t2XaQfjyOaYG/KulXg4RiGl8yVc+xE//JvRuqhAxWcw7bAA6+Eewl1AViQ /MUZjmldwWdDWBo8f4Vws99TzRH2Y4MtOhK/JhxY8OFw/Cy7f2GTJtGR7xmQwLRH+897pa 5Z2z5yCNRuXSmtflltBdnP2vfasJ9Lm/Do09I6ql4bK1psTTfe//1/331v8bTA== Date: Wed, 24 Jan 2024 16:26:46 +0100 From: Herve Codina To: Vadim Fedorenko 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 Subject: Re: [PATCH 3/4] net: wan: fsl_qmc_hdlc: Add runtime timeslots changes support Message-ID: <20240124162646.24bf9235@bootlin.com> In-Reply-To: References: <20240123164912.249540-1-herve.codina@bootlin.com> <20240123164912.249540-4-herve.codina@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.2.0 (GTK 3.24.38; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com 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 ? Best regards, Hervé