ipath_sysfs.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. /*
  2. * Copyright (c) 2006, 2007 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 "ipath_kernel.h"
  35. #include "ipath_common.h"
  36. /**
  37. * ipath_parse_ushort - parse an unsigned short value in an arbitrary base
  38. * @str: the string containing the number
  39. * @valp: where to put the result
  40. *
  41. * returns the number of bytes consumed, or negative value on error
  42. */
  43. int ipath_parse_ushort(const char *str, unsigned short *valp)
  44. {
  45. unsigned long val;
  46. char *end;
  47. int ret;
  48. if (!isdigit(str[0])) {
  49. ret = -EINVAL;
  50. goto bail;
  51. }
  52. val = simple_strtoul(str, &end, 0);
  53. if (val > 0xffff) {
  54. ret = -EINVAL;
  55. goto bail;
  56. }
  57. *valp = val;
  58. ret = end + 1 - str;
  59. if (ret == 0)
  60. ret = -EINVAL;
  61. bail:
  62. return ret;
  63. }
  64. static ssize_t show_version(struct device_driver *dev, char *buf)
  65. {
  66. /* The string printed here is already newline-terminated. */
  67. return scnprintf(buf, PAGE_SIZE, "%s", ib_ipath_version);
  68. }
  69. static ssize_t show_num_units(struct device_driver *dev, char *buf)
  70. {
  71. return scnprintf(buf, PAGE_SIZE, "%d\n",
  72. ipath_count_units(NULL, NULL, NULL));
  73. }
  74. static ssize_t show_status(struct device *dev,
  75. struct device_attribute *attr,
  76. char *buf)
  77. {
  78. struct ipath_devdata *dd = dev_get_drvdata(dev);
  79. ssize_t ret;
  80. if (!dd->ipath_statusp) {
  81. ret = -EINVAL;
  82. goto bail;
  83. }
  84. ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n",
  85. (unsigned long long) *(dd->ipath_statusp));
  86. bail:
  87. return ret;
  88. }
  89. static const char *ipath_status_str[] = {
  90. "Initted",
  91. "Disabled",
  92. "Admin_Disabled",
  93. "", /* This used to be the old "OIB_SMA" status. */
  94. "", /* This used to be the old "SMA" status. */
  95. "Present",
  96. "IB_link_up",
  97. "IB_configured",
  98. "NoIBcable",
  99. "Fatal_Hardware_Error",
  100. NULL,
  101. };
  102. static ssize_t show_status_str(struct device *dev,
  103. struct device_attribute *attr,
  104. char *buf)
  105. {
  106. struct ipath_devdata *dd = dev_get_drvdata(dev);
  107. int i, any;
  108. u64 s;
  109. ssize_t ret;
  110. if (!dd->ipath_statusp) {
  111. ret = -EINVAL;
  112. goto bail;
  113. }
  114. s = *(dd->ipath_statusp);
  115. *buf = '\0';
  116. for (any = i = 0; s && ipath_status_str[i]; i++) {
  117. if (s & 1) {
  118. if (any && strlcat(buf, " ", PAGE_SIZE) >=
  119. PAGE_SIZE)
  120. /* overflow */
  121. break;
  122. if (strlcat(buf, ipath_status_str[i],
  123. PAGE_SIZE) >= PAGE_SIZE)
  124. break;
  125. any = 1;
  126. }
  127. s >>= 1;
  128. }
  129. if (any)
  130. strlcat(buf, "\n", PAGE_SIZE);
  131. ret = strlen(buf);
  132. bail:
  133. return ret;
  134. }
  135. static ssize_t show_boardversion(struct device *dev,
  136. struct device_attribute *attr,
  137. char *buf)
  138. {
  139. struct ipath_devdata *dd = dev_get_drvdata(dev);
  140. /* The string printed here is already newline-terminated. */
  141. return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_boardversion);
  142. }
  143. static ssize_t show_lmc(struct device *dev,
  144. struct device_attribute *attr,
  145. char *buf)
  146. {
  147. struct ipath_devdata *dd = dev_get_drvdata(dev);
  148. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_lmc);
  149. }
  150. static ssize_t store_lmc(struct device *dev,
  151. struct device_attribute *attr,
  152. const char *buf,
  153. size_t count)
  154. {
  155. struct ipath_devdata *dd = dev_get_drvdata(dev);
  156. u16 lmc = 0;
  157. int ret;
  158. ret = ipath_parse_ushort(buf, &lmc);
  159. if (ret < 0)
  160. goto invalid;
  161. if (lmc > 7) {
  162. ret = -EINVAL;
  163. goto invalid;
  164. }
  165. ipath_set_lid(dd, dd->ipath_lid, lmc);
  166. goto bail;
  167. invalid:
  168. ipath_dev_err(dd, "attempt to set invalid LMC %u\n", lmc);
  169. bail:
  170. return ret;
  171. }
  172. static ssize_t show_lid(struct device *dev,
  173. struct device_attribute *attr,
  174. char *buf)
  175. {
  176. struct ipath_devdata *dd = dev_get_drvdata(dev);
  177. return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_lid);
  178. }
  179. static ssize_t store_lid(struct device *dev,
  180. struct device_attribute *attr,
  181. const char *buf,
  182. size_t count)
  183. {
  184. struct ipath_devdata *dd = dev_get_drvdata(dev);
  185. u16 lid = 0;
  186. int ret;
  187. ret = ipath_parse_ushort(buf, &lid);
  188. if (ret < 0)
  189. goto invalid;
  190. if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE) {
  191. ret = -EINVAL;
  192. goto invalid;
  193. }
  194. ipath_set_lid(dd, lid, dd->ipath_lmc);
  195. goto bail;
  196. invalid:
  197. ipath_dev_err(dd, "attempt to set invalid LID 0x%x\n", lid);
  198. bail:
  199. return ret;
  200. }
  201. static ssize_t show_mlid(struct device *dev,
  202. struct device_attribute *attr,
  203. char *buf)
  204. {
  205. struct ipath_devdata *dd = dev_get_drvdata(dev);
  206. return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_mlid);
  207. }
  208. static ssize_t store_mlid(struct device *dev,
  209. struct device_attribute *attr,
  210. const char *buf,
  211. size_t count)
  212. {
  213. struct ipath_devdata *dd = dev_get_drvdata(dev);
  214. u16 mlid;
  215. int ret;
  216. ret = ipath_parse_ushort(buf, &mlid);
  217. if (ret < 0 || mlid < IPATH_MULTICAST_LID_BASE)
  218. goto invalid;
  219. dd->ipath_mlid = mlid;
  220. goto bail;
  221. invalid:
  222. ipath_dev_err(dd, "attempt to set invalid MLID\n");
  223. bail:
  224. return ret;
  225. }
  226. static ssize_t show_guid(struct device *dev,
  227. struct device_attribute *attr,
  228. char *buf)
  229. {
  230. struct ipath_devdata *dd = dev_get_drvdata(dev);
  231. u8 *guid;
  232. guid = (u8 *) & (dd->ipath_guid);
  233. return scnprintf(buf, PAGE_SIZE,
  234. "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
  235. guid[0], guid[1], guid[2], guid[3],
  236. guid[4], guid[5], guid[6], guid[7]);
  237. }
  238. static ssize_t store_guid(struct device *dev,
  239. struct device_attribute *attr,
  240. const char *buf,
  241. size_t count)
  242. {
  243. struct ipath_devdata *dd = dev_get_drvdata(dev);
  244. ssize_t ret;
  245. unsigned short guid[8];
  246. __be64 new_guid;
  247. u8 *ng;
  248. int i;
  249. if (sscanf(buf, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
  250. &guid[0], &guid[1], &guid[2], &guid[3],
  251. &guid[4], &guid[5], &guid[6], &guid[7]) != 8)
  252. goto invalid;
  253. ng = (u8 *) &new_guid;
  254. for (i = 0; i < 8; i++) {
  255. if (guid[i] > 0xff)
  256. goto invalid;
  257. ng[i] = guid[i];
  258. }
  259. if (new_guid == 0)
  260. goto invalid;
  261. dd->ipath_guid = new_guid;
  262. dd->ipath_nguid = 1;
  263. ret = strlen(buf);
  264. goto bail;
  265. invalid:
  266. ipath_dev_err(dd, "attempt to set invalid GUID\n");
  267. ret = -EINVAL;
  268. bail:
  269. return ret;
  270. }
  271. static ssize_t show_nguid(struct device *dev,
  272. struct device_attribute *attr,
  273. char *buf)
  274. {
  275. struct ipath_devdata *dd = dev_get_drvdata(dev);
  276. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid);
  277. }
  278. static ssize_t show_nports(struct device *dev,
  279. struct device_attribute *attr,
  280. char *buf)
  281. {
  282. struct ipath_devdata *dd = dev_get_drvdata(dev);
  283. /* Return the number of user ports available. */
  284. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_cfgports - 1);
  285. }
  286. static ssize_t show_serial(struct device *dev,
  287. struct device_attribute *attr,
  288. char *buf)
  289. {
  290. struct ipath_devdata *dd = dev_get_drvdata(dev);
  291. buf[sizeof dd->ipath_serial] = '\0';
  292. memcpy(buf, dd->ipath_serial, sizeof dd->ipath_serial);
  293. strcat(buf, "\n");
  294. return strlen(buf);
  295. }
  296. static ssize_t show_unit(struct device *dev,
  297. struct device_attribute *attr,
  298. char *buf)
  299. {
  300. struct ipath_devdata *dd = dev_get_drvdata(dev);
  301. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_unit);
  302. }
  303. static ssize_t show_jint_max_packets(struct device *dev,
  304. struct device_attribute *attr,
  305. char *buf)
  306. {
  307. struct ipath_devdata *dd = dev_get_drvdata(dev);
  308. return scnprintf(buf, PAGE_SIZE, "%hu\n", dd->ipath_jint_max_packets);
  309. }
  310. static ssize_t store_jint_max_packets(struct device *dev,
  311. struct device_attribute *attr,
  312. const char *buf,
  313. size_t count)
  314. {
  315. struct ipath_devdata *dd = dev_get_drvdata(dev);
  316. u16 v = 0;
  317. int ret;
  318. ret = ipath_parse_ushort(buf, &v);
  319. if (ret < 0)
  320. ipath_dev_err(dd, "invalid jint_max_packets.\n");
  321. else
  322. dd->ipath_f_config_jint(dd, dd->ipath_jint_idle_ticks, v);
  323. return ret;
  324. }
  325. static ssize_t show_jint_idle_ticks(struct device *dev,
  326. struct device_attribute *attr,
  327. char *buf)
  328. {
  329. struct ipath_devdata *dd = dev_get_drvdata(dev);
  330. return scnprintf(buf, PAGE_SIZE, "%hu\n", dd->ipath_jint_idle_ticks);
  331. }
  332. static ssize_t store_jint_idle_ticks(struct device *dev,
  333. struct device_attribute *attr,
  334. const char *buf,
  335. size_t count)
  336. {
  337. struct ipath_devdata *dd = dev_get_drvdata(dev);
  338. u16 v = 0;
  339. int ret;
  340. ret = ipath_parse_ushort(buf, &v);
  341. if (ret < 0)
  342. ipath_dev_err(dd, "invalid jint_idle_ticks.\n");
  343. else
  344. dd->ipath_f_config_jint(dd, v, dd->ipath_jint_max_packets);
  345. return ret;
  346. }
  347. #define DEVICE_COUNTER(name, attr) \
  348. static ssize_t show_counter_##name(struct device *dev, \
  349. struct device_attribute *attr, \
  350. char *buf) \
  351. { \
  352. struct ipath_devdata *dd = dev_get_drvdata(dev); \
  353. return scnprintf(\
  354. buf, PAGE_SIZE, "%llu\n", (unsigned long long) \
  355. ipath_snap_cntr( \
  356. dd, offsetof(struct infinipath_counters, \
  357. attr) / sizeof(u64))); \
  358. } \
  359. static DEVICE_ATTR(name, S_IRUGO, show_counter_##name, NULL);
  360. DEVICE_COUNTER(ib_link_downeds, IBLinkDownedCnt);
  361. DEVICE_COUNTER(ib_link_err_recoveries, IBLinkErrRecoveryCnt);
  362. DEVICE_COUNTER(ib_status_changes, IBStatusChangeCnt);
  363. DEVICE_COUNTER(ib_symbol_errs, IBSymbolErrCnt);
  364. DEVICE_COUNTER(lb_flow_stalls, LBFlowStallCnt);
  365. DEVICE_COUNTER(lb_ints, LBIntCnt);
  366. DEVICE_COUNTER(rx_bad_formats, RxBadFormatCnt);
  367. DEVICE_COUNTER(rx_buf_ovfls, RxBufOvflCnt);
  368. DEVICE_COUNTER(rx_data_pkts, RxDataPktCnt);
  369. DEVICE_COUNTER(rx_dropped_pkts, RxDroppedPktCnt);
  370. DEVICE_COUNTER(rx_dwords, RxDwordCnt);
  371. DEVICE_COUNTER(rx_ebps, RxEBPCnt);
  372. DEVICE_COUNTER(rx_flow_ctrl_errs, RxFlowCtrlErrCnt);
  373. DEVICE_COUNTER(rx_flow_pkts, RxFlowPktCnt);
  374. DEVICE_COUNTER(rx_icrc_errs, RxICRCErrCnt);
  375. DEVICE_COUNTER(rx_len_errs, RxLenErrCnt);
  376. DEVICE_COUNTER(rx_link_problems, RxLinkProblemCnt);
  377. DEVICE_COUNTER(rx_lpcrc_errs, RxLPCRCErrCnt);
  378. DEVICE_COUNTER(rx_max_min_len_errs, RxMaxMinLenErrCnt);
  379. DEVICE_COUNTER(rx_p0_hdr_egr_ovfls, RxP0HdrEgrOvflCnt);
  380. DEVICE_COUNTER(rx_p1_hdr_egr_ovfls, RxP1HdrEgrOvflCnt);
  381. DEVICE_COUNTER(rx_p2_hdr_egr_ovfls, RxP2HdrEgrOvflCnt);
  382. DEVICE_COUNTER(rx_p3_hdr_egr_ovfls, RxP3HdrEgrOvflCnt);
  383. DEVICE_COUNTER(rx_p4_hdr_egr_ovfls, RxP4HdrEgrOvflCnt);
  384. DEVICE_COUNTER(rx_p5_hdr_egr_ovfls, RxP5HdrEgrOvflCnt);
  385. DEVICE_COUNTER(rx_p6_hdr_egr_ovfls, RxP6HdrEgrOvflCnt);
  386. DEVICE_COUNTER(rx_p7_hdr_egr_ovfls, RxP7HdrEgrOvflCnt);
  387. DEVICE_COUNTER(rx_p8_hdr_egr_ovfls, RxP8HdrEgrOvflCnt);
  388. DEVICE_COUNTER(rx_pkey_mismatches, RxPKeyMismatchCnt);
  389. DEVICE_COUNTER(rx_tid_full_errs, RxTIDFullErrCnt);
  390. DEVICE_COUNTER(rx_tid_valid_errs, RxTIDValidErrCnt);
  391. DEVICE_COUNTER(rx_vcrc_errs, RxVCRCErrCnt);
  392. DEVICE_COUNTER(tx_data_pkts, TxDataPktCnt);
  393. DEVICE_COUNTER(tx_dropped_pkts, TxDroppedPktCnt);
  394. DEVICE_COUNTER(tx_dwords, TxDwordCnt);
  395. DEVICE_COUNTER(tx_flow_pkts, TxFlowPktCnt);
  396. DEVICE_COUNTER(tx_flow_stalls, TxFlowStallCnt);
  397. DEVICE_COUNTER(tx_len_errs, TxLenErrCnt);
  398. DEVICE_COUNTER(tx_max_min_len_errs, TxMaxMinLenErrCnt);
  399. DEVICE_COUNTER(tx_underruns, TxUnderrunCnt);
  400. DEVICE_COUNTER(tx_unsup_vl_errs, TxUnsupVLErrCnt);
  401. static struct attribute *dev_counter_attributes[] = {
  402. &dev_attr_ib_link_downeds.attr,
  403. &dev_attr_ib_link_err_recoveries.attr,
  404. &dev_attr_ib_status_changes.attr,
  405. &dev_attr_ib_symbol_errs.attr,
  406. &dev_attr_lb_flow_stalls.attr,
  407. &dev_attr_lb_ints.attr,
  408. &dev_attr_rx_bad_formats.attr,
  409. &dev_attr_rx_buf_ovfls.attr,
  410. &dev_attr_rx_data_pkts.attr,
  411. &dev_attr_rx_dropped_pkts.attr,
  412. &dev_attr_rx_dwords.attr,
  413. &dev_attr_rx_ebps.attr,
  414. &dev_attr_rx_flow_ctrl_errs.attr,
  415. &dev_attr_rx_flow_pkts.attr,
  416. &dev_attr_rx_icrc_errs.attr,
  417. &dev_attr_rx_len_errs.attr,
  418. &dev_attr_rx_link_problems.attr,
  419. &dev_attr_rx_lpcrc_errs.attr,
  420. &dev_attr_rx_max_min_len_errs.attr,
  421. &dev_attr_rx_p0_hdr_egr_ovfls.attr,
  422. &dev_attr_rx_p1_hdr_egr_ovfls.attr,
  423. &dev_attr_rx_p2_hdr_egr_ovfls.attr,
  424. &dev_attr_rx_p3_hdr_egr_ovfls.attr,
  425. &dev_attr_rx_p4_hdr_egr_ovfls.attr,
  426. &dev_attr_rx_p5_hdr_egr_ovfls.attr,
  427. &dev_attr_rx_p6_hdr_egr_ovfls.attr,
  428. &dev_attr_rx_p7_hdr_egr_ovfls.attr,
  429. &dev_attr_rx_p8_hdr_egr_ovfls.attr,
  430. &dev_attr_rx_pkey_mismatches.attr,
  431. &dev_attr_rx_tid_full_errs.attr,
  432. &dev_attr_rx_tid_valid_errs.attr,
  433. &dev_attr_rx_vcrc_errs.attr,
  434. &dev_attr_tx_data_pkts.attr,
  435. &dev_attr_tx_dropped_pkts.attr,
  436. &dev_attr_tx_dwords.attr,
  437. &dev_attr_tx_flow_pkts.attr,
  438. &dev_attr_tx_flow_stalls.attr,
  439. &dev_attr_tx_len_errs.attr,
  440. &dev_attr_tx_max_min_len_errs.attr,
  441. &dev_attr_tx_underruns.attr,
  442. &dev_attr_tx_unsup_vl_errs.attr,
  443. NULL
  444. };
  445. static struct attribute_group dev_counter_attr_group = {
  446. .name = "counters",
  447. .attrs = dev_counter_attributes
  448. };
  449. static ssize_t store_reset(struct device *dev,
  450. struct device_attribute *attr,
  451. const char *buf,
  452. size_t count)
  453. {
  454. struct ipath_devdata *dd = dev_get_drvdata(dev);
  455. int ret;
  456. if (count < 5 || memcmp(buf, "reset", 5)) {
  457. ret = -EINVAL;
  458. goto bail;
  459. }
  460. if (dd->ipath_flags & IPATH_DISABLED) {
  461. /*
  462. * post-reset init would re-enable interrupts, etc.
  463. * so don't allow reset on disabled devices. Not
  464. * perfect error, but about the best choice.
  465. */
  466. dev_info(dev,"Unit %d is disabled, can't reset\n",
  467. dd->ipath_unit);
  468. ret = -EINVAL;
  469. }
  470. ret = ipath_reset_device(dd->ipath_unit);
  471. bail:
  472. return ret<0 ? ret : count;
  473. }
  474. static ssize_t store_link_state(struct device *dev,
  475. struct device_attribute *attr,
  476. const char *buf,
  477. size_t count)
  478. {
  479. struct ipath_devdata *dd = dev_get_drvdata(dev);
  480. int ret, r;
  481. u16 state;
  482. ret = ipath_parse_ushort(buf, &state);
  483. if (ret < 0)
  484. goto invalid;
  485. r = ipath_set_linkstate(dd, state);
  486. if (r < 0) {
  487. ret = r;
  488. goto bail;
  489. }
  490. goto bail;
  491. invalid:
  492. ipath_dev_err(dd, "attempt to set invalid link state\n");
  493. bail:
  494. return ret;
  495. }
  496. static ssize_t show_mtu(struct device *dev,
  497. struct device_attribute *attr,
  498. char *buf)
  499. {
  500. struct ipath_devdata *dd = dev_get_drvdata(dev);
  501. return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_ibmtu);
  502. }
  503. static ssize_t store_mtu(struct device *dev,
  504. struct device_attribute *attr,
  505. const char *buf,
  506. size_t count)
  507. {
  508. struct ipath_devdata *dd = dev_get_drvdata(dev);
  509. ssize_t ret;
  510. u16 mtu = 0;
  511. int r;
  512. ret = ipath_parse_ushort(buf, &mtu);
  513. if (ret < 0)
  514. goto invalid;
  515. r = ipath_set_mtu(dd, mtu);
  516. if (r < 0)
  517. ret = r;
  518. goto bail;
  519. invalid:
  520. ipath_dev_err(dd, "attempt to set invalid MTU\n");
  521. bail:
  522. return ret;
  523. }
  524. static ssize_t show_enabled(struct device *dev,
  525. struct device_attribute *attr,
  526. char *buf)
  527. {
  528. struct ipath_devdata *dd = dev_get_drvdata(dev);
  529. return scnprintf(buf, PAGE_SIZE, "%u\n",
  530. (dd->ipath_flags & IPATH_DISABLED) ? 0 : 1);
  531. }
  532. static ssize_t store_enabled(struct device *dev,
  533. struct device_attribute *attr,
  534. const char *buf,
  535. size_t count)
  536. {
  537. struct ipath_devdata *dd = dev_get_drvdata(dev);
  538. ssize_t ret;
  539. u16 enable = 0;
  540. ret = ipath_parse_ushort(buf, &enable);
  541. if (ret < 0) {
  542. ipath_dev_err(dd, "attempt to use non-numeric on enable\n");
  543. goto bail;
  544. }
  545. if (enable) {
  546. if (!(dd->ipath_flags & IPATH_DISABLED))
  547. goto bail;
  548. dev_info(dev, "Enabling unit %d\n", dd->ipath_unit);
  549. /* same as post-reset */
  550. ret = ipath_init_chip(dd, 1);
  551. if (ret)
  552. ipath_dev_err(dd, "Failed to enable unit %d\n",
  553. dd->ipath_unit);
  554. else {
  555. dd->ipath_flags &= ~IPATH_DISABLED;
  556. *dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED;
  557. }
  558. }
  559. else if (!(dd->ipath_flags & IPATH_DISABLED)) {
  560. dev_info(dev, "Disabling unit %d\n", dd->ipath_unit);
  561. ipath_shutdown_device(dd);
  562. dd->ipath_flags |= IPATH_DISABLED;
  563. *dd->ipath_statusp |= IPATH_STATUS_ADMIN_DISABLED;
  564. }
  565. bail:
  566. return ret;
  567. }
  568. static ssize_t store_rx_pol_inv(struct device *dev,
  569. struct device_attribute *attr,
  570. const char *buf,
  571. size_t count)
  572. {
  573. struct ipath_devdata *dd = dev_get_drvdata(dev);
  574. int ret, r;
  575. u16 val;
  576. ret = ipath_parse_ushort(buf, &val);
  577. if (ret < 0)
  578. goto invalid;
  579. r = ipath_set_rx_pol_inv(dd, val);
  580. if (r < 0) {
  581. ret = r;
  582. goto bail;
  583. }
  584. goto bail;
  585. invalid:
  586. ipath_dev_err(dd, "attempt to set invalid Rx Polarity invert\n");
  587. bail:
  588. return ret;
  589. }
  590. static ssize_t store_led_override(struct device *dev,
  591. struct device_attribute *attr,
  592. const char *buf,
  593. size_t count)
  594. {
  595. struct ipath_devdata *dd = dev_get_drvdata(dev);
  596. int ret;
  597. u16 val;
  598. ret = ipath_parse_ushort(buf, &val);
  599. if (ret > 0)
  600. ipath_set_led_override(dd, val);
  601. else
  602. ipath_dev_err(dd, "attempt to set invalid LED override\n");
  603. return ret;
  604. }
  605. static ssize_t show_logged_errs(struct device *dev,
  606. struct device_attribute *attr,
  607. char *buf)
  608. {
  609. struct ipath_devdata *dd = dev_get_drvdata(dev);
  610. int idx, count;
  611. /* force consistency with actual EEPROM */
  612. if (ipath_update_eeprom_log(dd) != 0)
  613. return -ENXIO;
  614. count = 0;
  615. for (idx = 0; idx < IPATH_EEP_LOG_CNT; ++idx) {
  616. count += scnprintf(buf + count, PAGE_SIZE - count, "%d%c",
  617. dd->ipath_eep_st_errs[idx],
  618. idx == (IPATH_EEP_LOG_CNT - 1) ? '\n' : ' ');
  619. }
  620. return count;
  621. }
  622. /*
  623. * New sysfs entries to control various IB config. These all turn into
  624. * accesses via ipath_f_get/set_ib_cfg.
  625. *
  626. * Get/Set heartbeat enable. Or of 1=enabled, 2=auto
  627. */
  628. static ssize_t show_hrtbt_enb(struct device *dev,
  629. struct device_attribute *attr,
  630. char *buf)
  631. {
  632. struct ipath_devdata *dd = dev_get_drvdata(dev);
  633. int ret;
  634. ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_HRTBT);
  635. if (ret >= 0)
  636. ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
  637. return ret;
  638. }
  639. static ssize_t store_hrtbt_enb(struct device *dev,
  640. struct device_attribute *attr,
  641. const char *buf,
  642. size_t count)
  643. {
  644. struct ipath_devdata *dd = dev_get_drvdata(dev);
  645. int ret, r;
  646. u16 val;
  647. ret = ipath_parse_ushort(buf, &val);
  648. if (ret >= 0 && val > 3)
  649. ret = -EINVAL;
  650. if (ret < 0) {
  651. ipath_dev_err(dd, "attempt to set invalid Heartbeat enable\n");
  652. goto bail;
  653. }
  654. /*
  655. * Set the "intentional" heartbeat enable per either of
  656. * "Enable" and "Auto", as these are normally set together.
  657. * This bit is consulted when leaving loopback mode,
  658. * because entering loopback mode overrides it and automatically
  659. * disables heartbeat.
  660. */
  661. r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_HRTBT, val);
  662. if (r < 0)
  663. ret = r;
  664. else if (val == IPATH_IB_HRTBT_OFF)
  665. dd->ipath_flags |= IPATH_NO_HRTBT;
  666. else
  667. dd->ipath_flags &= ~IPATH_NO_HRTBT;
  668. bail:
  669. return ret;
  670. }
  671. /*
  672. * Get/Set Link-widths enabled. Or of 1=1x, 2=4x (this is human/IB centric,
  673. * _not_ the particular encoding of any given chip)
  674. */
  675. static ssize_t show_lwid_enb(struct device *dev,
  676. struct device_attribute *attr,
  677. char *buf)
  678. {
  679. struct ipath_devdata *dd = dev_get_drvdata(dev);
  680. int ret;
  681. ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB);
  682. if (ret >= 0)
  683. ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
  684. return ret;
  685. }
  686. static ssize_t store_lwid_enb(struct device *dev,
  687. struct device_attribute *attr,
  688. const char *buf,
  689. size_t count)
  690. {
  691. struct ipath_devdata *dd = dev_get_drvdata(dev);
  692. int ret, r;
  693. u16 val;
  694. ret = ipath_parse_ushort(buf, &val);
  695. if (ret >= 0 && (val == 0 || val > 3))
  696. ret = -EINVAL;
  697. if (ret < 0) {
  698. ipath_dev_err(dd,
  699. "attempt to set invalid Link Width (enable)\n");
  700. goto bail;
  701. }
  702. r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB, val);
  703. if (r < 0)
  704. ret = r;
  705. bail:
  706. return ret;
  707. }
  708. /* Get current link width */
  709. static ssize_t show_lwid(struct device *dev,
  710. struct device_attribute *attr,
  711. char *buf)
  712. {
  713. struct ipath_devdata *dd = dev_get_drvdata(dev);
  714. int ret;
  715. ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LWID);
  716. if (ret >= 0)
  717. ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
  718. return ret;
  719. }
  720. /*
  721. * Get/Set Link-speeds enabled. Or of 1=SDR 2=DDR.
  722. */
  723. static ssize_t show_spd_enb(struct device *dev,
  724. struct device_attribute *attr,
  725. char *buf)
  726. {
  727. struct ipath_devdata *dd = dev_get_drvdata(dev);
  728. int ret;
  729. ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB);
  730. if (ret >= 0)
  731. ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
  732. return ret;
  733. }
  734. static ssize_t store_spd_enb(struct device *dev,
  735. struct device_attribute *attr,
  736. const char *buf,
  737. size_t count)
  738. {
  739. struct ipath_devdata *dd = dev_get_drvdata(dev);
  740. int ret, r;
  741. u16 val;
  742. ret = ipath_parse_ushort(buf, &val);
  743. if (ret >= 0 && (val == 0 || val > (IPATH_IB_SDR | IPATH_IB_DDR)))
  744. ret = -EINVAL;
  745. if (ret < 0) {
  746. ipath_dev_err(dd,
  747. "attempt to set invalid Link Speed (enable)\n");
  748. goto bail;
  749. }
  750. r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB, val);
  751. if (r < 0)
  752. ret = r;
  753. bail:
  754. return ret;
  755. }
  756. /* Get current link speed */
  757. static ssize_t show_spd(struct device *dev,
  758. struct device_attribute *attr,
  759. char *buf)
  760. {
  761. struct ipath_devdata *dd = dev_get_drvdata(dev);
  762. int ret;
  763. ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_SPD);
  764. if (ret >= 0)
  765. ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
  766. return ret;
  767. }
  768. /*
  769. * Get/Set RX polarity-invert enable. 0=no, 1=yes.
  770. */
  771. static ssize_t show_rx_polinv_enb(struct device *dev,
  772. struct device_attribute *attr,
  773. char *buf)
  774. {
  775. struct ipath_devdata *dd = dev_get_drvdata(dev);
  776. int ret;
  777. ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_RXPOL_ENB);
  778. if (ret >= 0)
  779. ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
  780. return ret;
  781. }
  782. static ssize_t store_rx_polinv_enb(struct device *dev,
  783. struct device_attribute *attr,
  784. const char *buf,
  785. size_t count)
  786. {
  787. struct ipath_devdata *dd = dev_get_drvdata(dev);
  788. int ret, r;
  789. u16 val;
  790. ret = ipath_parse_ushort(buf, &val);
  791. if (ret < 0 || val > 1)
  792. goto invalid;
  793. r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_RXPOL_ENB, val);
  794. if (r < 0) {
  795. ret = r;
  796. goto bail;
  797. }
  798. goto bail;
  799. invalid:
  800. ipath_dev_err(dd, "attempt to set invalid Rx Polarity (enable)\n");
  801. bail:
  802. return ret;
  803. }
  804. /*
  805. * Get/Set RX lane-reversal enable. 0=no, 1=yes.
  806. */
  807. static ssize_t show_lanerev_enb(struct device *dev,
  808. struct device_attribute *attr,
  809. char *buf)
  810. {
  811. struct ipath_devdata *dd = dev_get_drvdata(dev);
  812. int ret;
  813. ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LREV_ENB);
  814. if (ret >= 0)
  815. ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
  816. return ret;
  817. }
  818. static ssize_t store_lanerev_enb(struct device *dev,
  819. struct device_attribute *attr,
  820. const char *buf,
  821. size_t count)
  822. {
  823. struct ipath_devdata *dd = dev_get_drvdata(dev);
  824. int ret, r;
  825. u16 val;
  826. ret = ipath_parse_ushort(buf, &val);
  827. if (ret >= 0 && val > 1) {
  828. ret = -EINVAL;
  829. ipath_dev_err(dd,
  830. "attempt to set invalid Lane reversal (enable)\n");
  831. goto bail;
  832. }
  833. r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LREV_ENB, val);
  834. if (r < 0)
  835. ret = r;
  836. bail:
  837. return ret;
  838. }
  839. static DRIVER_ATTR(num_units, S_IRUGO, show_num_units, NULL);
  840. static DRIVER_ATTR(version, S_IRUGO, show_version, NULL);
  841. static struct attribute *driver_attributes[] = {
  842. &driver_attr_num_units.attr,
  843. &driver_attr_version.attr,
  844. NULL
  845. };
  846. static struct attribute_group driver_attr_group = {
  847. .attrs = driver_attributes
  848. };
  849. struct attribute_group *ipath_driver_attr_groups[] = {
  850. &driver_attr_group,
  851. NULL,
  852. };
  853. static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid);
  854. static DEVICE_ATTR(lmc, S_IWUSR | S_IRUGO, show_lmc, store_lmc);
  855. static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid);
  856. static DEVICE_ATTR(link_state, S_IWUSR, NULL, store_link_state);
  857. static DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid);
  858. static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu);
  859. static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled);
  860. static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL);
  861. static DEVICE_ATTR(nports, S_IRUGO, show_nports, NULL);
  862. static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset);
  863. static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
  864. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  865. static DEVICE_ATTR(status_str, S_IRUGO, show_status_str, NULL);
  866. static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
  867. static DEVICE_ATTR(unit, S_IRUGO, show_unit, NULL);
  868. static DEVICE_ATTR(rx_pol_inv, S_IWUSR, NULL, store_rx_pol_inv);
  869. static DEVICE_ATTR(led_override, S_IWUSR, NULL, store_led_override);
  870. static DEVICE_ATTR(logged_errors, S_IRUGO, show_logged_errs, NULL);
  871. static DEVICE_ATTR(jint_max_packets, S_IWUSR | S_IRUGO,
  872. show_jint_max_packets, store_jint_max_packets);
  873. static DEVICE_ATTR(jint_idle_ticks, S_IWUSR | S_IRUGO,
  874. show_jint_idle_ticks, store_jint_idle_ticks);
  875. static struct attribute *dev_attributes[] = {
  876. &dev_attr_guid.attr,
  877. &dev_attr_lmc.attr,
  878. &dev_attr_lid.attr,
  879. &dev_attr_link_state.attr,
  880. &dev_attr_mlid.attr,
  881. &dev_attr_mtu.attr,
  882. &dev_attr_nguid.attr,
  883. &dev_attr_nports.attr,
  884. &dev_attr_serial.attr,
  885. &dev_attr_status.attr,
  886. &dev_attr_status_str.attr,
  887. &dev_attr_boardversion.attr,
  888. &dev_attr_unit.attr,
  889. &dev_attr_enabled.attr,
  890. &dev_attr_rx_pol_inv.attr,
  891. &dev_attr_led_override.attr,
  892. &dev_attr_logged_errors.attr,
  893. NULL
  894. };
  895. static struct attribute_group dev_attr_group = {
  896. .attrs = dev_attributes
  897. };
  898. static DEVICE_ATTR(hrtbt_enable, S_IWUSR | S_IRUGO, show_hrtbt_enb,
  899. store_hrtbt_enb);
  900. static DEVICE_ATTR(link_width_enable, S_IWUSR | S_IRUGO, show_lwid_enb,
  901. store_lwid_enb);
  902. static DEVICE_ATTR(link_width, S_IRUGO, show_lwid, NULL);
  903. static DEVICE_ATTR(link_speed_enable, S_IWUSR | S_IRUGO, show_spd_enb,
  904. store_spd_enb);
  905. static DEVICE_ATTR(link_speed, S_IRUGO, show_spd, NULL);
  906. static DEVICE_ATTR(rx_pol_inv_enable, S_IWUSR | S_IRUGO, show_rx_polinv_enb,
  907. store_rx_polinv_enb);
  908. static DEVICE_ATTR(rx_lane_rev_enable, S_IWUSR | S_IRUGO, show_lanerev_enb,
  909. store_lanerev_enb);
  910. static struct attribute *dev_ibcfg_attributes[] = {
  911. &dev_attr_hrtbt_enable.attr,
  912. &dev_attr_link_width_enable.attr,
  913. &dev_attr_link_width.attr,
  914. &dev_attr_link_speed_enable.attr,
  915. &dev_attr_link_speed.attr,
  916. &dev_attr_rx_pol_inv_enable.attr,
  917. &dev_attr_rx_lane_rev_enable.attr,
  918. NULL
  919. };
  920. static struct attribute_group dev_ibcfg_attr_group = {
  921. .attrs = dev_ibcfg_attributes
  922. };
  923. /**
  924. * ipath_expose_reset - create a device reset file
  925. * @dev: the device structure
  926. *
  927. * Only expose a file that lets us reset the device after someone
  928. * enters diag mode. A device reset is quite likely to crash the
  929. * machine entirely, so we don't want to normally make it
  930. * available.
  931. *
  932. * Called with ipath_mutex held.
  933. */
  934. int ipath_expose_reset(struct device *dev)
  935. {
  936. static int exposed;
  937. int ret;
  938. if (!exposed) {
  939. ret = device_create_file(dev, &dev_attr_reset);
  940. exposed = 1;
  941. }
  942. else
  943. ret = 0;
  944. return ret;
  945. }
  946. int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
  947. {
  948. int ret;
  949. ret = sysfs_create_group(&dev->kobj, &dev_attr_group);
  950. if (ret)
  951. goto bail;
  952. ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group);
  953. if (ret)
  954. goto bail_attrs;
  955. if (dd->ipath_flags & IPATH_HAS_MULT_IB_SPEED) {
  956. ret = device_create_file(dev, &dev_attr_jint_idle_ticks);
  957. if (ret)
  958. goto bail_counter;
  959. ret = device_create_file(dev, &dev_attr_jint_max_packets);
  960. if (ret)
  961. goto bail_idle;
  962. ret = sysfs_create_group(&dev->kobj, &dev_ibcfg_attr_group);
  963. if (ret)
  964. goto bail_max;
  965. }
  966. return 0;
  967. bail_max:
  968. device_remove_file(dev, &dev_attr_jint_max_packets);
  969. bail_idle:
  970. device_remove_file(dev, &dev_attr_jint_idle_ticks);
  971. bail_counter:
  972. sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
  973. bail_attrs:
  974. sysfs_remove_group(&dev->kobj, &dev_attr_group);
  975. bail:
  976. return ret;
  977. }
  978. void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd)
  979. {
  980. sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
  981. if (dd->ipath_flags & IPATH_HAS_MULT_IB_SPEED) {
  982. sysfs_remove_group(&dev->kobj, &dev_ibcfg_attr_group);
  983. device_remove_file(dev, &dev_attr_jint_idle_ticks);
  984. device_remove_file(dev, &dev_attr_jint_max_packets);
  985. }
  986. sysfs_remove_group(&dev->kobj, &dev_attr_group);
  987. device_remove_file(dev, &dev_attr_reset);
  988. }