Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1208434ybv; Sun, 23 Feb 2020 01:36:43 -0800 (PST) X-Google-Smtp-Source: APXvYqx8ptjMhk+uQa5/r1SXPpDh+4Obg+IvHPM2AqZ3yZYzlsagLoszuZaHkUE1z/M6EiXaDpWQ X-Received: by 2002:aca:ea46:: with SMTP id i67mr8461232oih.149.1582450603454; Sun, 23 Feb 2020 01:36:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582450603; cv=none; d=google.com; s=arc-20160816; b=TFnLgrhvOEHeJd+vgRWN6UEJc3Unb4izcWHgzYXABp5cxZFzCaxnpCOUs7GmWJTddJ FkPf1TVGXLaL9i1X3zosUY4D0hgF2rV53JbtVm81bxUYIlQnltfc1vazIUsQTHRTN2uK Xsgf6EbqOhNHRowThWmVx9QFJNXnG6RWnS0sOYzktEj1PAo8q0RResbPQb5IedC1tUkw oNeS1C1kvgW61y/pd7I/w01QHNazv4xaOlzpAy+ulwGapuCcBCHeFn7/Md27CyD/JK2G zOP8GwvD7WpN6hOJCwuZCRbSWODtmHUzIHhQGf3J589JslkDKnNpqUqo0YHw1Kqb1R3z AdrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:wdcironportexception:ironport-sdr:ironport-sdr :ironport-sdr:dkim-signature; bh=hmPBtfw72HkL37uSu+tyJnBs/ufofyiAsFRdQjMzuqc=; b=sL1fRPrEfoF8sY3lOLivGVDBVnoUnFQxYop59JiBRvBHJHzvG4BW8hZbRnDmjsf6T5 8HrnkWgMaTfByZjw1W+LNJ5P2WBv3LS7risFW9U13YVDMhFXDSh2n8CAUH57LpJUiCsA 9QW1tQiZkkEYlYczY1rwngvdYCxYZaMP0xXs2eI7QqtaNBwYYo+6R2JUhRegQeWBzAl9 ogoK83EbS98+l6lyoqXZd7WuYweueVE5g2IYUEq7G7YpjTB6aROBN1CwSiwfW61Y39TL xMEModd8W2TRccS+cfLrRBXmslKQ5CfZ2KBR7esAklK+sNN/nnxeCIdLsd3lPhDqi8lU 3Saw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=AGmxGv3H; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l23si4099677otj.302.2020.02.23.01.36.31; Sun, 23 Feb 2020 01:36:43 -0800 (PST) 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; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=AGmxGv3H; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727287AbgBWJf7 (ORCPT + 99 others); Sun, 23 Feb 2020 04:35:59 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:33764 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727226AbgBWJf6 (ORCPT ); Sun, 23 Feb 2020 04:35:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582450558; x=1613986558; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=MCaxS1cxBQjYWUX34ixMu6TpXxrzDXEmdNY7B98w0eE=; b=AGmxGv3Hgw0i9p3Qy1FQCPSpv7a5nCBakLGBn9sEazBpCu/q7VMyJP0a g8Lkv613GgC4obAASBaGxrkiDyKdgi9bRNCPP1OE7Liy7Q6CDAeTP59au TQ53rtv7bzfgU7Y+YOBBBer+bA0fLHYybtBj0KdNn5kjryrdDeLQs+S2n 4lgd+BWofSfsK5kpDv0Gi/o7Rc9t+wxEDOw5xwQ8vR66CRpgZeDaFLQd+ u3DvbCuwW7+XPxeiSYze18p3Ymo/ceEl/kqCRTu4GYBC+46h+Joazw2wa uH3ooCIBQPsN28ShZo7RhxmKrZ954WaACvSe3gWUqe3+zSApr0JonMtj4 w==; IronPort-SDR: 2ZIYa/RwKdES51fZ3bTpll8bcVvOd2cnJktGHZKKkgQ+1Rm1UOExp/aXLostACEW8dHOhvq2s/ ZSejQ2+7qp7uVi/2phKZanj/y8EEck8q8CHAyV7EPcg3XAL32rKd+4h/TytUkAngm2BQGdK+/Y q3iHp8gQqE23JeJLuqvNDlA2lW05VrNItTQ0l6gNw7ci32iC70F0bZH9S16h53xGZ0tYQMUpS7 E1qZg98zUOwINENAJNLsnEdXiFOnZk1y/NGtczIOKPeIy9MFfij9xHarqiBy4MYMFtSpug9dc8 Dps= X-IronPort-AV: E=Sophos;i="5.70,475,1574092800"; d="scan'208";a="131020060" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 23 Feb 2020 17:35:46 +0800 IronPort-SDR: /LY3ZP6LgGZACLDplcjOvOdumFQAtjRTJppRcgtL0Bl00DIv9jXZj+IFKtaF1nsfl1ww/wU/ip dXIIqjHMvPN9QQ7hO5/8gxXuilOtA/psaliAyTY9OipR68N1AL0eEkYE4MDVaksqdY1PE9eI0l uw2FSaFUfeDT3H9X6PKoSO6UP+1zwS27xAQjWVfPszW5zrJTj8J8bDlrGgh3bvO5c7Trq226kf sL2/n9W4LlOLeY+klmWeMePo5KnQUSYFXBP9UHjDqAvB1mh2W29EXoP5B6uF3so4KuNDjl0ZzE onnhZ0wW541habbYbH7wBNu2 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Feb 2020 01:28:16 -0800 IronPort-SDR: X+2ZyEbsntDnnyVMIPWX1VW3o3s75m6gyAV2Mb4f5q43/YykjxfnV4/B8uFOq9I2zDply0PwqG b6hNqej8Q48D1o6Dk0Sn2iqRAkHdxzwfjsgssV/BzMoLF0C1f6n5WK2des2yE0JCxOmbNUbkMX HpEx92QAtbDOkyqYphz0LEhB/2r62KToSu1DF4DE+GHKDZgXrwY+RHLHkt+ugHNeo4SplUNbwY zmV5E+m0EHxsleG5WtheAqCKoACcfIh4BlIxdk1iew4H2mxDc6DXPHgoz60tz/TRjlVThGNS3p IQM= WDCIronportException: Internal Received: from kfae419068.sdcorp.global.sandisk.com ([10.0.231.195]) by uls-op-cesaip01.wdc.com with ESMTP; 23 Feb 2020 01:35:41 -0800 From: Avi Shchislowski To: Avri Altman , Guenter Roeck , Alim Akhtar , "James E.J. Bottomley" , "Martin K. Petersen" , Zhang Rui , Daniel Lezcano , linux-kernel@vger.kernel.org, avri.altman@wdc.com, avi.shchislowski@wdc.com Cc: Avi.shchislowski@wdc.com, Avi Shchislowski Subject: [RESEND PATCH 4/5] scsi: ufs-thermal: implement thermal file ops Date: Sun, 23 Feb 2020 11:35:21 +0200 Message-Id: <1582450522-13256-5-git-send-email-avi.shchislowski@wdc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1582450522-13256-1-git-send-email-avi.shchislowski@wdc.com> References: <1582450522-13256-1-git-send-email-avi.shchislowski@wdc.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Avi Shchislowski The thermal interface adds a new thermal zone device sensor under /sys/class/thermal/ folder. Signed-off-by: Avi Shchislowski --- drivers/scsi/ufs/ufs-thermal.c | 122 ++++++++++++++++++++++++++++++++++++++--- drivers/scsi/ufs/ufs.h | 3 + 2 files changed, 117 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/ufs/ufs-thermal.c b/drivers/scsi/ufs/ufs-thermal.c index dfa5d68..23e4ac1 100644 --- a/drivers/scsi/ufs/ufs-thermal.c +++ b/drivers/scsi/ufs/ufs-thermal.c @@ -31,6 +31,99 @@ enum { } }; +#define attr2milicelcius(attr) (((0xFF & attr) - 80) * 1000) + +static int ufs_thermal_get_temp(struct thermal_zone_device *device, + int *temperature) +{ + struct ufs_hba *hba = (struct ufs_hba *)device->devdata; + u32 temp; + int err; + + err = ufshcd_query_attr(hba, + UPIU_QUERY_OPCODE_READ_ATTR, + QUERY_ATTR_IDN_ROUGH_TEMP, + 0, 0, &temp); + if (err) + return -EINVAL; + + *temperature = attr2milicelcius(temp); + return 0; +} + +static int ufs_thermal_get_trip_temp( + struct thermal_zone_device *device, + int trip, int *temp) +{ + + if (trip < 0 || trip >= UFS_THERM_MAX_TRIPS) + return -EINVAL; + + *temp = thermal.trip[trip]; + + return 0; +} + +static int ufs_thermal_get_trip_type( + struct thermal_zone_device *device, + int trip, enum thermal_trip_type *type) +{ + if (trip < 0 || trip >= UFS_THERM_MAX_TRIPS) + return -EINVAL; + + *type = THERMAL_TRIP_PASSIVE; + + return 0; +} + +static int ufs_thermal_get_boundary(struct ufs_hba *hba, + int trip, int *boundary) +{ + enum attr_idn idn; + int err = 0; + u32 val; + + idn = trip == UFS_THERM_HIGH_TEMP ? + QUERY_ATTR_IDN_TOO_HIGH_TEMP : + QUERY_ATTR_IDN_TOO_LOW_TEMP; + + err = ufshcd_query_attr(hba, + UPIU_QUERY_OPCODE_READ_ATTR, + idn, 0, 0, &val); + if (err) { + dev_err(hba->dev, + "Failed to get device too %s temperature boundary\n", + trip == UFS_THERM_HIGH_TEMP ? "high" : "low"); + goto out; + } + + if (val < 1 || val > 250) { + dev_err(hba->dev, "out of device temperature boundary\n"); + err = -EINVAL; + goto out; + } + + *boundary = attr2milicelcius(val); + +out: + return err; +} + +static int ufs_thermal_set_trip(struct ufs_hba *hba, int trip) +{ + int temp; + int err = 0; + + err = ufs_thermal_get_boundary(hba, trip, &temp); + if (err) + return err; + + thermal.trip[trip] = temp; + + return err; + +} + void ufs_thermal_exception_event_handler(struct ufs_hba *hba, u32 exception_status) { @@ -46,17 +139,12 @@ void ufs_thermal_exception_event_handler(struct ufs_hba *hba, } } -static struct thermal_zone_device_ops ufs_thermal_ops = { - .get_temp = NULL, - .get_trip_temp = NULL, - .get_trip_type = NULL, -}; - static int ufs_thermal_enable_ee(struct ufs_hba *hba) { return ufshcd_enable_ee(hba, MASK_EE_URGENT_TEMP); } + static void ufs_thermal_zone_unregister(struct ufs_hba *hba) { if (thermal.zone) { @@ -66,7 +154,13 @@ static void ufs_thermal_zone_unregister(struct ufs_hba *hba) } } -static int ufs_thermal_register(struct ufs_hba *hba) +static struct thermal_zone_device_ops ufs_thermal_ops = { + .get_temp = ufs_thermal_get_temp, + .get_trip_temp = ufs_thermal_get_trip_temp, + .get_trip_type = ufs_thermal_get_trip_type, +}; + +static int ufs_thermal_register(struct ufs_hba *hba, u8 ufs_features) { int err = 0; char name[THERMAL_NAME_LENGTH] = {}; @@ -74,6 +168,18 @@ static int ufs_thermal_register(struct ufs_hba *hba) snprintf(name, THERMAL_NAME_LENGTH, "ufs_storage_%d", hba->host->host_no); + if (ufs_features & UFS_FEATURE_HTEMP) { + err = ufs_thermal_set_trip(hba, UFS_THERM_HIGH_TEMP); + if (err) + goto out; + } + + if (ufs_features & UFS_FEATURE_LTEMP) { + err = ufs_thermal_set_trip(hba, UFS_THERM_LOW_TEMP); + if (err) + goto out; + } + thermal.zone = thermal_zone_device_register(name, UFS_THERM_MAX_TRIPS, 0, hba, &ufs_thermal_ops, NULL, 0, 0); if (IS_ERR(thermal.zone)) { @@ -122,7 +228,7 @@ int ufs_thermal_probe(struct ufs_hba *hba) if (!ufs_features) goto out; - err = ufs_thermal_register(hba); + err = ufs_thermal_register(hba, ufs_features); if (err) goto out; diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index 8fc0b0c..9f8224b 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -167,6 +167,9 @@ enum attr_idn { QUERY_ATTR_IDN_FFU_STATUS = 0x14, QUERY_ATTR_IDN_PSA_STATE = 0x15, QUERY_ATTR_IDN_PSA_DATA_SIZE = 0x16, + QUERY_ATTR_IDN_ROUGH_TEMP = 0x18, + QUERY_ATTR_IDN_TOO_HIGH_TEMP = 0x19, + QUERY_ATTR_IDN_TOO_LOW_TEMP = 0x1A, }; /* Descriptor idn for Query requests */ -- 1.9.1