qib_sysfs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /*
  2. * Copyright (c) 2006, 2007, 2008, 2009 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 "qib.h"
  35. /**
  36. * qib_parse_ushort - parse an unsigned short value in an arbitrary base
  37. * @str: the string containing the number
  38. * @valp: where to put the result
  39. *
  40. * Returns the number of bytes consumed, or negative value on error.
  41. */
  42. static int qib_parse_ushort(const char *str, unsigned short *valp)
  43. {
  44. unsigned long val;
  45. char *end;
  46. int ret;
  47. if (!isdigit(str[0])) {
  48. ret = -EINVAL;
  49. goto bail;
  50. }
  51. val = simple_strtoul(str, &end, 0);
  52. if (val > 0xffff) {
  53. ret = -EINVAL;
  54. goto bail;
  55. }
  56. *valp = val;
  57. ret = end + 1 - str;
  58. if (ret == 0)
  59. ret = -EINVAL;
  60. bail:
  61. return ret;
  62. }
  63. /* start of per-port functions */
  64. /*
  65. * Get/Set heartbeat enable. OR of 1=enabled, 2=auto
  66. */
  67. static ssize_t show_hrtbt_enb(struct qib_pportdata *ppd, char *buf)
  68. {
  69. struct qib_devdata *dd = ppd->dd;
  70. int ret;
  71. ret = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_HRTBT);
  72. ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
  73. return ret;
  74. }
  75. static ssize_t store_hrtbt_enb(struct qib_pportdata *ppd, const char *buf,
  76. size_t count)
  77. {
  78. struct qib_devdata *dd = ppd->dd;
  79. int ret;
  80. u16 val;
  81. ret = qib_parse_ushort(buf, &val);
  82. /*
  83. * Set the "intentional" heartbeat enable per either of
  84. * "Enable" and "Auto", as these are normally set together.
  85. * This bit is consulted when leaving loopback mode,
  86. * because entering loopback mode overrides it and automatically
  87. * disables heartbeat.
  88. */
  89. if (ret >= 0)
  90. ret = dd->f_set_ib_cfg(ppd, QIB_IB_CFG_HRTBT, val);
  91. if (ret < 0)
  92. qib_dev_err(dd, "attempt to set invalid Heartbeat enable\n");
  93. return ret < 0 ? ret : count;
  94. }
  95. static ssize_t store_loopback(struct qib_pportdata *ppd, const char *buf,
  96. size_t count)
  97. {
  98. struct qib_devdata *dd = ppd->dd;
  99. int ret = count, r;
  100. r = dd->f_set_ib_loopback(ppd, buf);
  101. if (r < 0)
  102. ret = r;
  103. return ret;
  104. }
  105. static ssize_t store_led_override(struct qib_pportdata *ppd, const char *buf,
  106. size_t count)
  107. {
  108. struct qib_devdata *dd = ppd->dd;
  109. int ret;
  110. u16 val;
  111. ret = qib_parse_ushort(buf, &val);
  112. if (ret > 0)
  113. qib_set_led_override(ppd, val);
  114. else
  115. qib_dev_err(dd, "attempt to set invalid LED override\n");
  116. return ret < 0 ? ret : count;
  117. }
  118. static ssize_t show_status(struct qib_pportdata *ppd, char *buf)
  119. {
  120. ssize_t ret;
  121. if (!ppd->statusp)
  122. ret = -EINVAL;
  123. else
  124. ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n",
  125. (unsigned long long) *(ppd->statusp));
  126. return ret;
  127. }
  128. /*
  129. * For userland compatibility, these offsets must remain fixed.
  130. * They are strings for QIB_STATUS_*
  131. */
  132. static const char * const qib_status_str[] = {
  133. "Initted",
  134. "",
  135. "",
  136. "",
  137. "",
  138. "Present",
  139. "IB_link_up",
  140. "IB_configured",
  141. "",
  142. "Fatal_Hardware_Error",
  143. NULL,
  144. };
  145. static ssize_t show_status_str(struct qib_pportdata *ppd, char *buf)
  146. {
  147. int i, any;
  148. u64 s;
  149. ssize_t ret;
  150. if (!ppd->statusp) {
  151. ret = -EINVAL;
  152. goto bail;
  153. }
  154. s = *(ppd->statusp);
  155. *buf = '\0';
  156. for (any = i = 0; s && qib_status_str[i]; i++) {
  157. if (s & 1) {
  158. /* if overflow */
  159. if (any && strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
  160. break;
  161. if (strlcat(buf, qib_status_str[i], PAGE_SIZE) >=
  162. PAGE_SIZE)
  163. break;
  164. any = 1;
  165. }
  166. s >>= 1;
  167. }
  168. if (any)
  169. strlcat(buf, "\n", PAGE_SIZE);
  170. ret = strlen(buf);
  171. bail:
  172. return ret;
  173. }
  174. /* end of per-port functions */
  175. /*
  176. * Start of per-port file structures and support code
  177. * Because we are fitting into other infrastructure, we have to supply the
  178. * full set of kobject/sysfs_ops structures and routines.
  179. */
  180. #define QIB_PORT_ATTR(name, mode, show, store) \
  181. static struct qib_port_attr qib_port_attr_##name = \
  182. __ATTR(name, mode, show, store)
  183. struct qib_port_attr {
  184. struct attribute attr;
  185. ssize_t (*show)(struct qib_pportdata *, char *);
  186. ssize_t (*store)(struct qib_pportdata *, const char *, size_t);
  187. };
  188. QIB_PORT_ATTR(loopback, S_IWUSR, NULL, store_loopback);
  189. QIB_PORT_ATTR(led_override, S_IWUSR, NULL, store_led_override);
  190. QIB_PORT_ATTR(hrtbt_enable, S_IWUSR | S_IRUGO, show_hrtbt_enb,
  191. store_hrtbt_enb);
  192. QIB_PORT_ATTR(status, S_IRUGO, show_status, NULL);
  193. QIB_PORT_ATTR(status_str, S_IRUGO, show_status_str, NULL);
  194. static struct attribute *port_default_attributes[] = {
  195. &qib_port_attr_loopback.attr,
  196. &qib_port_attr_led_override.attr,
  197. &qib_port_attr_hrtbt_enable.attr,
  198. &qib_port_attr_status.attr,
  199. &qib_port_attr_status_str.attr,
  200. NULL
  201. };
  202. static ssize_t qib_portattr_show(struct kobject *kobj,
  203. struct attribute *attr, char *buf)
  204. {
  205. struct qib_port_attr *pattr =
  206. container_of(attr, struct qib_port_attr, attr);
  207. struct qib_pportdata *ppd =
  208. container_of(kobj, struct qib_pportdata, pport_kobj);
  209. return pattr->show(ppd, buf);
  210. }
  211. static ssize_t qib_portattr_store(struct kobject *kobj,
  212. struct attribute *attr, const char *buf, size_t len)
  213. {
  214. struct qib_port_attr *pattr =
  215. container_of(attr, struct qib_port_attr, attr);
  216. struct qib_pportdata *ppd =
  217. container_of(kobj, struct qib_pportdata, pport_kobj);
  218. return pattr->store(ppd, buf, len);
  219. }
  220. static void qib_port_release(struct kobject *kobj)
  221. {
  222. /* nothing to do since memory is freed by qib_free_devdata() */
  223. }
  224. static const struct sysfs_ops qib_port_ops = {
  225. .show = qib_portattr_show,
  226. .store = qib_portattr_store,
  227. };
  228. static struct kobj_type qib_port_ktype = {
  229. .release = qib_port_release,
  230. .sysfs_ops = &qib_port_ops,
  231. .default_attrs = port_default_attributes
  232. };
  233. /* Start sl2vl */
  234. #define QIB_SL2VL_ATTR(N) \
  235. static struct qib_sl2vl_attr qib_sl2vl_attr_##N = { \
  236. .attr = { .name = __stringify(N), .mode = 0444 }, \
  237. .sl = N \
  238. }
  239. struct qib_sl2vl_attr {
  240. struct attribute attr;
  241. int sl;
  242. };
  243. QIB_SL2VL_ATTR(0);
  244. QIB_SL2VL_ATTR(1);
  245. QIB_SL2VL_ATTR(2);
  246. QIB_SL2VL_ATTR(3);
  247. QIB_SL2VL_ATTR(4);
  248. QIB_SL2VL_ATTR(5);
  249. QIB_SL2VL_ATTR(6);
  250. QIB_SL2VL_ATTR(7);
  251. QIB_SL2VL_ATTR(8);
  252. QIB_SL2VL_ATTR(9);
  253. QIB_SL2VL_ATTR(10);
  254. QIB_SL2VL_ATTR(11);
  255. QIB_SL2VL_ATTR(12);
  256. QIB_SL2VL_ATTR(13);
  257. QIB_SL2VL_ATTR(14);
  258. QIB_SL2VL_ATTR(15);
  259. static struct attribute *sl2vl_default_attributes[] = {
  260. &qib_sl2vl_attr_0.attr,
  261. &qib_sl2vl_attr_1.attr,
  262. &qib_sl2vl_attr_2.attr,
  263. &qib_sl2vl_attr_3.attr,
  264. &qib_sl2vl_attr_4.attr,
  265. &qib_sl2vl_attr_5.attr,
  266. &qib_sl2vl_attr_6.attr,
  267. &qib_sl2vl_attr_7.attr,
  268. &qib_sl2vl_attr_8.attr,
  269. &qib_sl2vl_attr_9.attr,
  270. &qib_sl2vl_attr_10.attr,
  271. &qib_sl2vl_attr_11.attr,
  272. &qib_sl2vl_attr_12.attr,
  273. &qib_sl2vl_attr_13.attr,
  274. &qib_sl2vl_attr_14.attr,
  275. &qib_sl2vl_attr_15.attr,
  276. NULL
  277. };
  278. static ssize_t sl2vl_attr_show(struct kobject *kobj, struct attribute *attr,
  279. char *buf)
  280. {
  281. struct qib_sl2vl_attr *sattr =
  282. container_of(attr, struct qib_sl2vl_attr, attr);
  283. struct qib_pportdata *ppd =
  284. container_of(kobj, struct qib_pportdata, sl2vl_kobj);
  285. struct qib_ibport *qibp = &ppd->ibport_data;
  286. return sprintf(buf, "%u\n", qibp->sl_to_vl[sattr->sl]);
  287. }
  288. static const struct sysfs_ops qib_sl2vl_ops = {
  289. .show = sl2vl_attr_show,
  290. };
  291. static struct kobj_type qib_sl2vl_ktype = {
  292. .release = qib_port_release,
  293. .sysfs_ops = &qib_sl2vl_ops,
  294. .default_attrs = sl2vl_default_attributes
  295. };
  296. /* End sl2vl */
  297. /* Start diag_counters */
  298. #define QIB_DIAGC_ATTR(N) \
  299. static struct qib_diagc_attr qib_diagc_attr_##N = { \
  300. .attr = { .name = __stringify(N), .mode = 0664 }, \
  301. .counter = offsetof(struct qib_ibport, n_##N) \
  302. }
  303. struct qib_diagc_attr {
  304. struct attribute attr;
  305. size_t counter;
  306. };
  307. QIB_DIAGC_ATTR(rc_resends);
  308. QIB_DIAGC_ATTR(rc_acks);
  309. QIB_DIAGC_ATTR(rc_qacks);
  310. QIB_DIAGC_ATTR(rc_delayed_comp);
  311. QIB_DIAGC_ATTR(seq_naks);
  312. QIB_DIAGC_ATTR(rdma_seq);
  313. QIB_DIAGC_ATTR(rnr_naks);
  314. QIB_DIAGC_ATTR(other_naks);
  315. QIB_DIAGC_ATTR(rc_timeouts);
  316. QIB_DIAGC_ATTR(loop_pkts);
  317. QIB_DIAGC_ATTR(pkt_drops);
  318. QIB_DIAGC_ATTR(dmawait);
  319. QIB_DIAGC_ATTR(unaligned);
  320. QIB_DIAGC_ATTR(rc_dupreq);
  321. QIB_DIAGC_ATTR(rc_seqnak);
  322. static struct attribute *diagc_default_attributes[] = {
  323. &qib_diagc_attr_rc_resends.attr,
  324. &qib_diagc_attr_rc_acks.attr,
  325. &qib_diagc_attr_rc_qacks.attr,
  326. &qib_diagc_attr_rc_delayed_comp.attr,
  327. &qib_diagc_attr_seq_naks.attr,
  328. &qib_diagc_attr_rdma_seq.attr,
  329. &qib_diagc_attr_rnr_naks.attr,
  330. &qib_diagc_attr_other_naks.attr,
  331. &qib_diagc_attr_rc_timeouts.attr,
  332. &qib_diagc_attr_loop_pkts.attr,
  333. &qib_diagc_attr_pkt_drops.attr,
  334. &qib_diagc_attr_dmawait.attr,
  335. &qib_diagc_attr_unaligned.attr,
  336. &qib_diagc_attr_rc_dupreq.attr,
  337. &qib_diagc_attr_rc_seqnak.attr,
  338. NULL
  339. };
  340. static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
  341. char *buf)
  342. {
  343. struct qib_diagc_attr *dattr =
  344. container_of(attr, struct qib_diagc_attr, attr);
  345. struct qib_pportdata *ppd =
  346. container_of(kobj, struct qib_pportdata, diagc_kobj);
  347. struct qib_ibport *qibp = &ppd->ibport_data;
  348. return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter));
  349. }
  350. static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
  351. const char *buf, size_t size)
  352. {
  353. struct qib_diagc_attr *dattr =
  354. container_of(attr, struct qib_diagc_attr, attr);
  355. struct qib_pportdata *ppd =
  356. container_of(kobj, struct qib_pportdata, diagc_kobj);
  357. struct qib_ibport *qibp = &ppd->ibport_data;
  358. char *endp;
  359. long val = simple_strtol(buf, &endp, 0);
  360. if (val < 0 || endp == buf)
  361. return -EINVAL;
  362. *(u32 *)((char *) qibp + dattr->counter) = val;
  363. return size;
  364. }
  365. static const struct sysfs_ops qib_diagc_ops = {
  366. .show = diagc_attr_show,
  367. .store = diagc_attr_store,
  368. };
  369. static struct kobj_type qib_diagc_ktype = {
  370. .release = qib_port_release,
  371. .sysfs_ops = &qib_diagc_ops,
  372. .default_attrs = diagc_default_attributes
  373. };
  374. /* End diag_counters */
  375. /* end of per-port file structures and support code */
  376. /*
  377. * Start of per-unit (or driver, in some cases, but replicated
  378. * per unit) functions (these get a device *)
  379. */
  380. static ssize_t show_rev(struct device *device, struct device_attribute *attr,
  381. char *buf)
  382. {
  383. struct qib_ibdev *dev =
  384. container_of(device, struct qib_ibdev, ibdev.dev);
  385. return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev);
  386. }
  387. static ssize_t show_hca(struct device *device, struct device_attribute *attr,
  388. char *buf)
  389. {
  390. struct qib_ibdev *dev =
  391. container_of(device, struct qib_ibdev, ibdev.dev);
  392. struct qib_devdata *dd = dd_from_dev(dev);
  393. int ret;
  394. if (!dd->boardname)
  395. ret = -EINVAL;
  396. else
  397. ret = scnprintf(buf, PAGE_SIZE, "%s\n", dd->boardname);
  398. return ret;
  399. }
  400. static ssize_t show_version(struct device *device,
  401. struct device_attribute *attr, char *buf)
  402. {
  403. /* The string printed here is already newline-terminated. */
  404. return scnprintf(buf, PAGE_SIZE, "%s", (char *)ib_qib_version);
  405. }
  406. static ssize_t show_boardversion(struct device *device,
  407. struct device_attribute *attr, char *buf)
  408. {
  409. struct qib_ibdev *dev =
  410. container_of(device, struct qib_ibdev, ibdev.dev);
  411. struct qib_devdata *dd = dd_from_dev(dev);
  412. /* The string printed here is already newline-terminated. */
  413. return scnprintf(buf, PAGE_SIZE, "%s", dd->boardversion);
  414. }
  415. static ssize_t show_localbus_info(struct device *device,
  416. struct device_attribute *attr, char *buf)
  417. {
  418. struct qib_ibdev *dev =
  419. container_of(device, struct qib_ibdev, ibdev.dev);
  420. struct qib_devdata *dd = dd_from_dev(dev);
  421. /* The string printed here is already newline-terminated. */
  422. return scnprintf(buf, PAGE_SIZE, "%s", dd->lbus_info);
  423. }
  424. static ssize_t show_nctxts(struct device *device,
  425. struct device_attribute *attr, char *buf)
  426. {
  427. struct qib_ibdev *dev =
  428. container_of(device, struct qib_ibdev, ibdev.dev);
  429. struct qib_devdata *dd = dd_from_dev(dev);
  430. /* Return the number of user ports (contexts) available. */
  431. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->cfgctxts -
  432. dd->first_user_ctxt);
  433. }
  434. static ssize_t show_nfreectxts(struct device *device,
  435. struct device_attribute *attr, char *buf)
  436. {
  437. struct qib_ibdev *dev =
  438. container_of(device, struct qib_ibdev, ibdev.dev);
  439. struct qib_devdata *dd = dd_from_dev(dev);
  440. /* Return the number of free user ports (contexts) available. */
  441. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->freectxts);
  442. }
  443. static ssize_t show_serial(struct device *device,
  444. struct device_attribute *attr, char *buf)
  445. {
  446. struct qib_ibdev *dev =
  447. container_of(device, struct qib_ibdev, ibdev.dev);
  448. struct qib_devdata *dd = dd_from_dev(dev);
  449. buf[sizeof dd->serial] = '\0';
  450. memcpy(buf, dd->serial, sizeof dd->serial);
  451. strcat(buf, "\n");
  452. return strlen(buf);
  453. }
  454. static ssize_t store_chip_reset(struct device *device,
  455. struct device_attribute *attr, const char *buf,
  456. size_t count)
  457. {
  458. struct qib_ibdev *dev =
  459. container_of(device, struct qib_ibdev, ibdev.dev);
  460. struct qib_devdata *dd = dd_from_dev(dev);
  461. int ret;
  462. if (count < 5 || memcmp(buf, "reset", 5) || !dd->diag_client) {
  463. ret = -EINVAL;
  464. goto bail;
  465. }
  466. ret = qib_reset_device(dd->unit);
  467. bail:
  468. return ret < 0 ? ret : count;
  469. }
  470. /*
  471. * Dump tempsense regs. in decimal, to ease shell-scripts.
  472. */
  473. static ssize_t show_tempsense(struct device *device,
  474. struct device_attribute *attr, char *buf)
  475. {
  476. struct qib_ibdev *dev =
  477. container_of(device, struct qib_ibdev, ibdev.dev);
  478. struct qib_devdata *dd = dd_from_dev(dev);
  479. int ret;
  480. int idx;
  481. u8 regvals[8];
  482. ret = -ENXIO;
  483. for (idx = 0; idx < 8; ++idx) {
  484. if (idx == 6)
  485. continue;
  486. ret = dd->f_tempsense_rd(dd, idx);
  487. if (ret < 0)
  488. break;
  489. regvals[idx] = ret;
  490. }
  491. if (idx == 8)
  492. ret = scnprintf(buf, PAGE_SIZE, "%d %d %02X %02X %d %d\n",
  493. *(signed char *)(regvals),
  494. *(signed char *)(regvals + 1),
  495. regvals[2], regvals[3],
  496. *(signed char *)(regvals + 5),
  497. *(signed char *)(regvals + 7));
  498. return ret;
  499. }
  500. /*
  501. * end of per-unit (or driver, in some cases, but replicated
  502. * per unit) functions
  503. */
  504. /* start of per-unit file structures and support code */
  505. static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  506. static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
  507. static DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
  508. static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
  509. static DEVICE_ATTR(nctxts, S_IRUGO, show_nctxts, NULL);
  510. static DEVICE_ATTR(nfreectxts, S_IRUGO, show_nfreectxts, NULL);
  511. static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
  512. static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
  513. static DEVICE_ATTR(tempsense, S_IRUGO, show_tempsense, NULL);
  514. static DEVICE_ATTR(localbus_info, S_IRUGO, show_localbus_info, NULL);
  515. static DEVICE_ATTR(chip_reset, S_IWUSR, NULL, store_chip_reset);
  516. static struct device_attribute *qib_attributes[] = {
  517. &dev_attr_hw_rev,
  518. &dev_attr_hca_type,
  519. &dev_attr_board_id,
  520. &dev_attr_version,
  521. &dev_attr_nctxts,
  522. &dev_attr_nfreectxts,
  523. &dev_attr_serial,
  524. &dev_attr_boardversion,
  525. &dev_attr_tempsense,
  526. &dev_attr_localbus_info,
  527. &dev_attr_chip_reset,
  528. };
  529. int qib_create_port_files(struct ib_device *ibdev, u8 port_num,
  530. struct kobject *kobj)
  531. {
  532. struct qib_pportdata *ppd;
  533. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  534. int ret;
  535. if (!port_num || port_num > dd->num_pports) {
  536. qib_dev_err(dd, "Skipping infiniband class with "
  537. "invalid port %u\n", port_num);
  538. ret = -ENODEV;
  539. goto bail;
  540. }
  541. ppd = &dd->pport[port_num - 1];
  542. ret = kobject_init_and_add(&ppd->pport_kobj, &qib_port_ktype, kobj,
  543. "linkcontrol");
  544. if (ret) {
  545. qib_dev_err(dd, "Skipping linkcontrol sysfs info, "
  546. "(err %d) port %u\n", ret, port_num);
  547. goto bail;
  548. }
  549. kobject_uevent(&ppd->pport_kobj, KOBJ_ADD);
  550. ret = kobject_init_and_add(&ppd->sl2vl_kobj, &qib_sl2vl_ktype, kobj,
  551. "sl2vl");
  552. if (ret) {
  553. qib_dev_err(dd, "Skipping sl2vl sysfs info, "
  554. "(err %d) port %u\n", ret, port_num);
  555. goto bail_sl;
  556. }
  557. kobject_uevent(&ppd->sl2vl_kobj, KOBJ_ADD);
  558. ret = kobject_init_and_add(&ppd->diagc_kobj, &qib_diagc_ktype, kobj,
  559. "diag_counters");
  560. if (ret) {
  561. qib_dev_err(dd, "Skipping diag_counters sysfs info, "
  562. "(err %d) port %u\n", ret, port_num);
  563. goto bail_diagc;
  564. }
  565. kobject_uevent(&ppd->diagc_kobj, KOBJ_ADD);
  566. return 0;
  567. bail_diagc:
  568. kobject_put(&ppd->sl2vl_kobj);
  569. bail_sl:
  570. kobject_put(&ppd->pport_kobj);
  571. bail:
  572. return ret;
  573. }
  574. /*
  575. * Register and create our files in /sys/class/infiniband.
  576. */
  577. int qib_verbs_register_sysfs(struct qib_devdata *dd)
  578. {
  579. struct ib_device *dev = &dd->verbs_dev.ibdev;
  580. int i, ret;
  581. for (i = 0; i < ARRAY_SIZE(qib_attributes); ++i) {
  582. ret = device_create_file(&dev->dev, qib_attributes[i]);
  583. if (ret)
  584. return ret;
  585. }
  586. return 0;
  587. }
  588. /*
  589. * Unregister and remove our files in /sys/class/infiniband.
  590. */
  591. void qib_verbs_unregister_sysfs(struct qib_devdata *dd)
  592. {
  593. struct qib_pportdata *ppd;
  594. int i;
  595. for (i = 0; i < dd->num_pports; i++) {
  596. ppd = &dd->pport[i];
  597. kobject_put(&ppd->pport_kobj);
  598. kobject_put(&ppd->sl2vl_kobj);
  599. }
  600. }