blob: 74c84c655f7e5c18f2737adfd582429cbd99c2ca [file] [log] [blame]
Mike Marciniszyn77241052015-07-30 15:17:43 -04001/*
Jubin John05d6ac12016-02-14 20:22:17 -08002 * Copyright(c) 2015, 2016 Intel Corporation.
Mike Marciniszyn77241052015-07-30 15:17:43 -04003 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
Mike Marciniszyn77241052015-07-30 15:17:43 -04009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
Mike Marciniszyn77241052015-07-30 15:17:43 -040020 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47#include <linux/ctype.h>
48
49#include "hfi.h"
50#include "mad.h"
51#include "trace.h"
Tadeusz Strukb14db1f2016-07-25 13:39:27 -070052#include "affinity.h"
Mike Marciniszyn77241052015-07-30 15:17:43 -040053
Mike Marciniszyn77241052015-07-30 15:17:43 -040054/*
55 * Start of per-port congestion control structures and support code
56 */
57
58/*
59 * Congestion control table size followed by table entries
60 */
61static ssize_t read_cc_table_bin(struct file *filp, struct kobject *kobj,
Jubin John17fb4f22016-02-14 20:21:52 -080062 struct bin_attribute *bin_attr,
63 char *buf, loff_t pos, size_t count)
Mike Marciniszyn77241052015-07-30 15:17:43 -040064{
65 int ret;
66 struct hfi1_pportdata *ppd =
67 container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
68 struct cc_state *cc_state;
69
70 ret = ppd->total_cct_entry * sizeof(struct ib_cc_table_entry_shadow)
71 + sizeof(__be16);
72
73 if (pos > ret)
74 return -EINVAL;
75
76 if (count > ret - pos)
77 count = ret - pos;
78
79 if (!count)
80 return count;
81
82 rcu_read_lock();
83 cc_state = get_cc_state(ppd);
Jubin Johnd125a6c2016-02-14 20:19:49 -080084 if (!cc_state) {
Mike Marciniszyn77241052015-07-30 15:17:43 -040085 rcu_read_unlock();
86 return -EINVAL;
87 }
Dean Luick4ee15852016-04-12 10:49:58 -070088 memcpy(buf, (void *)&cc_state->cct + pos, count);
Mike Marciniszyn77241052015-07-30 15:17:43 -040089 rcu_read_unlock();
90
91 return count;
92}
93
94static void port_release(struct kobject *kobj)
95{
96 /* nothing to do since memory is freed by hfi1_free_devdata() */
97}
98
Mike Marciniszyn77241052015-07-30 15:17:43 -040099static struct bin_attribute cc_table_bin_attr = {
100 .attr = {.name = "cc_table_bin", .mode = 0444},
101 .read = read_cc_table_bin,
102 .size = PAGE_SIZE,
103};
104
105/*
106 * Congestion settings: port control, control map and an array of 16
107 * entries for the congestion entries - increase, timer, event log
108 * trigger threshold and the minimum injection rate delay.
109 */
110static ssize_t read_cc_setting_bin(struct file *filp, struct kobject *kobj,
Jubin John17fb4f22016-02-14 20:21:52 -0800111 struct bin_attribute *bin_attr,
112 char *buf, loff_t pos, size_t count)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400113{
114 int ret;
115 struct hfi1_pportdata *ppd =
116 container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
117 struct cc_state *cc_state;
118
119 ret = sizeof(struct opa_congestion_setting_attr_shadow);
120
121 if (pos > ret)
122 return -EINVAL;
123 if (count > ret - pos)
124 count = ret - pos;
125
126 if (!count)
127 return count;
128
129 rcu_read_lock();
130 cc_state = get_cc_state(ppd);
Jubin Johnd125a6c2016-02-14 20:19:49 -0800131 if (!cc_state) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400132 rcu_read_unlock();
133 return -EINVAL;
134 }
Dean Luick4ee15852016-04-12 10:49:58 -0700135 memcpy(buf, (void *)&cc_state->cong_setting + pos, count);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400136 rcu_read_unlock();
137
138 return count;
139}
140
141static struct bin_attribute cc_setting_bin_attr = {
142 .attr = {.name = "cc_settings_bin", .mode = 0444},
143 .read = read_cc_setting_bin,
144 .size = PAGE_SIZE,
145};
146
Vennila Megavannan6c9e50f2016-02-03 14:32:57 -0800147struct hfi1_port_attr {
148 struct attribute attr;
149 ssize_t (*show)(struct hfi1_pportdata *, char *);
150 ssize_t (*store)(struct hfi1_pportdata *, const char *, size_t);
151};
152
153static ssize_t cc_prescan_show(struct hfi1_pportdata *ppd, char *buf)
154{
155 return sprintf(buf, "%s\n", ppd->cc_prescan ? "on" : "off");
156}
157
158static ssize_t cc_prescan_store(struct hfi1_pportdata *ppd, const char *buf,
159 size_t count)
160{
161 if (!memcmp(buf, "on", 2))
162 ppd->cc_prescan = true;
163 else if (!memcmp(buf, "off", 3))
164 ppd->cc_prescan = false;
165
166 return count;
167}
168
169static struct hfi1_port_attr cc_prescan_attr =
170 __ATTR(cc_prescan, 0600, cc_prescan_show, cc_prescan_store);
171
172static ssize_t cc_attr_show(struct kobject *kobj, struct attribute *attr,
173 char *buf)
174{
175 struct hfi1_port_attr *port_attr =
176 container_of(attr, struct hfi1_port_attr, attr);
177 struct hfi1_pportdata *ppd =
178 container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
179
180 return port_attr->show(ppd, buf);
181}
182
183static ssize_t cc_attr_store(struct kobject *kobj, struct attribute *attr,
184 const char *buf, size_t count)
185{
186 struct hfi1_port_attr *port_attr =
187 container_of(attr, struct hfi1_port_attr, attr);
188 struct hfi1_pportdata *ppd =
189 container_of(kobj, struct hfi1_pportdata, pport_cc_kobj);
190
191 return port_attr->store(ppd, buf, count);
192}
193
194static const struct sysfs_ops port_cc_sysfs_ops = {
195 .show = cc_attr_show,
196 .store = cc_attr_store
197};
198
199static struct attribute *port_cc_default_attributes[] = {
200 &cc_prescan_attr.attr
201};
202
203static struct kobj_type port_cc_ktype = {
204 .release = port_release,
205 .sysfs_ops = &port_cc_sysfs_ops,
206 .default_attrs = port_cc_default_attributes
207};
208
Mike Marciniszyn77241052015-07-30 15:17:43 -0400209/* Start sc2vl */
210#define HFI1_SC2VL_ATTR(N) \
211 static struct hfi1_sc2vl_attr hfi1_sc2vl_attr_##N = { \
212 .attr = { .name = __stringify(N), .mode = 0444 }, \
213 .sc = N \
214 }
215
216struct hfi1_sc2vl_attr {
217 struct attribute attr;
218 int sc;
219};
220
221HFI1_SC2VL_ATTR(0);
222HFI1_SC2VL_ATTR(1);
223HFI1_SC2VL_ATTR(2);
224HFI1_SC2VL_ATTR(3);
225HFI1_SC2VL_ATTR(4);
226HFI1_SC2VL_ATTR(5);
227HFI1_SC2VL_ATTR(6);
228HFI1_SC2VL_ATTR(7);
229HFI1_SC2VL_ATTR(8);
230HFI1_SC2VL_ATTR(9);
231HFI1_SC2VL_ATTR(10);
232HFI1_SC2VL_ATTR(11);
233HFI1_SC2VL_ATTR(12);
234HFI1_SC2VL_ATTR(13);
235HFI1_SC2VL_ATTR(14);
236HFI1_SC2VL_ATTR(15);
237HFI1_SC2VL_ATTR(16);
238HFI1_SC2VL_ATTR(17);
239HFI1_SC2VL_ATTR(18);
240HFI1_SC2VL_ATTR(19);
241HFI1_SC2VL_ATTR(20);
242HFI1_SC2VL_ATTR(21);
243HFI1_SC2VL_ATTR(22);
244HFI1_SC2VL_ATTR(23);
245HFI1_SC2VL_ATTR(24);
246HFI1_SC2VL_ATTR(25);
247HFI1_SC2VL_ATTR(26);
248HFI1_SC2VL_ATTR(27);
249HFI1_SC2VL_ATTR(28);
250HFI1_SC2VL_ATTR(29);
251HFI1_SC2VL_ATTR(30);
252HFI1_SC2VL_ATTR(31);
253
Mike Marciniszyn77241052015-07-30 15:17:43 -0400254static struct attribute *sc2vl_default_attributes[] = {
255 &hfi1_sc2vl_attr_0.attr,
256 &hfi1_sc2vl_attr_1.attr,
257 &hfi1_sc2vl_attr_2.attr,
258 &hfi1_sc2vl_attr_3.attr,
259 &hfi1_sc2vl_attr_4.attr,
260 &hfi1_sc2vl_attr_5.attr,
261 &hfi1_sc2vl_attr_6.attr,
262 &hfi1_sc2vl_attr_7.attr,
263 &hfi1_sc2vl_attr_8.attr,
264 &hfi1_sc2vl_attr_9.attr,
265 &hfi1_sc2vl_attr_10.attr,
266 &hfi1_sc2vl_attr_11.attr,
267 &hfi1_sc2vl_attr_12.attr,
268 &hfi1_sc2vl_attr_13.attr,
269 &hfi1_sc2vl_attr_14.attr,
270 &hfi1_sc2vl_attr_15.attr,
271 &hfi1_sc2vl_attr_16.attr,
272 &hfi1_sc2vl_attr_17.attr,
273 &hfi1_sc2vl_attr_18.attr,
274 &hfi1_sc2vl_attr_19.attr,
275 &hfi1_sc2vl_attr_20.attr,
276 &hfi1_sc2vl_attr_21.attr,
277 &hfi1_sc2vl_attr_22.attr,
278 &hfi1_sc2vl_attr_23.attr,
279 &hfi1_sc2vl_attr_24.attr,
280 &hfi1_sc2vl_attr_25.attr,
281 &hfi1_sc2vl_attr_26.attr,
282 &hfi1_sc2vl_attr_27.attr,
283 &hfi1_sc2vl_attr_28.attr,
284 &hfi1_sc2vl_attr_29.attr,
285 &hfi1_sc2vl_attr_30.attr,
286 &hfi1_sc2vl_attr_31.attr,
287 NULL
288};
289
290static ssize_t sc2vl_attr_show(struct kobject *kobj, struct attribute *attr,
291 char *buf)
292{
293 struct hfi1_sc2vl_attr *sattr =
294 container_of(attr, struct hfi1_sc2vl_attr, attr);
295 struct hfi1_pportdata *ppd =
296 container_of(kobj, struct hfi1_pportdata, sc2vl_kobj);
297 struct hfi1_devdata *dd = ppd->dd;
298
299 return sprintf(buf, "%u\n", *((u8 *)dd->sc2vl + sattr->sc));
300}
301
302static const struct sysfs_ops hfi1_sc2vl_ops = {
303 .show = sc2vl_attr_show,
304};
305
306static struct kobj_type hfi1_sc2vl_ktype = {
307 .release = port_release,
308 .sysfs_ops = &hfi1_sc2vl_ops,
309 .default_attrs = sc2vl_default_attributes
310};
311
312/* End sc2vl */
313
314/* Start sl2sc */
315#define HFI1_SL2SC_ATTR(N) \
316 static struct hfi1_sl2sc_attr hfi1_sl2sc_attr_##N = { \
317 .attr = { .name = __stringify(N), .mode = 0444 }, \
318 .sl = N \
319 }
320
321struct hfi1_sl2sc_attr {
322 struct attribute attr;
323 int sl;
324};
325
326HFI1_SL2SC_ATTR(0);
327HFI1_SL2SC_ATTR(1);
328HFI1_SL2SC_ATTR(2);
329HFI1_SL2SC_ATTR(3);
330HFI1_SL2SC_ATTR(4);
331HFI1_SL2SC_ATTR(5);
332HFI1_SL2SC_ATTR(6);
333HFI1_SL2SC_ATTR(7);
334HFI1_SL2SC_ATTR(8);
335HFI1_SL2SC_ATTR(9);
336HFI1_SL2SC_ATTR(10);
337HFI1_SL2SC_ATTR(11);
338HFI1_SL2SC_ATTR(12);
339HFI1_SL2SC_ATTR(13);
340HFI1_SL2SC_ATTR(14);
341HFI1_SL2SC_ATTR(15);
342HFI1_SL2SC_ATTR(16);
343HFI1_SL2SC_ATTR(17);
344HFI1_SL2SC_ATTR(18);
345HFI1_SL2SC_ATTR(19);
346HFI1_SL2SC_ATTR(20);
347HFI1_SL2SC_ATTR(21);
348HFI1_SL2SC_ATTR(22);
349HFI1_SL2SC_ATTR(23);
350HFI1_SL2SC_ATTR(24);
351HFI1_SL2SC_ATTR(25);
352HFI1_SL2SC_ATTR(26);
353HFI1_SL2SC_ATTR(27);
354HFI1_SL2SC_ATTR(28);
355HFI1_SL2SC_ATTR(29);
356HFI1_SL2SC_ATTR(30);
357HFI1_SL2SC_ATTR(31);
358
Mike Marciniszyn77241052015-07-30 15:17:43 -0400359static struct attribute *sl2sc_default_attributes[] = {
360 &hfi1_sl2sc_attr_0.attr,
361 &hfi1_sl2sc_attr_1.attr,
362 &hfi1_sl2sc_attr_2.attr,
363 &hfi1_sl2sc_attr_3.attr,
364 &hfi1_sl2sc_attr_4.attr,
365 &hfi1_sl2sc_attr_5.attr,
366 &hfi1_sl2sc_attr_6.attr,
367 &hfi1_sl2sc_attr_7.attr,
368 &hfi1_sl2sc_attr_8.attr,
369 &hfi1_sl2sc_attr_9.attr,
370 &hfi1_sl2sc_attr_10.attr,
371 &hfi1_sl2sc_attr_11.attr,
372 &hfi1_sl2sc_attr_12.attr,
373 &hfi1_sl2sc_attr_13.attr,
374 &hfi1_sl2sc_attr_14.attr,
375 &hfi1_sl2sc_attr_15.attr,
376 &hfi1_sl2sc_attr_16.attr,
377 &hfi1_sl2sc_attr_17.attr,
378 &hfi1_sl2sc_attr_18.attr,
379 &hfi1_sl2sc_attr_19.attr,
380 &hfi1_sl2sc_attr_20.attr,
381 &hfi1_sl2sc_attr_21.attr,
382 &hfi1_sl2sc_attr_22.attr,
383 &hfi1_sl2sc_attr_23.attr,
384 &hfi1_sl2sc_attr_24.attr,
385 &hfi1_sl2sc_attr_25.attr,
386 &hfi1_sl2sc_attr_26.attr,
387 &hfi1_sl2sc_attr_27.attr,
388 &hfi1_sl2sc_attr_28.attr,
389 &hfi1_sl2sc_attr_29.attr,
390 &hfi1_sl2sc_attr_30.attr,
391 &hfi1_sl2sc_attr_31.attr,
392 NULL
393};
394
395static ssize_t sl2sc_attr_show(struct kobject *kobj, struct attribute *attr,
396 char *buf)
397{
398 struct hfi1_sl2sc_attr *sattr =
399 container_of(attr, struct hfi1_sl2sc_attr, attr);
400 struct hfi1_pportdata *ppd =
401 container_of(kobj, struct hfi1_pportdata, sl2sc_kobj);
402 struct hfi1_ibport *ibp = &ppd->ibport_data;
403
404 return sprintf(buf, "%u\n", ibp->sl_to_sc[sattr->sl]);
405}
406
407static const struct sysfs_ops hfi1_sl2sc_ops = {
408 .show = sl2sc_attr_show,
409};
410
411static struct kobj_type hfi1_sl2sc_ktype = {
412 .release = port_release,
413 .sysfs_ops = &hfi1_sl2sc_ops,
414 .default_attrs = sl2sc_default_attributes
415};
416
417/* End sl2sc */
418
419/* Start vl2mtu */
420
421#define HFI1_VL2MTU_ATTR(N) \
422 static struct hfi1_vl2mtu_attr hfi1_vl2mtu_attr_##N = { \
423 .attr = { .name = __stringify(N), .mode = 0444 }, \
424 .vl = N \
425 }
426
427struct hfi1_vl2mtu_attr {
428 struct attribute attr;
429 int vl;
430};
431
432HFI1_VL2MTU_ATTR(0);
433HFI1_VL2MTU_ATTR(1);
434HFI1_VL2MTU_ATTR(2);
435HFI1_VL2MTU_ATTR(3);
436HFI1_VL2MTU_ATTR(4);
437HFI1_VL2MTU_ATTR(5);
438HFI1_VL2MTU_ATTR(6);
439HFI1_VL2MTU_ATTR(7);
440HFI1_VL2MTU_ATTR(8);
441HFI1_VL2MTU_ATTR(9);
442HFI1_VL2MTU_ATTR(10);
443HFI1_VL2MTU_ATTR(11);
444HFI1_VL2MTU_ATTR(12);
445HFI1_VL2MTU_ATTR(13);
446HFI1_VL2MTU_ATTR(14);
447HFI1_VL2MTU_ATTR(15);
448
449static struct attribute *vl2mtu_default_attributes[] = {
450 &hfi1_vl2mtu_attr_0.attr,
451 &hfi1_vl2mtu_attr_1.attr,
452 &hfi1_vl2mtu_attr_2.attr,
453 &hfi1_vl2mtu_attr_3.attr,
454 &hfi1_vl2mtu_attr_4.attr,
455 &hfi1_vl2mtu_attr_5.attr,
456 &hfi1_vl2mtu_attr_6.attr,
457 &hfi1_vl2mtu_attr_7.attr,
458 &hfi1_vl2mtu_attr_8.attr,
459 &hfi1_vl2mtu_attr_9.attr,
460 &hfi1_vl2mtu_attr_10.attr,
461 &hfi1_vl2mtu_attr_11.attr,
462 &hfi1_vl2mtu_attr_12.attr,
463 &hfi1_vl2mtu_attr_13.attr,
464 &hfi1_vl2mtu_attr_14.attr,
465 &hfi1_vl2mtu_attr_15.attr,
466 NULL
467};
468
469static ssize_t vl2mtu_attr_show(struct kobject *kobj, struct attribute *attr,
470 char *buf)
471{
472 struct hfi1_vl2mtu_attr *vlattr =
473 container_of(attr, struct hfi1_vl2mtu_attr, attr);
474 struct hfi1_pportdata *ppd =
475 container_of(kobj, struct hfi1_pportdata, vl2mtu_kobj);
476 struct hfi1_devdata *dd = ppd->dd;
477
478 return sprintf(buf, "%u\n", dd->vld[vlattr->vl].mtu);
479}
480
481static const struct sysfs_ops hfi1_vl2mtu_ops = {
482 .show = vl2mtu_attr_show,
483};
484
485static struct kobj_type hfi1_vl2mtu_ktype = {
486 .release = port_release,
487 .sysfs_ops = &hfi1_vl2mtu_ops,
488 .default_attrs = vl2mtu_default_attributes
489};
490
Mike Marciniszyn77241052015-07-30 15:17:43 -0400491/* end of per-port file structures and support code */
492
493/*
494 * Start of per-unit (or driver, in some cases, but replicated
495 * per unit) functions (these get a device *)
496 */
497static ssize_t show_rev(struct device *device, struct device_attribute *attr,
498 char *buf)
499{
500 struct hfi1_ibdev *dev =
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -0800501 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400502
503 return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev);
504}
505
506static ssize_t show_hfi(struct device *device, struct device_attribute *attr,
507 char *buf)
508{
509 struct hfi1_ibdev *dev =
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -0800510 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400511 struct hfi1_devdata *dd = dd_from_dev(dev);
512 int ret;
513
514 if (!dd->boardname)
515 ret = -EINVAL;
516 else
517 ret = scnprintf(buf, PAGE_SIZE, "%s\n", dd->boardname);
518 return ret;
519}
520
521static ssize_t show_boardversion(struct device *device,
522 struct device_attribute *attr, char *buf)
523{
524 struct hfi1_ibdev *dev =
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -0800525 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400526 struct hfi1_devdata *dd = dd_from_dev(dev);
527
528 /* The string printed here is already newline-terminated. */
529 return scnprintf(buf, PAGE_SIZE, "%s", dd->boardversion);
530}
531
Mike Marciniszyn77241052015-07-30 15:17:43 -0400532static ssize_t show_nctxts(struct device *device,
533 struct device_attribute *attr, char *buf)
534{
535 struct hfi1_ibdev *dev =
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -0800536 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400537 struct hfi1_devdata *dd = dd_from_dev(dev);
538
539 /*
540 * Return the smaller of send and receive contexts.
541 * Normally, user level applications would require both a send
542 * and a receive context, so returning the smaller of the two counts
543 * give a more accurate picture of total contexts available.
544 */
545 return scnprintf(buf, PAGE_SIZE, "%u\n",
546 min(dd->num_rcv_contexts - dd->first_user_ctxt,
547 (u32)dd->sc_sizes[SC_USER].count));
548}
549
550static ssize_t show_nfreectxts(struct device *device,
Jubin John17fb4f22016-02-14 20:21:52 -0800551 struct device_attribute *attr, char *buf)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400552{
553 struct hfi1_ibdev *dev =
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -0800554 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400555 struct hfi1_devdata *dd = dd_from_dev(dev);
556
557 /* Return the number of free user ports (contexts) available. */
558 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->freectxts);
559}
560
561static ssize_t show_serial(struct device *device,
562 struct device_attribute *attr, char *buf)
563{
564 struct hfi1_ibdev *dev =
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -0800565 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400566 struct hfi1_devdata *dd = dd_from_dev(dev);
567
568 return scnprintf(buf, PAGE_SIZE, "%s", dd->serial);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400569}
570
571static ssize_t store_chip_reset(struct device *device,
572 struct device_attribute *attr, const char *buf,
573 size_t count)
574{
575 struct hfi1_ibdev *dev =
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -0800576 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400577 struct hfi1_devdata *dd = dd_from_dev(dev);
578 int ret;
579
580 if (count < 5 || memcmp(buf, "reset", 5) || !dd->diag_client) {
581 ret = -EINVAL;
582 goto bail;
583 }
584
585 ret = hfi1_reset_device(dd->unit);
586bail:
587 return ret < 0 ? ret : count;
588}
589
590/*
591 * Convert the reported temperature from an integer (reported in
592 * units of 0.25C) to a floating point number.
593 */
594#define temp2str(temp, buf, size, idx) \
595 scnprintf((buf) + (idx), (size) - (idx), "%u.%02u ", \
596 ((temp) >> 2), ((temp) & 0x3) * 25)
597
598/*
599 * Dump tempsense values, in decimal, to ease shell-scripts.
600 */
601static ssize_t show_tempsense(struct device *device,
602 struct device_attribute *attr, char *buf)
603{
604 struct hfi1_ibdev *dev =
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -0800605 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400606 struct hfi1_devdata *dd = dd_from_dev(dev);
607 struct hfi1_temp temp;
Amitoj Kaur Chawla4690ba02015-10-15 13:54:35 +0530608 int ret;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400609
610 ret = hfi1_tempsense_rd(dd, &temp);
611 if (!ret) {
612 int idx = 0;
613
614 idx += temp2str(temp.curr, buf, PAGE_SIZE, idx);
615 idx += temp2str(temp.lo_lim, buf, PAGE_SIZE, idx);
616 idx += temp2str(temp.hi_lim, buf, PAGE_SIZE, idx);
617 idx += temp2str(temp.crit_lim, buf, PAGE_SIZE, idx);
618 idx += scnprintf(buf + idx, PAGE_SIZE - idx,
619 "%u %u %u\n", temp.triggers & 0x1,
620 temp.triggers & 0x2, temp.triggers & 0x4);
621 ret = idx;
622 }
623 return ret;
624}
625
Tadeusz Strukb14db1f2016-07-25 13:39:27 -0700626static ssize_t show_sdma_affinity(struct device *device,
627 struct device_attribute *attr, char *buf)
628{
629 struct hfi1_ibdev *dev =
630 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
631 struct hfi1_devdata *dd = dd_from_dev(dev);
632
633 return hfi1_get_sdma_affinity(dd, buf);
634}
635
636static ssize_t store_sdma_affinity(struct device *device,
637 struct device_attribute *attr,
638 const char *buf, size_t count)
639{
640 struct hfi1_ibdev *dev =
641 container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
642 struct hfi1_devdata *dd = dd_from_dev(dev);
643
644 return hfi1_set_sdma_affinity(dd, buf, count);
645}
646
Mike Marciniszyn77241052015-07-30 15:17:43 -0400647/*
648 * end of per-unit (or driver, in some cases, but replicated
649 * per unit) functions
650 */
651
652/* start of per-unit file structures and support code */
653static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
654static DEVICE_ATTR(board_id, S_IRUGO, show_hfi, NULL);
655static DEVICE_ATTR(nctxts, S_IRUGO, show_nctxts, NULL);
656static DEVICE_ATTR(nfreectxts, S_IRUGO, show_nfreectxts, NULL);
657static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
658static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
659static DEVICE_ATTR(tempsense, S_IRUGO, show_tempsense, NULL);
660static DEVICE_ATTR(chip_reset, S_IWUSR, NULL, store_chip_reset);
Tadeusz Strukb14db1f2016-07-25 13:39:27 -0700661static DEVICE_ATTR(sdma_affinity, S_IWUSR | S_IRUGO, show_sdma_affinity,
662 store_sdma_affinity);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400663
664static struct device_attribute *hfi1_attributes[] = {
665 &dev_attr_hw_rev,
666 &dev_attr_board_id,
667 &dev_attr_nctxts,
668 &dev_attr_nfreectxts,
669 &dev_attr_serial,
670 &dev_attr_boardversion,
671 &dev_attr_tempsense,
672 &dev_attr_chip_reset,
Tadeusz Strukb14db1f2016-07-25 13:39:27 -0700673 &dev_attr_sdma_affinity,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400674};
675
676int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
677 struct kobject *kobj)
678{
679 struct hfi1_pportdata *ppd;
680 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
681 int ret;
682
683 if (!port_num || port_num > dd->num_pports) {
684 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -0800685 "Skipping infiniband class with invalid port %u\n",
686 port_num);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400687 return -ENODEV;
688 }
689 ppd = &dd->pport[port_num - 1];
690
691 ret = kobject_init_and_add(&ppd->sc2vl_kobj, &hfi1_sc2vl_ktype, kobj,
692 "sc2vl");
693 if (ret) {
694 dd_dev_err(dd,
695 "Skipping sc2vl sysfs info, (err %d) port %u\n",
696 ret, port_num);
697 goto bail;
698 }
699 kobject_uevent(&ppd->sc2vl_kobj, KOBJ_ADD);
700
701 ret = kobject_init_and_add(&ppd->sl2sc_kobj, &hfi1_sl2sc_ktype, kobj,
702 "sl2sc");
703 if (ret) {
704 dd_dev_err(dd,
705 "Skipping sl2sc sysfs info, (err %d) port %u\n",
706 ret, port_num);
707 goto bail_sc2vl;
708 }
709 kobject_uevent(&ppd->sl2sc_kobj, KOBJ_ADD);
710
711 ret = kobject_init_and_add(&ppd->vl2mtu_kobj, &hfi1_vl2mtu_ktype, kobj,
712 "vl2mtu");
713 if (ret) {
714 dd_dev_err(dd,
715 "Skipping vl2mtu sysfs info, (err %d) port %u\n",
716 ret, port_num);
717 goto bail_sl2sc;
718 }
719 kobject_uevent(&ppd->vl2mtu_kobj, KOBJ_ADD);
720
Mike Marciniszyn77241052015-07-30 15:17:43 -0400721 ret = kobject_init_and_add(&ppd->pport_cc_kobj, &port_cc_ktype,
722 kobj, "CCMgtA");
723 if (ret) {
724 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -0800725 "Skipping Congestion Control sysfs info, (err %d) port %u\n",
726 ret, port_num);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400727 goto bail_vl2mtu;
728 }
729
730 kobject_uevent(&ppd->pport_cc_kobj, KOBJ_ADD);
731
Jubin John17fb4f22016-02-14 20:21:52 -0800732 ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, &cc_setting_bin_attr);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400733 if (ret) {
734 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -0800735 "Skipping Congestion Control setting sysfs info, (err %d) port %u\n",
736 ret, port_num);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400737 goto bail_cc;
738 }
739
Jubin John17fb4f22016-02-14 20:21:52 -0800740 ret = sysfs_create_bin_file(&ppd->pport_cc_kobj, &cc_table_bin_attr);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400741 if (ret) {
742 dd_dev_err(dd,
Jubin John17fb4f22016-02-14 20:21:52 -0800743 "Skipping Congestion Control table sysfs info, (err %d) port %u\n",
744 ret, port_num);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400745 goto bail_cc_entry_bin;
746 }
747
748 dd_dev_info(dd,
Jakub Pawlakcde10af2016-05-12 10:23:35 -0700749 "Congestion Control Agent enabled for port %d\n",
750 port_num);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400751
752 return 0;
753
754bail_cc_entry_bin:
755 sysfs_remove_bin_file(&ppd->pport_cc_kobj,
756 &cc_setting_bin_attr);
757bail_cc:
758 kobject_put(&ppd->pport_cc_kobj);
759bail_vl2mtu:
760 kobject_put(&ppd->vl2mtu_kobj);
761bail_sl2sc:
762 kobject_put(&ppd->sl2sc_kobj);
763bail_sc2vl:
764 kobject_put(&ppd->sc2vl_kobj);
765bail:
766 return ret;
767}
768
769/*
770 * Register and create our files in /sys/class/infiniband.
771 */
772int hfi1_verbs_register_sysfs(struct hfi1_devdata *dd)
773{
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -0800774 struct ib_device *dev = &dd->verbs_dev.rdi.ibdev;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400775 int i, ret;
776
777 for (i = 0; i < ARRAY_SIZE(hfi1_attributes); ++i) {
778 ret = device_create_file(&dev->dev, hfi1_attributes[i]);
779 if (ret)
780 goto bail;
781 }
782
783 return 0;
784bail:
785 for (i = 0; i < ARRAY_SIZE(hfi1_attributes); ++i)
786 device_remove_file(&dev->dev, hfi1_attributes[i]);
787 return ret;
788}
789
790/*
791 * Unregister and remove our files in /sys/class/infiniband.
792 */
793void hfi1_verbs_unregister_sysfs(struct hfi1_devdata *dd)
794{
795 struct hfi1_pportdata *ppd;
796 int i;
797
798 for (i = 0; i < dd->num_pports; i++) {
799 ppd = &dd->pport[i];
800
801 sysfs_remove_bin_file(&ppd->pport_cc_kobj,
802 &cc_setting_bin_attr);
803 sysfs_remove_bin_file(&ppd->pport_cc_kobj,
804 &cc_table_bin_attr);
805 kobject_put(&ppd->pport_cc_kobj);
806 kobject_put(&ppd->vl2mtu_kobj);
807 kobject_put(&ppd->sl2sc_kobj);
808 kobject_put(&ppd->sc2vl_kobj);
809 }
810}