ipath_sysfs.c 18 KB

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