ipath_sysfs.c 18 KB

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