ipath_sysfs.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. u16 mlid;
  187. int ret;
  188. ret = ipath_parse_ushort(buf, &mlid);
  189. if (ret < 0 || mlid < IPATH_MULTICAST_LID_BASE)
  190. goto invalid;
  191. dd->ipath_mlid = mlid;
  192. goto bail;
  193. invalid:
  194. ipath_dev_err(dd, "attempt to set invalid MLID\n");
  195. bail:
  196. return ret;
  197. }
  198. static ssize_t show_guid(struct device *dev,
  199. struct device_attribute *attr,
  200. char *buf)
  201. {
  202. struct ipath_devdata *dd = dev_get_drvdata(dev);
  203. u8 *guid;
  204. guid = (u8 *) & (dd->ipath_guid);
  205. return scnprintf(buf, PAGE_SIZE,
  206. "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
  207. guid[0], guid[1], guid[2], guid[3],
  208. guid[4], guid[5], guid[6], guid[7]);
  209. }
  210. static ssize_t store_guid(struct device *dev,
  211. struct device_attribute *attr,
  212. const char *buf,
  213. size_t count)
  214. {
  215. struct ipath_devdata *dd = dev_get_drvdata(dev);
  216. ssize_t ret;
  217. unsigned short guid[8];
  218. __be64 new_guid;
  219. u8 *ng;
  220. int i;
  221. if (sscanf(buf, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
  222. &guid[0], &guid[1], &guid[2], &guid[3],
  223. &guid[4], &guid[5], &guid[6], &guid[7]) != 8)
  224. goto invalid;
  225. ng = (u8 *) &new_guid;
  226. for (i = 0; i < 8; i++) {
  227. if (guid[i] > 0xff)
  228. goto invalid;
  229. ng[i] = guid[i];
  230. }
  231. if (new_guid == 0)
  232. goto invalid;
  233. dd->ipath_guid = new_guid;
  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_nports(struct device *dev,
  251. struct device_attribute *attr,
  252. char *buf)
  253. {
  254. struct ipath_devdata *dd = dev_get_drvdata(dev);
  255. /* Return the number of user ports available. */
  256. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_cfgports - 1);
  257. }
  258. static ssize_t show_serial(struct device *dev,
  259. struct device_attribute *attr,
  260. char *buf)
  261. {
  262. struct ipath_devdata *dd = dev_get_drvdata(dev);
  263. buf[sizeof dd->ipath_serial] = '\0';
  264. memcpy(buf, dd->ipath_serial, sizeof dd->ipath_serial);
  265. strcat(buf, "\n");
  266. return strlen(buf);
  267. }
  268. static ssize_t show_unit(struct device *dev,
  269. struct device_attribute *attr,
  270. char *buf)
  271. {
  272. struct ipath_devdata *dd = dev_get_drvdata(dev);
  273. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_unit);
  274. }
  275. #define DEVICE_COUNTER(name, attr) \
  276. static ssize_t show_counter_##name(struct device *dev, \
  277. struct device_attribute *attr, \
  278. char *buf) \
  279. { \
  280. struct ipath_devdata *dd = dev_get_drvdata(dev); \
  281. return scnprintf(\
  282. buf, PAGE_SIZE, "%llu\n", (unsigned long long) \
  283. ipath_snap_cntr( \
  284. dd, offsetof(struct infinipath_counters, \
  285. attr) / sizeof(u64))); \
  286. } \
  287. static DEVICE_ATTR(name, S_IRUGO, show_counter_##name, NULL);
  288. DEVICE_COUNTER(ib_link_downeds, IBLinkDownedCnt);
  289. DEVICE_COUNTER(ib_link_err_recoveries, IBLinkErrRecoveryCnt);
  290. DEVICE_COUNTER(ib_status_changes, IBStatusChangeCnt);
  291. DEVICE_COUNTER(ib_symbol_errs, IBSymbolErrCnt);
  292. DEVICE_COUNTER(lb_flow_stalls, LBFlowStallCnt);
  293. DEVICE_COUNTER(lb_ints, LBIntCnt);
  294. DEVICE_COUNTER(rx_bad_formats, RxBadFormatCnt);
  295. DEVICE_COUNTER(rx_buf_ovfls, RxBufOvflCnt);
  296. DEVICE_COUNTER(rx_data_pkts, RxDataPktCnt);
  297. DEVICE_COUNTER(rx_dropped_pkts, RxDroppedPktCnt);
  298. DEVICE_COUNTER(rx_dwords, RxDwordCnt);
  299. DEVICE_COUNTER(rx_ebps, RxEBPCnt);
  300. DEVICE_COUNTER(rx_flow_ctrl_errs, RxFlowCtrlErrCnt);
  301. DEVICE_COUNTER(rx_flow_pkts, RxFlowPktCnt);
  302. DEVICE_COUNTER(rx_icrc_errs, RxICRCErrCnt);
  303. DEVICE_COUNTER(rx_len_errs, RxLenErrCnt);
  304. DEVICE_COUNTER(rx_link_problems, RxLinkProblemCnt);
  305. DEVICE_COUNTER(rx_lpcrc_errs, RxLPCRCErrCnt);
  306. DEVICE_COUNTER(rx_max_min_len_errs, RxMaxMinLenErrCnt);
  307. DEVICE_COUNTER(rx_p0_hdr_egr_ovfls, RxP0HdrEgrOvflCnt);
  308. DEVICE_COUNTER(rx_p1_hdr_egr_ovfls, RxP1HdrEgrOvflCnt);
  309. DEVICE_COUNTER(rx_p2_hdr_egr_ovfls, RxP2HdrEgrOvflCnt);
  310. DEVICE_COUNTER(rx_p3_hdr_egr_ovfls, RxP3HdrEgrOvflCnt);
  311. DEVICE_COUNTER(rx_p4_hdr_egr_ovfls, RxP4HdrEgrOvflCnt);
  312. DEVICE_COUNTER(rx_p5_hdr_egr_ovfls, RxP5HdrEgrOvflCnt);
  313. DEVICE_COUNTER(rx_p6_hdr_egr_ovfls, RxP6HdrEgrOvflCnt);
  314. DEVICE_COUNTER(rx_p7_hdr_egr_ovfls, RxP7HdrEgrOvflCnt);
  315. DEVICE_COUNTER(rx_p8_hdr_egr_ovfls, RxP8HdrEgrOvflCnt);
  316. DEVICE_COUNTER(rx_pkey_mismatches, RxPKeyMismatchCnt);
  317. DEVICE_COUNTER(rx_tid_full_errs, RxTIDFullErrCnt);
  318. DEVICE_COUNTER(rx_tid_valid_errs, RxTIDValidErrCnt);
  319. DEVICE_COUNTER(rx_vcrc_errs, RxVCRCErrCnt);
  320. DEVICE_COUNTER(tx_data_pkts, TxDataPktCnt);
  321. DEVICE_COUNTER(tx_dropped_pkts, TxDroppedPktCnt);
  322. DEVICE_COUNTER(tx_dwords, TxDwordCnt);
  323. DEVICE_COUNTER(tx_flow_pkts, TxFlowPktCnt);
  324. DEVICE_COUNTER(tx_flow_stalls, TxFlowStallCnt);
  325. DEVICE_COUNTER(tx_len_errs, TxLenErrCnt);
  326. DEVICE_COUNTER(tx_max_min_len_errs, TxMaxMinLenErrCnt);
  327. DEVICE_COUNTER(tx_underruns, TxUnderrunCnt);
  328. DEVICE_COUNTER(tx_unsup_vl_errs, TxUnsupVLErrCnt);
  329. static struct attribute *dev_counter_attributes[] = {
  330. &dev_attr_ib_link_downeds.attr,
  331. &dev_attr_ib_link_err_recoveries.attr,
  332. &dev_attr_ib_status_changes.attr,
  333. &dev_attr_ib_symbol_errs.attr,
  334. &dev_attr_lb_flow_stalls.attr,
  335. &dev_attr_lb_ints.attr,
  336. &dev_attr_rx_bad_formats.attr,
  337. &dev_attr_rx_buf_ovfls.attr,
  338. &dev_attr_rx_data_pkts.attr,
  339. &dev_attr_rx_dropped_pkts.attr,
  340. &dev_attr_rx_dwords.attr,
  341. &dev_attr_rx_ebps.attr,
  342. &dev_attr_rx_flow_ctrl_errs.attr,
  343. &dev_attr_rx_flow_pkts.attr,
  344. &dev_attr_rx_icrc_errs.attr,
  345. &dev_attr_rx_len_errs.attr,
  346. &dev_attr_rx_link_problems.attr,
  347. &dev_attr_rx_lpcrc_errs.attr,
  348. &dev_attr_rx_max_min_len_errs.attr,
  349. &dev_attr_rx_p0_hdr_egr_ovfls.attr,
  350. &dev_attr_rx_p1_hdr_egr_ovfls.attr,
  351. &dev_attr_rx_p2_hdr_egr_ovfls.attr,
  352. &dev_attr_rx_p3_hdr_egr_ovfls.attr,
  353. &dev_attr_rx_p4_hdr_egr_ovfls.attr,
  354. &dev_attr_rx_p5_hdr_egr_ovfls.attr,
  355. &dev_attr_rx_p6_hdr_egr_ovfls.attr,
  356. &dev_attr_rx_p7_hdr_egr_ovfls.attr,
  357. &dev_attr_rx_p8_hdr_egr_ovfls.attr,
  358. &dev_attr_rx_pkey_mismatches.attr,
  359. &dev_attr_rx_tid_full_errs.attr,
  360. &dev_attr_rx_tid_valid_errs.attr,
  361. &dev_attr_rx_vcrc_errs.attr,
  362. &dev_attr_tx_data_pkts.attr,
  363. &dev_attr_tx_dropped_pkts.attr,
  364. &dev_attr_tx_dwords.attr,
  365. &dev_attr_tx_flow_pkts.attr,
  366. &dev_attr_tx_flow_stalls.attr,
  367. &dev_attr_tx_len_errs.attr,
  368. &dev_attr_tx_max_min_len_errs.attr,
  369. &dev_attr_tx_underruns.attr,
  370. &dev_attr_tx_unsup_vl_errs.attr,
  371. NULL
  372. };
  373. static struct attribute_group dev_counter_attr_group = {
  374. .name = "counters",
  375. .attrs = dev_counter_attributes
  376. };
  377. static ssize_t store_reset(struct device *dev,
  378. struct device_attribute *attr,
  379. const char *buf,
  380. size_t count)
  381. {
  382. struct ipath_devdata *dd = dev_get_drvdata(dev);
  383. int ret;
  384. if (count < 5 || memcmp(buf, "reset", 5)) {
  385. ret = -EINVAL;
  386. goto bail;
  387. }
  388. if (dd->ipath_flags & IPATH_DISABLED) {
  389. /*
  390. * post-reset init would re-enable interrupts, etc.
  391. * so don't allow reset on disabled devices. Not
  392. * perfect error, but about the best choice.
  393. */
  394. dev_info(dev,"Unit %d is disabled, can't reset\n",
  395. dd->ipath_unit);
  396. ret = -EINVAL;
  397. }
  398. ret = ipath_reset_device(dd->ipath_unit);
  399. bail:
  400. return ret<0 ? ret : count;
  401. }
  402. static ssize_t store_link_state(struct device *dev,
  403. struct device_attribute *attr,
  404. const char *buf,
  405. size_t count)
  406. {
  407. struct ipath_devdata *dd = dev_get_drvdata(dev);
  408. int ret, r;
  409. u16 state;
  410. ret = ipath_parse_ushort(buf, &state);
  411. if (ret < 0)
  412. goto invalid;
  413. r = ipath_set_linkstate(dd, state);
  414. if (r < 0) {
  415. ret = r;
  416. goto bail;
  417. }
  418. goto bail;
  419. invalid:
  420. ipath_dev_err(dd, "attempt to set invalid link state\n");
  421. bail:
  422. return ret;
  423. }
  424. static ssize_t show_mtu(struct device *dev,
  425. struct device_attribute *attr,
  426. char *buf)
  427. {
  428. struct ipath_devdata *dd = dev_get_drvdata(dev);
  429. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_ibmtu);
  430. }
  431. static ssize_t store_mtu(struct device *dev,
  432. struct device_attribute *attr,
  433. const char *buf,
  434. size_t count)
  435. {
  436. struct ipath_devdata *dd = dev_get_drvdata(dev);
  437. ssize_t ret;
  438. u16 mtu = 0;
  439. int r;
  440. ret = ipath_parse_ushort(buf, &mtu);
  441. if (ret < 0)
  442. goto invalid;
  443. r = ipath_set_mtu(dd, mtu);
  444. if (r < 0)
  445. ret = r;
  446. goto bail;
  447. invalid:
  448. ipath_dev_err(dd, "attempt to set invalid MTU\n");
  449. bail:
  450. return ret;
  451. }
  452. static ssize_t show_enabled(struct device *dev,
  453. struct device_attribute *attr,
  454. char *buf)
  455. {
  456. struct ipath_devdata *dd = dev_get_drvdata(dev);
  457. return scnprintf(buf, PAGE_SIZE, "%u\n",
  458. (dd->ipath_flags & IPATH_DISABLED) ? 0 : 1);
  459. }
  460. static ssize_t store_enabled(struct device *dev,
  461. struct device_attribute *attr,
  462. const char *buf,
  463. size_t count)
  464. {
  465. struct ipath_devdata *dd = dev_get_drvdata(dev);
  466. ssize_t ret;
  467. u16 enable = 0;
  468. ret = ipath_parse_ushort(buf, &enable);
  469. if (ret < 0) {
  470. ipath_dev_err(dd, "attempt to use non-numeric on enable\n");
  471. goto bail;
  472. }
  473. if (enable) {
  474. if (!(dd->ipath_flags & IPATH_DISABLED))
  475. goto bail;
  476. dev_info(dev, "Enabling unit %d\n", dd->ipath_unit);
  477. /* same as post-reset */
  478. ret = ipath_init_chip(dd, 1);
  479. if (ret)
  480. ipath_dev_err(dd, "Failed to enable unit %d\n",
  481. dd->ipath_unit);
  482. else {
  483. dd->ipath_flags &= ~IPATH_DISABLED;
  484. *dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED;
  485. }
  486. }
  487. else if (!(dd->ipath_flags & IPATH_DISABLED)) {
  488. dev_info(dev, "Disabling unit %d\n", dd->ipath_unit);
  489. ipath_shutdown_device(dd);
  490. dd->ipath_flags |= IPATH_DISABLED;
  491. *dd->ipath_statusp |= IPATH_STATUS_ADMIN_DISABLED;
  492. }
  493. bail:
  494. return ret;
  495. }
  496. static ssize_t store_rx_pol_inv(struct device *dev,
  497. struct device_attribute *attr,
  498. const char *buf,
  499. size_t count)
  500. {
  501. struct ipath_devdata *dd = dev_get_drvdata(dev);
  502. int ret, r;
  503. u16 val;
  504. ret = ipath_parse_ushort(buf, &val);
  505. if (ret < 0)
  506. goto invalid;
  507. r = ipath_set_rx_pol_inv(dd, val);
  508. if (r < 0) {
  509. ret = r;
  510. goto bail;
  511. }
  512. goto bail;
  513. invalid:
  514. ipath_dev_err(dd, "attempt to set invalid Rx Polarity invert\n");
  515. bail:
  516. return ret;
  517. }
  518. static DRIVER_ATTR(num_units, S_IRUGO, show_num_units, NULL);
  519. static DRIVER_ATTR(version, S_IRUGO, show_version, NULL);
  520. static struct attribute *driver_attributes[] = {
  521. &driver_attr_num_units.attr,
  522. &driver_attr_version.attr,
  523. NULL
  524. };
  525. static struct attribute_group driver_attr_group = {
  526. .attrs = driver_attributes
  527. };
  528. static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid);
  529. static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid);
  530. static DEVICE_ATTR(link_state, S_IWUSR, NULL, store_link_state);
  531. static DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid);
  532. static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu);
  533. static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled);
  534. static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL);
  535. static DEVICE_ATTR(nports, S_IRUGO, show_nports, NULL);
  536. static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset);
  537. static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
  538. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  539. static DEVICE_ATTR(status_str, S_IRUGO, show_status_str, NULL);
  540. static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
  541. static DEVICE_ATTR(unit, S_IRUGO, show_unit, NULL);
  542. static DEVICE_ATTR(rx_pol_inv, S_IWUSR, NULL, store_rx_pol_inv);
  543. static struct attribute *dev_attributes[] = {
  544. &dev_attr_guid.attr,
  545. &dev_attr_lid.attr,
  546. &dev_attr_link_state.attr,
  547. &dev_attr_mlid.attr,
  548. &dev_attr_mtu.attr,
  549. &dev_attr_nguid.attr,
  550. &dev_attr_nports.attr,
  551. &dev_attr_serial.attr,
  552. &dev_attr_status.attr,
  553. &dev_attr_status_str.attr,
  554. &dev_attr_boardversion.attr,
  555. &dev_attr_unit.attr,
  556. &dev_attr_enabled.attr,
  557. &dev_attr_rx_pol_inv.attr,
  558. NULL
  559. };
  560. static struct attribute_group dev_attr_group = {
  561. .attrs = dev_attributes
  562. };
  563. /**
  564. * ipath_expose_reset - create a device reset file
  565. * @dev: the device structure
  566. *
  567. * Only expose a file that lets us reset the device after someone
  568. * enters diag mode. A device reset is quite likely to crash the
  569. * machine entirely, so we don't want to normally make it
  570. * available.
  571. *
  572. * Called with ipath_mutex held.
  573. */
  574. int ipath_expose_reset(struct device *dev)
  575. {
  576. static int exposed;
  577. int ret;
  578. if (!exposed) {
  579. ret = device_create_file(dev, &dev_attr_reset);
  580. exposed = 1;
  581. }
  582. else
  583. ret = 0;
  584. return ret;
  585. }
  586. int ipath_driver_create_group(struct device_driver *drv)
  587. {
  588. int ret;
  589. ret = sysfs_create_group(&drv->kobj, &driver_attr_group);
  590. return ret;
  591. }
  592. void ipath_driver_remove_group(struct device_driver *drv)
  593. {
  594. sysfs_remove_group(&drv->kobj, &driver_attr_group);
  595. }
  596. int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
  597. {
  598. int ret;
  599. char unit[5];
  600. ret = sysfs_create_group(&dev->kobj, &dev_attr_group);
  601. if (ret)
  602. goto bail;
  603. ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group);
  604. if (ret)
  605. goto bail_attrs;
  606. snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
  607. ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit);
  608. if (ret == 0)
  609. goto bail;
  610. sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
  611. bail_attrs:
  612. sysfs_remove_group(&dev->kobj, &dev_attr_group);
  613. bail:
  614. return ret;
  615. }
  616. void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd)
  617. {
  618. char unit[5];
  619. snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
  620. sysfs_remove_link(&dev->driver->kobj, unit);
  621. sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
  622. sysfs_remove_group(&dev->kobj, &dev_attr_group);
  623. device_remove_file(dev, &dev_attr_reset);
  624. }