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" | |
27b678dd | 38 | #include "ipath_common.h" |
3e9b4a5e BS |
39 | |
40 | /** | |
41 | * ipath_parse_ushort - parse an unsigned short value in an arbitrary base | |
42 | * @str: the string containing the number | |
43 | * @valp: where to put the result | |
44 | * | |
45 | * returns the number of bytes consumed, or negative value on error | |
46 | */ | |
47 | int ipath_parse_ushort(const char *str, unsigned short *valp) | |
48 | { | |
49 | unsigned long val; | |
50 | char *end; | |
51 | int ret; | |
52 | ||
53 | if (!isdigit(str[0])) { | |
54 | ret = -EINVAL; | |
55 | goto bail; | |
56 | } | |
57 | ||
58 | val = simple_strtoul(str, &end, 0); | |
59 | ||
60 | if (val > 0xffff) { | |
61 | ret = -EINVAL; | |
62 | goto bail; | |
63 | } | |
64 | ||
65 | *valp = val; | |
66 | ||
67 | ret = end + 1 - str; | |
68 | if (ret == 0) | |
69 | ret = -EINVAL; | |
70 | ||
71 | bail: | |
72 | return ret; | |
73 | } | |
74 | ||
75 | static ssize_t show_version(struct device_driver *dev, char *buf) | |
76 | { | |
77 | /* The string printed here is already newline-terminated. */ | |
b55f4f06 | 78 | return scnprintf(buf, PAGE_SIZE, "%s", ib_ipath_version); |
3e9b4a5e BS |
79 | } |
80 | ||
81 | static ssize_t show_num_units(struct device_driver *dev, char *buf) | |
82 | { | |
83 | return scnprintf(buf, PAGE_SIZE, "%d\n", | |
84 | ipath_count_units(NULL, NULL, NULL)); | |
85 | } | |
86 | ||
3e9b4a5e BS |
87 | static ssize_t show_status(struct device *dev, |
88 | struct device_attribute *attr, | |
89 | char *buf) | |
90 | { | |
91 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
92 | ssize_t ret; | |
93 | ||
94 | if (!dd->ipath_statusp) { | |
95 | ret = -EINVAL; | |
96 | goto bail; | |
97 | } | |
98 | ||
99 | ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n", | |
100 | (unsigned long long) *(dd->ipath_statusp)); | |
101 | ||
102 | bail: | |
103 | return ret; | |
104 | } | |
105 | ||
106 | static const char *ipath_status_str[] = { | |
107 | "Initted", | |
108 | "Disabled", | |
109 | "Admin_Disabled", | |
0fd41363 BS |
110 | "", /* This used to be the old "OIB_SMA" status. */ |
111 | "", /* This used to be the old "SMA" status. */ | |
3e9b4a5e BS |
112 | "Present", |
113 | "IB_link_up", | |
114 | "IB_configured", | |
115 | "NoIBcable", | |
116 | "Fatal_Hardware_Error", | |
117 | NULL, | |
118 | }; | |
119 | ||
120 | static ssize_t show_status_str(struct device *dev, | |
121 | struct device_attribute *attr, | |
122 | char *buf) | |
123 | { | |
124 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
125 | int i, any; | |
126 | u64 s; | |
127 | ssize_t ret; | |
128 | ||
129 | if (!dd->ipath_statusp) { | |
130 | ret = -EINVAL; | |
131 | goto bail; | |
132 | } | |
133 | ||
134 | s = *(dd->ipath_statusp); | |
135 | *buf = '\0'; | |
136 | for (any = i = 0; s && ipath_status_str[i]; i++) { | |
137 | if (s & 1) { | |
138 | if (any && strlcat(buf, " ", PAGE_SIZE) >= | |
139 | PAGE_SIZE) | |
140 | /* overflow */ | |
141 | break; | |
142 | if (strlcat(buf, ipath_status_str[i], | |
143 | PAGE_SIZE) >= PAGE_SIZE) | |
144 | break; | |
145 | any = 1; | |
146 | } | |
147 | s >>= 1; | |
148 | } | |
149 | if (any) | |
150 | strlcat(buf, "\n", PAGE_SIZE); | |
151 | ||
152 | ret = strlen(buf); | |
153 | ||
154 | bail: | |
155 | return ret; | |
156 | } | |
157 | ||
158 | static ssize_t show_boardversion(struct device *dev, | |
159 | struct device_attribute *attr, | |
160 | char *buf) | |
161 | { | |
162 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
163 | /* The string printed here is already newline-terminated. */ | |
164 | return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_boardversion); | |
165 | } | |
166 | ||
167 | static ssize_t show_lid(struct device *dev, | |
168 | struct device_attribute *attr, | |
169 | char *buf) | |
170 | { | |
171 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
172 | ||
173 | return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_lid); | |
174 | } | |
175 | ||
176 | static ssize_t store_lid(struct device *dev, | |
177 | struct device_attribute *attr, | |
178 | const char *buf, | |
179 | size_t count) | |
180 | { | |
181 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
1eb68b99 | 182 | u16 lid = 0; |
3e9b4a5e BS |
183 | int ret; |
184 | ||
185 | ret = ipath_parse_ushort(buf, &lid); | |
186 | if (ret < 0) | |
187 | goto invalid; | |
188 | ||
27b678dd | 189 | if (lid == 0 || lid >= IPATH_MULTICAST_LID_BASE) { |
3e9b4a5e BS |
190 | ret = -EINVAL; |
191 | goto invalid; | |
192 | } | |
193 | ||
1eb68b99 | 194 | ipath_set_lid(dd, lid, 0); |
3e9b4a5e BS |
195 | |
196 | goto bail; | |
197 | invalid: | |
1eb68b99 | 198 | ipath_dev_err(dd, "attempt to set invalid LID 0x%x\n", lid); |
3e9b4a5e BS |
199 | bail: |
200 | return ret; | |
201 | } | |
202 | ||
203 | static ssize_t show_mlid(struct device *dev, | |
204 | struct device_attribute *attr, | |
205 | char *buf) | |
206 | { | |
207 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
208 | ||
209 | return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_mlid); | |
210 | } | |
211 | ||
212 | static ssize_t store_mlid(struct device *dev, | |
213 | struct device_attribute *attr, | |
214 | const char *buf, | |
215 | size_t count) | |
216 | { | |
217 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
218 | int unit; | |
219 | u16 mlid; | |
220 | int ret; | |
221 | ||
222 | ret = ipath_parse_ushort(buf, &mlid); | |
27b678dd | 223 | if (ret < 0 || mlid < IPATH_MULTICAST_LID_BASE) |
3e9b4a5e BS |
224 | goto invalid; |
225 | ||
226 | unit = dd->ipath_unit; | |
227 | ||
228 | dd->ipath_mlid = mlid; | |
3e9b4a5e BS |
229 | |
230 | goto bail; | |
231 | invalid: | |
232 | ipath_dev_err(dd, "attempt to set invalid MLID\n"); | |
233 | bail: | |
234 | return ret; | |
235 | } | |
236 | ||
237 | static ssize_t show_guid(struct device *dev, | |
238 | struct device_attribute *attr, | |
239 | char *buf) | |
240 | { | |
241 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
242 | u8 *guid; | |
243 | ||
244 | guid = (u8 *) & (dd->ipath_guid); | |
245 | ||
246 | return scnprintf(buf, PAGE_SIZE, | |
247 | "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", | |
248 | guid[0], guid[1], guid[2], guid[3], | |
249 | guid[4], guid[5], guid[6], guid[7]); | |
250 | } | |
251 | ||
252 | static ssize_t store_guid(struct device *dev, | |
253 | struct device_attribute *attr, | |
254 | const char *buf, | |
255 | size_t count) | |
256 | { | |
257 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
258 | ssize_t ret; | |
259 | unsigned short guid[8]; | |
260 | __be64 nguid; | |
261 | u8 *ng; | |
262 | int i; | |
263 | ||
264 | if (sscanf(buf, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx", | |
265 | &guid[0], &guid[1], &guid[2], &guid[3], | |
266 | &guid[4], &guid[5], &guid[6], &guid[7]) != 8) | |
267 | goto invalid; | |
268 | ||
269 | ng = (u8 *) &nguid; | |
270 | ||
271 | for (i = 0; i < 8; i++) { | |
272 | if (guid[i] > 0xff) | |
273 | goto invalid; | |
274 | ng[i] = guid[i]; | |
275 | } | |
276 | ||
277 | dd->ipath_guid = nguid; | |
278 | dd->ipath_nguid = 1; | |
279 | ||
280 | ret = strlen(buf); | |
281 | goto bail; | |
282 | ||
283 | invalid: | |
284 | ipath_dev_err(dd, "attempt to set invalid GUID\n"); | |
285 | ret = -EINVAL; | |
286 | ||
287 | bail: | |
288 | return ret; | |
289 | } | |
290 | ||
291 | static ssize_t show_nguid(struct device *dev, | |
292 | struct device_attribute *attr, | |
293 | char *buf) | |
294 | { | |
295 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
296 | ||
297 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid); | |
298 | } | |
299 | ||
9929b0fb BS |
300 | static ssize_t show_nports(struct device *dev, |
301 | struct device_attribute *attr, | |
302 | char *buf) | |
303 | { | |
304 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
305 | ||
306 | /* Return the number of user ports available. */ | |
307 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_cfgports - 1); | |
308 | } | |
309 | ||
3e9b4a5e BS |
310 | static ssize_t show_serial(struct device *dev, |
311 | struct device_attribute *attr, | |
312 | char *buf) | |
313 | { | |
314 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
315 | ||
316 | buf[sizeof dd->ipath_serial] = '\0'; | |
317 | memcpy(buf, dd->ipath_serial, sizeof dd->ipath_serial); | |
318 | strcat(buf, "\n"); | |
319 | return strlen(buf); | |
320 | } | |
321 | ||
322 | static ssize_t show_unit(struct device *dev, | |
323 | struct device_attribute *attr, | |
324 | char *buf) | |
325 | { | |
326 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
327 | ||
328 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_unit); | |
329 | } | |
330 | ||
331 | #define DEVICE_COUNTER(name, attr) \ | |
332 | static ssize_t show_counter_##name(struct device *dev, \ | |
333 | struct device_attribute *attr, \ | |
334 | char *buf) \ | |
335 | { \ | |
336 | struct ipath_devdata *dd = dev_get_drvdata(dev); \ | |
337 | return scnprintf(\ | |
338 | buf, PAGE_SIZE, "%llu\n", (unsigned long long) \ | |
339 | ipath_snap_cntr( \ | |
340 | dd, offsetof(struct infinipath_counters, \ | |
341 | attr) / sizeof(u64))); \ | |
342 | } \ | |
343 | static DEVICE_ATTR(name, S_IRUGO, show_counter_##name, NULL); | |
344 | ||
345 | DEVICE_COUNTER(ib_link_downeds, IBLinkDownedCnt); | |
346 | DEVICE_COUNTER(ib_link_err_recoveries, IBLinkErrRecoveryCnt); | |
347 | DEVICE_COUNTER(ib_status_changes, IBStatusChangeCnt); | |
348 | DEVICE_COUNTER(ib_symbol_errs, IBSymbolErrCnt); | |
349 | DEVICE_COUNTER(lb_flow_stalls, LBFlowStallCnt); | |
350 | DEVICE_COUNTER(lb_ints, LBIntCnt); | |
351 | DEVICE_COUNTER(rx_bad_formats, RxBadFormatCnt); | |
352 | DEVICE_COUNTER(rx_buf_ovfls, RxBufOvflCnt); | |
353 | DEVICE_COUNTER(rx_data_pkts, RxDataPktCnt); | |
354 | DEVICE_COUNTER(rx_dropped_pkts, RxDroppedPktCnt); | |
355 | DEVICE_COUNTER(rx_dwords, RxDwordCnt); | |
356 | DEVICE_COUNTER(rx_ebps, RxEBPCnt); | |
357 | DEVICE_COUNTER(rx_flow_ctrl_errs, RxFlowCtrlErrCnt); | |
358 | DEVICE_COUNTER(rx_flow_pkts, RxFlowPktCnt); | |
359 | DEVICE_COUNTER(rx_icrc_errs, RxICRCErrCnt); | |
360 | DEVICE_COUNTER(rx_len_errs, RxLenErrCnt); | |
361 | DEVICE_COUNTER(rx_link_problems, RxLinkProblemCnt); | |
362 | DEVICE_COUNTER(rx_lpcrc_errs, RxLPCRCErrCnt); | |
363 | DEVICE_COUNTER(rx_max_min_len_errs, RxMaxMinLenErrCnt); | |
364 | DEVICE_COUNTER(rx_p0_hdr_egr_ovfls, RxP0HdrEgrOvflCnt); | |
365 | DEVICE_COUNTER(rx_p1_hdr_egr_ovfls, RxP1HdrEgrOvflCnt); | |
366 | DEVICE_COUNTER(rx_p2_hdr_egr_ovfls, RxP2HdrEgrOvflCnt); | |
367 | DEVICE_COUNTER(rx_p3_hdr_egr_ovfls, RxP3HdrEgrOvflCnt); | |
368 | DEVICE_COUNTER(rx_p4_hdr_egr_ovfls, RxP4HdrEgrOvflCnt); | |
369 | DEVICE_COUNTER(rx_p5_hdr_egr_ovfls, RxP5HdrEgrOvflCnt); | |
370 | DEVICE_COUNTER(rx_p6_hdr_egr_ovfls, RxP6HdrEgrOvflCnt); | |
371 | DEVICE_COUNTER(rx_p7_hdr_egr_ovfls, RxP7HdrEgrOvflCnt); | |
372 | DEVICE_COUNTER(rx_p8_hdr_egr_ovfls, RxP8HdrEgrOvflCnt); | |
373 | DEVICE_COUNTER(rx_pkey_mismatches, RxPKeyMismatchCnt); | |
374 | DEVICE_COUNTER(rx_tid_full_errs, RxTIDFullErrCnt); | |
375 | DEVICE_COUNTER(rx_tid_valid_errs, RxTIDValidErrCnt); | |
376 | DEVICE_COUNTER(rx_vcrc_errs, RxVCRCErrCnt); | |
377 | DEVICE_COUNTER(tx_data_pkts, TxDataPktCnt); | |
378 | DEVICE_COUNTER(tx_dropped_pkts, TxDroppedPktCnt); | |
379 | DEVICE_COUNTER(tx_dwords, TxDwordCnt); | |
380 | DEVICE_COUNTER(tx_flow_pkts, TxFlowPktCnt); | |
381 | DEVICE_COUNTER(tx_flow_stalls, TxFlowStallCnt); | |
382 | DEVICE_COUNTER(tx_len_errs, TxLenErrCnt); | |
383 | DEVICE_COUNTER(tx_max_min_len_errs, TxMaxMinLenErrCnt); | |
384 | DEVICE_COUNTER(tx_underruns, TxUnderrunCnt); | |
385 | DEVICE_COUNTER(tx_unsup_vl_errs, TxUnsupVLErrCnt); | |
386 | ||
387 | static struct attribute *dev_counter_attributes[] = { | |
388 | &dev_attr_ib_link_downeds.attr, | |
389 | &dev_attr_ib_link_err_recoveries.attr, | |
390 | &dev_attr_ib_status_changes.attr, | |
391 | &dev_attr_ib_symbol_errs.attr, | |
392 | &dev_attr_lb_flow_stalls.attr, | |
393 | &dev_attr_lb_ints.attr, | |
394 | &dev_attr_rx_bad_formats.attr, | |
395 | &dev_attr_rx_buf_ovfls.attr, | |
396 | &dev_attr_rx_data_pkts.attr, | |
397 | &dev_attr_rx_dropped_pkts.attr, | |
398 | &dev_attr_rx_dwords.attr, | |
399 | &dev_attr_rx_ebps.attr, | |
400 | &dev_attr_rx_flow_ctrl_errs.attr, | |
401 | &dev_attr_rx_flow_pkts.attr, | |
402 | &dev_attr_rx_icrc_errs.attr, | |
403 | &dev_attr_rx_len_errs.attr, | |
404 | &dev_attr_rx_link_problems.attr, | |
405 | &dev_attr_rx_lpcrc_errs.attr, | |
406 | &dev_attr_rx_max_min_len_errs.attr, | |
407 | &dev_attr_rx_p0_hdr_egr_ovfls.attr, | |
408 | &dev_attr_rx_p1_hdr_egr_ovfls.attr, | |
409 | &dev_attr_rx_p2_hdr_egr_ovfls.attr, | |
410 | &dev_attr_rx_p3_hdr_egr_ovfls.attr, | |
411 | &dev_attr_rx_p4_hdr_egr_ovfls.attr, | |
412 | &dev_attr_rx_p5_hdr_egr_ovfls.attr, | |
413 | &dev_attr_rx_p6_hdr_egr_ovfls.attr, | |
414 | &dev_attr_rx_p7_hdr_egr_ovfls.attr, | |
415 | &dev_attr_rx_p8_hdr_egr_ovfls.attr, | |
416 | &dev_attr_rx_pkey_mismatches.attr, | |
417 | &dev_attr_rx_tid_full_errs.attr, | |
418 | &dev_attr_rx_tid_valid_errs.attr, | |
419 | &dev_attr_rx_vcrc_errs.attr, | |
420 | &dev_attr_tx_data_pkts.attr, | |
421 | &dev_attr_tx_dropped_pkts.attr, | |
422 | &dev_attr_tx_dwords.attr, | |
423 | &dev_attr_tx_flow_pkts.attr, | |
424 | &dev_attr_tx_flow_stalls.attr, | |
425 | &dev_attr_tx_len_errs.attr, | |
426 | &dev_attr_tx_max_min_len_errs.attr, | |
427 | &dev_attr_tx_underruns.attr, | |
428 | &dev_attr_tx_unsup_vl_errs.attr, | |
429 | NULL | |
430 | }; | |
431 | ||
432 | static struct attribute_group dev_counter_attr_group = { | |
433 | .name = "counters", | |
434 | .attrs = dev_counter_attributes | |
435 | }; | |
436 | ||
437 | static ssize_t store_reset(struct device *dev, | |
438 | struct device_attribute *attr, | |
439 | const char *buf, | |
440 | size_t count) | |
441 | { | |
442 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
443 | int ret; | |
444 | ||
445 | if (count < 5 || memcmp(buf, "reset", 5)) { | |
446 | ret = -EINVAL; | |
447 | goto bail; | |
448 | } | |
449 | ||
450 | if (dd->ipath_flags & IPATH_DISABLED) { | |
451 | /* | |
452 | * post-reset init would re-enable interrupts, etc. | |
453 | * so don't allow reset on disabled devices. Not | |
454 | * perfect error, but about the best choice. | |
455 | */ | |
456 | dev_info(dev,"Unit %d is disabled, can't reset\n", | |
457 | dd->ipath_unit); | |
458 | ret = -EINVAL; | |
459 | } | |
460 | ret = ipath_reset_device(dd->ipath_unit); | |
461 | bail: | |
462 | return ret<0 ? ret : count; | |
463 | } | |
464 | ||
465 | static ssize_t store_link_state(struct device *dev, | |
466 | struct device_attribute *attr, | |
467 | const char *buf, | |
468 | size_t count) | |
469 | { | |
470 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
471 | int ret, r; | |
472 | u16 state; | |
473 | ||
474 | ret = ipath_parse_ushort(buf, &state); | |
475 | if (ret < 0) | |
476 | goto invalid; | |
477 | ||
34b2aafe | 478 | r = ipath_set_linkstate(dd, state); |
3e9b4a5e BS |
479 | if (r < 0) { |
480 | ret = r; | |
481 | goto bail; | |
482 | } | |
483 | ||
484 | goto bail; | |
485 | invalid: | |
486 | ipath_dev_err(dd, "attempt to set invalid link state\n"); | |
487 | bail: | |
488 | return ret; | |
489 | } | |
490 | ||
491 | static ssize_t show_mtu(struct device *dev, | |
492 | struct device_attribute *attr, | |
493 | char *buf) | |
494 | { | |
495 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
496 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_ibmtu); | |
497 | } | |
498 | ||
499 | static ssize_t store_mtu(struct device *dev, | |
500 | struct device_attribute *attr, | |
501 | const char *buf, | |
502 | size_t count) | |
503 | { | |
504 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
505 | ssize_t ret; | |
506 | u16 mtu = 0; | |
507 | int r; | |
508 | ||
509 | ret = ipath_parse_ushort(buf, &mtu); | |
510 | if (ret < 0) | |
511 | goto invalid; | |
512 | ||
34b2aafe | 513 | r = ipath_set_mtu(dd, mtu); |
3e9b4a5e BS |
514 | if (r < 0) |
515 | ret = r; | |
516 | ||
517 | goto bail; | |
518 | invalid: | |
519 | ipath_dev_err(dd, "attempt to set invalid MTU\n"); | |
520 | bail: | |
521 | return ret; | |
522 | } | |
523 | ||
524 | static ssize_t show_enabled(struct device *dev, | |
525 | struct device_attribute *attr, | |
526 | char *buf) | |
527 | { | |
528 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
529 | return scnprintf(buf, PAGE_SIZE, "%u\n", | |
530 | (dd->ipath_flags & IPATH_DISABLED) ? 0 : 1); | |
531 | } | |
532 | ||
533 | static ssize_t store_enabled(struct device *dev, | |
534 | struct device_attribute *attr, | |
535 | const char *buf, | |
536 | size_t count) | |
537 | { | |
538 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
539 | ssize_t ret; | |
540 | u16 enable = 0; | |
541 | ||
542 | ret = ipath_parse_ushort(buf, &enable); | |
543 | if (ret < 0) { | |
544 | ipath_dev_err(dd, "attempt to use non-numeric on enable\n"); | |
545 | goto bail; | |
546 | } | |
547 | ||
548 | if (enable) { | |
549 | if (!(dd->ipath_flags & IPATH_DISABLED)) | |
550 | goto bail; | |
551 | ||
552 | dev_info(dev, "Enabling unit %d\n", dd->ipath_unit); | |
553 | /* same as post-reset */ | |
554 | ret = ipath_init_chip(dd, 1); | |
555 | if (ret) | |
556 | ipath_dev_err(dd, "Failed to enable unit %d\n", | |
557 | dd->ipath_unit); | |
558 | else { | |
559 | dd->ipath_flags &= ~IPATH_DISABLED; | |
560 | *dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED; | |
561 | } | |
562 | } | |
563 | else if (!(dd->ipath_flags & IPATH_DISABLED)) { | |
564 | dev_info(dev, "Disabling unit %d\n", dd->ipath_unit); | |
565 | ipath_shutdown_device(dd); | |
566 | dd->ipath_flags |= IPATH_DISABLED; | |
567 | *dd->ipath_statusp |= IPATH_STATUS_ADMIN_DISABLED; | |
568 | } | |
569 | ||
570 | bail: | |
571 | return ret; | |
572 | } | |
573 | ||
30fc5c31 BS |
574 | static ssize_t store_rx_pol_inv(struct device *dev, |
575 | struct device_attribute *attr, | |
576 | const char *buf, | |
577 | size_t count) | |
578 | { | |
579 | struct ipath_devdata *dd = dev_get_drvdata(dev); | |
580 | int ret, r; | |
581 | u16 val; | |
582 | ||
583 | ret = ipath_parse_ushort(buf, &val); | |
584 | if (ret < 0) | |
585 | goto invalid; | |
586 | ||
587 | r = ipath_set_rx_pol_inv(dd, val); | |
588 | if (r < 0) { | |
589 | ret = r; | |
590 | goto bail; | |
591 | } | |
592 | ||
593 | goto bail; | |
594 | invalid: | |
595 | ipath_dev_err(dd, "attempt to set invalid Rx Polarity invert\n"); | |
596 | bail: | |
597 | return ret; | |
598 | } | |
599 | ||
600 | ||
3e9b4a5e BS |
601 | static DRIVER_ATTR(num_units, S_IRUGO, show_num_units, NULL); |
602 | static DRIVER_ATTR(version, S_IRUGO, show_version, NULL); | |
603 | ||
604 | static struct attribute *driver_attributes[] = { | |
605 | &driver_attr_num_units.attr, | |
606 | &driver_attr_version.attr, | |
607 | NULL | |
608 | }; | |
609 | ||
610 | static struct attribute_group driver_attr_group = { | |
611 | .attrs = driver_attributes | |
612 | }; | |
613 | ||
614 | static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid); | |
615 | static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid); | |
616 | static DEVICE_ATTR(link_state, S_IWUSR, NULL, store_link_state); | |
617 | static DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid); | |
618 | static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu); | |
619 | static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled); | |
620 | static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL); | |
9929b0fb | 621 | static DEVICE_ATTR(nports, S_IRUGO, show_nports, NULL); |
3e9b4a5e BS |
622 | static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset); |
623 | static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL); | |
624 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); | |
625 | static DEVICE_ATTR(status_str, S_IRUGO, show_status_str, NULL); | |
626 | static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL); | |
627 | static DEVICE_ATTR(unit, S_IRUGO, show_unit, NULL); | |
30fc5c31 | 628 | static DEVICE_ATTR(rx_pol_inv, S_IWUSR, NULL, store_rx_pol_inv); |
3e9b4a5e BS |
629 | |
630 | static struct attribute *dev_attributes[] = { | |
631 | &dev_attr_guid.attr, | |
632 | &dev_attr_lid.attr, | |
633 | &dev_attr_link_state.attr, | |
634 | &dev_attr_mlid.attr, | |
635 | &dev_attr_mtu.attr, | |
636 | &dev_attr_nguid.attr, | |
9929b0fb | 637 | &dev_attr_nports.attr, |
3e9b4a5e BS |
638 | &dev_attr_serial.attr, |
639 | &dev_attr_status.attr, | |
640 | &dev_attr_status_str.attr, | |
641 | &dev_attr_boardversion.attr, | |
642 | &dev_attr_unit.attr, | |
643 | &dev_attr_enabled.attr, | |
30fc5c31 | 644 | &dev_attr_rx_pol_inv.attr, |
3e9b4a5e BS |
645 | NULL |
646 | }; | |
647 | ||
648 | static struct attribute_group dev_attr_group = { | |
649 | .attrs = dev_attributes | |
650 | }; | |
651 | ||
652 | /** | |
653 | * ipath_expose_reset - create a device reset file | |
654 | * @dev: the device structure | |
655 | * | |
656 | * Only expose a file that lets us reset the device after someone | |
657 | * enters diag mode. A device reset is quite likely to crash the | |
658 | * machine entirely, so we don't want to normally make it | |
659 | * available. | |
755e4ca4 BS |
660 | * |
661 | * Called with ipath_mutex held. | |
3e9b4a5e BS |
662 | */ |
663 | int ipath_expose_reset(struct device *dev) | |
664 | { | |
755e4ca4 BS |
665 | static int exposed; |
666 | int ret; | |
667 | ||
668 | if (!exposed) { | |
669 | ret = device_create_file(dev, &dev_attr_reset); | |
670 | exposed = 1; | |
671 | } | |
672 | else | |
673 | ret = 0; | |
674 | ||
675 | return ret; | |
3e9b4a5e BS |
676 | } |
677 | ||
678 | int ipath_driver_create_group(struct device_driver *drv) | |
679 | { | |
680 | int ret; | |
681 | ||
682 | ret = sysfs_create_group(&drv->kobj, &driver_attr_group); | |
3e9b4a5e | 683 | |
3e9b4a5e BS |
684 | return ret; |
685 | } | |
686 | ||
687 | void ipath_driver_remove_group(struct device_driver *drv) | |
688 | { | |
3e9b4a5e BS |
689 | sysfs_remove_group(&drv->kobj, &driver_attr_group); |
690 | } | |
691 | ||
692 | int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd) | |
693 | { | |
694 | int ret; | |
695 | char unit[5]; | |
696 | ||
697 | ret = sysfs_create_group(&dev->kobj, &dev_attr_group); | |
698 | if (ret) | |
699 | goto bail; | |
700 | ||
701 | ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group); | |
702 | if (ret) | |
703 | goto bail_attrs; | |
704 | ||
705 | snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit); | |
706 | ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit); | |
707 | if (ret == 0) | |
708 | goto bail; | |
709 | ||
710 | sysfs_remove_group(&dev->kobj, &dev_counter_attr_group); | |
711 | bail_attrs: | |
712 | sysfs_remove_group(&dev->kobj, &dev_attr_group); | |
713 | bail: | |
714 | return ret; | |
715 | } | |
716 | ||
717 | void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd) | |
718 | { | |
719 | char unit[5]; | |
720 | ||
721 | snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit); | |
722 | sysfs_remove_link(&dev->driver->kobj, unit); | |
723 | ||
724 | sysfs_remove_group(&dev->kobj, &dev_counter_attr_group); | |
725 | sysfs_remove_group(&dev->kobj, &dev_attr_group); | |
726 | ||
727 | device_remove_file(dev, &dev_attr_reset); | |
728 | } |