treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / ethernet / chelsio / cxgb4 / cxgb4_thermal.c
blob3de8a5e83b6c7f73ac3868d2550bfef45f7fd073
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2017 Chelsio Communications. All rights reserved.
5 * Written by: Ganesh Goudar (ganeshgr@chelsio.com)
6 */
8 #include "cxgb4.h"
10 #define CXGB4_NUM_TRIPS 1
12 static int cxgb4_thermal_get_temp(struct thermal_zone_device *tzdev,
13 int *temp)
15 struct adapter *adap = tzdev->devdata;
16 u32 param, val;
17 int ret;
19 param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
20 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
21 FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
23 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
24 &param, &val);
25 if (ret < 0 || val == 0)
26 return -1;
28 *temp = val * 1000;
29 return 0;
32 static int cxgb4_thermal_get_trip_type(struct thermal_zone_device *tzdev,
33 int trip, enum thermal_trip_type *type)
35 struct adapter *adap = tzdev->devdata;
37 if (!adap->ch_thermal.trip_temp)
38 return -EINVAL;
40 *type = adap->ch_thermal.trip_type;
41 return 0;
44 static int cxgb4_thermal_get_trip_temp(struct thermal_zone_device *tzdev,
45 int trip, int *temp)
47 struct adapter *adap = tzdev->devdata;
49 if (!adap->ch_thermal.trip_temp)
50 return -EINVAL;
52 *temp = adap->ch_thermal.trip_temp;
53 return 0;
56 static struct thermal_zone_device_ops cxgb4_thermal_ops = {
57 .get_temp = cxgb4_thermal_get_temp,
58 .get_trip_type = cxgb4_thermal_get_trip_type,
59 .get_trip_temp = cxgb4_thermal_get_trip_temp,
62 int cxgb4_thermal_init(struct adapter *adap)
64 struct ch_thermal *ch_thermal = &adap->ch_thermal;
65 int num_trip = CXGB4_NUM_TRIPS;
66 u32 param, val;
67 int ret;
69 /* on older firmwares we may not get the trip temperature,
70 * set the num of trips to 0.
72 param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
73 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
74 FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_MAXTMPTHRESH));
76 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
77 &param, &val);
78 if (ret < 0) {
79 num_trip = 0; /* could not get trip temperature */
80 } else {
81 ch_thermal->trip_temp = val * 1000;
82 ch_thermal->trip_type = THERMAL_TRIP_CRITICAL;
85 ch_thermal->tzdev = thermal_zone_device_register("cxgb4", num_trip,
86 0, adap,
87 &cxgb4_thermal_ops,
88 NULL, 0, 0);
89 if (IS_ERR(ch_thermal->tzdev)) {
90 ret = PTR_ERR(ch_thermal->tzdev);
91 dev_err(adap->pdev_dev, "Failed to register thermal zone\n");
92 ch_thermal->tzdev = NULL;
93 return ret;
95 return 0;
98 int cxgb4_thermal_remove(struct adapter *adap)
100 if (adap->ch_thermal.tzdev)
101 thermal_zone_device_unregister(adap->ch_thermal.tzdev);
102 return 0;