From mboxrd@z Thu Jan 1 00:00:00 1970 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=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 3DE46CA9EC7 for ; Wed, 30 Oct 2019 14:13:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0F9D120856 for ; Wed, 30 Oct 2019 14:13:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726554AbfJ3ONA (ORCPT ); Wed, 30 Oct 2019 10:13:00 -0400 Received: from verein.lst.de ([213.95.11.211]:45754 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726284AbfJ3OM7 (ORCPT ); Wed, 30 Oct 2019 10:12:59 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 35A1568B05; Wed, 30 Oct 2019 15:12:56 +0100 (CET) Date: Wed, 30 Oct 2019 15:12:56 +0100 From: Christoph Hellwig To: Guenter Roeck Cc: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, Akinobu Mita , linux-pm@vger.kernel.org, Chris Healy Subject: Re: [PATCH v2] nvme: Add hardware monitoring support Message-ID: <20191030141256.GB14252@lst.de> References: <20191029223214.18889-1-linux@roeck-us.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191029223214.18889-1-linux@roeck-us.net> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 29, 2019 at 03:32:14PM -0700, Guenter Roeck wrote: > This patch adds support to read NVME temperatures from the kernel using the > hwmon API and adds temperature zones for NVME drives. The thermal subsystem > can use this information to set thermal policies, and userspace can access > it using libsensors and/or the "sensors" command. Except in all upper case or all lower case identifier the speling should always be "NVMe". Thi also happens a few more places like in the Kconfig text. > +static int nvme_hwmon_get_smart_log(struct nvme_hwmon_data *data) > +{ > + return nvme_get_log(data->ctrl, NVME_NSID_ALL, NVME_LOG_SMART, 0, > + &data->log, sizeof(data->log), 0); > +} > + > +static int nvme_hwmon_read(struct device *dev, enum hwmon_sensor_types type, > + u32 attr, int channel, long *val) > +{ > + struct nvme_hwmon_data *data = dev_get_drvdata(dev); > + struct nvme_smart_log *log = &data->log; > + int err; > + int temp; > + > + err = nvme_hwmon_get_smart_log(data); > + if (err) > + return err < 0 ? err : -EPROTO; I think the handling of positive errnos fits better into nvme_hwmon_get_smart_log. Also EIO sounds like a better error for generic NVMe level errors. > + > + switch (attr) { > + case hwmon_temp_max: > + *val = (data->ctrl->wctemp - 273) * 1000; > + break; > + case hwmon_temp_crit: > + *val = (data->ctrl->cctemp - 273) * 1000; > + break; > + case hwmon_temp_input: > + if (!channel) > + temp = le16_to_cpup((__le16 *)log->temperature); This needs to use get_unaligned_le16, otherwise you'll run into problems on architectures that don't support unaligned loads. > +static const struct hwmon_ops nvme_hwmon_ops = { > + .is_visible = nvme_hwmon_is_visible, > + .read = nvme_hwmon_read, > + .read_string = nvme_hwmon_read_string, > +}; > + > +static const struct hwmon_chip_info nvme_hwmon_chip_info = { > + .ops = &nvme_hwmon_ops, > + .info = nvme_hwmon_info, > +}; Please use tabs to align all the = in an ops structure. > +#if IS_ENABLED(CONFIG_NVME_HWMON) No real need to use IS_ENABLED here, a plain ifdef should do it.