fp@2685: /* Intel(R) Gigabit Ethernet Linux driver
fp@2685: * Copyright(c) 2007-2014 Intel Corporation.
fp@2685: *
fp@2685: * This program is free software; you can redistribute it and/or modify it
fp@2685: * under the terms and conditions of the GNU General Public License,
fp@2685: * version 2, as published by the Free Software Foundation.
fp@2685: *
fp@2685: * This program is distributed in the hope it will be useful, but WITHOUT
fp@2685: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fp@2685: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
fp@2685: * more details.
fp@2685: *
fp@2685: * You should have received a copy of the GNU General Public License along with
fp@2685: * this program; if not, see .
fp@2685: *
fp@2685: * The full GNU General Public License is included in this distribution in
fp@2685: * the file called "COPYING".
fp@2685: *
fp@2685: * Contact Information:
fp@2685: * e1000-devel Mailing List
fp@2685: * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
fp@2685: */
fp@2685:
fp@2685: #include "igb.h"
fp@2685: #include "e1000_82575.h"
fp@2685: #include "e1000_hw.h"
fp@2685:
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685: #include
fp@2685:
fp@2685: #ifdef CONFIG_IGB_HWMON
fp@2685: static struct i2c_board_info i350_sensor_info = {
fp@2685: I2C_BOARD_INFO("i350bb", (0Xf8 >> 1)),
fp@2685: };
fp@2685:
fp@2685: /* hwmon callback functions */
fp@2685: static ssize_t igb_hwmon_show_location(struct device *dev,
fp@2685: struct device_attribute *attr,
fp@2685: char *buf)
fp@2685: {
fp@2685: struct hwmon_attr *igb_attr = container_of(attr, struct hwmon_attr,
fp@2685: dev_attr);
fp@2685: return sprintf(buf, "loc%u\n",
fp@2685: igb_attr->sensor->location);
fp@2685: }
fp@2685:
fp@2685: static ssize_t igb_hwmon_show_temp(struct device *dev,
fp@2685: struct device_attribute *attr,
fp@2685: char *buf)
fp@2685: {
fp@2685: struct hwmon_attr *igb_attr = container_of(attr, struct hwmon_attr,
fp@2685: dev_attr);
fp@2685: unsigned int value;
fp@2685:
fp@2685: /* reset the temp field */
fp@2685: igb_attr->hw->mac.ops.get_thermal_sensor_data(igb_attr->hw);
fp@2685:
fp@2685: value = igb_attr->sensor->temp;
fp@2685:
fp@2685: /* display millidegree */
fp@2685: value *= 1000;
fp@2685:
fp@2685: return sprintf(buf, "%u\n", value);
fp@2685: }
fp@2685:
fp@2685: static ssize_t igb_hwmon_show_cautionthresh(struct device *dev,
fp@2685: struct device_attribute *attr,
fp@2685: char *buf)
fp@2685: {
fp@2685: struct hwmon_attr *igb_attr = container_of(attr, struct hwmon_attr,
fp@2685: dev_attr);
fp@2685: unsigned int value = igb_attr->sensor->caution_thresh;
fp@2685:
fp@2685: /* display millidegree */
fp@2685: value *= 1000;
fp@2685:
fp@2685: return sprintf(buf, "%u\n", value);
fp@2685: }
fp@2685:
fp@2685: static ssize_t igb_hwmon_show_maxopthresh(struct device *dev,
fp@2685: struct device_attribute *attr,
fp@2685: char *buf)
fp@2685: {
fp@2685: struct hwmon_attr *igb_attr = container_of(attr, struct hwmon_attr,
fp@2685: dev_attr);
fp@2685: unsigned int value = igb_attr->sensor->max_op_thresh;
fp@2685:
fp@2685: /* display millidegree */
fp@2685: value *= 1000;
fp@2685:
fp@2685: return sprintf(buf, "%u\n", value);
fp@2685: }
fp@2685:
fp@2685: /* igb_add_hwmon_attr - Create hwmon attr table for a hwmon sysfs file.
fp@2685: * @ adapter: pointer to the adapter structure
fp@2685: * @ offset: offset in the eeprom sensor data table
fp@2685: * @ type: type of sensor data to display
fp@2685: *
fp@2685: * For each file we want in hwmon's sysfs interface we need a device_attribute
fp@2685: * This is included in our hwmon_attr struct that contains the references to
fp@2685: * the data structures we need to get the data to display.
fp@2685: */
fp@2685: static int igb_add_hwmon_attr(struct igb_adapter *adapter,
fp@2685: unsigned int offset, int type)
fp@2685: {
fp@2685: int rc;
fp@2685: unsigned int n_attr;
fp@2685: struct hwmon_attr *igb_attr;
fp@2685:
fp@2685: n_attr = adapter->igb_hwmon_buff->n_hwmon;
fp@2685: igb_attr = &adapter->igb_hwmon_buff->hwmon_list[n_attr];
fp@2685:
fp@2685: switch (type) {
fp@2685: case IGB_HWMON_TYPE_LOC:
fp@2685: igb_attr->dev_attr.show = igb_hwmon_show_location;
fp@2685: snprintf(igb_attr->name, sizeof(igb_attr->name),
fp@2685: "temp%u_label", offset + 1);
fp@2685: break;
fp@2685: case IGB_HWMON_TYPE_TEMP:
fp@2685: igb_attr->dev_attr.show = igb_hwmon_show_temp;
fp@2685: snprintf(igb_attr->name, sizeof(igb_attr->name),
fp@2685: "temp%u_input", offset + 1);
fp@2685: break;
fp@2685: case IGB_HWMON_TYPE_CAUTION:
fp@2685: igb_attr->dev_attr.show = igb_hwmon_show_cautionthresh;
fp@2685: snprintf(igb_attr->name, sizeof(igb_attr->name),
fp@2685: "temp%u_max", offset + 1);
fp@2685: break;
fp@2685: case IGB_HWMON_TYPE_MAX:
fp@2685: igb_attr->dev_attr.show = igb_hwmon_show_maxopthresh;
fp@2685: snprintf(igb_attr->name, sizeof(igb_attr->name),
fp@2685: "temp%u_crit", offset + 1);
fp@2685: break;
fp@2685: default:
fp@2685: rc = -EPERM;
fp@2685: return rc;
fp@2685: }
fp@2685:
fp@2685: /* These always the same regardless of type */
fp@2685: igb_attr->sensor =
fp@2685: &adapter->hw.mac.thermal_sensor_data.sensor[offset];
fp@2685: igb_attr->hw = &adapter->hw;
fp@2685: igb_attr->dev_attr.store = NULL;
fp@2685: igb_attr->dev_attr.attr.mode = S_IRUGO;
fp@2685: igb_attr->dev_attr.attr.name = igb_attr->name;
fp@2685: sysfs_attr_init(&igb_attr->dev_attr.attr);
fp@2685:
fp@2685: adapter->igb_hwmon_buff->attrs[n_attr] = &igb_attr->dev_attr.attr;
fp@2685:
fp@2685: ++adapter->igb_hwmon_buff->n_hwmon;
fp@2685:
fp@2685: return 0;
fp@2685: }
fp@2685:
fp@2685: static void igb_sysfs_del_adapter(struct igb_adapter *adapter)
fp@2685: {
fp@2685: }
fp@2685:
fp@2685: /* called from igb_main.c */
fp@2685: void igb_sysfs_exit(struct igb_adapter *adapter)
fp@2685: {
fp@2685: igb_sysfs_del_adapter(adapter);
fp@2685: }
fp@2685:
fp@2685: /* called from igb_main.c */
fp@2685: int igb_sysfs_init(struct igb_adapter *adapter)
fp@2685: {
fp@2685: struct hwmon_buff *igb_hwmon;
fp@2685: struct i2c_client *client;
fp@2685: struct device *hwmon_dev;
fp@2685: unsigned int i;
fp@2685: int rc = 0;
fp@2685:
fp@2685: /* If this method isn't defined we don't support thermals */
fp@2685: if (adapter->hw.mac.ops.init_thermal_sensor_thresh == NULL)
fp@2685: goto exit;
fp@2685:
fp@2685: /* Don't create thermal hwmon interface if no sensors present */
fp@2685: rc = (adapter->hw.mac.ops.init_thermal_sensor_thresh(&adapter->hw));
fp@2685: if (rc)
fp@2685: goto exit;
fp@2685:
fp@2685: igb_hwmon = devm_kzalloc(&adapter->pdev->dev, sizeof(*igb_hwmon),
fp@2685: GFP_KERNEL);
fp@2685: if (!igb_hwmon) {
fp@2685: rc = -ENOMEM;
fp@2685: goto exit;
fp@2685: }
fp@2685: adapter->igb_hwmon_buff = igb_hwmon;
fp@2685:
fp@2685: for (i = 0; i < E1000_MAX_SENSORS; i++) {
fp@2685:
fp@2685: /* Only create hwmon sysfs entries for sensors that have
fp@2685: * meaningful data.
fp@2685: */
fp@2685: if (adapter->hw.mac.thermal_sensor_data.sensor[i].location == 0)
fp@2685: continue;
fp@2685:
fp@2685: /* Bail if any hwmon attr struct fails to initialize */
fp@2685: rc = igb_add_hwmon_attr(adapter, i, IGB_HWMON_TYPE_CAUTION);
fp@2685: if (rc)
fp@2685: goto exit;
fp@2685: rc = igb_add_hwmon_attr(adapter, i, IGB_HWMON_TYPE_LOC);
fp@2685: if (rc)
fp@2685: goto exit;
fp@2685: rc = igb_add_hwmon_attr(adapter, i, IGB_HWMON_TYPE_TEMP);
fp@2685: if (rc)
fp@2685: goto exit;
fp@2685: rc = igb_add_hwmon_attr(adapter, i, IGB_HWMON_TYPE_MAX);
fp@2685: if (rc)
fp@2685: goto exit;
fp@2685: }
fp@2685:
fp@2685: /* init i2c_client */
fp@2685: client = i2c_new_device(&adapter->i2c_adap, &i350_sensor_info);
fp@2685: if (client == NULL) {
fp@2685: dev_info(&adapter->pdev->dev,
fp@2685: "Failed to create new i2c device.\n");
fp@2685: rc = -ENODEV;
fp@2685: goto exit;
fp@2685: }
fp@2685: adapter->i2c_client = client;
fp@2685:
fp@2685: igb_hwmon->groups[0] = &igb_hwmon->group;
fp@2685: igb_hwmon->group.attrs = igb_hwmon->attrs;
fp@2685:
fp@2685: hwmon_dev = devm_hwmon_device_register_with_groups(&adapter->pdev->dev,
fp@2685: client->name,
fp@2685: igb_hwmon,
fp@2685: igb_hwmon->groups);
fp@2685: if (IS_ERR(hwmon_dev)) {
fp@2685: rc = PTR_ERR(hwmon_dev);
fp@2685: goto err;
fp@2685: }
fp@2685:
fp@2685: goto exit;
fp@2685:
fp@2685: err:
fp@2685: igb_sysfs_del_adapter(adapter);
fp@2685: exit:
fp@2685: return rc;
fp@2685: }
fp@2685: #endif