[PATCH net-next 1/6] eth: fbnic: move sensor read logic out of fbnic_mac
From: Zinc Lim <hidden>
Date: 2026-07-21 22:15:47
Also in:
linux-hwmon, lkml
Subsystem:
meta ethernet drivers, networking drivers, the rest · Maintainers:
Alexander Duyck, Jakub Kicinski, Andrew Lunn, "David S. Miller", Eric Dumazet, Paolo Abeni, Linus Torvalds
The sensor read lived behind the fbnic_mac get_sensor op, but it is only ever used by the hwmon subsystem. Move the read into fbnic_hwmon.c and call it directly there, closer to where it is used, and drop the now-unused get_sensor op from struct fbnic_mac. No functional change. Signed-off-by: Zinc Lim <redacted> --- drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c | 56 ++++++++++++++++++- drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 55 ------------------ drivers/net/ethernet/meta/fbnic/fbnic_mac.h | 2 - 3 files changed, 54 insertions(+), 59 deletions(-)
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
index def8598aceec..6c8c66ab86c1 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_hwmon.c@@ -28,15 +28,67 @@ static umode_t fbnic_hwmon_is_visible(const void *drvdata, return 0; } +static int fbnic_hwmon_sensor_read(struct fbnic_dev *fbd, int id, long *val) +{ + struct fbnic_fw_completion *fw_cmpl; + int err = 0; + s32 *sensor; + + fw_cmpl = fbnic_fw_alloc_cmpl(FBNIC_TLV_MSG_ID_TSENE_READ_RESP); + if (!fw_cmpl) + return -ENOMEM; + + switch (id) { + case FBNIC_SENSOR_TEMP: + sensor = &fw_cmpl->u.tsene.millidegrees; + break; + case FBNIC_SENSOR_VOLTAGE: + sensor = &fw_cmpl->u.tsene.millivolts; + break; + default: + err = -EINVAL; + goto exit_free; + } + + err = fbnic_fw_xmit_tsene_read_msg(fbd, fw_cmpl); + if (err) { + dev_err(fbd->dev, + "Failed to transmit TSENE read msg, err %d\n", + err); + goto exit_free; + } + + if (!wait_for_completion_timeout(&fw_cmpl->done, 10 * HZ)) { + dev_err(fbd->dev, "Timed out waiting for TSENE read\n"); + err = -ETIMEDOUT; + goto exit_cleanup; + } + + /* Handle error returned by firmware */ + if (fw_cmpl->result) { + err = fw_cmpl->result; + dev_err(fbd->dev, "%s: Firmware returned error %d\n", + __func__, err); + goto exit_cleanup; + } + + *val = *sensor; +exit_cleanup: + fbnic_mbx_clear_cmpl(fbd, fw_cmpl); +exit_free: + fbnic_fw_put_cmpl(fw_cmpl); + + return err; +} + 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); + return id < 0 ? id : fbnic_hwmon_sensor_read(fbd, id, val); } static const struct hwmon_ops fbnic_hwmon_ops = {
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
index 53b7a938b4c2..fba2e2efaeb8 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c@@ -899,60 +899,6 @@ fbnic_mac_get_rmon_stats(struct fbnic_dev *fbd, bool reset, TMI_STAT_TX_PACKET_9217_MAX_BYTES); } -static int fbnic_mac_get_sensor_asic(struct fbnic_dev *fbd, int id, - long *val) -{ - struct fbnic_fw_completion *fw_cmpl; - int err = 0; - s32 *sensor; - - fw_cmpl = fbnic_fw_alloc_cmpl(FBNIC_TLV_MSG_ID_TSENE_READ_RESP); - if (!fw_cmpl) - return -ENOMEM; - - switch (id) { - case FBNIC_SENSOR_TEMP: - sensor = &fw_cmpl->u.tsene.millidegrees; - break; - case FBNIC_SENSOR_VOLTAGE: - sensor = &fw_cmpl->u.tsene.millivolts; - break; - default: - err = -EINVAL; - goto exit_free; - } - - err = fbnic_fw_xmit_tsene_read_msg(fbd, fw_cmpl); - if (err) { - dev_err(fbd->dev, - "Failed to transmit TSENE read msg, err %d\n", - err); - goto exit_free; - } - - if (!wait_for_completion_timeout(&fw_cmpl->done, 10 * HZ)) { - dev_err(fbd->dev, "Timed out waiting for TSENE read\n"); - err = -ETIMEDOUT; - goto exit_cleanup; - } - - /* Handle error returned by firmware */ - if (fw_cmpl->result) { - err = fw_cmpl->result; - dev_err(fbd->dev, "%s: Firmware returned error %d\n", - __func__, err); - goto exit_cleanup; - } - - *val = *sensor; -exit_cleanup: - fbnic_mbx_clear_cmpl(fbd, fw_cmpl); -exit_free: - fbnic_fw_put_cmpl(fw_cmpl); - - return err; -} - static const struct fbnic_mac fbnic_mac_asic = { .init_regs = fbnic_mac_init_regs, .get_link = fbnic_mac_get_link,
@@ -966,7 +912,6 @@ static const struct fbnic_mac fbnic_mac_asic = { .get_rmon_stats = fbnic_mac_get_rmon_stats, .link_down = fbnic_mac_link_down_asic, .link_up = fbnic_mac_link_up_asic, - .get_sensor = fbnic_mac_get_sensor_asic, }; /**
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_mac.h b/drivers/net/ethernet/meta/fbnic/fbnic_mac.h
index 10f30e0e8f69..bde2daa65645 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_mac.h
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_mac.h@@ -137,8 +137,6 @@ struct fbnic_mac { void (*link_down)(struct fbnic_dev *fbd); void (*link_up)(struct fbnic_dev *fbd, bool tx_pause, bool rx_pause); - - int (*get_sensor)(struct fbnic_dev *fbd, int id, long *val); }; int fbnic_mac_init(struct fbnic_dev *fbd);
--
2.53.0-Meta