Commit | Line | Data |
---|---|---|
3e9b4a5e | 1 | /* |
759d5768 | 2 | * Copyright (c) 2006 QLogic, Inc. 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> | |
35 | #include <linux/pci.h> | |
36 | ||
37 | #include "ipath_kernel.h" | |
38 | #include "ips_common.h" | |
39 | #include "ipath_layer.h" | |
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. */ | |
79 | return scnprintf(buf, PAGE_SIZE, "%s", ipath_core_version); | |
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", | |
111 | "OIB_SMA", | |
112 | "SMA", | |
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 | ||
168 | static ssize_t show_lid(struct device *dev, | |
169 | struct device_attribute *attr, | |
170 | char *buf) | |
171 | { | |
172 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
173 | ||
174 | return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_lid); | |
175 | } | |
176 | ||
177 | static ssize_t store_lid(struct device *dev, | |
178 | struct device_attribute *attr, | |
179 | const char *buf, | |
180 | size_t count) | |
181 | { | |
182 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
1eb68b99 | 183 | u16 lid = 0; |
3e9b4a5e BS |
184 | int ret; |
185 | ||
186 | ret = ipath_parse_ushort(buf, &lid); | |
187 | if (ret < 0) | |
188 | goto invalid; | |
189 | ||
85322947 | 190 | if (lid == 0 || lid >= IPS_MULTICAST_LID_BASE) { |
3e9b4a5e BS |
191 | ret = -EINVAL; |
192 | goto invalid; | |
193 | } | |
194 | ||
1eb68b99 | 195 | ipath_set_lid(dd, lid, 0); |
3e9b4a5e BS |
196 | |
197 | goto bail; | |
198 | invalid: | |
1eb68b99 | 199 | ipath_dev_err(dd, "attempt to set invalid LID 0x%x\n", lid); |
3e9b4a5e BS |
200 | bail: |
201 | return ret; | |
202 | } | |
203 | ||
204 | static ssize_t show_mlid(struct device *dev, | |
205 | struct device_attribute *attr, | |
206 | char *buf) | |
207 | { | |
208 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
209 | ||
210 | return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_mlid); | |
211 | } | |
212 | ||
213 | static ssize_t store_mlid(struct device *dev, | |
214 | struct device_attribute *attr, | |
215 | const char *buf, | |
216 | size_t count) | |
217 | { | |
218 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
219 | int unit; | |
220 | u16 mlid; | |
221 | int ret; | |
222 | ||
223 | ret = ipath_parse_ushort(buf, &mlid); | |
85322947 | 224 | if (ret < 0 || mlid < IPS_MULTICAST_LID_BASE) |
3e9b4a5e BS |
225 | goto invalid; |
226 | ||
227 | unit = dd->ipath_unit; | |
228 | ||
229 | dd->ipath_mlid = mlid; | |
3e9b4a5e BS |
230 | ipath_layer_intr(dd, IPATH_LAYER_INT_BCAST); |
231 | ||
232 | goto bail; | |
233 | invalid: | |
234 | ipath_dev_err(dd, "attempt to set invalid MLID\n"); | |
235 | bail: | |
236 | return ret; | |
237 | } | |
238 | ||
239 | static ssize_t show_guid(struct device *dev, | |
240 | struct device_attribute *attr, | |
241 | char *buf) | |
242 | { | |
243 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
244 | u8 *guid; | |
245 | ||
246 | guid = (u8 *) & (dd->ipath_guid); | |
247 | ||
248 | return scnprintf(buf, PAGE_SIZE, | |
249 | "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", | |
250 | guid[0], guid[1], guid[2], guid[3], | |
251 | guid[4], guid[5], guid[6], guid[7]); | |
252 | } | |
253 | ||
254 | static ssize_t store_guid(struct device *dev, | |
255 | struct device_attribute *attr, | |
256 | const char *buf, | |
257 | size_t count) | |
258 | { | |
259 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
260 | ssize_t ret; | |
261 | unsigned short guid[8]; | |
262 | __be64 nguid; | |
263 | u8 *ng; | |
264 | int i; | |
265 | ||
266 | if (sscanf(buf, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx", | |
267 | &guid[0], &guid[1], &guid[2], &guid[3], | |
268 | &guid[4], &guid[5], &guid[6], &guid[7]) != 8) | |
269 | goto invalid; | |
270 | ||
271 | ng = (u8 *) &nguid; | |
272 | ||
273 | for (i = 0; i < 8; i++) { | |
274 | if (guid[i] > 0xff) | |
275 | goto invalid; | |
276 | ng[i] = guid[i]; | |
277 | } | |
278 | ||
279 | dd->ipath_guid = nguid; | |
280 | dd->ipath_nguid = 1; | |
281 | ||
282 | ret = strlen(buf); | |
283 | goto bail; | |
284 | ||
285 | invalid: | |
286 | ipath_dev_err(dd, "attempt to set invalid GUID\n"); | |
287 | ret = -EINVAL; | |
288 | ||
289 | bail: | |
290 | return ret; | |
291 | } | |
292 | ||
293 | static ssize_t show_nguid(struct device *dev, | |
294 | struct device_attribute *attr, | |
295 | char *buf) | |
296 | { | |
297 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
298 | ||
299 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid); | |
300 | } | |
301 | ||
302 | static ssize_t show_serial(struct device *dev, | |
303 | struct device_attribute *attr, | |
304 | char *buf) | |
305 | { | |
306 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
307 | ||
308 | buf[sizeof dd->ipath_serial] = '\0'; | |
309 | memcpy(buf, dd->ipath_serial, sizeof dd->ipath_serial); | |
310 | strcat(buf, "\n"); | |
311 | return strlen(buf); | |
312 | } | |
313 | ||
314 | static ssize_t show_unit(struct device *dev, | |
315 | struct device_attribute *attr, | |
316 | char *buf) | |
317 | { | |
318 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
319 | ||
320 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_unit); | |
321 | } | |
322 | ||
323 | #define DEVICE_COUNTER(name, attr) \ | |
324 | static ssize_t show_counter_##name(struct device *dev, \ | |
325 | struct device_attribute *attr, \ | |
326 | char *buf) \ | |
327 | { \ | |
328 | struct ipath_devdata *dd = dev_get_drvdata(dev); \ | |
329 | return scnprintf(\ | |
330 | buf, PAGE_SIZE, "%llu\n", (unsigned long long) \ | |
331 | ipath_snap_cntr( \ | |
332 | dd, offsetof(struct infinipath_counters, \ | |
333 | attr) / sizeof(u64))); \ | |
334 | } \ | |
335 | static DEVICE_ATTR(name, S_IRUGO, show_counter_##name, NULL); | |
336 | ||
337 | DEVICE_COUNTER(ib_link_downeds, IBLinkDownedCnt); | |
338 | DEVICE_COUNTER(ib_link_err_recoveries, IBLinkErrRecoveryCnt); | |
339 | DEVICE_COUNTER(ib_status_changes, IBStatusChangeCnt); | |
340 | DEVICE_COUNTER(ib_symbol_errs, IBSymbolErrCnt); | |
341 | DEVICE_COUNTER(lb_flow_stalls, LBFlowStallCnt); | |
342 | DEVICE_COUNTER(lb_ints, LBIntCnt); | |
343 | DEVICE_COUNTER(rx_bad_formats, RxBadFormatCnt); | |
344 | DEVICE_COUNTER(rx_buf_ovfls, RxBufOvflCnt); | |
345 | DEVICE_COUNTER(rx_data_pkts, RxDataPktCnt); | |
346 | DEVICE_COUNTER(rx_dropped_pkts, RxDroppedPktCnt); | |
347 | DEVICE_COUNTER(rx_dwords, RxDwordCnt); | |
348 | DEVICE_COUNTER(rx_ebps, RxEBPCnt); | |
349 | DEVICE_COUNTER(rx_flow_ctrl_errs, RxFlowCtrlErrCnt); | |
350 | DEVICE_COUNTER(rx_flow_pkts, RxFlowPktCnt); | |
351 | DEVICE_COUNTER(rx_icrc_errs, RxICRCErrCnt); | |
352 | DEVICE_COUNTER(rx_len_errs, RxLenErrCnt); | |
353 | DEVICE_COUNTER(rx_link_problems, RxLinkProblemCnt); | |
354 | DEVICE_COUNTER(rx_lpcrc_errs, RxLPCRCErrCnt); | |
355 | DEVICE_COUNTER(rx_max_min_len_errs, RxMaxMinLenErrCnt); | |
356 | DEVICE_COUNTER(rx_p0_hdr_egr_ovfls, RxP0HdrEgrOvflCnt); | |
357 | DEVICE_COUNTER(rx_p1_hdr_egr_ovfls, RxP1HdrEgrOvflCnt); | |
358 | DEVICE_COUNTER(rx_p2_hdr_egr_ovfls, RxP2HdrEgrOvflCnt); | |
359 | DEVICE_COUNTER(rx_p3_hdr_egr_ovfls, RxP3HdrEgrOvflCnt); | |
360 | DEVICE_COUNTER(rx_p4_hdr_egr_ovfls, RxP4HdrEgrOvflCnt); | |
361 | DEVICE_COUNTER(rx_p5_hdr_egr_ovfls, RxP5HdrEgrOvflCnt); | |
362 | DEVICE_COUNTER(rx_p6_hdr_egr_ovfls, RxP6HdrEgrOvflCnt); | |
363 | DEVICE_COUNTER(rx_p7_hdr_egr_ovfls, RxP7HdrEgrOvflCnt); | |
364 | DEVICE_COUNTER(rx_p8_hdr_egr_ovfls, RxP8HdrEgrOvflCnt); | |
365 | DEVICE_COUNTER(rx_pkey_mismatches, RxPKeyMismatchCnt); | |
366 | DEVICE_COUNTER(rx_tid_full_errs, RxTIDFullErrCnt); | |
367 | DEVICE_COUNTER(rx_tid_valid_errs, RxTIDValidErrCnt); | |
368 | DEVICE_COUNTER(rx_vcrc_errs, RxVCRCErrCnt); | |
369 | DEVICE_COUNTER(tx_data_pkts, TxDataPktCnt); | |
370 | DEVICE_COUNTER(tx_dropped_pkts, TxDroppedPktCnt); | |
371 | DEVICE_COUNTER(tx_dwords, TxDwordCnt); | |
372 | DEVICE_COUNTER(tx_flow_pkts, TxFlowPktCnt); | |
373 | DEVICE_COUNTER(tx_flow_stalls, TxFlowStallCnt); | |
374 | DEVICE_COUNTER(tx_len_errs, TxLenErrCnt); | |
375 | DEVICE_COUNTER(tx_max_min_len_errs, TxMaxMinLenErrCnt); | |
376 | DEVICE_COUNTER(tx_underruns, TxUnderrunCnt); | |
377 | DEVICE_COUNTER(tx_unsup_vl_errs, TxUnsupVLErrCnt); | |
378 | ||
379 | static struct attribute *dev_counter_attributes[] = { | |
380 | &dev_attr_ib_link_downeds.attr, | |
381 | &dev_attr_ib_link_err_recoveries.attr, | |
382 | &dev_attr_ib_status_changes.attr, | |
383 | &dev_attr_ib_symbol_errs.attr, | |
384 | &dev_attr_lb_flow_stalls.attr, | |
385 | &dev_attr_lb_ints.attr, | |
386 | &dev_attr_rx_bad_formats.attr, | |
387 | &dev_attr_rx_buf_ovfls.attr, | |
388 | &dev_attr_rx_data_pkts.attr, | |
389 | &dev_attr_rx_dropped_pkts.attr, | |
390 | &dev_attr_rx_dwords.attr, | |
391 | &dev_attr_rx_ebps.attr, | |
392 | &dev_attr_rx_flow_ctrl_errs.attr, | |
393 | &dev_attr_rx_flow_pkts.attr, | |
394 | &dev_attr_rx_icrc_errs.attr, | |
395 | &dev_attr_rx_len_errs.attr, | |
396 | &dev_attr_rx_link_problems.attr, | |
397 | &dev_attr_rx_lpcrc_errs.attr, | |
398 | &dev_attr_rx_max_min_len_errs.attr, | |
399 | &dev_attr_rx_p0_hdr_egr_ovfls.attr, | |
400 | &dev_attr_rx_p1_hdr_egr_ovfls.attr, | |
401 | &dev_attr_rx_p2_hdr_egr_ovfls.attr, | |
402 | &dev_attr_rx_p3_hdr_egr_ovfls.attr, | |
403 | &dev_attr_rx_p4_hdr_egr_ovfls.attr, | |
404 | &dev_attr_rx_p5_hdr_egr_ovfls.attr, | |
405 | &dev_attr_rx_p6_hdr_egr_ovfls.attr, | |
406 | &dev_attr_rx_p7_hdr_egr_ovfls.attr, | |
407 | &dev_attr_rx_p8_hdr_egr_ovfls.attr, | |
408 | &dev_attr_rx_pkey_mismatches.attr, | |
409 | &dev_attr_rx_tid_full_errs.attr, | |
410 | &dev_attr_rx_tid_valid_errs.attr, | |
411 | &dev_attr_rx_vcrc_errs.attr, | |
412 | &dev_attr_tx_data_pkts.attr, | |
413 | &dev_attr_tx_dropped_pkts.attr, | |
414 | &dev_attr_tx_dwords.attr, | |
415 | &dev_attr_tx_flow_pkts.attr, | |
416 | &dev_attr_tx_flow_stalls.attr, | |
417 | &dev_attr_tx_len_errs.attr, | |
418 | &dev_attr_tx_max_min_len_errs.attr, | |
419 | &dev_attr_tx_underruns.attr, | |
420 | &dev_attr_tx_unsup_vl_errs.attr, | |
421 | NULL | |
422 | }; | |
423 | ||
424 | static struct attribute_group dev_counter_attr_group = { | |
425 | .name = "counters", | |
426 | .attrs = dev_counter_attributes | |
427 | }; | |
428 | ||
429 | static ssize_t store_reset(struct device *dev, | |
430 | struct device_attribute *attr, | |
431 | const char *buf, | |
432 | size_t count) | |
433 | { | |
434 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
435 | int ret; | |
436 | ||
437 | if (count < 5 || memcmp(buf, "reset", 5)) { | |
438 | ret = -EINVAL; | |
439 | goto bail; | |
440 | } | |
441 | ||
442 | if (dd->ipath_flags & IPATH_DISABLED) { | |
443 | /* | |
444 | * post-reset init would re-enable interrupts, etc. | |
445 | * so don't allow reset on disabled devices. Not | |
446 | * perfect error, but about the best choice. | |
447 | */ | |
448 | dev_info(dev,"Unit %d is disabled, can't reset\n", | |
449 | dd->ipath_unit); | |
450 | ret = -EINVAL; | |
451 | } | |
452 | ret = ipath_reset_device(dd->ipath_unit); | |
453 | bail: | |
454 | return ret<0 ? ret : count; | |
455 | } | |
456 | ||
457 | static ssize_t store_link_state(struct device *dev, | |
458 | struct device_attribute *attr, | |
459 | const char *buf, | |
460 | size_t count) | |
461 | { | |
462 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
463 | int ret, r; | |
464 | u16 state; | |
465 | ||
466 | ret = ipath_parse_ushort(buf, &state); | |
467 | if (ret < 0) | |
468 | goto invalid; | |
469 | ||
470 | r = ipath_layer_set_linkstate(dd, state); | |
471 | if (r < 0) { | |
472 | ret = r; | |
473 | goto bail; | |
474 | } | |
475 | ||
476 | goto bail; | |
477 | invalid: | |
478 | ipath_dev_err(dd, "attempt to set invalid link state\n"); | |
479 | bail: | |
480 | return ret; | |
481 | } | |
482 | ||
483 | static ssize_t show_mtu(struct device *dev, | |
484 | struct device_attribute *attr, | |
485 | char *buf) | |
486 | { | |
487 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
488 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_ibmtu); | |
489 | } | |
490 | ||
491 | static ssize_t store_mtu(struct device *dev, | |
492 | struct device_attribute *attr, | |
493 | const char *buf, | |
494 | size_t count) | |
495 | { | |
496 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
497 | ssize_t ret; | |
498 | u16 mtu = 0; | |
499 | int r; | |
500 | ||
501 | ret = ipath_parse_ushort(buf, &mtu); | |
502 | if (ret < 0) | |
503 | goto invalid; | |
504 | ||
505 | r = ipath_layer_set_mtu(dd, mtu); | |
506 | if (r < 0) | |
507 | ret = r; | |
508 | ||
509 | goto bail; | |
510 | invalid: | |
511 | ipath_dev_err(dd, "attempt to set invalid MTU\n"); | |
512 | bail: | |
513 | return ret; | |
514 | } | |
515 | ||
516 | static ssize_t show_enabled(struct device *dev, | |
517 | struct device_attribute *attr, | |
518 | char *buf) | |
519 | { | |
520 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
521 | return scnprintf(buf, PAGE_SIZE, "%u\n", | |
522 | (dd->ipath_flags & IPATH_DISABLED) ? 0 : 1); | |
523 | } | |
524 | ||
525 | static ssize_t store_enabled(struct device *dev, | |
526 | struct device_attribute *attr, | |
527 | const char *buf, | |
528 | size_t count) | |
529 | { | |
530 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
531 | ssize_t ret; | |
532 | u16 enable = 0; | |
533 | ||
534 | ret = ipath_parse_ushort(buf, &enable); | |
535 | if (ret < 0) { | |
536 | ipath_dev_err(dd, "attempt to use non-numeric on enable\n"); | |
537 | goto bail; | |
538 | } | |
539 | ||
540 | if (enable) { | |
541 | if (!(dd->ipath_flags & IPATH_DISABLED)) | |
542 | goto bail; | |
543 | ||
544 | dev_info(dev, "Enabling unit %d\n", dd->ipath_unit); | |
545 | /* same as post-reset */ | |
546 | ret = ipath_init_chip(dd, 1); | |
547 | if (ret) | |
548 | ipath_dev_err(dd, "Failed to enable unit %d\n", | |
549 | dd->ipath_unit); | |
550 | else { | |
551 | dd->ipath_flags &= ~IPATH_DISABLED; | |
552 | *dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED; | |
553 | } | |
554 | } | |
555 | else if (!(dd->ipath_flags & IPATH_DISABLED)) { | |
556 | dev_info(dev, "Disabling unit %d\n", dd->ipath_unit); | |
557 | ipath_shutdown_device(dd); | |
558 | dd->ipath_flags |= IPATH_DISABLED; | |
559 | *dd->ipath_statusp |= IPATH_STATUS_ADMIN_DISABLED; | |
560 | } | |
561 | ||
562 | bail: | |
563 | return ret; | |
564 | } | |
565 | ||
566 | static DRIVER_ATTR(num_units, S_IRUGO, show_num_units, NULL); | |
567 | static DRIVER_ATTR(version, S_IRUGO, show_version, NULL); | |
568 | ||
569 | static struct attribute *driver_attributes[] = { | |
570 | &driver_attr_num_units.attr, | |
571 | &driver_attr_version.attr, | |
572 | NULL | |
573 | }; | |
574 | ||
575 | static struct attribute_group driver_attr_group = { | |
576 | .attrs = driver_attributes | |
577 | }; | |
578 | ||
579 | static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid); | |
580 | static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid); | |
581 | static DEVICE_ATTR(link_state, S_IWUSR, NULL, store_link_state); | |
582 | static DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid); | |
583 | static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu); | |
584 | static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled); | |
585 | static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL); | |
586 | static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset); | |
587 | static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL); | |
588 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); | |
589 | static DEVICE_ATTR(status_str, S_IRUGO, show_status_str, NULL); | |
590 | static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL); | |
591 | static DEVICE_ATTR(unit, S_IRUGO, show_unit, NULL); | |
592 | ||
593 | static struct attribute *dev_attributes[] = { | |
594 | &dev_attr_guid.attr, | |
595 | &dev_attr_lid.attr, | |
596 | &dev_attr_link_state.attr, | |
597 | &dev_attr_mlid.attr, | |
598 | &dev_attr_mtu.attr, | |
599 | &dev_attr_nguid.attr, | |
600 | &dev_attr_serial.attr, | |
601 | &dev_attr_status.attr, | |
602 | &dev_attr_status_str.attr, | |
603 | &dev_attr_boardversion.attr, | |
604 | &dev_attr_unit.attr, | |
605 | &dev_attr_enabled.attr, | |
606 | NULL | |
607 | }; | |
608 | ||
609 | static struct attribute_group dev_attr_group = { | |
610 | .attrs = dev_attributes | |
611 | }; | |
612 | ||
613 | /** | |
614 | * ipath_expose_reset - create a device reset file | |
615 | * @dev: the device structure | |
616 | * | |
617 | * Only expose a file that lets us reset the device after someone | |
618 | * enters diag mode. A device reset is quite likely to crash the | |
619 | * machine entirely, so we don't want to normally make it | |
620 | * available. | |
755e4ca4 BS |
621 | * |
622 | * Called with ipath_mutex held. | |
3e9b4a5e BS |
623 | */ |
624 | int ipath_expose_reset(struct device *dev) | |
625 | { | |
755e4ca4 BS |
626 | static int exposed; |
627 | int ret; | |
628 | ||
629 | if (!exposed) { | |
630 | ret = device_create_file(dev, &dev_attr_reset); | |
631 | exposed = 1; | |
632 | } | |
633 | else | |
634 | ret = 0; | |
635 | ||
636 | return ret; | |
3e9b4a5e BS |
637 | } |
638 | ||
639 | int ipath_driver_create_group(struct device_driver *drv) | |
640 | { | |
641 | int ret; | |
642 | ||
643 | ret = sysfs_create_group(&drv->kobj, &driver_attr_group); | |
3e9b4a5e | 644 | |
3e9b4a5e BS |
645 | return ret; |
646 | } | |
647 | ||
648 | void ipath_driver_remove_group(struct device_driver *drv) | |
649 | { | |
3e9b4a5e BS |
650 | sysfs_remove_group(&drv->kobj, &driver_attr_group); |
651 | } | |
652 | ||
653 | int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd) | |
654 | { | |
655 | int ret; | |
656 | char unit[5]; | |
657 | ||
658 | ret = sysfs_create_group(&dev->kobj, &dev_attr_group); | |
659 | if (ret) | |
660 | goto bail; | |
661 | ||
662 | ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group); | |
663 | if (ret) | |
664 | goto bail_attrs; | |
665 | ||
666 | snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit); | |
667 | ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit); | |
668 | if (ret == 0) | |
669 | goto bail; | |
670 | ||
671 | sysfs_remove_group(&dev->kobj, &dev_counter_attr_group); | |
672 | bail_attrs: | |
673 | sysfs_remove_group(&dev->kobj, &dev_attr_group); | |
674 | bail: | |
675 | return ret; | |
676 | } | |
677 | ||
678 | void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd) | |
679 | { | |
680 | char unit[5]; | |
681 | ||
682 | snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit); | |
683 | sysfs_remove_link(&dev->driver->kobj, unit); | |
684 | ||
685 | sysfs_remove_group(&dev->kobj, &dev_counter_attr_group); | |
686 | sysfs_remove_group(&dev->kobj, &dev_attr_group); | |
687 | ||
688 | device_remove_file(dev, &dev_attr_reset); | |
689 | } |