qib_sysfs.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  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 "qib.h"
  36. #include "qib_mad.h"
  37. /**
  38. * qib_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. static int qib_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. /* start of per-port functions */
  66. /*
  67. * Get/Set heartbeat enable. OR of 1=enabled, 2=auto
  68. */
  69. static ssize_t show_hrtbt_enb(struct qib_pportdata *ppd, char *buf)
  70. {
  71. struct qib_devdata *dd = ppd->dd;
  72. int ret;
  73. ret = dd->f_get_ib_cfg(ppd, QIB_IB_CFG_HRTBT);
  74. ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
  75. return ret;
  76. }
  77. static ssize_t store_hrtbt_enb(struct qib_pportdata *ppd, const char *buf,
  78. size_t count)
  79. {
  80. struct qib_devdata *dd = ppd->dd;
  81. int ret;
  82. u16 val;
  83. ret = qib_parse_ushort(buf, &val);
  84. /*
  85. * Set the "intentional" heartbeat enable per either of
  86. * "Enable" and "Auto", as these are normally set together.
  87. * This bit is consulted when leaving loopback mode,
  88. * because entering loopback mode overrides it and automatically
  89. * disables heartbeat.
  90. */
  91. if (ret >= 0)
  92. ret = dd->f_set_ib_cfg(ppd, QIB_IB_CFG_HRTBT, val);
  93. if (ret < 0)
  94. qib_dev_err(dd, "attempt to set invalid Heartbeat enable\n");
  95. return ret < 0 ? ret : count;
  96. }
  97. static ssize_t store_loopback(struct qib_pportdata *ppd, const char *buf,
  98. size_t count)
  99. {
  100. struct qib_devdata *dd = ppd->dd;
  101. int ret = count, r;
  102. r = dd->f_set_ib_loopback(ppd, buf);
  103. if (r < 0)
  104. ret = r;
  105. return ret;
  106. }
  107. static ssize_t store_led_override(struct qib_pportdata *ppd, const char *buf,
  108. size_t count)
  109. {
  110. struct qib_devdata *dd = ppd->dd;
  111. int ret;
  112. u16 val;
  113. ret = qib_parse_ushort(buf, &val);
  114. if (ret > 0)
  115. qib_set_led_override(ppd, val);
  116. else
  117. qib_dev_err(dd, "attempt to set invalid LED override\n");
  118. return ret < 0 ? ret : count;
  119. }
  120. static ssize_t show_status(struct qib_pportdata *ppd, char *buf)
  121. {
  122. ssize_t ret;
  123. if (!ppd->statusp)
  124. ret = -EINVAL;
  125. else
  126. ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n",
  127. (unsigned long long) *(ppd->statusp));
  128. return ret;
  129. }
  130. /*
  131. * For userland compatibility, these offsets must remain fixed.
  132. * They are strings for QIB_STATUS_*
  133. */
  134. static const char * const qib_status_str[] = {
  135. "Initted",
  136. "",
  137. "",
  138. "",
  139. "",
  140. "Present",
  141. "IB_link_up",
  142. "IB_configured",
  143. "",
  144. "Fatal_Hardware_Error",
  145. NULL,
  146. };
  147. static ssize_t show_status_str(struct qib_pportdata *ppd, char *buf)
  148. {
  149. int i, any;
  150. u64 s;
  151. ssize_t ret;
  152. if (!ppd->statusp) {
  153. ret = -EINVAL;
  154. goto bail;
  155. }
  156. s = *(ppd->statusp);
  157. *buf = '\0';
  158. for (any = i = 0; s && qib_status_str[i]; i++) {
  159. if (s & 1) {
  160. /* if overflow */
  161. if (any && strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
  162. break;
  163. if (strlcat(buf, qib_status_str[i], PAGE_SIZE) >=
  164. PAGE_SIZE)
  165. break;
  166. any = 1;
  167. }
  168. s >>= 1;
  169. }
  170. if (any)
  171. strlcat(buf, "\n", PAGE_SIZE);
  172. ret = strlen(buf);
  173. bail:
  174. return ret;
  175. }
  176. /* end of per-port functions */
  177. /*
  178. * Start of per-port file structures and support code
  179. * Because we are fitting into other infrastructure, we have to supply the
  180. * full set of kobject/sysfs_ops structures and routines.
  181. */
  182. #define QIB_PORT_ATTR(name, mode, show, store) \
  183. static struct qib_port_attr qib_port_attr_##name = \
  184. __ATTR(name, mode, show, store)
  185. struct qib_port_attr {
  186. struct attribute attr;
  187. ssize_t (*show)(struct qib_pportdata *, char *);
  188. ssize_t (*store)(struct qib_pportdata *, const char *, size_t);
  189. };
  190. QIB_PORT_ATTR(loopback, S_IWUSR, NULL, store_loopback);
  191. QIB_PORT_ATTR(led_override, S_IWUSR, NULL, store_led_override);
  192. QIB_PORT_ATTR(hrtbt_enable, S_IWUSR | S_IRUGO, show_hrtbt_enb,
  193. store_hrtbt_enb);
  194. QIB_PORT_ATTR(status, S_IRUGO, show_status, NULL);
  195. QIB_PORT_ATTR(status_str, S_IRUGO, show_status_str, NULL);
  196. static struct attribute *port_default_attributes[] = {
  197. &qib_port_attr_loopback.attr,
  198. &qib_port_attr_led_override.attr,
  199. &qib_port_attr_hrtbt_enable.attr,
  200. &qib_port_attr_status.attr,
  201. &qib_port_attr_status_str.attr,
  202. NULL
  203. };
  204. /*
  205. * Start of per-port congestion control structures and support code
  206. */
  207. /*
  208. * Congestion control table size followed by table entries
  209. */
  210. static ssize_t read_cc_table_bin(struct file *filp, struct kobject *kobj,
  211. struct bin_attribute *bin_attr,
  212. char *buf, loff_t pos, size_t count)
  213. {
  214. int ret;
  215. struct qib_pportdata *ppd =
  216. container_of(kobj, struct qib_pportdata, pport_cc_kobj);
  217. if (!qib_cc_table_size || !ppd->ccti_entries_shadow)
  218. return -EINVAL;
  219. ret = ppd->total_cct_entry * sizeof(struct ib_cc_table_entry_shadow)
  220. + sizeof(__be16);
  221. if (pos > ret)
  222. return -EINVAL;
  223. if (count > ret - pos)
  224. count = ret - pos;
  225. if (!count)
  226. return count;
  227. spin_lock(&ppd->cc_shadow_lock);
  228. memcpy(buf, ppd->ccti_entries_shadow, count);
  229. spin_unlock(&ppd->cc_shadow_lock);
  230. return count;
  231. }
  232. static void qib_port_release(struct kobject *kobj)
  233. {
  234. /* nothing to do since memory is freed by qib_free_devdata() */
  235. }
  236. static struct kobj_type qib_port_cc_ktype = {
  237. .release = qib_port_release,
  238. };
  239. static struct bin_attribute cc_table_bin_attr = {
  240. .attr = {.name = "cc_table_bin", .mode = 0444},
  241. .read = read_cc_table_bin,
  242. .size = PAGE_SIZE,
  243. };
  244. /*
  245. * Congestion settings: port control, control map and an array of 16
  246. * entries for the congestion entries - increase, timer, event log
  247. * trigger threshold and the minimum injection rate delay.
  248. */
  249. static ssize_t read_cc_setting_bin(struct file *filp, struct kobject *kobj,
  250. struct bin_attribute *bin_attr,
  251. char *buf, loff_t pos, size_t count)
  252. {
  253. int ret;
  254. struct qib_pportdata *ppd =
  255. container_of(kobj, struct qib_pportdata, pport_cc_kobj);
  256. if (!qib_cc_table_size || !ppd->congestion_entries_shadow)
  257. return -EINVAL;
  258. ret = sizeof(struct ib_cc_congestion_setting_attr_shadow);
  259. if (pos > ret)
  260. return -EINVAL;
  261. if (count > ret - pos)
  262. count = ret - pos;
  263. if (!count)
  264. return count;
  265. spin_lock(&ppd->cc_shadow_lock);
  266. memcpy(buf, ppd->congestion_entries_shadow, count);
  267. spin_unlock(&ppd->cc_shadow_lock);
  268. return count;
  269. }
  270. static struct bin_attribute cc_setting_bin_attr = {
  271. .attr = {.name = "cc_settings_bin", .mode = 0444},
  272. .read = read_cc_setting_bin,
  273. .size = PAGE_SIZE,
  274. };
  275. static ssize_t qib_portattr_show(struct kobject *kobj,
  276. struct attribute *attr, char *buf)
  277. {
  278. struct qib_port_attr *pattr =
  279. container_of(attr, struct qib_port_attr, attr);
  280. struct qib_pportdata *ppd =
  281. container_of(kobj, struct qib_pportdata, pport_kobj);
  282. return pattr->show(ppd, buf);
  283. }
  284. static ssize_t qib_portattr_store(struct kobject *kobj,
  285. struct attribute *attr, const char *buf, size_t len)
  286. {
  287. struct qib_port_attr *pattr =
  288. container_of(attr, struct qib_port_attr, attr);
  289. struct qib_pportdata *ppd =
  290. container_of(kobj, struct qib_pportdata, pport_kobj);
  291. return pattr->store(ppd, buf, len);
  292. }
  293. static const struct sysfs_ops qib_port_ops = {
  294. .show = qib_portattr_show,
  295. .store = qib_portattr_store,
  296. };
  297. static struct kobj_type qib_port_ktype = {
  298. .release = qib_port_release,
  299. .sysfs_ops = &qib_port_ops,
  300. .default_attrs = port_default_attributes
  301. };
  302. /* Start sl2vl */
  303. #define QIB_SL2VL_ATTR(N) \
  304. static struct qib_sl2vl_attr qib_sl2vl_attr_##N = { \
  305. .attr = { .name = __stringify(N), .mode = 0444 }, \
  306. .sl = N \
  307. }
  308. struct qib_sl2vl_attr {
  309. struct attribute attr;
  310. int sl;
  311. };
  312. QIB_SL2VL_ATTR(0);
  313. QIB_SL2VL_ATTR(1);
  314. QIB_SL2VL_ATTR(2);
  315. QIB_SL2VL_ATTR(3);
  316. QIB_SL2VL_ATTR(4);
  317. QIB_SL2VL_ATTR(5);
  318. QIB_SL2VL_ATTR(6);
  319. QIB_SL2VL_ATTR(7);
  320. QIB_SL2VL_ATTR(8);
  321. QIB_SL2VL_ATTR(9);
  322. QIB_SL2VL_ATTR(10);
  323. QIB_SL2VL_ATTR(11);
  324. QIB_SL2VL_ATTR(12);
  325. QIB_SL2VL_ATTR(13);
  326. QIB_SL2VL_ATTR(14);
  327. QIB_SL2VL_ATTR(15);
  328. static struct attribute *sl2vl_default_attributes[] = {
  329. &qib_sl2vl_attr_0.attr,
  330. &qib_sl2vl_attr_1.attr,
  331. &qib_sl2vl_attr_2.attr,
  332. &qib_sl2vl_attr_3.attr,
  333. &qib_sl2vl_attr_4.attr,
  334. &qib_sl2vl_attr_5.attr,
  335. &qib_sl2vl_attr_6.attr,
  336. &qib_sl2vl_attr_7.attr,
  337. &qib_sl2vl_attr_8.attr,
  338. &qib_sl2vl_attr_9.attr,
  339. &qib_sl2vl_attr_10.attr,
  340. &qib_sl2vl_attr_11.attr,
  341. &qib_sl2vl_attr_12.attr,
  342. &qib_sl2vl_attr_13.attr,
  343. &qib_sl2vl_attr_14.attr,
  344. &qib_sl2vl_attr_15.attr,
  345. NULL
  346. };
  347. static ssize_t sl2vl_attr_show(struct kobject *kobj, struct attribute *attr,
  348. char *buf)
  349. {
  350. struct qib_sl2vl_attr *sattr =
  351. container_of(attr, struct qib_sl2vl_attr, attr);
  352. struct qib_pportdata *ppd =
  353. container_of(kobj, struct qib_pportdata, sl2vl_kobj);
  354. struct qib_ibport *qibp = &ppd->ibport_data;
  355. return sprintf(buf, "%u\n", qibp->sl_to_vl[sattr->sl]);
  356. }
  357. static const struct sysfs_ops qib_sl2vl_ops = {
  358. .show = sl2vl_attr_show,
  359. };
  360. static struct kobj_type qib_sl2vl_ktype = {
  361. .release = qib_port_release,
  362. .sysfs_ops = &qib_sl2vl_ops,
  363. .default_attrs = sl2vl_default_attributes
  364. };
  365. /* End sl2vl */
  366. /* Start diag_counters */
  367. #define QIB_DIAGC_ATTR(N) \
  368. static struct qib_diagc_attr qib_diagc_attr_##N = { \
  369. .attr = { .name = __stringify(N), .mode = 0664 }, \
  370. .counter = offsetof(struct qib_ibport, n_##N) \
  371. }
  372. struct qib_diagc_attr {
  373. struct attribute attr;
  374. size_t counter;
  375. };
  376. QIB_DIAGC_ATTR(rc_resends);
  377. QIB_DIAGC_ATTR(rc_acks);
  378. QIB_DIAGC_ATTR(rc_qacks);
  379. QIB_DIAGC_ATTR(rc_delayed_comp);
  380. QIB_DIAGC_ATTR(seq_naks);
  381. QIB_DIAGC_ATTR(rdma_seq);
  382. QIB_DIAGC_ATTR(rnr_naks);
  383. QIB_DIAGC_ATTR(other_naks);
  384. QIB_DIAGC_ATTR(rc_timeouts);
  385. QIB_DIAGC_ATTR(loop_pkts);
  386. QIB_DIAGC_ATTR(pkt_drops);
  387. QIB_DIAGC_ATTR(dmawait);
  388. QIB_DIAGC_ATTR(unaligned);
  389. QIB_DIAGC_ATTR(rc_dupreq);
  390. QIB_DIAGC_ATTR(rc_seqnak);
  391. static struct attribute *diagc_default_attributes[] = {
  392. &qib_diagc_attr_rc_resends.attr,
  393. &qib_diagc_attr_rc_acks.attr,
  394. &qib_diagc_attr_rc_qacks.attr,
  395. &qib_diagc_attr_rc_delayed_comp.attr,
  396. &qib_diagc_attr_seq_naks.attr,
  397. &qib_diagc_attr_rdma_seq.attr,
  398. &qib_diagc_attr_rnr_naks.attr,
  399. &qib_diagc_attr_other_naks.attr,
  400. &qib_diagc_attr_rc_timeouts.attr,
  401. &qib_diagc_attr_loop_pkts.attr,
  402. &qib_diagc_attr_pkt_drops.attr,
  403. &qib_diagc_attr_dmawait.attr,
  404. &qib_diagc_attr_unaligned.attr,
  405. &qib_diagc_attr_rc_dupreq.attr,
  406. &qib_diagc_attr_rc_seqnak.attr,
  407. NULL
  408. };
  409. static ssize_t diagc_attr_show(struct kobject *kobj, struct attribute *attr,
  410. char *buf)
  411. {
  412. struct qib_diagc_attr *dattr =
  413. container_of(attr, struct qib_diagc_attr, attr);
  414. struct qib_pportdata *ppd =
  415. container_of(kobj, struct qib_pportdata, diagc_kobj);
  416. struct qib_ibport *qibp = &ppd->ibport_data;
  417. return sprintf(buf, "%u\n", *(u32 *)((char *)qibp + dattr->counter));
  418. }
  419. static ssize_t diagc_attr_store(struct kobject *kobj, struct attribute *attr,
  420. const char *buf, size_t size)
  421. {
  422. struct qib_diagc_attr *dattr =
  423. container_of(attr, struct qib_diagc_attr, attr);
  424. struct qib_pportdata *ppd =
  425. container_of(kobj, struct qib_pportdata, diagc_kobj);
  426. struct qib_ibport *qibp = &ppd->ibport_data;
  427. char *endp;
  428. long val = simple_strtol(buf, &endp, 0);
  429. if (val < 0 || endp == buf)
  430. return -EINVAL;
  431. *(u32 *)((char *) qibp + dattr->counter) = val;
  432. return size;
  433. }
  434. static const struct sysfs_ops qib_diagc_ops = {
  435. .show = diagc_attr_show,
  436. .store = diagc_attr_store,
  437. };
  438. static struct kobj_type qib_diagc_ktype = {
  439. .release = qib_port_release,
  440. .sysfs_ops = &qib_diagc_ops,
  441. .default_attrs = diagc_default_attributes
  442. };
  443. /* End diag_counters */
  444. /* end of per-port file structures and support code */
  445. /*
  446. * Start of per-unit (or driver, in some cases, but replicated
  447. * per unit) functions (these get a device *)
  448. */
  449. static ssize_t show_rev(struct device *device, struct device_attribute *attr,
  450. char *buf)
  451. {
  452. struct qib_ibdev *dev =
  453. container_of(device, struct qib_ibdev, ibdev.dev);
  454. return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev);
  455. }
  456. static ssize_t show_hca(struct device *device, struct device_attribute *attr,
  457. char *buf)
  458. {
  459. struct qib_ibdev *dev =
  460. container_of(device, struct qib_ibdev, ibdev.dev);
  461. struct qib_devdata *dd = dd_from_dev(dev);
  462. int ret;
  463. if (!dd->boardname)
  464. ret = -EINVAL;
  465. else
  466. ret = scnprintf(buf, PAGE_SIZE, "%s\n", dd->boardname);
  467. return ret;
  468. }
  469. static ssize_t show_version(struct device *device,
  470. struct device_attribute *attr, char *buf)
  471. {
  472. /* The string printed here is already newline-terminated. */
  473. return scnprintf(buf, PAGE_SIZE, "%s", (char *)ib_qib_version);
  474. }
  475. static ssize_t show_boardversion(struct device *device,
  476. struct device_attribute *attr, char *buf)
  477. {
  478. struct qib_ibdev *dev =
  479. container_of(device, struct qib_ibdev, ibdev.dev);
  480. struct qib_devdata *dd = dd_from_dev(dev);
  481. /* The string printed here is already newline-terminated. */
  482. return scnprintf(buf, PAGE_SIZE, "%s", dd->boardversion);
  483. }
  484. static ssize_t show_localbus_info(struct device *device,
  485. struct device_attribute *attr, char *buf)
  486. {
  487. struct qib_ibdev *dev =
  488. container_of(device, struct qib_ibdev, ibdev.dev);
  489. struct qib_devdata *dd = dd_from_dev(dev);
  490. /* The string printed here is already newline-terminated. */
  491. return scnprintf(buf, PAGE_SIZE, "%s", dd->lbus_info);
  492. }
  493. static ssize_t show_nctxts(struct device *device,
  494. struct device_attribute *attr, char *buf)
  495. {
  496. struct qib_ibdev *dev =
  497. container_of(device, struct qib_ibdev, ibdev.dev);
  498. struct qib_devdata *dd = dd_from_dev(dev);
  499. /* Return the number of user ports (contexts) available. */
  500. /* The calculation below deals with a special case where
  501. * cfgctxts is set to 1 on a single-port board. */
  502. return scnprintf(buf, PAGE_SIZE, "%u\n",
  503. (dd->first_user_ctxt > dd->cfgctxts) ? 0 :
  504. (dd->cfgctxts - dd->first_user_ctxt));
  505. }
  506. static ssize_t show_nfreectxts(struct device *device,
  507. struct device_attribute *attr, char *buf)
  508. {
  509. struct qib_ibdev *dev =
  510. container_of(device, struct qib_ibdev, ibdev.dev);
  511. struct qib_devdata *dd = dd_from_dev(dev);
  512. /* Return the number of free user ports (contexts) available. */
  513. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->freectxts);
  514. }
  515. static ssize_t show_serial(struct device *device,
  516. struct device_attribute *attr, char *buf)
  517. {
  518. struct qib_ibdev *dev =
  519. container_of(device, struct qib_ibdev, ibdev.dev);
  520. struct qib_devdata *dd = dd_from_dev(dev);
  521. buf[sizeof dd->serial] = '\0';
  522. memcpy(buf, dd->serial, sizeof dd->serial);
  523. strcat(buf, "\n");
  524. return strlen(buf);
  525. }
  526. static ssize_t store_chip_reset(struct device *device,
  527. struct device_attribute *attr, const char *buf,
  528. size_t count)
  529. {
  530. struct qib_ibdev *dev =
  531. container_of(device, struct qib_ibdev, ibdev.dev);
  532. struct qib_devdata *dd = dd_from_dev(dev);
  533. int ret;
  534. if (count < 5 || memcmp(buf, "reset", 5) || !dd->diag_client) {
  535. ret = -EINVAL;
  536. goto bail;
  537. }
  538. ret = qib_reset_device(dd->unit);
  539. bail:
  540. return ret < 0 ? ret : count;
  541. }
  542. static ssize_t show_logged_errs(struct device *device,
  543. struct device_attribute *attr, char *buf)
  544. {
  545. struct qib_ibdev *dev =
  546. container_of(device, struct qib_ibdev, ibdev.dev);
  547. struct qib_devdata *dd = dd_from_dev(dev);
  548. int idx, count;
  549. /* force consistency with actual EEPROM */
  550. if (qib_update_eeprom_log(dd) != 0)
  551. return -ENXIO;
  552. count = 0;
  553. for (idx = 0; idx < QIB_EEP_LOG_CNT; ++idx) {
  554. count += scnprintf(buf + count, PAGE_SIZE - count, "%d%c",
  555. dd->eep_st_errs[idx],
  556. idx == (QIB_EEP_LOG_CNT - 1) ? '\n' : ' ');
  557. }
  558. return count;
  559. }
  560. /*
  561. * Dump tempsense regs. in decimal, to ease shell-scripts.
  562. */
  563. static ssize_t show_tempsense(struct device *device,
  564. struct device_attribute *attr, char *buf)
  565. {
  566. struct qib_ibdev *dev =
  567. container_of(device, struct qib_ibdev, ibdev.dev);
  568. struct qib_devdata *dd = dd_from_dev(dev);
  569. int ret;
  570. int idx;
  571. u8 regvals[8];
  572. ret = -ENXIO;
  573. for (idx = 0; idx < 8; ++idx) {
  574. if (idx == 6)
  575. continue;
  576. ret = dd->f_tempsense_rd(dd, idx);
  577. if (ret < 0)
  578. break;
  579. regvals[idx] = ret;
  580. }
  581. if (idx == 8)
  582. ret = scnprintf(buf, PAGE_SIZE, "%d %d %02X %02X %d %d\n",
  583. *(signed char *)(regvals),
  584. *(signed char *)(regvals + 1),
  585. regvals[2], regvals[3],
  586. *(signed char *)(regvals + 5),
  587. *(signed char *)(regvals + 7));
  588. return ret;
  589. }
  590. /*
  591. * end of per-unit (or driver, in some cases, but replicated
  592. * per unit) functions
  593. */
  594. /* start of per-unit file structures and support code */
  595. static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  596. static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
  597. static DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
  598. static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
  599. static DEVICE_ATTR(nctxts, S_IRUGO, show_nctxts, NULL);
  600. static DEVICE_ATTR(nfreectxts, S_IRUGO, show_nfreectxts, NULL);
  601. static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
  602. static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
  603. static DEVICE_ATTR(logged_errors, S_IRUGO, show_logged_errs, NULL);
  604. static DEVICE_ATTR(tempsense, S_IRUGO, show_tempsense, NULL);
  605. static DEVICE_ATTR(localbus_info, S_IRUGO, show_localbus_info, NULL);
  606. static DEVICE_ATTR(chip_reset, S_IWUSR, NULL, store_chip_reset);
  607. static struct device_attribute *qib_attributes[] = {
  608. &dev_attr_hw_rev,
  609. &dev_attr_hca_type,
  610. &dev_attr_board_id,
  611. &dev_attr_version,
  612. &dev_attr_nctxts,
  613. &dev_attr_nfreectxts,
  614. &dev_attr_serial,
  615. &dev_attr_boardversion,
  616. &dev_attr_logged_errors,
  617. &dev_attr_tempsense,
  618. &dev_attr_localbus_info,
  619. &dev_attr_chip_reset,
  620. };
  621. int qib_create_port_files(struct ib_device *ibdev, u8 port_num,
  622. struct kobject *kobj)
  623. {
  624. struct qib_pportdata *ppd;
  625. struct qib_devdata *dd = dd_from_ibdev(ibdev);
  626. int ret;
  627. if (!port_num || port_num > dd->num_pports) {
  628. qib_dev_err(dd, "Skipping infiniband class with "
  629. "invalid port %u\n", port_num);
  630. ret = -ENODEV;
  631. goto bail;
  632. }
  633. ppd = &dd->pport[port_num - 1];
  634. ret = kobject_init_and_add(&ppd->pport_kobj, &qib_port_ktype, kobj,
  635. "linkcontrol");
  636. if (ret) {
  637. qib_dev_err(dd, "Skipping linkcontrol sysfs info, "
  638. "(err %d) port %u\n", ret, port_num);
  639. goto bail;
  640. }
  641. kobject_uevent(&ppd->pport_kobj, KOBJ_ADD);
  642. ret = kobject_init_and_add(&ppd->sl2vl_kobj, &qib_sl2vl_ktype, kobj,
  643. "sl2vl");
  644. if (ret) {
  645. qib_dev_err(dd, "Skipping sl2vl sysfs info, "
  646. "(err %d) port %u\n", ret, port_num);
  647. goto bail_link;
  648. }
  649. kobject_uevent(&ppd->sl2vl_kobj, KOBJ_ADD);
  650. ret = kobject_init_and_add(&ppd->diagc_kobj, &qib_diagc_ktype, kobj,
  651. "diag_counters");
  652. if (ret) {
  653. qib_dev_err(dd, "Skipping diag_counters sysfs info, "
  654. "(err %d) port %u\n", ret, port_num);
  655. goto bail_sl;
  656. }
  657. kobject_uevent(&ppd->diagc_kobj, KOBJ_ADD);
  658. if (!qib_cc_table_size || !ppd->congestion_entries_shadow)
  659. return 0;
  660. ret = kobject_init_and_add(&ppd->pport_cc_kobj, &qib_port_cc_ktype,
  661. kobj, "CCMgtA");
  662. if (ret) {
  663. qib_dev_err(dd,
  664. "Skipping Congestion Control sysfs info, (err %d) port %u\n",
  665. ret, port_num);
  666. goto bail_diagc;
  667. }
  668. kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD);
  669. ret = sysfs_create_bin_file(&ppd->pport_cc_kobj,
  670. &cc_setting_bin_attr);
  671. if (ret) {
  672. qib_dev_err(dd,
  673. "Skipping Congestion Control setting sysfs info, (err %d) port %u\n",
  674. ret, port_num);
  675. goto bail_cc;
  676. }
  677. ret = sysfs_create_bin_file(&ppd->pport_cc_kobj,
  678. &cc_table_bin_attr);
  679. if (ret) {
  680. qib_dev_err(dd,
  681. "Skipping Congestion Control table sysfs info, (err %d) port %u\n",
  682. ret, port_num);
  683. goto bail_cc_entry_bin;
  684. }
  685. qib_devinfo(dd->pcidev,
  686. "IB%u: Congestion Control Agent enabled for port %d\n",
  687. dd->unit, port_num);
  688. return 0;
  689. bail_cc_entry_bin:
  690. sysfs_remove_bin_file(&ppd->pport_cc_kobj, &cc_setting_bin_attr);
  691. bail_cc:
  692. kobject_put(&ppd->pport_cc_kobj);
  693. bail_diagc:
  694. kobject_put(&ppd->diagc_kobj);
  695. bail_sl:
  696. kobject_put(&ppd->sl2vl_kobj);
  697. bail_link:
  698. kobject_put(&ppd->pport_kobj);
  699. bail:
  700. return ret;
  701. }
  702. /*
  703. * Register and create our files in /sys/class/infiniband.
  704. */
  705. int qib_verbs_register_sysfs(struct qib_devdata *dd)
  706. {
  707. struct ib_device *dev = &dd->verbs_dev.ibdev;
  708. int i, ret;
  709. for (i = 0; i < ARRAY_SIZE(qib_attributes); ++i) {
  710. ret = device_create_file(&dev->dev, qib_attributes[i]);
  711. if (ret)
  712. return ret;
  713. }
  714. return 0;
  715. }
  716. /*
  717. * Unregister and remove our files in /sys/class/infiniband.
  718. */
  719. void qib_verbs_unregister_sysfs(struct qib_devdata *dd)
  720. {
  721. struct qib_pportdata *ppd;
  722. int i;
  723. for (i = 0; i < dd->num_pports; i++) {
  724. ppd = &dd->pport[i];
  725. if (qib_cc_table_size &&
  726. ppd->congestion_entries_shadow) {
  727. sysfs_remove_bin_file(&ppd->pport_cc_kobj,
  728. &cc_setting_bin_attr);
  729. sysfs_remove_bin_file(&ppd->pport_cc_kobj,
  730. &cc_table_bin_attr);
  731. kobject_put(&ppd->pport_cc_kobj);
  732. }
  733. kobject_put(&ppd->sl2vl_kobj);
  734. kobject_put(&ppd->pport_kobj);
  735. }
  736. }