13e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan/*
2e7eacd36865ae0707f5efae8e4dda421ffcd1b66Ralph Campbell * Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved.
33e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * Copyright (c) 2006 PathScale, Inc. All rights reserved.
43e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *
53e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * This software is available to you under a choice of one of two
63e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * licenses.  You may choose to be licensed under the terms of the GNU
73e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * General Public License (GPL) Version 2, available from the file
83e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * COPYING in the main directory of this source tree, or the
93e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * OpenIB.org BSD license below:
103e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *
113e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *     Redistribution and use in source and binary forms, with or
123e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *     without modification, are permitted provided that the following
133e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *     conditions are met:
143e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *
153e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *      - Redistributions of source code must retain the above
163e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *        copyright notice, this list of conditions and the following
173e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *        disclaimer.
183e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *
193e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *      - Redistributions in binary form must reproduce the above
203e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *        copyright notice, this list of conditions and the following
213e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *        disclaimer in the documentation and/or other materials
223e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *        provided with the distribution.
233e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *
243e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
253e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
263e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
273e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
283e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
293e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
303e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
313e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * SOFTWARE.
323e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan */
333e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
343e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan#include <linux/ctype.h>
35fc87af74af7f856bb8e7585308fb1fdaaa69ec73Paul Gortmaker#include <linux/stat.h>
363e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
373e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan#include "ipath_kernel.h"
38bb9171448deb1f7ece27674e2e431e4f267fd453Arthur Jones#include "ipath_verbs.h"
3927b678dd04a636f2c351816f4b3042c8815d4e9dBryan O'Sullivan#include "ipath_common.h"
403e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
413e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan/**
423e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * ipath_parse_ushort - parse an unsigned short value in an arbitrary base
433e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * @str: the string containing the number
443e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * @valp: where to put the result
453e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *
463e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * returns the number of bytes consumed, or negative value on error
473e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan */
483e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanint ipath_parse_ushort(const char *str, unsigned short *valp)
493e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
503e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	unsigned long val;
513e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	char *end;
523e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	int ret;
533e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
543e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (!isdigit(str[0])) {
553e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ret = -EINVAL;
563e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto bail;
573e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
583e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
593e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	val = simple_strtoul(str, &end, 0);
603e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
613e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (val > 0xffff) {
623e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ret = -EINVAL;
633e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto bail;
643e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
653e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
663e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	*valp = val;
673e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
683e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = end + 1 - str;
693e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (ret == 0)
703e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ret = -EINVAL;
713e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
723e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanbail:
733e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return ret;
743e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
753e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
763e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_version(struct device_driver *dev, char *buf)
773e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
783e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	/* The string printed here is already newline-terminated. */
79b55f4f06c834a67f949a5219c5f97ffafa240989Bryan O'Sullivan	return scnprintf(buf, PAGE_SIZE, "%s", ib_ipath_version);
803e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
813e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
823e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_num_units(struct device_driver *dev, char *buf)
833e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
843e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return scnprintf(buf, PAGE_SIZE, "%d\n",
853e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 ipath_count_units(NULL, NULL, NULL));
863e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
873e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
883e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_status(struct device *dev,
893e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			   struct device_attribute *attr,
903e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			   char *buf)
913e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
923e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
933e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ssize_t ret;
943e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
953e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (!dd->ipath_statusp) {
963e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ret = -EINVAL;
973e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto bail;
983e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
993e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1003e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n",
1013e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			(unsigned long long) *(dd->ipath_statusp));
1023e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1033e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanbail:
1043e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return ret;
1053e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
1063e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1073e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic const char *ipath_status_str[] = {
1083e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	"Initted",
1093e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	"Disabled",
1103e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	"Admin_Disabled",
1110fd41363e0785247b7c19127318abc8b5eacc86bBryan O'Sullivan	"", /* This used to be the old "OIB_SMA" status. */
1120fd41363e0785247b7c19127318abc8b5eacc86bBryan O'Sullivan	"", /* This used to be the old "SMA" status. */
1133e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	"Present",
1143e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	"IB_link_up",
1153e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	"IB_configured",
1163e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	"NoIBcable",
1173e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	"Fatal_Hardware_Error",
1183e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	NULL,
1193e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan};
1203e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1213e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_status_str(struct device *dev,
1223e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			       struct device_attribute *attr,
1233e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			       char *buf)
1243e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
1253e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
1263e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	int i, any;
1273e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	u64 s;
1283e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ssize_t ret;
1293e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1303e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (!dd->ipath_statusp) {
1313e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ret = -EINVAL;
1323e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto bail;
1333e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
1343e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1353e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	s = *(dd->ipath_statusp);
1363e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	*buf = '\0';
1373e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	for (any = i = 0; s && ipath_status_str[i]; i++) {
1383e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		if (s & 1) {
1393e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			if (any && strlcat(buf, " ", PAGE_SIZE) >=
1403e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			    PAGE_SIZE)
1413e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan				/* overflow */
1423e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan				break;
1433e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			if (strlcat(buf, ipath_status_str[i],
1443e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan				    PAGE_SIZE) >= PAGE_SIZE)
1453e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan				break;
1463e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			any = 1;
1473e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		}
1483e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		s >>= 1;
1493e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
1503e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (any)
1513e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		strlcat(buf, "\n", PAGE_SIZE);
1523e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1533e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = strlen(buf);
1543e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1553e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanbail:
1563e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return ret;
1573e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
1583e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1593e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_boardversion(struct device *dev,
1603e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			       struct device_attribute *attr,
1613e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			       char *buf)
1623e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
1633e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
1643e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	/* The string printed here is already newline-terminated. */
1653e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_boardversion);
1663e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
1673e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1686ca2abf4c02fb3e35247a985c2b6f5834e995033Arthur Jonesstatic ssize_t show_localbus_info(struct device *dev,
1696ca2abf4c02fb3e35247a985c2b6f5834e995033Arthur Jones			       struct device_attribute *attr,
1706ca2abf4c02fb3e35247a985c2b6f5834e995033Arthur Jones			       char *buf)
1716ca2abf4c02fb3e35247a985c2b6f5834e995033Arthur Jones{
1726ca2abf4c02fb3e35247a985c2b6f5834e995033Arthur Jones	struct ipath_devdata *dd = dev_get_drvdata(dev);
1736ca2abf4c02fb3e35247a985c2b6f5834e995033Arthur Jones	/* The string printed here is already newline-terminated. */
1746ca2abf4c02fb3e35247a985c2b6f5834e995033Arthur Jones	return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_lbus_info);
1756ca2abf4c02fb3e35247a985c2b6f5834e995033Arthur Jones}
1766ca2abf4c02fb3e35247a985c2b6f5834e995033Arthur Jones
17715cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbellstatic ssize_t show_lmc(struct device *dev,
17815cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell			struct device_attribute *attr,
17915cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell			char *buf)
18015cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell{
18115cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	struct ipath_devdata *dd = dev_get_drvdata(dev);
18215cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell
18315cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_lmc);
18415cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell}
18515cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell
18615cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbellstatic ssize_t store_lmc(struct device *dev,
18715cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell			 struct device_attribute *attr,
18815cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell			 const char *buf,
18915cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell			 size_t count)
19015cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell{
19115cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	struct ipath_devdata *dd = dev_get_drvdata(dev);
19215cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	u16 lmc = 0;
19315cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	int ret;
19415cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell
19515cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	ret = ipath_parse_ushort(buf, &lmc);
19615cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	if (ret < 0)
19715cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell		goto invalid;
19815cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell
19915cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	if (lmc > 7) {
20015cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell		ret = -EINVAL;
20115cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell		goto invalid;
20215cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	}
20315cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell
20415cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	ipath_set_lid(dd, dd->ipath_lid, lmc);
20515cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell
20615cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	goto bail;
20715cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbellinvalid:
20815cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	ipath_dev_err(dd, "attempt to set invalid LMC %u\n", lmc);
20915cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbellbail:
21015cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	return ret;
21115cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell}
21215cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell
2133e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_lid(struct device *dev,
2143e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			struct device_attribute *attr,
2153e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			char *buf)
2163e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
2173e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
2183e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2193e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_lid);
2203e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
2213e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2223e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t store_lid(struct device *dev,
2233e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 struct device_attribute *attr,
2243e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  const char *buf,
2253e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  size_t count)
2263e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
2273e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
2281eb68b990aab4c007e520acae39c74d8116693bcBryan O'Sullivan	u16 lid = 0;
2293e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	int ret;
2303e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2313e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = ipath_parse_ushort(buf, &lid);
2323e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (ret < 0)
2333e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto invalid;
2343e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
23527b678dd04a636f2c351816f4b3042c8815d4e9dBryan O'Sullivan	if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE) {
2363e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ret = -EINVAL;
2373e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto invalid;
2383e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
2393e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
24015cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	ipath_set_lid(dd, lid, dd->ipath_lmc);
2413e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2423e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	goto bail;
2433e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivaninvalid:
2441eb68b990aab4c007e520acae39c74d8116693bcBryan O'Sullivan	ipath_dev_err(dd, "attempt to set invalid LID 0x%x\n", lid);
2453e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanbail:
2463e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return ret;
2473e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
2483e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2493e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_mlid(struct device *dev,
2503e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 struct device_attribute *attr,
2513e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 char *buf)
2523e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
2533e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
2543e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2553e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_mlid);
2563e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
2573e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2583e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t store_mlid(struct device *dev,
2593e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 struct device_attribute *attr,
2603e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  const char *buf,
2613e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  size_t count)
2623e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
2633e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
2643e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	u16 mlid;
2653e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	int ret;
2663e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2673e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = ipath_parse_ushort(buf, &mlid);
26827b678dd04a636f2c351816f4b3042c8815d4e9dBryan O'Sullivan	if (ret < 0 || mlid < IPATH_MULTICAST_LID_BASE)
2693e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto invalid;
2703e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2713e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	dd->ipath_mlid = mlid;
2723e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2733e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	goto bail;
2743e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivaninvalid:
2753e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ipath_dev_err(dd, "attempt to set invalid MLID\n");
2763e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanbail:
2773e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return ret;
2783e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
2793e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2803e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_guid(struct device *dev,
2813e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 struct device_attribute *attr,
2823e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 char *buf)
2833e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
2843e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
2853e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	u8 *guid;
2863e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2873e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	guid = (u8 *) & (dd->ipath_guid);
2883e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2893e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return scnprintf(buf, PAGE_SIZE,
2903e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
2913e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 guid[0], guid[1], guid[2], guid[3],
2923e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 guid[4], guid[5], guid[6], guid[7]);
2933e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
2943e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
2953e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t store_guid(struct device *dev,
2963e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 struct device_attribute *attr,
2973e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  const char *buf,
2983e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  size_t count)
2993e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
3003e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
3013e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ssize_t ret;
3023e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	unsigned short guid[8];
30311b054fe1d453954449a86de178bb98274bb86efBryan O'Sullivan	__be64 new_guid;
3043e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	u8 *ng;
3053e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	int i;
3063e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
3073e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (sscanf(buf, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
3083e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		   &guid[0], &guid[1], &guid[2], &guid[3],
3093e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		   &guid[4], &guid[5], &guid[6], &guid[7]) != 8)
3103e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto invalid;
3113e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
31211b054fe1d453954449a86de178bb98274bb86efBryan O'Sullivan	ng = (u8 *) &new_guid;
3133e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
3143e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	for (i = 0; i < 8; i++) {
3153e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		if (guid[i] > 0xff)
3163e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			goto invalid;
3173e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ng[i] = guid[i];
3183e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
3193e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
32011b054fe1d453954449a86de178bb98274bb86efBryan O'Sullivan	if (new_guid == 0)
32111b054fe1d453954449a86de178bb98274bb86efBryan O'Sullivan		goto invalid;
32211b054fe1d453954449a86de178bb98274bb86efBryan O'Sullivan
32311b054fe1d453954449a86de178bb98274bb86efBryan O'Sullivan	dd->ipath_guid = new_guid;
3243e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	dd->ipath_nguid = 1;
325bb9171448deb1f7ece27674e2e431e4f267fd453Arthur Jones	if (dd->verbs_dev)
326bb9171448deb1f7ece27674e2e431e4f267fd453Arthur Jones		dd->verbs_dev->ibdev.node_guid = new_guid;
3273e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
3283e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = strlen(buf);
3293e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	goto bail;
3303e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
3313e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivaninvalid:
3323e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ipath_dev_err(dd, "attempt to set invalid GUID\n");
3333e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = -EINVAL;
3343e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
3353e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanbail:
3363e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return ret;
3373e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
3383e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
3393e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_nguid(struct device *dev,
3403e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  struct device_attribute *attr,
3413e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  char *buf)
3423e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
3433e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
3443e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
3453e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid);
3463e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
3473e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
3489929b0fb0f35f54371e9364bab809bcd753f9d3aBryan O'Sullivanstatic ssize_t show_nports(struct device *dev,
3499929b0fb0f35f54371e9364bab809bcd753f9d3aBryan O'Sullivan			   struct device_attribute *attr,
3509929b0fb0f35f54371e9364bab809bcd753f9d3aBryan O'Sullivan			   char *buf)
3519929b0fb0f35f54371e9364bab809bcd753f9d3aBryan O'Sullivan{
3529929b0fb0f35f54371e9364bab809bcd753f9d3aBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
3539929b0fb0f35f54371e9364bab809bcd753f9d3aBryan O'Sullivan
3549929b0fb0f35f54371e9364bab809bcd753f9d3aBryan O'Sullivan	/* Return the number of user ports available. */
3559929b0fb0f35f54371e9364bab809bcd753f9d3aBryan O'Sullivan	return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_cfgports - 1);
3569929b0fb0f35f54371e9364bab809bcd753f9d3aBryan O'Sullivan}
3579929b0fb0f35f54371e9364bab809bcd753f9d3aBryan O'Sullivan
3583e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_serial(struct device *dev,
3593e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			   struct device_attribute *attr,
3603e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			   char *buf)
3613e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
3623e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
3633e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
3643e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	buf[sizeof dd->ipath_serial] = '\0';
3653e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	memcpy(buf, dd->ipath_serial, sizeof dd->ipath_serial);
3663e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	strcat(buf, "\n");
3673e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return strlen(buf);
3683e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
3693e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
3703e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_unit(struct device *dev,
3713e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 struct device_attribute *attr,
3723e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 char *buf)
3733e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
3743e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
3753e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
3763e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_unit);
3773e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
3783e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
379359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t show_jint_max_packets(struct device *dev,
380359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh				     struct device_attribute *attr,
381359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh				     char *buf)
382359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
383359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
384359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
385359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return scnprintf(buf, PAGE_SIZE, "%hu\n", dd->ipath_jint_max_packets);
386359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
387359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
388359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t store_jint_max_packets(struct device *dev,
389359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh				      struct device_attribute *attr,
390359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh				      const char *buf,
391359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh				      size_t count)
392359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
393359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
394359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	u16 v = 0;
395359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret;
396359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
397359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = ipath_parse_ushort(buf, &v);
398359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret < 0)
399359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ipath_dev_err(dd, "invalid jint_max_packets.\n");
400359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	else
401359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		dd->ipath_f_config_jint(dd, dd->ipath_jint_idle_ticks, v);
402359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
403359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
404359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
405359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
406359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t show_jint_idle_ticks(struct device *dev,
407359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh				    struct device_attribute *attr,
408359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh				    char *buf)
409359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
410359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
411359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
412359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return scnprintf(buf, PAGE_SIZE, "%hu\n", dd->ipath_jint_idle_ticks);
413359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
414359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
415359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t store_jint_idle_ticks(struct device *dev,
416359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh				     struct device_attribute *attr,
417359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh				     const char *buf,
418359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh				     size_t count)
419359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
420359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
421359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	u16 v = 0;
422359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret;
423359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
424359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = ipath_parse_ushort(buf, &v);
425359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret < 0)
426359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ipath_dev_err(dd, "invalid jint_idle_ticks.\n");
427359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	else
428359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		dd->ipath_f_config_jint(dd, v, dd->ipath_jint_max_packets);
429359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
430359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
431359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
432359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
4333e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan#define DEVICE_COUNTER(name, attr) \
4343e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	static ssize_t show_counter_##name(struct device *dev, \
4353e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan					   struct device_attribute *attr, \
4363e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan					   char *buf) \
4373e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	{ \
4383e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		struct ipath_devdata *dd = dev_get_drvdata(dev); \
4393e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		return scnprintf(\
4403e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			buf, PAGE_SIZE, "%llu\n", (unsigned long long) \
4413e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			ipath_snap_cntr( \
4423e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan				dd, offsetof(struct infinipath_counters, \
4433e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan					     attr) / sizeof(u64)));	\
4443e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	} \
4453e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	static DEVICE_ATTR(name, S_IRUGO, show_counter_##name, NULL);
4463e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
4473e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(ib_link_downeds, IBLinkDownedCnt);
4483e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(ib_link_err_recoveries, IBLinkErrRecoveryCnt);
4493e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(ib_status_changes, IBStatusChangeCnt);
4503e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(ib_symbol_errs, IBSymbolErrCnt);
4513e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(lb_flow_stalls, LBFlowStallCnt);
4523e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(lb_ints, LBIntCnt);
4533e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_bad_formats, RxBadFormatCnt);
4543e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_buf_ovfls, RxBufOvflCnt);
4553e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_data_pkts, RxDataPktCnt);
4563e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_dropped_pkts, RxDroppedPktCnt);
4573e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_dwords, RxDwordCnt);
4583e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_ebps, RxEBPCnt);
4593e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_flow_ctrl_errs, RxFlowCtrlErrCnt);
4603e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_flow_pkts, RxFlowPktCnt);
4613e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_icrc_errs, RxICRCErrCnt);
4623e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_len_errs, RxLenErrCnt);
4633e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_link_problems, RxLinkProblemCnt);
4643e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_lpcrc_errs, RxLPCRCErrCnt);
4653e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_max_min_len_errs, RxMaxMinLenErrCnt);
4663e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_p0_hdr_egr_ovfls, RxP0HdrEgrOvflCnt);
4673e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_p1_hdr_egr_ovfls, RxP1HdrEgrOvflCnt);
4683e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_p2_hdr_egr_ovfls, RxP2HdrEgrOvflCnt);
4693e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_p3_hdr_egr_ovfls, RxP3HdrEgrOvflCnt);
4703e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_p4_hdr_egr_ovfls, RxP4HdrEgrOvflCnt);
4713e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_p5_hdr_egr_ovfls, RxP5HdrEgrOvflCnt);
4723e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_p6_hdr_egr_ovfls, RxP6HdrEgrOvflCnt);
4733e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_p7_hdr_egr_ovfls, RxP7HdrEgrOvflCnt);
4743e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_p8_hdr_egr_ovfls, RxP8HdrEgrOvflCnt);
4753e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_pkey_mismatches, RxPKeyMismatchCnt);
4763e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_tid_full_errs, RxTIDFullErrCnt);
4773e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_tid_valid_errs, RxTIDValidErrCnt);
4783e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(rx_vcrc_errs, RxVCRCErrCnt);
4793e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(tx_data_pkts, TxDataPktCnt);
4803e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(tx_dropped_pkts, TxDroppedPktCnt);
4813e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(tx_dwords, TxDwordCnt);
4823e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(tx_flow_pkts, TxFlowPktCnt);
4833e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(tx_flow_stalls, TxFlowStallCnt);
4843e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(tx_len_errs, TxLenErrCnt);
4853e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(tx_max_min_len_errs, TxMaxMinLenErrCnt);
4863e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(tx_underruns, TxUnderrunCnt);
4873e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'SullivanDEVICE_COUNTER(tx_unsup_vl_errs, TxUnsupVLErrCnt);
4883e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
4893e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic struct attribute *dev_counter_attributes[] = {
4903e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_ib_link_downeds.attr,
4913e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_ib_link_err_recoveries.attr,
4923e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_ib_status_changes.attr,
4933e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_ib_symbol_errs.attr,
4943e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_lb_flow_stalls.attr,
4953e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_lb_ints.attr,
4963e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_bad_formats.attr,
4973e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_buf_ovfls.attr,
4983e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_data_pkts.attr,
4993e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_dropped_pkts.attr,
5003e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_dwords.attr,
5013e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_ebps.attr,
5023e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_flow_ctrl_errs.attr,
5033e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_flow_pkts.attr,
5043e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_icrc_errs.attr,
5053e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_len_errs.attr,
5063e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_link_problems.attr,
5073e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_lpcrc_errs.attr,
5083e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_max_min_len_errs.attr,
5093e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_p0_hdr_egr_ovfls.attr,
5103e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_p1_hdr_egr_ovfls.attr,
5113e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_p2_hdr_egr_ovfls.attr,
5123e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_p3_hdr_egr_ovfls.attr,
5133e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_p4_hdr_egr_ovfls.attr,
5143e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_p5_hdr_egr_ovfls.attr,
5153e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_p6_hdr_egr_ovfls.attr,
5163e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_p7_hdr_egr_ovfls.attr,
5173e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_p8_hdr_egr_ovfls.attr,
5183e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_pkey_mismatches.attr,
5193e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_tid_full_errs.attr,
5203e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_tid_valid_errs.attr,
5213e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_rx_vcrc_errs.attr,
5223e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_tx_data_pkts.attr,
5233e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_tx_dropped_pkts.attr,
5243e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_tx_dwords.attr,
5253e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_tx_flow_pkts.attr,
5263e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_tx_flow_stalls.attr,
5273e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_tx_len_errs.attr,
5283e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_tx_max_min_len_errs.attr,
5293e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_tx_underruns.attr,
5303e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_tx_unsup_vl_errs.attr,
5313e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	NULL
5323e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan};
5333e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
5343e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic struct attribute_group dev_counter_attr_group = {
5353e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	.name = "counters",
5363e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	.attrs = dev_counter_attributes
5373e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan};
5383e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
5393e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t store_reset(struct device *dev,
5403e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 struct device_attribute *attr,
5413e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  const char *buf,
5423e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  size_t count)
5433e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
5443e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
5453e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	int ret;
5463e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
5473e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (count < 5 || memcmp(buf, "reset", 5)) {
5483e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ret = -EINVAL;
5493e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto bail;
5503e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
5513e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
5523e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (dd->ipath_flags & IPATH_DISABLED) {
5533e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		/*
5543e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		 * post-reset init would re-enable interrupts, etc.
5553e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		 * so don't allow reset on disabled devices.  Not
5563e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		 * perfect error, but about the best choice.
5573e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		 */
5583e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		dev_info(dev,"Unit %d is disabled, can't reset\n",
5593e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 dd->ipath_unit);
5603e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ret = -EINVAL;
5612a543904ddcb463db9d56d1efcb2f80884ea55f3Nicolas Kaiser		goto bail;
5623e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
5633e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = ipath_reset_device(dd->ipath_unit);
5643e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanbail:
5653e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return ret<0 ? ret : count;
5663e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
5673e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
5683e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t store_link_state(struct device *dev,
5693e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 struct device_attribute *attr,
5703e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  const char *buf,
5713e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  size_t count)
5723e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
5733e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
5743e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	int ret, r;
5753e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	u16 state;
5763e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
5773e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = ipath_parse_ushort(buf, &state);
5783e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (ret < 0)
5793e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto invalid;
5803e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
58134b2aafea38efdf02cd8107a6e1057e2a297c447Bryan O'Sullivan	r = ipath_set_linkstate(dd, state);
5823e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (r < 0) {
5833e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ret = r;
5843e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto bail;
5853e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
5863e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
5873e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	goto bail;
5883e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivaninvalid:
5893e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ipath_dev_err(dd, "attempt to set invalid link state\n");
5903e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanbail:
5913e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return ret;
5923e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
5933e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
5943e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_mtu(struct device *dev,
5953e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 struct device_attribute *attr,
5963e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 char *buf)
5973e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
5983e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
5993e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_ibmtu);
6003e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
6013e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
6023e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t store_mtu(struct device *dev,
6033e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 struct device_attribute *attr,
6043e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  const char *buf,
6053e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  size_t count)
6063e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
6073e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
6083e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ssize_t ret;
6093e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	u16 mtu = 0;
6103e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	int r;
6113e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
6123e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = ipath_parse_ushort(buf, &mtu);
6133e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (ret < 0)
6143e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto invalid;
6153e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
61634b2aafea38efdf02cd8107a6e1057e2a297c447Bryan O'Sullivan	r = ipath_set_mtu(dd, mtu);
6173e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (r < 0)
6183e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ret = r;
6193e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
6203e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	goto bail;
6213e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivaninvalid:
6223e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ipath_dev_err(dd, "attempt to set invalid MTU\n");
6233e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanbail:
6243e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return ret;
6253e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
6263e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
6273e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t show_enabled(struct device *dev,
6283e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 struct device_attribute *attr,
6293e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 char *buf)
6303e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
6313e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
6323e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return scnprintf(buf, PAGE_SIZE, "%u\n",
6333e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 (dd->ipath_flags & IPATH_DISABLED) ? 0 : 1);
6343e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
6353e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
6363e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic ssize_t store_enabled(struct device *dev,
6373e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			 struct device_attribute *attr,
6383e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  const char *buf,
6393e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			  size_t count)
6403e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
6413e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
6423e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ssize_t ret;
6433e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	u16 enable = 0;
6443e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
6453e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = ipath_parse_ushort(buf, &enable);
6463e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (ret < 0) {
6473e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ipath_dev_err(dd, "attempt to use non-numeric on enable\n");
6483e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto bail;
6493e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
6503e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
6513e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (enable) {
6523e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		if (!(dd->ipath_flags & IPATH_DISABLED))
6533e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			goto bail;
6543e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
6553e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		dev_info(dev, "Enabling unit %d\n", dd->ipath_unit);
6563e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		/* same as post-reset */
6573e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ret = ipath_init_chip(dd, 1);
6583e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		if (ret)
6593e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			ipath_dev_err(dd, "Failed to enable unit %d\n",
6603e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan				      dd->ipath_unit);
6613e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		else {
6623e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			dd->ipath_flags &= ~IPATH_DISABLED;
6633e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan			*dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED;
6643e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		}
6653e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
6663e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	else if (!(dd->ipath_flags & IPATH_DISABLED)) {
6673e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		dev_info(dev, "Disabling unit %d\n", dd->ipath_unit);
6683e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		ipath_shutdown_device(dd);
6693e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		dd->ipath_flags |= IPATH_DISABLED;
6703e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		*dd->ipath_statusp |= IPATH_STATUS_ADMIN_DISABLED;
6713e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	}
6723e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
6733e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanbail:
6743e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return ret;
6753e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
6763e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
67730fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivanstatic ssize_t store_rx_pol_inv(struct device *dev,
67830fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan			  struct device_attribute *attr,
67930fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan			  const char *buf,
68030fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan			  size_t count)
68130fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan{
68230fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan	struct ipath_devdata *dd = dev_get_drvdata(dev);
68330fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan	int ret, r;
68430fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan	u16 val;
68530fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan
68630fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan	ret = ipath_parse_ushort(buf, &val);
68730fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan	if (ret < 0)
68830fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan		goto invalid;
68930fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan
69030fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan	r = ipath_set_rx_pol_inv(dd, val);
69130fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan	if (r < 0) {
69230fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan		ret = r;
69330fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan		goto bail;
69430fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan	}
69530fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan
69630fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan	goto bail;
69730fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivaninvalid:
69830fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan	ipath_dev_err(dd, "attempt to set invalid Rx Polarity invert\n");
69930fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivanbail:
70030fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan	return ret;
70130fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan}
70230fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan
70382466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaughstatic ssize_t store_led_override(struct device *dev,
70482466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh			  struct device_attribute *attr,
70582466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh			  const char *buf,
70682466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh			  size_t count)
70782466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh{
70882466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
70982466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh	int ret;
71082466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh	u16 val;
71182466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh
71282466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh	ret = ipath_parse_ushort(buf, &val);
71382466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh	if (ret > 0)
71482466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh		ipath_set_led_override(dd, val);
71582466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh	else
71682466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh		ipath_dev_err(dd, "attempt to set invalid LED override\n");
71782466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh	return ret;
71882466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh}
71982466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh
720aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaughstatic ssize_t show_logged_errs(struct device *dev,
721aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh				struct device_attribute *attr,
722aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh				char *buf)
723aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh{
724aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
725aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh	int idx, count;
726aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh
727aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh	/* force consistency with actual EEPROM */
728aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh	if (ipath_update_eeprom_log(dd) != 0)
729aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh		return -ENXIO;
730aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh
731aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh	count = 0;
732aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh	for (idx = 0; idx < IPATH_EEP_LOG_CNT; ++idx) {
733aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh		count += scnprintf(buf + count, PAGE_SIZE - count, "%d%c",
734aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh			dd->ipath_eep_st_errs[idx],
735aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh			idx == (IPATH_EEP_LOG_CNT - 1) ? '\n' : ' ');
736aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh	}
737aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh
738aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh	return count;
739aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh}
74030fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan
741359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh/*
742359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh * New sysfs entries to control various IB config. These all turn into
743359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh * accesses via ipath_f_get/set_ib_cfg.
744359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh *
745359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh * Get/Set heartbeat enable. Or of 1=enabled, 2=auto
746359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh */
747359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t show_hrtbt_enb(struct device *dev,
748359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 struct device_attribute *attr,
749359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 char *buf)
750359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
751359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
752359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret;
753359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
754359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_HRTBT);
755359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret >= 0)
756359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
757359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
758359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
759359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
760359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t store_hrtbt_enb(struct device *dev,
761359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  struct device_attribute *attr,
762359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  const char *buf,
763359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  size_t count)
764359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
765359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
766359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret, r;
767359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	u16 val;
768359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
769359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = ipath_parse_ushort(buf, &val);
770359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret >= 0 && val > 3)
771359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = -EINVAL;
772359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret < 0) {
773359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ipath_dev_err(dd, "attempt to set invalid Heartbeat enable\n");
774359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		goto bail;
775359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	}
776359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
777359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	/*
778359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	 * Set the "intentional" heartbeat enable per either of
779359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	 * "Enable" and "Auto", as these are normally set together.
780359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	 * This bit is consulted when leaving loopback mode,
781359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	 * because entering loopback mode overrides it and automatically
782359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	 * disables heartbeat.
783359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	 */
784359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_HRTBT, val);
785359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (r < 0)
786359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = r;
787359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	else if (val == IPATH_IB_HRTBT_OFF)
788359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		dd->ipath_flags |= IPATH_NO_HRTBT;
789359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	else
790359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		dd->ipath_flags &= ~IPATH_NO_HRTBT;
791359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
792359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughbail:
793359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
794359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
795359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
796359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh/*
797359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh * Get/Set Link-widths enabled. Or of 1=1x, 2=4x (this is human/IB centric,
798359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh * _not_ the particular encoding of any given chip)
799359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh */
800359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t show_lwid_enb(struct device *dev,
801359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 struct device_attribute *attr,
802359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 char *buf)
803359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
804359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
805359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret;
806359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
807359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB);
808359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret >= 0)
809359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
810359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
811359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
812359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
813359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t store_lwid_enb(struct device *dev,
814359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  struct device_attribute *attr,
815359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  const char *buf,
816359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  size_t count)
817359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
818359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
819359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret, r;
820359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	u16 val;
821359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
822359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = ipath_parse_ushort(buf, &val);
823359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret >= 0 && (val == 0 || val > 3))
824359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = -EINVAL;
825359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret < 0) {
826359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ipath_dev_err(dd,
827359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			"attempt to set invalid Link Width (enable)\n");
828359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		goto bail;
829359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	}
830359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
831359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB, val);
832359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (r < 0)
833359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = r;
834359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
835359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughbail:
836359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
837359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
838359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
839359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh/* Get current link width */
840359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t show_lwid(struct device *dev,
841359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 struct device_attribute *attr,
842359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 char *buf)
843359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
844359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
845359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
846359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret;
847359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
848359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LWID);
849359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret >= 0)
850359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
851359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
852359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
853359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
854359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh/*
855359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh * Get/Set Link-speeds enabled. Or of 1=SDR 2=DDR.
856359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh */
857359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t show_spd_enb(struct device *dev,
858359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 struct device_attribute *attr,
859359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 char *buf)
860359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
861359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
862359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret;
863359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
864359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB);
865359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret >= 0)
866359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
867359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
868359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
869359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
870359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t store_spd_enb(struct device *dev,
871359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  struct device_attribute *attr,
872359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  const char *buf,
873359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  size_t count)
874359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
875359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
876359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret, r;
877359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	u16 val;
878359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
879359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = ipath_parse_ushort(buf, &val);
880359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret >= 0 && (val == 0 || val > (IPATH_IB_SDR | IPATH_IB_DDR)))
881359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = -EINVAL;
882359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret < 0) {
883359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ipath_dev_err(dd,
884359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			"attempt to set invalid Link Speed (enable)\n");
885359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		goto bail;
886359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	}
887359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
888359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB, val);
889359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (r < 0)
890359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = r;
891359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
892359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughbail:
893359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
894359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
895359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
896359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh/* Get current link speed */
897359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t show_spd(struct device *dev,
898359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 struct device_attribute *attr,
899359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 char *buf)
900359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
901359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
902359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret;
903359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
904359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_SPD);
905359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret >= 0)
906359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
907359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
908359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
909359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
910359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh/*
911359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh * Get/Set RX polarity-invert enable. 0=no, 1=yes.
912359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh */
913359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t show_rx_polinv_enb(struct device *dev,
914359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 struct device_attribute *attr,
915359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 char *buf)
916359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
917359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
918359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret;
919359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
920359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_RXPOL_ENB);
921359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret >= 0)
922359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
923359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
924359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
925359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
926359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t store_rx_polinv_enb(struct device *dev,
927359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  struct device_attribute *attr,
928359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  const char *buf,
929359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  size_t count)
930359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
931359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
932359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret, r;
933359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	u16 val;
934359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
935359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = ipath_parse_ushort(buf, &val);
936bb9171448deb1f7ece27674e2e431e4f267fd453Arthur Jones	if (ret >= 0 && val > 1) {
937bb9171448deb1f7ece27674e2e431e4f267fd453Arthur Jones		ipath_dev_err(dd,
938bb9171448deb1f7ece27674e2e431e4f267fd453Arthur Jones			"attempt to set invalid Rx Polarity (enable)\n");
939bb9171448deb1f7ece27674e2e431e4f267fd453Arthur Jones		ret = -EINVAL;
940bb9171448deb1f7ece27674e2e431e4f267fd453Arthur Jones		goto bail;
941bb9171448deb1f7ece27674e2e431e4f267fd453Arthur Jones	}
942359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
943359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_RXPOL_ENB, val);
944bb9171448deb1f7ece27674e2e431e4f267fd453Arthur Jones	if (r < 0)
945359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = r;
946359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
947359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughbail:
948359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
949359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
950d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh
951359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh/*
952359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh * Get/Set RX lane-reversal enable. 0=no, 1=yes.
953359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh */
954359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t show_lanerev_enb(struct device *dev,
955359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 struct device_attribute *attr,
956359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			 char *buf)
957359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
958359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
959359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret;
960359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
961359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LREV_ENB);
962359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret >= 0)
963359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret);
964359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
965359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
966359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
967359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic ssize_t store_lanerev_enb(struct device *dev,
968359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  struct device_attribute *attr,
969359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  const char *buf,
970359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			  size_t count)
971359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh{
972359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
973359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	int ret, r;
974359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	u16 val;
975359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
976359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	ret = ipath_parse_ushort(buf, &val);
977359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (ret >= 0 && val > 1) {
978359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = -EINVAL;
979359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ipath_dev_err(dd,
980359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			"attempt to set invalid Lane reversal (enable)\n");
981359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		goto bail;
982359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	}
983359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
984359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LREV_ENB, val);
985359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (r < 0)
986359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = r;
987359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
988359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughbail:
989359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	return ret;
990359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh}
991359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
9923e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DRIVER_ATTR(num_units, S_IRUGO, show_num_units, NULL);
9933e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DRIVER_ATTR(version, S_IRUGO, show_version, NULL);
9943e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
9953e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic struct attribute *driver_attributes[] = {
9963e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&driver_attr_num_units.attr,
9973e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&driver_attr_version.attr,
9983e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	NULL
9993e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan};
10003e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
10013e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic struct attribute_group driver_attr_group = {
10023e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	.attrs = driver_attributes
10033e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan};
10043e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1005d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaughstatic ssize_t store_tempsense(struct device *dev,
1006d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh			       struct device_attribute *attr,
1007d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh			       const char *buf,
1008d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh			       size_t count)
1009d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh{
1010d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
1011d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	int ret, stat;
1012d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	u16 val;
1013d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh
1014d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	ret = ipath_parse_ushort(buf, &val);
1015d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	if (ret <= 0) {
1016d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		ipath_dev_err(dd, "attempt to set invalid tempsense config\n");
1017d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		goto bail;
1018d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	}
1019d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	/* If anything but the highest limit, enable T_CRIT_A "interrupt" */
1020d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	stat = ipath_tempsense_write(dd, 9, (val == 0x7f7f) ? 0x80 : 0);
1021d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	if (stat) {
1022d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		ipath_dev_err(dd, "Unable to set tempsense config\n");
1023d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		ret = -1;
1024d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		goto bail;
1025d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	}
1026d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	stat = ipath_tempsense_write(dd, 0xB, (u8) (val & 0xFF));
1027d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	if (stat) {
1028d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		ipath_dev_err(dd, "Unable to set local Tcrit\n");
1029d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		ret = -1;
1030d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		goto bail;
1031d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	}
1032d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	stat = ipath_tempsense_write(dd, 0xD, (u8) (val >> 8));
1033d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	if (stat) {
1034d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		ipath_dev_err(dd, "Unable to set remote Tcrit\n");
1035d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		ret = -1;
1036d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		goto bail;
1037d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	}
1038d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh
1039d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaughbail:
1040d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	return ret;
1041d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh}
1042d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh
1043d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh/*
1044d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh * dump tempsense regs. in decimal, to ease shell-scripts.
1045d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh */
1046d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaughstatic ssize_t show_tempsense(struct device *dev,
1047d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh			      struct device_attribute *attr,
1048d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh			      char *buf)
1049d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh{
1050d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	struct ipath_devdata *dd = dev_get_drvdata(dev);
1051d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	int ret;
1052d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	int idx;
1053d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	u8 regvals[8];
1054d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh
1055d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	ret = -ENXIO;
1056d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	for (idx = 0; idx < 8; ++idx) {
1057d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		if (idx == 6)
1058d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh			continue;
1059d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		ret = ipath_tempsense_read(dd, idx);
1060d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		if (ret < 0)
1061d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh			break;
1062d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		regvals[idx] = ret;
1063d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	}
1064d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	if (idx == 8)
1065d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		ret = scnprintf(buf, PAGE_SIZE, "%d %d %02X %02X %d %d\n",
1066d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh			*(signed char *)(regvals),
1067d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh			*(signed char *)(regvals + 1),
1068d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh			regvals[2], regvals[3],
1069d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh			*(signed char *)(regvals + 5),
1070d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh			*(signed char *)(regvals + 7));
1071d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	return ret;
1072d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh}
1073d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh
1074a4dbd6740df0872cdf0a86841f75beec8381964dDavid Brownellconst struct attribute_group *ipath_driver_attr_groups[] = {
107523b9c1ab5baf368a32b7242bf110ef1f48700d04Greg Kroah-Hartman	&driver_attr_group,
107623b9c1ab5baf368a32b7242bf110ef1f48700d04Greg Kroah-Hartman	NULL,
107723b9c1ab5baf368a32b7242bf110ef1f48700d04Greg Kroah-Hartman};
107823b9c1ab5baf368a32b7242bf110ef1f48700d04Greg Kroah-Hartman
10793e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid);
108015cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbellstatic DEVICE_ATTR(lmc, S_IWUSR | S_IRUGO, show_lmc, store_lmc);
10813e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid);
10823e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(link_state, S_IWUSR, NULL, store_link_state);
10833e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid);
10843e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu);
10853e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled);
10863e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL);
10879929b0fb0f35f54371e9364bab809bcd753f9d3aBryan O'Sullivanstatic DEVICE_ATTR(nports, S_IRUGO, show_nports, NULL);
10883e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset);
10893e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
10903e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
10913e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(status_str, S_IRUGO, show_status_str, NULL);
10923e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
10933e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic DEVICE_ATTR(unit, S_IRUGO, show_unit, NULL);
109430fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivanstatic DEVICE_ATTR(rx_pol_inv, S_IWUSR, NULL, store_rx_pol_inv);
109582466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaughstatic DEVICE_ATTR(led_override, S_IWUSR, NULL, store_led_override);
1096aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaughstatic DEVICE_ATTR(logged_errors, S_IRUGO, show_logged_errs, NULL);
10976ca2abf4c02fb3e35247a985c2b6f5834e995033Arthur Jonesstatic DEVICE_ATTR(localbus_info, S_IRUGO, show_localbus_info, NULL);
1098359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic DEVICE_ATTR(jint_max_packets, S_IWUSR | S_IRUGO,
1099359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		   show_jint_max_packets, store_jint_max_packets);
1100359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic DEVICE_ATTR(jint_idle_ticks, S_IWUSR | S_IRUGO,
1101359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		   show_jint_idle_ticks, store_jint_idle_ticks);
1102d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaughstatic DEVICE_ATTR(tempsense, S_IWUSR | S_IRUGO,
1103d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh		   show_tempsense, store_tempsense);
11043e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
11053e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic struct attribute *dev_attributes[] = {
11063e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_guid.attr,
110715cba26f42c13ca30cbb4388f132ac0ddf4df538Ralph Campbell	&dev_attr_lmc.attr,
11083e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_lid.attr,
11093e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_link_state.attr,
11103e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_mlid.attr,
11113e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_mtu.attr,
11123e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_nguid.attr,
11139929b0fb0f35f54371e9364bab809bcd753f9d3aBryan O'Sullivan	&dev_attr_nports.attr,
11143e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_serial.attr,
11153e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_status.attr,
11163e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_status_str.attr,
11173e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_boardversion.attr,
11183e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_unit.attr,
11193e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	&dev_attr_enabled.attr,
112030fc5c3130bdbc7cc051a2d6054ad38360d408a8Bryan O'Sullivan	&dev_attr_rx_pol_inv.attr,
112182466f00ec6ef0a5ca7ea8991c731af2ec561c7dMichael Albaugh	&dev_attr_led_override.attr,
1122aecd3b5ab19624ca9644b9df9c61615282d8923fMichael Albaugh	&dev_attr_logged_errors.attr,
1123d84e0b28d3a0b41fc574ea50d60522ae0fba75f4Michael Albaugh	&dev_attr_tempsense.attr,
11246ca2abf4c02fb3e35247a985c2b6f5834e995033Arthur Jones	&dev_attr_localbus_info.attr,
11253e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	NULL
11263e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan};
11273e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
11283e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanstatic struct attribute_group dev_attr_group = {
11293e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	.attrs = dev_attributes
11303e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan};
11313e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1132359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic DEVICE_ATTR(hrtbt_enable, S_IWUSR | S_IRUGO, show_hrtbt_enb,
1133359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		   store_hrtbt_enb);
1134359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic DEVICE_ATTR(link_width_enable, S_IWUSR | S_IRUGO, show_lwid_enb,
1135359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		   store_lwid_enb);
1136359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic DEVICE_ATTR(link_width, S_IRUGO, show_lwid, NULL);
1137359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic DEVICE_ATTR(link_speed_enable, S_IWUSR | S_IRUGO, show_spd_enb,
1138359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		   store_spd_enb);
1139359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic DEVICE_ATTR(link_speed, S_IRUGO, show_spd, NULL);
1140359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic DEVICE_ATTR(rx_pol_inv_enable, S_IWUSR | S_IRUGO, show_rx_polinv_enb,
1141359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		   store_rx_polinv_enb);
1142359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic DEVICE_ATTR(rx_lane_rev_enable, S_IWUSR | S_IRUGO, show_lanerev_enb,
1143359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		   store_lanerev_enb);
1144359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
1145359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic struct attribute *dev_ibcfg_attributes[] = {
1146359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	&dev_attr_hrtbt_enable.attr,
1147359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	&dev_attr_link_width_enable.attr,
1148359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	&dev_attr_link_width.attr,
1149359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	&dev_attr_link_speed_enable.attr,
1150359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	&dev_attr_link_speed.attr,
1151359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	&dev_attr_rx_pol_inv_enable.attr,
1152359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	&dev_attr_rx_lane_rev_enable.attr,
1153359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	NULL
1154359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh};
1155359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
1156359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughstatic struct attribute_group dev_ibcfg_attr_group = {
1157359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	.attrs = dev_ibcfg_attributes
1158359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh};
1159359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
11603e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan/**
11613e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * ipath_expose_reset - create a device reset file
11623e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * @dev: the device structure
11633e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan *
11643e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * Only expose a file that lets us reset the device after someone
11653e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * enters diag mode.  A device reset is quite likely to crash the
11663e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * machine entirely, so we don't want to normally make it
11673e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan * available.
1168755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan *
1169755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan * Called with ipath_mutex held.
11703e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan */
11713e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanint ipath_expose_reset(struct device *dev)
11723e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
1173755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan	static int exposed;
1174755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan	int ret;
1175755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan
1176755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan	if (!exposed) {
1177755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan		ret = device_create_file(dev, &dev_attr_reset);
1178755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan		exposed = 1;
1179755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan	}
1180755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan	else
1181755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan		ret = 0;
1182755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan
1183755e4ca4a9885b79a14169ab5b615920eb38a32aBryan O'Sullivan	return ret;
11843e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
11853e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
11863e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanint ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
11873e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
11883e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	int ret;
11893e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
11903e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = sysfs_create_group(&dev->kobj, &dev_attr_group);
11913e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (ret)
11923e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto bail;
11933e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
11943e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group);
11953e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	if (ret)
11963e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan		goto bail_attrs;
11973e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
1198359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (dd->ipath_flags & IPATH_HAS_MULT_IB_SPEED) {
1199359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = device_create_file(dev, &dev_attr_jint_idle_ticks);
1200359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		if (ret)
1201359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			goto bail_counter;
1202359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = device_create_file(dev, &dev_attr_jint_max_packets);
1203359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		if (ret)
1204359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			goto bail_idle;
1205359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
1206359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		ret = sysfs_create_group(&dev->kobj, &dev_ibcfg_attr_group);
1207359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		if (ret)
1208359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh			goto bail_max;
1209359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	}
1210359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
1211657c2f2cbccbac88689ac5174fc13dd3f9aece34Roland Dreier	return 0;
1212657c2f2cbccbac88689ac5174fc13dd3f9aece34Roland Dreier
1213359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughbail_max:
1214359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	device_remove_file(dev, &dev_attr_jint_max_packets);
1215359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughbail_idle:
1216359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	device_remove_file(dev, &dev_attr_jint_idle_ticks);
1217359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaughbail_counter:
1218359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
12193e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanbail_attrs:
12203e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	sysfs_remove_group(&dev->kobj, &dev_attr_group);
12213e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanbail:
12223e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	return ret;
12233e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
12243e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
12253e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivanvoid ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd)
12263e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan{
12273e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
1228359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
1229359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	if (dd->ipath_flags & IPATH_HAS_MULT_IB_SPEED) {
1230359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		sysfs_remove_group(&dev->kobj, &dev_ibcfg_attr_group);
1231359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		device_remove_file(dev, &dev_attr_jint_idle_ticks);
1232359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh		device_remove_file(dev, &dev_attr_jint_max_packets);
1233359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh	}
1234359193ef433061515fe24d57e5bd5a1318d71bc3Michael Albaugh
12353e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	sysfs_remove_group(&dev->kobj, &dev_attr_group);
12363e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan
12373e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan	device_remove_file(dev, &dev_attr_reset);
12383e9b4a5eb4ae4936feeea256c0105e078c7702cdBryan O'Sullivan}
1239