ipath_sysfs.c 18 KB

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