10 #include <linux/bitops.h>
11 #include <linux/slab.h>
13 #include <linux/stat.h>
32 #define SENSOR(name, label, hwmon_type, port) \
33 [MC_CMD_SENSOR_##name] = { label, hwmon_type, port }
52 static const char *
const sensor_status_names[] = {
71 name = efx_mcdi_sensor_type[
type].label;
73 name =
"No sensor name available";
75 state_txt = sensor_status_names[
state];
78 "Sensor %d (%s) reports condition '%s' for raw value %d\n",
79 type, name, state_txt, value);
82 #ifdef CONFIG_SFC_MCDI_MON
84 struct efx_mcdi_mon_attribute {
88 unsigned int limit_value;
92 static int efx_mcdi_mon_update(
struct efx_nic *efx)
99 hwmon->
dma_buf.dma_addr & 0xffffffff);
104 inbuf,
sizeof(inbuf),
NULL, 0,
NULL);
114 return sprintf(buf,
"%s\n", KBUILD_MODNAME);
117 static int efx_mcdi_mon_get_entry(
struct device *
dev,
unsigned int index,
132 rc = efx_mcdi_mon_update(efx);
146 struct efx_mcdi_mon_attribute *mon_attr =
152 rc = efx_mcdi_mon_get_entry(dev, mon_attr->index, &entry);
156 value =
EFX_DWORD_FIELD(entry, MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_VALUE);
159 if (efx_mcdi_sensor_type[mon_attr->type].hwmon_type ==
EFX_HWMON_TEMP)
162 return sprintf(buf,
"%u\n", value);
169 struct efx_mcdi_mon_attribute *mon_attr =
173 value = mon_attr->limit_value;
176 if (efx_mcdi_sensor_type[mon_attr->type].hwmon_type ==
EFX_HWMON_TEMP)
179 return sprintf(buf,
"%u\n", value);
186 struct efx_mcdi_mon_attribute *mon_attr =
192 rc = efx_mcdi_mon_get_entry(dev, mon_attr->index, &entry);
196 state =
EFX_DWORD_FIELD(entry, MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_STATE);
204 struct efx_mcdi_mon_attribute *mon_attr =
207 efx_mcdi_sensor_type[mon_attr->type].label);
211 efx_mcdi_mon_add_attr(
struct efx_nic *efx,
const char *
name,
214 unsigned int index,
unsigned int type,
215 unsigned int limit_value)
218 struct efx_mcdi_mon_attribute *attr = &hwmon->
attrs[hwmon->
n_attrs];
221 strlcpy(attr->name, name,
sizeof(attr->name));
224 attr->limit_value = limit_value;
226 attr->dev_attr.attr.name = attr->name;
227 attr->dev_attr.attr.mode =
S_IRUGO;
228 attr->dev_attr.show = reader;
235 int efx_mcdi_mon_probe(
struct efx_nic *efx)
238 unsigned int n_attrs, n_temp = 0, n_cool = 0, n_in = 0;
248 outbuf,
sizeof(outbuf), &outlen);
257 mask =
MCDI_DWORD(outbuf, SENSOR_INFO_OUT_MASK);
271 efx_mcdi_mon_update(efx);
285 if (IS_ERR(hwmon->
device)) {
286 rc = PTR_ERR(hwmon->
device);
290 rc = efx_mcdi_mon_add_attr(efx,
"name", efx_mcdi_mon_show_name, 0, 0, 0);
294 for (i = 0, type = -1; ; i++) {
295 const char *hwmon_prefix;
296 unsigned hwmon_index;
301 while (!(mask & (1 << type))) {
309 efx_mcdi_sensor_type[type].
port >= 0 &&
310 efx_mcdi_sensor_type[type].
port != efx_port_num(efx))
313 switch (efx_mcdi_sensor_type[type].
hwmon_type) {
315 hwmon_prefix =
"temp";
316 hwmon_index = ++n_temp;
323 hwmon_prefix =
"fan";
324 hwmon_index = ++n_cool;
328 hwmon_index = n_in++;
333 SENSOR_INFO_ENTRY, i, MIN1);
335 SENSOR_INFO_ENTRY, i, MAX1);
337 SENSOR_INFO_ENTRY, i, MIN2);
339 SENSOR_INFO_ENTRY, i, MAX2);
342 snprintf(name,
sizeof(name),
"%s%u_input",
343 hwmon_prefix, hwmon_index);
344 rc = efx_mcdi_mon_add_attr(
345 efx, name, efx_mcdi_mon_show_value, i, type, 0);
349 snprintf(name,
sizeof(name),
"%s%u_min",
350 hwmon_prefix, hwmon_index);
351 rc = efx_mcdi_mon_add_attr(
352 efx, name, efx_mcdi_mon_show_limit,
357 snprintf(name,
sizeof(name),
"%s%u_max",
358 hwmon_prefix, hwmon_index);
359 rc = efx_mcdi_mon_add_attr(
360 efx, name, efx_mcdi_mon_show_limit,
369 snprintf(name,
sizeof(name),
"%s%u_crit",
370 hwmon_prefix, hwmon_index);
371 rc = efx_mcdi_mon_add_attr(
372 efx, name, efx_mcdi_mon_show_limit,
379 snprintf(name,
sizeof(name),
"%s%u_alarm",
380 hwmon_prefix, hwmon_index);
381 rc = efx_mcdi_mon_add_attr(
382 efx, name, efx_mcdi_mon_show_alarm, i, type, 0);
386 if (efx_mcdi_sensor_type[type].
label) {
387 snprintf(name,
sizeof(name),
"%s%u_label",
388 hwmon_prefix, hwmon_index);
389 rc = efx_mcdi_mon_add_attr(
390 efx, name, efx_mcdi_mon_show_label, i, type, 0);
397 efx_mcdi_mon_remove(efx);
401 void efx_mcdi_mon_remove(
struct efx_nic *efx)
407 for (i = 0; i < hwmon->
n_attrs; i++)
409 &hwmon->
attrs[i].dev_attr);