2 * Copyright (c) 2006, 2007 QLogic Corporation. All rights reserved.
3 * Copyright (c) 2006 PathScale, Inc. All rights reserved.
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:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
34 #include <linux/ctype.h>
36 #include "ipath_kernel.h"
37 #include "ipath_common.h"
40 * ipath_parse_ushort - parse an unsigned short value in an arbitrary base
41 * @str: the string containing the number
42 * @valp: where to put the result
44 * returns the number of bytes consumed, or negative value on error
46 int ipath_parse_ushort(const char *str, unsigned short *valp)
52 if (!isdigit(str[0])) {
57 val = simple_strtoul(str, &end, 0);
74 static ssize_t show_version(struct device_driver *dev, char *buf)
76 /* The string printed here is already newline-terminated. */
77 return scnprintf(buf, PAGE_SIZE, "%s", ib_ipath_version);
80 static ssize_t show_num_units(struct device_driver *dev, char *buf)
82 return scnprintf(buf, PAGE_SIZE, "%d\n",
83 ipath_count_units(NULL, NULL, NULL));
86 static ssize_t show_status(struct device *dev,
87 struct device_attribute *attr,
90 struct ipath_devdata *dd = dev_get_drvdata(dev);
93 if (!dd->ipath_statusp) {
98 ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n",
99 (unsigned long long) *(dd->ipath_statusp));
105 static const char *ipath_status_str[] = {
109 "", /* This used to be the old "OIB_SMA" status. */
110 "", /* This used to be the old "SMA" status. */
115 "Fatal_Hardware_Error",
119 static ssize_t show_status_str(struct device *dev,
120 struct device_attribute *attr,
123 struct ipath_devdata *dd = dev_get_drvdata(dev);
128 if (!dd->ipath_statusp) {
133 s = *(dd->ipath_statusp);
135 for (any = i = 0; s && ipath_status_str[i]; i++) {
137 if (any && strlcat(buf, " ", PAGE_SIZE) >=
141 if (strlcat(buf, ipath_status_str[i],
142 PAGE_SIZE) >= PAGE_SIZE)
149 strlcat(buf, "\n", PAGE_SIZE);
157 static ssize_t show_boardversion(struct device *dev,
158 struct device_attribute *attr,
161 struct ipath_devdata *dd = dev_get_drvdata(dev);
162 /* The string printed here is already newline-terminated. */
163 return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_boardversion);
166 static ssize_t show_localbus_info(struct device *dev,
167 struct device_attribute *attr,
170 struct ipath_devdata *dd = dev_get_drvdata(dev);
171 /* The string printed here is already newline-terminated. */
172 return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_lbus_info);
175 static ssize_t show_lmc(struct device *dev,
176 struct device_attribute *attr,
179 struct ipath_devdata *dd = dev_get_drvdata(dev);
181 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_lmc);
184 static ssize_t store_lmc(struct device *dev,
185 struct device_attribute *attr,
189 struct ipath_devdata *dd = dev_get_drvdata(dev);
193 ret = ipath_parse_ushort(buf, &lmc);
202 ipath_set_lid(dd, dd->ipath_lid, lmc);
206 ipath_dev_err(dd, "attempt to set invalid LMC %u\n", lmc);
211 static ssize_t show_lid(struct device *dev,
212 struct device_attribute *attr,
215 struct ipath_devdata *dd = dev_get_drvdata(dev);
217 return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_lid);
220 static ssize_t store_lid(struct device *dev,
221 struct device_attribute *attr,
225 struct ipath_devdata *dd = dev_get_drvdata(dev);
229 ret = ipath_parse_ushort(buf, &lid);
233 if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE) {
238 ipath_set_lid(dd, lid, dd->ipath_lmc);
242 ipath_dev_err(dd, "attempt to set invalid LID 0x%x\n", lid);
247 static ssize_t show_mlid(struct device *dev,
248 struct device_attribute *attr,
251 struct ipath_devdata *dd = dev_get_drvdata(dev);
253 return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_mlid);
256 static ssize_t store_mlid(struct device *dev,
257 struct device_attribute *attr,
261 struct ipath_devdata *dd = dev_get_drvdata(dev);
265 ret = ipath_parse_ushort(buf, &mlid);
266 if (ret < 0 || mlid < IPATH_MULTICAST_LID_BASE)
269 dd->ipath_mlid = mlid;
273 ipath_dev_err(dd, "attempt to set invalid MLID\n");
278 static ssize_t show_guid(struct device *dev,
279 struct device_attribute *attr,
282 struct ipath_devdata *dd = dev_get_drvdata(dev);
285 guid = (u8 *) & (dd->ipath_guid);
287 return scnprintf(buf, PAGE_SIZE,
288 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
289 guid[0], guid[1], guid[2], guid[3],
290 guid[4], guid[5], guid[6], guid[7]);
293 static ssize_t store_guid(struct device *dev,
294 struct device_attribute *attr,
298 struct ipath_devdata *dd = dev_get_drvdata(dev);
300 unsigned short guid[8];
305 if (sscanf(buf, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
306 &guid[0], &guid[1], &guid[2], &guid[3],
307 &guid[4], &guid[5], &guid[6], &guid[7]) != 8)
310 ng = (u8 *) &new_guid;
312 for (i = 0; i < 8; i++) {
321 dd->ipath_guid = new_guid;
328 ipath_dev_err(dd, "attempt to set invalid GUID\n");
335 static ssize_t show_nguid(struct device *dev,
336 struct device_attribute *attr,
339 struct ipath_devdata *dd = dev_get_drvdata(dev);
341 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid);
344 static ssize_t show_nports(struct device *dev,
345 struct device_attribute *attr,
348 struct ipath_devdata *dd = dev_get_drvdata(dev);
350 /* Return the number of user ports available. */
351 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_cfgports - 1);
354 static ssize_t show_serial(struct device *dev,
355 struct device_attribute *attr,
358 struct ipath_devdata *dd = dev_get_drvdata(dev);
360 buf[sizeof dd->ipath_serial] = '\0';
361 memcpy(buf, dd->ipath_serial, sizeof dd->ipath_serial);
366 static ssize_t show_unit(struct device *dev,
367 struct device_attribute *attr,
370 struct ipath_devdata *dd = dev_get_drvdata(dev);
372 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_unit);
375 static ssize_t show_jint_max_packets(struct device *dev,
376 struct device_attribute *attr,
379 struct ipath_devdata *dd = dev_get_drvdata(dev);
381 return scnprintf(buf, PAGE_SIZE, "%hu\n", dd->ipath_jint_max_packets);
384 static ssize_t store_jint_max_packets(struct device *dev,
385 struct device_attribute *attr,
389 struct ipath_devdata *dd = dev_get_drvdata(dev);
393 ret = ipath_parse_ushort(buf, &v);
395 ipath_dev_err(dd, "invalid jint_max_packets.\n");
397 dd->ipath_f_config_jint(dd, dd->ipath_jint_idle_ticks, v);
402 static ssize_t show_jint_idle_ticks(struct device *dev,
403 struct device_attribute *attr,
406 struct ipath_devdata *dd = dev_get_drvdata(dev);
408 return scnprintf(buf, PAGE_SIZE, "%hu\n", dd->ipath_jint_idle_ticks);
411 static ssize_t store_jint_idle_ticks(struct device *dev,
412 struct device_attribute *attr,
416 struct ipath_devdata *dd = dev_get_drvdata(dev);
420 ret = ipath_parse_ushort(buf, &v);
422 ipath_dev_err(dd, "invalid jint_idle_ticks.\n");
424 dd->ipath_f_config_jint(dd, v, dd->ipath_jint_max_packets);
429 #define DEVICE_COUNTER(name, attr) \
430 static ssize_t show_counter_##name(struct device *dev, \
431 struct device_attribute *attr, \
434 struct ipath_devdata *dd = dev_get_drvdata(dev); \
436 buf, PAGE_SIZE, "%llu\n", (unsigned long long) \
438 dd, offsetof(struct infinipath_counters, \
439 attr) / sizeof(u64))); \
441 static DEVICE_ATTR(name, S_IRUGO, show_counter_##name, NULL);
443 DEVICE_COUNTER(ib_link_downeds, IBLinkDownedCnt);
444 DEVICE_COUNTER(ib_link_err_recoveries, IBLinkErrRecoveryCnt);
445 DEVICE_COUNTER(ib_status_changes, IBStatusChangeCnt);
446 DEVICE_COUNTER(ib_symbol_errs, IBSymbolErrCnt);
447 DEVICE_COUNTER(lb_flow_stalls, LBFlowStallCnt);
448 DEVICE_COUNTER(lb_ints, LBIntCnt);
449 DEVICE_COUNTER(rx_bad_formats, RxBadFormatCnt);
450 DEVICE_COUNTER(rx_buf_ovfls, RxBufOvflCnt);
451 DEVICE_COUNTER(rx_data_pkts, RxDataPktCnt);
452 DEVICE_COUNTER(rx_dropped_pkts, RxDroppedPktCnt);
453 DEVICE_COUNTER(rx_dwords, RxDwordCnt);
454 DEVICE_COUNTER(rx_ebps, RxEBPCnt);
455 DEVICE_COUNTER(rx_flow_ctrl_errs, RxFlowCtrlErrCnt);
456 DEVICE_COUNTER(rx_flow_pkts, RxFlowPktCnt);
457 DEVICE_COUNTER(rx_icrc_errs, RxICRCErrCnt);
458 DEVICE_COUNTER(rx_len_errs, RxLenErrCnt);
459 DEVICE_COUNTER(rx_link_problems, RxLinkProblemCnt);
460 DEVICE_COUNTER(rx_lpcrc_errs, RxLPCRCErrCnt);
461 DEVICE_COUNTER(rx_max_min_len_errs, RxMaxMinLenErrCnt);
462 DEVICE_COUNTER(rx_p0_hdr_egr_ovfls, RxP0HdrEgrOvflCnt);
463 DEVICE_COUNTER(rx_p1_hdr_egr_ovfls, RxP1HdrEgrOvflCnt);
464 DEVICE_COUNTER(rx_p2_hdr_egr_ovfls, RxP2HdrEgrOvflCnt);
465 DEVICE_COUNTER(rx_p3_hdr_egr_ovfls, RxP3HdrEgrOvflCnt);
466 DEVICE_COUNTER(rx_p4_hdr_egr_ovfls, RxP4HdrEgrOvflCnt);
467 DEVICE_COUNTER(rx_p5_hdr_egr_ovfls, RxP5HdrEgrOvflCnt);
468 DEVICE_COUNTER(rx_p6_hdr_egr_ovfls, RxP6HdrEgrOvflCnt);
469 DEVICE_COUNTER(rx_p7_hdr_egr_ovfls, RxP7HdrEgrOvflCnt);
470 DEVICE_COUNTER(rx_p8_hdr_egr_ovfls, RxP8HdrEgrOvflCnt);
471 DEVICE_COUNTER(rx_pkey_mismatches, RxPKeyMismatchCnt);
472 DEVICE_COUNTER(rx_tid_full_errs, RxTIDFullErrCnt);
473 DEVICE_COUNTER(rx_tid_valid_errs, RxTIDValidErrCnt);
474 DEVICE_COUNTER(rx_vcrc_errs, RxVCRCErrCnt);
475 DEVICE_COUNTER(tx_data_pkts, TxDataPktCnt);
476 DEVICE_COUNTER(tx_dropped_pkts, TxDroppedPktCnt);
477 DEVICE_COUNTER(tx_dwords, TxDwordCnt);
478 DEVICE_COUNTER(tx_flow_pkts, TxFlowPktCnt);
479 DEVICE_COUNTER(tx_flow_stalls, TxFlowStallCnt);
480 DEVICE_COUNTER(tx_len_errs, TxLenErrCnt);
481 DEVICE_COUNTER(tx_max_min_len_errs, TxMaxMinLenErrCnt);
482 DEVICE_COUNTER(tx_underruns, TxUnderrunCnt);
483 DEVICE_COUNTER(tx_unsup_vl_errs, TxUnsupVLErrCnt);
485 static struct attribute *dev_counter_attributes[] = {
486 &dev_attr_ib_link_downeds.attr,
487 &dev_attr_ib_link_err_recoveries.attr,
488 &dev_attr_ib_status_changes.attr,
489 &dev_attr_ib_symbol_errs.attr,
490 &dev_attr_lb_flow_stalls.attr,
491 &dev_attr_lb_ints.attr,
492 &dev_attr_rx_bad_formats.attr,
493 &dev_attr_rx_buf_ovfls.attr,
494 &dev_attr_rx_data_pkts.attr,
495 &dev_attr_rx_dropped_pkts.attr,
496 &dev_attr_rx_dwords.attr,
497 &dev_attr_rx_ebps.attr,
498 &dev_attr_rx_flow_ctrl_errs.attr,
499 &dev_attr_rx_flow_pkts.attr,
500 &dev_attr_rx_icrc_errs.attr,
501 &dev_attr_rx_len_errs.attr,
502 &dev_attr_rx_link_problems.attr,
503 &dev_attr_rx_lpcrc_errs.attr,
504 &dev_attr_rx_max_min_len_errs.attr,
505 &dev_attr_rx_p0_hdr_egr_ovfls.attr,
506 &dev_attr_rx_p1_hdr_egr_ovfls.attr,
507 &dev_attr_rx_p2_hdr_egr_ovfls.attr,
508 &dev_attr_rx_p3_hdr_egr_ovfls.attr,
509 &dev_attr_rx_p4_hdr_egr_ovfls.attr,
510 &dev_attr_rx_p5_hdr_egr_ovfls.attr,
511 &dev_attr_rx_p6_hdr_egr_ovfls.attr,
512 &dev_attr_rx_p7_hdr_egr_ovfls.attr,
513 &dev_attr_rx_p8_hdr_egr_ovfls.attr,
514 &dev_attr_rx_pkey_mismatches.attr,
515 &dev_attr_rx_tid_full_errs.attr,
516 &dev_attr_rx_tid_valid_errs.attr,
517 &dev_attr_rx_vcrc_errs.attr,
518 &dev_attr_tx_data_pkts.attr,
519 &dev_attr_tx_dropped_pkts.attr,
520 &dev_attr_tx_dwords.attr,
521 &dev_attr_tx_flow_pkts.attr,
522 &dev_attr_tx_flow_stalls.attr,
523 &dev_attr_tx_len_errs.attr,
524 &dev_attr_tx_max_min_len_errs.attr,
525 &dev_attr_tx_underruns.attr,
526 &dev_attr_tx_unsup_vl_errs.attr,
530 static struct attribute_group dev_counter_attr_group = {
532 .attrs = dev_counter_attributes
535 static ssize_t store_reset(struct device *dev,
536 struct device_attribute *attr,
540 struct ipath_devdata *dd = dev_get_drvdata(dev);
543 if (count < 5 || memcmp(buf, "reset", 5)) {
548 if (dd->ipath_flags & IPATH_DISABLED) {
550 * post-reset init would re-enable interrupts, etc.
551 * so don't allow reset on disabled devices. Not
552 * perfect error, but about the best choice.
554 dev_info(dev,"Unit %d is disabled, can't reset\n",
558 ret = ipath_reset_device(dd->ipath_unit);
560 return ret<0 ? ret : count;
563 static ssize_t store_link_state(struct device *dev,
564 struct device_attribute *attr,
568 struct ipath_devdata *dd = dev_get_drvdata(dev);
572 ret = ipath_parse_ushort(buf, &state);
576 r = ipath_set_linkstate(dd, state);
584 ipath_dev_err(dd, "attempt to set invalid link state\n");
589 static ssize_t show_mtu(struct device *dev,
590 struct device_attribute *attr,
593 struct ipath_devdata *dd = dev_get_drvdata(dev);
594 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_ibmtu);
597 static ssize_t store_mtu(struct device *dev,
598 struct device_attribute *attr,
602 struct ipath_devdata *dd = dev_get_drvdata(dev);
607 ret = ipath_parse_ushort(buf, &mtu);
611 r = ipath_set_mtu(dd, mtu);
617 ipath_dev_err(dd, "attempt to set invalid MTU\n");
622 static ssize_t show_enabled(struct device *dev,
623 struct device_attribute *attr,
626 struct ipath_devdata *dd = dev_get_drvdata(dev);
627 return scnprintf(buf, PAGE_SIZE, "%u\n",
628 (dd->ipath_flags & IPATH_DISABLED) ? 0 : 1);
631 static ssize_t store_enabled(struct device *dev,
632 struct device_attribute *attr,
636 struct ipath_devdata *dd = dev_get_drvdata(dev);
640 ret = ipath_parse_ushort(buf, &enable);
642 ipath_dev_err(dd, "attempt to use non-numeric on enable\n");
647 if (!(dd->ipath_flags & IPATH_DISABLED))
650 dev_info(dev, "Enabling unit %d\n", dd->ipath_unit);
651 /* same as post-reset */
652 ret = ipath_init_chip(dd, 1);
654 ipath_dev_err(dd, "Failed to enable unit %d\n",
657 dd->ipath_flags &= ~IPATH_DISABLED;
658 *dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED;
661 else if (!(dd->ipath_flags & IPATH_DISABLED)) {
662 dev_info(dev, "Disabling unit %d\n", dd->ipath_unit);
663 ipath_shutdown_device(dd);
664 dd->ipath_flags |= IPATH_DISABLED;
665 *dd->ipath_statusp |= IPATH_STATUS_ADMIN_DISABLED;
672 static ssize_t store_rx_pol_inv(struct device *dev,
673 struct device_attribute *attr,
677 struct ipath_devdata *dd = dev_get_drvdata(dev);
681 ret = ipath_parse_ushort(buf, &val);
685 r = ipath_set_rx_pol_inv(dd, val);
693 ipath_dev_err(dd, "attempt to set invalid Rx Polarity invert\n");
698 static ssize_t store_led_override(struct device *dev,
699 struct device_attribute *attr,
703 struct ipath_devdata *dd = dev_get_drvdata(dev);
707 ret = ipath_parse_ushort(buf, &val);
709 ipath_set_led_override(dd, val);
711 ipath_dev_err(dd, "attempt to set invalid LED override\n");
715 static ssize_t show_logged_errs(struct device *dev,
716 struct device_attribute *attr,
719 struct ipath_devdata *dd = dev_get_drvdata(dev);
722 /* force consistency with actual EEPROM */
723 if (ipath_update_eeprom_log(dd) != 0)
727 for (idx = 0; idx < IPATH_EEP_LOG_CNT; ++idx) {
728 count += scnprintf(buf + count, PAGE_SIZE - count, "%d%c",
729 dd->ipath_eep_st_errs[idx],
730 idx == (IPATH_EEP_LOG_CNT - 1) ? '\n' : ' ');
737 * New sysfs entries to control various IB config. These all turn into
738 * accesses via ipath_f_get/set_ib_cfg.
740 * Get/Set heartbeat enable. Or of 1=enabled, 2=auto
742 static ssize_t show_hrtbt_enb(struct device *dev,
743 struct device_attribute *attr,
746 struct ipath_devdata *dd = dev_get_drvdata(dev);
749 ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_HRTBT);
751 ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
755 static ssize_t store_hrtbt_enb(struct device *dev,
756 struct device_attribute *attr,
760 struct ipath_devdata *dd = dev_get_drvdata(dev);
764 ret = ipath_parse_ushort(buf, &val);
765 if (ret >= 0 && val > 3)
768 ipath_dev_err(dd, "attempt to set invalid Heartbeat enable\n");
773 * Set the "intentional" heartbeat enable per either of
774 * "Enable" and "Auto", as these are normally set together.
775 * This bit is consulted when leaving loopback mode,
776 * because entering loopback mode overrides it and automatically
777 * disables heartbeat.
779 r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_HRTBT, val);
782 else if (val == IPATH_IB_HRTBT_OFF)
783 dd->ipath_flags |= IPATH_NO_HRTBT;
785 dd->ipath_flags &= ~IPATH_NO_HRTBT;
792 * Get/Set Link-widths enabled. Or of 1=1x, 2=4x (this is human/IB centric,
793 * _not_ the particular encoding of any given chip)
795 static ssize_t show_lwid_enb(struct device *dev,
796 struct device_attribute *attr,
799 struct ipath_devdata *dd = dev_get_drvdata(dev);
802 ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB);
804 ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
808 static ssize_t store_lwid_enb(struct device *dev,
809 struct device_attribute *attr,
813 struct ipath_devdata *dd = dev_get_drvdata(dev);
817 ret = ipath_parse_ushort(buf, &val);
818 if (ret >= 0 && (val == 0 || val > 3))
822 "attempt to set invalid Link Width (enable)\n");
826 r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB, val);
834 /* Get current link width */
835 static ssize_t show_lwid(struct device *dev,
836 struct device_attribute *attr,
840 struct ipath_devdata *dd = dev_get_drvdata(dev);
843 ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LWID);
845 ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
850 * Get/Set Link-speeds enabled. Or of 1=SDR 2=DDR.
852 static ssize_t show_spd_enb(struct device *dev,
853 struct device_attribute *attr,
856 struct ipath_devdata *dd = dev_get_drvdata(dev);
859 ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB);
861 ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
865 static ssize_t store_spd_enb(struct device *dev,
866 struct device_attribute *attr,
870 struct ipath_devdata *dd = dev_get_drvdata(dev);
874 ret = ipath_parse_ushort(buf, &val);
875 if (ret >= 0 && (val == 0 || val > (IPATH_IB_SDR | IPATH_IB_DDR)))
879 "attempt to set invalid Link Speed (enable)\n");
883 r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB, val);
891 /* Get current link speed */
892 static ssize_t show_spd(struct device *dev,
893 struct device_attribute *attr,
896 struct ipath_devdata *dd = dev_get_drvdata(dev);
899 ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_SPD);
901 ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
906 * Get/Set RX polarity-invert enable. 0=no, 1=yes.
908 static ssize_t show_rx_polinv_enb(struct device *dev,
909 struct device_attribute *attr,
912 struct ipath_devdata *dd = dev_get_drvdata(dev);
915 ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_RXPOL_ENB);
917 ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
921 static ssize_t store_rx_polinv_enb(struct device *dev,
922 struct device_attribute *attr,
926 struct ipath_devdata *dd = dev_get_drvdata(dev);
930 ret = ipath_parse_ushort(buf, &val);
931 if (ret < 0 || val > 1)
934 r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_RXPOL_ENB, val);
942 ipath_dev_err(dd, "attempt to set invalid Rx Polarity (enable)\n");
947 * Get/Set RX lane-reversal enable. 0=no, 1=yes.
949 static ssize_t show_lanerev_enb(struct device *dev,
950 struct device_attribute *attr,
953 struct ipath_devdata *dd = dev_get_drvdata(dev);
956 ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LREV_ENB);
958 ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
962 static ssize_t store_lanerev_enb(struct device *dev,
963 struct device_attribute *attr,
967 struct ipath_devdata *dd = dev_get_drvdata(dev);
971 ret = ipath_parse_ushort(buf, &val);
972 if (ret >= 0 && val > 1) {
975 "attempt to set invalid Lane reversal (enable)\n");
979 r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LREV_ENB, val);
987 static DRIVER_ATTR(num_units, S_IRUGO, show_num_units, NULL);
988 static DRIVER_ATTR(version, S_IRUGO, show_version, NULL);
990 static struct attribute *driver_attributes[] = {
991 &driver_attr_num_units.attr,
992 &driver_attr_version.attr,
996 static struct attribute_group driver_attr_group = {
997 .attrs = driver_attributes
1000 struct attribute_group *ipath_driver_attr_groups[] = {
1005 static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid);
1006 static DEVICE_ATTR(lmc, S_IWUSR | S_IRUGO, show_lmc, store_lmc);
1007 static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid);
1008 static DEVICE_ATTR(link_state, S_IWUSR, NULL, store_link_state);
1009 static DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid);
1010 static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu);
1011 static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled);
1012 static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL);
1013 static DEVICE_ATTR(nports, S_IRUGO, show_nports, NULL);
1014 static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset);
1015 static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
1016 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1017 static DEVICE_ATTR(status_str, S_IRUGO, show_status_str, NULL);
1018 static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
1019 static DEVICE_ATTR(unit, S_IRUGO, show_unit, NULL);
1020 static DEVICE_ATTR(rx_pol_inv, S_IWUSR, NULL, store_rx_pol_inv);
1021 static DEVICE_ATTR(led_override, S_IWUSR, NULL, store_led_override);
1022 static DEVICE_ATTR(logged_errors, S_IRUGO, show_logged_errs, NULL);
1023 static DEVICE_ATTR(localbus_info, S_IRUGO, show_localbus_info, NULL);
1024 static DEVICE_ATTR(jint_max_packets, S_IWUSR | S_IRUGO,
1025 show_jint_max_packets, store_jint_max_packets);
1026 static DEVICE_ATTR(jint_idle_ticks, S_IWUSR | S_IRUGO,
1027 show_jint_idle_ticks, store_jint_idle_ticks);
1029 static struct attribute *dev_attributes[] = {
1030 &dev_attr_guid.attr,
1033 &dev_attr_link_state.attr,
1034 &dev_attr_mlid.attr,
1036 &dev_attr_nguid.attr,
1037 &dev_attr_nports.attr,
1038 &dev_attr_serial.attr,
1039 &dev_attr_status.attr,
1040 &dev_attr_status_str.attr,
1041 &dev_attr_boardversion.attr,
1042 &dev_attr_unit.attr,
1043 &dev_attr_enabled.attr,
1044 &dev_attr_rx_pol_inv.attr,
1045 &dev_attr_led_override.attr,
1046 &dev_attr_logged_errors.attr,
1047 &dev_attr_localbus_info.attr,
1051 static struct attribute_group dev_attr_group = {
1052 .attrs = dev_attributes
1055 static DEVICE_ATTR(hrtbt_enable, S_IWUSR | S_IRUGO, show_hrtbt_enb,
1057 static DEVICE_ATTR(link_width_enable, S_IWUSR | S_IRUGO, show_lwid_enb,
1059 static DEVICE_ATTR(link_width, S_IRUGO, show_lwid, NULL);
1060 static DEVICE_ATTR(link_speed_enable, S_IWUSR | S_IRUGO, show_spd_enb,
1062 static DEVICE_ATTR(link_speed, S_IRUGO, show_spd, NULL);
1063 static DEVICE_ATTR(rx_pol_inv_enable, S_IWUSR | S_IRUGO, show_rx_polinv_enb,
1064 store_rx_polinv_enb);
1065 static DEVICE_ATTR(rx_lane_rev_enable, S_IWUSR | S_IRUGO, show_lanerev_enb,
1068 static struct attribute *dev_ibcfg_attributes[] = {
1069 &dev_attr_hrtbt_enable.attr,
1070 &dev_attr_link_width_enable.attr,
1071 &dev_attr_link_width.attr,
1072 &dev_attr_link_speed_enable.attr,
1073 &dev_attr_link_speed.attr,
1074 &dev_attr_rx_pol_inv_enable.attr,
1075 &dev_attr_rx_lane_rev_enable.attr,
1079 static struct attribute_group dev_ibcfg_attr_group = {
1080 .attrs = dev_ibcfg_attributes
1084 * ipath_expose_reset - create a device reset file
1085 * @dev: the device structure
1087 * Only expose a file that lets us reset the device after someone
1088 * enters diag mode. A device reset is quite likely to crash the
1089 * machine entirely, so we don't want to normally make it
1092 * Called with ipath_mutex held.
1094 int ipath_expose_reset(struct device *dev)
1100 ret = device_create_file(dev, &dev_attr_reset);
1109 int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
1113 ret = sysfs_create_group(&dev->kobj, &dev_attr_group);
1117 ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group);
1121 if (dd->ipath_flags & IPATH_HAS_MULT_IB_SPEED) {
1122 ret = device_create_file(dev, &dev_attr_jint_idle_ticks);
1125 ret = device_create_file(dev, &dev_attr_jint_max_packets);
1129 ret = sysfs_create_group(&dev->kobj, &dev_ibcfg_attr_group);
1137 device_remove_file(dev, &dev_attr_jint_max_packets);
1139 device_remove_file(dev, &dev_attr_jint_idle_ticks);
1141 sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
1143 sysfs_remove_group(&dev->kobj, &dev_attr_group);
1148 void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd)
1150 sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
1152 if (dd->ipath_flags & IPATH_HAS_MULT_IB_SPEED) {
1153 sysfs_remove_group(&dev->kobj, &dev_ibcfg_attr_group);
1154 device_remove_file(dev, &dev_attr_jint_idle_ticks);
1155 device_remove_file(dev, &dev_attr_jint_max_packets);
1158 sysfs_remove_group(&dev->kobj, &dev_attr_group);
1160 device_remove_file(dev, &dev_attr_reset);