Commit 95978931 authored by Su Hui's avatar Su Hui Committed by Jakub Kicinski
Browse files

eth: fbnic: Revert "eth: fbnic: Add hardware monitoring support via HWMON interface"



There is a garbage value problem in fbnic_mac_get_sensor_asic(). 'fw_cmpl'
is uninitialized which makes 'sensor' and '*val' to be stored garbage
value. Revert commit d85ebade ("eth: fbnic: Add hardware monitoring
support via HWMON interface") to avoid this problem.

Fixes: d85ebade ("eth: fbnic: Add hardware monitoring support via HWMON interface")
Signed-off-by: default avatarSu Hui <suhui@nfschina.com>
Suggested-by: default avatarJakub Kicinski <kuba@kernel.org>
Suggested-by: default avatarMichal Swiatkowski <michal.swiatkowski@linux.intel.com>
Link: https://patch.msgid.link/20250106023647.47756-1-suhui@nfschina.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent fd48f071
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@ fbnic-y := fbnic_csr.o \
	   fbnic_ethtool.o \
	   fbnic_fw.o \
	   fbnic_hw_stats.o \
	   fbnic_hwmon.o \
	   fbnic_irq.o \
	   fbnic_mac.o \
	   fbnic_netdev.o \
+0 −5
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ struct fbnic_dev {
	struct device *dev;
	struct net_device *netdev;
	struct dentry *dbg_fbd;
	struct device *hwmon;

	u32 __iomem *uc_addr0;
	u32 __iomem *uc_addr4;
@@ -33,7 +32,6 @@ struct fbnic_dev {

	struct fbnic_fw_mbx mbx[FBNIC_IPC_MBX_INDICES];
	struct fbnic_fw_cap fw_cap;
	struct fbnic_fw_completion *cmpl_data;
	/* Lock protecting Tx Mailbox queue to prevent possible races */
	spinlock_t fw_tx_lock;

@@ -142,9 +140,6 @@ void fbnic_devlink_unregister(struct fbnic_dev *fbd);
int fbnic_fw_enable_mbx(struct fbnic_dev *fbd);
void fbnic_fw_disable_mbx(struct fbnic_dev *fbd);

void fbnic_hwmon_register(struct fbnic_dev *fbd);
void fbnic_hwmon_unregister(struct fbnic_dev *fbd);

int fbnic_pcs_irq_enable(struct fbnic_dev *fbd);
void fbnic_pcs_irq_disable(struct fbnic_dev *fbd);

+0 −7
Original line number Diff line number Diff line
@@ -44,13 +44,6 @@ struct fbnic_fw_cap {
	u8	link_fec;
};

struct fbnic_fw_completion {
	struct {
		s32 millivolts;
		s32 millidegrees;
	} tsene;
};

void fbnic_mbx_init(struct fbnic_dev *fbd);
void fbnic_mbx_clean(struct fbnic_dev *fbd);
void fbnic_mbx_poll(struct fbnic_dev *fbd);
+0 −81
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) Meta Platforms, Inc. and affiliates. */

#include <linux/hwmon.h>

#include "fbnic.h"
#include "fbnic_mac.h"

static int fbnic_hwmon_sensor_id(enum hwmon_sensor_types type)
{
	if (type == hwmon_temp)
		return FBNIC_SENSOR_TEMP;
	if (type == hwmon_in)
		return FBNIC_SENSOR_VOLTAGE;

	return -EOPNOTSUPP;
}

static umode_t fbnic_hwmon_is_visible(const void *drvdata,
				      enum hwmon_sensor_types type,
				      u32 attr, int channel)
{
	if (type == hwmon_temp && attr == hwmon_temp_input)
		return 0444;
	if (type == hwmon_in && attr == hwmon_in_input)
		return 0444;

	return 0;
}

static int fbnic_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
			    u32 attr, int channel, long *val)
{
	struct fbnic_dev *fbd = dev_get_drvdata(dev);
	const struct fbnic_mac *mac = fbd->mac;
	int id;

	id = fbnic_hwmon_sensor_id(type);
	return id < 0 ? id : mac->get_sensor(fbd, id, val);
}

static const struct hwmon_ops fbnic_hwmon_ops = {
	.is_visible = fbnic_hwmon_is_visible,
	.read = fbnic_hwmon_read,
};

static const struct hwmon_channel_info *fbnic_hwmon_info[] = {
	HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),
	HWMON_CHANNEL_INFO(in, HWMON_I_INPUT),
	NULL
};

static const struct hwmon_chip_info fbnic_chip_info = {
	.ops = &fbnic_hwmon_ops,
	.info = fbnic_hwmon_info,
};

void fbnic_hwmon_register(struct fbnic_dev *fbd)
{
	if (!IS_REACHABLE(CONFIG_HWMON))
		return;

	fbd->hwmon = hwmon_device_register_with_info(fbd->dev, "fbnic",
						     fbd, &fbnic_chip_info,
						     NULL);
	if (IS_ERR(fbd->hwmon)) {
		dev_notice(fbd->dev,
			   "Failed to register hwmon device %pe\n",
			fbd->hwmon);
		fbd->hwmon = NULL;
	}
}

void fbnic_hwmon_unregister(struct fbnic_dev *fbd)
{
	if (!IS_REACHABLE(CONFIG_HWMON) || !fbd->hwmon)
		return;

	hwmon_device_unregister(fbd->hwmon);
	fbd->hwmon = NULL;
}
+0 −22
Original line number Diff line number Diff line
@@ -686,27 +686,6 @@ fbnic_mac_get_eth_mac_stats(struct fbnic_dev *fbd, bool reset,
			    MAC_STAT_TX_BROADCAST);
}

static int fbnic_mac_get_sensor_asic(struct fbnic_dev *fbd, int id, long *val)
{
	struct fbnic_fw_completion fw_cmpl;
	s32 *sensor;

	switch (id) {
	case FBNIC_SENSOR_TEMP:
		sensor = &fw_cmpl.tsene.millidegrees;
		break;
	case FBNIC_SENSOR_VOLTAGE:
		sensor = &fw_cmpl.tsene.millivolts;
		break;
	default:
		return -EINVAL;
	}

	*val = *sensor;

	return 0;
}

static const struct fbnic_mac fbnic_mac_asic = {
	.init_regs = fbnic_mac_init_regs,
	.pcs_enable = fbnic_pcs_enable_asic,
@@ -716,7 +695,6 @@ static const struct fbnic_mac fbnic_mac_asic = {
	.get_eth_mac_stats = fbnic_mac_get_eth_mac_stats,
	.link_down = fbnic_mac_link_down_asic,
	.link_up = fbnic_mac_link_up_asic,
	.get_sensor = fbnic_mac_get_sensor_asic,
};

/**
Loading