sysfs.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. /*
  2. * Copyright(c) 2015, 2016 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. #include <linux/ctype.h>
  48. #include "hfi.h"
  49. #include "mad.h"
  50. #include "trace.h"
  51. #include "affinity.h"
  52. /*
  53. * Start of per-port congestion control structures and support code
  54. */
  55. /*
  56. * Congestion control table size followed by table entries
  57. */
  58. static ssize_t read_cc_table_bin(struct file *filp, struct kobject *kobj,
  59. struct bin_attribute *bin_attr,
  60. char *buf, loff_t pos, size_t count)
  61. {
  62. int ret;
  63. struct hfi1_pportdata *ppd =
  64. container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
  65. struct cc_state *cc_state;
  66. ret = ppd->total_cct_entry * sizeof(struct ib_cc_table_entry_shadow)
  67. + sizeof(__be16);
  68. if (pos > ret)
  69. return -EINVAL;
  70. if (count > ret - pos)
  71. count = ret - pos;
  72. if (!count)
  73. return count;
  74. rcu_read_lock();
  75. cc_state = get_cc_state(ppd);
  76. if (!cc_state) {
  77. rcu_read_unlock();
  78. return -EINVAL;
  79. }
  80. memcpy(buf, (void *)&cc_state->cct + pos, count);
  81. rcu_read_unlock();
  82. return count;
  83. }
  84. static void port_release(struct kobject *kobj)
  85. {
  86. /* nothing to do since memory is freed by hfi1_free_devdata() */
  87. }
  88. static struct bin_attribute cc_table_bin_attr = {
  89. .attr = {.name = "cc_table_bin", .mode = 0444},
  90. .read = read_cc_table_bin,
  91. .size = PAGE_SIZE,
  92. };
  93. /*
  94. * Congestion settings: port control, control map and an array of 16
  95. * entries for the congestion entries - increase, timer, event log
  96. * trigger threshold and the minimum injection rate delay.
  97. */
  98. static ssize_t read_cc_setting_bin(struct file *filp, struct kobject *kobj,
  99. struct bin_attribute *bin_attr,
  100. char *buf, loff_t pos, size_t count)
  101. {
  102. int ret;
  103. struct hfi1_pportdata *ppd =
  104. container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
  105. struct cc_state *cc_state;
  106. ret = sizeof(struct opa_congestion_setting_attr_shadow);
  107. if (pos > ret)
  108. return -EINVAL;
  109. if (count > ret - pos)
  110. count = ret - pos;
  111. if (!count)
  112. return count;
  113. rcu_read_lock();
  114. cc_state = get_cc_state(ppd);
  115. if (!cc_state) {
  116. rcu_read_unlock();
  117. return -EINVAL;
  118. }
  119. memcpy(buf, (void *)&cc_state->cong_setting + pos, count);
  120. rcu_read_unlock();
  121. return count;
  122. }
  123. static struct bin_attribute cc_setting_bin_attr = {
  124. .attr = {.name = "cc_settings_bin", .mode = 0444},
  125. .read = read_cc_setting_bin,
  126. .size = PAGE_SIZE,
  127. };
  128. struct hfi1_port_attr {
  129. struct attribute attr;
  130. ssize_t (*show)(struct hfi1_pportdata *, char *);
  131. ssize_t (*store)(struct hfi1_pportdata *, const char *, size_t);
  132. };
  133. static ssize_t cc_prescan_show(struct hfi1_pportdata *ppd, char *buf)
  134. {
  135. return sprintf(buf, "%s\n", ppd->cc_prescan ? "on" : "off");
  136. }
  137. static ssize_t cc_prescan_store(struct hfi1_pportdata *ppd, const char *buf,
  138. size_t count)
  139. {
  140. if (!memcmp(buf, "on", 2))
  141. ppd->cc_prescan = true;
  142. else if (!memcmp(buf, "off", 3))
  143. ppd->cc_prescan = false;
  144. return count;
  145. }
  146. static struct hfi1_port_attr cc_prescan_attr =
  147. __ATTR(cc_prescan, 0600, cc_prescan_show, cc_prescan_store);
  148. static ssize_t cc_attr_show(struct kobject *kobj, struct attribute *attr,
  149. char *buf)
  150. {
  151. struct hfi1_port_attr *port_attr =
  152. container_of(attr, struct hfi1_port_attr, attr);
  153. struct hfi1_pportdata *ppd =
  154. container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
  155. return port_attr->show(ppd, buf);
  156. }
  157. static ssize_t cc_attr_store(struct kobject *kobj, struct attribute *attr,
  158. const char *buf, size_t count)
  159. {
  160. struct hfi1_port_attr *port_attr =
  161. container_of(attr, struct hfi1_port_attr, attr);
  162. struct hfi1_pportdata *ppd =
  163. container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
  164. return port_attr->store(ppd, buf, count);
  165. }
  166. static const struct sysfs_ops port_cc_sysfs_ops = {
  167. .show = cc_attr_show,
  168. .store = cc_attr_store
  169. };
  170. static struct attribute *port_cc_default_attributes[] = {
  171. &cc_prescan_attr.attr
  172. };
  173. static struct kobj_type port_cc_ktype = {
  174. .release = port_release,
  175. .sysfs_ops = &port_cc_sysfs_ops,
  176. .default_attrs = port_cc_default_attributes
  177. };
  178. /* Start sc2vl */
  179. #define HFI1_SC2VL_ATTR(N) \
  180. static struct hfi1_sc2vl_attr hfi1_sc2vl_attr_##N = { \
  181. .attr = { .name = __stringify(N), .mode = 0444 }, \
  182. .sc = N \
  183. }
  184. struct hfi1_sc2vl_attr {
  185. struct attribute attr;
  186. int sc;
  187. };
  188. HFI1_SC2VL_ATTR(0);
  189. HFI1_SC2VL_ATTR(1);
  190. HFI1_SC2VL_ATTR(2);
  191. HFI1_SC2VL_ATTR(3);
  192. HFI1_SC2VL_ATTR(4);
  193. HFI1_SC2VL_ATTR(5);
  194. HFI1_SC2VL_ATTR(6);
  195. HFI1_SC2VL_ATTR(7);
  196. HFI1_SC2VL_ATTR(8);
  197. HFI1_SC2VL_ATTR(9);
  198. HFI1_SC2VL_ATTR(10);
  199. HFI1_SC2VL_ATTR(11);
  200. HFI1_SC2VL_ATTR(12);
  201. HFI1_SC2VL_ATTR(13);
  202. HFI1_SC2VL_ATTR(14);
  203. HFI1_SC2VL_ATTR(15);
  204. HFI1_SC2VL_ATTR(16);
  205. HFI1_SC2VL_ATTR(17);
  206. HFI1_SC2VL_ATTR(18);
  207. HFI1_SC2VL_ATTR(19);
  208. HFI1_SC2VL_ATTR(20);
  209. HFI1_SC2VL_ATTR(21);
  210. HFI1_SC2VL_ATTR(22);
  211. HFI1_SC2VL_ATTR(23);
  212. HFI1_SC2VL_ATTR(24);
  213. HFI1_SC2VL_ATTR(25);
  214. HFI1_SC2VL_ATTR(26);
  215. HFI1_SC2VL_ATTR(27);
  216. HFI1_SC2VL_ATTR(28);
  217. HFI1_SC2VL_ATTR(29);
  218. HFI1_SC2VL_ATTR(30);
  219. HFI1_SC2VL_ATTR(31);
  220. static struct attribute *sc2vl_default_attributes[] = {
  221. &hfi1_sc2vl_attr_0.attr,
  222. &hfi1_sc2vl_attr_1.attr,
  223. &hfi1_sc2vl_attr_2.attr,
  224. &hfi1_sc2vl_attr_3.attr,
  225. &hfi1_sc2vl_attr_4.attr,
  226. &hfi1_sc2vl_attr_5.attr,
  227. &hfi1_sc2vl_attr_6.attr,
  228. &hfi1_sc2vl_attr_7.attr,
  229. &hfi1_sc2vl_attr_8.attr,
  230. &hfi1_sc2vl_attr_9.attr,
  231. &hfi1_sc2vl_attr_10.attr,
  232. &hfi1_sc2vl_attr_11.attr,
  233. &hfi1_sc2vl_attr_12.attr,
  234. &hfi1_sc2vl_attr_13.attr,
  235. &hfi1_sc2vl_attr_14.attr,
  236. &hfi1_sc2vl_attr_15.attr,
  237. &hfi1_sc2vl_attr_16.attr,
  238. &hfi1_sc2vl_attr_17.attr,
  239. &hfi1_sc2vl_attr_18.attr,
  240. &hfi1_sc2vl_attr_19.attr,
  241. &hfi1_sc2vl_attr_20.attr,
  242. &hfi1_sc2vl_attr_21.attr,
  243. &hfi1_sc2vl_attr_22.attr,
  244. &hfi1_sc2vl_attr_23.attr,
  245. &hfi1_sc2vl_attr_24.attr,
  246. &hfi1_sc2vl_attr_25.attr,
  247. &hfi1_sc2vl_attr_26.attr,
  248. &hfi1_sc2vl_attr_27.attr,
  249. &hfi1_sc2vl_attr_28.attr,
  250. &hfi1_sc2vl_attr_29.attr,
  251. &hfi1_sc2vl_attr_30.attr,
  252. &hfi1_sc2vl_attr_31.attr,
  253. NULL
  254. };
  255. static ssize_t sc2vl_attr_show(struct kobject *kobj, struct attribute *attr,
  256. char *buf)
  257. {
  258. struct hfi1_sc2vl_attr *sattr =
  259. container_of(attr, struct hfi1_sc2vl_attr, attr);
  260. struct hfi1_pportdata *ppd =
  261. container_of(kobj, struct hfi1_pportdata, sc2vl_kobj);
  262. struct hfi1_devdata *dd = ppd->dd;
  263. return sprintf(buf, "%u\n", *((u8 *)dd->sc2vl + sattr->sc));
  264. }
  265. static const struct sysfs_ops hfi1_sc2vl_ops = {
  266. .show = sc2vl_attr_show,
  267. };
  268. static struct kobj_type hfi1_sc2vl_ktype = {
  269. .release = port_release,
  270. .sysfs_ops = &hfi1_sc2vl_ops,
  271. .default_attrs = sc2vl_default_attributes
  272. };
  273. /* End sc2vl */
  274. /* Start sl2sc */
  275. #define HFI1_SL2SC_ATTR(N) \
  276. static struct hfi1_sl2sc_attr hfi1_sl2sc_attr_##N = { \
  277. .attr = { .name = __stringify(N), .mode = 0444 }, \
  278. .sl = N \
  279. }
  280. struct hfi1_sl2sc_attr {
  281. struct attribute attr;
  282. int sl;
  283. };
  284. HFI1_SL2SC_ATTR(0);
  285. HFI1_SL2SC_ATTR(1);
  286. HFI1_SL2SC_ATTR(2);
  287. HFI1_SL2SC_ATTR(3);
  288. HFI1_SL2SC_ATTR(4);
  289. HFI1_SL2SC_ATTR(5);
  290. HFI1_SL2SC_ATTR(6);
  291. HFI1_SL2SC_ATTR(7);
  292. HFI1_SL2SC_ATTR(8);
  293. HFI1_SL2SC_ATTR(9);
  294. HFI1_SL2SC_ATTR(10);
  295. HFI1_SL2SC_ATTR(11);
  296. HFI1_SL2SC_ATTR(12);
  297. HFI1_SL2SC_ATTR(13);
  298. HFI1_SL2SC_ATTR(14);
  299. HFI1_SL2SC_ATTR(15);
  300. HFI1_SL2SC_ATTR(16);
  301. HFI1_SL2SC_ATTR(17);
  302. HFI1_SL2SC_ATTR(18);
  303. HFI1_SL2SC_ATTR(19);
  304. HFI1_SL2SC_ATTR(20);
  305. HFI1_SL2SC_ATTR(21);
  306. HFI1_SL2SC_ATTR(22);
  307. HFI1_SL2SC_ATTR(23);
  308. HFI1_SL2SC_ATTR(24);
  309. HFI1_SL2SC_ATTR(25);
  310. HFI1_SL2SC_ATTR(26);
  311. HFI1_SL2SC_ATTR(27);
  312. HFI1_SL2SC_ATTR(28);
  313. HFI1_SL2SC_ATTR(29);
  314. HFI1_SL2SC_ATTR(30);
  315. HFI1_SL2SC_ATTR(31);
  316. static struct attribute *sl2sc_default_attributes[] = {
  317. &hfi1_sl2sc_attr_0.attr,
  318. &hfi1_sl2sc_attr_1.attr,
  319. &hfi1_sl2sc_attr_2.attr,
  320. &hfi1_sl2sc_attr_3.attr,
  321. &hfi1_sl2sc_attr_4.attr,
  322. &hfi1_sl2sc_attr_5.attr,
  323. &hfi1_sl2sc_attr_6.attr,
  324. &hfi1_sl2sc_attr_7.attr,
  325. &hfi1_sl2sc_attr_8.attr,
  326. &hfi1_sl2sc_attr_9.attr,
  327. &hfi1_sl2sc_attr_10.attr,
  328. &hfi1_sl2sc_attr_11.attr,
  329. &hfi1_sl2sc_attr_12.attr,
  330. &hfi1_sl2sc_attr_13.attr,
  331. &hfi1_sl2sc_attr_14.attr,
  332. &hfi1_sl2sc_attr_15.attr,
  333. &hfi1_sl2sc_attr_16.attr,
  334. &hfi1_sl2sc_attr_17.attr,
  335. &hfi1_sl2sc_attr_18.attr,
  336. &hfi1_sl2sc_attr_19.attr,
  337. &hfi1_sl2sc_attr_20.attr,
  338. &hfi1_sl2sc_attr_21.attr,
  339. &hfi1_sl2sc_attr_22.attr,
  340. &hfi1_sl2sc_attr_23.attr,
  341. &hfi1_sl2sc_attr_24.attr,
  342. &hfi1_sl2sc_attr_25.attr,
  343. &hfi1_sl2sc_attr_26.attr,
  344. &hfi1_sl2sc_attr_27.attr,
  345. &hfi1_sl2sc_attr_28.attr,
  346. &hfi1_sl2sc_attr_29.attr,
  347. &hfi1_sl2sc_attr_30.attr,
  348. &hfi1_sl2sc_attr_31.attr,
  349. NULL
  350. };
  351. static ssize_t sl2sc_attr_show(struct kobject *kobj, struct attribute *attr,
  352. char *buf)
  353. {
  354. struct hfi1_sl2sc_attr *sattr =
  355. container_of(attr, struct hfi1_sl2sc_attr, attr);
  356. struct hfi1_pportdata *ppd =
  357. container_of(kobj, struct hfi1_pportdata, sl2sc_kobj);
  358. struct hfi1_ibport *ibp = &ppd->ibport_data;
  359. return sprintf(buf, "%u\n", ibp->sl_to_sc[sattr->sl]);
  360. }
  361. static const struct sysfs_ops hfi1_sl2sc_ops = {
  362. .show = sl2sc_attr_show,
  363. };
  364. static struct kobj_type hfi1_sl2sc_ktype = {
  365. .release = port_release,
  366. .sysfs_ops = &hfi1_sl2sc_ops,
  367. .default_attrs = sl2sc_default_attributes
  368. };
  369. /* End sl2sc */
  370. /* Start vl2mtu */
  371. #define HFI1_VL2MTU_ATTR(N) \
  372. static struct hfi1_vl2mtu_attr hfi1_vl2mtu_attr_##N = { \
  373. .attr = { .name = __stringify(N), .mode = 0444 }, \
  374. .vl = N \
  375. }
  376. struct hfi1_vl2mtu_attr {
  377. struct attribute attr;
  378. int vl;
  379. };
  380. HFI1_VL2MTU_ATTR(0);
  381. HFI1_VL2MTU_ATTR(1);
  382. HFI1_VL2MTU_ATTR(2);
  383. HFI1_VL2MTU_ATTR(3);
  384. HFI1_VL2MTU_ATTR(4);
  385. HFI1_VL2MTU_ATTR(5);
  386. HFI1_VL2MTU_ATTR(6);
  387. HFI1_VL2MTU_ATTR(7);
  388. HFI1_VL2MTU_ATTR(8);
  389. HFI1_VL2MTU_ATTR(9);
  390. HFI1_VL2MTU_ATTR(10);
  391. HFI1_VL2MTU_ATTR(11);
  392. HFI1_VL2MTU_ATTR(12);
  393. HFI1_VL2MTU_ATTR(13);
  394. HFI1_VL2MTU_ATTR(14);
  395. HFI1_VL2MTU_ATTR(15);
  396. static struct attribute *vl2mtu_default_attributes[] = {
  397. &hfi1_vl2mtu_attr_0.attr,
  398. &hfi1_vl2mtu_attr_1.attr,
  399. &hfi1_vl2mtu_attr_2.attr,
  400. &hfi1_vl2mtu_attr_3.attr,
  401. &hfi1_vl2mtu_attr_4.attr,
  402. &hfi1_vl2mtu_attr_5.attr,
  403. &hfi1_vl2mtu_attr_6.attr,
  404. &hfi1_vl2mtu_attr_7.attr,
  405. &hfi1_vl2mtu_attr_8.attr,
  406. &hfi1_vl2mtu_attr_9.attr,
  407. &hfi1_vl2mtu_attr_10.attr,
  408. &hfi1_vl2mtu_attr_11.attr,
  409. &hfi1_vl2mtu_attr_12.attr,
  410. &hfi1_vl2mtu_attr_13.attr,
  411. &hfi1_vl2mtu_attr_14.attr,
  412. &hfi1_vl2mtu_attr_15.attr,
  413. NULL
  414. };
  415. static ssize_t vl2mtu_attr_show(struct kobject *kobj, struct attribute *attr,
  416. char *buf)
  417. {
  418. struct hfi1_vl2mtu_attr *vlattr =
  419. container_of(attr, struct hfi1_vl2mtu_attr, attr);
  420. struct hfi1_pportdata *ppd =
  421. container_of(kobj, struct hfi1_pportdata, vl2mtu_kobj);
  422. struct hfi1_devdata *dd = ppd->dd;
  423. return sprintf(buf, "%u\n", dd->vld[vlattr->vl].mtu);
  424. }
  425. static const struct sysfs_ops hfi1_vl2mtu_ops = {
  426. .show = vl2mtu_attr_show,
  427. };
  428. static struct kobj_type hfi1_vl2mtu_ktype = {
  429. .release = port_release,
  430. .sysfs_ops = &hfi1_vl2mtu_ops,
  431. .default_attrs = vl2mtu_default_attributes
  432. };
  433. /* end of per-port file structures and support code */
  434. /*
  435. * Start of per-unit (or driver, in some cases, but replicated
  436. * per unit) functions (these get a device *)
  437. */
  438. static ssize_t show_rev(struct device *device, struct device_attribute *attr,
  439. char *buf)
  440. {
  441. struct hfi1_ibdev *dev =
  442. container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
  443. return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev);
  444. }
  445. static ssize_t show_hfi(struct device *device, struct device_attribute *attr,
  446. char *buf)
  447. {
  448. struct hfi1_ibdev *dev =
  449. container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
  450. struct hfi1_devdata *dd = dd_from_dev(dev);
  451. int ret;
  452. if (!dd->boardname)
  453. ret = -EINVAL;
  454. else
  455. ret = scnprintf(buf, PAGE_SIZE, "%s\n", dd->boardname);
  456. return ret;
  457. }
  458. static ssize_t show_boardversion(struct device *device,
  459. struct device_attribute *attr, char *buf)
  460. {
  461. struct hfi1_ibdev *dev =
  462. container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
  463. struct hfi1_devdata *dd = dd_from_dev(dev);
  464. /* The string printed here is already newline-terminated. */
  465. return scnprintf(buf, PAGE_SIZE, "%s", dd->boardversion);
  466. }
  467. static ssize_t show_nctxts(struct device *device,
  468. struct device_attribute *attr, char *buf)
  469. {
  470. struct hfi1_ibdev *dev =
  471. container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
  472. struct hfi1_devdata *dd = dd_from_dev(dev);
  473. /*
  474. * Return the smaller of send and receive contexts.
  475. * Normally, user level applications would require both a send
  476. * and a receive context, so returning the smaller of the two counts
  477. * give a more accurate picture of total contexts available.
  478. */
  479. return scnprintf(buf, PAGE_SIZE, "%u\n",
  480. min(dd->num_rcv_contexts - dd->first_user_ctxt,
  481. (u32)dd->sc_sizes[SC_USER].count));
  482. }
  483. static ssize_t show_nfreectxts(struct device *device,
  484. struct device_attribute *attr, char *buf)
  485. {
  486. struct hfi1_ibdev *dev =
  487. container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
  488. struct hfi1_devdata *dd = dd_from_dev(dev);
  489. /* Return the number of free user ports (contexts) available. */
  490. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->freectxts);
  491. }
  492. static ssize_t show_serial(struct device *device,
  493. struct device_attribute *attr, char *buf)
  494. {
  495. struct hfi1_ibdev *dev =
  496. container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
  497. struct hfi1_devdata *dd = dd_from_dev(dev);
  498. return scnprintf(buf, PAGE_SIZE, "%s", dd->serial);
  499. }
  500. static ssize_t store_chip_reset(struct device *device,
  501. struct device_attribute *attr, const char *buf,
  502. size_t count)
  503. {
  504. struct hfi1_ibdev *dev =
  505. container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
  506. struct hfi1_devdata *dd = dd_from_dev(dev);
  507. int ret;
  508. if (count < 5 || memcmp(buf, "reset", 5) || !dd->diag_client) {
  509. ret = -EINVAL;
  510. goto bail;
  511. }
  512. ret = hfi1_reset_device(dd->unit);
  513. bail:
  514. return ret < 0 ? ret : count;
  515. }
  516. /*
  517. * Convert the reported temperature from an integer (reported in
  518. * units of 0.25C) to a floating point number.
  519. */
  520. #define temp2str(temp, buf, size, idx) \
  521. scnprintf((buf) + (idx), (size) - (idx), "%u.%02u ", \
  522. ((temp) >> 2), ((temp) & 0x3) * 25)
  523. /*
  524. * Dump tempsense values, in decimal, to ease shell-scripts.
  525. */
  526. static ssize_t show_tempsense(struct device *device,
  527. struct device_attribute *attr, char *buf)
  528. {
  529. struct hfi1_ibdev *dev =
  530. container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
  531. struct hfi1_devdata *dd = dd_from_dev(dev);
  532. struct hfi1_temp temp;
  533. int ret;
  534. ret = hfi1_tempsense_rd(dd, &temp);
  535. if (!ret) {
  536. int idx = 0;
  537. idx += temp2str(temp.curr, buf, PAGE_SIZE, idx);
  538. idx += temp2str(temp.lo_lim, buf, PAGE_SIZE, idx);
  539. idx += temp2str(temp.hi_lim, buf, PAGE_SIZE, idx);
  540. idx += temp2str(temp.crit_lim, buf, PAGE_SIZE, idx);
  541. idx += scnprintf(buf + idx, PAGE_SIZE - idx,
  542. "%u %u %u\n", temp.triggers & 0x1,
  543. temp.triggers & 0x2, temp.triggers & 0x4);
  544. ret = idx;
  545. }
  546. return ret;
  547. }
  548. static ssize_t show_sdma_affinity(struct device *device,
  549. struct device_attribute *attr, char *buf)
  550. {
  551. struct hfi1_ibdev *dev =
  552. container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
  553. struct hfi1_devdata *dd = dd_from_dev(dev);
  554. return hfi1_get_sdma_affinity(dd, buf);
  555. }
  556. static ssize_t store_sdma_affinity(struct device *device,
  557. struct device_attribute *attr,
  558. const char *buf, size_t count)
  559. {
  560. struct hfi1_ibdev *dev =
  561. container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
  562. struct hfi1_devdata *dd = dd_from_dev(dev);
  563. return hfi1_set_sdma_affinity(dd, buf, count);
  564. }
  565. /*
  566. * end of per-unit (or driver, in some cases, but replicated
  567. * per unit) functions
  568. */
  569. /* start of per-unit file structures and support code */
  570. static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  571. static DEVICE_ATTR(board_id, S_IRUGO, show_hfi, NULL);
  572. static DEVICE_ATTR(nctxts, S_IRUGO, show_nctxts, NULL);
  573. static DEVICE_ATTR(nfreectxts, S_IRUGO, show_nfreectxts, NULL);
  574. static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
  575. static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
  576. static DEVICE_ATTR(tempsense, S_IRUGO, show_tempsense, NULL);
  577. static DEVICE_ATTR(chip_reset, S_IWUSR, NULL, store_chip_reset);
  578. static DEVICE_ATTR(sdma_affinity, S_IWUSR | S_IRUGO, show_sdma_affinity,
  579. store_sdma_affinity);
  580. static struct device_attribute *hfi1_attributes[] = {
  581. &dev_attr_hw_rev,
  582. &dev_attr_board_id,
  583. &dev_attr_nctxts,
  584. &dev_attr_nfreectxts,
  585. &dev_attr_serial,
  586. &dev_attr_boardversion,
  587. &dev_attr_tempsense,
  588. &dev_attr_chip_reset,
  589. &dev_attr_sdma_affinity,
  590. };
  591. int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
  592. struct kobject *kobj)
  593. {
  594. struct hfi1_pportdata *ppd;
  595. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  596. int ret;
  597. if (!port_num || port_num > dd->num_pports) {
  598. dd_dev_err(dd,
  599. "Skipping infiniband class with invalid port %u\n",
  600. port_num);
  601. return -ENODEV;
  602. }
  603. ppd = &dd->pport[port_num - 1];
  604. ret = kobject_init_and_add(&ppd->sc2vl_kobj, &hfi1_sc2vl_ktype, kobj,
  605. "sc2vl");
  606. if (ret) {
  607. dd_dev_err(dd,
  608. "Skipping sc2vl sysfs info, (err %d) port %u\n",
  609. ret, port_num);
  610. goto bail;
  611. }
  612. kobject_uevent(&ppd->sc2vl_kobj, KOBJ_ADD);
  613. ret = kobject_init_and_add(&ppd->sl2sc_kobj, &hfi1_sl2sc_ktype, kobj,
  614. "sl2sc");
  615. if (ret) {
  616. dd_dev_err(dd,
  617. "Skipping sl2sc sysfs info, (err %d) port %u\n",
  618. ret, port_num);
  619. goto bail_sc2vl;
  620. }
  621. kobject_uevent(&ppd->sl2sc_kobj, KOBJ_ADD);
  622. ret = kobject_init_and_add(&ppd->vl2mtu_kobj, &hfi1_vl2mtu_ktype, kobj,
  623. "vl2mtu");
  624. if (ret) {
  625. dd_dev_err(dd,
  626. "Skipping vl2mtu sysfs info, (err %d) port %u\n",
  627. ret, port_num);
  628. goto bail_sl2sc;
  629. }
  630. kobject_uevent(&ppd->vl2mtu_kobj, KOBJ_ADD);
  631. ret = kobject_init_and_add(&ppd->pport_cc_kobj, &port_cc_ktype,
  632. kobj, "CCMgtA");
  633. if (ret) {
  634. dd_dev_err(dd,
  635. "Skipping Congestion Control sysfs info, (err %d) port %u\n",
  636. ret, port_num);
  637. goto bail_vl2mtu;
  638. }
  639. kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD);
  640. ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, &cc_setting_bin_attr);
  641. if (ret) {
  642. dd_dev_err(dd,
  643. "Skipping Congestion Control setting sysfs info, (err %d) port %u\n",
  644. ret, port_num);
  645. goto bail_cc;
  646. }
  647. ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, &cc_table_bin_attr);
  648. if (ret) {
  649. dd_dev_err(dd,
  650. "Skipping Congestion Control table sysfs info, (err %d) port %u\n",
  651. ret, port_num);
  652. goto bail_cc_entry_bin;
  653. }
  654. dd_dev_info(dd,
  655. "Congestion Control Agent enabled for port %d\n",
  656. port_num);
  657. return 0;
  658. bail_cc_entry_bin:
  659. sysfs_remove_bin_file(&ppd->pport_cc_kobj,
  660. &cc_setting_bin_attr);
  661. bail_cc:
  662. kobject_put(&ppd->pport_cc_kobj);
  663. bail_vl2mtu:
  664. kobject_put(&ppd->vl2mtu_kobj);
  665. bail_sl2sc:
  666. kobject_put(&ppd->sl2sc_kobj);
  667. bail_sc2vl:
  668. kobject_put(&ppd->sc2vl_kobj);
  669. bail:
  670. return ret;
  671. }
  672. /*
  673. * Register and create our files in /sys/class/infiniband.
  674. */
  675. int hfi1_verbs_register_sysfs(struct hfi1_devdata *dd)
  676. {
  677. struct ib_device *dev = &dd->verbs_dev.rdi.ibdev;
  678. int i, ret;
  679. for (i = 0; i < ARRAY_SIZE(hfi1_attributes); ++i) {
  680. ret = device_create_file(&dev->dev, hfi1_attributes[i]);
  681. if (ret)
  682. goto bail;
  683. }
  684. return 0;
  685. bail:
  686. for (i = 0; i < ARRAY_SIZE(hfi1_attributes); ++i)
  687. device_remove_file(&dev->dev, hfi1_attributes[i]);
  688. return ret;
  689. }
  690. /*
  691. * Unregister and remove our files in /sys/class/infiniband.
  692. */
  693. void hfi1_verbs_unregister_sysfs(struct hfi1_devdata *dd)
  694. {
  695. struct hfi1_pportdata *ppd;
  696. int i;
  697. for (i = 0; i < dd->num_pports; i++) {
  698. ppd = &dd->pport[i];
  699. sysfs_remove_bin_file(&ppd->pport_cc_kobj,
  700. &cc_setting_bin_attr);
  701. sysfs_remove_bin_file(&ppd->pport_cc_kobj,
  702. &cc_table_bin_attr);
  703. kobject_put(&ppd->pport_cc_kobj);
  704. kobject_put(&ppd->vl2mtu_kobj);
  705. kobject_put(&ppd->sl2sc_kobj);
  706. kobject_put(&ppd->sc2vl_kobj);
  707. }
  708. }