ipath_sysfs.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /*
  2. * Copyright (c) 2006 PathScale, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/ctype.h>
  33. #include <linux/pci.h>
  34. #include "ipath_kernel.h"
  35. #include "ips_common.h"
  36. #include "ipath_layer.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", ipath_core_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. #define DRIVER_STAT(name, attr) \
  76. static ssize_t show_stat_##name(struct device_driver *dev, \
  77. char *buf) \
  78. { \
  79. return scnprintf( \
  80. buf, PAGE_SIZE, "%llu\n", \
  81. (unsigned long long) ipath_stats.sps_ ##attr); \
  82. } \
  83. static DRIVER_ATTR(name, S_IRUGO, show_stat_##name, NULL)
  84. DRIVER_STAT(intrs, ints);
  85. DRIVER_STAT(err_intrs, errints);
  86. DRIVER_STAT(errs, errs);
  87. DRIVER_STAT(pkt_errs, pkterrs);
  88. DRIVER_STAT(crc_errs, crcerrs);
  89. DRIVER_STAT(hw_errs, hwerrs);
  90. DRIVER_STAT(ib_link, iblink);
  91. DRIVER_STAT(port0_pkts, port0pkts);
  92. DRIVER_STAT(ether_spkts, ether_spkts);
  93. DRIVER_STAT(ether_rpkts, ether_rpkts);
  94. DRIVER_STAT(sma_spkts, sma_spkts);
  95. DRIVER_STAT(sma_rpkts, sma_rpkts);
  96. DRIVER_STAT(hdrq_full, hdrqfull);
  97. DRIVER_STAT(etid_full, etidfull);
  98. DRIVER_STAT(no_piobufs, nopiobufs);
  99. DRIVER_STAT(ports, ports);
  100. DRIVER_STAT(pkey0, pkeys[0]);
  101. DRIVER_STAT(pkey1, pkeys[1]);
  102. DRIVER_STAT(pkey2, pkeys[2]);
  103. DRIVER_STAT(pkey3, pkeys[3]);
  104. /* XXX fix the following when dynamic table of devices used */
  105. DRIVER_STAT(lid0, lid[0]);
  106. DRIVER_STAT(lid1, lid[1]);
  107. DRIVER_STAT(lid2, lid[2]);
  108. DRIVER_STAT(lid3, lid[3]);
  109. DRIVER_STAT(nports, nports);
  110. DRIVER_STAT(null_intr, nullintr);
  111. DRIVER_STAT(max_pkts_call, maxpkts_call);
  112. DRIVER_STAT(avg_pkts_call, avgpkts_call);
  113. DRIVER_STAT(page_locks, pagelocks);
  114. DRIVER_STAT(page_unlocks, pageunlocks);
  115. DRIVER_STAT(krdrops, krdrops);
  116. /* XXX fix the following when dynamic table of devices used */
  117. DRIVER_STAT(mlid0, mlid[0]);
  118. DRIVER_STAT(mlid1, mlid[1]);
  119. DRIVER_STAT(mlid2, mlid[2]);
  120. DRIVER_STAT(mlid3, mlid[3]);
  121. static struct attribute *driver_stat_attributes[] = {
  122. &driver_attr_intrs.attr,
  123. &driver_attr_err_intrs.attr,
  124. &driver_attr_errs.attr,
  125. &driver_attr_pkt_errs.attr,
  126. &driver_attr_crc_errs.attr,
  127. &driver_attr_hw_errs.attr,
  128. &driver_attr_ib_link.attr,
  129. &driver_attr_port0_pkts.attr,
  130. &driver_attr_ether_spkts.attr,
  131. &driver_attr_ether_rpkts.attr,
  132. &driver_attr_sma_spkts.attr,
  133. &driver_attr_sma_rpkts.attr,
  134. &driver_attr_hdrq_full.attr,
  135. &driver_attr_etid_full.attr,
  136. &driver_attr_no_piobufs.attr,
  137. &driver_attr_ports.attr,
  138. &driver_attr_pkey0.attr,
  139. &driver_attr_pkey1.attr,
  140. &driver_attr_pkey2.attr,
  141. &driver_attr_pkey3.attr,
  142. &driver_attr_lid0.attr,
  143. &driver_attr_lid1.attr,
  144. &driver_attr_lid2.attr,
  145. &driver_attr_lid3.attr,
  146. &driver_attr_nports.attr,
  147. &driver_attr_null_intr.attr,
  148. &driver_attr_max_pkts_call.attr,
  149. &driver_attr_avg_pkts_call.attr,
  150. &driver_attr_page_locks.attr,
  151. &driver_attr_page_unlocks.attr,
  152. &driver_attr_krdrops.attr,
  153. &driver_attr_mlid0.attr,
  154. &driver_attr_mlid1.attr,
  155. &driver_attr_mlid2.attr,
  156. &driver_attr_mlid3.attr,
  157. NULL
  158. };
  159. static struct attribute_group driver_stat_attr_group = {
  160. .name = "stats",
  161. .attrs = driver_stat_attributes
  162. };
  163. static ssize_t show_status(struct device *dev,
  164. struct device_attribute *attr,
  165. char *buf)
  166. {
  167. struct ipath_devdata *dd = dev_get_drvdata(dev);
  168. ssize_t ret;
  169. if (!dd->ipath_statusp) {
  170. ret = -EINVAL;
  171. goto bail;
  172. }
  173. ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n",
  174. (unsigned long long) *(dd->ipath_statusp));
  175. bail:
  176. return ret;
  177. }
  178. static const char *ipath_status_str[] = {
  179. "Initted",
  180. "Disabled",
  181. "Admin_Disabled",
  182. "OIB_SMA",
  183. "SMA",
  184. "Present",
  185. "IB_link_up",
  186. "IB_configured",
  187. "NoIBcable",
  188. "Fatal_Hardware_Error",
  189. NULL,
  190. };
  191. static ssize_t show_status_str(struct device *dev,
  192. struct device_attribute *attr,
  193. char *buf)
  194. {
  195. struct ipath_devdata *dd = dev_get_drvdata(dev);
  196. int i, any;
  197. u64 s;
  198. ssize_t ret;
  199. if (!dd->ipath_statusp) {
  200. ret = -EINVAL;
  201. goto bail;
  202. }
  203. s = *(dd->ipath_statusp);
  204. *buf = '\0';
  205. for (any = i = 0; s && ipath_status_str[i]; i++) {
  206. if (s & 1) {
  207. if (any && strlcat(buf, " ", PAGE_SIZE) >=
  208. PAGE_SIZE)
  209. /* overflow */
  210. break;
  211. if (strlcat(buf, ipath_status_str[i],
  212. PAGE_SIZE) >= PAGE_SIZE)
  213. break;
  214. any = 1;
  215. }
  216. s >>= 1;
  217. }
  218. if (any)
  219. strlcat(buf, "\n", PAGE_SIZE);
  220. ret = strlen(buf);
  221. bail:
  222. return ret;
  223. }
  224. static ssize_t show_boardversion(struct device *dev,
  225. struct device_attribute *attr,
  226. char *buf)
  227. {
  228. struct ipath_devdata *dd = dev_get_drvdata(dev);
  229. /* The string printed here is already newline-terminated. */
  230. return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_boardversion);
  231. }
  232. static ssize_t show_lid(struct device *dev,
  233. struct device_attribute *attr,
  234. char *buf)
  235. {
  236. struct ipath_devdata *dd = dev_get_drvdata(dev);
  237. return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_lid);
  238. }
  239. static ssize_t store_lid(struct device *dev,
  240. struct device_attribute *attr,
  241. const char *buf,
  242. size_t count)
  243. {
  244. struct ipath_devdata *dd = dev_get_drvdata(dev);
  245. u16 lid;
  246. int ret;
  247. ret = ipath_parse_ushort(buf, &lid);
  248. if (ret < 0)
  249. goto invalid;
  250. if (lid == 0 || lid >= 0xc000) {
  251. ret = -EINVAL;
  252. goto invalid;
  253. }
  254. ipath_set_sps_lid(dd, lid, 0);
  255. goto bail;
  256. invalid:
  257. ipath_dev_err(dd, "attempt to set invalid LID\n");
  258. bail:
  259. return ret;
  260. }
  261. static ssize_t show_mlid(struct device *dev,
  262. struct device_attribute *attr,
  263. char *buf)
  264. {
  265. struct ipath_devdata *dd = dev_get_drvdata(dev);
  266. return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_mlid);
  267. }
  268. static ssize_t store_mlid(struct device *dev,
  269. struct device_attribute *attr,
  270. const char *buf,
  271. size_t count)
  272. {
  273. struct ipath_devdata *dd = dev_get_drvdata(dev);
  274. int unit;
  275. u16 mlid;
  276. int ret;
  277. ret = ipath_parse_ushort(buf, &mlid);
  278. if (ret < 0)
  279. goto invalid;
  280. unit = dd->ipath_unit;
  281. dd->ipath_mlid = mlid;
  282. ipath_stats.sps_mlid[unit] = mlid;
  283. ipath_layer_intr(dd, IPATH_LAYER_INT_BCAST);
  284. goto bail;
  285. invalid:
  286. ipath_dev_err(dd, "attempt to set invalid MLID\n");
  287. bail:
  288. return ret;
  289. }
  290. static ssize_t show_guid(struct device *dev,
  291. struct device_attribute *attr,
  292. char *buf)
  293. {
  294. struct ipath_devdata *dd = dev_get_drvdata(dev);
  295. u8 *guid;
  296. guid = (u8 *) & (dd->ipath_guid);
  297. return scnprintf(buf, PAGE_SIZE,
  298. "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
  299. guid[0], guid[1], guid[2], guid[3],
  300. guid[4], guid[5], guid[6], guid[7]);
  301. }
  302. static ssize_t store_guid(struct device *dev,
  303. struct device_attribute *attr,
  304. const char *buf,
  305. size_t count)
  306. {
  307. struct ipath_devdata *dd = dev_get_drvdata(dev);
  308. ssize_t ret;
  309. unsigned short guid[8];
  310. __be64 nguid;
  311. u8 *ng;
  312. int i;
  313. if (sscanf(buf, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
  314. &guid[0], &guid[1], &guid[2], &guid[3],
  315. &guid[4], &guid[5], &guid[6], &guid[7]) != 8)
  316. goto invalid;
  317. ng = (u8 *) &nguid;
  318. for (i = 0; i < 8; i++) {
  319. if (guid[i] > 0xff)
  320. goto invalid;
  321. ng[i] = guid[i];
  322. }
  323. dd->ipath_guid = nguid;
  324. dd->ipath_nguid = 1;
  325. ret = strlen(buf);
  326. goto bail;
  327. invalid:
  328. ipath_dev_err(dd, "attempt to set invalid GUID\n");
  329. ret = -EINVAL;
  330. bail:
  331. return ret;
  332. }
  333. static ssize_t show_nguid(struct device *dev,
  334. struct device_attribute *attr,
  335. char *buf)
  336. {
  337. struct ipath_devdata *dd = dev_get_drvdata(dev);
  338. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid);
  339. }
  340. static ssize_t show_serial(struct device *dev,
  341. struct device_attribute *attr,
  342. char *buf)
  343. {
  344. struct ipath_devdata *dd = dev_get_drvdata(dev);
  345. buf[sizeof dd->ipath_serial] = '\0';
  346. memcpy(buf, dd->ipath_serial, sizeof dd->ipath_serial);
  347. strcat(buf, "\n");
  348. return strlen(buf);
  349. }
  350. static ssize_t show_unit(struct device *dev,
  351. struct device_attribute *attr,
  352. char *buf)
  353. {
  354. struct ipath_devdata *dd = dev_get_drvdata(dev);
  355. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_unit);
  356. }
  357. #define DEVICE_COUNTER(name, attr) \
  358. static ssize_t show_counter_##name(struct device *dev, \
  359. struct device_attribute *attr, \
  360. char *buf) \
  361. { \
  362. struct ipath_devdata *dd = dev_get_drvdata(dev); \
  363. return scnprintf(\
  364. buf, PAGE_SIZE, "%llu\n", (unsigned long long) \
  365. ipath_snap_cntr( \
  366. dd, offsetof(struct infinipath_counters, \
  367. attr) / sizeof(u64))); \
  368. } \
  369. static DEVICE_ATTR(name, S_IRUGO, show_counter_##name, NULL);
  370. DEVICE_COUNTER(ib_link_downeds, IBLinkDownedCnt);
  371. DEVICE_COUNTER(ib_link_err_recoveries, IBLinkErrRecoveryCnt);
  372. DEVICE_COUNTER(ib_status_changes, IBStatusChangeCnt);
  373. DEVICE_COUNTER(ib_symbol_errs, IBSymbolErrCnt);
  374. DEVICE_COUNTER(lb_flow_stalls, LBFlowStallCnt);
  375. DEVICE_COUNTER(lb_ints, LBIntCnt);
  376. DEVICE_COUNTER(rx_bad_formats, RxBadFormatCnt);
  377. DEVICE_COUNTER(rx_buf_ovfls, RxBufOvflCnt);
  378. DEVICE_COUNTER(rx_data_pkts, RxDataPktCnt);
  379. DEVICE_COUNTER(rx_dropped_pkts, RxDroppedPktCnt);
  380. DEVICE_COUNTER(rx_dwords, RxDwordCnt);
  381. DEVICE_COUNTER(rx_ebps, RxEBPCnt);
  382. DEVICE_COUNTER(rx_flow_ctrl_errs, RxFlowCtrlErrCnt);
  383. DEVICE_COUNTER(rx_flow_pkts, RxFlowPktCnt);
  384. DEVICE_COUNTER(rx_icrc_errs, RxICRCErrCnt);
  385. DEVICE_COUNTER(rx_len_errs, RxLenErrCnt);
  386. DEVICE_COUNTER(rx_link_problems, RxLinkProblemCnt);
  387. DEVICE_COUNTER(rx_lpcrc_errs, RxLPCRCErrCnt);
  388. DEVICE_COUNTER(rx_max_min_len_errs, RxMaxMinLenErrCnt);
  389. DEVICE_COUNTER(rx_p0_hdr_egr_ovfls, RxP0HdrEgrOvflCnt);
  390. DEVICE_COUNTER(rx_p1_hdr_egr_ovfls, RxP1HdrEgrOvflCnt);
  391. DEVICE_COUNTER(rx_p2_hdr_egr_ovfls, RxP2HdrEgrOvflCnt);
  392. DEVICE_COUNTER(rx_p3_hdr_egr_ovfls, RxP3HdrEgrOvflCnt);
  393. DEVICE_COUNTER(rx_p4_hdr_egr_ovfls, RxP4HdrEgrOvflCnt);
  394. DEVICE_COUNTER(rx_p5_hdr_egr_ovfls, RxP5HdrEgrOvflCnt);
  395. DEVICE_COUNTER(rx_p6_hdr_egr_ovfls, RxP6HdrEgrOvflCnt);
  396. DEVICE_COUNTER(rx_p7_hdr_egr_ovfls, RxP7HdrEgrOvflCnt);
  397. DEVICE_COUNTER(rx_p8_hdr_egr_ovfls, RxP8HdrEgrOvflCnt);
  398. DEVICE_COUNTER(rx_pkey_mismatches, RxPKeyMismatchCnt);
  399. DEVICE_COUNTER(rx_tid_full_errs, RxTIDFullErrCnt);
  400. DEVICE_COUNTER(rx_tid_valid_errs, RxTIDValidErrCnt);
  401. DEVICE_COUNTER(rx_vcrc_errs, RxVCRCErrCnt);
  402. DEVICE_COUNTER(tx_data_pkts, TxDataPktCnt);
  403. DEVICE_COUNTER(tx_dropped_pkts, TxDroppedPktCnt);
  404. DEVICE_COUNTER(tx_dwords, TxDwordCnt);
  405. DEVICE_COUNTER(tx_flow_pkts, TxFlowPktCnt);
  406. DEVICE_COUNTER(tx_flow_stalls, TxFlowStallCnt);
  407. DEVICE_COUNTER(tx_len_errs, TxLenErrCnt);
  408. DEVICE_COUNTER(tx_max_min_len_errs, TxMaxMinLenErrCnt);
  409. DEVICE_COUNTER(tx_underruns, TxUnderrunCnt);
  410. DEVICE_COUNTER(tx_unsup_vl_errs, TxUnsupVLErrCnt);
  411. static struct attribute *dev_counter_attributes[] = {
  412. &dev_attr_ib_link_downeds.attr,
  413. &dev_attr_ib_link_err_recoveries.attr,
  414. &dev_attr_ib_status_changes.attr,
  415. &dev_attr_ib_symbol_errs.attr,
  416. &dev_attr_lb_flow_stalls.attr,
  417. &dev_attr_lb_ints.attr,
  418. &dev_attr_rx_bad_formats.attr,
  419. &dev_attr_rx_buf_ovfls.attr,
  420. &dev_attr_rx_data_pkts.attr,
  421. &dev_attr_rx_dropped_pkts.attr,
  422. &dev_attr_rx_dwords.attr,
  423. &dev_attr_rx_ebps.attr,
  424. &dev_attr_rx_flow_ctrl_errs.attr,
  425. &dev_attr_rx_flow_pkts.attr,
  426. &dev_attr_rx_icrc_errs.attr,
  427. &dev_attr_rx_len_errs.attr,
  428. &dev_attr_rx_link_problems.attr,
  429. &dev_attr_rx_lpcrc_errs.attr,
  430. &dev_attr_rx_max_min_len_errs.attr,
  431. &dev_attr_rx_p0_hdr_egr_ovfls.attr,
  432. &dev_attr_rx_p1_hdr_egr_ovfls.attr,
  433. &dev_attr_rx_p2_hdr_egr_ovfls.attr,
  434. &dev_attr_rx_p3_hdr_egr_ovfls.attr,
  435. &dev_attr_rx_p4_hdr_egr_ovfls.attr,
  436. &dev_attr_rx_p5_hdr_egr_ovfls.attr,
  437. &dev_attr_rx_p6_hdr_egr_ovfls.attr,
  438. &dev_attr_rx_p7_hdr_egr_ovfls.attr,
  439. &dev_attr_rx_p8_hdr_egr_ovfls.attr,
  440. &dev_attr_rx_pkey_mismatches.attr,
  441. &dev_attr_rx_tid_full_errs.attr,
  442. &dev_attr_rx_tid_valid_errs.attr,
  443. &dev_attr_rx_vcrc_errs.attr,
  444. &dev_attr_tx_data_pkts.attr,
  445. &dev_attr_tx_dropped_pkts.attr,
  446. &dev_attr_tx_dwords.attr,
  447. &dev_attr_tx_flow_pkts.attr,
  448. &dev_attr_tx_flow_stalls.attr,
  449. &dev_attr_tx_len_errs.attr,
  450. &dev_attr_tx_max_min_len_errs.attr,
  451. &dev_attr_tx_underruns.attr,
  452. &dev_attr_tx_unsup_vl_errs.attr,
  453. NULL
  454. };
  455. static struct attribute_group dev_counter_attr_group = {
  456. .name = "counters",
  457. .attrs = dev_counter_attributes
  458. };
  459. static ssize_t store_reset(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. int ret;
  466. if (count < 5 || memcmp(buf, "reset", 5)) {
  467. ret = -EINVAL;
  468. goto bail;
  469. }
  470. if (dd->ipath_flags & IPATH_DISABLED) {
  471. /*
  472. * post-reset init would re-enable interrupts, etc.
  473. * so don't allow reset on disabled devices. Not
  474. * perfect error, but about the best choice.
  475. */
  476. dev_info(dev,"Unit %d is disabled, can't reset\n",
  477. dd->ipath_unit);
  478. ret = -EINVAL;
  479. }
  480. ret = ipath_reset_device(dd->ipath_unit);
  481. bail:
  482. return ret<0 ? ret : count;
  483. }
  484. static ssize_t store_link_state(struct device *dev,
  485. struct device_attribute *attr,
  486. const char *buf,
  487. size_t count)
  488. {
  489. struct ipath_devdata *dd = dev_get_drvdata(dev);
  490. int ret, r;
  491. u16 state;
  492. ret = ipath_parse_ushort(buf, &state);
  493. if (ret < 0)
  494. goto invalid;
  495. r = ipath_layer_set_linkstate(dd, state);
  496. if (r < 0) {
  497. ret = r;
  498. goto bail;
  499. }
  500. goto bail;
  501. invalid:
  502. ipath_dev_err(dd, "attempt to set invalid link state\n");
  503. bail:
  504. return ret;
  505. }
  506. static ssize_t show_mtu(struct device *dev,
  507. struct device_attribute *attr,
  508. char *buf)
  509. {
  510. struct ipath_devdata *dd = dev_get_drvdata(dev);
  511. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_ibmtu);
  512. }
  513. static ssize_t store_mtu(struct device *dev,
  514. struct device_attribute *attr,
  515. const char *buf,
  516. size_t count)
  517. {
  518. struct ipath_devdata *dd = dev_get_drvdata(dev);
  519. ssize_t ret;
  520. u16 mtu = 0;
  521. int r;
  522. ret = ipath_parse_ushort(buf, &mtu);
  523. if (ret < 0)
  524. goto invalid;
  525. r = ipath_layer_set_mtu(dd, mtu);
  526. if (r < 0)
  527. ret = r;
  528. goto bail;
  529. invalid:
  530. ipath_dev_err(dd, "attempt to set invalid MTU\n");
  531. bail:
  532. return ret;
  533. }
  534. static ssize_t show_enabled(struct device *dev,
  535. struct device_attribute *attr,
  536. char *buf)
  537. {
  538. struct ipath_devdata *dd = dev_get_drvdata(dev);
  539. return scnprintf(buf, PAGE_SIZE, "%u\n",
  540. (dd->ipath_flags & IPATH_DISABLED) ? 0 : 1);
  541. }
  542. static ssize_t store_enabled(struct device *dev,
  543. struct device_attribute *attr,
  544. const char *buf,
  545. size_t count)
  546. {
  547. struct ipath_devdata *dd = dev_get_drvdata(dev);
  548. ssize_t ret;
  549. u16 enable = 0;
  550. ret = ipath_parse_ushort(buf, &enable);
  551. if (ret < 0) {
  552. ipath_dev_err(dd, "attempt to use non-numeric on enable\n");
  553. goto bail;
  554. }
  555. if (enable) {
  556. if (!(dd->ipath_flags & IPATH_DISABLED))
  557. goto bail;
  558. dev_info(dev, "Enabling unit %d\n", dd->ipath_unit);
  559. /* same as post-reset */
  560. ret = ipath_init_chip(dd, 1);
  561. if (ret)
  562. ipath_dev_err(dd, "Failed to enable unit %d\n",
  563. dd->ipath_unit);
  564. else {
  565. dd->ipath_flags &= ~IPATH_DISABLED;
  566. *dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED;
  567. }
  568. }
  569. else if (!(dd->ipath_flags & IPATH_DISABLED)) {
  570. dev_info(dev, "Disabling unit %d\n", dd->ipath_unit);
  571. ipath_shutdown_device(dd);
  572. dd->ipath_flags |= IPATH_DISABLED;
  573. *dd->ipath_statusp |= IPATH_STATUS_ADMIN_DISABLED;
  574. }
  575. bail:
  576. return ret;
  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(lid, S_IWUSR | S_IRUGO, show_lid, store_lid);
  590. static DEVICE_ATTR(link_state, S_IWUSR, NULL, store_link_state);
  591. static DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid);
  592. static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu);
  593. static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled);
  594. static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL);
  595. static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset);
  596. static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
  597. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  598. static DEVICE_ATTR(status_str, S_IRUGO, show_status_str, NULL);
  599. static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
  600. static DEVICE_ATTR(unit, S_IRUGO, show_unit, NULL);
  601. static struct attribute *dev_attributes[] = {
  602. &dev_attr_guid.attr,
  603. &dev_attr_lid.attr,
  604. &dev_attr_link_state.attr,
  605. &dev_attr_mlid.attr,
  606. &dev_attr_mtu.attr,
  607. &dev_attr_nguid.attr,
  608. &dev_attr_serial.attr,
  609. &dev_attr_status.attr,
  610. &dev_attr_status_str.attr,
  611. &dev_attr_boardversion.attr,
  612. &dev_attr_unit.attr,
  613. &dev_attr_enabled.attr,
  614. NULL
  615. };
  616. static struct attribute_group dev_attr_group = {
  617. .attrs = dev_attributes
  618. };
  619. /**
  620. * ipath_expose_reset - create a device reset file
  621. * @dev: the device structure
  622. *
  623. * Only expose a file that lets us reset the device after someone
  624. * enters diag mode. A device reset is quite likely to crash the
  625. * machine entirely, so we don't want to normally make it
  626. * available.
  627. */
  628. int ipath_expose_reset(struct device *dev)
  629. {
  630. return device_create_file(dev, &dev_attr_reset);
  631. }
  632. int ipath_driver_create_group(struct device_driver *drv)
  633. {
  634. int ret;
  635. ret = sysfs_create_group(&drv->kobj, &driver_attr_group);
  636. if (ret)
  637. goto bail;
  638. ret = sysfs_create_group(&drv->kobj, &driver_stat_attr_group);
  639. if (ret)
  640. sysfs_remove_group(&drv->kobj, &driver_attr_group);
  641. bail:
  642. return ret;
  643. }
  644. void ipath_driver_remove_group(struct device_driver *drv)
  645. {
  646. sysfs_remove_group(&drv->kobj, &driver_stat_attr_group);
  647. sysfs_remove_group(&drv->kobj, &driver_attr_group);
  648. }
  649. int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
  650. {
  651. int ret;
  652. char unit[5];
  653. ret = sysfs_create_group(&dev->kobj, &dev_attr_group);
  654. if (ret)
  655. goto bail;
  656. ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group);
  657. if (ret)
  658. goto bail_attrs;
  659. snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
  660. ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit);
  661. if (ret == 0)
  662. goto bail;
  663. sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
  664. bail_attrs:
  665. sysfs_remove_group(&dev->kobj, &dev_attr_group);
  666. bail:
  667. return ret;
  668. }
  669. void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd)
  670. {
  671. char unit[5];
  672. snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
  673. sysfs_remove_link(&dev->driver->kobj, unit);
  674. sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
  675. sysfs_remove_group(&dev->kobj, &dev_attr_group);
  676. device_remove_file(dev, &dev_attr_reset);
  677. }