ipath_sysfs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. * Copyright (c) 2006 QLogic, Inc. All rights reserved.
  3. * Copyright (c) 2006 PathScale, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include <linux/ctype.h>
  34. #include <linux/pci.h>
  35. #include "ipath_kernel.h"
  36. #include "ipath_layer.h"
  37. #include "ipath_common.h"
  38. /**
  39. * ipath_parse_ushort - parse an unsigned short value in an arbitrary base
  40. * @str: the string containing the number
  41. * @valp: where to put the result
  42. *
  43. * returns the number of bytes consumed, or negative value on error
  44. */
  45. int ipath_parse_ushort(const char *str, unsigned short *valp)
  46. {
  47. unsigned long val;
  48. char *end;
  49. int ret;
  50. if (!isdigit(str[0])) {
  51. ret = -EINVAL;
  52. goto bail;
  53. }
  54. val = simple_strtoul(str, &end, 0);
  55. if (val > 0xffff) {
  56. ret = -EINVAL;
  57. goto bail;
  58. }
  59. *valp = val;
  60. ret = end + 1 - str;
  61. if (ret == 0)
  62. ret = -EINVAL;
  63. bail:
  64. return ret;
  65. }
  66. static ssize_t show_version(struct device_driver *dev, char *buf)
  67. {
  68. /* The string printed here is already newline-terminated. */
  69. return scnprintf(buf, PAGE_SIZE, "%s", ipath_core_version);
  70. }
  71. static ssize_t show_num_units(struct device_driver *dev, char *buf)
  72. {
  73. return scnprintf(buf, PAGE_SIZE, "%d\n",
  74. ipath_count_units(NULL, NULL, NULL));
  75. }
  76. static ssize_t show_status(struct device *dev,
  77. struct device_attribute *attr,
  78. char *buf)
  79. {
  80. struct ipath_devdata *dd = dev_get_drvdata(dev);
  81. ssize_t ret;
  82. if (!dd->ipath_statusp) {
  83. ret = -EINVAL;
  84. goto bail;
  85. }
  86. ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n",
  87. (unsigned long long) *(dd->ipath_statusp));
  88. bail:
  89. return ret;
  90. }
  91. static const char *ipath_status_str[] = {
  92. "Initted",
  93. "Disabled",
  94. "Admin_Disabled",
  95. "OIB_SMA",
  96. "SMA",
  97. "Present",
  98. "IB_link_up",
  99. "IB_configured",
  100. "NoIBcable",
  101. "Fatal_Hardware_Error",
  102. NULL,
  103. };
  104. static ssize_t show_status_str(struct device *dev,
  105. struct device_attribute *attr,
  106. char *buf)
  107. {
  108. struct ipath_devdata *dd = dev_get_drvdata(dev);
  109. int i, any;
  110. u64 s;
  111. ssize_t ret;
  112. if (!dd->ipath_statusp) {
  113. ret = -EINVAL;
  114. goto bail;
  115. }
  116. s = *(dd->ipath_statusp);
  117. *buf = '\0';
  118. for (any = i = 0; s && ipath_status_str[i]; i++) {
  119. if (s & 1) {
  120. if (any && strlcat(buf, " ", PAGE_SIZE) >=
  121. PAGE_SIZE)
  122. /* overflow */
  123. break;
  124. if (strlcat(buf, ipath_status_str[i],
  125. PAGE_SIZE) >= PAGE_SIZE)
  126. break;
  127. any = 1;
  128. }
  129. s >>= 1;
  130. }
  131. if (any)
  132. strlcat(buf, "\n", PAGE_SIZE);
  133. ret = strlen(buf);
  134. bail:
  135. return ret;
  136. }
  137. static ssize_t show_boardversion(struct device *dev,
  138. struct device_attribute *attr,
  139. char *buf)
  140. {
  141. struct ipath_devdata *dd = dev_get_drvdata(dev);
  142. /* The string printed here is already newline-terminated. */
  143. return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_boardversion);
  144. }
  145. static ssize_t show_lid(struct device *dev,
  146. struct device_attribute *attr,
  147. char *buf)
  148. {
  149. struct ipath_devdata *dd = dev_get_drvdata(dev);
  150. return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_lid);
  151. }
  152. static ssize_t store_lid(struct device *dev,
  153. struct device_attribute *attr,
  154. const char *buf,
  155. size_t count)
  156. {
  157. struct ipath_devdata *dd = dev_get_drvdata(dev);
  158. u16 lid = 0;
  159. int ret;
  160. ret = ipath_parse_ushort(buf, &lid);
  161. if (ret < 0)
  162. goto invalid;
  163. if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE) {
  164. ret = -EINVAL;
  165. goto invalid;
  166. }
  167. ipath_set_lid(dd, lid, 0);
  168. goto bail;
  169. invalid:
  170. ipath_dev_err(dd, "attempt to set invalid LID 0x%x\n", lid);
  171. bail:
  172. return ret;
  173. }
  174. static ssize_t show_mlid(struct device *dev,
  175. struct device_attribute *attr,
  176. char *buf)
  177. {
  178. struct ipath_devdata *dd = dev_get_drvdata(dev);
  179. return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_mlid);
  180. }
  181. static ssize_t store_mlid(struct device *dev,
  182. struct device_attribute *attr,
  183. const char *buf,
  184. size_t count)
  185. {
  186. struct ipath_devdata *dd = dev_get_drvdata(dev);
  187. int unit;
  188. u16 mlid;
  189. int ret;
  190. ret = ipath_parse_ushort(buf, &mlid);
  191. if (ret < 0 || mlid < IPATH_MULTICAST_LID_BASE)
  192. goto invalid;
  193. unit = dd->ipath_unit;
  194. dd->ipath_mlid = mlid;
  195. ipath_layer_intr(dd, IPATH_LAYER_INT_BCAST);
  196. goto bail;
  197. invalid:
  198. ipath_dev_err(dd, "attempt to set invalid MLID\n");
  199. bail:
  200. return ret;
  201. }
  202. static ssize_t show_guid(struct device *dev,
  203. struct device_attribute *attr,
  204. char *buf)
  205. {
  206. struct ipath_devdata *dd = dev_get_drvdata(dev);
  207. u8 *guid;
  208. guid = (u8 *) & (dd->ipath_guid);
  209. return scnprintf(buf, PAGE_SIZE,
  210. "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
  211. guid[0], guid[1], guid[2], guid[3],
  212. guid[4], guid[5], guid[6], guid[7]);
  213. }
  214. static ssize_t store_guid(struct device *dev,
  215. struct device_attribute *attr,
  216. const char *buf,
  217. size_t count)
  218. {
  219. struct ipath_devdata *dd = dev_get_drvdata(dev);
  220. ssize_t ret;
  221. unsigned short guid[8];
  222. __be64 nguid;
  223. u8 *ng;
  224. int i;
  225. if (sscanf(buf, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
  226. &guid[0], &guid[1], &guid[2], &guid[3],
  227. &guid[4], &guid[5], &guid[6], &guid[7]) != 8)
  228. goto invalid;
  229. ng = (u8 *) &nguid;
  230. for (i = 0; i < 8; i++) {
  231. if (guid[i] > 0xff)
  232. goto invalid;
  233. ng[i] = guid[i];
  234. }
  235. dd->ipath_guid = nguid;
  236. dd->ipath_nguid = 1;
  237. ret = strlen(buf);
  238. goto bail;
  239. invalid:
  240. ipath_dev_err(dd, "attempt to set invalid GUID\n");
  241. ret = -EINVAL;
  242. bail:
  243. return ret;
  244. }
  245. static ssize_t show_nguid(struct device *dev,
  246. struct device_attribute *attr,
  247. char *buf)
  248. {
  249. struct ipath_devdata *dd = dev_get_drvdata(dev);
  250. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid);
  251. }
  252. static ssize_t show_serial(struct device *dev,
  253. struct device_attribute *attr,
  254. char *buf)
  255. {
  256. struct ipath_devdata *dd = dev_get_drvdata(dev);
  257. buf[sizeof dd->ipath_serial] = '\0';
  258. memcpy(buf, dd->ipath_serial, sizeof dd->ipath_serial);
  259. strcat(buf, "\n");
  260. return strlen(buf);
  261. }
  262. static ssize_t show_unit(struct device *dev,
  263. struct device_attribute *attr,
  264. char *buf)
  265. {
  266. struct ipath_devdata *dd = dev_get_drvdata(dev);
  267. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_unit);
  268. }
  269. #define DEVICE_COUNTER(name, attr) \
  270. static ssize_t show_counter_##name(struct device *dev, \
  271. struct device_attribute *attr, \
  272. char *buf) \
  273. { \
  274. struct ipath_devdata *dd = dev_get_drvdata(dev); \
  275. return scnprintf(\
  276. buf, PAGE_SIZE, "%llu\n", (unsigned long long) \
  277. ipath_snap_cntr( \
  278. dd, offsetof(struct infinipath_counters, \
  279. attr) / sizeof(u64))); \
  280. } \
  281. static DEVICE_ATTR(name, S_IRUGO, show_counter_##name, NULL);
  282. DEVICE_COUNTER(ib_link_downeds, IBLinkDownedCnt);
  283. DEVICE_COUNTER(ib_link_err_recoveries, IBLinkErrRecoveryCnt);
  284. DEVICE_COUNTER(ib_status_changes, IBStatusChangeCnt);
  285. DEVICE_COUNTER(ib_symbol_errs, IBSymbolErrCnt);
  286. DEVICE_COUNTER(lb_flow_stalls, LBFlowStallCnt);
  287. DEVICE_COUNTER(lb_ints, LBIntCnt);
  288. DEVICE_COUNTER(rx_bad_formats, RxBadFormatCnt);
  289. DEVICE_COUNTER(rx_buf_ovfls, RxBufOvflCnt);
  290. DEVICE_COUNTER(rx_data_pkts, RxDataPktCnt);
  291. DEVICE_COUNTER(rx_dropped_pkts, RxDroppedPktCnt);
  292. DEVICE_COUNTER(rx_dwords, RxDwordCnt);
  293. DEVICE_COUNTER(rx_ebps, RxEBPCnt);
  294. DEVICE_COUNTER(rx_flow_ctrl_errs, RxFlowCtrlErrCnt);
  295. DEVICE_COUNTER(rx_flow_pkts, RxFlowPktCnt);
  296. DEVICE_COUNTER(rx_icrc_errs, RxICRCErrCnt);
  297. DEVICE_COUNTER(rx_len_errs, RxLenErrCnt);
  298. DEVICE_COUNTER(rx_link_problems, RxLinkProblemCnt);
  299. DEVICE_COUNTER(rx_lpcrc_errs, RxLPCRCErrCnt);
  300. DEVICE_COUNTER(rx_max_min_len_errs, RxMaxMinLenErrCnt);
  301. DEVICE_COUNTER(rx_p0_hdr_egr_ovfls, RxP0HdrEgrOvflCnt);
  302. DEVICE_COUNTER(rx_p1_hdr_egr_ovfls, RxP1HdrEgrOvflCnt);
  303. DEVICE_COUNTER(rx_p2_hdr_egr_ovfls, RxP2HdrEgrOvflCnt);
  304. DEVICE_COUNTER(rx_p3_hdr_egr_ovfls, RxP3HdrEgrOvflCnt);
  305. DEVICE_COUNTER(rx_p4_hdr_egr_ovfls, RxP4HdrEgrOvflCnt);
  306. DEVICE_COUNTER(rx_p5_hdr_egr_ovfls, RxP5HdrEgrOvflCnt);
  307. DEVICE_COUNTER(rx_p6_hdr_egr_ovfls, RxP6HdrEgrOvflCnt);
  308. DEVICE_COUNTER(rx_p7_hdr_egr_ovfls, RxP7HdrEgrOvflCnt);
  309. DEVICE_COUNTER(rx_p8_hdr_egr_ovfls, RxP8HdrEgrOvflCnt);
  310. DEVICE_COUNTER(rx_pkey_mismatches, RxPKeyMismatchCnt);
  311. DEVICE_COUNTER(rx_tid_full_errs, RxTIDFullErrCnt);
  312. DEVICE_COUNTER(rx_tid_valid_errs, RxTIDValidErrCnt);
  313. DEVICE_COUNTER(rx_vcrc_errs, RxVCRCErrCnt);
  314. DEVICE_COUNTER(tx_data_pkts, TxDataPktCnt);
  315. DEVICE_COUNTER(tx_dropped_pkts, TxDroppedPktCnt);
  316. DEVICE_COUNTER(tx_dwords, TxDwordCnt);
  317. DEVICE_COUNTER(tx_flow_pkts, TxFlowPktCnt);
  318. DEVICE_COUNTER(tx_flow_stalls, TxFlowStallCnt);
  319. DEVICE_COUNTER(tx_len_errs, TxLenErrCnt);
  320. DEVICE_COUNTER(tx_max_min_len_errs, TxMaxMinLenErrCnt);
  321. DEVICE_COUNTER(tx_underruns, TxUnderrunCnt);
  322. DEVICE_COUNTER(tx_unsup_vl_errs, TxUnsupVLErrCnt);
  323. static struct attribute *dev_counter_attributes[] = {
  324. &dev_attr_ib_link_downeds.attr,
  325. &dev_attr_ib_link_err_recoveries.attr,
  326. &dev_attr_ib_status_changes.attr,
  327. &dev_attr_ib_symbol_errs.attr,
  328. &dev_attr_lb_flow_stalls.attr,
  329. &dev_attr_lb_ints.attr,
  330. &dev_attr_rx_bad_formats.attr,
  331. &dev_attr_rx_buf_ovfls.attr,
  332. &dev_attr_rx_data_pkts.attr,
  333. &dev_attr_rx_dropped_pkts.attr,
  334. &dev_attr_rx_dwords.attr,
  335. &dev_attr_rx_ebps.attr,
  336. &dev_attr_rx_flow_ctrl_errs.attr,
  337. &dev_attr_rx_flow_pkts.attr,
  338. &dev_attr_rx_icrc_errs.attr,
  339. &dev_attr_rx_len_errs.attr,
  340. &dev_attr_rx_link_problems.attr,
  341. &dev_attr_rx_lpcrc_errs.attr,
  342. &dev_attr_rx_max_min_len_errs.attr,
  343. &dev_attr_rx_p0_hdr_egr_ovfls.attr,
  344. &dev_attr_rx_p1_hdr_egr_ovfls.attr,
  345. &dev_attr_rx_p2_hdr_egr_ovfls.attr,
  346. &dev_attr_rx_p3_hdr_egr_ovfls.attr,
  347. &dev_attr_rx_p4_hdr_egr_ovfls.attr,
  348. &dev_attr_rx_p5_hdr_egr_ovfls.attr,
  349. &dev_attr_rx_p6_hdr_egr_ovfls.attr,
  350. &dev_attr_rx_p7_hdr_egr_ovfls.attr,
  351. &dev_attr_rx_p8_hdr_egr_ovfls.attr,
  352. &dev_attr_rx_pkey_mismatches.attr,
  353. &dev_attr_rx_tid_full_errs.attr,
  354. &dev_attr_rx_tid_valid_errs.attr,
  355. &dev_attr_rx_vcrc_errs.attr,
  356. &dev_attr_tx_data_pkts.attr,
  357. &dev_attr_tx_dropped_pkts.attr,
  358. &dev_attr_tx_dwords.attr,
  359. &dev_attr_tx_flow_pkts.attr,
  360. &dev_attr_tx_flow_stalls.attr,
  361. &dev_attr_tx_len_errs.attr,
  362. &dev_attr_tx_max_min_len_errs.attr,
  363. &dev_attr_tx_underruns.attr,
  364. &dev_attr_tx_unsup_vl_errs.attr,
  365. NULL
  366. };
  367. static struct attribute_group dev_counter_attr_group = {
  368. .name = "counters",
  369. .attrs = dev_counter_attributes
  370. };
  371. static ssize_t store_reset(struct device *dev,
  372. struct device_attribute *attr,
  373. const char *buf,
  374. size_t count)
  375. {
  376. struct ipath_devdata *dd = dev_get_drvdata(dev);
  377. int ret;
  378. if (count < 5 || memcmp(buf, "reset", 5)) {
  379. ret = -EINVAL;
  380. goto bail;
  381. }
  382. if (dd->ipath_flags & IPATH_DISABLED) {
  383. /*
  384. * post-reset init would re-enable interrupts, etc.
  385. * so don't allow reset on disabled devices. Not
  386. * perfect error, but about the best choice.
  387. */
  388. dev_info(dev,"Unit %d is disabled, can't reset\n",
  389. dd->ipath_unit);
  390. ret = -EINVAL;
  391. }
  392. ret = ipath_reset_device(dd->ipath_unit);
  393. bail:
  394. return ret<0 ? ret : count;
  395. }
  396. static ssize_t store_link_state(struct device *dev,
  397. struct device_attribute *attr,
  398. const char *buf,
  399. size_t count)
  400. {
  401. struct ipath_devdata *dd = dev_get_drvdata(dev);
  402. int ret, r;
  403. u16 state;
  404. ret = ipath_parse_ushort(buf, &state);
  405. if (ret < 0)
  406. goto invalid;
  407. r = ipath_layer_set_linkstate(dd, state);
  408. if (r < 0) {
  409. ret = r;
  410. goto bail;
  411. }
  412. goto bail;
  413. invalid:
  414. ipath_dev_err(dd, "attempt to set invalid link state\n");
  415. bail:
  416. return ret;
  417. }
  418. static ssize_t show_mtu(struct device *dev,
  419. struct device_attribute *attr,
  420. char *buf)
  421. {
  422. struct ipath_devdata *dd = dev_get_drvdata(dev);
  423. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_ibmtu);
  424. }
  425. static ssize_t store_mtu(struct device *dev,
  426. struct device_attribute *attr,
  427. const char *buf,
  428. size_t count)
  429. {
  430. struct ipath_devdata *dd = dev_get_drvdata(dev);
  431. ssize_t ret;
  432. u16 mtu = 0;
  433. int r;
  434. ret = ipath_parse_ushort(buf, &mtu);
  435. if (ret < 0)
  436. goto invalid;
  437. r = ipath_layer_set_mtu(dd, mtu);
  438. if (r < 0)
  439. ret = r;
  440. goto bail;
  441. invalid:
  442. ipath_dev_err(dd, "attempt to set invalid MTU\n");
  443. bail:
  444. return ret;
  445. }
  446. static ssize_t show_enabled(struct device *dev,
  447. struct device_attribute *attr,
  448. char *buf)
  449. {
  450. struct ipath_devdata *dd = dev_get_drvdata(dev);
  451. return scnprintf(buf, PAGE_SIZE, "%u\n",
  452. (dd->ipath_flags & IPATH_DISABLED) ? 0 : 1);
  453. }
  454. static ssize_t store_enabled(struct device *dev,
  455. struct device_attribute *attr,
  456. const char *buf,
  457. size_t count)
  458. {
  459. struct ipath_devdata *dd = dev_get_drvdata(dev);
  460. ssize_t ret;
  461. u16 enable = 0;
  462. ret = ipath_parse_ushort(buf, &enable);
  463. if (ret < 0) {
  464. ipath_dev_err(dd, "attempt to use non-numeric on enable\n");
  465. goto bail;
  466. }
  467. if (enable) {
  468. if (!(dd->ipath_flags & IPATH_DISABLED))
  469. goto bail;
  470. dev_info(dev, "Enabling unit %d\n", dd->ipath_unit);
  471. /* same as post-reset */
  472. ret = ipath_init_chip(dd, 1);
  473. if (ret)
  474. ipath_dev_err(dd, "Failed to enable unit %d\n",
  475. dd->ipath_unit);
  476. else {
  477. dd->ipath_flags &= ~IPATH_DISABLED;
  478. *dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED;
  479. }
  480. }
  481. else if (!(dd->ipath_flags & IPATH_DISABLED)) {
  482. dev_info(dev, "Disabling unit %d\n", dd->ipath_unit);
  483. ipath_shutdown_device(dd);
  484. dd->ipath_flags |= IPATH_DISABLED;
  485. *dd->ipath_statusp |= IPATH_STATUS_ADMIN_DISABLED;
  486. }
  487. bail:
  488. return ret;
  489. }
  490. static DRIVER_ATTR(num_units, S_IRUGO, show_num_units, NULL);
  491. static DRIVER_ATTR(version, S_IRUGO, show_version, NULL);
  492. static struct attribute *driver_attributes[] = {
  493. &driver_attr_num_units.attr,
  494. &driver_attr_version.attr,
  495. NULL
  496. };
  497. static struct attribute_group driver_attr_group = {
  498. .attrs = driver_attributes
  499. };
  500. static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid);
  501. static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid);
  502. static DEVICE_ATTR(link_state, S_IWUSR, NULL, store_link_state);
  503. static DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid);
  504. static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu);
  505. static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled);
  506. static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL);
  507. static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset);
  508. static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
  509. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  510. static DEVICE_ATTR(status_str, S_IRUGO, show_status_str, NULL);
  511. static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
  512. static DEVICE_ATTR(unit, S_IRUGO, show_unit, NULL);
  513. static struct attribute *dev_attributes[] = {
  514. &dev_attr_guid.attr,
  515. &dev_attr_lid.attr,
  516. &dev_attr_link_state.attr,
  517. &dev_attr_mlid.attr,
  518. &dev_attr_mtu.attr,
  519. &dev_attr_nguid.attr,
  520. &dev_attr_serial.attr,
  521. &dev_attr_status.attr,
  522. &dev_attr_status_str.attr,
  523. &dev_attr_boardversion.attr,
  524. &dev_attr_unit.attr,
  525. &dev_attr_enabled.attr,
  526. NULL
  527. };
  528. static struct attribute_group dev_attr_group = {
  529. .attrs = dev_attributes
  530. };
  531. /**
  532. * ipath_expose_reset - create a device reset file
  533. * @dev: the device structure
  534. *
  535. * Only expose a file that lets us reset the device after someone
  536. * enters diag mode. A device reset is quite likely to crash the
  537. * machine entirely, so we don't want to normally make it
  538. * available.
  539. *
  540. * Called with ipath_mutex held.
  541. */
  542. int ipath_expose_reset(struct device *dev)
  543. {
  544. static int exposed;
  545. int ret;
  546. if (!exposed) {
  547. ret = device_create_file(dev, &dev_attr_reset);
  548. exposed = 1;
  549. }
  550. else
  551. ret = 0;
  552. return ret;
  553. }
  554. int ipath_driver_create_group(struct device_driver *drv)
  555. {
  556. int ret;
  557. ret = sysfs_create_group(&drv->kobj, &driver_attr_group);
  558. return ret;
  559. }
  560. void ipath_driver_remove_group(struct device_driver *drv)
  561. {
  562. sysfs_remove_group(&drv->kobj, &driver_attr_group);
  563. }
  564. int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
  565. {
  566. int ret;
  567. char unit[5];
  568. ret = sysfs_create_group(&dev->kobj, &dev_attr_group);
  569. if (ret)
  570. goto bail;
  571. ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group);
  572. if (ret)
  573. goto bail_attrs;
  574. snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
  575. ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit);
  576. if (ret == 0)
  577. goto bail;
  578. sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
  579. bail_attrs:
  580. sysfs_remove_group(&dev->kobj, &dev_attr_group);
  581. bail:
  582. return ret;
  583. }
  584. void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd)
  585. {
  586. char unit[5];
  587. snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
  588. sysfs_remove_link(&dev->driver->kobj, unit);
  589. sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
  590. sysfs_remove_group(&dev->kobj, &dev_attr_group);
  591. device_remove_file(dev, &dev_attr_reset);
  592. }