mcdi_mon.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. /****************************************************************************
  2. * Driver for Solarflare network controllers and boards
  3. * Copyright 2011-2013 Solarflare Communications Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation, incorporated herein by reference.
  8. */
  9. #include <linux/bitops.h>
  10. #include <linux/slab.h>
  11. #include <linux/hwmon.h>
  12. #include <linux/stat.h>
  13. #include "net_driver.h"
  14. #include "mcdi.h"
  15. #include "mcdi_pcol.h"
  16. #include "nic.h"
  17. enum efx_hwmon_type {
  18. EFX_HWMON_UNKNOWN,
  19. EFX_HWMON_TEMP, /* temperature */
  20. EFX_HWMON_COOL, /* cooling device, probably a heatsink */
  21. EFX_HWMON_IN, /* voltage */
  22. EFX_HWMON_CURR, /* current */
  23. EFX_HWMON_POWER, /* power */
  24. EFX_HWMON_TYPES_COUNT
  25. };
  26. static const char *const efx_hwmon_unit[EFX_HWMON_TYPES_COUNT] = {
  27. [EFX_HWMON_TEMP] = " degC",
  28. [EFX_HWMON_COOL] = " rpm", /* though nonsense for a heatsink */
  29. [EFX_HWMON_IN] = " mV",
  30. [EFX_HWMON_CURR] = " mA",
  31. [EFX_HWMON_POWER] = " W",
  32. };
  33. static const struct {
  34. const char *label;
  35. enum efx_hwmon_type hwmon_type;
  36. int port;
  37. } efx_mcdi_sensor_type[] = {
  38. #define SENSOR(name, label, hwmon_type, port) \
  39. [MC_CMD_SENSOR_##name] = { label, EFX_HWMON_ ## hwmon_type, port }
  40. SENSOR(CONTROLLER_TEMP, "Controller board temp.", TEMP, -1),
  41. SENSOR(PHY_COMMON_TEMP, "PHY temp.", TEMP, -1),
  42. SENSOR(CONTROLLER_COOLING, "Controller heat sink", COOL, -1),
  43. SENSOR(PHY0_TEMP, "PHY temp.", TEMP, 0),
  44. SENSOR(PHY0_COOLING, "PHY heat sink", COOL, 0),
  45. SENSOR(PHY1_TEMP, "PHY temp.", TEMP, 1),
  46. SENSOR(PHY1_COOLING, "PHY heat sink", COOL, 1),
  47. SENSOR(IN_1V0, "1.0V supply", IN, -1),
  48. SENSOR(IN_1V2, "1.2V supply", IN, -1),
  49. SENSOR(IN_1V8, "1.8V supply", IN, -1),
  50. SENSOR(IN_2V5, "2.5V supply", IN, -1),
  51. SENSOR(IN_3V3, "3.3V supply", IN, -1),
  52. SENSOR(IN_12V0, "12.0V supply", IN, -1),
  53. SENSOR(IN_1V2A, "1.2V analogue supply", IN, -1),
  54. SENSOR(IN_VREF, "Ref. voltage", IN, -1),
  55. SENSOR(OUT_VAOE, "AOE FPGA supply", IN, -1),
  56. SENSOR(AOE_TEMP, "AOE FPGA temp.", TEMP, -1),
  57. SENSOR(PSU_AOE_TEMP, "AOE regulator temp.", TEMP, -1),
  58. SENSOR(PSU_TEMP, "Controller regulator temp.",
  59. TEMP, -1),
  60. SENSOR(FAN_0, "Fan 0", COOL, -1),
  61. SENSOR(FAN_1, "Fan 1", COOL, -1),
  62. SENSOR(FAN_2, "Fan 2", COOL, -1),
  63. SENSOR(FAN_3, "Fan 3", COOL, -1),
  64. SENSOR(FAN_4, "Fan 4", COOL, -1),
  65. SENSOR(IN_VAOE, "AOE input supply", IN, -1),
  66. SENSOR(OUT_IAOE, "AOE output current", CURR, -1),
  67. SENSOR(IN_IAOE, "AOE input current", CURR, -1),
  68. SENSOR(NIC_POWER, "Board power use", POWER, -1),
  69. SENSOR(IN_0V9, "0.9V supply", IN, -1),
  70. SENSOR(IN_I0V9, "0.9V supply current", CURR, -1),
  71. SENSOR(IN_I1V2, "1.2V supply current", CURR, -1),
  72. SENSOR(IN_0V9_ADC, "0.9V supply (ext. ADC)", IN, -1),
  73. SENSOR(CONTROLLER_2_TEMP, "Controller board temp. 2", TEMP, -1),
  74. SENSOR(VREG_INTERNAL_TEMP, "Regulator die temp.", TEMP, -1),
  75. SENSOR(VREG_0V9_TEMP, "0.9V regulator temp.", TEMP, -1),
  76. SENSOR(VREG_1V2_TEMP, "1.2V regulator temp.", TEMP, -1),
  77. SENSOR(CONTROLLER_VPTAT,
  78. "Controller PTAT voltage (int. ADC)", IN, -1),
  79. SENSOR(CONTROLLER_INTERNAL_TEMP,
  80. "Controller die temp. (int. ADC)", TEMP, -1),
  81. SENSOR(CONTROLLER_VPTAT_EXTADC,
  82. "Controller PTAT voltage (ext. ADC)", IN, -1),
  83. SENSOR(CONTROLLER_INTERNAL_TEMP_EXTADC,
  84. "Controller die temp. (ext. ADC)", TEMP, -1),
  85. SENSOR(AMBIENT_TEMP, "Ambient temp.", TEMP, -1),
  86. SENSOR(AIRFLOW, "Air flow raw", IN, -1),
  87. SENSOR(VDD08D_VSS08D_CSR, "0.9V die (int. ADC)", IN, -1),
  88. SENSOR(VDD08D_VSS08D_CSR_EXTADC, "0.9V die (ext. ADC)", IN, -1),
  89. SENSOR(HOTPOINT_TEMP, "Controller board temp. (hotpoint)", TEMP, -1),
  90. #undef SENSOR
  91. };
  92. static const char *const sensor_status_names[] = {
  93. [MC_CMD_SENSOR_STATE_OK] = "OK",
  94. [MC_CMD_SENSOR_STATE_WARNING] = "Warning",
  95. [MC_CMD_SENSOR_STATE_FATAL] = "Fatal",
  96. [MC_CMD_SENSOR_STATE_BROKEN] = "Device failure",
  97. [MC_CMD_SENSOR_STATE_NO_READING] = "No reading",
  98. };
  99. void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev)
  100. {
  101. unsigned int type, state, value;
  102. enum efx_hwmon_type hwmon_type = EFX_HWMON_UNKNOWN;
  103. const char *name = NULL, *state_txt, *unit;
  104. type = EFX_QWORD_FIELD(*ev, MCDI_EVENT_SENSOREVT_MONITOR);
  105. state = EFX_QWORD_FIELD(*ev, MCDI_EVENT_SENSOREVT_STATE);
  106. value = EFX_QWORD_FIELD(*ev, MCDI_EVENT_SENSOREVT_VALUE);
  107. /* Deal gracefully with the board having more drivers than we
  108. * know about, but do not expect new sensor states. */
  109. if (type < ARRAY_SIZE(efx_mcdi_sensor_type)) {
  110. name = efx_mcdi_sensor_type[type].label;
  111. hwmon_type = efx_mcdi_sensor_type[type].hwmon_type;
  112. }
  113. if (!name)
  114. name = "No sensor name available";
  115. EFX_BUG_ON_PARANOID(state >= ARRAY_SIZE(sensor_status_names));
  116. state_txt = sensor_status_names[state];
  117. EFX_BUG_ON_PARANOID(hwmon_type >= EFX_HWMON_TYPES_COUNT);
  118. unit = efx_hwmon_unit[hwmon_type];
  119. if (!unit)
  120. unit = "";
  121. netif_err(efx, hw, efx->net_dev,
  122. "Sensor %d (%s) reports condition '%s' for value %d%s\n",
  123. type, name, state_txt, value, unit);
  124. }
  125. #ifdef CONFIG_SFC_MCDI_MON
  126. struct efx_mcdi_mon_attribute {
  127. struct device_attribute dev_attr;
  128. unsigned int index;
  129. unsigned int type;
  130. enum efx_hwmon_type hwmon_type;
  131. unsigned int limit_value;
  132. char name[12];
  133. };
  134. static int efx_mcdi_mon_update(struct efx_nic *efx)
  135. {
  136. struct efx_mcdi_mon *hwmon = efx_mcdi_mon(efx);
  137. MCDI_DECLARE_BUF(inbuf, MC_CMD_READ_SENSORS_EXT_IN_LEN);
  138. int rc;
  139. MCDI_SET_QWORD(inbuf, READ_SENSORS_EXT_IN_DMA_ADDR,
  140. hwmon->dma_buf.dma_addr);
  141. MCDI_SET_DWORD(inbuf, READ_SENSORS_EXT_IN_LENGTH, hwmon->dma_buf.len);
  142. rc = efx_mcdi_rpc(efx, MC_CMD_READ_SENSORS,
  143. inbuf, sizeof(inbuf), NULL, 0, NULL);
  144. if (rc == 0)
  145. hwmon->last_update = jiffies;
  146. return rc;
  147. }
  148. static int efx_mcdi_mon_get_entry(struct device *dev, unsigned int index,
  149. efx_dword_t *entry)
  150. {
  151. struct efx_nic *efx = dev_get_drvdata(dev->parent);
  152. struct efx_mcdi_mon *hwmon = efx_mcdi_mon(efx);
  153. int rc;
  154. BUILD_BUG_ON(MC_CMD_READ_SENSORS_OUT_LEN != 0);
  155. mutex_lock(&hwmon->update_lock);
  156. /* Use cached value if last update was < 1 s ago */
  157. if (time_before(jiffies, hwmon->last_update + HZ))
  158. rc = 0;
  159. else
  160. rc = efx_mcdi_mon_update(efx);
  161. /* Copy out the requested entry */
  162. *entry = ((efx_dword_t *)hwmon->dma_buf.addr)[index];
  163. mutex_unlock(&hwmon->update_lock);
  164. return rc;
  165. }
  166. static ssize_t efx_mcdi_mon_show_value(struct device *dev,
  167. struct device_attribute *attr,
  168. char *buf)
  169. {
  170. struct efx_mcdi_mon_attribute *mon_attr =
  171. container_of(attr, struct efx_mcdi_mon_attribute, dev_attr);
  172. efx_dword_t entry;
  173. unsigned int value, state;
  174. int rc;
  175. rc = efx_mcdi_mon_get_entry(dev, mon_attr->index, &entry);
  176. if (rc)
  177. return rc;
  178. state = EFX_DWORD_FIELD(entry, MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_STATE);
  179. if (state == MC_CMD_SENSOR_STATE_NO_READING)
  180. return -EBUSY;
  181. value = EFX_DWORD_FIELD(entry, MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_VALUE);
  182. switch (mon_attr->hwmon_type) {
  183. case EFX_HWMON_TEMP:
  184. /* Convert temperature from degrees to milli-degrees Celsius */
  185. value *= 1000;
  186. break;
  187. case EFX_HWMON_POWER:
  188. /* Convert power from watts to microwatts */
  189. value *= 1000000;
  190. break;
  191. default:
  192. /* No conversion needed */
  193. break;
  194. }
  195. return sprintf(buf, "%u\n", value);
  196. }
  197. static ssize_t efx_mcdi_mon_show_limit(struct device *dev,
  198. struct device_attribute *attr,
  199. char *buf)
  200. {
  201. struct efx_mcdi_mon_attribute *mon_attr =
  202. container_of(attr, struct efx_mcdi_mon_attribute, dev_attr);
  203. unsigned int value;
  204. value = mon_attr->limit_value;
  205. switch (mon_attr->hwmon_type) {
  206. case EFX_HWMON_TEMP:
  207. /* Convert temperature from degrees to milli-degrees Celsius */
  208. value *= 1000;
  209. break;
  210. case EFX_HWMON_POWER:
  211. /* Convert power from watts to microwatts */
  212. value *= 1000000;
  213. break;
  214. default:
  215. /* No conversion needed */
  216. break;
  217. }
  218. return sprintf(buf, "%u\n", value);
  219. }
  220. static ssize_t efx_mcdi_mon_show_alarm(struct device *dev,
  221. struct device_attribute *attr,
  222. char *buf)
  223. {
  224. struct efx_mcdi_mon_attribute *mon_attr =
  225. container_of(attr, struct efx_mcdi_mon_attribute, dev_attr);
  226. efx_dword_t entry;
  227. int state;
  228. int rc;
  229. rc = efx_mcdi_mon_get_entry(dev, mon_attr->index, &entry);
  230. if (rc)
  231. return rc;
  232. state = EFX_DWORD_FIELD(entry, MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_STATE);
  233. return sprintf(buf, "%d\n", state != MC_CMD_SENSOR_STATE_OK);
  234. }
  235. static ssize_t efx_mcdi_mon_show_label(struct device *dev,
  236. struct device_attribute *attr,
  237. char *buf)
  238. {
  239. struct efx_mcdi_mon_attribute *mon_attr =
  240. container_of(attr, struct efx_mcdi_mon_attribute, dev_attr);
  241. return sprintf(buf, "%s\n",
  242. efx_mcdi_sensor_type[mon_attr->type].label);
  243. }
  244. static void
  245. efx_mcdi_mon_add_attr(struct efx_nic *efx, const char *name,
  246. ssize_t (*reader)(struct device *,
  247. struct device_attribute *, char *),
  248. unsigned int index, unsigned int type,
  249. unsigned int limit_value)
  250. {
  251. struct efx_mcdi_mon *hwmon = efx_mcdi_mon(efx);
  252. struct efx_mcdi_mon_attribute *attr = &hwmon->attrs[hwmon->n_attrs];
  253. strlcpy(attr->name, name, sizeof(attr->name));
  254. attr->index = index;
  255. attr->type = type;
  256. if (type < ARRAY_SIZE(efx_mcdi_sensor_type))
  257. attr->hwmon_type = efx_mcdi_sensor_type[type].hwmon_type;
  258. else
  259. attr->hwmon_type = EFX_HWMON_UNKNOWN;
  260. attr->limit_value = limit_value;
  261. sysfs_attr_init(&attr->dev_attr.attr);
  262. attr->dev_attr.attr.name = attr->name;
  263. attr->dev_attr.attr.mode = S_IRUGO;
  264. attr->dev_attr.show = reader;
  265. hwmon->group.attrs[hwmon->n_attrs++] = &attr->dev_attr.attr;
  266. }
  267. int efx_mcdi_mon_probe(struct efx_nic *efx)
  268. {
  269. unsigned int n_temp = 0, n_cool = 0, n_in = 0, n_curr = 0, n_power = 0;
  270. struct efx_mcdi_mon *hwmon = efx_mcdi_mon(efx);
  271. MCDI_DECLARE_BUF(inbuf, MC_CMD_SENSOR_INFO_EXT_IN_LEN);
  272. MCDI_DECLARE_BUF(outbuf, MC_CMD_SENSOR_INFO_OUT_LENMAX);
  273. unsigned int n_pages, n_sensors, n_attrs, page;
  274. size_t outlen;
  275. char name[12];
  276. u32 mask;
  277. int rc, i, j, type;
  278. /* Find out how many sensors are present */
  279. n_sensors = 0;
  280. page = 0;
  281. do {
  282. MCDI_SET_DWORD(inbuf, SENSOR_INFO_EXT_IN_PAGE, page);
  283. rc = efx_mcdi_rpc(efx, MC_CMD_SENSOR_INFO, inbuf, sizeof(inbuf),
  284. outbuf, sizeof(outbuf), &outlen);
  285. if (rc)
  286. return rc;
  287. if (outlen < MC_CMD_SENSOR_INFO_OUT_LENMIN)
  288. return -EIO;
  289. mask = MCDI_DWORD(outbuf, SENSOR_INFO_OUT_MASK);
  290. n_sensors += hweight32(mask & ~(1 << MC_CMD_SENSOR_PAGE0_NEXT));
  291. ++page;
  292. } while (mask & (1 << MC_CMD_SENSOR_PAGE0_NEXT));
  293. n_pages = page;
  294. /* Don't create a device if there are none */
  295. if (n_sensors == 0)
  296. return 0;
  297. rc = efx_nic_alloc_buffer(
  298. efx, &hwmon->dma_buf,
  299. n_sensors * MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_LEN,
  300. GFP_KERNEL);
  301. if (rc)
  302. return rc;
  303. mutex_init(&hwmon->update_lock);
  304. efx_mcdi_mon_update(efx);
  305. /* Allocate space for the maximum possible number of
  306. * attributes for this set of sensors:
  307. * value, min, max, crit, alarm and label for each sensor.
  308. */
  309. n_attrs = 6 * n_sensors;
  310. hwmon->attrs = kcalloc(n_attrs, sizeof(*hwmon->attrs), GFP_KERNEL);
  311. if (!hwmon->attrs) {
  312. rc = -ENOMEM;
  313. goto fail;
  314. }
  315. hwmon->group.attrs = kcalloc(n_attrs + 1, sizeof(struct attribute *),
  316. GFP_KERNEL);
  317. if (!hwmon->group.attrs) {
  318. rc = -ENOMEM;
  319. goto fail;
  320. }
  321. for (i = 0, j = -1, type = -1; ; i++) {
  322. enum efx_hwmon_type hwmon_type;
  323. const char *hwmon_prefix;
  324. unsigned hwmon_index;
  325. u16 min1, max1, min2, max2;
  326. /* Find next sensor type or exit if there is none */
  327. do {
  328. type++;
  329. if ((type % 32) == 0) {
  330. page = type / 32;
  331. j = -1;
  332. if (page == n_pages)
  333. goto hwmon_register;
  334. MCDI_SET_DWORD(inbuf, SENSOR_INFO_EXT_IN_PAGE,
  335. page);
  336. rc = efx_mcdi_rpc(efx, MC_CMD_SENSOR_INFO,
  337. inbuf, sizeof(inbuf),
  338. outbuf, sizeof(outbuf),
  339. &outlen);
  340. if (rc)
  341. goto fail;
  342. if (outlen < MC_CMD_SENSOR_INFO_OUT_LENMIN) {
  343. rc = -EIO;
  344. goto fail;
  345. }
  346. mask = (MCDI_DWORD(outbuf,
  347. SENSOR_INFO_OUT_MASK) &
  348. ~(1 << MC_CMD_SENSOR_PAGE0_NEXT));
  349. /* Check again for short response */
  350. if (outlen <
  351. MC_CMD_SENSOR_INFO_OUT_LEN(hweight32(mask))) {
  352. rc = -EIO;
  353. goto fail;
  354. }
  355. }
  356. } while (!(mask & (1 << type % 32)));
  357. j++;
  358. if (type < ARRAY_SIZE(efx_mcdi_sensor_type)) {
  359. hwmon_type = efx_mcdi_sensor_type[type].hwmon_type;
  360. /* Skip sensors specific to a different port */
  361. if (hwmon_type != EFX_HWMON_UNKNOWN &&
  362. efx_mcdi_sensor_type[type].port >= 0 &&
  363. efx_mcdi_sensor_type[type].port !=
  364. efx_port_num(efx))
  365. continue;
  366. } else {
  367. hwmon_type = EFX_HWMON_UNKNOWN;
  368. }
  369. switch (hwmon_type) {
  370. case EFX_HWMON_TEMP:
  371. hwmon_prefix = "temp";
  372. hwmon_index = ++n_temp; /* 1-based */
  373. break;
  374. case EFX_HWMON_COOL:
  375. /* This is likely to be a heatsink, but there
  376. * is no convention for representing cooling
  377. * devices other than fans.
  378. */
  379. hwmon_prefix = "fan";
  380. hwmon_index = ++n_cool; /* 1-based */
  381. break;
  382. default:
  383. hwmon_prefix = "in";
  384. hwmon_index = n_in++; /* 0-based */
  385. break;
  386. case EFX_HWMON_CURR:
  387. hwmon_prefix = "curr";
  388. hwmon_index = ++n_curr; /* 1-based */
  389. break;
  390. case EFX_HWMON_POWER:
  391. hwmon_prefix = "power";
  392. hwmon_index = ++n_power; /* 1-based */
  393. break;
  394. }
  395. min1 = MCDI_ARRAY_FIELD(outbuf, SENSOR_ENTRY,
  396. SENSOR_INFO_ENTRY, j, MIN1);
  397. max1 = MCDI_ARRAY_FIELD(outbuf, SENSOR_ENTRY,
  398. SENSOR_INFO_ENTRY, j, MAX1);
  399. min2 = MCDI_ARRAY_FIELD(outbuf, SENSOR_ENTRY,
  400. SENSOR_INFO_ENTRY, j, MIN2);
  401. max2 = MCDI_ARRAY_FIELD(outbuf, SENSOR_ENTRY,
  402. SENSOR_INFO_ENTRY, j, MAX2);
  403. if (min1 != max1) {
  404. snprintf(name, sizeof(name), "%s%u_input",
  405. hwmon_prefix, hwmon_index);
  406. efx_mcdi_mon_add_attr(
  407. efx, name, efx_mcdi_mon_show_value, i, type, 0);
  408. if (hwmon_type != EFX_HWMON_POWER) {
  409. snprintf(name, sizeof(name), "%s%u_min",
  410. hwmon_prefix, hwmon_index);
  411. efx_mcdi_mon_add_attr(
  412. efx, name, efx_mcdi_mon_show_limit,
  413. i, type, min1);
  414. }
  415. snprintf(name, sizeof(name), "%s%u_max",
  416. hwmon_prefix, hwmon_index);
  417. efx_mcdi_mon_add_attr(
  418. efx, name, efx_mcdi_mon_show_limit,
  419. i, type, max1);
  420. if (min2 != max2) {
  421. /* Assume max2 is critical value.
  422. * But we have no good way to expose min2.
  423. */
  424. snprintf(name, sizeof(name), "%s%u_crit",
  425. hwmon_prefix, hwmon_index);
  426. efx_mcdi_mon_add_attr(
  427. efx, name, efx_mcdi_mon_show_limit,
  428. i, type, max2);
  429. }
  430. }
  431. snprintf(name, sizeof(name), "%s%u_alarm",
  432. hwmon_prefix, hwmon_index);
  433. efx_mcdi_mon_add_attr(
  434. efx, name, efx_mcdi_mon_show_alarm, i, type, 0);
  435. if (type < ARRAY_SIZE(efx_mcdi_sensor_type) &&
  436. efx_mcdi_sensor_type[type].label) {
  437. snprintf(name, sizeof(name), "%s%u_label",
  438. hwmon_prefix, hwmon_index);
  439. efx_mcdi_mon_add_attr(
  440. efx, name, efx_mcdi_mon_show_label, i, type, 0);
  441. }
  442. }
  443. hwmon_register:
  444. hwmon->groups[0] = &hwmon->group;
  445. hwmon->device = hwmon_device_register_with_groups(&efx->pci_dev->dev,
  446. KBUILD_MODNAME, NULL,
  447. hwmon->groups);
  448. if (IS_ERR(hwmon->device)) {
  449. rc = PTR_ERR(hwmon->device);
  450. goto fail;
  451. }
  452. return 0;
  453. fail:
  454. efx_mcdi_mon_remove(efx);
  455. return rc;
  456. }
  457. void efx_mcdi_mon_remove(struct efx_nic *efx)
  458. {
  459. struct efx_mcdi_mon *hwmon = efx_mcdi_mon(efx);
  460. if (hwmon->device)
  461. hwmon_device_unregister(hwmon->device);
  462. kfree(hwmon->attrs);
  463. kfree(hwmon->group.attrs);
  464. efx_nic_free_buffer(efx, &hwmon->dma_buf);
  465. }
  466. #endif /* CONFIG_SFC_MCDI_MON */