Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp551478lqs; Tue, 5 Mar 2024 09:15:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXqLOLjz6S9sUQpBKAc9jc+anGSaswaVwAg6G4u51mpfn8Wu1tVYJW2zaGaOqIz7l8SQxgJhMxRE3F+BewFfIoEleHdJCnXMARbpDRsZg== X-Google-Smtp-Source: AGHT+IH+SLbbshXRsSoUcxQ1+HpcrEtqXhhuVYaHhrUl6cfxP4WRZ0/xAAtBtbUX424bYxgLpKqb X-Received: by 2002:a05:6a20:6a27:b0:1a0:ef1e:a658 with SMTP id p39-20020a056a206a2700b001a0ef1ea658mr2568570pzk.11.1709658953027; Tue, 05 Mar 2024 09:15:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709658953; cv=pass; d=google.com; s=arc-20160816; b=Ba7VxduyYcaIzM0GAX5qWrUWAdb3xPKyxw9U54KftUdCsk8B1x2NJOMitCKyziTaiO DkDr+Ep8ZnOM6cKcNRe2yNrJIXBLV1Dm5RejhA8E1endXxsUT7TNEuF8IskKTvuKnyTY JOe4n7v686Q33PqzVrlFwoRsx1AHhKlqhHhBM2GlQ9Jyb+xVe1zGsMP83j6+FeM6Owy2 5s7H5PRRbl87Cnc/UMIU1bBf7RTXS0QMFvi0kA2hweQ62RxQimrMyuR8ceR9A7Zx/ljH 88sKGEqnq5FItTWcwZeHE3Rne8df0IQSuSQS4Pgma+yxhzllxQ4jk0pTXgsAPGoHQqGC xX/w== 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=r/DJ06AQj7j8kFaAT82/9WOuSylUEZa/XluKSMLVR2c=; fh=12pro/Y/lDXTnCiR/HP+/xH9APUzuQXz1oRgHp1swnE=; b=ZNwfmpOH0QmCAw9q+gfw8msnYUdNKhUWAU3dKSuWQNUpp8c3e7ljhkaPgTsRqhLw07 3FegdZlxZiFM6u1xjeehMS4kG3BswJrCRpXpeYUWX72xTaTerLXHL0ie5W48xIbZSK4V M2TtaVnVemZ0u4ggMMhLguDNOJ7hEGcRkQtPuzF8CjZxBBR9hHRRHbEwsMZKfoL2dXxZ qLck877XazqDqT5EnWvGhvSA5GuEDn7h2vSi/n27S2/kNmICOZYqXUUL+ziL3uAG8uUB bBsvfsW7j8rRLOHenBxezliXdZ/752Ev2wr7odXZUHwgdIY5F3FmMlxPNuGLWHH0S5Rq p1AA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CZbUipyX; 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-92715-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92715-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id i4-20020a63e444000000b005dc4202b402si10345283pgk.173.2024.03.05.09.15.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 09:15:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-92715-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=@bootlin.com header.s=gm1 header.b=CZbUipyX; 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-92715-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92715-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 96734B23A59 for ; Tue, 5 Mar 2024 16:53:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06312DDC4; Tue, 5 Mar 2024 16:53:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="CZbUipyX" 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 8EE70134A0; Tue, 5 Mar 2024 16:52:58 +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=1709657582; cv=none; b=nX/pRd0YFW+c9x/yrsaYGOBR4QrMinGPGo3wmDrNbz86xWfFHr19IKc/NrGYrwa36AuBFbvFe5O/F+lM9BlDV1HT/sKGxjpVhFnd1j7YUYo8yvTIzlRjbXTfqPKZtzQ/8+G38PYorYh6OZvQnc4oEvRldy+SugY4rGZ7oYyHN3s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709657582; c=relaxed/simple; bh=wtYtDVJZiqM1pogoWHG3mgthzJAbRFC3EtRyyF4qw5w=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kIXBHLtGwe1MrU17NfbLPYAnyZFyco9rN8njlaI7S97uUu46mGwHFGsMLPzHT1MijVXe/5KsW3mZ6tSAZ6pAZ5nhwy0bc3hVxPB7leIK0yw838wj9p3tgbmTQVfSub3HhAt+6Ft6x/QmvwwkLlIN3Z2hCY+3foP20v2hyZOrGP0= 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=CZbUipyX; 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 98E236000F; Tue, 5 Mar 2024 16:52:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1709657576; 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=r/DJ06AQj7j8kFaAT82/9WOuSylUEZa/XluKSMLVR2c=; b=CZbUipyXh0uIDFs7UIuHYQbXhuzXMGFrVmVOGNvAhHvPowzAFnNVPDo2G/WiPUra5Kgq0s nztEcaah9if87869LbLxZjfBOoc/e9AacgFZ5R3KbDRf2/uRkTrszDuq7Pc/SCVHJY91qd 0n7stiMeN+EqUFlWfmwXcV+p1ZcqcH49S3SyerF8mgpHzyT0H53xLK2/CDc97S3VsnFkVF 8CgFoaUyaUL8vVMw1/BchY9/KmgNwAGxqCUpGMjhKTkrvRjxZiQIMUVmc5fyekQ+tDeo9N Kw1PXxCRBwrLfsb+MlxSCquvAMBv0NTv+drYyOmrEi5kK8fsL2ihc9QkXM1toQ== Date: Tue, 5 Mar 2024 17:52:53 +0100 From: =?UTF-8?B?S8O2cnk=?= Maincent To: Jakub Kicinski Cc: Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Paolo Abeni , Richard Cochran , Radu Pirea , Jay Vosburgh , Andy Gospodarek , Nicolas Ferre , Claudiu Beznea , Willem de Bruijn , Jonathan Corbet , Horatiu Vultur , UNGLinuxDriver@microchip.com, Simon Horman , Vladimir Oltean , Thomas Petazzoni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Maxime Chevallier , Rahul Rameshbabu Subject: Re: [PATCH net-next v9 12/13] net: ethtool: tsinfo: Add support for hwtstamp provider and get/set hwtstamp config Message-ID: <20240305175253.764f041a@kmaincent-XPS-13-7390> In-Reply-To: <20240304192733.1e8e08cc@kernel.org> References: <20240226-feature_ptp_netnext-v9-0-455611549f21@bootlin.com> <20240226-feature_ptp_netnext-v9-12-455611549f21@bootlin.com> <20240304192733.1e8e08cc@kernel.org> Organization: bootlin X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-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: quoted-printable X-GND-Sasl: kory.maincent@bootlin.com On Mon, 4 Mar 2024 19:27:33 -0800 Jakub Kicinski wrote: > On Mon, 26 Feb 2024 14:40:03 +0100 Kory Maincent wrote: > > diff --git a/net/ethtool/common.c b/net/ethtool/common.c > > index b3f45c307301..37071929128a 100644 > > --- a/net/ethtool/common.c > > +++ b/net/ethtool/common.c > > @@ -426,6 +426,7 @@ const char sof_timestamping_names[][ETH_GSTRING_LEN= ] =3D { > > [const_ilog2(SOF_TIMESTAMPING_OPT_TX_SWHW)] =3D "option-tx-swhw", > > [const_ilog2(SOF_TIMESTAMPING_BIND_PHC)] =3D "bind-phc", > > [const_ilog2(SOF_TIMESTAMPING_OPT_ID_TCP)] =3D "option-id-tcp", > > + [const_ilog2(SOF_TIMESTAMPING_GHWTSTAMP)] =3D "get-hwtstamp", =20 >=20 > What is this new SOF_TIMESTAMPING_GHWTSTAMP? If there's=20 > a good reason for it to exist it should be documented in > Documentation/networking/timestamping.rst /o\ Sorry I totally forgot about documentation here! > > +const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_MAX += 1] > > =3D { [ETHTOOL_A_TSINFO_HEADER] =3D > > NLA_POLICY_NESTED(ethnl_header_policy), > > + [ETHTOOL_A_TSINFO_TIMESTAMPING] =3D { .type =3D NLA_NESTED }, > > + [ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER_NEST] =3D { .type =3D NLA_NESTED > > }, =20 >=20 > link the policy by NLA_POLICY_NESTED() so that user space can inspect > the sub-layers via the control family. Ok thanks! > > + > > + if (!hwtst_tb[ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER_INDEX] || > > + !hwtst_tb[ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER_QUALIFIER]) > > + return -EINVAL; =20 >=20 > NL_REQ_ATTR_CHECK() ok. >=20 > > + ret =3D > > nla_get_u32(hwtst_tb[ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER_INDEX]); > > + if (ret < 0) > > + return -EINVAL; =20 >=20 > How's the get_u32 going to return a negative value? > That's the purpose of this check? > The policy should contain the max expected value - NLA_POLICY_MAX(). Right I will use more NLA_POLICY_* to check the values in next version. > > return ret; > > - ret =3D __ethtool_get_ts_info(dev, &data->ts_info); > > + > > + if (!netif_device_present(dev)) { =20 >=20 > ethnl_ops_begin() checks for presence Ok thanks! >=20 > > + if (req->hwtst.index !=3D -1) { > > + struct hwtstamp_provider hwtstamp; > > + > > + hwtstamp.ptp =3D ptp_clock_get_by_index(req->hwtst.index); > > + if (!hwtstamp.ptp) { > > + ret =3D -ENODEV; > > + goto out; > > + } > > + hwtstamp.qualifier =3D req->hwtst.qualifier; > > + > > + ret =3D ethtool_get_ts_info_by_phc(dev, &data->ts_info, > > + &hwtstamp); > > + } else { > > + ret =3D __ethtool_get_ts_info(dev, &data->ts_info); =20 >=20 > Not sure I grok why we need 3 forms of getting the tstamp config. >=20 > Please make sure to always update > Documentation/networking/ethtool-netlink.rst > when extending ethtool-nl. Yes sorry I forgot! The three cases are: - get hwtstamp config like ioctl SIOCGHWTSTAMP - get tsinfo of the current hwtstamp - get tsinfo of a specific hwtstamp > > + if (ts_info->phc_index >=3D 0) { > > + /* _TSINFO_HWTSTAMP_PROVIDER_NEST */ > > + len +=3D nla_total_size(sizeof(u32) * 2); =20 >=20 > That translates to two raw u32s into a single attribute. > Is that what you mean? Oh right that's not what I want. Thanks you! This is better: len +=3D 2 * nla_total_size(sizeof(u32)); > > + if (ts_info->phc_index >=3D 0) { > > + ret =3D nla_put_u32(skb, ETHTOOL_A_TSINFO_PHC_INDEX, > > + ts_info->phc_index); > > + if (ret) > > + return -EMSGSIZE; > > + > > + nest =3D nla_nest_start(skb, > > ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER_NEST); > > + if (!nest) > > + return -EMSGSIZE; > > + > > + ret =3D nla_put_u32(skb, > > + ETHTOOL_A_TSINFO_HWTSTAMP_PROVIDER_INDEX, > > + ts_info->phc_index); =20 >=20 > You can assume nla_put_u32 only returns EMSGSIZE, so doing: >=20 > if (nla_put_u32(....) || > nla_put_u32(....)) > return -EMSGSIZE; >=20 > is generally considered to be fine. Ok. > > + > > + /* Does the hwtstamp supported in the netdev topology */ > > + if (mod) { > > + hwtstamp.ptp =3D ptp_clock_get_by_index(phc_index); =20 >=20 > This just returns a pointer without any refcounting, right? > What guarantees the ptp object doesn't disappear? Could the ptp object disappears within rtnlock? Maybe I should add refcounting. Regards, --=20 K=C3=B6ry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com