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>
354a7aaf88SJason Gunthorpe #include <rdma/ib_sysfs.h>
36f931551bSRalph Campbell
37f931551bSRalph Campbell #include "qib.h"
3836a8f01cSMike Marciniszyn #include "qib_mad.h"
39f931551bSRalph Campbell
qib_get_pportdata_kobj(struct kobject * kobj)404a7aaf88SJason Gunthorpe static struct qib_pportdata *qib_get_pportdata_kobj(struct kobject *kobj)
414a7aaf88SJason Gunthorpe {
424a7aaf88SJason Gunthorpe u32 port_num;
434a7aaf88SJason Gunthorpe struct ib_device *ibdev = ib_port_sysfs_get_ibdev_kobj(kobj, &port_num);
444a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
454a7aaf88SJason Gunthorpe
464a7aaf88SJason Gunthorpe return &dd->pport[port_num - 1];
474a7aaf88SJason Gunthorpe }
484a7aaf88SJason Gunthorpe
49f931551bSRalph Campbell /*
50f931551bSRalph Campbell * Get/Set heartbeat enable. OR of 1=enabled, 2=auto
51f931551bSRalph Campbell */
hrtbt_enable_show(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,char * buf)524a7aaf88SJason Gunthorpe static ssize_t hrtbt_enable_show(struct ib_device *ibdev, u32 port_num,
534a7aaf88SJason Gunthorpe struct ib_port_attribute *attr, char *buf)
54f931551bSRalph Campbell {
554a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
564a7aaf88SJason 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
hrtbt_enable_store(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,const char * buf,size_t count)614a7aaf88SJason Gunthorpe static ssize_t hrtbt_enable_store(struct ib_device *ibdev, u32 port_num,
624a7aaf88SJason Gunthorpe struct ib_port_attribute *attr,
634a7aaf88SJason Gunthorpe const char *buf, size_t count)
64f931551bSRalph Campbell {
654a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
664a7aaf88SJason 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 }
864a7aaf88SJason Gunthorpe static IB_PORT_ATTR_RW(hrtbt_enable);
87f931551bSRalph Campbell
loopback_store(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,const char * buf,size_t count)884a7aaf88SJason Gunthorpe static ssize_t loopback_store(struct ib_device *ibdev, u32 port_num,
894a7aaf88SJason Gunthorpe struct ib_port_attribute *attr, const char *buf,
90f931551bSRalph Campbell size_t count)
91f931551bSRalph Campbell {
924a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
934a7aaf88SJason 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 }
1024a7aaf88SJason Gunthorpe static IB_PORT_ATTR_WO(loopback);
103f931551bSRalph Campbell
led_override_store(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,const char * buf,size_t count)1044a7aaf88SJason Gunthorpe static ssize_t led_override_store(struct ib_device *ibdev, u32 port_num,
1054a7aaf88SJason Gunthorpe struct ib_port_attribute *attr,
1064a7aaf88SJason Gunthorpe const char *buf, size_t count)
107f931551bSRalph Campbell {
1084a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
1094a7aaf88SJason 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 }
1224a7aaf88SJason Gunthorpe static IB_PORT_ATTR_WO(led_override);
123f931551bSRalph Campbell
status_show(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,char * buf)1244a7aaf88SJason Gunthorpe static ssize_t status_show(struct ib_device *ibdev, u32 port_num,
1254a7aaf88SJason Gunthorpe struct ib_port_attribute *attr, char *buf)
126f931551bSRalph Campbell {
1274a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
1284a7aaf88SJason Gunthorpe struct qib_pportdata *ppd = &dd->pport[port_num - 1];
1294a7aaf88SJason 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 }
1354a7aaf88SJason 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
status_str_show(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,char * buf)1554a7aaf88SJason Gunthorpe static ssize_t status_str_show(struct ib_device *ibdev, u32 port_num,
1564a7aaf88SJason Gunthorpe struct ib_port_attribute *attr, char *buf)
157f931551bSRalph Campbell {
1584a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
1594a7aaf88SJason 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 }
1914a7aaf88SJason Gunthorpe static IB_PORT_ATTR_RO(status_str);
192f931551bSRalph Campbell
193f931551bSRalph Campbell /* end of per-port functions */
194f931551bSRalph Campbell
1954a7aaf88SJason Gunthorpe static struct attribute *port_linkcontrol_attributes[] = {
1964a7aaf88SJason Gunthorpe &ib_port_attr_loopback.attr,
1974a7aaf88SJason Gunthorpe &ib_port_attr_led_override.attr,
1984a7aaf88SJason Gunthorpe &ib_port_attr_hrtbt_enable.attr,
1994a7aaf88SJason Gunthorpe &ib_port_attr_status.attr,
2004a7aaf88SJason Gunthorpe &ib_port_attr_status_str.attr,
2014a7aaf88SJason Gunthorpe NULL
202f931551bSRalph Campbell };
203f931551bSRalph Campbell
2044a7aaf88SJason Gunthorpe static const struct attribute_group port_linkcontrol_group = {
2054a7aaf88SJason Gunthorpe .name = "linkcontrol",
2064a7aaf88SJason 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 */
cc_table_bin_read(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t pos,size_t count)2164a7aaf88SJason Gunthorpe static ssize_t cc_table_bin_read(struct file *filp, struct kobject *kobj,
2174a7aaf88SJason Gunthorpe struct bin_attribute *bin_attr, char *buf,
2184a7aaf88SJason Gunthorpe loff_t pos, size_t count)
21936a8f01cSMike Marciniszyn {
2204a7aaf88SJason 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 }
2444a7aaf88SJason 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 */
cc_setting_bin_read(struct file * filp,struct kobject * kobj,struct bin_attribute * bin_attr,char * buf,loff_t pos,size_t count)2514a7aaf88SJason Gunthorpe static ssize_t cc_setting_bin_read(struct file *filp, struct kobject *kobj,
2524a7aaf88SJason Gunthorpe struct bin_attribute *bin_attr, char *buf,
2534a7aaf88SJason Gunthorpe loff_t pos, size_t count)
25436a8f01cSMike Marciniszyn {
2554a7aaf88SJason 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 }
2774a7aaf88SJason Gunthorpe static BIN_ATTR_RO(cc_setting_bin, PAGE_SIZE);
27836a8f01cSMike Marciniszyn
2794a7aaf88SJason Gunthorpe static struct bin_attribute *port_ccmgta_attributes[] = {
2804a7aaf88SJason Gunthorpe &bin_attr_cc_setting_bin,
2814a7aaf88SJason Gunthorpe &bin_attr_cc_table_bin,
2824a7aaf88SJason Gunthorpe NULL,
28336a8f01cSMike Marciniszyn };
28436a8f01cSMike Marciniszyn
qib_ccmgta_is_bin_visible(struct kobject * kobj,struct bin_attribute * attr,int n)2854a7aaf88SJason Gunthorpe static umode_t qib_ccmgta_is_bin_visible(struct kobject *kobj,
2864a7aaf88SJason Gunthorpe struct bin_attribute *attr, int n)
287f931551bSRalph Campbell {
2884a7aaf88SJason Gunthorpe struct qib_pportdata *ppd = qib_get_pportdata_kobj(kobj);
289f931551bSRalph Campbell
2904a7aaf88SJason Gunthorpe if (!qib_cc_table_size || !ppd->congestion_entries_shadow)
2914a7aaf88SJason Gunthorpe return 0;
2924a7aaf88SJason Gunthorpe return attr->attr.mode;
293f931551bSRalph Campbell }
294f931551bSRalph Campbell
2954a7aaf88SJason Gunthorpe static const struct attribute_group port_ccmgta_attribute_group = {
2964a7aaf88SJason Gunthorpe .name = "CCMgtA",
2974a7aaf88SJason Gunthorpe .is_bin_visible = qib_ccmgta_is_bin_visible,
2984a7aaf88SJason Gunthorpe .bin_attrs = port_ccmgta_attributes,
299f931551bSRalph Campbell };
300f931551bSRalph Campbell
301f931551bSRalph Campbell /* Start sl2vl */
302f931551bSRalph Campbell
303f931551bSRalph Campbell struct qib_sl2vl_attr {
3044a7aaf88SJason Gunthorpe struct ib_port_attribute attr;
305f931551bSRalph Campbell int sl;
306f931551bSRalph Campbell };
307f931551bSRalph Campbell
sl2vl_attr_show(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,char * buf)3084a7aaf88SJason Gunthorpe static ssize_t sl2vl_attr_show(struct ib_device *ibdev, u32 port_num,
3094a7aaf88SJason Gunthorpe struct ib_port_attribute *attr, char *buf)
3104a7aaf88SJason Gunthorpe {
3114a7aaf88SJason Gunthorpe struct qib_sl2vl_attr *sattr =
3124a7aaf88SJason Gunthorpe container_of(attr, struct qib_sl2vl_attr, attr);
3134a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
3144a7aaf88SJason Gunthorpe struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
3154a7aaf88SJason Gunthorpe
3164a7aaf88SJason Gunthorpe return sysfs_emit(buf, "%u\n", qibp->sl_to_vl[sattr->sl]);
3174a7aaf88SJason Gunthorpe }
3184a7aaf88SJason Gunthorpe
3194a7aaf88SJason Gunthorpe #define QIB_SL2VL_ATTR(N) \
3204a7aaf88SJason Gunthorpe static struct qib_sl2vl_attr qib_sl2vl_attr_##N = { \
3214a7aaf88SJason Gunthorpe .attr = __ATTR(N, 0444, sl2vl_attr_show, NULL), \
3224a7aaf88SJason Gunthorpe .sl = N, \
3234a7aaf88SJason Gunthorpe }
3244a7aaf88SJason 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
3424a7aaf88SJason Gunthorpe static struct attribute *port_sl2vl_attributes[] = {
3434a7aaf88SJason Gunthorpe &qib_sl2vl_attr_0.attr.attr,
3444a7aaf88SJason Gunthorpe &qib_sl2vl_attr_1.attr.attr,
3454a7aaf88SJason Gunthorpe &qib_sl2vl_attr_2.attr.attr,
3464a7aaf88SJason Gunthorpe &qib_sl2vl_attr_3.attr.attr,
3474a7aaf88SJason Gunthorpe &qib_sl2vl_attr_4.attr.attr,
3484a7aaf88SJason Gunthorpe &qib_sl2vl_attr_5.attr.attr,
3494a7aaf88SJason Gunthorpe &qib_sl2vl_attr_6.attr.attr,
3504a7aaf88SJason Gunthorpe &qib_sl2vl_attr_7.attr.attr,
3514a7aaf88SJason Gunthorpe &qib_sl2vl_attr_8.attr.attr,
3524a7aaf88SJason Gunthorpe &qib_sl2vl_attr_9.attr.attr,
3534a7aaf88SJason Gunthorpe &qib_sl2vl_attr_10.attr.attr,
3544a7aaf88SJason Gunthorpe &qib_sl2vl_attr_11.attr.attr,
3554a7aaf88SJason Gunthorpe &qib_sl2vl_attr_12.attr.attr,
3564a7aaf88SJason Gunthorpe &qib_sl2vl_attr_13.attr.attr,
3574a7aaf88SJason Gunthorpe &qib_sl2vl_attr_14.attr.attr,
3584a7aaf88SJason Gunthorpe &qib_sl2vl_attr_15.attr.attr,
359f931551bSRalph Campbell NULL
360f931551bSRalph Campbell };
361f931551bSRalph Campbell
3624a7aaf88SJason Gunthorpe static const struct attribute_group port_sl2vl_group = {
3634a7aaf88SJason Gunthorpe .name = "sl2vl",
3644a7aaf88SJason 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 {
3724a7aaf88SJason Gunthorpe struct ib_port_attribute attr;
373f931551bSRalph Campbell size_t counter;
374f931551bSRalph Campbell };
375f931551bSRalph Campbell
diagc_attr_show(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,char * buf)3764a7aaf88SJason Gunthorpe static ssize_t diagc_attr_show(struct ib_device *ibdev, u32 port_num,
3774a7aaf88SJason Gunthorpe struct ib_port_attribute *attr, char *buf)
3784a7aaf88SJason Gunthorpe {
3794a7aaf88SJason Gunthorpe struct qib_diagc_attr *dattr =
3804a7aaf88SJason Gunthorpe container_of(attr, struct qib_diagc_attr, attr);
3814a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
3824a7aaf88SJason Gunthorpe struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
3834a7aaf88SJason Gunthorpe
3844a7aaf88SJason Gunthorpe return sysfs_emit(buf, "%llu\n", *((u64 *)qibp + dattr->counter));
3854a7aaf88SJason Gunthorpe }
3864a7aaf88SJason Gunthorpe
diagc_attr_store(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,const char * buf,size_t count)3874a7aaf88SJason Gunthorpe static ssize_t diagc_attr_store(struct ib_device *ibdev, u32 port_num,
3884a7aaf88SJason Gunthorpe struct ib_port_attribute *attr, const char *buf,
3894a7aaf88SJason Gunthorpe size_t count)
3904a7aaf88SJason Gunthorpe {
3914a7aaf88SJason Gunthorpe struct qib_diagc_attr *dattr =
3924a7aaf88SJason Gunthorpe container_of(attr, struct qib_diagc_attr, attr);
3934a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
3944a7aaf88SJason Gunthorpe struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
3954a7aaf88SJason Gunthorpe u64 val;
3964a7aaf88SJason Gunthorpe int ret;
3974a7aaf88SJason Gunthorpe
3984a7aaf88SJason Gunthorpe ret = kstrtou64(buf, 0, &val);
3994a7aaf88SJason Gunthorpe if (ret)
4004a7aaf88SJason Gunthorpe return ret;
4014a7aaf88SJason Gunthorpe *((u64 *)qibp + dattr->counter) = val;
4024a7aaf88SJason Gunthorpe return count;
4034a7aaf88SJason Gunthorpe }
4044a7aaf88SJason Gunthorpe
4054a7aaf88SJason Gunthorpe #define QIB_DIAGC_ATTR(N) \
4063110b942SJason Gunthorpe static_assert(__same_type(((struct qib_ibport *)0)->rvp.n_##N, u64)); \
4074a7aaf88SJason Gunthorpe static struct qib_diagc_attr qib_diagc_attr_##N = { \
4084a7aaf88SJason Gunthorpe .attr = __ATTR(N, 0664, diagc_attr_show, diagc_attr_store), \
40984f969e1SJason Gunthorpe .counter = \
41084f969e1SJason Gunthorpe offsetof(struct qib_ibport, rvp.n_##N) / sizeof(u64) \
4114a7aaf88SJason Gunthorpe }
412f24a6d48SHarish Chegondi
413f931551bSRalph Campbell QIB_DIAGC_ATTR(rc_resends);
414f931551bSRalph Campbell QIB_DIAGC_ATTR(seq_naks);
415f931551bSRalph Campbell QIB_DIAGC_ATTR(rdma_seq);
416f931551bSRalph Campbell QIB_DIAGC_ATTR(rnr_naks);
417f931551bSRalph Campbell QIB_DIAGC_ATTR(other_naks);
418f931551bSRalph Campbell QIB_DIAGC_ATTR(rc_timeouts);
419f931551bSRalph Campbell QIB_DIAGC_ATTR(loop_pkts);
420f931551bSRalph Campbell QIB_DIAGC_ATTR(pkt_drops);
421f931551bSRalph Campbell QIB_DIAGC_ATTR(dmawait);
422f931551bSRalph Campbell QIB_DIAGC_ATTR(unaligned);
423f931551bSRalph Campbell QIB_DIAGC_ATTR(rc_dupreq);
424f931551bSRalph Campbell QIB_DIAGC_ATTR(rc_seqnak);
42571994354SKaike Wan QIB_DIAGC_ATTR(rc_crwaits);
426f931551bSRalph Campbell
get_all_cpu_total(u64 __percpu * cntr)427f24a6d48SHarish Chegondi static u64 get_all_cpu_total(u64 __percpu *cntr)
428f24a6d48SHarish Chegondi {
429f24a6d48SHarish Chegondi int cpu;
430f24a6d48SHarish Chegondi u64 counter = 0;
431f24a6d48SHarish Chegondi
432f24a6d48SHarish Chegondi for_each_possible_cpu(cpu)
433f24a6d48SHarish Chegondi counter += *per_cpu_ptr(cntr, cpu);
434f24a6d48SHarish Chegondi return counter;
435f24a6d48SHarish Chegondi }
436f24a6d48SHarish Chegondi
qib_store_per_cpu(struct qib_devdata * dd,const char * buf,size_t count,u64 * zero,u64 cur)4374a7aaf88SJason Gunthorpe static ssize_t qib_store_per_cpu(struct qib_devdata *dd, const char *buf,
4384a7aaf88SJason Gunthorpe size_t count, u64 *zero, u64 cur)
439f931551bSRalph Campbell {
4407fac3301SMike Marciniszyn u32 val;
4417fac3301SMike Marciniszyn int ret;
4424c6931f5SIra Weiny
4437fac3301SMike Marciniszyn ret = kstrtou32(buf, 0, &val);
4447fac3301SMike Marciniszyn if (ret)
4457fac3301SMike Marciniszyn return ret;
4464a7aaf88SJason Gunthorpe if (val != 0) {
4474a7aaf88SJason Gunthorpe qib_dev_err(dd, "Per CPU cntrs can only be zeroed");
4484a7aaf88SJason Gunthorpe return count;
4494a7aaf88SJason Gunthorpe }
4504a7aaf88SJason Gunthorpe *zero = cur;
4514a7aaf88SJason Gunthorpe return count;
4524c6931f5SIra Weiny }
4534c6931f5SIra Weiny
rc_acks_show(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,char * buf)4544a7aaf88SJason Gunthorpe static ssize_t rc_acks_show(struct ib_device *ibdev, u32 port_num,
4554a7aaf88SJason Gunthorpe struct ib_port_attribute *attr, char *buf)
4564a7aaf88SJason Gunthorpe {
4574a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
4584a7aaf88SJason Gunthorpe struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
4594a7aaf88SJason Gunthorpe
4604a7aaf88SJason Gunthorpe return sysfs_emit(buf, "%llu\n",
4614a7aaf88SJason Gunthorpe get_all_cpu_total(qibp->rvp.rc_acks) -
4624a7aaf88SJason Gunthorpe qibp->rvp.z_rc_acks);
4634a7aaf88SJason Gunthorpe }
4644a7aaf88SJason Gunthorpe
rc_acks_store(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,const char * buf,size_t count)4654a7aaf88SJason Gunthorpe static ssize_t rc_acks_store(struct ib_device *ibdev, u32 port_num,
4664a7aaf88SJason Gunthorpe struct ib_port_attribute *attr, const char *buf,
4674a7aaf88SJason Gunthorpe size_t count)
4684a7aaf88SJason Gunthorpe {
4694a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
4704a7aaf88SJason Gunthorpe struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
4714a7aaf88SJason Gunthorpe
4724a7aaf88SJason Gunthorpe return qib_store_per_cpu(dd, buf, count, &qibp->rvp.z_rc_acks,
4734a7aaf88SJason Gunthorpe get_all_cpu_total(qibp->rvp.rc_acks));
4744a7aaf88SJason Gunthorpe }
4754a7aaf88SJason Gunthorpe static IB_PORT_ATTR_RW(rc_acks);
4764a7aaf88SJason Gunthorpe
rc_qacks_show(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,char * buf)4774a7aaf88SJason Gunthorpe static ssize_t rc_qacks_show(struct ib_device *ibdev, u32 port_num,
4784a7aaf88SJason Gunthorpe struct ib_port_attribute *attr, char *buf)
4794a7aaf88SJason Gunthorpe {
4804a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
4814a7aaf88SJason Gunthorpe struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
4824a7aaf88SJason Gunthorpe
4834a7aaf88SJason Gunthorpe return sysfs_emit(buf, "%llu\n",
4844a7aaf88SJason Gunthorpe get_all_cpu_total(qibp->rvp.rc_qacks) -
4854a7aaf88SJason Gunthorpe qibp->rvp.z_rc_qacks);
4864a7aaf88SJason Gunthorpe }
4874a7aaf88SJason Gunthorpe
rc_qacks_store(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,const char * buf,size_t count)4884a7aaf88SJason Gunthorpe static ssize_t rc_qacks_store(struct ib_device *ibdev, u32 port_num,
4894a7aaf88SJason Gunthorpe struct ib_port_attribute *attr, const char *buf,
4904a7aaf88SJason Gunthorpe size_t count)
4914a7aaf88SJason Gunthorpe {
4924a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
4934a7aaf88SJason Gunthorpe struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
4944a7aaf88SJason Gunthorpe
4954a7aaf88SJason Gunthorpe return qib_store_per_cpu(dd, buf, count, &qibp->rvp.z_rc_qacks,
4964a7aaf88SJason Gunthorpe get_all_cpu_total(qibp->rvp.rc_qacks));
4974a7aaf88SJason Gunthorpe }
4984a7aaf88SJason Gunthorpe static IB_PORT_ATTR_RW(rc_qacks);
4994a7aaf88SJason Gunthorpe
rc_delayed_comp_show(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,char * buf)5004a7aaf88SJason Gunthorpe static ssize_t rc_delayed_comp_show(struct ib_device *ibdev, u32 port_num,
5014a7aaf88SJason Gunthorpe struct ib_port_attribute *attr, char *buf)
5024a7aaf88SJason Gunthorpe {
5034a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
5044a7aaf88SJason Gunthorpe struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
5054a7aaf88SJason Gunthorpe
5064a7aaf88SJason Gunthorpe return sysfs_emit(buf, "%llu\n",
5074a7aaf88SJason Gunthorpe get_all_cpu_total(qibp->rvp.rc_delayed_comp) -
5084a7aaf88SJason Gunthorpe qibp->rvp.z_rc_delayed_comp);
5094a7aaf88SJason Gunthorpe }
5104a7aaf88SJason Gunthorpe
rc_delayed_comp_store(struct ib_device * ibdev,u32 port_num,struct ib_port_attribute * attr,const char * buf,size_t count)5114a7aaf88SJason Gunthorpe static ssize_t rc_delayed_comp_store(struct ib_device *ibdev, u32 port_num,
5124a7aaf88SJason Gunthorpe struct ib_port_attribute *attr,
5134a7aaf88SJason Gunthorpe const char *buf, size_t count)
5144a7aaf88SJason Gunthorpe {
5154a7aaf88SJason Gunthorpe struct qib_devdata *dd = dd_from_ibdev(ibdev);
5164a7aaf88SJason Gunthorpe struct qib_ibport *qibp = &dd->pport[port_num - 1].ibport_data;
5174a7aaf88SJason Gunthorpe
5184a7aaf88SJason Gunthorpe return qib_store_per_cpu(dd, buf, count, &qibp->rvp.z_rc_delayed_comp,
5194a7aaf88SJason Gunthorpe get_all_cpu_total(qibp->rvp.rc_delayed_comp));
5204a7aaf88SJason Gunthorpe }
5214a7aaf88SJason Gunthorpe static IB_PORT_ATTR_RW(rc_delayed_comp);
5224a7aaf88SJason Gunthorpe
5234a7aaf88SJason Gunthorpe static struct attribute *port_diagc_attributes[] = {
5244a7aaf88SJason Gunthorpe &qib_diagc_attr_rc_resends.attr.attr,
5254a7aaf88SJason Gunthorpe &qib_diagc_attr_seq_naks.attr.attr,
5264a7aaf88SJason Gunthorpe &qib_diagc_attr_rdma_seq.attr.attr,
5274a7aaf88SJason Gunthorpe &qib_diagc_attr_rnr_naks.attr.attr,
5284a7aaf88SJason Gunthorpe &qib_diagc_attr_other_naks.attr.attr,
5294a7aaf88SJason Gunthorpe &qib_diagc_attr_rc_timeouts.attr.attr,
5304a7aaf88SJason Gunthorpe &qib_diagc_attr_loop_pkts.attr.attr,
5314a7aaf88SJason Gunthorpe &qib_diagc_attr_pkt_drops.attr.attr,
5324a7aaf88SJason Gunthorpe &qib_diagc_attr_dmawait.attr.attr,
5334a7aaf88SJason Gunthorpe &qib_diagc_attr_unaligned.attr.attr,
5344a7aaf88SJason Gunthorpe &qib_diagc_attr_rc_dupreq.attr.attr,
5354a7aaf88SJason Gunthorpe &qib_diagc_attr_rc_seqnak.attr.attr,
5364a7aaf88SJason Gunthorpe &qib_diagc_attr_rc_crwaits.attr.attr,
5374a7aaf88SJason Gunthorpe &ib_port_attr_rc_acks.attr,
5384a7aaf88SJason Gunthorpe &ib_port_attr_rc_qacks.attr,
5394a7aaf88SJason Gunthorpe &ib_port_attr_rc_delayed_comp.attr,
5404a7aaf88SJason Gunthorpe NULL
541f931551bSRalph Campbell };
542f931551bSRalph Campbell
5434a7aaf88SJason Gunthorpe static const struct attribute_group port_diagc_group = {
544*32f57cb1SMike Marciniszyn .name = "diag_counters",
5454a7aaf88SJason Gunthorpe .attrs = port_diagc_attributes,
546f931551bSRalph Campbell };
547f931551bSRalph Campbell
548f931551bSRalph Campbell /* End diag_counters */
549f931551bSRalph Campbell
550d7407d16SJason Gunthorpe const struct attribute_group *qib_attr_port_groups[] = {
5514a7aaf88SJason Gunthorpe &port_linkcontrol_group,
5524a7aaf88SJason Gunthorpe &port_ccmgta_attribute_group,
5534a7aaf88SJason Gunthorpe &port_sl2vl_group,
5544a7aaf88SJason Gunthorpe &port_diagc_group,
5554a7aaf88SJason Gunthorpe NULL,
5564a7aaf88SJason Gunthorpe };
5574a7aaf88SJason Gunthorpe
558f931551bSRalph Campbell /* end of per-port file structures and support code */
559f931551bSRalph Campbell
560f931551bSRalph Campbell /*
561f931551bSRalph Campbell * Start of per-unit (or driver, in some cases, but replicated
562f931551bSRalph Campbell * per unit) functions (these get a device *)
563f931551bSRalph Campbell */
hw_rev_show(struct device * device,struct device_attribute * attr,char * buf)564508a523fSParav Pandit static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
565f931551bSRalph Campbell char *buf)
566f931551bSRalph Campbell {
567f931551bSRalph Campbell struct qib_ibdev *dev =
56854747231SParav Pandit rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
569f931551bSRalph Campbell
5701c7fd726SJoe Perches return sysfs_emit(buf, "%x\n", dd_from_dev(dev)->minrev);
571f931551bSRalph Campbell }
572508a523fSParav Pandit static DEVICE_ATTR_RO(hw_rev);
573f931551bSRalph Campbell
hca_type_show(struct device * device,struct device_attribute * attr,char * buf)574508a523fSParav Pandit static ssize_t hca_type_show(struct device *device,
575508a523fSParav Pandit struct device_attribute *attr, char *buf)
576f931551bSRalph Campbell {
577f931551bSRalph Campbell struct qib_ibdev *dev =
57854747231SParav Pandit rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
579f931551bSRalph Campbell struct qib_devdata *dd = dd_from_dev(dev);
580f931551bSRalph Campbell
581f931551bSRalph Campbell if (!dd->boardname)
58245808361SJoe Perches return -EINVAL;
58345808361SJoe Perches return sysfs_emit(buf, "%s\n", dd->boardname);
584f931551bSRalph Campbell }
585508a523fSParav Pandit static DEVICE_ATTR_RO(hca_type);
586508a523fSParav Pandit static DEVICE_ATTR(board_id, 0444, hca_type_show, NULL);
587f931551bSRalph Campbell
version_show(struct device * device,struct device_attribute * attr,char * buf)588508a523fSParav Pandit static ssize_t version_show(struct device *device,
589f931551bSRalph Campbell struct device_attribute *attr, char *buf)
590f931551bSRalph Campbell {
591f931551bSRalph Campbell /* The string printed here is already newline-terminated. */
5921c7fd726SJoe Perches return sysfs_emit(buf, "%s", (char *)ib_qib_version);
593f931551bSRalph Campbell }
594508a523fSParav Pandit static DEVICE_ATTR_RO(version);
595f931551bSRalph Campbell
boardversion_show(struct device * device,struct device_attribute * attr,char * buf)596508a523fSParav Pandit static ssize_t boardversion_show(struct device *device,
597f931551bSRalph Campbell struct device_attribute *attr, char *buf)
598f931551bSRalph Campbell {
599f931551bSRalph Campbell struct qib_ibdev *dev =
60054747231SParav Pandit rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
601f931551bSRalph Campbell struct qib_devdata *dd = dd_from_dev(dev);
602f931551bSRalph Campbell
603f931551bSRalph Campbell /* The string printed here is already newline-terminated. */
6041c7fd726SJoe Perches return sysfs_emit(buf, "%s", dd->boardversion);
605f931551bSRalph Campbell }
606508a523fSParav Pandit static DEVICE_ATTR_RO(boardversion);
607f931551bSRalph Campbell
localbus_info_show(struct device * device,struct device_attribute * attr,char * buf)608508a523fSParav Pandit static ssize_t localbus_info_show(struct device *device,
609f931551bSRalph Campbell struct device_attribute *attr, char *buf)
610f931551bSRalph Campbell {
611f931551bSRalph Campbell struct qib_ibdev *dev =
61254747231SParav Pandit rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
613f931551bSRalph Campbell struct qib_devdata *dd = dd_from_dev(dev);
614f931551bSRalph Campbell
615f931551bSRalph Campbell /* The string printed here is already newline-terminated. */
6161c7fd726SJoe Perches return sysfs_emit(buf, "%s", dd->lbus_info);
617f931551bSRalph Campbell }
618508a523fSParav Pandit static DEVICE_ATTR_RO(localbus_info);
619f931551bSRalph Campbell
nctxts_show(struct device * device,struct device_attribute * attr,char * buf)620508a523fSParav Pandit static ssize_t nctxts_show(struct device *device,
621f931551bSRalph Campbell struct device_attribute *attr, char *buf)
622f931551bSRalph Campbell {
623f931551bSRalph Campbell struct qib_ibdev *dev =
62454747231SParav Pandit rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
625f931551bSRalph Campbell struct qib_devdata *dd = dd_from_dev(dev);
626f931551bSRalph Campbell
627f931551bSRalph Campbell /* Return the number of user ports (contexts) available. */
6286ceaadeeSMitko Haralanov /* The calculation below deals with a special case where
6296ceaadeeSMitko Haralanov * cfgctxts is set to 1 on a single-port board. */
6301c7fd726SJoe Perches return sysfs_emit(buf, "%u\n",
6311c7fd726SJoe Perches (dd->first_user_ctxt > dd->cfgctxts) ?
6321c7fd726SJoe Perches 0 :
6336ceaadeeSMitko Haralanov (dd->cfgctxts - dd->first_user_ctxt));
634f931551bSRalph Campbell }
635508a523fSParav Pandit static DEVICE_ATTR_RO(nctxts);
636f931551bSRalph Campbell
nfreectxts_show(struct device * device,struct device_attribute * attr,char * buf)637508a523fSParav Pandit static ssize_t nfreectxts_show(struct device *device,
6382df4f757SRam Vepa struct device_attribute *attr, char *buf)
6392df4f757SRam Vepa {
6402df4f757SRam Vepa struct qib_ibdev *dev =
64154747231SParav Pandit rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
6422df4f757SRam Vepa struct qib_devdata *dd = dd_from_dev(dev);
6432df4f757SRam Vepa
6442df4f757SRam Vepa /* Return the number of free user ports (contexts) available. */
6451c7fd726SJoe Perches return sysfs_emit(buf, "%u\n", dd->freectxts);
6462df4f757SRam Vepa }
647508a523fSParav Pandit static DEVICE_ATTR_RO(nfreectxts);
6482df4f757SRam Vepa
serial_show(struct device * device,struct device_attribute * attr,char * buf)64945808361SJoe Perches static ssize_t serial_show(struct device *device, struct device_attribute *attr,
65045808361SJoe Perches char *buf)
651f931551bSRalph Campbell {
652f931551bSRalph Campbell struct qib_ibdev *dev =
65354747231SParav Pandit rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
654f931551bSRalph Campbell struct qib_devdata *dd = dd_from_dev(dev);
65545808361SJoe Perches const u8 *end = memchr(dd->serial, 0, ARRAY_SIZE(dd->serial));
65645808361SJoe Perches int size = end ? end - dd->serial : ARRAY_SIZE(dd->serial);
657f931551bSRalph Campbell
65845808361SJoe Perches return sysfs_emit(buf, ".%*s\n", size, dd->serial);
659f931551bSRalph Campbell }
660508a523fSParav Pandit static DEVICE_ATTR_RO(serial);
661f931551bSRalph Campbell
chip_reset_store(struct device * device,struct device_attribute * attr,const char * buf,size_t count)662508a523fSParav Pandit static ssize_t chip_reset_store(struct device *device,
663f931551bSRalph Campbell struct device_attribute *attr, const char *buf,
664f931551bSRalph Campbell size_t count)
665f931551bSRalph Campbell {
666f931551bSRalph Campbell struct qib_ibdev *dev =
66754747231SParav Pandit rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
668f931551bSRalph Campbell struct qib_devdata *dd = dd_from_dev(dev);
669f931551bSRalph Campbell int ret;
670f931551bSRalph Campbell
671f931551bSRalph Campbell if (count < 5 || memcmp(buf, "reset", 5) || !dd->diag_client) {
672f931551bSRalph Campbell ret = -EINVAL;
673f931551bSRalph Campbell goto bail;
674f931551bSRalph Campbell }
675f931551bSRalph Campbell
676f931551bSRalph Campbell ret = qib_reset_device(dd->unit);
677f931551bSRalph Campbell bail:
678f931551bSRalph Campbell return ret < 0 ? ret : count;
679f931551bSRalph Campbell }
680508a523fSParav Pandit static DEVICE_ATTR_WO(chip_reset);
681f931551bSRalph Campbell
682f931551bSRalph Campbell /*
683f931551bSRalph Campbell * Dump tempsense regs. in decimal, to ease shell-scripts.
684f931551bSRalph Campbell */
tempsense_show(struct device * device,struct device_attribute * attr,char * buf)685508a523fSParav Pandit static ssize_t tempsense_show(struct device *device,
686f931551bSRalph Campbell struct device_attribute *attr, char *buf)
687f931551bSRalph Campbell {
688f931551bSRalph Campbell struct qib_ibdev *dev =
68954747231SParav Pandit rdma_device_to_drv_device(device, struct qib_ibdev, rdi.ibdev);
690f931551bSRalph Campbell struct qib_devdata *dd = dd_from_dev(dev);
69145808361SJoe Perches int i;
692f931551bSRalph Campbell u8 regvals[8];
693f931551bSRalph Campbell
69445808361SJoe Perches for (i = 0; i < 8; i++) {
69545808361SJoe Perches int ret;
69645808361SJoe Perches
69745808361SJoe Perches if (i == 6)
698f931551bSRalph Campbell continue;
69945808361SJoe Perches ret = dd->f_tempsense_rd(dd, i);
700f931551bSRalph Campbell if (ret < 0)
70145808361SJoe Perches return ret; /* return error on bad read */
70245808361SJoe Perches regvals[i] = ret;
703f931551bSRalph Campbell }
70445808361SJoe Perches return sysfs_emit(buf, "%d %d %02X %02X %d %d\n",
70545808361SJoe Perches (signed char)regvals[0],
70645808361SJoe Perches (signed char)regvals[1],
70745808361SJoe Perches regvals[2],
70845808361SJoe Perches regvals[3],
70945808361SJoe Perches (signed char)regvals[5],
71045808361SJoe Perches (signed char)regvals[7]);
711f931551bSRalph Campbell }
712508a523fSParav Pandit static DEVICE_ATTR_RO(tempsense);
713f931551bSRalph Campbell
714f931551bSRalph Campbell /*
715f931551bSRalph Campbell * end of per-unit (or driver, in some cases, but replicated
716f931551bSRalph Campbell * per unit) functions
717f931551bSRalph Campbell */
718f931551bSRalph Campbell
719f931551bSRalph Campbell /* start of per-unit file structures and support code */
720508a523fSParav Pandit static struct attribute *qib_attributes[] = {
721508a523fSParav Pandit &dev_attr_hw_rev.attr,
722508a523fSParav Pandit &dev_attr_hca_type.attr,
723508a523fSParav Pandit &dev_attr_board_id.attr,
724508a523fSParav Pandit &dev_attr_version.attr,
725508a523fSParav Pandit &dev_attr_nctxts.attr,
726508a523fSParav Pandit &dev_attr_nfreectxts.attr,
727508a523fSParav Pandit &dev_attr_serial.attr,
728508a523fSParav Pandit &dev_attr_boardversion.attr,
729508a523fSParav Pandit &dev_attr_tempsense.attr,
730508a523fSParav Pandit &dev_attr_localbus_info.attr,
731508a523fSParav Pandit &dev_attr_chip_reset.attr,
732508a523fSParav Pandit NULL,
733508a523fSParav Pandit };
734f931551bSRalph Campbell
735508a523fSParav Pandit const struct attribute_group qib_attr_group = {
736508a523fSParav Pandit .attrs = qib_attributes,
737f931551bSRalph Campbell };
738