Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp921666ybx; Wed, 30 Oct 2019 07:16:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPh6d++5CcKfXrinfVC1DgiEtuQOtl+NfVNdN7GFCHXPlwlERE8a+I8TVUqFhS98ej1ixA X-Received: by 2002:a50:f096:: with SMTP id v22mr32852723edl.149.1572444961227; Wed, 30 Oct 2019 07:16:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572444961; cv=none; d=google.com; s=arc-20160816; b=PR68I+ibrhfgoZbBeJ9uPxh8+ekbesMEH9AihjFI+etPk+cmKIRfke5J8aB7972U+y IJqi7JkHV0/360mZiO8ZqY5bBL3/67V3ZbdVnsj8WAYPZP3+pjqFfyeFmDpFuJk7Lf7r GTfD+uiTVyJy8fXgFGxdohWCvIXCooUNbRr+x3kDCJ0A2bUNOzC9GQm7NNsSRQSRiZAT mChX53gjRpw5wDxzmNb/TuAQ+WqVmaf6rcFpsBg4txm3p8UJ7S6j/O77K+OG/55GKmzF Ct6+mRpxu8PGbC+fsLHSHpWpP1JXZFE4EJ5/fQZdOlPsaX2S7Hxumme3uyVwnYdv8QYV EkdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=oJoSGttXIiejPtPuPJkRV6ZmkthQr1YxBAjlCEwv66w=; b=Pw8WSpR1jMCqkUUeQU9RkjFFUjM2tnnTaUKzRSvQ3vOI1vQ72fOTYq8fVeI6Xsy0BK rEw2nAChbjgZBiO/9qJggf3Hd9Uvzw/HrrYIe1TdXLIm1mHEApIK0t7xNZZVpy0woyT0 YsxnJZDXYvhLrQgt5f+uzEhN39LnDdM3v1D+Ayt+KeucW9QEEFYmN6dBw9f4GQ10ieiL GP2TWTUuCaRxuC5g8Un9wPEipygq1L9IDulrHIcBmOGdWV23/JnNhIaC3YGmTJqc6dLs PPGH3UIAjZCWGgBQr0qbNPA+bgMEiotkbJysSNtSlEVgEQycqFmq+xUWbbQavz9hOqIF aFDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si1655378edb.226.2019.10.30.07.15.37; Wed, 30 Oct 2019 07:16:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726530AbfJ3ONA (ORCPT + 99 others); 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.