Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  Copyright (C) 2017 Chelsio Communications.  All rights reserved.
0004  *
0005  *  Written by: Ganesh Goudar (ganeshgr@chelsio.com)
0006  */
0007 
0008 #include "cxgb4.h"
0009 
0010 #define CXGB4_NUM_TRIPS 1
0011 
0012 static int cxgb4_thermal_get_temp(struct thermal_zone_device *tzdev,
0013                   int *temp)
0014 {
0015     struct adapter *adap = tzdev->devdata;
0016     u32 param, val;
0017     int ret;
0018 
0019     param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
0020          FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
0021          FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
0022 
0023     ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
0024                   &param, &val);
0025     if (ret < 0 || val == 0)
0026         return -1;
0027 
0028     *temp = val * 1000;
0029     return 0;
0030 }
0031 
0032 static int cxgb4_thermal_get_trip_type(struct thermal_zone_device *tzdev,
0033                        int trip, enum thermal_trip_type *type)
0034 {
0035     struct adapter *adap = tzdev->devdata;
0036 
0037     if (!adap->ch_thermal.trip_temp)
0038         return -EINVAL;
0039 
0040     *type = adap->ch_thermal.trip_type;
0041     return 0;
0042 }
0043 
0044 static int cxgb4_thermal_get_trip_temp(struct thermal_zone_device *tzdev,
0045                        int trip, int *temp)
0046 {
0047     struct adapter *adap = tzdev->devdata;
0048 
0049     if (!adap->ch_thermal.trip_temp)
0050         return -EINVAL;
0051 
0052     *temp = adap->ch_thermal.trip_temp;
0053     return 0;
0054 }
0055 
0056 static struct thermal_zone_device_ops cxgb4_thermal_ops = {
0057     .get_temp = cxgb4_thermal_get_temp,
0058     .get_trip_type = cxgb4_thermal_get_trip_type,
0059     .get_trip_temp = cxgb4_thermal_get_trip_temp,
0060 };
0061 
0062 int cxgb4_thermal_init(struct adapter *adap)
0063 {
0064     struct ch_thermal *ch_thermal = &adap->ch_thermal;
0065     char ch_tz_name[THERMAL_NAME_LENGTH];
0066     int num_trip = CXGB4_NUM_TRIPS;
0067     u32 param, val;
0068     int ret;
0069 
0070     /* on older firmwares we may not get the trip temperature,
0071      * set the num of trips to 0.
0072      */
0073     param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
0074          FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
0075          FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_MAXTMPTHRESH));
0076 
0077     ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
0078                   &param, &val);
0079     if (ret < 0) {
0080         num_trip = 0; /* could not get trip temperature */
0081     } else {
0082         ch_thermal->trip_temp = val * 1000;
0083         ch_thermal->trip_type = THERMAL_TRIP_CRITICAL;
0084     }
0085 
0086     snprintf(ch_tz_name, sizeof(ch_tz_name), "cxgb4_%s", adap->name);
0087     ch_thermal->tzdev = thermal_zone_device_register(ch_tz_name, num_trip,
0088                              0, adap,
0089                              &cxgb4_thermal_ops,
0090                              NULL, 0, 0);
0091     if (IS_ERR(ch_thermal->tzdev)) {
0092         ret = PTR_ERR(ch_thermal->tzdev);
0093         dev_err(adap->pdev_dev, "Failed to register thermal zone\n");
0094         ch_thermal->tzdev = NULL;
0095         return ret;
0096     }
0097 
0098     ret = thermal_zone_device_enable(ch_thermal->tzdev);
0099     if (ret) {
0100         dev_err(adap->pdev_dev, "Failed to enable thermal zone\n");
0101         thermal_zone_device_unregister(adap->ch_thermal.tzdev);
0102         return ret;
0103     }
0104 
0105     return 0;
0106 }
0107 
0108 int cxgb4_thermal_remove(struct adapter *adap)
0109 {
0110     if (adap->ch_thermal.tzdev) {
0111         thermal_zone_device_unregister(adap->ch_thermal.tzdev);
0112         adap->ch_thermal.tzdev = NULL;
0113     }
0114     return 0;
0115 }