]>
Commit | Line | Data |
---|---|---|
3e9b4a5e | 1 | /* |
e7eacd36 | 2 | * Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved. |
3e9b4a5e BS |
3 | * Copyright (c) 2006 PathScale, Inc. All rights reserved. |
4 | * | |
5 | * This software is available to you under a choice of one of two | |
6 | * licenses. You may choose to be licensed under the terms of the GNU | |
7 | * General Public License (GPL) Version 2, available from the file | |
8 | * COPYING in the main directory of this source tree, or the | |
9 | * OpenIB.org BSD license below: | |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or | |
12 | * without modification, are permitted provided that the following | |
13 | * conditions are met: | |
14 | * | |
15 | * - Redistributions of source code must retain the above | |
16 | * copyright notice, this list of conditions and the following | |
17 | * disclaimer. | |
18 | * | |
19 | * - Redistributions in binary form must reproduce the above | |
20 | * copyright notice, this list of conditions and the following | |
21 | * disclaimer in the documentation and/or other materials | |
22 | * provided with the distribution. | |
23 | * | |
24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
25 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
26 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
27 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
28 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
29 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
30 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
31 | * SOFTWARE. | |
32 | */ | |
33 | ||
34 | #include <linux/ctype.h> | |
fc87af74 | 35 | #include <linux/stat.h> |
3e9b4a5e BS |
36 | |
37 | #include "ipath_kernel.h" | |
bb917144 | 38 | #include "ipath_verbs.h" |
27b678dd | 39 | #include "ipath_common.h" |
3e9b4a5e BS |
40 | |
41 | /** | |
42 | * ipath_parse_ushort - parse an unsigned short value in an arbitrary base | |
43 | * @str: the string containing the number | |
44 | * @valp: where to put the result | |
45 | * | |
46 | * returns the number of bytes consumed, or negative value on error | |
47 | */ | |
48 | int ipath_parse_ushort(const char *str, unsigned short *valp) | |
49 | { | |
50 | unsigned long val; | |
51 | char *end; | |
52 | int ret; | |
53 | ||
54 | if (!isdigit(str[0])) { | |
55 | ret = -EINVAL; | |
56 | goto bail; | |
57 | } | |
58 | ||
59 | val = simple_strtoul(str, &end, 0); | |
60 | ||
61 | if (val > 0xffff) { | |
62 | ret = -EINVAL; | |
63 | goto bail; | |
64 | } | |
65 | ||
66 | *valp = val; | |
67 | ||
68 | ret = end + 1 - str; | |
69 | if (ret == 0) | |
70 | ret = -EINVAL; | |
71 | ||
72 | bail: | |
73 | return ret; | |
74 | } | |
75 | ||
76 | static ssize_t show_version(struct device_driver *dev, char *buf) | |
77 | { | |
78 | /* The string printed here is already newline-terminated. */ | |
b55f4f06 | 79 | return scnprintf(buf, PAGE_SIZE, "%s", ib_ipath_version); |
3e9b4a5e BS |
80 | } |
81 | ||
82 | static ssize_t show_num_units(struct device_driver *dev, char *buf) | |
83 | { | |
84 | return scnprintf(buf, PAGE_SIZE, "%d\n", | |
85 | ipath_count_units(NULL, NULL, NULL)); | |
86 | } | |
87 | ||
3e9b4a5e BS |
88 | static ssize_t show_status(struct device *dev, |
89 | struct device_attribute *attr, | |
90 | char *buf) | |
91 | { | |
92 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
93 | ssize_t ret; | |
94 | ||
95 | if (!dd->ipath_statusp) { | |
96 | ret = -EINVAL; | |
97 | goto bail; | |
98 | } | |
99 | ||
100 | ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n", | |
101 | (unsigned long long) *(dd->ipath_statusp)); | |
102 | ||
103 | bail: | |
104 | return ret; | |
105 | } | |
106 | ||
107 | static const char *ipath_status_str[] = { | |
108 | "Initted", | |
109 | "Disabled", | |
110 | "Admin_Disabled", | |
0fd41363 BS |
111 | "", /* This used to be the old "OIB_SMA" status. */ |
112 | "", /* This used to be the old "SMA" status. */ | |
3e9b4a5e BS |
113 | "Present", |
114 | "IB_link_up", | |
115 | "IB_configured", | |
116 | "NoIBcable", | |
117 | "Fatal_Hardware_Error", | |
118 | NULL, | |
119 | }; | |
120 | ||
121 | static ssize_t show_status_str(struct device *dev, | |
122 | struct device_attribute *attr, | |
123 | char *buf) | |
124 | { | |
125 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
126 | int i, any; | |
127 | u64 s; | |
128 | ssize_t ret; | |
129 | ||
130 | if (!dd->ipath_statusp) { | |
131 | ret = -EINVAL; | |
132 | goto bail; | |
133 | } | |
134 | ||
135 | s = *(dd->ipath_statusp); | |
136 | *buf = '\0'; | |
137 | for (any = i = 0; s && ipath_status_str[i]; i++) { | |
138 | if (s & 1) { | |
139 | if (any && strlcat(buf, " ", PAGE_SIZE) >= | |
140 | PAGE_SIZE) | |
141 | /* overflow */ | |
142 | break; | |
143 | if (strlcat(buf, ipath_status_str[i], | |
144 | PAGE_SIZE) >= PAGE_SIZE) | |
145 | break; | |
146 | any = 1; | |
147 | } | |
148 | s >>= 1; | |
149 | } | |
150 | if (any) | |
151 | strlcat(buf, "\n", PAGE_SIZE); | |
152 | ||
153 | ret = strlen(buf); | |
154 | ||
155 | bail: | |
156 | return ret; | |
157 | } | |
158 | ||
159 | static ssize_t show_boardversion(struct device *dev, | |
160 | struct device_attribute *attr, | |
161 | char *buf) | |
162 | { | |
163 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
164 | /* The string printed here is already newline-terminated. */ | |
165 | return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_boardversion); | |
166 | } | |
167 | ||
6ca2abf4 AJ |
168 | static ssize_t show_localbus_info(struct device *dev, |
169 | struct device_attribute *attr, | |
170 | char *buf) | |
171 | { | |
172 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
173 | /* The string printed here is already newline-terminated. */ | |
174 | return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_lbus_info); | |
175 | } | |
176 | ||
15cba26f RC |
177 | static ssize_t show_lmc(struct device *dev, |
178 | struct device_attribute *attr, | |
179 | char *buf) | |
180 | { | |
181 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
182 | ||
183 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_lmc); | |
184 | } | |
185 | ||
186 | static ssize_t store_lmc(struct device *dev, | |
187 | struct device_attribute *attr, | |
188 | const char *buf, | |
189 | size_t count) | |
190 | { | |
191 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
192 | u16 lmc = 0; | |
193 | int ret; | |
194 | ||
195 | ret = ipath_parse_ushort(buf, &lmc); | |
196 | if (ret < 0) | |
197 | goto invalid; | |
198 | ||
199 | if (lmc > 7) { | |
200 | ret = -EINVAL; | |
201 | goto invalid; | |
202 | } | |
203 | ||
204 | ipath_set_lid(dd, dd->ipath_lid, lmc); | |
205 | ||
206 | goto bail; | |
207 | invalid: | |
208 | ipath_dev_err(dd, "attempt to set invalid LMC %u\n", lmc); | |
209 | bail: | |
210 | return ret; | |
211 | } | |
212 | ||
3e9b4a5e BS |
213 | static ssize_t show_lid(struct device *dev, |
214 | struct device_attribute *attr, | |
215 | char *buf) | |
216 | { | |
217 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
218 | ||
219 | return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_lid); | |
220 | } | |
221 | ||
222 | static ssize_t store_lid(struct device *dev, | |
223 | struct device_attribute *attr, | |
224 | const char *buf, | |
225 | size_t count) | |
226 | { | |
227 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
1eb68b99 | 228 | u16 lid = 0; |
3e9b4a5e BS |
229 | int ret; |
230 | ||
231 | ret = ipath_parse_ushort(buf, &lid); | |
232 | if (ret < 0) | |
233 | goto invalid; | |
234 | ||
27b678dd | 235 | if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE) { |
3e9b4a5e BS |
236 | ret = -EINVAL; |
237 | goto invalid; | |
238 | } | |
239 | ||
15cba26f | 240 | ipath_set_lid(dd, lid, dd->ipath_lmc); |
3e9b4a5e BS |
241 | |
242 | goto bail; | |
243 | invalid: | |
1eb68b99 | 244 | ipath_dev_err(dd, "attempt to set invalid LID 0x%x\n", lid); |
3e9b4a5e BS |
245 | bail: |
246 | return ret; | |
247 | } | |
248 | ||
249 | static ssize_t show_mlid(struct device *dev, | |
250 | struct device_attribute *attr, | |
251 | char *buf) | |
252 | { | |
253 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
254 | ||
255 | return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_mlid); | |
256 | } | |
257 | ||
258 | static ssize_t store_mlid(struct device *dev, | |
259 | struct device_attribute *attr, | |
260 | const char *buf, | |
261 | size_t count) | |
262 | { | |
263 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
3e9b4a5e BS |
264 | u16 mlid; |
265 | int ret; | |
266 | ||
267 | ret = ipath_parse_ushort(buf, &mlid); | |
27b678dd | 268 | if (ret < 0 || mlid < IPATH_MULTICAST_LID_BASE) |
3e9b4a5e BS |
269 | goto invalid; |
270 | ||
3e9b4a5e | 271 | dd->ipath_mlid = mlid; |
3e9b4a5e BS |
272 | |
273 | goto bail; | |
274 | invalid: | |
275 | ipath_dev_err(dd, "attempt to set invalid MLID\n"); | |
276 | bail: | |
277 | return ret; | |
278 | } | |
279 | ||
280 | static ssize_t show_guid(struct device *dev, | |
281 | struct device_attribute *attr, | |
282 | char *buf) | |
283 | { | |
284 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
285 | u8 *guid; | |
286 | ||
287 | guid = (u8 *) & (dd->ipath_guid); | |
288 | ||
289 | return scnprintf(buf, PAGE_SIZE, | |
290 | "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", | |
291 | guid[0], guid[1], guid[2], guid[3], | |
292 | guid[4], guid[5], guid[6], guid[7]); | |
293 | } | |
294 | ||
295 | static ssize_t store_guid(struct device *dev, | |
296 | struct device_attribute *attr, | |
297 | const char *buf, | |
298 | size_t count) | |
299 | { | |
300 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
301 | ssize_t ret; | |
302 | unsigned short guid[8]; | |
11b054fe | 303 | __be64 new_guid; |
3e9b4a5e BS |
304 | u8 *ng; |
305 | int i; | |
306 | ||
307 | if (sscanf(buf, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx", | |
308 | &guid[0], &guid[1], &guid[2], &guid[3], | |
309 | &guid[4], &guid[5], &guid[6], &guid[7]) != 8) | |
310 | goto invalid; | |
311 | ||
11b054fe | 312 | ng = (u8 *) &new_guid; |
3e9b4a5e BS |
313 | |
314 | for (i = 0; i < 8; i++) { | |
315 | if (guid[i] > 0xff) | |
316 | goto invalid; | |
317 | ng[i] = guid[i]; | |
318 | } | |
319 | ||
11b054fe BS |
320 | if (new_guid == 0) |
321 | goto invalid; | |
322 | ||
323 | dd->ipath_guid = new_guid; | |
3e9b4a5e | 324 | dd->ipath_nguid = 1; |
bb917144 AJ |
325 | if (dd->verbs_dev) |
326 | dd->verbs_dev->ibdev.node_guid = new_guid; | |
3e9b4a5e BS |
327 | |
328 | ret = strlen(buf); | |
329 | goto bail; | |
330 | ||
331 | invalid: | |
332 | ipath_dev_err(dd, "attempt to set invalid GUID\n"); | |
333 | ret = -EINVAL; | |
334 | ||
335 | bail: | |
336 | return ret; | |
337 | } | |
338 | ||
339 | static ssize_t show_nguid(struct device *dev, | |
340 | struct device_attribute *attr, | |
341 | char *buf) | |
342 | { | |
343 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
344 | ||
345 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid); | |
346 | } | |
347 | ||
9929b0fb BS |
348 | static ssize_t show_nports(struct device *dev, |
349 | struct device_attribute *attr, | |
350 | char *buf) | |
351 | { | |
352 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
353 | ||
354 | /* Return the number of user ports available. */ | |
355 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_cfgports - 1); | |
356 | } | |
357 | ||
3e9b4a5e BS |
358 | static ssize_t show_serial(struct device *dev, |
359 | struct device_attribute *attr, | |
360 | char *buf) | |
361 | { | |
362 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
363 | ||
364 | buf[sizeof dd->ipath_serial] = '\0'; | |
365 | memcpy(buf, dd->ipath_serial, sizeof dd->ipath_serial); | |
366 | strcat(buf, "\n"); | |
367 | return strlen(buf); | |
368 | } | |
369 | ||
370 | static ssize_t show_unit(struct device *dev, | |
371 | struct device_attribute *attr, | |
372 | char *buf) | |
373 | { | |
374 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
375 | ||
376 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_unit); | |
377 | } | |
378 | ||
359193ef MA |
379 | static ssize_t show_jint_max_packets(struct device *dev, |
380 | struct device_attribute *attr, | |
381 | char *buf) | |
382 | { | |
383 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
384 | ||
385 | return scnprintf(buf, PAGE_SIZE, "%hu\n", dd->ipath_jint_max_packets); | |
386 | } | |
387 | ||
388 | static ssize_t store_jint_max_packets(struct device *dev, | |
389 | struct device_attribute *attr, | |
390 | const char *buf, | |
391 | size_t count) | |
392 | { | |
393 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
394 | u16 v = 0; | |
395 | int ret; | |
396 | ||
397 | ret = ipath_parse_ushort(buf, &v); | |
398 | if (ret < 0) | |
399 | ipath_dev_err(dd, "invalid jint_max_packets.\n"); | |
400 | else | |
401 | dd->ipath_f_config_jint(dd, dd->ipath_jint_idle_ticks, v); | |
402 | ||
403 | return ret; | |
404 | } | |
405 | ||
406 | static ssize_t show_jint_idle_ticks(struct device *dev, | |
407 | struct device_attribute *attr, | |
408 | char *buf) | |
409 | { | |
410 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
411 | ||
412 | return scnprintf(buf, PAGE_SIZE, "%hu\n", dd->ipath_jint_idle_ticks); | |
413 | } | |
414 | ||
415 | static ssize_t store_jint_idle_ticks(struct device *dev, | |
416 | struct device_attribute *attr, | |
417 | const char *buf, | |
418 | size_t count) | |
419 | { | |
420 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
421 | u16 v = 0; | |
422 | int ret; | |
423 | ||
424 | ret = ipath_parse_ushort(buf, &v); | |
425 | if (ret < 0) | |
426 | ipath_dev_err(dd, "invalid jint_idle_ticks.\n"); | |
427 | else | |
428 | dd->ipath_f_config_jint(dd, v, dd->ipath_jint_max_packets); | |
429 | ||
430 | return ret; | |
431 | } | |
432 | ||
3e9b4a5e BS |
433 | #define DEVICE_COUNTER(name, attr) \ |
434 | static ssize_t show_counter_##name(struct device *dev, \ | |
435 | struct device_attribute *attr, \ | |
436 | char *buf) \ | |
437 | { \ | |
438 | struct ipath_devdata *dd = dev_get_drvdata(dev); \ | |
439 | return scnprintf(\ | |
440 | buf, PAGE_SIZE, "%llu\n", (unsigned long long) \ | |
441 | ipath_snap_cntr( \ | |
442 | dd, offsetof(struct infinipath_counters, \ | |
443 | attr) / sizeof(u64))); \ | |
444 | } \ | |
445 | static DEVICE_ATTR(name, S_IRUGO, show_counter_##name, NULL); | |
446 | ||
447 | DEVICE_COUNTER(ib_link_downeds, IBLinkDownedCnt); | |
448 | DEVICE_COUNTER(ib_link_err_recoveries, IBLinkErrRecoveryCnt); | |
449 | DEVICE_COUNTER(ib_status_changes, IBStatusChangeCnt); | |
450 | DEVICE_COUNTER(ib_symbol_errs, IBSymbolErrCnt); | |
451 | DEVICE_COUNTER(lb_flow_stalls, LBFlowStallCnt); | |
452 | DEVICE_COUNTER(lb_ints, LBIntCnt); | |
453 | DEVICE_COUNTER(rx_bad_formats, RxBadFormatCnt); | |
454 | DEVICE_COUNTER(rx_buf_ovfls, RxBufOvflCnt); | |
455 | DEVICE_COUNTER(rx_data_pkts, RxDataPktCnt); | |
456 | DEVICE_COUNTER(rx_dropped_pkts, RxDroppedPktCnt); | |
457 | DEVICE_COUNTER(rx_dwords, RxDwordCnt); | |
458 | DEVICE_COUNTER(rx_ebps, RxEBPCnt); | |
459 | DEVICE_COUNTER(rx_flow_ctrl_errs, RxFlowCtrlErrCnt); | |
460 | DEVICE_COUNTER(rx_flow_pkts, RxFlowPktCnt); | |
461 | DEVICE_COUNTER(rx_icrc_errs, RxICRCErrCnt); | |
462 | DEVICE_COUNTER(rx_len_errs, RxLenErrCnt); | |
463 | DEVICE_COUNTER(rx_link_problems, RxLinkProblemCnt); | |
464 | DEVICE_COUNTER(rx_lpcrc_errs, RxLPCRCErrCnt); | |
465 | DEVICE_COUNTER(rx_max_min_len_errs, RxMaxMinLenErrCnt); | |
466 | DEVICE_COUNTER(rx_p0_hdr_egr_ovfls, RxP0HdrEgrOvflCnt); | |
467 | DEVICE_COUNTER(rx_p1_hdr_egr_ovfls, RxP1HdrEgrOvflCnt); | |
468 | DEVICE_COUNTER(rx_p2_hdr_egr_ovfls, RxP2HdrEgrOvflCnt); | |
469 | DEVICE_COUNTER(rx_p3_hdr_egr_ovfls, RxP3HdrEgrOvflCnt); | |
470 | DEVICE_COUNTER(rx_p4_hdr_egr_ovfls, RxP4HdrEgrOvflCnt); | |
471 | DEVICE_COUNTER(rx_p5_hdr_egr_ovfls, RxP5HdrEgrOvflCnt); | |
472 | DEVICE_COUNTER(rx_p6_hdr_egr_ovfls, RxP6HdrEgrOvflCnt); | |
473 | DEVICE_COUNTER(rx_p7_hdr_egr_ovfls, RxP7HdrEgrOvflCnt); | |
474 | DEVICE_COUNTER(rx_p8_hdr_egr_ovfls, RxP8HdrEgrOvflCnt); | |
475 | DEVICE_COUNTER(rx_pkey_mismatches, RxPKeyMismatchCnt); | |
476 | DEVICE_COUNTER(rx_tid_full_errs, RxTIDFullErrCnt); | |
477 | DEVICE_COUNTER(rx_tid_valid_errs, RxTIDValidErrCnt); | |
478 | DEVICE_COUNTER(rx_vcrc_errs, RxVCRCErrCnt); | |
479 | DEVICE_COUNTER(tx_data_pkts, TxDataPktCnt); | |
480 | DEVICE_COUNTER(tx_dropped_pkts, TxDroppedPktCnt); | |
481 | DEVICE_COUNTER(tx_dwords, TxDwordCnt); | |
482 | DEVICE_COUNTER(tx_flow_pkts, TxFlowPktCnt); | |
483 | DEVICE_COUNTER(tx_flow_stalls, TxFlowStallCnt); | |
484 | DEVICE_COUNTER(tx_len_errs, TxLenErrCnt); | |
485 | DEVICE_COUNTER(tx_max_min_len_errs, TxMaxMinLenErrCnt); | |
486 | DEVICE_COUNTER(tx_underruns, TxUnderrunCnt); | |
487 | DEVICE_COUNTER(tx_unsup_vl_errs, TxUnsupVLErrCnt); | |
488 | ||
489 | static struct attribute *dev_counter_attributes[] = { | |
490 | &dev_attr_ib_link_downeds.attr, | |
491 | &dev_attr_ib_link_err_recoveries.attr, | |
492 | &dev_attr_ib_status_changes.attr, | |
493 | &dev_attr_ib_symbol_errs.attr, | |
494 | &dev_attr_lb_flow_stalls.attr, | |
495 | &dev_attr_lb_ints.attr, | |
496 | &dev_attr_rx_bad_formats.attr, | |
497 | &dev_attr_rx_buf_ovfls.attr, | |
498 | &dev_attr_rx_data_pkts.attr, | |
499 | &dev_attr_rx_dropped_pkts.attr, | |
500 | &dev_attr_rx_dwords.attr, | |
501 | &dev_attr_rx_ebps.attr, | |
502 | &dev_attr_rx_flow_ctrl_errs.attr, | |
503 | &dev_attr_rx_flow_pkts.attr, | |
504 | &dev_attr_rx_icrc_errs.attr, | |
505 | &dev_attr_rx_len_errs.attr, | |
506 | &dev_attr_rx_link_problems.attr, | |
507 | &dev_attr_rx_lpcrc_errs.attr, | |
508 | &dev_attr_rx_max_min_len_errs.attr, | |
509 | &dev_attr_rx_p0_hdr_egr_ovfls.attr, | |
510 | &dev_attr_rx_p1_hdr_egr_ovfls.attr, | |
511 | &dev_attr_rx_p2_hdr_egr_ovfls.attr, | |
512 | &dev_attr_rx_p3_hdr_egr_ovfls.attr, | |
513 | &dev_attr_rx_p4_hdr_egr_ovfls.attr, | |
514 | &dev_attr_rx_p5_hdr_egr_ovfls.attr, | |
515 | &dev_attr_rx_p6_hdr_egr_ovfls.attr, | |
516 | &dev_attr_rx_p7_hdr_egr_ovfls.attr, | |
517 | &dev_attr_rx_p8_hdr_egr_ovfls.attr, | |
518 | &dev_attr_rx_pkey_mismatches.attr, | |
519 | &dev_attr_rx_tid_full_errs.attr, | |
520 | &dev_attr_rx_tid_valid_errs.attr, | |
521 | &dev_attr_rx_vcrc_errs.attr, | |
522 | &dev_attr_tx_data_pkts.attr, | |
523 | &dev_attr_tx_dropped_pkts.attr, | |
524 | &dev_attr_tx_dwords.attr, | |
525 | &dev_attr_tx_flow_pkts.attr, | |
526 | &dev_attr_tx_flow_stalls.attr, | |
527 | &dev_attr_tx_len_errs.attr, | |
528 | &dev_attr_tx_max_min_len_errs.attr, | |
529 | &dev_attr_tx_underruns.attr, | |
530 | &dev_attr_tx_unsup_vl_errs.attr, | |
531 | NULL | |
532 | }; | |
533 | ||
534 | static struct attribute_group dev_counter_attr_group = { | |
535 | .name = "counters", | |
536 | .attrs = dev_counter_attributes | |
537 | }; | |
538 | ||
539 | static ssize_t store_reset(struct device *dev, | |
540 | struct device_attribute *attr, | |
541 | const char *buf, | |
542 | size_t count) | |
543 | { | |
544 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
545 | int ret; | |
546 | ||
547 | if (count < 5 || memcmp(buf, "reset", 5)) { | |
548 | ret = -EINVAL; | |
549 | goto bail; | |
550 | } | |
551 | ||
552 | if (dd->ipath_flags & IPATH_DISABLED) { | |
553 | /* | |
554 | * post-reset init would re-enable interrupts, etc. | |
555 | * so don't allow reset on disabled devices. Not | |
556 | * perfect error, but about the best choice. | |
557 | */ | |
558 | dev_info(dev,"Unit %d is disabled, can't reset\n", | |
559 | dd->ipath_unit); | |
560 | ret = -EINVAL; | |
2a543904 | 561 | goto bail; |
3e9b4a5e BS |
562 | } |
563 | ret = ipath_reset_device(dd->ipath_unit); | |
564 | bail: | |
565 | return ret<0 ? ret : count; | |
566 | } | |
567 | ||
568 | static ssize_t store_link_state(struct device *dev, | |
569 | struct device_attribute *attr, | |
570 | const char *buf, | |
571 | size_t count) | |
572 | { | |
573 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
574 | int ret, r; | |
575 | u16 state; | |
576 | ||
577 | ret = ipath_parse_ushort(buf, &state); | |
578 | if (ret < 0) | |
579 | goto invalid; | |
580 | ||
34b2aafe | 581 | r = ipath_set_linkstate(dd, state); |
3e9b4a5e BS |
582 | if (r < 0) { |
583 | ret = r; | |
584 | goto bail; | |
585 | } | |
586 | ||
587 | goto bail; | |
588 | invalid: | |
589 | ipath_dev_err(dd, "attempt to set invalid link state\n"); | |
590 | bail: | |
591 | return ret; | |
592 | } | |
593 | ||
594 | static ssize_t show_mtu(struct device *dev, | |
595 | struct device_attribute *attr, | |
596 | char *buf) | |
597 | { | |
598 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
599 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_ibmtu); | |
600 | } | |
601 | ||
602 | static ssize_t store_mtu(struct device *dev, | |
603 | struct device_attribute *attr, | |
604 | const char *buf, | |
605 | size_t count) | |
606 | { | |
607 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
608 | ssize_t ret; | |
609 | u16 mtu = 0; | |
610 | int r; | |
611 | ||
612 | ret = ipath_parse_ushort(buf, &mtu); | |
613 | if (ret < 0) | |
614 | goto invalid; | |
615 | ||
34b2aafe | 616 | r = ipath_set_mtu(dd, mtu); |
3e9b4a5e BS |
617 | if (r < 0) |
618 | ret = r; | |
619 | ||
620 | goto bail; | |
621 | invalid: | |
622 | ipath_dev_err(dd, "attempt to set invalid MTU\n"); | |
623 | bail: | |
624 | return ret; | |
625 | } | |
626 | ||
627 | static ssize_t show_enabled(struct device *dev, | |
628 | struct device_attribute *attr, | |
629 | char *buf) | |
630 | { | |
631 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
632 | return scnprintf(buf, PAGE_SIZE, "%u\n", | |
633 | (dd->ipath_flags & IPATH_DISABLED) ? 0 : 1); | |
634 | } | |
635 | ||
636 | static ssize_t store_enabled(struct device *dev, | |
637 | struct device_attribute *attr, | |
638 | const char *buf, | |
639 | size_t count) | |
640 | { | |
641 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
642 | ssize_t ret; | |
643 | u16 enable = 0; | |
644 | ||
645 | ret = ipath_parse_ushort(buf, &enable); | |
646 | if (ret < 0) { | |
647 | ipath_dev_err(dd, "attempt to use non-numeric on enable\n"); | |
648 | goto bail; | |
649 | } | |
650 | ||
651 | if (enable) { | |
652 | if (!(dd->ipath_flags & IPATH_DISABLED)) | |
653 | goto bail; | |
654 | ||
655 | dev_info(dev, "Enabling unit %d\n", dd->ipath_unit); | |
656 | /* same as post-reset */ | |
657 | ret = ipath_init_chip(dd, 1); | |
658 | if (ret) | |
659 | ipath_dev_err(dd, "Failed to enable unit %d\n", | |
660 | dd->ipath_unit); | |
661 | else { | |
662 | dd->ipath_flags &= ~IPATH_DISABLED; | |
663 | *dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED; | |
664 | } | |
63417188 | 665 | } else if (!(dd->ipath_flags & IPATH_DISABLED)) { |
3e9b4a5e BS |
666 | dev_info(dev, "Disabling unit %d\n", dd->ipath_unit); |
667 | ipath_shutdown_device(dd); | |
668 | dd->ipath_flags |= IPATH_DISABLED; | |
669 | *dd->ipath_statusp |= IPATH_STATUS_ADMIN_DISABLED; | |
670 | } | |
671 | ||
672 | bail: | |
673 | return ret; | |
674 | } | |
675 | ||
30fc5c31 BS |
676 | static ssize_t store_rx_pol_inv(struct device *dev, |
677 | struct device_attribute *attr, | |
678 | const char *buf, | |
679 | size_t count) | |
680 | { | |
681 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
682 | int ret, r; | |
683 | u16 val; | |
684 | ||
685 | ret = ipath_parse_ushort(buf, &val); | |
686 | if (ret < 0) | |
687 | goto invalid; | |
688 | ||
689 | r = ipath_set_rx_pol_inv(dd, val); | |
690 | if (r < 0) { | |
691 | ret = r; | |
692 | goto bail; | |
693 | } | |
694 | ||
695 | goto bail; | |
696 | invalid: | |
697 | ipath_dev_err(dd, "attempt to set invalid Rx Polarity invert\n"); | |
698 | bail: | |
699 | return ret; | |
700 | } | |
701 | ||
82466f00 MA |
702 | static ssize_t store_led_override(struct device *dev, |
703 | struct device_attribute *attr, | |
704 | const char *buf, | |
705 | size_t count) | |
706 | { | |
707 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
708 | int ret; | |
709 | u16 val; | |
710 | ||
711 | ret = ipath_parse_ushort(buf, &val); | |
712 | if (ret > 0) | |
713 | ipath_set_led_override(dd, val); | |
714 | else | |
715 | ipath_dev_err(dd, "attempt to set invalid LED override\n"); | |
716 | return ret; | |
717 | } | |
718 | ||
aecd3b5a MA |
719 | static ssize_t show_logged_errs(struct device *dev, |
720 | struct device_attribute *attr, | |
721 | char *buf) | |
722 | { | |
723 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
724 | int idx, count; | |
725 | ||
726 | /* force consistency with actual EEPROM */ | |
727 | if (ipath_update_eeprom_log(dd) != 0) | |
728 | return -ENXIO; | |
729 | ||
730 | count = 0; | |
731 | for (idx = 0; idx < IPATH_EEP_LOG_CNT; ++idx) { | |
732 | count += scnprintf(buf + count, PAGE_SIZE - count, "%d%c", | |
733 | dd->ipath_eep_st_errs[idx], | |
734 | idx == (IPATH_EEP_LOG_CNT - 1) ? '\n' : ' '); | |
735 | } | |
736 | ||
737 | return count; | |
738 | } | |
30fc5c31 | 739 | |
359193ef MA |
740 | /* |
741 | * New sysfs entries to control various IB config. These all turn into | |
742 | * accesses via ipath_f_get/set_ib_cfg. | |
743 | * | |
744 | * Get/Set heartbeat enable. Or of 1=enabled, 2=auto | |
745 | */ | |
746 | static ssize_t show_hrtbt_enb(struct device *dev, | |
747 | struct device_attribute *attr, | |
748 | char *buf) | |
749 | { | |
750 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
751 | int ret; | |
752 | ||
753 | ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_HRTBT); | |
754 | if (ret >= 0) | |
755 | ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret); | |
756 | return ret; | |
757 | } | |
758 | ||
759 | static ssize_t store_hrtbt_enb(struct device *dev, | |
760 | struct device_attribute *attr, | |
761 | const char *buf, | |
762 | size_t count) | |
763 | { | |
764 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
765 | int ret, r; | |
766 | u16 val; | |
767 | ||
768 | ret = ipath_parse_ushort(buf, &val); | |
769 | if (ret >= 0 && val > 3) | |
770 | ret = -EINVAL; | |
771 | if (ret < 0) { | |
772 | ipath_dev_err(dd, "attempt to set invalid Heartbeat enable\n"); | |
773 | goto bail; | |
774 | } | |
775 | ||
776 | /* | |
777 | * Set the "intentional" heartbeat enable per either of | |
778 | * "Enable" and "Auto", as these are normally set together. | |
779 | * This bit is consulted when leaving loopback mode, | |
780 | * because entering loopback mode overrides it and automatically | |
781 | * disables heartbeat. | |
782 | */ | |
783 | r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_HRTBT, val); | |
784 | if (r < 0) | |
785 | ret = r; | |
786 | else if (val == IPATH_IB_HRTBT_OFF) | |
787 | dd->ipath_flags |= IPATH_NO_HRTBT; | |
788 | else | |
789 | dd->ipath_flags &= ~IPATH_NO_HRTBT; | |
790 | ||
791 | bail: | |
792 | return ret; | |
793 | } | |
794 | ||
795 | /* | |
796 | * Get/Set Link-widths enabled. Or of 1=1x, 2=4x (this is human/IB centric, | |
797 | * _not_ the particular encoding of any given chip) | |
798 | */ | |
799 | static ssize_t show_lwid_enb(struct device *dev, | |
800 | struct device_attribute *attr, | |
801 | char *buf) | |
802 | { | |
803 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
804 | int ret; | |
805 | ||
806 | ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB); | |
807 | if (ret >= 0) | |
808 | ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret); | |
809 | return ret; | |
810 | } | |
811 | ||
812 | static ssize_t store_lwid_enb(struct device *dev, | |
813 | struct device_attribute *attr, | |
814 | const char *buf, | |
815 | size_t count) | |
816 | { | |
817 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
818 | int ret, r; | |
819 | u16 val; | |
820 | ||
821 | ret = ipath_parse_ushort(buf, &val); | |
822 | if (ret >= 0 && (val == 0 || val > 3)) | |
823 | ret = -EINVAL; | |
824 | if (ret < 0) { | |
825 | ipath_dev_err(dd, | |
826 | "attempt to set invalid Link Width (enable)\n"); | |
827 | goto bail; | |
828 | } | |
829 | ||
830 | r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LWID_ENB, val); | |
831 | if (r < 0) | |
832 | ret = r; | |
833 | ||
834 | bail: | |
835 | return ret; | |
836 | } | |
837 | ||
838 | /* Get current link width */ | |
839 | static ssize_t show_lwid(struct device *dev, | |
840 | struct device_attribute *attr, | |
841 | char *buf) | |
842 | ||
843 | { | |
844 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
845 | int ret; | |
846 | ||
847 | ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LWID); | |
848 | if (ret >= 0) | |
849 | ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret); | |
850 | return ret; | |
851 | } | |
852 | ||
853 | /* | |
854 | * Get/Set Link-speeds enabled. Or of 1=SDR 2=DDR. | |
855 | */ | |
856 | static ssize_t show_spd_enb(struct device *dev, | |
857 | struct device_attribute *attr, | |
858 | char *buf) | |
859 | { | |
860 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
861 | int ret; | |
862 | ||
863 | ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB); | |
864 | if (ret >= 0) | |
865 | ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret); | |
866 | return ret; | |
867 | } | |
868 | ||
869 | static ssize_t store_spd_enb(struct device *dev, | |
870 | struct device_attribute *attr, | |
871 | const char *buf, | |
872 | size_t count) | |
873 | { | |
874 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
875 | int ret, r; | |
876 | u16 val; | |
877 | ||
878 | ret = ipath_parse_ushort(buf, &val); | |
879 | if (ret >= 0 && (val == 0 || val > (IPATH_IB_SDR | IPATH_IB_DDR))) | |
880 | ret = -EINVAL; | |
881 | if (ret < 0) { | |
882 | ipath_dev_err(dd, | |
883 | "attempt to set invalid Link Speed (enable)\n"); | |
884 | goto bail; | |
885 | } | |
886 | ||
887 | r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_SPD_ENB, val); | |
888 | if (r < 0) | |
889 | ret = r; | |
890 | ||
891 | bail: | |
892 | return ret; | |
893 | } | |
894 | ||
895 | /* Get current link speed */ | |
896 | static ssize_t show_spd(struct device *dev, | |
897 | struct device_attribute *attr, | |
898 | char *buf) | |
899 | { | |
900 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
901 | int ret; | |
902 | ||
903 | ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_SPD); | |
904 | if (ret >= 0) | |
905 | ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret); | |
906 | return ret; | |
907 | } | |
908 | ||
909 | /* | |
910 | * Get/Set RX polarity-invert enable. 0=no, 1=yes. | |
911 | */ | |
912 | static ssize_t show_rx_polinv_enb(struct device *dev, | |
913 | struct device_attribute *attr, | |
914 | char *buf) | |
915 | { | |
916 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
917 | int ret; | |
918 | ||
919 | ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_RXPOL_ENB); | |
920 | if (ret >= 0) | |
921 | ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret); | |
922 | return ret; | |
923 | } | |
924 | ||
925 | static ssize_t store_rx_polinv_enb(struct device *dev, | |
926 | struct device_attribute *attr, | |
927 | const char *buf, | |
928 | size_t count) | |
929 | { | |
930 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
931 | int ret, r; | |
932 | u16 val; | |
933 | ||
934 | ret = ipath_parse_ushort(buf, &val); | |
bb917144 AJ |
935 | if (ret >= 0 && val > 1) { |
936 | ipath_dev_err(dd, | |
937 | "attempt to set invalid Rx Polarity (enable)\n"); | |
938 | ret = -EINVAL; | |
939 | goto bail; | |
940 | } | |
359193ef MA |
941 | |
942 | r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_RXPOL_ENB, val); | |
bb917144 | 943 | if (r < 0) |
359193ef | 944 | ret = r; |
359193ef | 945 | |
359193ef MA |
946 | bail: |
947 | return ret; | |
948 | } | |
d84e0b28 | 949 | |
359193ef MA |
950 | /* |
951 | * Get/Set RX lane-reversal enable. 0=no, 1=yes. | |
952 | */ | |
953 | static ssize_t show_lanerev_enb(struct device *dev, | |
954 | struct device_attribute *attr, | |
955 | char *buf) | |
956 | { | |
957 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
958 | int ret; | |
959 | ||
960 | ret = dd->ipath_f_get_ib_cfg(dd, IPATH_IB_CFG_LREV_ENB); | |
961 | if (ret >= 0) | |
962 | ret = scnprintf(buf, PAGE_SIZE, "%d\n", ret); | |
963 | return ret; | |
964 | } | |
965 | ||
966 | static ssize_t store_lanerev_enb(struct device *dev, | |
967 | struct device_attribute *attr, | |
968 | const char *buf, | |
969 | size_t count) | |
970 | { | |
971 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
972 | int ret, r; | |
973 | u16 val; | |
974 | ||
975 | ret = ipath_parse_ushort(buf, &val); | |
976 | if (ret >= 0 && val > 1) { | |
977 | ret = -EINVAL; | |
978 | ipath_dev_err(dd, | |
979 | "attempt to set invalid Lane reversal (enable)\n"); | |
980 | goto bail; | |
981 | } | |
982 | ||
983 | r = dd->ipath_f_set_ib_cfg(dd, IPATH_IB_CFG_LREV_ENB, val); | |
984 | if (r < 0) | |
985 | ret = r; | |
986 | ||
987 | bail: | |
988 | return ret; | |
989 | } | |
990 | ||
3e9b4a5e BS |
991 | static DRIVER_ATTR(num_units, S_IRUGO, show_num_units, NULL); |
992 | static DRIVER_ATTR(version, S_IRUGO, show_version, NULL); | |
993 | ||
994 | static struct attribute *driver_attributes[] = { | |
995 | &driver_attr_num_units.attr, | |
996 | &driver_attr_version.attr, | |
997 | NULL | |
998 | }; | |
999 | ||
1000 | static struct attribute_group driver_attr_group = { | |
1001 | .attrs = driver_attributes | |
1002 | }; | |
1003 | ||
d84e0b28 MA |
1004 | static ssize_t store_tempsense(struct device *dev, |
1005 | struct device_attribute *attr, | |
1006 | const char *buf, | |
1007 | size_t count) | |
1008 | { | |
1009 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
1010 | int ret, stat; | |
1011 | u16 val; | |
1012 | ||
1013 | ret = ipath_parse_ushort(buf, &val); | |
1014 | if (ret <= 0) { | |
1015 | ipath_dev_err(dd, "attempt to set invalid tempsense config\n"); | |
1016 | goto bail; | |
1017 | } | |
1018 | /* If anything but the highest limit, enable T_CRIT_A "interrupt" */ | |
1019 | stat = ipath_tempsense_write(dd, 9, (val == 0x7f7f) ? 0x80 : 0); | |
1020 | if (stat) { | |
1021 | ipath_dev_err(dd, "Unable to set tempsense config\n"); | |
1022 | ret = -1; | |
1023 | goto bail; | |
1024 | } | |
1025 | stat = ipath_tempsense_write(dd, 0xB, (u8) (val & 0xFF)); | |
1026 | if (stat) { | |
1027 | ipath_dev_err(dd, "Unable to set local Tcrit\n"); | |
1028 | ret = -1; | |
1029 | goto bail; | |
1030 | } | |
1031 | stat = ipath_tempsense_write(dd, 0xD, (u8) (val >> 8)); | |
1032 | if (stat) { | |
1033 | ipath_dev_err(dd, "Unable to set remote Tcrit\n"); | |
1034 | ret = -1; | |
1035 | goto bail; | |
1036 | } | |
1037 | ||
1038 | bail: | |
1039 | return ret; | |
1040 | } | |
1041 | ||
1042 | /* | |
1043 | * dump tempsense regs. in decimal, to ease shell-scripts. | |
1044 | */ | |
1045 | static ssize_t show_tempsense(struct device *dev, | |
1046 | struct device_attribute *attr, | |
1047 | char *buf) | |
1048 | { | |
1049 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
1050 | int ret; | |
1051 | int idx; | |
1052 | u8 regvals[8]; | |
1053 | ||
1054 | ret = -ENXIO; | |
1055 | for (idx = 0; idx < 8; ++idx) { | |
1056 | if (idx == 6) | |
1057 | continue; | |
1058 | ret = ipath_tempsense_read(dd, idx); | |
1059 | if (ret < 0) | |
1060 | break; | |
1061 | regvals[idx] = ret; | |
1062 | } | |
1063 | if (idx == 8) | |
1064 | ret = scnprintf(buf, PAGE_SIZE, "%d %d %02X %02X %d %d\n", | |
1065 | *(signed char *)(regvals), | |
1066 | *(signed char *)(regvals + 1), | |
1067 | regvals[2], regvals[3], | |
1068 | *(signed char *)(regvals + 5), | |
1069 | *(signed char *)(regvals + 7)); | |
1070 | return ret; | |
1071 | } | |
1072 | ||
a4dbd674 | 1073 | const struct attribute_group *ipath_driver_attr_groups[] = { |
23b9c1ab GKH |
1074 | &driver_attr_group, |
1075 | NULL, | |
1076 | }; | |
1077 | ||
3e9b4a5e | 1078 | static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid); |
15cba26f | 1079 | static DEVICE_ATTR(lmc, S_IWUSR | S_IRUGO, show_lmc, store_lmc); |
3e9b4a5e BS |
1080 | static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid); |
1081 | static DEVICE_ATTR(link_state, S_IWUSR, NULL, store_link_state); | |
1082 | static DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid); | |
1083 | static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu); | |
1084 | static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled); | |
1085 | static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL); | |
9929b0fb | 1086 | static DEVICE_ATTR(nports, S_IRUGO, show_nports, NULL); |
3e9b4a5e BS |
1087 | static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset); |
1088 | static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL); | |
1089 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); | |
1090 | static DEVICE_ATTR(status_str, S_IRUGO, show_status_str, NULL); | |
1091 | static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL); | |
1092 | static DEVICE_ATTR(unit, S_IRUGO, show_unit, NULL); | |
30fc5c31 | 1093 | static DEVICE_ATTR(rx_pol_inv, S_IWUSR, NULL, store_rx_pol_inv); |
82466f00 | 1094 | static DEVICE_ATTR(led_override, S_IWUSR, NULL, store_led_override); |
aecd3b5a | 1095 | static DEVICE_ATTR(logged_errors, S_IRUGO, show_logged_errs, NULL); |
6ca2abf4 | 1096 | static DEVICE_ATTR(localbus_info, S_IRUGO, show_localbus_info, NULL); |
359193ef MA |
1097 | static DEVICE_ATTR(jint_max_packets, S_IWUSR | S_IRUGO, |
1098 | show_jint_max_packets, store_jint_max_packets); | |
1099 | static DEVICE_ATTR(jint_idle_ticks, S_IWUSR | S_IRUGO, | |
1100 | show_jint_idle_ticks, store_jint_idle_ticks); | |
d84e0b28 MA |
1101 | static DEVICE_ATTR(tempsense, S_IWUSR | S_IRUGO, |
1102 | show_tempsense, store_tempsense); | |
3e9b4a5e BS |
1103 | |
1104 | static struct attribute *dev_attributes[] = { | |
1105 | &dev_attr_guid.attr, | |
15cba26f | 1106 | &dev_attr_lmc.attr, |
3e9b4a5e BS |
1107 | &dev_attr_lid.attr, |
1108 | &dev_attr_link_state.attr, | |
1109 | &dev_attr_mlid.attr, | |
1110 | &dev_attr_mtu.attr, | |
1111 | &dev_attr_nguid.attr, | |
9929b0fb | 1112 | &dev_attr_nports.attr, |
3e9b4a5e BS |
1113 | &dev_attr_serial.attr, |
1114 | &dev_attr_status.attr, | |
1115 | &dev_attr_status_str.attr, | |
1116 | &dev_attr_boardversion.attr, | |
1117 | &dev_attr_unit.attr, | |
1118 | &dev_attr_enabled.attr, | |
30fc5c31 | 1119 | &dev_attr_rx_pol_inv.attr, |
82466f00 | 1120 | &dev_attr_led_override.attr, |
aecd3b5a | 1121 | &dev_attr_logged_errors.attr, |
d84e0b28 | 1122 | &dev_attr_tempsense.attr, |
6ca2abf4 | 1123 | &dev_attr_localbus_info.attr, |
3e9b4a5e BS |
1124 | NULL |
1125 | }; | |
1126 | ||
1127 | static struct attribute_group dev_attr_group = { | |
1128 | .attrs = dev_attributes | |
1129 | }; | |
1130 | ||
359193ef MA |
1131 | static DEVICE_ATTR(hrtbt_enable, S_IWUSR | S_IRUGO, show_hrtbt_enb, |
1132 | store_hrtbt_enb); | |
1133 | static DEVICE_ATTR(link_width_enable, S_IWUSR | S_IRUGO, show_lwid_enb, | |
1134 | store_lwid_enb); | |
1135 | static DEVICE_ATTR(link_width, S_IRUGO, show_lwid, NULL); | |
1136 | static DEVICE_ATTR(link_speed_enable, S_IWUSR | S_IRUGO, show_spd_enb, | |
1137 | store_spd_enb); | |
1138 | static DEVICE_ATTR(link_speed, S_IRUGO, show_spd, NULL); | |
1139 | static DEVICE_ATTR(rx_pol_inv_enable, S_IWUSR | S_IRUGO, show_rx_polinv_enb, | |
1140 | store_rx_polinv_enb); | |
1141 | static DEVICE_ATTR(rx_lane_rev_enable, S_IWUSR | S_IRUGO, show_lanerev_enb, | |
1142 | store_lanerev_enb); | |
1143 | ||
1144 | static struct attribute *dev_ibcfg_attributes[] = { | |
1145 | &dev_attr_hrtbt_enable.attr, | |
1146 | &dev_attr_link_width_enable.attr, | |
1147 | &dev_attr_link_width.attr, | |
1148 | &dev_attr_link_speed_enable.attr, | |
1149 | &dev_attr_link_speed.attr, | |
1150 | &dev_attr_rx_pol_inv_enable.attr, | |
1151 | &dev_attr_rx_lane_rev_enable.attr, | |
1152 | NULL | |
1153 | }; | |
1154 | ||
1155 | static struct attribute_group dev_ibcfg_attr_group = { | |
1156 | .attrs = dev_ibcfg_attributes | |
1157 | }; | |
1158 | ||
3e9b4a5e BS |
1159 | /** |
1160 | * ipath_expose_reset - create a device reset file | |
1161 | * @dev: the device structure | |
1162 | * | |
1163 | * Only expose a file that lets us reset the device after someone | |
1164 | * enters diag mode. A device reset is quite likely to crash the | |
1165 | * machine entirely, so we don't want to normally make it | |
1166 | * available. | |
755e4ca4 BS |
1167 | * |
1168 | * Called with ipath_mutex held. | |
3e9b4a5e BS |
1169 | */ |
1170 | int ipath_expose_reset(struct device *dev) | |
1171 | { | |
755e4ca4 BS |
1172 | static int exposed; |
1173 | int ret; | |
1174 | ||
1175 | if (!exposed) { | |
1176 | ret = device_create_file(dev, &dev_attr_reset); | |
1177 | exposed = 1; | |
63417188 | 1178 | } else { |
755e4ca4 | 1179 | ret = 0; |
63417188 | 1180 | } |
755e4ca4 BS |
1181 | |
1182 | return ret; | |
3e9b4a5e BS |
1183 | } |
1184 | ||
3e9b4a5e BS |
1185 | int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd) |
1186 | { | |
1187 | int ret; | |
3e9b4a5e BS |
1188 | |
1189 | ret = sysfs_create_group(&dev->kobj, &dev_attr_group); | |
1190 | if (ret) | |
1191 | goto bail; | |
1192 | ||
1193 | ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group); | |
1194 | if (ret) | |
1195 | goto bail_attrs; | |
1196 | ||
359193ef MA |
1197 | if (dd->ipath_flags & IPATH_HAS_MULT_IB_SPEED) { |
1198 | ret = device_create_file(dev, &dev_attr_jint_idle_ticks); | |
1199 | if (ret) | |
1200 | goto bail_counter; | |
1201 | ret = device_create_file(dev, &dev_attr_jint_max_packets); | |
1202 | if (ret) | |
1203 | goto bail_idle; | |
1204 | ||
1205 | ret = sysfs_create_group(&dev->kobj, &dev_ibcfg_attr_group); | |
1206 | if (ret) | |
1207 | goto bail_max; | |
1208 | } | |
1209 | ||
657c2f2c RD |
1210 | return 0; |
1211 | ||
359193ef MA |
1212 | bail_max: |
1213 | device_remove_file(dev, &dev_attr_jint_max_packets); | |
1214 | bail_idle: | |
1215 | device_remove_file(dev, &dev_attr_jint_idle_ticks); | |
1216 | bail_counter: | |
1217 | sysfs_remove_group(&dev->kobj, &dev_counter_attr_group); | |
3e9b4a5e BS |
1218 | bail_attrs: |
1219 | sysfs_remove_group(&dev->kobj, &dev_attr_group); | |
1220 | bail: | |
1221 | return ret; | |
1222 | } | |
1223 | ||
1224 | void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd) | |
1225 | { | |
3e9b4a5e | 1226 | sysfs_remove_group(&dev->kobj, &dev_counter_attr_group); |
359193ef MA |
1227 | |
1228 | if (dd->ipath_flags & IPATH_HAS_MULT_IB_SPEED) { | |
1229 | sysfs_remove_group(&dev->kobj, &dev_ibcfg_attr_group); | |
1230 | device_remove_file(dev, &dev_attr_jint_idle_ticks); | |
1231 | device_remove_file(dev, &dev_attr_jint_max_packets); | |
1232 | } | |
1233 | ||
3e9b4a5e BS |
1234 | sysfs_remove_group(&dev->kobj, &dev_attr_group); |
1235 | ||
1236 | device_remove_file(dev, &dev_attr_reset); | |
1237 | } |