Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C22D5C43381 for ; Mon, 25 Feb 2019 07:36:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 816332084D for ; Mon, 25 Feb 2019 07:36:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DoVVLSST" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726478AbfBYHgE (ORCPT ); Mon, 25 Feb 2019 02:36:04 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44439 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726341AbfBYHgE (ORCPT ); Mon, 25 Feb 2019 02:36:04 -0500 Received: by mail-wr1-f65.google.com with SMTP id w2so8638863wrt.11 for ; Sun, 24 Feb 2019 23:36:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=D6pz3XW4mKWh5ZviPZgB0io1Es1KMSA2GikCxtsCdfQ=; b=DoVVLSSTi6CwoiRr+7N0PKMrDagFBeUcHGgbQbXVEnmxR2DS74d0pDNHwZmwfawlvN UOG6siWQ7pWClcyiIOkkRrMb3lWSMedUhkMgbh2nNZKRV9Q0S401yw/dSjAlXUGJiX3r P/pyTy+oWVsoS+4AMy0Xroe4AGN2uhqkTXeD0KRl4N4Nr8sGpDI16xpjLKIZEPteWnS5 Y47Uqti+8ZNbfAo+4urgE34OHh2Yw5ERqImY7hZ2bQPbtZFFUuTzzK3pLfQBIBlwXq66 JNWyvlwcv5DN+GaagsihWVvFIaHxTpcI0AHPgLOT34CTmt865SBmAA340lpBx+HQmb5C UE/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=D6pz3XW4mKWh5ZviPZgB0io1Es1KMSA2GikCxtsCdfQ=; b=ssJ1L98LQcLNvxKKO2S0fnnStRJUrDwrGzmhT/Ue7IkeYm7byKXy8P7cuIVyG8jv31 8fraw5HnqKiplmsqCxv2KNdQUxd9y6btOegxxgMgGVo1YvsSKlKGzYKokD1it7s8SZZ2 qucdWE8RRd7bHPjilcW7zIqWWzNPM6dmYs//UcxaeLjNJWiuxHkM5Q5V4UsDbD35GldU 2JMnIR8XNnV1XpEi2rC3CxFKGsk14rhSIPR99kqlYSzyJb+rNn9CfRpEtwUT+fXWE+k2 OzlKbVOz/P9SUI9aiXxn55HW6oEy7xgpWzEHx+qlEvgCVgflL1bqiOx4X8oPyRhQJfez szwA== X-Gm-Message-State: AHQUAuYFkjYLCwrn3zyg848vt71/LYHsaq8vJqKdtCwLNt4A658LmdO+ C7Ch48kj19N9GLIbp9Zyn68L53pf X-Google-Smtp-Source: AHgI3IZkIndijBsyACizlFCcm4F/7y6l29I1DhaycPdL4ew0x9E7TupGts0FIJXpy+M/aB3rQ6/kYg== X-Received: by 2002:a5d:6207:: with SMTP id y7mr11104809wru.60.1551080161314; Sun, 24 Feb 2019 23:36:01 -0800 (PST) Received: from ?IPv6:2003:ea:8bf1:e200:79a5:45c6:660b:4aff? (p200300EA8BF1E20079A545C6660B4AFF.dip0.t-ipconnect.de. [2003:ea:8bf1:e200:79a5:45c6:660b:4aff]) by smtp.googlemail.com with ESMTPSA id b197sm18514380wmd.23.2019.02.24.23.36.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Feb 2019 23:36:00 -0800 (PST) Subject: Re: [PATCH net-next v2 2/2] net: phy: aquantia: add hwmon support To: Florian Fainelli , Andrew Lunn , David Miller Cc: "netdev@vger.kernel.org" References: <2b46ac62-db6f-b72c-e81b-c6fbf063ab4b@gmail.com> <5e9c1d9f-4c9f-10fd-439e-26f7f2cc467e@gmail.com> From: Heiner Kallweit Message-ID: <0350413e-be0e-39ac-411f-f4fa9470855b@gmail.com> Date: Mon, 25 Feb 2019 08:34:35 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <5e9c1d9f-4c9f-10fd-439e-26f7f2cc467e@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 25.02.2019 03:17, Florian Fainelli wrote: > Le 2/24/19 à 1:36 PM, Heiner Kallweit a écrit : >> This adds HWMON support for the temperature sensor and the related >> alarms on the 107/108/109 chips. This patch is based on work from >> Nikita and Andrew. I added: >> - support for changing alarm thresholds via sysfs >> - move HWMON code to a separate source file to improve maintainability >> - smaller changes like using IS_REACHABLE instead of ifdef >> (avoids problems if PHY driver is built in and HWMON is a module) >> >> v2: >> - remove struct aqr_priv >> - rename header file to aquantia.h >> >> Signed-off-by: Nikita Yushchenko > > Should not Nikita be the author for that patch? Some minor nits below: > >> Signed-off-by: Andrew Lunn >> Signed-off-by: Heiner Kallweit >> --- >> drivers/net/phy/Makefile | 2 +- >> drivers/net/phy/aquantia.h | 16 ++ >> drivers/net/phy/aquantia_hwmon.c | 245 +++++++++++++++++++++++++++++++ >> drivers/net/phy/aquantia_main.c | 4 + >> 4 files changed, 266 insertions(+), 1 deletion(-) >> create mode 100644 drivers/net/phy/aquantia.h >> create mode 100644 drivers/net/phy/aquantia_hwmon.c >> >> diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile >> index b0845adaf..c48596626 100644 >> --- a/drivers/net/phy/Makefile >> +++ b/drivers/net/phy/Makefile >> @@ -45,7 +45,7 @@ sfp-obj-$(CONFIG_SFP) += sfp-bus.o >> obj-y += $(sfp-obj-y) $(sfp-obj-m) >> >> obj-$(CONFIG_AMD_PHY) += amd.o >> -aquantia-objs += aquantia_main.o >> +aquantia-objs += aquantia_main.o aquantia_hwmon.o > > Since you are adding a stub if CONFIG_HWMON is not reachable, does not > that mean you would want to do something like: > > ifdef CONFIG_HWMON > aquanti-objs += aquantia_hwmon.o > endif > > in this makefile? > Yepp, this should be changed as suggested by you. > [snip] > >> +static int aqr_hwmon_get(struct phy_device *phydev, int reg, long *value) >> +{ >> + int temp = phy_read_mmd(phydev, MDIO_MMD_VEND1, reg); >> + >> + if (temp < 0) >> + return temp; >> + >> + /* register value is 2's complement with LSB = 1/256th degree Celsius */ >> + if (temp > 0x8000) >> + temp -= 0x10000; > > Would decimal or BIT() notation be easier to use/read here? > For the comparison I agree, we can write it as: if (temp & BIT(15)) And yes, the offset we could write decimal. An alternative could be to write: temp = (s16)temp; I tested it and it works, but I'm not sure whether this is covered by C standard and works with all supported compilers. >> + >> + *value = temp * 1000 / 256; >> + >> + return 0; >> +} >> + >> +static int aqr_hwmon_set(struct phy_device *phydev, int reg, long value) >> +{ >> + int temp; >> + >> + if (value >= 128000 || value < -128000) >> + return -ERANGE; >> + >> + temp = value * 256 / 1000; >> + >> + if (temp < 0) >> + temp += 0x10000; > > Likewise > >> + >> + return phy_write_mmd(phydev, MDIO_MMD_VEND1, reg, temp); >> +} >> + >> +static int aqr_hwmon_status1(struct phy_device *phydev, int bit, long *value) >> +{ >> + int reg = phy_read_mmd(phydev, MDIO_MMD_VEND1, VEND1_GENERAL_STAT1); >> + >> + if (reg < 0) >> + return reg; >> + >> + *value = !!(reg & bit); >> + >> + return 0; >> +} > > Can you also make this function take a register offset as parameter such > that you can eliminate open coding that in the case hwmon_temp_input below? > OK >> + >> +static int aqr_hwmon_read(struct device *dev, enum hwmon_sensor_types type, >> + u32 attr, int channel, long *value) >> +{ >> + struct phy_device *phydev = dev_get_drvdata(dev); >> + int reg; >> + >> + if (type != hwmon_temp) >> + return -EOPNOTSUPP; >> + >> + switch (attr) { >> + case hwmon_temp_input: >> + reg = phy_read_mmd(phydev, MDIO_MMD_VEND1, >> + VEND1_THERMAL_STAT2); >> + if (reg < 0) >> + return reg; >> + if (!(reg & VEND1_THERMAL_STAT2_VALID)) >> + return -EIO; > > And use that helper here. > >> + >> + return aqr_hwmon_get(phydev, VEND1_THERMAL_STAT1, value); >> + > > [snip] > >> + hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL); >> + if (!hwmon_name) >> + return -ENOMEM; >> + >> + for (i = j = 0; hwmon_name[i]; i++) { >> + if (isalnum(hwmon_name[i])) { >> + if (i != j) >> + hwmon_name[j] = hwmon_name[i]; >> + j++; >> + } >> + } >> + hwmon_name[j] = '\0'; > > I am always baffled that drivers need to take care of these details... > but that seems to be the way to go. > IIRC we still have a similar construction site in phylib. If a PHY driver name includes e.g. a slash then sysfs is broken. There should be a general helper e.g. in lib/string.c, because we have this across subsystems wherever a device name is used in a sysfs path.