ipath_sysfs.c 20 KB

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