xref: /openbmc/linux/drivers/infiniband/hw/qib/qib_sysfs.c (revision 4a7aaf88c89f12f8048137e274ce0d40fe1056b2)
1f931551bSRalph Campbell /*
236a8f01cSMike Marciniszyn  * Copyright (c) 2012 Intel Corporation.  All rights reserved.
336a8f01cSMike Marciniszyn  * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
4f931551bSRalph Campbell  * Copyright (c) 2006 PathScale, Inc. All rights reserved.
5f931551bSRalph Campbell  *
6f931551bSRalph Campbell  * This software is available to you under a choice of one of two
7f931551bSRalph Campbell  * licenses.  You may choose to be licensed under the terms of the GNU
8f931551bSRalph Campbell  * General Public License (GPL) Version 2, available from the file
9f931551bSRalph Campbell  * COPYING in the main directory of this source tree, or the
10f931551bSRalph Campbell  * OpenIB.org BSD license below:
11f931551bSRalph Campbell  *
12f931551bSRalph Campbell  *     Redistribution and use in source and binary forms, with or
13f931551bSRalph Campbell  *     without modification, are permitted provided that the following
14f931551bSRalph Campbell  *     conditions are met:
15f931551bSRalph Campbell  *
16f931551bSRalph Campbell  *      - Redistributions of source code must retain the above
17f931551bSRalph Campbell  *        copyright notice, this list of conditions and the following
18f931551bSRalph Campbell  *        disclaimer.
19f931551bSRalph Campbell  *
20f931551bSRalph Campbell  *      - Redistributions in binary form must reproduce the above
21f931551bSRalph Campbell  *        copyright notice, this list of conditions and the following
22f931551bSRalph Campbell  *        disclaimer in the documentation and/or other materials
23f931551bSRalph Campbell  *        provided with the distribution.
24f931551bSRalph Campbell  *
25f931551bSRalph Campbell  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26f931551bSRalph Campbell  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27f931551bSRalph Campbell  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28f931551bSRalph Campbell  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29f931551bSRalph Campbell  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30f931551bSRalph Campbell  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31f931551bSRalph Campbell  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32f931551bSRalph Campbell  * SOFTWARE.
33f931551bSRalph Campbell  */
34f931551bSRalph Campbell #include <linux/ctype.h>
35*4a7aaf88SJason Gunthorpe #include <rdma/ib_sysfs.h>
36f931551bSRalph Campbell 
37f931551bSRalph Campbell #include "qib.h"
3836a8f01cSMike Marciniszyn #include "qib_mad.h"
39f931551bSRalph Campbell 
40*4a7aaf88SJason Gunthorpe static struct qib_pportdata *qib_get_pportdata_kobj(struct kobject *kobj)
41*4a7aaf88SJason Gunthorpe {
42*4a7aaf88SJason Gunthorpe 	u32 port_num;
43*4a7aaf88SJason Gunthorpe 	struct ib_device *ibdev = ib_port_sysfs_get_ibdev_kobj(kobj, &port_num);
44*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
45*4a7aaf88SJason Gunthorpe 
46*4a7aaf88SJason Gunthorpe 	return &dd->pport[port_num - 1];
47*4a7aaf88SJason Gunthorpe }
48*4a7aaf88SJason Gunthorpe 
49f931551bSRalph Campbell /*
50f931551bSRalph Campbell  * Get/Set heartbeat enable. OR of 1=enabled, 2=auto
51f931551bSRalph Campbell  */
52*4a7aaf88SJason Gunthorpe static ssize_t hrtbt_enable_show(struct ib_device *ibdev, u32 port_num,
53*4a7aaf88SJason Gunthorpe 				 struct ib_port_attribute *attr, char *buf)
54f931551bSRalph Campbell {
55*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
56*4a7aaf88SJason Gunthorpe 	struct qib_pportdata *ppd = &dd->pport[port_num - 1];
57f931551bSRalph Campbell 
58e28bf1f0SJoe Perches 	return sysfs_emit(buf, "%d\n", dd->f_get_ib_cfg(ppd, QIB_IB_CFG_HRTBT));
59f931551bSRalph Campbell }
60f931551bSRalph Campbell 
61*4a7aaf88SJason Gunthorpe static ssize_t hrtbt_enable_store(struct ib_device *ibdev, u32 port_num,
62*4a7aaf88SJason Gunthorpe 				  struct ib_port_attribute *attr,
63*4a7aaf88SJason Gunthorpe 				  const char *buf, size_t count)
64f931551bSRalph Campbell {
65*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
66*4a7aaf88SJason Gunthorpe 	struct qib_pportdata *ppd = &dd->pport[port_num - 1];
67f931551bSRalph Campbell 	int ret;
68f931551bSRalph Campbell 	u16 val;
69f931551bSRalph Campbell 
707fac3301SMike Marciniszyn 	ret = kstrtou16(buf, 0, &val);
717fac3301SMike Marciniszyn 	if (ret) {
727fac3301SMike Marciniszyn 		qib_dev_err(dd, "attempt to set invalid Heartbeat enable\n");
737fac3301SMike Marciniszyn 		return ret;
747fac3301SMike Marciniszyn 	}
75f931551bSRalph Campbell 
76f931551bSRalph Campbell 	/*
77f931551bSRalph Campbell 	 * Set the "intentional" heartbeat enable per either of
78f931551bSRalph Campbell 	 * "Enable" and "Auto", as these are normally set together.
79f931551bSRalph Campbell 	 * This bit is consulted when leaving loopback mode,
80f931551bSRalph Campbell 	 * because entering loopback mode overrides it and automatically
81f931551bSRalph Campbell 	 * disables heartbeat.
82f931551bSRalph Campbell 	 */
83f931551bSRalph Campbell 	ret = dd->f_set_ib_cfg(ppd, QIB_IB_CFG_HRTBT, val);
84f931551bSRalph Campbell 	return ret < 0 ? ret : count;
85f931551bSRalph Campbell }
86*4a7aaf88SJason Gunthorpe static IB_PORT_ATTR_RW(hrtbt_enable);
87f931551bSRalph Campbell 
88*4a7aaf88SJason Gunthorpe static ssize_t loopback_store(struct ib_device *ibdev, u32 port_num,
89*4a7aaf88SJason Gunthorpe 			      struct ib_port_attribute *attr, const char *buf,
90f931551bSRalph Campbell 			      size_t count)
91f931551bSRalph Campbell {
92*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
93*4a7aaf88SJason Gunthorpe 	struct qib_pportdata *ppd = &dd->pport[port_num - 1];
94f931551bSRalph Campbell 	int ret = count, r;
95f931551bSRalph Campbell 
96f931551bSRalph Campbell 	r = dd->f_set_ib_loopback(ppd, buf);
97f931551bSRalph Campbell 	if (r < 0)
98f931551bSRalph Campbell 		ret = r;
99f931551bSRalph Campbell 
100f931551bSRalph Campbell 	return ret;
101f931551bSRalph Campbell }
102*4a7aaf88SJason Gunthorpe static IB_PORT_ATTR_WO(loopback);
103f931551bSRalph Campbell 
104*4a7aaf88SJason Gunthorpe static ssize_t led_override_store(struct ib_device *ibdev, u32 port_num,
105*4a7aaf88SJason Gunthorpe 				  struct ib_port_attribute *attr,
106*4a7aaf88SJason Gunthorpe 				  const char *buf, size_t count)
107f931551bSRalph Campbell {
108*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
109*4a7aaf88SJason Gunthorpe 	struct qib_pportdata *ppd = &dd->pport[port_num - 1];
110f931551bSRalph Campbell 	int ret;
111f931551bSRalph Campbell 	u16 val;
112f931551bSRalph Campbell 
1137fac3301SMike Marciniszyn 	ret = kstrtou16(buf, 0, &val);
1147fac3301SMike Marciniszyn 	if (ret) {
115f931551bSRalph Campbell 		qib_dev_err(dd, "attempt to set invalid LED override\n");
1167fac3301SMike Marciniszyn 		return ret;
1177fac3301SMike Marciniszyn 	}
1187fac3301SMike Marciniszyn 
1197fac3301SMike Marciniszyn 	qib_set_led_override(ppd, val);
1207fac3301SMike Marciniszyn 	return count;
121f931551bSRalph Campbell }
122*4a7aaf88SJason Gunthorpe static IB_PORT_ATTR_WO(led_override);
123f931551bSRalph Campbell 
124*4a7aaf88SJason Gunthorpe static ssize_t status_show(struct ib_device *ibdev, u32 port_num,
125*4a7aaf88SJason Gunthorpe 			   struct ib_port_attribute *attr, char *buf)
126f931551bSRalph Campbell {
127*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
128*4a7aaf88SJason Gunthorpe 	struct qib_pportdata *ppd = &dd->pport[port_num - 1];
129*4a7aaf88SJason Gunthorpe 
130f931551bSRalph Campbell 	if (!ppd->statusp)
131e28bf1f0SJoe Perches 		return -EINVAL;
132e28bf1f0SJoe Perches 
133e28bf1f0SJoe Perches 	return sysfs_emit(buf, "0x%llx\n", (unsigned long long)*(ppd->statusp));
134f931551bSRalph Campbell }
135*4a7aaf88SJason Gunthorpe static IB_PORT_ATTR_RO(status);
136f931551bSRalph Campbell 
137f931551bSRalph Campbell /*
138f931551bSRalph Campbell  * For userland compatibility, these offsets must remain fixed.
139f931551bSRalph Campbell  * They are strings for QIB_STATUS_*
140f931551bSRalph Campbell  */
141865b64beSMike Marciniszyn static const char * const qib_status_str[] = {
142f931551bSRalph Campbell 	"Initted",
143f931551bSRalph Campbell 	"",
144f931551bSRalph Campbell 	"",
145f931551bSRalph Campbell 	"",
146f931551bSRalph Campbell 	"",
147f931551bSRalph Campbell 	"Present",
148f931551bSRalph Campbell 	"IB_link_up",
149f931551bSRalph Campbell 	"IB_configured",
150f931551bSRalph Campbell 	"",
151f931551bSRalph Campbell 	"Fatal_Hardware_Error",
152f931551bSRalph Campbell 	NULL,
153f931551bSRalph Campbell };
154f931551bSRalph Campbell 
155*4a7aaf88SJason Gunthorpe static ssize_t status_str_show(struct ib_device *ibdev, u32 port_num,
156*4a7aaf88SJason Gunthorpe 			       struct ib_port_attribute *attr, char *buf)
157f931551bSRalph Campbell {
158*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
159*4a7aaf88SJason Gunthorpe 	struct qib_pportdata *ppd = &dd->pport[port_num - 1];
160f931551bSRalph Campbell 	int i, any;
161f931551bSRalph Campbell 	u64 s;
162f931551bSRalph Campbell 	ssize_t ret;
163f931551bSRalph Campbell 
164f931551bSRalph Campbell 	if (!ppd->statusp) {
165f931551bSRalph Campbell 		ret = -EINVAL;
166f931551bSRalph Campbell 		goto bail;
167f931551bSRalph Campbell 	}
168f931551bSRalph Campbell 
169f931551bSRalph Campbell 	s = *(ppd->statusp);
170f931551bSRalph Campbell 	*buf = '\0';
171f931551bSRalph Campbell 	for (any = i = 0; s && qib_status_str[i]; i++) {
172f931551bSRalph Campbell 		if (s & 1) {
173f931551bSRalph Campbell 			/* if overflow */
174f931551bSRalph Campbell 			if (any && strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
175f931551bSRalph Campbell 				break;
176f931551bSRalph Campbell 			if (strlcat(buf, qib_status_str[i], PAGE_SIZE) >=
177f931551bSRalph Campbell 					PAGE_SIZE)
178f931551bSRalph Campbell 				break;
179f931551bSRalph Campbell 			any = 1;
180f931551bSRalph Campbell 		}
181f931551bSRalph Campbell 		s >>= 1;
182f931551bSRalph Campbell 	}
183f931551bSRalph Campbell 	if (any)
184f931551bSRalph Campbell 		strlcat(buf, "\n", PAGE_SIZE);
185f931551bSRalph Campbell 
186f931551bSRalph Campbell 	ret = strlen(buf);
187f931551bSRalph Campbell 
188f931551bSRalph Campbell bail:
189f931551bSRalph Campbell 	return ret;
190f931551bSRalph Campbell }
191*4a7aaf88SJason Gunthorpe static IB_PORT_ATTR_RO(status_str);
192f931551bSRalph Campbell 
193f931551bSRalph Campbell /* end of per-port functions */
194f931551bSRalph Campbell 
195*4a7aaf88SJason Gunthorpe static struct attribute *port_linkcontrol_attributes[] = {
196*4a7aaf88SJason Gunthorpe 	&ib_port_attr_loopback.attr,
197*4a7aaf88SJason Gunthorpe 	&ib_port_attr_led_override.attr,
198*4a7aaf88SJason Gunthorpe 	&ib_port_attr_hrtbt_enable.attr,
199*4a7aaf88SJason Gunthorpe 	&ib_port_attr_status.attr,
200*4a7aaf88SJason Gunthorpe 	&ib_port_attr_status_str.attr,
201*4a7aaf88SJason Gunthorpe 	NULL
202f931551bSRalph Campbell };
203f931551bSRalph Campbell 
204*4a7aaf88SJason Gunthorpe static const struct attribute_group port_linkcontrol_group = {
205*4a7aaf88SJason Gunthorpe 	.name = "linkcontrol",
206*4a7aaf88SJason Gunthorpe 	.attrs = port_linkcontrol_attributes,
207f931551bSRalph Campbell };
208f931551bSRalph Campbell 
20936a8f01cSMike Marciniszyn /*
21036a8f01cSMike Marciniszyn  * Start of per-port congestion control structures and support code
21136a8f01cSMike Marciniszyn  */
21236a8f01cSMike Marciniszyn 
21336a8f01cSMike Marciniszyn /*
21436a8f01cSMike Marciniszyn  * Congestion control table size followed by table entries
21536a8f01cSMike Marciniszyn  */
216*4a7aaf88SJason Gunthorpe static ssize_t cc_table_bin_read(struct file *filp, struct kobject *kobj,
217*4a7aaf88SJason Gunthorpe 				 struct bin_attribute *bin_attr, char *buf,
218*4a7aaf88SJason Gunthorpe 				 loff_t pos, size_t count)
21936a8f01cSMike Marciniszyn {
220*4a7aaf88SJason Gunthorpe 	struct qib_pportdata *ppd = qib_get_pportdata_kobj(kobj);
22136a8f01cSMike Marciniszyn 	int ret;
22236a8f01cSMike Marciniszyn 
22336a8f01cSMike Marciniszyn 	if (!qib_cc_table_size || !ppd->ccti_entries_shadow)
22436a8f01cSMike Marciniszyn 		return -EINVAL;
22536a8f01cSMike Marciniszyn 
22636a8f01cSMike Marciniszyn 	ret = ppd->total_cct_entry * sizeof(struct ib_cc_table_entry_shadow)
22736a8f01cSMike Marciniszyn 		 + sizeof(__be16);
22836a8f01cSMike Marciniszyn 
22936a8f01cSMike Marciniszyn 	if (pos > ret)
23036a8f01cSMike Marciniszyn 		return -EINVAL;
23136a8f01cSMike Marciniszyn 
23236a8f01cSMike Marciniszyn 	if (count > ret - pos)
23336a8f01cSMike Marciniszyn 		count = ret - pos;
23436a8f01cSMike Marciniszyn 
23536a8f01cSMike Marciniszyn 	if (!count)
23636a8f01cSMike Marciniszyn 		return count;
23736a8f01cSMike Marciniszyn 
23836a8f01cSMike Marciniszyn 	spin_lock(&ppd->cc_shadow_lock);
23936a8f01cSMike Marciniszyn 	memcpy(buf, ppd->ccti_entries_shadow, count);
24036a8f01cSMike Marciniszyn 	spin_unlock(&ppd->cc_shadow_lock);
24136a8f01cSMike Marciniszyn 
24236a8f01cSMike Marciniszyn 	return count;
24336a8f01cSMike Marciniszyn }
244*4a7aaf88SJason Gunthorpe static BIN_ATTR_RO(cc_table_bin, PAGE_SIZE);
24536a8f01cSMike Marciniszyn 
24636a8f01cSMike Marciniszyn /*
24736a8f01cSMike Marciniszyn  * Congestion settings: port control, control map and an array of 16
24836a8f01cSMike Marciniszyn  * entries for the congestion entries - increase, timer, event log
24936a8f01cSMike Marciniszyn  * trigger threshold and the minimum injection rate delay.
25036a8f01cSMike Marciniszyn  */
251*4a7aaf88SJason Gunthorpe static ssize_t cc_setting_bin_read(struct file *filp, struct kobject *kobj,
252*4a7aaf88SJason Gunthorpe 				   struct bin_attribute *bin_attr, char *buf,
253*4a7aaf88SJason Gunthorpe 				   loff_t pos, size_t count)
25436a8f01cSMike Marciniszyn {
255*4a7aaf88SJason Gunthorpe 	struct qib_pportdata *ppd = qib_get_pportdata_kobj(kobj);
25636a8f01cSMike Marciniszyn 	int ret;
25736a8f01cSMike Marciniszyn 
25836a8f01cSMike Marciniszyn 	if (!qib_cc_table_size || !ppd->congestion_entries_shadow)
25936a8f01cSMike Marciniszyn 		return -EINVAL;
26036a8f01cSMike Marciniszyn 
26136a8f01cSMike Marciniszyn 	ret = sizeof(struct ib_cc_congestion_setting_attr_shadow);
26236a8f01cSMike Marciniszyn 
26336a8f01cSMike Marciniszyn 	if (pos > ret)
26436a8f01cSMike Marciniszyn 		return -EINVAL;
26536a8f01cSMike Marciniszyn 	if (count > ret - pos)
26636a8f01cSMike Marciniszyn 		count = ret - pos;
26736a8f01cSMike Marciniszyn 
26836a8f01cSMike Marciniszyn 	if (!count)
26936a8f01cSMike Marciniszyn 		return count;
27036a8f01cSMike Marciniszyn 
27136a8f01cSMike Marciniszyn 	spin_lock(&ppd->cc_shadow_lock);
27236a8f01cSMike Marciniszyn 	memcpy(buf, ppd->congestion_entries_shadow, count);
27336a8f01cSMike Marciniszyn 	spin_unlock(&ppd->cc_shadow_lock);
27436a8f01cSMike Marciniszyn 
27536a8f01cSMike Marciniszyn 	return count;
27636a8f01cSMike Marciniszyn }
277*4a7aaf88SJason Gunthorpe static BIN_ATTR_RO(cc_setting_bin, PAGE_SIZE);
27836a8f01cSMike Marciniszyn 
279*4a7aaf88SJason Gunthorpe static struct bin_attribute *port_ccmgta_attributes[] = {
280*4a7aaf88SJason Gunthorpe 	&bin_attr_cc_setting_bin,
281*4a7aaf88SJason Gunthorpe 	&bin_attr_cc_table_bin,
282*4a7aaf88SJason Gunthorpe 	NULL,
28336a8f01cSMike Marciniszyn };
28436a8f01cSMike Marciniszyn 
285*4a7aaf88SJason Gunthorpe static umode_t qib_ccmgta_is_bin_visible(struct kobject *kobj,
286*4a7aaf88SJason Gunthorpe 				 struct bin_attribute *attr, int n)
287f931551bSRalph Campbell {
288*4a7aaf88SJason Gunthorpe 	struct qib_pportdata *ppd = qib_get_pportdata_kobj(kobj);
289f931551bSRalph Campbell 
290*4a7aaf88SJason Gunthorpe 	if (!qib_cc_table_size || !ppd->congestion_entries_shadow)
291*4a7aaf88SJason Gunthorpe 		return 0;
292*4a7aaf88SJason Gunthorpe 	return attr->attr.mode;
293f931551bSRalph Campbell }
294f931551bSRalph Campbell 
295*4a7aaf88SJason Gunthorpe static const struct attribute_group port_ccmgta_attribute_group = {
296*4a7aaf88SJason Gunthorpe 	.name = "CCMgtA",
297*4a7aaf88SJason Gunthorpe 	.is_bin_visible = qib_ccmgta_is_bin_visible,
298*4a7aaf88SJason Gunthorpe 	.bin_attrs = port_ccmgta_attributes,
299f931551bSRalph Campbell };
300f931551bSRalph Campbell 
301f931551bSRalph Campbell /* Start sl2vl */
302f931551bSRalph Campbell 
303f931551bSRalph Campbell struct qib_sl2vl_attr {
304*4a7aaf88SJason Gunthorpe 	struct ib_port_attribute attr;
305f931551bSRalph Campbell 	int sl;
306f931551bSRalph Campbell };
307f931551bSRalph Campbell 
308*4a7aaf88SJason Gunthorpe static ssize_t sl2vl_attr_show(struct ib_device *ibdev, u32 port_num,
309*4a7aaf88SJason Gunthorpe 			       struct ib_port_attribute *attr, char *buf)
310*4a7aaf88SJason Gunthorpe {
311*4a7aaf88SJason Gunthorpe 	struct qib_sl2vl_attr *sattr =
312*4a7aaf88SJason Gunthorpe 		container_of(attr, struct qib_sl2vl_attr, attr);
313*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
314*4a7aaf88SJason Gunthorpe 	struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
315*4a7aaf88SJason Gunthorpe 
316*4a7aaf88SJason Gunthorpe 	return sysfs_emit(buf, "%u\n", qibp->sl_to_vl[sattr->sl]);
317*4a7aaf88SJason Gunthorpe }
318*4a7aaf88SJason Gunthorpe 
319*4a7aaf88SJason Gunthorpe #define QIB_SL2VL_ATTR(N)                                                      \
320*4a7aaf88SJason Gunthorpe 	static struct qib_sl2vl_attr qib_sl2vl_attr_##N = {                    \
321*4a7aaf88SJason Gunthorpe 		.attr = __ATTR(N, 0444, sl2vl_attr_show, NULL),                \
322*4a7aaf88SJason Gunthorpe 		.sl = N,                                                       \
323*4a7aaf88SJason Gunthorpe 	}
324*4a7aaf88SJason Gunthorpe 
325f931551bSRalph Campbell QIB_SL2VL_ATTR(0);
326f931551bSRalph Campbell QIB_SL2VL_ATTR(1);
327f931551bSRalph Campbell QIB_SL2VL_ATTR(2);
328f931551bSRalph Campbell QIB_SL2VL_ATTR(3);
329f931551bSRalph Campbell QIB_SL2VL_ATTR(4);
330f931551bSRalph Campbell QIB_SL2VL_ATTR(5);
331f931551bSRalph Campbell QIB_SL2VL_ATTR(6);
332f931551bSRalph Campbell QIB_SL2VL_ATTR(7);
333f931551bSRalph Campbell QIB_SL2VL_ATTR(8);
334f931551bSRalph Campbell QIB_SL2VL_ATTR(9);
335f931551bSRalph Campbell QIB_SL2VL_ATTR(10);
336f931551bSRalph Campbell QIB_SL2VL_ATTR(11);
337f931551bSRalph Campbell QIB_SL2VL_ATTR(12);
338f931551bSRalph Campbell QIB_SL2VL_ATTR(13);
339f931551bSRalph Campbell QIB_SL2VL_ATTR(14);
340f931551bSRalph Campbell QIB_SL2VL_ATTR(15);
341f931551bSRalph Campbell 
342*4a7aaf88SJason Gunthorpe static struct attribute *port_sl2vl_attributes[] = {
343*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_0.attr.attr,
344*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_1.attr.attr,
345*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_2.attr.attr,
346*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_3.attr.attr,
347*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_4.attr.attr,
348*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_5.attr.attr,
349*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_6.attr.attr,
350*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_7.attr.attr,
351*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_8.attr.attr,
352*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_9.attr.attr,
353*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_10.attr.attr,
354*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_11.attr.attr,
355*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_12.attr.attr,
356*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_13.attr.attr,
357*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_14.attr.attr,
358*4a7aaf88SJason Gunthorpe 	&qib_sl2vl_attr_15.attr.attr,
359f931551bSRalph Campbell 	NULL
360f931551bSRalph Campbell };
361f931551bSRalph Campbell 
362*4a7aaf88SJason Gunthorpe static const struct attribute_group port_sl2vl_group = {
363*4a7aaf88SJason Gunthorpe 	.name = "sl2vl",
364*4a7aaf88SJason Gunthorpe 	.attrs = port_sl2vl_attributes,
365f931551bSRalph Campbell };
366f931551bSRalph Campbell 
367f931551bSRalph Campbell /* End sl2vl */
368f931551bSRalph Campbell 
369f931551bSRalph Campbell /* Start diag_counters */
370f931551bSRalph Campbell 
371f931551bSRalph Campbell struct qib_diagc_attr {
372*4a7aaf88SJason Gunthorpe 	struct ib_port_attribute attr;
373f931551bSRalph Campbell 	size_t counter;
374f931551bSRalph Campbell };
375f931551bSRalph Campbell 
376*4a7aaf88SJason Gunthorpe static ssize_t diagc_attr_show(struct ib_device *ibdev, u32 port_num,
377*4a7aaf88SJason Gunthorpe 			       struct ib_port_attribute *attr, char *buf)
378*4a7aaf88SJason Gunthorpe {
379*4a7aaf88SJason Gunthorpe 	struct qib_diagc_attr *dattr =
380*4a7aaf88SJason Gunthorpe 		container_of(attr, struct qib_diagc_attr, attr);
381*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
382*4a7aaf88SJason Gunthorpe 	struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
383*4a7aaf88SJason Gunthorpe 
384*4a7aaf88SJason Gunthorpe 	return sysfs_emit(buf, "%llu\n", *((u64 *)qibp + dattr->counter));
385*4a7aaf88SJason Gunthorpe }
386*4a7aaf88SJason Gunthorpe 
387*4a7aaf88SJason Gunthorpe static ssize_t diagc_attr_store(struct ib_device *ibdev, u32 port_num,
388*4a7aaf88SJason Gunthorpe 				struct ib_port_attribute *attr, const char *buf,
389*4a7aaf88SJason Gunthorpe 				size_t count)
390*4a7aaf88SJason Gunthorpe {
391*4a7aaf88SJason Gunthorpe 	struct qib_diagc_attr *dattr =
392*4a7aaf88SJason Gunthorpe 		container_of(attr, struct qib_diagc_attr, attr);
393*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
394*4a7aaf88SJason Gunthorpe 	struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
395*4a7aaf88SJason Gunthorpe 	u64 val;
396*4a7aaf88SJason Gunthorpe 	int ret;
397*4a7aaf88SJason Gunthorpe 
398*4a7aaf88SJason Gunthorpe 	ret = kstrtou64(buf, 0, &val);
399*4a7aaf88SJason Gunthorpe 	if (ret)
400*4a7aaf88SJason Gunthorpe 		return ret;
401*4a7aaf88SJason Gunthorpe 	*((u64 *)qibp + dattr->counter) = val;
402*4a7aaf88SJason Gunthorpe 	return count;
403*4a7aaf88SJason Gunthorpe }
404*4a7aaf88SJason Gunthorpe 
405*4a7aaf88SJason Gunthorpe #define QIB_DIAGC_ATTR(N)                                                      \
406*4a7aaf88SJason Gunthorpe 	static struct qib_diagc_attr qib_diagc_attr_##N = {                    \
407*4a7aaf88SJason Gunthorpe 		.attr = __ATTR(N, 0664, diagc_attr_show, diagc_attr_store),    \
408*4a7aaf88SJason Gunthorpe 		.counter = &((struct qib_ibport *)0)->rvp.n_##N - (u64 *)0,    \
409*4a7aaf88SJason Gunthorpe 	}
410f24a6d48SHarish Chegondi 
411f931551bSRalph Campbell QIB_DIAGC_ATTR(rc_resends);
412f931551bSRalph Campbell QIB_DIAGC_ATTR(seq_naks);
413f931551bSRalph Campbell QIB_DIAGC_ATTR(rdma_seq);
414f931551bSRalph Campbell QIB_DIAGC_ATTR(rnr_naks);
415f931551bSRalph Campbell QIB_DIAGC_ATTR(other_naks);
416f931551bSRalph Campbell QIB_DIAGC_ATTR(rc_timeouts);
417f931551bSRalph Campbell QIB_DIAGC_ATTR(loop_pkts);
418f931551bSRalph Campbell QIB_DIAGC_ATTR(pkt_drops);
419f931551bSRalph Campbell QIB_DIAGC_ATTR(dmawait);
420f931551bSRalph Campbell QIB_DIAGC_ATTR(unaligned);
421f931551bSRalph Campbell QIB_DIAGC_ATTR(rc_dupreq);
422f931551bSRalph Campbell QIB_DIAGC_ATTR(rc_seqnak);
42371994354SKaike Wan QIB_DIAGC_ATTR(rc_crwaits);
424f931551bSRalph Campbell 
425f24a6d48SHarish Chegondi static u64 get_all_cpu_total(u64 __percpu *cntr)
426f24a6d48SHarish Chegondi {
427f24a6d48SHarish Chegondi 	int cpu;
428f24a6d48SHarish Chegondi 	u64 counter = 0;
429f24a6d48SHarish Chegondi 
430f24a6d48SHarish Chegondi 	for_each_possible_cpu(cpu)
431f24a6d48SHarish Chegondi 		counter += *per_cpu_ptr(cntr, cpu);
432f24a6d48SHarish Chegondi 	return counter;
433f24a6d48SHarish Chegondi }
434f24a6d48SHarish Chegondi 
435*4a7aaf88SJason Gunthorpe static ssize_t qib_store_per_cpu(struct qib_devdata *dd, const char *buf,
436*4a7aaf88SJason Gunthorpe 				 size_t count, u64 *zero, u64 cur)
437f931551bSRalph Campbell {
4387fac3301SMike Marciniszyn 	u32 val;
4397fac3301SMike Marciniszyn 	int ret;
4404c6931f5SIra Weiny 
4417fac3301SMike Marciniszyn 	ret = kstrtou32(buf, 0, &val);
4427fac3301SMike Marciniszyn 	if (ret)
4437fac3301SMike Marciniszyn 		return ret;
444*4a7aaf88SJason Gunthorpe 	if (val != 0) {
445*4a7aaf88SJason Gunthorpe 		qib_dev_err(dd, "Per CPU cntrs can only be zeroed");
446*4a7aaf88SJason Gunthorpe 		return count;
447*4a7aaf88SJason Gunthorpe 	}
448*4a7aaf88SJason Gunthorpe 	*zero = cur;
449*4a7aaf88SJason Gunthorpe 	return count;
4504c6931f5SIra Weiny }
4514c6931f5SIra Weiny 
452*4a7aaf88SJason Gunthorpe static ssize_t rc_acks_show(struct ib_device *ibdev, u32 port_num,
453*4a7aaf88SJason Gunthorpe 			    struct ib_port_attribute *attr, char *buf)
454*4a7aaf88SJason Gunthorpe {
455*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
456*4a7aaf88SJason Gunthorpe 	struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
457*4a7aaf88SJason Gunthorpe 
458*4a7aaf88SJason Gunthorpe 	return sysfs_emit(buf, "%llu\n",
459*4a7aaf88SJason Gunthorpe 			  get_all_cpu_total(qibp->rvp.rc_acks) -
460*4a7aaf88SJason Gunthorpe 				  qibp->rvp.z_rc_acks);
461*4a7aaf88SJason Gunthorpe }
462*4a7aaf88SJason Gunthorpe 
463*4a7aaf88SJason Gunthorpe static ssize_t rc_acks_store(struct ib_device *ibdev, u32 port_num,
464*4a7aaf88SJason Gunthorpe 			     struct ib_port_attribute *attr, const char *buf,
465*4a7aaf88SJason Gunthorpe 			     size_t count)
466*4a7aaf88SJason Gunthorpe {
467*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
468*4a7aaf88SJason Gunthorpe 	struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
469*4a7aaf88SJason Gunthorpe 
470*4a7aaf88SJason Gunthorpe 	return qib_store_per_cpu(dd, buf, count, &qibp->rvp.z_rc_acks,
471*4a7aaf88SJason Gunthorpe 				 get_all_cpu_total(qibp->rvp.rc_acks));
472*4a7aaf88SJason Gunthorpe }
473*4a7aaf88SJason Gunthorpe static IB_PORT_ATTR_RW(rc_acks);
474*4a7aaf88SJason Gunthorpe 
475*4a7aaf88SJason Gunthorpe static ssize_t rc_qacks_show(struct ib_device *ibdev, u32 port_num,
476*4a7aaf88SJason Gunthorpe 			     struct ib_port_attribute *attr, char *buf)
477*4a7aaf88SJason Gunthorpe {
478*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
479*4a7aaf88SJason Gunthorpe 	struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
480*4a7aaf88SJason Gunthorpe 
481*4a7aaf88SJason Gunthorpe 	return sysfs_emit(buf, "%llu\n",
482*4a7aaf88SJason Gunthorpe 			  get_all_cpu_total(qibp->rvp.rc_qacks) -
483*4a7aaf88SJason Gunthorpe 				  qibp->rvp.z_rc_qacks);
484*4a7aaf88SJason Gunthorpe }
485*4a7aaf88SJason Gunthorpe 
486*4a7aaf88SJason Gunthorpe static ssize_t rc_qacks_store(struct ib_device *ibdev, u32 port_num,
487*4a7aaf88SJason Gunthorpe 			      struct ib_port_attribute *attr, const char *buf,
488*4a7aaf88SJason Gunthorpe 			      size_t count)
489*4a7aaf88SJason Gunthorpe {
490*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
491*4a7aaf88SJason Gunthorpe 	struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
492*4a7aaf88SJason Gunthorpe 
493*4a7aaf88SJason Gunthorpe 	return qib_store_per_cpu(dd, buf, count, &qibp->rvp.z_rc_qacks,
494*4a7aaf88SJason Gunthorpe 				 get_all_cpu_total(qibp->rvp.rc_qacks));
495*4a7aaf88SJason Gunthorpe }
496*4a7aaf88SJason Gunthorpe static IB_PORT_ATTR_RW(rc_qacks);
497*4a7aaf88SJason Gunthorpe 
498*4a7aaf88SJason Gunthorpe static ssize_t rc_delayed_comp_show(struct ib_device *ibdev, u32 port_num,
499*4a7aaf88SJason Gunthorpe 				    struct ib_port_attribute *attr, char *buf)
500*4a7aaf88SJason Gunthorpe {
501*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
502*4a7aaf88SJason Gunthorpe 	struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
503*4a7aaf88SJason Gunthorpe 
504*4a7aaf88SJason Gunthorpe 	return sysfs_emit(buf, "%llu\n",
505*4a7aaf88SJason Gunthorpe 			 get_all_cpu_total(qibp->rvp.rc_delayed_comp) -
506*4a7aaf88SJason Gunthorpe 				 qibp->rvp.z_rc_delayed_comp);
507*4a7aaf88SJason Gunthorpe }
508*4a7aaf88SJason Gunthorpe 
509*4a7aaf88SJason Gunthorpe static ssize_t rc_delayed_comp_store(struct ib_device *ibdev, u32 port_num,
510*4a7aaf88SJason Gunthorpe 				     struct ib_port_attribute *attr,
511*4a7aaf88SJason Gunthorpe 				     const char *buf, size_t count)
512*4a7aaf88SJason Gunthorpe {
513*4a7aaf88SJason Gunthorpe 	struct qib_devdata *dd = dd_from_ibdev(ibdev);
514*4a7aaf88SJason Gunthorpe 	struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
515*4a7aaf88SJason Gunthorpe 
516*4a7aaf88SJason Gunthorpe 	return qib_store_per_cpu(dd, buf, count, &qibp->rvp.z_rc_delayed_comp,
517*4a7aaf88SJason Gunthorpe 				 get_all_cpu_total(qibp->rvp.rc_delayed_comp));
518*4a7aaf88SJason Gunthorpe }
519*4a7aaf88SJason Gunthorpe static IB_PORT_ATTR_RW(rc_delayed_comp);
520*4a7aaf88SJason Gunthorpe 
521*4a7aaf88SJason Gunthorpe static struct attribute *port_diagc_attributes[] = {
522*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_rc_resends.attr.attr,
523*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_seq_naks.attr.attr,
524*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_rdma_seq.attr.attr,
525*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_rnr_naks.attr.attr,
526*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_other_naks.attr.attr,
527*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_rc_timeouts.attr.attr,
528*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_loop_pkts.attr.attr,
529*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_pkt_drops.attr.attr,
530*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_dmawait.attr.attr,
531*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_unaligned.attr.attr,
532*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_rc_dupreq.attr.attr,
533*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_rc_seqnak.attr.attr,
534*4a7aaf88SJason Gunthorpe 	&qib_diagc_attr_rc_crwaits.attr.attr,
535*4a7aaf88SJason Gunthorpe 	&ib_port_attr_rc_acks.attr,
536*4a7aaf88SJason Gunthorpe 	&ib_port_attr_rc_qacks.attr,
537*4a7aaf88SJason Gunthorpe 	&ib_port_attr_rc_delayed_comp.attr,
538*4a7aaf88SJason Gunthorpe 	NULL
539f931551bSRalph Campbell };
540f931551bSRalph Campbell 
541*4a7aaf88SJason Gunthorpe static const struct attribute_group port_diagc_group = {
542*4a7aaf88SJason Gunthorpe 	.name = "linkcontrol",
543*4a7aaf88SJason Gunthorpe 	.attrs = port_diagc_attributes,
544f931551bSRalph Campbell };
545f931551bSRalph Campbell 
546f931551bSRalph Campbell /* End diag_counters */
547f931551bSRalph Campbell 
548*4a7aaf88SJason Gunthorpe static const struct attribute_group *qib_port_groups[] = {
549*4a7aaf88SJason Gunthorpe 	&port_linkcontrol_group,
550*4a7aaf88SJason Gunthorpe 	&port_ccmgta_attribute_group,
551*4a7aaf88SJason Gunthorpe 	&port_sl2vl_group,
552*4a7aaf88SJason Gunthorpe 	&port_diagc_group,
553*4a7aaf88SJason Gunthorpe 	NULL,
554*4a7aaf88SJason Gunthorpe };
555*4a7aaf88SJason Gunthorpe 
556f931551bSRalph Campbell /* end of per-port file structures and support code */
557f931551bSRalph Campbell 
558f931551bSRalph Campbell /*
559f931551bSRalph Campbell  * Start of per-unit (or driver, in some cases, but replicated
560f931551bSRalph Campbell  * per unit) functions (these get a device *)
561f931551bSRalph Campbell  */
562508a523fSParav Pandit static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
563f931551bSRalph Campbell 			   char *buf)
564f931551bSRalph Campbell {
565f931551bSRalph Campbell 	struct qib_ibdev *dev =
56654747231SParav Pandit 		rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
567f931551bSRalph Campbell 
5681c7fd726SJoe Perches 	return sysfs_emit(buf, "%x\n", dd_from_dev(dev)->minrev);
569f931551bSRalph Campbell }
570508a523fSParav Pandit static DEVICE_ATTR_RO(hw_rev);
571f931551bSRalph Campbell 
572508a523fSParav Pandit static ssize_t hca_type_show(struct device *device,
573508a523fSParav Pandit 			     struct device_attribute *attr, char *buf)
574f931551bSRalph Campbell {
575f931551bSRalph Campbell 	struct qib_ibdev *dev =
57654747231SParav Pandit 		rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
577f931551bSRalph Campbell 	struct qib_devdata *dd = dd_from_dev(dev);
578f931551bSRalph Campbell 
579f931551bSRalph Campbell 	if (!dd->boardname)
58045808361SJoe Perches 		return -EINVAL;
58145808361SJoe Perches 	return sysfs_emit(buf, "%s\n", dd->boardname);
582f931551bSRalph Campbell }
583508a523fSParav Pandit static DEVICE_ATTR_RO(hca_type);
584508a523fSParav Pandit static DEVICE_ATTR(board_id, 0444, hca_type_show, NULL);
585f931551bSRalph Campbell 
586508a523fSParav Pandit static ssize_t version_show(struct device *device,
587f931551bSRalph Campbell 			    struct device_attribute *attr, char *buf)
588f931551bSRalph Campbell {
589f931551bSRalph Campbell 	/* The string printed here is already newline-terminated. */
5901c7fd726SJoe Perches 	return sysfs_emit(buf, "%s", (char *)ib_qib_version);
591f931551bSRalph Campbell }
592508a523fSParav Pandit static DEVICE_ATTR_RO(version);
593f931551bSRalph Campbell 
594508a523fSParav Pandit static ssize_t boardversion_show(struct device *device,
595f931551bSRalph Campbell 				 struct device_attribute *attr, char *buf)
596f931551bSRalph Campbell {
597f931551bSRalph Campbell 	struct qib_ibdev *dev =
59854747231SParav Pandit 		rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
599f931551bSRalph Campbell 	struct qib_devdata *dd = dd_from_dev(dev);
600f931551bSRalph Campbell 
601f931551bSRalph Campbell 	/* The string printed here is already newline-terminated. */
6021c7fd726SJoe Perches 	return sysfs_emit(buf, "%s", dd->boardversion);
603f931551bSRalph Campbell }
604508a523fSParav Pandit static DEVICE_ATTR_RO(boardversion);
605f931551bSRalph Campbell 
606508a523fSParav Pandit static ssize_t localbus_info_show(struct device *device,
607f931551bSRalph Campbell 				  struct device_attribute *attr, char *buf)
608f931551bSRalph Campbell {
609f931551bSRalph Campbell 	struct qib_ibdev *dev =
61054747231SParav Pandit 		rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
611f931551bSRalph Campbell 	struct qib_devdata *dd = dd_from_dev(dev);
612f931551bSRalph Campbell 
613f931551bSRalph Campbell 	/* The string printed here is already newline-terminated. */
6141c7fd726SJoe Perches 	return sysfs_emit(buf, "%s", dd->lbus_info);
615f931551bSRalph Campbell }
616508a523fSParav Pandit static DEVICE_ATTR_RO(localbus_info);
617f931551bSRalph Campbell 
618508a523fSParav Pandit static ssize_t nctxts_show(struct device *device,
619f931551bSRalph Campbell 			   struct device_attribute *attr, char *buf)
620f931551bSRalph Campbell {
621f931551bSRalph Campbell 	struct qib_ibdev *dev =
62254747231SParav Pandit 		rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
623f931551bSRalph Campbell 	struct qib_devdata *dd = dd_from_dev(dev);
624f931551bSRalph Campbell 
625f931551bSRalph Campbell 	/* Return the number of user ports (contexts) available. */
6266ceaadeeSMitko Haralanov 	/* The calculation below deals with a special case where
6276ceaadeeSMitko Haralanov 	 * cfgctxts is set to 1 on a single-port board. */
6281c7fd726SJoe Perches 	return sysfs_emit(buf, "%u\n",
6291c7fd726SJoe Perches 			  (dd->first_user_ctxt > dd->cfgctxts) ?
6301c7fd726SJoe Perches 				  0 :
6316ceaadeeSMitko Haralanov 				  (dd->cfgctxts - dd->first_user_ctxt));
632f931551bSRalph Campbell }
633508a523fSParav Pandit static DEVICE_ATTR_RO(nctxts);
634f931551bSRalph Campbell 
635508a523fSParav Pandit static ssize_t nfreectxts_show(struct device *device,
6362df4f757SRam Vepa 			       struct device_attribute *attr, char *buf)
6372df4f757SRam Vepa {
6382df4f757SRam Vepa 	struct qib_ibdev *dev =
63954747231SParav Pandit 		rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
6402df4f757SRam Vepa 	struct qib_devdata *dd = dd_from_dev(dev);
6412df4f757SRam Vepa 
6422df4f757SRam Vepa 	/* Return the number of free user ports (contexts) available. */
6431c7fd726SJoe Perches 	return sysfs_emit(buf, "%u\n", dd->freectxts);
6442df4f757SRam Vepa }
645508a523fSParav Pandit static DEVICE_ATTR_RO(nfreectxts);
6462df4f757SRam Vepa 
64745808361SJoe Perches static ssize_t serial_show(struct device *device, struct device_attribute *attr,
64845808361SJoe Perches 			   char *buf)
649f931551bSRalph Campbell {
650f931551bSRalph Campbell 	struct qib_ibdev *dev =
65154747231SParav Pandit 		rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
652f931551bSRalph Campbell 	struct qib_devdata *dd = dd_from_dev(dev);
65345808361SJoe Perches 	const u8 *end = memchr(dd->serial, 0, ARRAY_SIZE(dd->serial));
65445808361SJoe Perches 	int size = end ? end - dd->serial : ARRAY_SIZE(dd->serial);
655f931551bSRalph Campbell 
65645808361SJoe Perches 	return sysfs_emit(buf, ".%*s\n", size, dd->serial);
657f931551bSRalph Campbell }
658508a523fSParav Pandit static DEVICE_ATTR_RO(serial);
659f931551bSRalph Campbell 
660508a523fSParav Pandit static ssize_t chip_reset_store(struct device *device,
661f931551bSRalph Campbell 				struct device_attribute *attr, const char *buf,
662f931551bSRalph Campbell 				size_t count)
663f931551bSRalph Campbell {
664f931551bSRalph Campbell 	struct qib_ibdev *dev =
66554747231SParav Pandit 		rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
666f931551bSRalph Campbell 	struct qib_devdata *dd = dd_from_dev(dev);
667f931551bSRalph Campbell 	int ret;
668f931551bSRalph Campbell 
669f931551bSRalph Campbell 	if (count < 5 || memcmp(buf, "reset", 5) || !dd->diag_client) {
670f931551bSRalph Campbell 		ret = -EINVAL;
671f931551bSRalph Campbell 		goto bail;
672f931551bSRalph Campbell 	}
673f931551bSRalph Campbell 
674f931551bSRalph Campbell 	ret = qib_reset_device(dd->unit);
675f931551bSRalph Campbell bail:
676f931551bSRalph Campbell 	return ret < 0 ? ret : count;
677f931551bSRalph Campbell }
678508a523fSParav Pandit static DEVICE_ATTR_WO(chip_reset);
679f931551bSRalph Campbell 
680f931551bSRalph Campbell /*
681f931551bSRalph Campbell  * Dump tempsense regs. in decimal, to ease shell-scripts.
682f931551bSRalph Campbell  */
683508a523fSParav Pandit static ssize_t tempsense_show(struct device *device,
684f931551bSRalph Campbell 			      struct device_attribute *attr, char *buf)
685f931551bSRalph Campbell {
686f931551bSRalph Campbell 	struct qib_ibdev *dev =
68754747231SParav Pandit 		rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
688f931551bSRalph Campbell 	struct qib_devdata *dd = dd_from_dev(dev);
68945808361SJoe Perches 	int i;
690f931551bSRalph Campbell 	u8 regvals[8];
691f931551bSRalph Campbell 
69245808361SJoe Perches 	for (i = 0; i < 8; i++) {
69345808361SJoe Perches 		int ret;
69445808361SJoe Perches 
69545808361SJoe Perches 		if (i == 6)
696f931551bSRalph Campbell 			continue;
69745808361SJoe Perches 		ret = dd->f_tempsense_rd(dd, i);
698f931551bSRalph Campbell 		if (ret < 0)
69945808361SJoe Perches 			return ret;	/* return error on bad read */
70045808361SJoe Perches 		regvals[i] = ret;
701f931551bSRalph Campbell 	}
70245808361SJoe Perches 	return sysfs_emit(buf, "%d %d %02X %02X %d %d\n",
70345808361SJoe Perches 			  (signed char)regvals[0],
70445808361SJoe Perches 			  (signed char)regvals[1],
70545808361SJoe Perches 			  regvals[2],
70645808361SJoe Perches 			  regvals[3],
70745808361SJoe Perches 			  (signed char)regvals[5],
70845808361SJoe Perches 			  (signed char)regvals[7]);
709f931551bSRalph Campbell }
710508a523fSParav Pandit static DEVICE_ATTR_RO(tempsense);
711f931551bSRalph Campbell 
712f931551bSRalph Campbell /*
713f931551bSRalph Campbell  * end of per-unit (or driver, in some cases, but replicated
714f931551bSRalph Campbell  * per unit) functions
715f931551bSRalph Campbell  */
716f931551bSRalph Campbell 
717f931551bSRalph Campbell /* start of per-unit file structures and support code */
718508a523fSParav Pandit static struct attribute *qib_attributes[] = {
719508a523fSParav Pandit 	&dev_attr_hw_rev.attr,
720508a523fSParav Pandit 	&dev_attr_hca_type.attr,
721508a523fSParav Pandit 	&dev_attr_board_id.attr,
722508a523fSParav Pandit 	&dev_attr_version.attr,
723508a523fSParav Pandit 	&dev_attr_nctxts.attr,
724508a523fSParav Pandit 	&dev_attr_nfreectxts.attr,
725508a523fSParav Pandit 	&dev_attr_serial.attr,
726508a523fSParav Pandit 	&dev_attr_boardversion.attr,
727508a523fSParav Pandit 	&dev_attr_tempsense.attr,
728508a523fSParav Pandit 	&dev_attr_localbus_info.attr,
729508a523fSParav Pandit 	&dev_attr_chip_reset.attr,
730508a523fSParav Pandit 	NULL,
731508a523fSParav Pandit };
732f931551bSRalph Campbell 
733508a523fSParav Pandit const struct attribute_group qib_attr_group = {
734508a523fSParav Pandit 	.attrs = qib_attributes,
735f931551bSRalph Campbell };
736f931551bSRalph Campbell 
7371fb7f897SMark Bloch int qib_create_port_files(struct ib_device *ibdev, u32 port_num,
738f931551bSRalph Campbell 			  struct kobject *kobj)
739f931551bSRalph Campbell {
740*4a7aaf88SJason Gunthorpe 	return ib_port_sysfs_create_groups(ibdev, port_num, qib_port_groups);
741f931551bSRalph Campbell }
742f931551bSRalph Campbell 
743f931551bSRalph Campbell /*
744f931551bSRalph Campbell  * Unregister and remove our files in /sys/class/infiniband.
745f931551bSRalph Campbell  */
746f931551bSRalph Campbell void qib_verbs_unregister_sysfs(struct qib_devdata *dd)
747f931551bSRalph Campbell {
748f931551bSRalph Campbell 	int i;
749f931551bSRalph Campbell 
750*4a7aaf88SJason Gunthorpe 	for (i = 0; i < dd->num_pports; i++)
751*4a7aaf88SJason Gunthorpe 		ib_port_sysfs_remove_groups(&dd->verbs_dev.rdi.ibdev, i,
752*4a7aaf88SJason Gunthorpe 					    qib_port_groups);
753f931551bSRalph Campbell }
754