···5252#include <linux/ptp_clock_kernel.h>5353#include <linux/ptp_classify.h>5454#include <linux/crash_dump.h>5555+#include <linux/thermal.h>5556#include <asm/io.h>5657#include "t4_chip_type.h"5758#include "cxgb4_uld.h"···891890 atomic_t refcnt;892891};893892893893+#ifdef CONFIG_THERMAL894894+struct ch_thermal {895895+ struct thermal_zone_device *tzdev;896896+ int trip_temp;897897+ int trip_type;898898+};899899+#endif900900+894901struct adapter {895902 void __iomem *regs;896903 void __iomem *bar2;···1017100810181009 /* Dump buffer for collecting logs in kdump kernel */10191010 struct vmcoredd_data vmcoredd;10111011+#ifdef CONFIG_THERMAL10121012+ struct ch_thermal ch_thermal;10131013+#endif10201014};1021101510221016/* Support for "sched-class" command to allow a TX Scheduling Class to be···18741862int t4_set_vlan_acl(struct adapter *adap, unsigned int mbox, unsigned int vf,18751863 u16 vlan);18761864int cxgb4_dcb_enabled(const struct net_device *dev);18651865+18661866+#ifdef CONFIG_THERMAL18671867+int cxgb4_thermal_init(struct adapter *adap);18681868+int cxgb4_thermal_remove(struct adapter *adap);18691869+#endif /* CONFIG_THERMAL */18701870+18771871#endif /* __CXGB4_H__ */
+8
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
···58645864 if (!is_t4(adapter->params.chip))58655865 cxgb4_ptp_init(adapter);5866586658675867+#ifdef CONFIG_THERMAL58685868+ if (!is_t4(adapter->params.chip) && (adapter->flags & FW_OK))58695869+ cxgb4_thermal_init(adapter);58705870+#endif /* CONFIG_THERMAL */58715871+58675872 print_adapter_info(adapter);58685873 return 0;58695874···5934592959355930 if (!is_t4(adapter->params.chip))59365931 cxgb4_ptp_stop(adapter);59325932+#ifdef CONFIG_THERMAL59335933+ cxgb4_thermal_remove(adapter);59345934+#endif5937593559385936 /* If we allocated filters, free up state associated with any59395937 * valid filters ...
···11+/*22+ * Copyright (C) 2017 Chelsio Communications. All rights reserved.33+ *44+ * This program is free software; you can redistribute it and/or modify it55+ * under the terms and conditions of the GNU General Public License,66+ * version 2, as published by the Free Software Foundation.77+ *88+ * This program is distributed in the hope it will be useful, but WITHOUT99+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or1010+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for1111+ * more details.1212+ *1313+ * The full GNU General Public License is included in this distribution in1414+ * the file called "COPYING".1515+ *1616+ * Written by: Ganesh Goudar (ganeshgr@chelsio.com)1717+ */1818+1919+#include "cxgb4.h"2020+2121+#define CXGB4_NUM_TRIPS 12222+2323+static int cxgb4_thermal_get_temp(struct thermal_zone_device *tzdev,2424+ int *temp)2525+{2626+ struct adapter *adap = tzdev->devdata;2727+ u32 param, val;2828+ int ret;2929+3030+ param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |3131+ FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |3232+ FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));3333+3434+ ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,3535+ ¶m, &val);3636+ if (ret < 0 || val == 0)3737+ return -1;3838+3939+ *temp = val * 1000;4040+ return 0;4141+}4242+4343+static int cxgb4_thermal_get_trip_type(struct thermal_zone_device *tzdev,4444+ int trip, enum thermal_trip_type *type)4545+{4646+ struct adapter *adap = tzdev->devdata;4747+4848+ if (!adap->ch_thermal.trip_temp)4949+ return -EINVAL;5050+5151+ *type = adap->ch_thermal.trip_type;5252+ return 0;5353+}5454+5555+static int cxgb4_thermal_get_trip_temp(struct thermal_zone_device *tzdev,5656+ int trip, int *temp)5757+{5858+ struct adapter *adap = tzdev->devdata;5959+6060+ if (!adap->ch_thermal.trip_temp)6161+ return -EINVAL;6262+6363+ *temp = adap->ch_thermal.trip_temp;6464+ return 0;6565+}6666+6767+static struct thermal_zone_device_ops cxgb4_thermal_ops = {6868+ .get_temp = cxgb4_thermal_get_temp,6969+ .get_trip_type = cxgb4_thermal_get_trip_type,7070+ .get_trip_temp = cxgb4_thermal_get_trip_temp,7171+};7272+7373+int cxgb4_thermal_init(struct adapter *adap)7474+{7575+ struct ch_thermal *ch_thermal = &adap->ch_thermal;7676+ int num_trip = CXGB4_NUM_TRIPS;7777+ u32 param, val;7878+ int ret;7979+8080+ /* on older firmwares we may not get the trip temperature,8181+ * set the num of trips to 0.8282+ */8383+ param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |8484+ FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |8585+ FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_MAXTMPTHRESH));8686+8787+ ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,8888+ ¶m, &val);8989+ if (ret < 0) {9090+ num_trip = 0; /* could not get trip temperature */9191+ } else {9292+ ch_thermal->trip_temp = val * 1000;9393+ ch_thermal->trip_type = THERMAL_TRIP_CRITICAL;9494+ }9595+9696+ ch_thermal->tzdev = thermal_zone_device_register("cxgb4", num_trip,9797+ 0, adap,9898+ &cxgb4_thermal_ops,9999+ NULL, 0, 0);100100+ if (IS_ERR(ch_thermal->tzdev)) {101101+ ret = PTR_ERR(ch_thermal->tzdev);102102+ dev_err(adap->pdev_dev, "Failed to register thermal zone\n");103103+ ch_thermal->tzdev = NULL;104104+ return ret;105105+ }106106+ return 0;107107+}108108+109109+int cxgb4_thermal_remove(struct adapter *adap)110110+{111111+ if (adap->ch_thermal.tzdev)112112+ thermal_zone_device_unregister(adap->ch_thermal.tzdev);113113+ return 0;114114+}