qib_sysfs.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. * Copyright (c) 2012 Intel Corporation. All rights reserved.
  3. * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
  4. * Copyright (c) 2006 PathScale, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/ctype.h>
  35. #include <rdma/ib_sysfs.h>
  36. #include "qib.h"
  37. #include "qib_mad.h"
  38. static struct qib_pportdata *qib_get_pportdata_kobj(struct kobject *kobj)
  39. {
  40. u32 port_num;
  41. struct ib_device *ibdev = ib_port_sysfs_get_ibdev_kobj(kobj, &port_num);
  42. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  43. return &dd->pport[port_num - 1];
  44. }
  45. /*
  46. * Get/Set heartbeat enable. OR of 1=enabled, 2=auto
  47. */
  48. static ssize_t hrtbt_enable_show(struct ib_device *ibdev, u32 port_num,
  49. struct ib_port_attribute *attr, char *buf)
  50. {
  51. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  52. struct qib_pportdata *ppd = &dd->pport[port_num - 1];
  53. return sysfs_emit(buf, "%d\n", dd->f_get_ib_cfg(ppd, QIB_IB_CFG_HRTBT));
  54. }
  55. static ssize_t hrtbt_enable_store(struct ib_device *ibdev, u32 port_num,
  56. struct ib_port_attribute *attr,
  57. const char *buf, size_t count)
  58. {
  59. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  60. struct qib_pportdata *ppd = &dd->pport[port_num - 1];
  61. int ret;
  62. u16 val;
  63. ret = kstrtou16(buf, 0, &val);
  64. if (ret) {
  65. qib_dev_err(dd, "attempt to set invalid Heartbeat enable\n");
  66. return ret;
  67. }
  68. /*
  69. * Set the "intentional" heartbeat enable per either of
  70. * "Enable" and "Auto", as these are normally set together.
  71. * This bit is consulted when leaving loopback mode,
  72. * because entering loopback mode overrides it and automatically
  73. * disables heartbeat.
  74. */
  75. ret = dd->f_set_ib_cfg(ppd, QIB_IB_CFG_HRTBT, val);
  76. return ret < 0 ? ret : count;
  77. }
  78. static IB_PORT_ATTR_RW(hrtbt_enable);
  79. static ssize_t loopback_store(struct ib_device *ibdev, u32 port_num,
  80. struct ib_port_attribute *attr, const char *buf,
  81. size_t count)
  82. {
  83. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  84. struct qib_pportdata *ppd = &dd->pport[port_num - 1];
  85. int ret = count, r;
  86. r = dd->f_set_ib_loopback(ppd, buf);
  87. if (r < 0)
  88. ret = r;
  89. return ret;
  90. }
  91. static IB_PORT_ATTR_WO(loopback);
  92. static ssize_t led_override_store(struct ib_device *ibdev, u32 port_num,
  93. struct ib_port_attribute *attr,
  94. const char *buf, size_t count)
  95. {
  96. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  97. struct qib_pportdata *ppd = &dd->pport[port_num - 1];
  98. int ret;
  99. u16 val;
  100. ret = kstrtou16(buf, 0, &val);
  101. if (ret) {
  102. qib_dev_err(dd, "attempt to set invalid LED override\n");
  103. return ret;
  104. }
  105. qib_set_led_override(ppd, val);
  106. return count;
  107. }
  108. static IB_PORT_ATTR_WO(led_override);
  109. static ssize_t status_show(struct ib_device *ibdev, u32 port_num,
  110. struct ib_port_attribute *attr, char *buf)
  111. {
  112. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  113. struct qib_pportdata *ppd = &dd->pport[port_num - 1];
  114. if (!ppd->statusp)
  115. return -EINVAL;
  116. return sysfs_emit(buf, "0x%llx\n", (unsigned long long)*(ppd->statusp));
  117. }
  118. static IB_PORT_ATTR_RO(status);
  119. /*
  120. * For userland compatibility, these offsets must remain fixed.
  121. * They are strings for QIB_STATUS_*
  122. */
  123. static const char * const qib_status_str[] = {
  124. "Initted",
  125. "",
  126. "",
  127. "",
  128. "",
  129. "Present",
  130. "IB_link_up",
  131. "IB_configured",
  132. "",
  133. "Fatal_Hardware_Error",
  134. NULL,
  135. };
  136. static ssize_t status_str_show(struct ib_device *ibdev, u32 port_num,
  137. struct ib_port_attribute *attr, char *buf)
  138. {
  139. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  140. struct qib_pportdata *ppd = &dd->pport[port_num - 1];
  141. int i, any;
  142. u64 s;
  143. ssize_t ret;
  144. if (!ppd->statusp) {
  145. ret = -EINVAL;
  146. goto bail;
  147. }
  148. s = *(ppd->statusp);
  149. *buf = '\0';
  150. for (any = i = 0; s && qib_status_str[i]; i++) {
  151. if (s & 1) {
  152. /* if overflow */
  153. if (any && strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
  154. break;
  155. if (strlcat(buf, qib_status_str[i], PAGE_SIZE) >=
  156. PAGE_SIZE)
  157. break;
  158. any = 1;
  159. }
  160. s >>= 1;
  161. }
  162. if (any)
  163. strlcat(buf, "\n", PAGE_SIZE);
  164. ret = strlen(buf);
  165. bail:
  166. return ret;
  167. }
  168. static IB_PORT_ATTR_RO(status_str);
  169. /* end of per-port functions */
  170. static struct attribute *port_linkcontrol_attributes[] = {
  171. &ib_port_attr_loopback.attr,
  172. &ib_port_attr_led_override.attr,
  173. &ib_port_attr_hrtbt_enable.attr,
  174. &ib_port_attr_status.attr,
  175. &ib_port_attr_status_str.attr,
  176. NULL
  177. };
  178. static const struct attribute_group port_linkcontrol_group = {
  179. .name = "linkcontrol",
  180. .attrs = port_linkcontrol_attributes,
  181. };
  182. /*
  183. * Start of per-port congestion control structures and support code
  184. */
  185. /*
  186. * Congestion control table size followed by table entries
  187. */
  188. static ssize_t cc_table_bin_read(struct file *filp, struct kobject *kobj,
  189. struct bin_attribute *bin_attr, char *buf,
  190. loff_t pos, size_t count)
  191. {
  192. struct qib_pportdata *ppd = qib_get_pportdata_kobj(kobj);
  193. int ret;
  194. if (!qib_cc_table_size || !ppd->ccti_entries_shadow)
  195. return -EINVAL;
  196. ret = ppd->total_cct_entry * sizeof(struct ib_cc_table_entry_shadow)
  197. + sizeof(__be16);
  198. if (pos > ret)
  199. return -EINVAL;
  200. if (count > ret - pos)
  201. count = ret - pos;
  202. if (!count)
  203. return count;
  204. spin_lock(&ppd->cc_shadow_lock);
  205. memcpy(buf, ppd->ccti_entries_shadow, count);
  206. spin_unlock(&ppd->cc_shadow_lock);
  207. return count;
  208. }
  209. static BIN_ATTR_RO(cc_table_bin, PAGE_SIZE);
  210. /*
  211. * Congestion settings: port control, control map and an array of 16
  212. * entries for the congestion entries - increase, timer, event log
  213. * trigger threshold and the minimum injection rate delay.
  214. */
  215. static ssize_t cc_setting_bin_read(struct file *filp, struct kobject *kobj,
  216. struct bin_attribute *bin_attr, char *buf,
  217. loff_t pos, size_t count)
  218. {
  219. struct qib_pportdata *ppd = qib_get_pportdata_kobj(kobj);
  220. int ret;
  221. if (!qib_cc_table_size || !ppd->congestion_entries_shadow)
  222. return -EINVAL;
  223. ret = sizeof(struct ib_cc_congestion_setting_attr_shadow);
  224. if (pos > ret)
  225. return -EINVAL;
  226. if (count > ret - pos)
  227. count = ret - pos;
  228. if (!count)
  229. return count;
  230. spin_lock(&ppd->cc_shadow_lock);
  231. memcpy(buf, ppd->congestion_entries_shadow, count);
  232. spin_unlock(&ppd->cc_shadow_lock);
  233. return count;
  234. }
  235. static BIN_ATTR_RO(cc_setting_bin, PAGE_SIZE);
  236. static struct bin_attribute *port_ccmgta_attributes[] = {
  237. &bin_attr_cc_setting_bin,
  238. &bin_attr_cc_table_bin,
  239. NULL,
  240. };
  241. static umode_t qib_ccmgta_is_bin_visible(struct kobject *kobj,
  242. struct bin_attribute *attr, int n)
  243. {
  244. struct qib_pportdata *ppd = qib_get_pportdata_kobj(kobj);
  245. if (!qib_cc_table_size || !ppd->congestion_entries_shadow)
  246. return 0;
  247. return attr->attr.mode;
  248. }
  249. static const struct attribute_group port_ccmgta_attribute_group = {
  250. .name = "CCMgtA",
  251. .is_bin_visible = qib_ccmgta_is_bin_visible,
  252. .bin_attrs = port_ccmgta_attributes,
  253. };
  254. /* Start sl2vl */
  255. struct qib_sl2vl_attr {
  256. struct ib_port_attribute attr;
  257. int sl;
  258. };
  259. static ssize_t sl2vl_attr_show(struct ib_device *ibdev, u32 port_num,
  260. struct ib_port_attribute *attr, char *buf)
  261. {
  262. struct qib_sl2vl_attr *sattr =
  263. container_of(attr, struct qib_sl2vl_attr, attr);
  264. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  265. struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
  266. return sysfs_emit(buf, "%u\n", qibp->sl_to_vl[sattr->sl]);
  267. }
  268. #define QIB_SL2VL_ATTR(N) \
  269. static struct qib_sl2vl_attr qib_sl2vl_attr_##N = { \
  270. .attr = __ATTR(N, 0444, sl2vl_attr_show, NULL), \
  271. .sl = N, \
  272. }
  273. QIB_SL2VL_ATTR(0);
  274. QIB_SL2VL_ATTR(1);
  275. QIB_SL2VL_ATTR(2);
  276. QIB_SL2VL_ATTR(3);
  277. QIB_SL2VL_ATTR(4);
  278. QIB_SL2VL_ATTR(5);
  279. QIB_SL2VL_ATTR(6);
  280. QIB_SL2VL_ATTR(7);
  281. QIB_SL2VL_ATTR(8);
  282. QIB_SL2VL_ATTR(9);
  283. QIB_SL2VL_ATTR(10);
  284. QIB_SL2VL_ATTR(11);
  285. QIB_SL2VL_ATTR(12);
  286. QIB_SL2VL_ATTR(13);
  287. QIB_SL2VL_ATTR(14);
  288. QIB_SL2VL_ATTR(15);
  289. static struct attribute *port_sl2vl_attributes[] = {
  290. &qib_sl2vl_attr_0.attr.attr,
  291. &qib_sl2vl_attr_1.attr.attr,
  292. &qib_sl2vl_attr_2.attr.attr,
  293. &qib_sl2vl_attr_3.attr.attr,
  294. &qib_sl2vl_attr_4.attr.attr,
  295. &qib_sl2vl_attr_5.attr.attr,
  296. &qib_sl2vl_attr_6.attr.attr,
  297. &qib_sl2vl_attr_7.attr.attr,
  298. &qib_sl2vl_attr_8.attr.attr,
  299. &qib_sl2vl_attr_9.attr.attr,
  300. &qib_sl2vl_attr_10.attr.attr,
  301. &qib_sl2vl_attr_11.attr.attr,
  302. &qib_sl2vl_attr_12.attr.attr,
  303. &qib_sl2vl_attr_13.attr.attr,
  304. &qib_sl2vl_attr_14.attr.attr,
  305. &qib_sl2vl_attr_15.attr.attr,
  306. NULL
  307. };
  308. static const struct attribute_group port_sl2vl_group = {
  309. .name = "sl2vl",
  310. .attrs = port_sl2vl_attributes,
  311. };
  312. /* End sl2vl */
  313. /* Start diag_counters */
  314. struct qib_diagc_attr {
  315. struct ib_port_attribute attr;
  316. size_t counter;
  317. };
  318. static ssize_t diagc_attr_show(struct ib_device *ibdev, u32 port_num,
  319. struct ib_port_attribute *attr, char *buf)
  320. {
  321. struct qib_diagc_attr *dattr =
  322. container_of(attr, struct qib_diagc_attr, attr);
  323. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  324. struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
  325. return sysfs_emit(buf, "%llu\n", *((u64 *)qibp + dattr->counter));
  326. }
  327. static ssize_t diagc_attr_store(struct ib_device *ibdev, u32 port_num,
  328. struct ib_port_attribute *attr, const char *buf,
  329. size_t count)
  330. {
  331. struct qib_diagc_attr *dattr =
  332. container_of(attr, struct qib_diagc_attr, attr);
  333. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  334. struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
  335. u64 val;
  336. int ret;
  337. ret = kstrtou64(buf, 0, &val);
  338. if (ret)
  339. return ret;
  340. *((u64 *)qibp + dattr->counter) = val;
  341. return count;
  342. }
  343. #define QIB_DIAGC_ATTR(N) \
  344. static_assert(__same_type(((struct qib_ibport *)0)->rvp.n_##N, u64)); \
  345. static struct qib_diagc_attr qib_diagc_attr_##N = { \
  346. .attr = __ATTR(N, 0664, diagc_attr_show, diagc_attr_store), \
  347. .counter = \
  348. offsetof(struct qib_ibport, rvp.n_##N) / sizeof(u64) \
  349. }
  350. QIB_DIAGC_ATTR(rc_resends);
  351. QIB_DIAGC_ATTR(seq_naks);
  352. QIB_DIAGC_ATTR(rdma_seq);
  353. QIB_DIAGC_ATTR(rnr_naks);
  354. QIB_DIAGC_ATTR(other_naks);
  355. QIB_DIAGC_ATTR(rc_timeouts);
  356. QIB_DIAGC_ATTR(loop_pkts);
  357. QIB_DIAGC_ATTR(pkt_drops);
  358. QIB_DIAGC_ATTR(dmawait);
  359. QIB_DIAGC_ATTR(unaligned);
  360. QIB_DIAGC_ATTR(rc_dupreq);
  361. QIB_DIAGC_ATTR(rc_seqnak);
  362. QIB_DIAGC_ATTR(rc_crwaits);
  363. static u64 get_all_cpu_total(u64 __percpu *cntr)
  364. {
  365. int cpu;
  366. u64 counter = 0;
  367. for_each_possible_cpu(cpu)
  368. counter += *per_cpu_ptr(cntr, cpu);
  369. return counter;
  370. }
  371. static ssize_t qib_store_per_cpu(struct qib_devdata *dd, const char *buf,
  372. size_t count, u64 *zero, u64 cur)
  373. {
  374. u32 val;
  375. int ret;
  376. ret = kstrtou32(buf, 0, &val);
  377. if (ret)
  378. return ret;
  379. if (val != 0) {
  380. qib_dev_err(dd, "Per CPU cntrs can only be zeroed");
  381. return count;
  382. }
  383. *zero = cur;
  384. return count;
  385. }
  386. static ssize_t rc_acks_show(struct ib_device *ibdev, u32 port_num,
  387. struct ib_port_attribute *attr, char *buf)
  388. {
  389. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  390. struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
  391. return sysfs_emit(buf, "%llu\n",
  392. get_all_cpu_total(qibp->rvp.rc_acks) -
  393. qibp->rvp.z_rc_acks);
  394. }
  395. static ssize_t rc_acks_store(struct ib_device *ibdev, u32 port_num,
  396. struct ib_port_attribute *attr, const char *buf,
  397. size_t count)
  398. {
  399. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  400. struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
  401. return qib_store_per_cpu(dd, buf, count, &qibp->rvp.z_rc_acks,
  402. get_all_cpu_total(qibp->rvp.rc_acks));
  403. }
  404. static IB_PORT_ATTR_RW(rc_acks);
  405. static ssize_t rc_qacks_show(struct ib_device *ibdev, u32 port_num,
  406. struct ib_port_attribute *attr, char *buf)
  407. {
  408. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  409. struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
  410. return sysfs_emit(buf, "%llu\n",
  411. get_all_cpu_total(qibp->rvp.rc_qacks) -
  412. qibp->rvp.z_rc_qacks);
  413. }
  414. static ssize_t rc_qacks_store(struct ib_device *ibdev, u32 port_num,
  415. struct ib_port_attribute *attr, const char *buf,
  416. size_t count)
  417. {
  418. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  419. struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
  420. return qib_store_per_cpu(dd, buf, count, &qibp->rvp.z_rc_qacks,
  421. get_all_cpu_total(qibp->rvp.rc_qacks));
  422. }
  423. static IB_PORT_ATTR_RW(rc_qacks);
  424. static ssize_t rc_delayed_comp_show(struct ib_device *ibdev, u32 port_num,
  425. struct ib_port_attribute *attr, char *buf)
  426. {
  427. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  428. struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
  429. return sysfs_emit(buf, "%llu\n",
  430. get_all_cpu_total(qibp->rvp.rc_delayed_comp) -
  431. qibp->rvp.z_rc_delayed_comp);
  432. }
  433. static ssize_t rc_delayed_comp_store(struct ib_device *ibdev, u32 port_num,
  434. struct ib_port_attribute *attr,
  435. const char *buf, size_t count)
  436. {
  437. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  438. struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
  439. return qib_store_per_cpu(dd, buf, count, &qibp->rvp.z_rc_delayed_comp,
  440. get_all_cpu_total(qibp->rvp.rc_delayed_comp));
  441. }
  442. static IB_PORT_ATTR_RW(rc_delayed_comp);
  443. static struct attribute *port_diagc_attributes[] = {
  444. &qib_diagc_attr_rc_resends.attr.attr,
  445. &qib_diagc_attr_seq_naks.attr.attr,
  446. &qib_diagc_attr_rdma_seq.attr.attr,
  447. &qib_diagc_attr_rnr_naks.attr.attr,
  448. &qib_diagc_attr_other_naks.attr.attr,
  449. &qib_diagc_attr_rc_timeouts.attr.attr,
  450. &qib_diagc_attr_loop_pkts.attr.attr,
  451. &qib_diagc_attr_pkt_drops.attr.attr,
  452. &qib_diagc_attr_dmawait.attr.attr,
  453. &qib_diagc_attr_unaligned.attr.attr,
  454. &qib_diagc_attr_rc_dupreq.attr.attr,
  455. &qib_diagc_attr_rc_seqnak.attr.attr,
  456. &qib_diagc_attr_rc_crwaits.attr.attr,
  457. &ib_port_attr_rc_acks.attr,
  458. &ib_port_attr_rc_qacks.attr,
  459. &ib_port_attr_rc_delayed_comp.attr,
  460. NULL
  461. };
  462. static const struct attribute_group port_diagc_group = {
  463. .name = "diag_counters",
  464. .attrs = port_diagc_attributes,
  465. };
  466. /* End diag_counters */
  467. const struct attribute_group *qib_attr_port_groups[] = {
  468. &port_linkcontrol_group,
  469. &port_ccmgta_attribute_group,
  470. &port_sl2vl_group,
  471. &port_diagc_group,
  472. NULL,
  473. };
  474. /* end of per-port file structures and support code */
  475. /*
  476. * Start of per-unit (or driver, in some cases, but replicated
  477. * per unit) functions (these get a device *)
  478. */
  479. static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
  480. char *buf)
  481. {
  482. struct qib_ibdev *dev =
  483. rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
  484. return sysfs_emit(buf, "%x\n", dd_from_dev(dev)->minrev);
  485. }
  486. static DEVICE_ATTR_RO(hw_rev);
  487. static ssize_t hca_type_show(struct device *device,
  488. struct device_attribute *attr, char *buf)
  489. {
  490. struct qib_ibdev *dev =
  491. rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
  492. struct qib_devdata *dd = dd_from_dev(dev);
  493. if (!dd->boardname)
  494. return -EINVAL;
  495. return sysfs_emit(buf, "%s\n", dd->boardname);
  496. }
  497. static DEVICE_ATTR_RO(hca_type);
  498. static DEVICE_ATTR(board_id, 0444, hca_type_show, NULL);
  499. static ssize_t version_show(struct device *device,
  500. struct device_attribute *attr, char *buf)
  501. {
  502. /* The string printed here is already newline-terminated. */
  503. return sysfs_emit(buf, "%s", (char *)ib_qib_version);
  504. }
  505. static DEVICE_ATTR_RO(version);
  506. static ssize_t boardversion_show(struct device *device,
  507. struct device_attribute *attr, char *buf)
  508. {
  509. struct qib_ibdev *dev =
  510. rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
  511. struct qib_devdata *dd = dd_from_dev(dev);
  512. /* The string printed here is already newline-terminated. */
  513. return sysfs_emit(buf, "%s", dd->boardversion);
  514. }
  515. static DEVICE_ATTR_RO(boardversion);
  516. static ssize_t localbus_info_show(struct device *device,
  517. struct device_attribute *attr, char *buf)
  518. {
  519. struct qib_ibdev *dev =
  520. rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
  521. struct qib_devdata *dd = dd_from_dev(dev);
  522. /* The string printed here is already newline-terminated. */
  523. return sysfs_emit(buf, "%s", dd->lbus_info);
  524. }
  525. static DEVICE_ATTR_RO(localbus_info);
  526. static ssize_t nctxts_show(struct device *device,
  527. struct device_attribute *attr, char *buf)
  528. {
  529. struct qib_ibdev *dev =
  530. rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
  531. struct qib_devdata *dd = dd_from_dev(dev);
  532. /* Return the number of user ports (contexts) available. */
  533. /* The calculation below deals with a special case where
  534. * cfgctxts is set to 1 on a single-port board. */
  535. return sysfs_emit(buf, "%u\n",
  536. (dd->first_user_ctxt > dd->cfgctxts) ?
  537. 0 :
  538. (dd->cfgctxts - dd->first_user_ctxt));
  539. }
  540. static DEVICE_ATTR_RO(nctxts);
  541. static ssize_t nfreectxts_show(struct device *device,
  542. struct device_attribute *attr, char *buf)
  543. {
  544. struct qib_ibdev *dev =
  545. rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
  546. struct qib_devdata *dd = dd_from_dev(dev);
  547. /* Return the number of free user ports (contexts) available. */
  548. return sysfs_emit(buf, "%u\n", dd->freectxts);
  549. }
  550. static DEVICE_ATTR_RO(nfreectxts);
  551. static ssize_t serial_show(struct device *device, struct device_attribute *attr,
  552. char *buf)
  553. {
  554. struct qib_ibdev *dev =
  555. rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
  556. struct qib_devdata *dd = dd_from_dev(dev);
  557. const u8 *end = memchr(dd->serial, 0, ARRAY_SIZE(dd->serial));
  558. int size = end ? end - dd->serial : ARRAY_SIZE(dd->serial);
  559. return sysfs_emit(buf, ".%*s\n", size, dd->serial);
  560. }
  561. static DEVICE_ATTR_RO(serial);
  562. static ssize_t chip_reset_store(struct device *device,
  563. struct device_attribute *attr, const char *buf,
  564. size_t count)
  565. {
  566. struct qib_ibdev *dev =
  567. rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
  568. struct qib_devdata *dd = dd_from_dev(dev);
  569. int ret;
  570. if (count < 5 || memcmp(buf, "reset", 5) || !dd->diag_client) {
  571. ret = -EINVAL;
  572. goto bail;
  573. }
  574. ret = qib_reset_device(dd->unit);
  575. bail:
  576. return ret < 0 ? ret : count;
  577. }
  578. static DEVICE_ATTR_WO(chip_reset);
  579. /*
  580. * Dump tempsense regs. in decimal, to ease shell-scripts.
  581. */
  582. static ssize_t tempsense_show(struct device *device,
  583. struct device_attribute *attr, char *buf)
  584. {
  585. struct qib_ibdev *dev =
  586. rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
  587. struct qib_devdata *dd = dd_from_dev(dev);
  588. int i;
  589. u8 regvals[8];
  590. for (i = 0; i < 8; i++) {
  591. int ret;
  592. if (i == 6)
  593. continue;
  594. ret = dd->f_tempsense_rd(dd, i);
  595. if (ret < 0)
  596. return ret; /* return error on bad read */
  597. regvals[i] = ret;
  598. }
  599. return sysfs_emit(buf, "%d %d %02X %02X %d %d\n",
  600. (signed char)regvals[0],
  601. (signed char)regvals[1],
  602. regvals[2],
  603. regvals[3],
  604. (signed char)regvals[5],
  605. (signed char)regvals[7]);
  606. }
  607. static DEVICE_ATTR_RO(tempsense);
  608. /*
  609. * end of per-unit (or driver, in some cases, but replicated
  610. * per unit) functions
  611. */
  612. /* start of per-unit file structures and support code */
  613. static struct attribute *qib_attributes[] = {
  614. &dev_attr_hw_rev.attr,
  615. &dev_attr_hca_type.attr,
  616. &dev_attr_board_id.attr,
  617. &dev_attr_version.attr,
  618. &dev_attr_nctxts.attr,
  619. &dev_attr_nfreectxts.attr,
  620. &dev_attr_serial.attr,
  621. &dev_attr_boardversion.attr,
  622. &dev_attr_tempsense.attr,
  623. &dev_attr_localbus_info.attr,
  624. &dev_attr_chip_reset.attr,
  625. NULL,
  626. };
  627. const struct attribute_group qib_attr_group = {
  628. .attrs = qib_attributes,
  629. };