From patchwork Wed Oct 4 09:05:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kubalewski, Arkadiusz" X-Patchwork-Id: 13408482 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 E8E301094A for ; Wed, 4 Oct 2023 09:08:48 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51044C9; Wed, 4 Oct 2023 02:08:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696410527; x=1727946527; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=T7B4f7810U0FdBKSEAXDN5xAeXxcWlTekOw+2N8jEHU=; b=knu1Gli8qjvqpdiojM9/ON6loiEt4cLxZJz709nSEPc4C9pE9XIZ+pD/ wd/VRIS+MqkHaS3q55gmhtBRtCrAYm5qg4+WKEQuPQJ+JpLVYmAjVqXk+ syZ4/lcRoaHW89imW7UbZpg9T2/1FxG7PSJrFGj40ESk42Bq//VGFviSx uo69gUl4Txq7+vEAOYIWZnLz5VC3CWl91jrx7vb3fCphXjZfLaGlLV1Or zhqXaUoaCECS5lqh59axL/s6dE9Km26BFnvGOpG7WPagFcqDa5vQxklNu 2wCymzPUIHFUTlG+evrC0H5iXCkTQ1hLcguN+qMNcSrCqdx2nlsEfbEMo A==; X-IronPort-AV: E=McAfee;i="6600,9927,10852"; a="373448545" X-IronPort-AV: E=Sophos;i="6.03,199,1694761200"; d="scan'208";a="373448545" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2023 02:08:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10852"; a="780668482" X-IronPort-AV: E=Sophos;i="6.03,199,1694761200"; d="scan'208";a="780668482" Received: from amlin-018-114.igk.intel.com ([10.102.18.114]) by orsmga008.jf.intel.com with ESMTP; 04 Oct 2023 02:08:44 -0700 From: Arkadiusz Kubalewski To: netdev@vger.kernel.org Cc: vadim.fedorenko@linux.dev, jiri@resnulli.us, corbet@lwn.net, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com, linux-doc@vger.kernel.org, intel-wired-lan@lists.osuosl.org, Arkadiusz Kubalewski Subject: [PATCH net-next v2 5/5] dpll: netlink/core: change pin frequency set behavior Date: Wed, 4 Oct 2023 11:05:47 +0200 Message-Id: <20231004090547.1597844-6-arkadiusz.kubalewski@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20231004090547.1597844-1-arkadiusz.kubalewski@intel.com> References: <20231004090547.1597844-1-arkadiusz.kubalewski@intel.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Align the aproach of pin frequency set behavior with the approach introduced with pin phase adjust set. Fail the request if any of devices did not registered the callback ops. If callback op on any pin's registered device fails, return error and rollback the value to previous one. Signed-off-by: Arkadiusz Kubalewski --- drivers/dpll/dpll_netlink.c | 50 +++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/drivers/dpll/dpll_netlink.c b/drivers/dpll/dpll_netlink.c index 97319a9e4667..8e5fea74aec1 100644 --- a/drivers/dpll/dpll_netlink.c +++ b/drivers/dpll/dpll_netlink.c @@ -615,30 +615,60 @@ static int dpll_pin_freq_set(struct dpll_pin *pin, struct nlattr *a, struct netlink_ext_ack *extack) { - u64 freq = nla_get_u64(a); - struct dpll_pin_ref *ref; + u64 freq = nla_get_u64(a), old_freq; + struct dpll_pin_ref *ref, *failed; + const struct dpll_pin_ops *ops; + struct dpll_device *dpll; unsigned long i; int ret; if (!dpll_pin_is_freq_supported(pin, freq)) { - NL_SET_ERR_MSG_ATTR(extack, a, "frequency is not supported by the device"); + NL_SET_ERR_MSG_ATTR(extack, a, + "frequency is not supported by the device"); return -EINVAL; } - xa_for_each(&pin->dpll_refs, i, ref) { - const struct dpll_pin_ops *ops = dpll_pin_ops(ref); - struct dpll_device *dpll = ref->dpll; - - if (!ops->frequency_set) + ops = dpll_pin_ops(ref); + if (!ops->frequency_set || !ops->frequency_get) return -EOPNOTSUPP; + } + ref = dpll_xa_ref_dpll_first(&pin->dpll_refs); + ops = dpll_pin_ops(ref); + dpll = ref->dpll; + ret = ops->frequency_get(pin, dpll_pin_on_dpll_priv(dpll, pin), dpll, + dpll_priv(dpll), &old_freq, extack); + if (ret) { + NL_SET_ERR_MSG(extack, "unable to get old frequency value"); + return ret; + } + if (freq == old_freq) + return 0; + + xa_for_each(&pin->dpll_refs, i, ref) { + ops = dpll_pin_ops(ref); + dpll = ref->dpll; ret = ops->frequency_set(pin, dpll_pin_on_dpll_priv(dpll, pin), dpll, dpll_priv(dpll), freq, extack); - if (ret) - return ret; + if (ret) { + failed = ref; + goto rollback; + } } __dpll_pin_change_ntf(pin); return 0; + +rollback: + xa_for_each(&pin->dpll_refs, i, ref) { + if (ref == failed) + break; + ops = dpll_pin_ops(ref); + dpll = ref->dpll; + if (ops->frequency_set(pin, dpll_pin_on_dpll_priv(dpll, pin), + dpll, dpll_priv(dpll), old_freq, extack)) + NL_SET_ERR_MSG(extack, "set frequency rollback failed"); + } + return ret; } static int