Skip to content

Commit b187191

Browse files
Ganesh Goudardavem330
authored andcommitted
cxgb4: Add thermal zone support
Add thermal zone support to monitor ASIC's temperature. Signed-off-by: Ganesh Goudar <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2705545 commit b187191

File tree

5 files changed

+142
-0
lines changed

5 files changed

+142
-0
lines changed

drivers/net/ethernet/chelsio/cxgb4/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ cxgb4-objs := cxgb4_main.o l2t.o smt.o t4_hw.o sge.o clip_tbl.o cxgb4_ethtool.o
1212
cxgb4-$(CONFIG_CHELSIO_T4_DCB) += cxgb4_dcb.o
1313
cxgb4-$(CONFIG_CHELSIO_T4_FCOE) += cxgb4_fcoe.o
1414
cxgb4-$(CONFIG_DEBUG_FS) += cxgb4_debugfs.o
15+
cxgb4-$(CONFIG_THERMAL) += cxgb4_thermal.o

drivers/net/ethernet/chelsio/cxgb4/cxgb4.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <linux/ptp_clock_kernel.h>
5353
#include <linux/ptp_classify.h>
5454
#include <linux/crash_dump.h>
55+
#include <linux/thermal.h>
5556
#include <asm/io.h>
5657
#include "t4_chip_type.h"
5758
#include "cxgb4_uld.h"
@@ -890,6 +891,14 @@ struct mps_encap_entry {
890891
atomic_t refcnt;
891892
};
892893

894+
#ifdef CONFIG_THERMAL
895+
struct ch_thermal {
896+
struct thermal_zone_device *tzdev;
897+
int trip_temp;
898+
int trip_type;
899+
};
900+
#endif
901+
893902
struct adapter {
894903
void __iomem *regs;
895904
void __iomem *bar2;
@@ -1008,6 +1017,9 @@ struct adapter {
10081017

10091018
/* Dump buffer for collecting logs in kdump kernel */
10101019
struct vmcoredd_data vmcoredd;
1020+
#ifdef CONFIG_THERMAL
1021+
struct ch_thermal ch_thermal;
1022+
#endif
10111023
};
10121024

10131025
/* Support for "sched-class" command to allow a TX Scheduling Class to be
@@ -1862,4 +1874,10 @@ void cxgb4_ring_tx_db(struct adapter *adap, struct sge_txq *q, int n);
18621874
int t4_set_vlan_acl(struct adapter *adap, unsigned int mbox, unsigned int vf,
18631875
u16 vlan);
18641876
int cxgb4_dcb_enabled(const struct net_device *dev);
1877+
1878+
#ifdef CONFIG_THERMAL
1879+
int cxgb4_thermal_init(struct adapter *adap);
1880+
int cxgb4_thermal_remove(struct adapter *adap);
1881+
#endif /* CONFIG_THERMAL */
1882+
18651883
#endif /* __CXGB4_H__ */

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5864,6 +5864,11 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
58645864
if (!is_t4(adapter->params.chip))
58655865
cxgb4_ptp_init(adapter);
58665866

5867+
#ifdef CONFIG_THERMAL
5868+
if (!is_t4(adapter->params.chip) && (adapter->flags & FW_OK))
5869+
cxgb4_thermal_init(adapter);
5870+
#endif /* CONFIG_THERMAL */
5871+
58675872
print_adapter_info(adapter);
58685873
return 0;
58695874

@@ -5929,6 +5934,9 @@ static void remove_one(struct pci_dev *pdev)
59295934

59305935
if (!is_t4(adapter->params.chip))
59315936
cxgb4_ptp_stop(adapter);
5937+
#ifdef CONFIG_THERMAL
5938+
cxgb4_thermal_remove(adapter);
5939+
#endif
59325940

59335941
/* If we allocated filters, free up state associated with any
59345942
* valid filters ...
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (C) 2017 Chelsio Communications. All rights reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms and conditions of the GNU General Public License,
6+
* version 2, as published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
*
13+
* The full GNU General Public License is included in this distribution in
14+
* the file called "COPYING".
15+
*
16+
* Written by: Ganesh Goudar ([email protected])
17+
*/
18+
19+
#include "cxgb4.h"
20+
21+
#define CXGB4_NUM_TRIPS 1
22+
23+
static int cxgb4_thermal_get_temp(struct thermal_zone_device *tzdev,
24+
int *temp)
25+
{
26+
struct adapter *adap = tzdev->devdata;
27+
u32 param, val;
28+
int ret;
29+
30+
param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
31+
FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
32+
FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
33+
34+
ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
35+
&param, &val);
36+
if (ret < 0 || val == 0)
37+
return -1;
38+
39+
*temp = val * 1000;
40+
return 0;
41+
}
42+
43+
static int cxgb4_thermal_get_trip_type(struct thermal_zone_device *tzdev,
44+
int trip, enum thermal_trip_type *type)
45+
{
46+
struct adapter *adap = tzdev->devdata;
47+
48+
if (!adap->ch_thermal.trip_temp)
49+
return -EINVAL;
50+
51+
*type = adap->ch_thermal.trip_type;
52+
return 0;
53+
}
54+
55+
static int cxgb4_thermal_get_trip_temp(struct thermal_zone_device *tzdev,
56+
int trip, int *temp)
57+
{
58+
struct adapter *adap = tzdev->devdata;
59+
60+
if (!adap->ch_thermal.trip_temp)
61+
return -EINVAL;
62+
63+
*temp = adap->ch_thermal.trip_temp;
64+
return 0;
65+
}
66+
67+
static struct thermal_zone_device_ops cxgb4_thermal_ops = {
68+
.get_temp = cxgb4_thermal_get_temp,
69+
.get_trip_type = cxgb4_thermal_get_trip_type,
70+
.get_trip_temp = cxgb4_thermal_get_trip_temp,
71+
};
72+
73+
int cxgb4_thermal_init(struct adapter *adap)
74+
{
75+
struct ch_thermal *ch_thermal = &adap->ch_thermal;
76+
int num_trip = CXGB4_NUM_TRIPS;
77+
u32 param, val;
78+
int ret;
79+
80+
/* on older firmwares we may not get the trip temperature,
81+
* set the num of trips to 0.
82+
*/
83+
param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
84+
FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
85+
FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_MAXTMPTHRESH));
86+
87+
ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
88+
&param, &val);
89+
if (ret < 0) {
90+
num_trip = 0; /* could not get trip temperature */
91+
} else {
92+
ch_thermal->trip_temp = val * 1000;
93+
ch_thermal->trip_type = THERMAL_TRIP_CRITICAL;
94+
}
95+
96+
ch_thermal->tzdev = thermal_zone_device_register("cxgb4", num_trip,
97+
0, adap,
98+
&cxgb4_thermal_ops,
99+
NULL, 0, 0);
100+
if (IS_ERR(ch_thermal->tzdev)) {
101+
ret = PTR_ERR(ch_thermal->tzdev);
102+
dev_err(adap->pdev_dev, "Failed to register thermal zone\n");
103+
ch_thermal->tzdev = NULL;
104+
return ret;
105+
}
106+
return 0;
107+
}
108+
109+
int cxgb4_thermal_remove(struct adapter *adap)
110+
{
111+
if (adap->ch_thermal.tzdev)
112+
thermal_zone_device_unregister(adap->ch_thermal.tzdev);
113+
return 0;
114+
}

drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,7 @@ enum fw_params_param_dev_phyfw {
13321332
enum fw_params_param_dev_diag {
13331333
FW_PARAM_DEV_DIAG_TMP = 0x00,
13341334
FW_PARAM_DEV_DIAG_VDD = 0x01,
1335+
FW_PARAM_DEV_DIAG_MAXTMPTHRESH = 0x02,
13351336
};
13361337

13371338
enum fw_params_param_dev_fwcache {

0 commit comments

Comments
 (0)