Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cxgb4: Add thermal zone support

Add thermal zone support to monitor ASIC's temperature.

Signed-off-by: Ganesh Goudar <ganeshgr@chelsio.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Ganesh Goudar and committed by
David S. Miller
b1871915 27055454

+142
+1
drivers/net/ethernet/chelsio/cxgb4/Makefile
··· 12 12 cxgb4-$(CONFIG_CHELSIO_T4_DCB) += cxgb4_dcb.o 13 13 cxgb4-$(CONFIG_CHELSIO_T4_FCOE) += cxgb4_fcoe.o 14 14 cxgb4-$(CONFIG_DEBUG_FS) += cxgb4_debugfs.o 15 + cxgb4-$(CONFIG_THERMAL) += cxgb4_thermal.o
+18
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
··· 52 52 #include <linux/ptp_clock_kernel.h> 53 53 #include <linux/ptp_classify.h> 54 54 #include <linux/crash_dump.h> 55 + #include <linux/thermal.h> 55 56 #include <asm/io.h> 56 57 #include "t4_chip_type.h" 57 58 #include "cxgb4_uld.h" ··· 891 890 atomic_t refcnt; 892 891 }; 893 892 893 + #ifdef CONFIG_THERMAL 894 + struct ch_thermal { 895 + struct thermal_zone_device *tzdev; 896 + int trip_temp; 897 + int trip_type; 898 + }; 899 + #endif 900 + 894 901 struct adapter { 895 902 void __iomem *regs; 896 903 void __iomem *bar2; ··· 1017 1008 1018 1009 /* Dump buffer for collecting logs in kdump kernel */ 1019 1010 struct vmcoredd_data vmcoredd; 1011 + #ifdef CONFIG_THERMAL 1012 + struct ch_thermal ch_thermal; 1013 + #endif 1020 1014 }; 1021 1015 1022 1016 /* Support for "sched-class" command to allow a TX Scheduling Class to be ··· 1874 1862 int t4_set_vlan_acl(struct adapter *adap, unsigned int mbox, unsigned int vf, 1875 1863 u16 vlan); 1876 1864 int cxgb4_dcb_enabled(const struct net_device *dev); 1865 + 1866 + #ifdef CONFIG_THERMAL 1867 + int cxgb4_thermal_init(struct adapter *adap); 1868 + int cxgb4_thermal_remove(struct adapter *adap); 1869 + #endif /* CONFIG_THERMAL */ 1870 + 1877 1871 #endif /* __CXGB4_H__ */
+8
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
··· 5864 5864 if (!is_t4(adapter->params.chip)) 5865 5865 cxgb4_ptp_init(adapter); 5866 5866 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 + 5867 5872 print_adapter_info(adapter); 5868 5873 return 0; 5869 5874 ··· 5934 5929 5935 5930 if (!is_t4(adapter->params.chip)) 5936 5931 cxgb4_ptp_stop(adapter); 5932 + #ifdef CONFIG_THERMAL 5933 + cxgb4_thermal_remove(adapter); 5934 + #endif 5937 5935 5938 5936 /* If we allocated filters, free up state associated with any 5939 5937 * valid filters ...
+114
drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c
··· 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 (ganeshgr@chelsio.com) 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 + }
+1
drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h
··· 1332 1332 enum fw_params_param_dev_diag { 1333 1333 FW_PARAM_DEV_DIAG_TMP = 0x00, 1334 1334 FW_PARAM_DEV_DIAG_VDD = 0x01, 1335 + FW_PARAM_DEV_DIAG_MAXTMPTHRESH = 0x02, 1335 1336 }; 1336 1337 1337 1338 enum fw_params_param_dev_fwcache {