From patchwork Fri Oct 14 07:32:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 2557 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp54472wrs; Fri, 14 Oct 2022 00:58:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6qBGYlobl/lB9ScLRB+KqczJKWwl3VBPb+hP+sERGHIzxoy8wb6gBUxhO0YNWviuP7YExZ X-Received: by 2002:a17:907:2dab:b0:78d:fc4b:7e31 with SMTP id gt43-20020a1709072dab00b0078dfc4b7e31mr2513122ejc.531.1665734308068; Fri, 14 Oct 2022 00:58:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665734308; cv=none; d=google.com; s=arc-20160816; b=be8uZ8P1PUn6/EkmvSTEjoDIMSA2+RxtuyD6llxFrwGvvJRMsnjgWKrjQJq8BCk4Tu zxGcc3G6mjfexiVyC9LXKYB/nKhAeEQey+VnJ+/HrN91xv1GjbShXoPdfi1rTuvd/QiG 6dYafzz6jBrWhUtJXiGPncmxjgsGCMtSC4Orxic7wB9ux9t6KGK0Kj0oAAgxQMV1DSgE 1ocd6JVvdWUcK4ghhmDsoyhBViWbbeVTBKRjVzPl4aKUU8NI1Ow+UTFg/eeXKU9BF1A6 wELiz1WXLS6T28HsZ9tcFy/5XRULMJX2WB3C+4mfydVRCKSYwLdGSMUYjPQtbV6W9jFm k3JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=SKEmi6vccBwd4SuCcKc/2Tnsrh3azVvNbQckYv+e6ak=; b=iNanywu0kkYMS1BTVhv4kcDjEdVXB0skw8ZVD1XXJ0j+btpnaogANEEJlSZPDmKra1 GWFUwUh7Mc8JKqErTdKcUgsIZdoRMe19uqZkANyCFonuEQ+EoVjZRvLdbLqZiCQdWKv7 +g+LUP0lvi8R6ZMcrm43+RH8GIUD2Klru0QArgYuvsOp7Uz2VPEZek5XGPbqT8SyN7Xi 77bdKiE2u9vO77+x6oHmArxSAOgnSpUXwiMN6bxBHEU1Ud5VdGp4atbLbupnACoUctt7 wxqx37xdZriIVtt/7j8YKYAQkINUBqsLO+sItMyQuJ4X/VOhn1xlZrPOD5RECkJT9PHY hrbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gNx2C+pR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr42-20020a1709073faa00b0078de51e658esi2084710ejc.208.2022.10.14.00.58.03; Fri, 14 Oct 2022 00:58:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gNx2C+pR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229777AbiJNHdR (ORCPT + 99 others); Fri, 14 Oct 2022 03:33:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbiJNHdN (ORCPT ); Fri, 14 Oct 2022 03:33:13 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4032A1B76FB for ; Fri, 14 Oct 2022 00:33:12 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id a10so6209005wrm.12 for ; Fri, 14 Oct 2022 00:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SKEmi6vccBwd4SuCcKc/2Tnsrh3azVvNbQckYv+e6ak=; b=gNx2C+pR029dJrAMYsM/ISYcaMzSXUq1lw4AX6GAvR0rl8PXVM3vUZ283CFCrrzcpo ncW5tMv7rYUFtP525ZQYUFEh/mtcdqZ/T0guZr8y2hnTgHfaJvuIi9G3kbdiBmtDeX2q Eb3snzOIVOuFoiLa0GB0N6eJj0hYjh/VnSQtp3nuH4xuHXfduU7mknGehTL9WNI2Wbrt c3gQyocfEbOVsgseyD1o1uXHN/HAWozN1uYfgau0sQLhvwpdJO+wdrnTIbYh7leWx8P3 iG6IQRSx4queQONUNMipBhA7LjaKBTCe7wuJfosMY/+Yhkkq+xKmI7hMNG5hFmcvRUbP 5d3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SKEmi6vccBwd4SuCcKc/2Tnsrh3azVvNbQckYv+e6ak=; b=fcXv2c/SH+Ojz5jIHsTzUDmJD09Dh+Pg85X5b+ziijpCvPmq5Fackjn7aXJOE0+J3a 0wAIYSbwmoDe7dyBKgkDgCDKWq/nbqUE+1GhxRyyrFj4aIKma0ifDsUs7YXvhUQVNZfX E4m/icoAVBeW+tpp/N1ORxt6XPjEGmuuhBkv7zof34gwSpD/kJnp+y0JDHmnGfa1cN2M J56HcHDwQhX3BqVcoppxyX/Hl9vr+5i/IRAoXQtBL5OqaNFXGVVHaUQxQ5Q53oXS7wMH Gi+D6ekECGWD49d1Z1d9cJ98m2T5No17sW4xOIl6X21jZZ0pH+AwgJynPZ8KHjLOydlI D7Ig== X-Gm-Message-State: ACrzQf0zw6PPZ/nJdY3IB9tDIg7V8RHkC5rvKTGnjDb9twS67qbT407g taMbPkK/6k9+yh0EgmpegUOXYg== X-Received: by 2002:a5d:4887:0:b0:226:ed34:7bbd with SMTP id g7-20020a5d4887000000b00226ed347bbdmr2218132wrq.561.1665732790764; Fri, 14 Oct 2022 00:33:10 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:b460:17f0:186d:9d2e]) by smtp.gmail.com with ESMTPSA id w12-20020a05600c474c00b003a682354f63sm898148wmo.11.2022.10.14.00.33.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 00:33:10 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org, daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Gregory Greenman , Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Luca Coelho , Johannes Berg , Emmanuel Grumbach , Miri Korenblit , Nathan Errera , linux-wireless@vger.kernel.org (open list:INTEL WIRELESS WIFI LINK (iwlwifi)), netdev@vger.kernel.org (open list:NETWORKING DRIVERS) Subject: [PATCH 1/2] thermal/drivers/iwlwifi: Use generic thermal_zone_get_trip() function Date: Fri, 14 Oct 2022 09:32:50 +0200 Message-Id: <20221014073253.3719911-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746649017674973148?= X-GMAIL-MSGID: =?utf-8?q?1746649017674973148?= The thermal framework gives the possibility to register the trip points with the thermal zone. When that is done, no get_trip_* ops are needed and they can be removed. The get_trip_temp, get_trip_hyst and get_trip_type are handled by the get_trip_point(). The set_trip_temp() generic function does some checks which are no longer needed in the set_trip_point() ops. Convert ops content logic into generic trip points and register them with the thermal zone. Signed-off-by: Daniel Lezcano Acked-by: Gregory Greenman Acked-by: Kalle Valo --- drivers/net/wireless/intel/iwlwifi/mvm/mvm.h | 2 +- drivers/net/wireless/intel/iwlwifi/mvm/tt.c | 71 ++++---------------- 2 files changed, 13 insertions(+), 60 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h index bf35e130c876..38e7426f98c0 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +++ b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h @@ -501,7 +501,7 @@ struct iwl_mvm_tt_mgmt { * @tzone: thermal zone device data */ struct iwl_mvm_thermal_device { - s16 temp_trips[IWL_MAX_DTS_TRIPS]; + struct thermal_trip trips[IWL_MAX_DTS_TRIPS]; u8 fw_trips_index[IWL_MAX_DTS_TRIPS]; struct thermal_zone_device *tzone; }; diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c index 69cf3a372759..3da4af7bc1ca 100644 --- a/drivers/net/wireless/intel/iwlwifi/mvm/tt.c +++ b/drivers/net/wireless/intel/iwlwifi/mvm/tt.c @@ -573,11 +573,11 @@ int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm) * and uncompressed, the FW should get it compressed and sorted */ - /* compress temp_trips to cmd array, remove uninitialized values*/ + /* compress trips to cmd array, remove uninitialized values*/ for (i = 0; i < IWL_MAX_DTS_TRIPS; i++) { - if (mvm->tz_device.temp_trips[i] != S16_MIN) { + if (mvm->tz_device.trips[i].temperature != INT_MIN) { cmd.thresholds[idx++] = - cpu_to_le16(mvm->tz_device.temp_trips[i]); + cpu_to_le16((s16)(mvm->tz_device.trips[i].temperature / 1000)); } } cmd.num_temps = cpu_to_le32(idx); @@ -593,8 +593,8 @@ int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm) */ for (i = 0; i < idx; i++) { for (j = 0; j < IWL_MAX_DTS_TRIPS; j++) { - if (le16_to_cpu(cmd.thresholds[i]) == - mvm->tz_device.temp_trips[j]) + if ((int)(le16_to_cpu(cmd.thresholds[i]) * 1000) == + mvm->tz_device.trips[j].temperature) mvm->tz_device.fw_trips_index[i] = j; } } @@ -638,37 +638,12 @@ static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device, return ret; } -static int iwl_mvm_tzone_get_trip_temp(struct thermal_zone_device *device, - int trip, int *temp) -{ - struct iwl_mvm *mvm = (struct iwl_mvm *)device->devdata; - - if (trip < 0 || trip >= IWL_MAX_DTS_TRIPS) - return -EINVAL; - - *temp = mvm->tz_device.temp_trips[trip] * 1000; - - return 0; -} - -static int iwl_mvm_tzone_get_trip_type(struct thermal_zone_device *device, - int trip, enum thermal_trip_type *type) -{ - if (trip < 0 || trip >= IWL_MAX_DTS_TRIPS) - return -EINVAL; - - *type = THERMAL_TRIP_PASSIVE; - - return 0; -} - static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device, int trip, int temp) { struct iwl_mvm *mvm = (struct iwl_mvm *)device->devdata; struct iwl_mvm_thermal_device *tzone; - int i, ret; - s16 temperature; + int ret; mutex_lock(&mvm->mutex); @@ -678,40 +653,17 @@ static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device, goto out; } - if (trip < 0 || trip >= IWL_MAX_DTS_TRIPS) { - ret = -EINVAL; - goto out; - } - if ((temp / 1000) > S16_MAX) { ret = -EINVAL; goto out; } - temperature = (s16)(temp / 1000); tzone = &mvm->tz_device; - if (!tzone) { ret = -EIO; goto out; } - /* no updates*/ - if (tzone->temp_trips[trip] == temperature) { - ret = 0; - goto out; - } - - /* already existing temperature */ - for (i = 0; i < IWL_MAX_DTS_TRIPS; i++) { - if (tzone->temp_trips[i] == temperature) { - ret = -EINVAL; - goto out; - } - } - - tzone->temp_trips[trip] = temperature; - ret = iwl_mvm_send_temp_report_ths_cmd(mvm); out: mutex_unlock(&mvm->mutex); @@ -720,8 +672,6 @@ static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device, static struct thermal_zone_device_ops tzone_ops = { .get_temp = iwl_mvm_tzone_get_temp, - .get_trip_temp = iwl_mvm_tzone_get_trip_temp, - .get_trip_type = iwl_mvm_tzone_get_trip_type, .set_trip_temp = iwl_mvm_tzone_set_trip_temp, }; @@ -743,7 +693,8 @@ static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) BUILD_BUG_ON(ARRAY_SIZE(name) >= THERMAL_NAME_LENGTH); sprintf(name, "iwlwifi_%u", atomic_inc_return(&counter) & 0xFF); - mvm->tz_device.tzone = thermal_zone_device_register(name, + mvm->tz_device.tzone = thermal_zone_device_register_with_trips(name, + mvm->tz_device.trips, IWL_MAX_DTS_TRIPS, IWL_WRITABLE_TRIPS_MSK, mvm, &tzone_ops, @@ -766,8 +717,10 @@ static void iwl_mvm_thermal_zone_register(struct iwl_mvm *mvm) /* 0 is a valid temperature, * so initialize the array with S16_MIN which invalid temperature */ - for (i = 0 ; i < IWL_MAX_DTS_TRIPS; i++) - mvm->tz_device.temp_trips[i] = S16_MIN; + for (i = 0 ; i < IWL_MAX_DTS_TRIPS; i++) { + mvm->tz_device.trips[i].temperature = INT_MIN; + mvm->tz_device.trips[i].type = THERMAL_TRIP_PASSIVE; + } } static int iwl_mvm_tcool_get_max_state(struct thermal_cooling_device *cdev, From patchwork Fri Oct 14 07:32:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 2551 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp52356wrs; Fri, 14 Oct 2022 00:51:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5DmWFbsrpiZo//qP/Y1Kg6IZF8Yq9l5mtK+8dJAAzr7aQFwS8yigli6p8yB8hoy/XIfJek X-Received: by 2002:a17:907:6d92:b0:78d:d2e5:7cda with SMTP id sb18-20020a1709076d9200b0078dd2e57cdamr2582222ejc.625.1665733878980; Fri, 14 Oct 2022 00:51:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665733878; cv=none; d=google.com; s=arc-20160816; b=KR0UfzysiFWmlaXnVFwgqmA6Vyyfzg6abDuBxd+epD9gZbXlOtm2o9tU2kTlW8Mboh CRA2pHDBdXrgDdfzccy7VsSd1PTOeIud5s6kdlNEXGYznKdc/bjVFv2gWIwvQgQpbCKP A1zYO/QNFD5/vO27B/sLS4sZPRjPmhwoPck7JBn01NN/I3ogz/kC2D3Kkd+pkLQxSV/h C5WB1niA0hcRHmDtjXG07nyuk6GrOdqjWGUjL32x+8OO9j5afIaWPXJhpldjy/pRZfGa QSSEeyxJyfkdXdxbnmvF00MpwuqlgEhWy2xrw1uLCF3m8eI9cfnmW0C3CsDr7nZuLxa4 Pgjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lu7OnC5QoNnsZv1mkvWVBWm6k6o6Wf6fZ8wtEd3eTD4=; b=LYL6Tsgx+NzByyowsRfYzMEL6ztrbLdznr+bZPtm+USNR1xjMFkd14VaWbemZKD1ES 9e4LtehjrEwp7AZWq1fH602ysznFYDOW/L81S8ytSSY5BrG7Rjz/HyZqblHww8uLM2vD OK5XTw4qIlrpqQvbJdTfi9zuOLctZ8anGzNODPy5gkc2gU4kMo4j6hFIbe9vCVKUWkW3 4QPR3nKSzj5FB4km5Go/RDDvEcxEUT+UKW7mhxMVYYU9rF29cA5tPciNBdUNefvXSZ+F HFfeXjCNoXjkEaBPUT7dOVCb9NoMg5u3UhZI9hiJoCufbiXtgUCkmvkofZY/4Y17gEbS 6a3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="GsCGh/sC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc11-20020a1709078a0b00b0078de51e1c3dsi1886417ejc.840.2022.10.14.00.50.52; Fri, 14 Oct 2022 00:51:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="GsCGh/sC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229955AbiJNHdV (ORCPT + 99 others); Fri, 14 Oct 2022 03:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229887AbiJNHdP (ORCPT ); Fri, 14 Oct 2022 03:33:15 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6D211B8650 for ; Fri, 14 Oct 2022 00:33:13 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id r3-20020a05600c35c300b003b4b5f6c6bdso2958047wmq.2 for ; Fri, 14 Oct 2022 00:33:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lu7OnC5QoNnsZv1mkvWVBWm6k6o6Wf6fZ8wtEd3eTD4=; b=GsCGh/sCIBRCZOFrLbBdUst6l1jn0P59V3smFbobcddHSm0M2c1sTn5NADfRfX7WA+ 2D16i5Ypu/KgaLB6IjflJJWyfJpNciDnrJfTe0pBOrlCp/vCoKVoRHE0jjMhwHVXmoaM Ulhi9RxczthN9EcjyU015/0cPv3VB9YB7il3J24ISwRaE1NdNNCZev13B/Tp7FgGzMZM /O3NLHiO73GY0QqatVAquXeAJyYq99edsbD20MHBo4oLISWCZkK+tWNO2ocywMOWaVxr oze14cXbvgNo252fZ+nD9NLVGBpnZqEC+KWOEApAdNQcxbNUS7Whs58v5NlUWOOra/56 nSGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lu7OnC5QoNnsZv1mkvWVBWm6k6o6Wf6fZ8wtEd3eTD4=; b=YpypQH4lYoC7pMIo1FF6BpjyiUOV2AMMVeuz6yZkTze+nXhcDxy8fc70pvg6tDYNmh xUl5V9cwHOlCklZbzgbXoe4Rky5wp69fjZkfrb7FDNu/GmFpIQtBB5buVeC5L6044bp+ RxzOJLFwkraK67yq/3wmQ7bkhtwbAmdnZj+zwB3DsWnaknLZpK2j+B1DpX8qtcCkrsOk IRWoUIm6sGJR81YjyiC9N/EPRW/6oaUbp5MMNbde7sLO0jV4tVcA3JsmjDWYkpYCpFtY vm4KlsnCv9p6Mdc3zy1WKqFPVBQKTYew8JHhtnCCWexVuaTTydg3FipzsKLJqmAsgfZj sY1Q== X-Gm-Message-State: ACrzQf1EmrudZMHhVVFokA7aseXu3rINKPdI55HQAlTC4201Sfx9/sXq HBtT8ibBGZzIFTUtPRsgrnGiwA== X-Received: by 2002:a05:600c:35c9:b0:3c6:de85:cd38 with SMTP id r9-20020a05600c35c900b003c6de85cd38mr5023235wmq.48.1665732792151; Fri, 14 Oct 2022 00:33:12 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:b460:17f0:186d:9d2e]) by smtp.gmail.com with ESMTPSA id w12-20020a05600c474c00b003a682354f63sm898148wmo.11.2022.10.14.00.33.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 00:33:11 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org, daniel.lezcano@linaro.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Ido Schimmel , Petr Machata , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org (open list:MELLANOX ETHERNET SWITCH DRIVERS) Subject: [PATCH 2/2] thermal/drivers/mellanox: Use generic thermal_zone_get_trip() function Date: Fri, 14 Oct 2022 09:32:51 +0200 Message-Id: <20221014073253.3719911-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221014073253.3719911-1-daniel.lezcano@linaro.org> References: <20221014073253.3719911-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746648567927683234?= X-GMAIL-MSGID: =?utf-8?q?1746648567927683234?= The thermal framework gives the possibility to register the trip points with the thermal zone. When that is done, no get_trip_* ops are needed and they can be removed. Convert ops content logic into generic trip points and register them with the thermal zone. Signed-off-by: Daniel Lezcano --- .../ethernet/mellanox/mlxsw/core_thermal.c | 209 ++++-------------- 1 file changed, 48 insertions(+), 161 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c index 987fe5c9d5a3..c5240d38c9db 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c @@ -36,33 +36,39 @@ enum mlxsw_thermal_trips { MLXSW_THERMAL_TEMP_TRIP_HOT, }; -struct mlxsw_thermal_trip { - int type; - int temp; - int hyst; +struct mlxsw_cooling_states { int min_state; int max_state; }; -static const struct mlxsw_thermal_trip default_thermal_trips[] = { +static const struct thermal_trip default_thermal_trips[] = { { /* In range - 0-40% PWM */ .type = THERMAL_TRIP_ACTIVE, - .temp = MLXSW_THERMAL_ASIC_TEMP_NORM, - .hyst = MLXSW_THERMAL_HYSTERESIS_TEMP, - .min_state = 0, - .max_state = (4 * MLXSW_THERMAL_MAX_STATE) / 10, + .temperature = MLXSW_THERMAL_ASIC_TEMP_NORM, + .hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP, }, { /* In range - 40-100% PWM */ .type = THERMAL_TRIP_ACTIVE, - .temp = MLXSW_THERMAL_ASIC_TEMP_HIGH, - .hyst = MLXSW_THERMAL_HYSTERESIS_TEMP, - .min_state = (4 * MLXSW_THERMAL_MAX_STATE) / 10, - .max_state = MLXSW_THERMAL_MAX_STATE, + .temperature = MLXSW_THERMAL_ASIC_TEMP_HIGH, + .hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP, }, { /* Warning */ .type = THERMAL_TRIP_HOT, - .temp = MLXSW_THERMAL_ASIC_TEMP_HOT, + .temperature = MLXSW_THERMAL_ASIC_TEMP_HOT, + }, +}; + +static const struct mlxsw_cooling_states default_cooling_states[] = { + { + .min_state = 0, + .max_state = (4 * MLXSW_THERMAL_MAX_STATE) / 10, + }, + { + .min_state = (4 * MLXSW_THERMAL_MAX_STATE) / 10, + .max_state = MLXSW_THERMAL_MAX_STATE, + }, + { .min_state = MLXSW_THERMAL_MAX_STATE, .max_state = MLXSW_THERMAL_MAX_STATE, }, @@ -78,7 +84,8 @@ struct mlxsw_thermal; struct mlxsw_thermal_module { struct mlxsw_thermal *parent; struct thermal_zone_device *tzdev; - struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; + struct thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; + struct mlxsw_cooling_states cooling_states[MLXSW_THERMAL_NUM_TRIPS]; int module; /* Module or gearbox number */ u8 slot_index; }; @@ -99,7 +106,8 @@ struct mlxsw_thermal { int polling_delay; struct thermal_cooling_device *cdevs[MLXSW_MFCR_PWMS_MAX]; u8 cooling_levels[MLXSW_THERMAL_MAX_STATE + 1]; - struct mlxsw_thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; + struct thermal_trip trips[MLXSW_THERMAL_NUM_TRIPS]; + struct mlxsw_cooling_states cooling_states[MLXSW_THERMAL_NUM_TRIPS]; struct mlxsw_thermal_area line_cards[]; }; @@ -136,9 +144,9 @@ static int mlxsw_get_cooling_device_idx(struct mlxsw_thermal *thermal, static void mlxsw_thermal_module_trips_reset(struct mlxsw_thermal_module *tz) { - tz->trips[MLXSW_THERMAL_TEMP_TRIP_NORM].temp = 0; - tz->trips[MLXSW_THERMAL_TEMP_TRIP_HIGH].temp = 0; - tz->trips[MLXSW_THERMAL_TEMP_TRIP_HOT].temp = 0; + tz->trips[MLXSW_THERMAL_TEMP_TRIP_NORM].temperature = 0; + tz->trips[MLXSW_THERMAL_TEMP_TRIP_HIGH].temperature = 0; + tz->trips[MLXSW_THERMAL_TEMP_TRIP_HOT].temperature = 0; } static int @@ -180,12 +188,12 @@ mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core, * by subtracting double hysteresis value. */ if (crit_temp >= MLXSW_THERMAL_MODULE_TEMP_SHIFT) - tz->trips[MLXSW_THERMAL_TEMP_TRIP_NORM].temp = crit_temp - + tz->trips[MLXSW_THERMAL_TEMP_TRIP_NORM].temperature = crit_temp - MLXSW_THERMAL_MODULE_TEMP_SHIFT; else - tz->trips[MLXSW_THERMAL_TEMP_TRIP_NORM].temp = crit_temp; - tz->trips[MLXSW_THERMAL_TEMP_TRIP_HIGH].temp = crit_temp; - tz->trips[MLXSW_THERMAL_TEMP_TRIP_HOT].temp = emerg_temp; + tz->trips[MLXSW_THERMAL_TEMP_TRIP_NORM].temperature = crit_temp; + tz->trips[MLXSW_THERMAL_TEMP_TRIP_HIGH].temperature = crit_temp; + tz->trips[MLXSW_THERMAL_TEMP_TRIP_HOT].temperature = emerg_temp; return 0; } @@ -202,11 +210,11 @@ static int mlxsw_thermal_bind(struct thermal_zone_device *tzdev, return 0; for (i = 0; i < MLXSW_THERMAL_NUM_TRIPS; i++) { - const struct mlxsw_thermal_trip *trip = &thermal->trips[i]; + const struct mlxsw_cooling_states *state = &thermal->cooling_states[i]; err = thermal_zone_bind_cooling_device(tzdev, i, cdev, - trip->max_state, - trip->min_state, + state->max_state, + state->min_state, THERMAL_WEIGHT_DEFAULT); if (err < 0) { dev_err(dev, "Failed to bind cooling device to trip %d\n", i); @@ -260,61 +268,6 @@ static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev, return 0; } -static int mlxsw_thermal_get_trip_type(struct thermal_zone_device *tzdev, - int trip, - enum thermal_trip_type *p_type) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS) - return -EINVAL; - - *p_type = thermal->trips[trip].type; - return 0; -} - -static int mlxsw_thermal_get_trip_temp(struct thermal_zone_device *tzdev, - int trip, int *p_temp) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS) - return -EINVAL; - - *p_temp = thermal->trips[trip].temp; - return 0; -} - -static int mlxsw_thermal_set_trip_temp(struct thermal_zone_device *tzdev, - int trip, int temp) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS) - return -EINVAL; - - thermal->trips[trip].temp = temp; - return 0; -} - -static int mlxsw_thermal_get_trip_hyst(struct thermal_zone_device *tzdev, - int trip, int *p_hyst) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - *p_hyst = thermal->trips[trip].hyst; - return 0; -} - -static int mlxsw_thermal_set_trip_hyst(struct thermal_zone_device *tzdev, - int trip, int hyst) -{ - struct mlxsw_thermal *thermal = tzdev->devdata; - - thermal->trips[trip].hyst = hyst; - return 0; -} - static struct thermal_zone_params mlxsw_thermal_params = { .no_hwmon = true, }; @@ -323,11 +276,6 @@ static struct thermal_zone_device_ops mlxsw_thermal_ops = { .bind = mlxsw_thermal_bind, .unbind = mlxsw_thermal_unbind, .get_temp = mlxsw_thermal_get_temp, - .get_trip_type = mlxsw_thermal_get_trip_type, - .get_trip_temp = mlxsw_thermal_get_trip_temp, - .set_trip_temp = mlxsw_thermal_set_trip_temp, - .get_trip_hyst = mlxsw_thermal_get_trip_hyst, - .set_trip_hyst = mlxsw_thermal_set_trip_hyst, }; static int mlxsw_thermal_module_bind(struct thermal_zone_device *tzdev, @@ -342,11 +290,11 @@ static int mlxsw_thermal_module_bind(struct thermal_zone_device *tzdev, return 0; for (i = 0; i < MLXSW_THERMAL_NUM_TRIPS; i++) { - const struct mlxsw_thermal_trip *trip = &tz->trips[i]; + const struct mlxsw_cooling_states *state = &tz->cooling_states[i]; err = thermal_zone_bind_cooling_device(tzdev, i, cdev, - trip->max_state, - trip->min_state, + state->max_state, + state->min_state, THERMAL_WEIGHT_DEFAULT); if (err < 0) goto err_thermal_zone_bind_cooling_device; @@ -434,74 +382,10 @@ static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev, return 0; } -static int -mlxsw_thermal_module_trip_type_get(struct thermal_zone_device *tzdev, int trip, - enum thermal_trip_type *p_type) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - - if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS) - return -EINVAL; - - *p_type = tz->trips[trip].type; - return 0; -} - -static int -mlxsw_thermal_module_trip_temp_get(struct thermal_zone_device *tzdev, - int trip, int *p_temp) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - - if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS) - return -EINVAL; - - *p_temp = tz->trips[trip].temp; - return 0; -} - -static int -mlxsw_thermal_module_trip_temp_set(struct thermal_zone_device *tzdev, - int trip, int temp) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - - if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS) - return -EINVAL; - - tz->trips[trip].temp = temp; - return 0; -} - -static int -mlxsw_thermal_module_trip_hyst_get(struct thermal_zone_device *tzdev, int trip, - int *p_hyst) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - - *p_hyst = tz->trips[trip].hyst; - return 0; -} - -static int -mlxsw_thermal_module_trip_hyst_set(struct thermal_zone_device *tzdev, int trip, - int hyst) -{ - struct mlxsw_thermal_module *tz = tzdev->devdata; - - tz->trips[trip].hyst = hyst; - return 0; -} - static struct thermal_zone_device_ops mlxsw_thermal_module_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, .get_temp = mlxsw_thermal_module_temp_get, - .get_trip_type = mlxsw_thermal_module_trip_type_get, - .get_trip_temp = mlxsw_thermal_module_trip_temp_get, - .set_trip_temp = mlxsw_thermal_module_trip_temp_set, - .get_trip_hyst = mlxsw_thermal_module_trip_hyst_get, - .set_trip_hyst = mlxsw_thermal_module_trip_hyst_set, }; static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev, @@ -531,11 +415,6 @@ static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = { .bind = mlxsw_thermal_module_bind, .unbind = mlxsw_thermal_module_unbind, .get_temp = mlxsw_thermal_gearbox_temp_get, - .get_trip_type = mlxsw_thermal_module_trip_type_get, - .get_trip_temp = mlxsw_thermal_module_trip_temp_get, - .set_trip_temp = mlxsw_thermal_module_trip_temp_set, - .get_trip_hyst = mlxsw_thermal_module_trip_hyst_get, - .set_trip_hyst = mlxsw_thermal_module_trip_hyst_set, }; static int mlxsw_thermal_get_max_state(struct thermal_cooling_device *cdev, @@ -617,7 +496,8 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) else snprintf(tz_name, sizeof(tz_name), "mlxsw-module%d", module_tz->module + 1); - module_tz->tzdev = thermal_zone_device_register(tz_name, + module_tz->tzdev = thermal_zone_device_register_with_trips(tz_name, + module_tz->trips, MLXSW_THERMAL_NUM_TRIPS, MLXSW_THERMAL_TRIP_MASK, module_tz, @@ -661,6 +541,8 @@ mlxsw_thermal_module_init(struct device *dev, struct mlxsw_core *core, module_tz->parent = thermal; memcpy(module_tz->trips, default_thermal_trips, sizeof(thermal->trips)); + memcpy(module_tz->cooling_states, default_cooling_states, + sizeof(thermal->cooling_states)); /* Initialize all trip point. */ mlxsw_thermal_module_trips_reset(module_tz); /* Read module temperature and thresholds. */ @@ -756,7 +638,8 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) else snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d", gearbox_tz->module + 1); - gearbox_tz->tzdev = thermal_zone_device_register(tz_name, + gearbox_tz->tzdev = thermal_zone_device_register_with_trips(tz_name, + gearbox_tz->trips, MLXSW_THERMAL_NUM_TRIPS, MLXSW_THERMAL_TRIP_MASK, gearbox_tz, @@ -813,6 +696,8 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core, gearbox_tz = &area->tz_gearbox_arr[i]; memcpy(gearbox_tz->trips, default_thermal_trips, sizeof(thermal->trips)); + memcpy(gearbox_tz->cooling_states, default_cooling_states, + sizeof(thermal->cooling_states)); gearbox_tz->module = i; gearbox_tz->parent = thermal; gearbox_tz->slot_index = area->slot_index; @@ -928,6 +813,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core, thermal->core = core; thermal->bus_info = bus_info; memcpy(thermal->trips, default_thermal_trips, sizeof(thermal->trips)); + memcpy(thermal->cooling_states, default_cooling_states, sizeof(thermal->cooling_states)); thermal->line_cards[0].slot_index = 0; err = mlxsw_reg_query(thermal->core, MLXSW_REG(mfcr), mfcr_pl); @@ -981,7 +867,8 @@ int mlxsw_thermal_init(struct mlxsw_core *core, MLXSW_THERMAL_SLOW_POLL_INT : MLXSW_THERMAL_POLL_INT; - thermal->tzdev = thermal_zone_device_register("mlxsw", + thermal->tzdev = thermal_zone_device_register_with_trips("mlxsw", + thermal->trips, MLXSW_THERMAL_NUM_TRIPS, MLXSW_THERMAL_TRIP_MASK, thermal,