cxgb4: Add thermal zone support
authorGanesh Goudar <ganeshgr@chelsio.com>
Tue, 9 Oct 2018 13:44:13 +0000 (19:14 +0530)
committerDavid S. Miller <davem@davemloft.net>
Tue, 9 Oct 2018 18:16:28 +0000 (11:16 -0700)
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>
drivers/net/ethernet/chelsio/cxgb4/Makefile
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c [new file with mode: 0644]
drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h

index bea6a059a8f111672e4b23e867e5f5287b53321e..91d8a885deba9b8ea82125c3f0f9009fae9a3f91 100644 (file)
@@ -12,3 +12,4 @@ cxgb4-objs := cxgb4_main.o l2t.o smt.o t4_hw.o sge.o clip_tbl.o cxgb4_ethtool.o
 cxgb4-$(CONFIG_CHELSIO_T4_DCB) +=  cxgb4_dcb.o
 cxgb4-$(CONFIG_CHELSIO_T4_FCOE) +=  cxgb4_fcoe.o
 cxgb4-$(CONFIG_DEBUG_FS) += cxgb4_debugfs.o
+cxgb4-$(CONFIG_THERMAL) += cxgb4_thermal.o
index b5010bd32ea3ebfb7ac14a07b9ad6e83203e089d..95909f0686b18a3a8e39463aaa3d4dd535dfc063 100644 (file)
@@ -52,6 +52,7 @@
 #include <linux/ptp_clock_kernel.h>
 #include <linux/ptp_classify.h>
 #include <linux/crash_dump.h>
+#include <linux/thermal.h>
 #include <asm/io.h>
 #include "t4_chip_type.h"
 #include "cxgb4_uld.h"
@@ -890,6 +891,14 @@ struct mps_encap_entry {
        atomic_t refcnt;
 };
 
+#ifdef CONFIG_THERMAL
+struct ch_thermal {
+       struct thermal_zone_device *tzdev;
+       int trip_temp;
+       int trip_type;
+};
+#endif
+
 struct adapter {
        void __iomem *regs;
        void __iomem *bar2;
@@ -1008,6 +1017,9 @@ struct adapter {
 
        /* Dump buffer for collecting logs in kdump kernel */
        struct vmcoredd_data vmcoredd;
+#ifdef CONFIG_THERMAL
+       struct ch_thermal ch_thermal;
+#endif
 };
 
 /* 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);
 int t4_set_vlan_acl(struct adapter *adap, unsigned int mbox, unsigned int vf,
                    u16 vlan);
 int cxgb4_dcb_enabled(const struct net_device *dev);
+
+#ifdef CONFIG_THERMAL
+int cxgb4_thermal_init(struct adapter *adap);
+int cxgb4_thermal_remove(struct adapter *adap);
+#endif /* CONFIG_THERMAL */
+
 #endif /* __CXGB4_H__ */
index 1a93efa60e719b94282a64cd69c994e05a42536e..03cc07386b4ac0087d55ff33c6041b7471d0fa68 100644 (file)
@@ -5864,6 +5864,11 @@ fw_attach_fail:
        if (!is_t4(adapter->params.chip))
                cxgb4_ptp_init(adapter);
 
+#ifdef CONFIG_THERMAL
+       if (!is_t4(adapter->params.chip) && (adapter->flags & FW_OK))
+               cxgb4_thermal_init(adapter);
+#endif /* CONFIG_THERMAL */
+
        print_adapter_info(adapter);
        return 0;
 
@@ -5929,6 +5934,9 @@ static void remove_one(struct pci_dev *pdev)
 
                if (!is_t4(adapter->params.chip))
                        cxgb4_ptp_stop(adapter);
+#ifdef CONFIG_THERMAL
+               cxgb4_thermal_remove(adapter);
+#endif
 
                /* If we allocated filters, free up state associated with any
                 * valid filters ...
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c
new file mode 100644 (file)
index 0000000..28052e7
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ *  Copyright (C) 2017 Chelsio Communications.  All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under the terms and conditions of the GNU General Public License,
+ *  version 2, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope it will be useful, but WITHOUT
+ *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ *  more details.
+ *
+ *  The full GNU General Public License is included in this distribution in
+ *  the file called "COPYING".
+ *
+ *  Written by: Ganesh Goudar (ganeshgr@chelsio.com)
+ */
+
+#include "cxgb4.h"
+
+#define CXGB4_NUM_TRIPS 1
+
+static int cxgb4_thermal_get_temp(struct thermal_zone_device *tzdev,
+                                 int *temp)
+{
+       struct adapter *adap = tzdev->devdata;
+       u32 param, val;
+       int ret;
+
+       param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
+                FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
+                FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
+
+       ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
+                             &param, &val);
+       if (ret < 0 || val == 0)
+               return -1;
+
+       *temp = val * 1000;
+       return 0;
+}
+
+static int cxgb4_thermal_get_trip_type(struct thermal_zone_device *tzdev,
+                                      int trip, enum thermal_trip_type *type)
+{
+       struct adapter *adap = tzdev->devdata;
+
+       if (!adap->ch_thermal.trip_temp)
+               return -EINVAL;
+
+       *type = adap->ch_thermal.trip_type;
+       return 0;
+}
+
+static int cxgb4_thermal_get_trip_temp(struct thermal_zone_device *tzdev,
+                                      int trip, int *temp)
+{
+       struct adapter *adap = tzdev->devdata;
+
+       if (!adap->ch_thermal.trip_temp)
+               return -EINVAL;
+
+       *temp = adap->ch_thermal.trip_temp;
+       return 0;
+}
+
+static struct thermal_zone_device_ops cxgb4_thermal_ops = {
+       .get_temp = cxgb4_thermal_get_temp,
+       .get_trip_type = cxgb4_thermal_get_trip_type,
+       .get_trip_temp = cxgb4_thermal_get_trip_temp,
+};
+
+int cxgb4_thermal_init(struct adapter *adap)
+{
+       struct ch_thermal *ch_thermal = &adap->ch_thermal;
+       int num_trip = CXGB4_NUM_TRIPS;
+       u32 param, val;
+       int ret;
+
+       /* on older firmwares we may not get the trip temperature,
+        * set the num of trips to 0.
+        */
+       param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
+                FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
+                FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_MAXTMPTHRESH));
+
+       ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
+                             &param, &val);
+       if (ret < 0) {
+               num_trip = 0; /* could not get trip temperature */
+       } else {
+               ch_thermal->trip_temp = val * 1000;
+               ch_thermal->trip_type = THERMAL_TRIP_CRITICAL;
+       }
+
+       ch_thermal->tzdev = thermal_zone_device_register("cxgb4", num_trip,
+                                                        0, adap,
+                                                        &cxgb4_thermal_ops,
+                                                        NULL, 0, 0);
+       if (IS_ERR(ch_thermal->tzdev)) {
+               ret = PTR_ERR(ch_thermal->tzdev);
+               dev_err(adap->pdev_dev, "Failed to register thermal zone\n");
+               ch_thermal->tzdev = NULL;
+               return ret;
+       }
+       return 0;
+}
+
+int cxgb4_thermal_remove(struct adapter *adap)
+{
+       if (adap->ch_thermal.tzdev)
+               thermal_zone_device_unregister(adap->ch_thermal.tzdev);
+       return 0;
+}
index 6d2bc8789223e7e423e9b2742c0b327bef2d5770..57584ab32043bd27e4de2fb1d56d88e00944163d 100644 (file)
@@ -1332,6 +1332,7 @@ enum fw_params_param_dev_phyfw {
 enum fw_params_param_dev_diag {
        FW_PARAM_DEV_DIAG_TMP           = 0x00,
        FW_PARAM_DEV_DIAG_VDD           = 0x01,
+       FW_PARAM_DEV_DIAG_MAXTMPTHRESH  = 0x02,
 };
 
 enum fw_params_param_dev_fwcache {