diff options
author | Bryan O'Sullivan <bos@pathscale.com> | 2006-03-29 18:23:30 -0500 |
---|---|---|
committer | Roland Dreier <rolandd@cisco.com> | 2006-03-31 16:14:19 -0500 |
commit | 3e9b4a5eb4ae4936feeea256c0105e078c7702cd (patch) | |
tree | f2d8e2f82de310ec6c7d7d44d15c39e42a165f45 /drivers/infiniband | |
parent | 108ecf0d90655055d5a7db8d3a7239133b4d52b7 (diff) |
IB/ipath: sysfs and ipathfs support for core driver
The ipathfs filesystem contains files that are not appropriate for
sysfs, because they contain binary data. The hierarchy is simple; the
top-level directory contains driver-wide attribute files, while numbered
subdirectories contain per-device attribute files.
Our userspace code currently expects this filesystem to be mounted on
/ipathfs, but a final location has not yet been chosen.
Signed-off-by: Bryan O'Sullivan <bos@pathscale.com>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r-- | drivers/infiniband/hw/ipath/ipath_fs.c | 605 | ||||
-rw-r--r-- | drivers/infiniband/hw/ipath/ipath_sysfs.c | 778 |
2 files changed, 1383 insertions, 0 deletions
diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c new file mode 100644 index 000000000000..e274120567e1 --- /dev/null +++ b/drivers/infiniband/hw/ipath/ipath_fs.c | |||
@@ -0,0 +1,605 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2006 PathScale, Inc. All rights reserved. | ||
3 | * | ||
4 | * This software is available to you under a choice of one of two | ||
5 | * licenses. You may choose to be licensed under the terms of the GNU | ||
6 | * General Public License (GPL) Version 2, available from the file | ||
7 | * COPYING in the main directory of this source tree, or the | ||
8 | * OpenIB.org BSD license below: | ||
9 | * | ||
10 | * Redistribution and use in source and binary forms, with or | ||
11 | * without modification, are permitted provided that the following | ||
12 | * conditions are met: | ||
13 | * | ||
14 | * - Redistributions of source code must retain the above | ||
15 | * copyright notice, this list of conditions and the following | ||
16 | * disclaimer. | ||
17 | * | ||
18 | * - Redistributions in binary form must reproduce the above | ||
19 | * copyright notice, this list of conditions and the following | ||
20 | * disclaimer in the documentation and/or other materials | ||
21 | * provided with the distribution. | ||
22 | * | ||
23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
30 | * SOFTWARE. | ||
31 | */ | ||
32 | |||
33 | #include <linux/version.h> | ||
34 | #include <linux/config.h> | ||
35 | #include <linux/module.h> | ||
36 | #include <linux/fs.h> | ||
37 | #include <linux/mount.h> | ||
38 | #include <linux/pagemap.h> | ||
39 | #include <linux/init.h> | ||
40 | #include <linux/namei.h> | ||
41 | #include <linux/pci.h> | ||
42 | |||
43 | #include "ipath_kernel.h" | ||
44 | |||
45 | #define IPATHFS_MAGIC 0x726a77 | ||
46 | |||
47 | static struct super_block *ipath_super; | ||
48 | |||
49 | static int ipathfs_mknod(struct inode *dir, struct dentry *dentry, | ||
50 | int mode, struct file_operations *fops, | ||
51 | void *data) | ||
52 | { | ||
53 | int error; | ||
54 | struct inode *inode = new_inode(dir->i_sb); | ||
55 | |||
56 | if (!inode) { | ||
57 | error = -EPERM; | ||
58 | goto bail; | ||
59 | } | ||
60 | |||
61 | inode->i_mode = mode; | ||
62 | inode->i_uid = 0; | ||
63 | inode->i_gid = 0; | ||
64 | inode->i_blksize = PAGE_CACHE_SIZE; | ||
65 | inode->i_blocks = 0; | ||
66 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; | ||
67 | inode->u.generic_ip = data; | ||
68 | if ((mode & S_IFMT) == S_IFDIR) { | ||
69 | inode->i_op = &simple_dir_inode_operations; | ||
70 | inode->i_nlink++; | ||
71 | dir->i_nlink++; | ||
72 | } | ||
73 | |||
74 | inode->i_fop = fops; | ||
75 | |||
76 | d_instantiate(dentry, inode); | ||
77 | error = 0; | ||
78 | |||
79 | bail: | ||
80 | return error; | ||
81 | } | ||
82 | |||
83 | static int create_file(const char *name, mode_t mode, | ||
84 | struct dentry *parent, struct dentry **dentry, | ||
85 | struct file_operations *fops, void *data) | ||
86 | { | ||
87 | int error; | ||
88 | |||
89 | *dentry = NULL; | ||
90 | mutex_lock(&parent->d_inode->i_mutex); | ||
91 | *dentry = lookup_one_len(name, parent, strlen(name)); | ||
92 | if (!IS_ERR(dentry)) | ||
93 | error = ipathfs_mknod(parent->d_inode, *dentry, | ||
94 | mode, fops, data); | ||
95 | else | ||
96 | error = PTR_ERR(dentry); | ||
97 | mutex_unlock(&parent->d_inode->i_mutex); | ||
98 | |||
99 | return error; | ||
100 | } | ||
101 | |||
102 | static ssize_t atomic_stats_read(struct file *file, char __user *buf, | ||
103 | size_t count, loff_t *ppos) | ||
104 | { | ||
105 | return simple_read_from_buffer(buf, count, ppos, &ipath_stats, | ||
106 | sizeof ipath_stats); | ||
107 | } | ||
108 | |||
109 | static struct file_operations atomic_stats_ops = { | ||
110 | .read = atomic_stats_read, | ||
111 | }; | ||
112 | |||
113 | #define NUM_COUNTERS sizeof(struct infinipath_counters) / sizeof(u64) | ||
114 | |||
115 | static ssize_t atomic_counters_read(struct file *file, char __user *buf, | ||
116 | size_t count, loff_t *ppos) | ||
117 | { | ||
118 | u64 counters[NUM_COUNTERS]; | ||
119 | u16 i; | ||
120 | struct ipath_devdata *dd; | ||
121 | |||
122 | dd = file->f_dentry->d_inode->u.generic_ip; | ||
123 | |||
124 | for (i = 0; i < NUM_COUNTERS; i++) | ||
125 | counters[i] = ipath_snap_cntr(dd, i); | ||
126 | |||
127 | return simple_read_from_buffer(buf, count, ppos, counters, | ||
128 | sizeof counters); | ||
129 | } | ||
130 | |||
131 | static struct file_operations atomic_counters_ops = { | ||
132 | .read = atomic_counters_read, | ||
133 | }; | ||
134 | |||
135 | static ssize_t atomic_node_info_read(struct file *file, char __user *buf, | ||
136 | size_t count, loff_t *ppos) | ||
137 | { | ||
138 | u32 nodeinfo[10]; | ||
139 | struct ipath_devdata *dd; | ||
140 | u64 guid; | ||
141 | |||
142 | dd = file->f_dentry->d_inode->u.generic_ip; | ||
143 | |||
144 | guid = be64_to_cpu(dd->ipath_guid); | ||
145 | |||
146 | nodeinfo[0] = /* BaseVersion is SMA */ | ||
147 | /* ClassVersion is SMA */ | ||
148 | (1 << 8) /* NodeType */ | ||
149 | | (1 << 0); /* NumPorts */ | ||
150 | nodeinfo[1] = (u32) (guid >> 32); | ||
151 | nodeinfo[2] = (u32) (guid & 0xffffffff); | ||
152 | /* PortGUID == SystemImageGUID for us */ | ||
153 | nodeinfo[3] = nodeinfo[1]; | ||
154 | /* PortGUID == SystemImageGUID for us */ | ||
155 | nodeinfo[4] = nodeinfo[2]; | ||
156 | /* PortGUID == NodeGUID for us */ | ||
157 | nodeinfo[5] = nodeinfo[3]; | ||
158 | /* PortGUID == NodeGUID for us */ | ||
159 | nodeinfo[6] = nodeinfo[4]; | ||
160 | nodeinfo[7] = (4 << 16) /* we support 4 pkeys */ | ||
161 | | (dd->ipath_deviceid << 0); | ||
162 | /* our chip version as 16 bits major, 16 bits minor */ | ||
163 | nodeinfo[8] = dd->ipath_minrev | (dd->ipath_majrev << 16); | ||
164 | nodeinfo[9] = (dd->ipath_unit << 24) | (dd->ipath_vendorid << 0); | ||
165 | |||
166 | return simple_read_from_buffer(buf, count, ppos, nodeinfo, | ||
167 | sizeof nodeinfo); | ||
168 | } | ||
169 | |||
170 | static struct file_operations atomic_node_info_ops = { | ||
171 | .read = atomic_node_info_read, | ||
172 | }; | ||
173 | |||
174 | static ssize_t atomic_port_info_read(struct file *file, char __user *buf, | ||
175 | size_t count, loff_t *ppos) | ||
176 | { | ||
177 | u32 portinfo[13]; | ||
178 | u32 tmp, tmp2; | ||
179 | struct ipath_devdata *dd; | ||
180 | |||
181 | dd = file->f_dentry->d_inode->u.generic_ip; | ||
182 | |||
183 | /* so we only initialize non-zero fields. */ | ||
184 | memset(portinfo, 0, sizeof portinfo); | ||
185 | |||
186 | /* | ||
187 | * Notimpl yet M_Key (64) | ||
188 | * Notimpl yet GID (64) | ||
189 | */ | ||
190 | |||
191 | portinfo[4] = (dd->ipath_lid << 16); | ||
192 | |||
193 | /* | ||
194 | * Notimpl yet SMLID (should we store this in the driver, in case | ||
195 | * SMA dies?) CapabilityMask is 0, we don't support any of these | ||
196 | * DiagCode is 0; we don't store any diag info for now Notimpl yet | ||
197 | * M_KeyLeasePeriod (we don't support M_Key) | ||
198 | */ | ||
199 | |||
200 | /* LocalPortNum is whichever port number they ask for */ | ||
201 | portinfo[7] = (dd->ipath_unit << 24) | ||
202 | /* LinkWidthEnabled */ | ||
203 | | (2 << 16) | ||
204 | /* LinkWidthSupported (really 2, but not IB valid) */ | ||
205 | | (3 << 8) | ||
206 | /* LinkWidthActive */ | ||
207 | | (2 << 0); | ||
208 | tmp = dd->ipath_lastibcstat & IPATH_IBSTATE_MASK; | ||
209 | tmp2 = 5; | ||
210 | if (tmp == IPATH_IBSTATE_INIT) | ||
211 | tmp = 2; | ||
212 | else if (tmp == IPATH_IBSTATE_ARM) | ||
213 | tmp = 3; | ||
214 | else if (tmp == IPATH_IBSTATE_ACTIVE) | ||
215 | tmp = 4; | ||
216 | else { | ||
217 | tmp = 0; /* down */ | ||
218 | tmp2 = tmp & 0xf; | ||
219 | } | ||
220 | |||
221 | portinfo[8] = (1 << 28) /* LinkSpeedSupported */ | ||
222 | | (tmp << 24) /* PortState */ | ||
223 | | (tmp2 << 20) /* PortPhysicalState */ | ||
224 | | (2 << 16) | ||
225 | |||
226 | /* LinkDownDefaultState */ | ||
227 | /* M_KeyProtectBits == 0 */ | ||
228 | /* NotImpl yet LMC == 0 (we can support all values) */ | ||
229 | | (1 << 4) /* LinkSpeedActive */ | ||
230 | | (1 << 0); /* LinkSpeedEnabled */ | ||
231 | switch (dd->ipath_ibmtu) { | ||
232 | case 4096: | ||
233 | tmp = 5; | ||
234 | break; | ||
235 | case 2048: | ||
236 | tmp = 4; | ||
237 | break; | ||
238 | case 1024: | ||
239 | tmp = 3; | ||
240 | break; | ||
241 | case 512: | ||
242 | tmp = 2; | ||
243 | break; | ||
244 | case 256: | ||
245 | tmp = 1; | ||
246 | break; | ||
247 | default: /* oops, something is wrong */ | ||
248 | ipath_dbg("Problem, ipath_ibmtu 0x%x not a valid IB MTU, " | ||
249 | "treat as 2048\n", dd->ipath_ibmtu); | ||
250 | tmp = 4; | ||
251 | break; | ||
252 | } | ||
253 | portinfo[9] = (tmp << 28) | ||
254 | /* NeighborMTU */ | ||
255 | /* Notimpl MasterSMSL */ | ||
256 | | (1 << 20) | ||
257 | |||
258 | /* VLCap */ | ||
259 | /* Notimpl InitType (actually, an SMA decision) */ | ||
260 | /* VLHighLimit is 0 (only one VL) */ | ||
261 | ; /* VLArbitrationHighCap is 0 (only one VL) */ | ||
262 | portinfo[10] = /* VLArbitrationLowCap is 0 (only one VL) */ | ||
263 | /* InitTypeReply is SMA decision */ | ||
264 | (5 << 16) /* MTUCap 4096 */ | ||
265 | | (7 << 13) /* VLStallCount */ | ||
266 | | (0x1f << 8) /* HOQLife */ | ||
267 | | (1 << 4) | ||
268 | |||
269 | /* OperationalVLs 0 */ | ||
270 | /* PartitionEnforcementInbound */ | ||
271 | /* PartitionEnforcementOutbound not enforced */ | ||
272 | /* FilterRawinbound not enforced */ | ||
273 | ; /* FilterRawOutbound not enforced */ | ||
274 | /* M_KeyViolations are not counted by hardware, SMA can count */ | ||
275 | tmp = ipath_read_creg32(dd, dd->ipath_cregs->cr_errpkey); | ||
276 | /* P_KeyViolations are counted by hardware. */ | ||
277 | portinfo[11] = ((tmp & 0xffff) << 0); | ||
278 | portinfo[12] = | ||
279 | /* Q_KeyViolations are not counted by hardware */ | ||
280 | (1 << 8) | ||
281 | |||
282 | /* GUIDCap */ | ||
283 | /* SubnetTimeOut handled by SMA */ | ||
284 | /* RespTimeValue handled by SMA */ | ||
285 | ; | ||
286 | /* LocalPhyErrors are programmed to max */ | ||
287 | portinfo[12] |= (0xf << 20) | ||
288 | | (0xf << 16) /* OverRunErrors are programmed to max */ | ||
289 | ; | ||
290 | |||
291 | return simple_read_from_buffer(buf, count, ppos, portinfo, | ||
292 | sizeof portinfo); | ||
293 | } | ||
294 | |||
295 | static struct file_operations atomic_port_info_ops = { | ||
296 | .read = atomic_port_info_read, | ||
297 | }; | ||
298 | |||
299 | static ssize_t flash_read(struct file *file, char __user *buf, | ||
300 | size_t count, loff_t *ppos) | ||
301 | { | ||
302 | struct ipath_devdata *dd; | ||
303 | ssize_t ret; | ||
304 | loff_t pos; | ||
305 | char *tmp; | ||
306 | |||
307 | pos = *ppos; | ||
308 | |||
309 | if ( pos < 0) { | ||
310 | ret = -EINVAL; | ||
311 | goto bail; | ||
312 | } | ||
313 | |||
314 | if (pos >= sizeof(struct ipath_flash)) { | ||
315 | ret = 0; | ||
316 | goto bail; | ||
317 | } | ||
318 | |||
319 | if (count > sizeof(struct ipath_flash) - pos) | ||
320 | count = sizeof(struct ipath_flash) - pos; | ||
321 | |||
322 | tmp = kmalloc(count, GFP_KERNEL); | ||
323 | if (!tmp) { | ||
324 | ret = -ENOMEM; | ||
325 | goto bail; | ||
326 | } | ||
327 | |||
328 | dd = file->f_dentry->d_inode->u.generic_ip; | ||
329 | if (ipath_eeprom_read(dd, pos, tmp, count)) { | ||
330 | ipath_dev_err(dd, "failed to read from flash\n"); | ||
331 | ret = -ENXIO; | ||
332 | goto bail_tmp; | ||
333 | } | ||
334 | |||
335 | if (copy_to_user(buf, tmp, count)) { | ||
336 | ret = -EFAULT; | ||
337 | goto bail_tmp; | ||
338 | } | ||
339 | |||
340 | *ppos = pos + count; | ||
341 | ret = count; | ||
342 | |||
343 | bail_tmp: | ||
344 | kfree(tmp); | ||
345 | |||
346 | bail: | ||
347 | return ret; | ||
348 | } | ||
349 | |||
350 | static ssize_t flash_write(struct file *file, const char __user *buf, | ||
351 | size_t count, loff_t *ppos) | ||
352 | { | ||
353 | struct ipath_devdata *dd; | ||
354 | ssize_t ret; | ||
355 | loff_t pos; | ||
356 | char *tmp; | ||
357 | |||
358 | pos = *ppos; | ||
359 | |||
360 | if ( pos < 0) { | ||
361 | ret = -EINVAL; | ||
362 | goto bail; | ||
363 | } | ||
364 | |||
365 | if (pos >= sizeof(struct ipath_flash)) { | ||
366 | ret = 0; | ||
367 | goto bail; | ||
368 | } | ||
369 | |||
370 | if (count > sizeof(struct ipath_flash) - pos) | ||
371 | count = sizeof(struct ipath_flash) - pos; | ||
372 | |||
373 | tmp = kmalloc(count, GFP_KERNEL); | ||
374 | if (!tmp) { | ||
375 | ret = -ENOMEM; | ||
376 | goto bail; | ||
377 | } | ||
378 | |||
379 | if (copy_from_user(tmp, buf, count)) { | ||
380 | ret = -EFAULT; | ||
381 | goto bail_tmp; | ||
382 | } | ||
383 | |||
384 | dd = file->f_dentry->d_inode->u.generic_ip; | ||
385 | if (ipath_eeprom_write(dd, pos, tmp, count)) { | ||
386 | ret = -ENXIO; | ||
387 | ipath_dev_err(dd, "failed to write to flash\n"); | ||
388 | goto bail_tmp; | ||
389 | } | ||
390 | |||
391 | *ppos = pos + count; | ||
392 | ret = count; | ||
393 | |||
394 | bail_tmp: | ||
395 | kfree(tmp); | ||
396 | |||
397 | bail: | ||
398 | return ret; | ||
399 | } | ||
400 | |||
401 | static struct file_operations flash_ops = { | ||
402 | .read = flash_read, | ||
403 | .write = flash_write, | ||
404 | }; | ||
405 | |||
406 | static int create_device_files(struct super_block *sb, | ||
407 | struct ipath_devdata *dd) | ||
408 | { | ||
409 | struct dentry *dir, *tmp; | ||
410 | char unit[10]; | ||
411 | int ret; | ||
412 | |||
413 | snprintf(unit, sizeof unit, "%02d", dd->ipath_unit); | ||
414 | ret = create_file(unit, S_IFDIR|S_IRUGO|S_IXUGO, sb->s_root, &dir, | ||
415 | (struct file_operations *) &simple_dir_operations, | ||
416 | dd); | ||
417 | if (ret) { | ||
418 | printk(KERN_ERR "create_file(%s) failed: %d\n", unit, ret); | ||
419 | goto bail; | ||
420 | } | ||
421 | |||
422 | ret = create_file("atomic_counters", S_IFREG|S_IRUGO, dir, &tmp, | ||
423 | &atomic_counters_ops, dd); | ||
424 | if (ret) { | ||
425 | printk(KERN_ERR "create_file(%s/atomic_counters) " | ||
426 | "failed: %d\n", unit, ret); | ||
427 | goto bail; | ||
428 | } | ||
429 | |||
430 | ret = create_file("node_info", S_IFREG|S_IRUGO, dir, &tmp, | ||
431 | &atomic_node_info_ops, dd); | ||
432 | if (ret) { | ||
433 | printk(KERN_ERR "create_file(%s/node_info) " | ||
434 | "failed: %d\n", unit, ret); | ||
435 | goto bail; | ||
436 | } | ||
437 | |||
438 | ret = create_file("port_info", S_IFREG|S_IRUGO, dir, &tmp, | ||
439 | &atomic_port_info_ops, dd); | ||
440 | if (ret) { | ||
441 | printk(KERN_ERR "create_file(%s/port_info) " | ||
442 | "failed: %d\n", unit, ret); | ||
443 | goto bail; | ||
444 | } | ||
445 | |||
446 | ret = create_file("flash", S_IFREG|S_IWUSR|S_IRUGO, dir, &tmp, | ||
447 | &flash_ops, dd); | ||
448 | if (ret) { | ||
449 | printk(KERN_ERR "create_file(%s/flash) " | ||
450 | "failed: %d\n", unit, ret); | ||
451 | goto bail; | ||
452 | } | ||
453 | |||
454 | bail: | ||
455 | return ret; | ||
456 | } | ||
457 | |||
458 | static void remove_file(struct dentry *parent, char *name) | ||
459 | { | ||
460 | struct dentry *tmp; | ||
461 | |||
462 | tmp = lookup_one_len(name, parent, strlen(name)); | ||
463 | |||
464 | spin_lock(&dcache_lock); | ||
465 | spin_lock(&tmp->d_lock); | ||
466 | if (!(d_unhashed(tmp) && tmp->d_inode)) { | ||
467 | dget_locked(tmp); | ||
468 | __d_drop(tmp); | ||
469 | spin_unlock(&tmp->d_lock); | ||
470 | spin_unlock(&dcache_lock); | ||
471 | simple_unlink(parent->d_inode, tmp); | ||
472 | } else { | ||
473 | spin_unlock(&tmp->d_lock); | ||
474 | spin_unlock(&dcache_lock); | ||
475 | } | ||
476 | } | ||
477 | |||
478 | static int remove_device_files(struct super_block *sb, | ||
479 | struct ipath_devdata *dd) | ||
480 | { | ||
481 | struct dentry *dir, *root; | ||
482 | char unit[10]; | ||
483 | int ret; | ||
484 | |||
485 | root = dget(sb->s_root); | ||
486 | mutex_lock(&root->d_inode->i_mutex); | ||
487 | snprintf(unit, sizeof unit, "%02d", dd->ipath_unit); | ||
488 | dir = lookup_one_len(unit, root, strlen(unit)); | ||
489 | |||
490 | if (IS_ERR(dir)) { | ||
491 | ret = PTR_ERR(dir); | ||
492 | printk(KERN_ERR "Lookup of %s failed\n", unit); | ||
493 | goto bail; | ||
494 | } | ||
495 | |||
496 | remove_file(dir, "flash"); | ||
497 | remove_file(dir, "port_info"); | ||
498 | remove_file(dir, "node_info"); | ||
499 | remove_file(dir, "atomic_counters"); | ||
500 | d_delete(dir); | ||
501 | ret = simple_rmdir(root->d_inode, dir); | ||
502 | |||
503 | bail: | ||
504 | mutex_unlock(&root->d_inode->i_mutex); | ||
505 | dput(root); | ||
506 | return ret; | ||
507 | } | ||
508 | |||
509 | static int ipathfs_fill_super(struct super_block *sb, void *data, | ||
510 | int silent) | ||
511 | { | ||
512 | struct ipath_devdata *dd, *tmp; | ||
513 | unsigned long flags; | ||
514 | int ret; | ||
515 | |||
516 | static struct tree_descr files[] = { | ||
517 | [1] = {"atomic_stats", &atomic_stats_ops, S_IRUGO}, | ||
518 | {""}, | ||
519 | }; | ||
520 | |||
521 | ret = simple_fill_super(sb, IPATHFS_MAGIC, files); | ||
522 | if (ret) { | ||
523 | printk(KERN_ERR "simple_fill_super failed: %d\n", ret); | ||
524 | goto bail; | ||
525 | } | ||
526 | |||
527 | spin_lock_irqsave(&ipath_devs_lock, flags); | ||
528 | |||
529 | list_for_each_entry_safe(dd, tmp, &ipath_dev_list, ipath_list) { | ||
530 | spin_unlock_irqrestore(&ipath_devs_lock, flags); | ||
531 | ret = create_device_files(sb, dd); | ||
532 | if (ret) { | ||
533 | deactivate_super(sb); | ||
534 | goto bail; | ||
535 | } | ||
536 | spin_lock_irqsave(&ipath_devs_lock, flags); | ||
537 | } | ||
538 | |||
539 | spin_unlock_irqrestore(&ipath_devs_lock, flags); | ||
540 | |||
541 | bail: | ||
542 | return ret; | ||
543 | } | ||
544 | |||
545 | static struct super_block *ipathfs_get_sb(struct file_system_type *fs_type, | ||
546 | int flags, const char *dev_name, | ||
547 | void *data) | ||
548 | { | ||
549 | ipath_super = get_sb_single(fs_type, flags, data, | ||
550 | ipathfs_fill_super); | ||
551 | return ipath_super; | ||
552 | } | ||
553 | |||
554 | static void ipathfs_kill_super(struct super_block *s) | ||
555 | { | ||
556 | kill_litter_super(s); | ||
557 | ipath_super = NULL; | ||
558 | } | ||
559 | |||
560 | int ipathfs_add_device(struct ipath_devdata *dd) | ||
561 | { | ||
562 | int ret; | ||
563 | |||
564 | if (ipath_super == NULL) { | ||
565 | ret = 0; | ||
566 | goto bail; | ||
567 | } | ||
568 | |||
569 | ret = create_device_files(ipath_super, dd); | ||
570 | |||
571 | bail: | ||
572 | return ret; | ||
573 | } | ||
574 | |||
575 | int ipathfs_remove_device(struct ipath_devdata *dd) | ||
576 | { | ||
577 | int ret; | ||
578 | |||
579 | if (ipath_super == NULL) { | ||
580 | ret = 0; | ||
581 | goto bail; | ||
582 | } | ||
583 | |||
584 | ret = remove_device_files(ipath_super, dd); | ||
585 | |||
586 | bail: | ||
587 | return ret; | ||
588 | } | ||
589 | |||
590 | static struct file_system_type ipathfs_fs_type = { | ||
591 | .owner = THIS_MODULE, | ||
592 | .name = "ipathfs", | ||
593 | .get_sb = ipathfs_get_sb, | ||
594 | .kill_sb = ipathfs_kill_super, | ||
595 | }; | ||
596 | |||
597 | int __init ipath_init_ipathfs(void) | ||
598 | { | ||
599 | return register_filesystem(&ipathfs_fs_type); | ||
600 | } | ||
601 | |||
602 | void __exit ipath_exit_ipathfs(void) | ||
603 | { | ||
604 | unregister_filesystem(&ipathfs_fs_type); | ||
605 | } | ||
diff --git a/drivers/infiniband/hw/ipath/ipath_sysfs.c b/drivers/infiniband/hw/ipath/ipath_sysfs.c new file mode 100644 index 000000000000..32acd8048b49 --- /dev/null +++ b/drivers/infiniband/hw/ipath/ipath_sysfs.c | |||
@@ -0,0 +1,778 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2006 PathScale, Inc. All rights reserved. | ||
3 | * | ||
4 | * This software is available to you under a choice of one of two | ||
5 | * licenses. You may choose to be licensed under the terms of the GNU | ||
6 | * General Public License (GPL) Version 2, available from the file | ||
7 | * COPYING in the main directory of this source tree, or the | ||
8 | * OpenIB.org BSD license below: | ||
9 | * | ||
10 | * Redistribution and use in source and binary forms, with or | ||
11 | * without modification, are permitted provided that the following | ||
12 | * conditions are met: | ||
13 | * | ||
14 | * - Redistributions of source code must retain the above | ||
15 | * copyright notice, this list of conditions and the following | ||
16 | * disclaimer. | ||
17 | * | ||
18 | * - Redistributions in binary form must reproduce the above | ||
19 | * copyright notice, this list of conditions and the following | ||
20 | * disclaimer in the documentation and/or other materials | ||
21 | * provided with the distribution. | ||
22 | * | ||
23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
30 | * SOFTWARE. | ||
31 | */ | ||
32 | |||
33 | #include <linux/ctype.h> | ||
34 | #include <linux/pci.h> | ||
35 | |||
36 | #include "ipath_kernel.h" | ||
37 | #include "ips_common.h" | ||
38 | #include "ipath_layer.h" | ||
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. */ | ||
78 | return scnprintf(buf, PAGE_SIZE, "%s", ipath_core_version); | ||
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 | |||
87 | #define DRIVER_STAT(name, attr) \ | ||
88 | static ssize_t show_stat_##name(struct device_driver *dev, \ | ||
89 | char *buf) \ | ||
90 | { \ | ||
91 | return scnprintf( \ | ||
92 | buf, PAGE_SIZE, "%llu\n", \ | ||
93 | (unsigned long long) ipath_stats.sps_ ##attr); \ | ||
94 | } \ | ||
95 | static DRIVER_ATTR(name, S_IRUGO, show_stat_##name, NULL) | ||
96 | |||
97 | DRIVER_STAT(intrs, ints); | ||
98 | DRIVER_STAT(err_intrs, errints); | ||
99 | DRIVER_STAT(errs, errs); | ||
100 | DRIVER_STAT(pkt_errs, pkterrs); | ||
101 | DRIVER_STAT(crc_errs, crcerrs); | ||
102 | DRIVER_STAT(hw_errs, hwerrs); | ||
103 | DRIVER_STAT(ib_link, iblink); | ||
104 | DRIVER_STAT(port0_pkts, port0pkts); | ||
105 | DRIVER_STAT(ether_spkts, ether_spkts); | ||
106 | DRIVER_STAT(ether_rpkts, ether_rpkts); | ||
107 | DRIVER_STAT(sma_spkts, sma_spkts); | ||
108 | DRIVER_STAT(sma_rpkts, sma_rpkts); | ||
109 | DRIVER_STAT(hdrq_full, hdrqfull); | ||
110 | DRIVER_STAT(etid_full, etidfull); | ||
111 | DRIVER_STAT(no_piobufs, nopiobufs); | ||
112 | DRIVER_STAT(ports, ports); | ||
113 | DRIVER_STAT(pkey0, pkeys[0]); | ||
114 | DRIVER_STAT(pkey1, pkeys[1]); | ||
115 | DRIVER_STAT(pkey2, pkeys[2]); | ||
116 | DRIVER_STAT(pkey3, pkeys[3]); | ||
117 | /* XXX fix the following when dynamic table of devices used */ | ||
118 | DRIVER_STAT(lid0, lid[0]); | ||
119 | DRIVER_STAT(lid1, lid[1]); | ||
120 | DRIVER_STAT(lid2, lid[2]); | ||
121 | DRIVER_STAT(lid3, lid[3]); | ||
122 | |||
123 | DRIVER_STAT(nports, nports); | ||
124 | DRIVER_STAT(null_intr, nullintr); | ||
125 | DRIVER_STAT(max_pkts_call, maxpkts_call); | ||
126 | DRIVER_STAT(avg_pkts_call, avgpkts_call); | ||
127 | DRIVER_STAT(page_locks, pagelocks); | ||
128 | DRIVER_STAT(page_unlocks, pageunlocks); | ||
129 | DRIVER_STAT(krdrops, krdrops); | ||
130 | /* XXX fix the following when dynamic table of devices used */ | ||
131 | DRIVER_STAT(mlid0, mlid[0]); | ||
132 | DRIVER_STAT(mlid1, mlid[1]); | ||
133 | DRIVER_STAT(mlid2, mlid[2]); | ||
134 | DRIVER_STAT(mlid3, mlid[3]); | ||
135 | |||
136 | static struct attribute *driver_stat_attributes[] = { | ||
137 | &driver_attr_intrs.attr, | ||
138 | &driver_attr_err_intrs.attr, | ||
139 | &driver_attr_errs.attr, | ||
140 | &driver_attr_pkt_errs.attr, | ||
141 | &driver_attr_crc_errs.attr, | ||
142 | &driver_attr_hw_errs.attr, | ||
143 | &driver_attr_ib_link.attr, | ||
144 | &driver_attr_port0_pkts.attr, | ||
145 | &driver_attr_ether_spkts.attr, | ||
146 | &driver_attr_ether_rpkts.attr, | ||
147 | &driver_attr_sma_spkts.attr, | ||
148 | &driver_attr_sma_rpkts.attr, | ||
149 | &driver_attr_hdrq_full.attr, | ||
150 | &driver_attr_etid_full.attr, | ||
151 | &driver_attr_no_piobufs.attr, | ||
152 | &driver_attr_ports.attr, | ||
153 | &driver_attr_pkey0.attr, | ||
154 | &driver_attr_pkey1.attr, | ||
155 | &driver_attr_pkey2.attr, | ||
156 | &driver_attr_pkey3.attr, | ||
157 | &driver_attr_lid0.attr, | ||
158 | &driver_attr_lid1.attr, | ||
159 | &driver_attr_lid2.attr, | ||
160 | &driver_attr_lid3.attr, | ||
161 | &driver_attr_nports.attr, | ||
162 | &driver_attr_null_intr.attr, | ||
163 | &driver_attr_max_pkts_call.attr, | ||
164 | &driver_attr_avg_pkts_call.attr, | ||
165 | &driver_attr_page_locks.attr, | ||
166 | &driver_attr_page_unlocks.attr, | ||
167 | &driver_attr_krdrops.attr, | ||
168 | &driver_attr_mlid0.attr, | ||
169 | &driver_attr_mlid1.attr, | ||
170 | &driver_attr_mlid2.attr, | ||
171 | &driver_attr_mlid3.attr, | ||
172 | NULL | ||
173 | }; | ||
174 | |||
175 | static struct attribute_group driver_stat_attr_group = { | ||
176 | .name = "stats", | ||
177 | .attrs = driver_stat_attributes | ||
178 | }; | ||
179 | |||
180 | static ssize_t show_status(struct device *dev, | ||
181 | struct device_attribute *attr, | ||
182 | char *buf) | ||
183 | { | ||
184 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
185 | ssize_t ret; | ||
186 | |||
187 | if (!dd->ipath_statusp) { | ||
188 | ret = -EINVAL; | ||
189 | goto bail; | ||
190 | } | ||
191 | |||
192 | ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n", | ||
193 | (unsigned long long) *(dd->ipath_statusp)); | ||
194 | |||
195 | bail: | ||
196 | return ret; | ||
197 | } | ||
198 | |||
199 | static const char *ipath_status_str[] = { | ||
200 | "Initted", | ||
201 | "Disabled", | ||
202 | "Admin_Disabled", | ||
203 | "OIB_SMA", | ||
204 | "SMA", | ||
205 | "Present", | ||
206 | "IB_link_up", | ||
207 | "IB_configured", | ||
208 | "NoIBcable", | ||
209 | "Fatal_Hardware_Error", | ||
210 | NULL, | ||
211 | }; | ||
212 | |||
213 | static ssize_t show_status_str(struct device *dev, | ||
214 | struct device_attribute *attr, | ||
215 | char *buf) | ||
216 | { | ||
217 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
218 | int i, any; | ||
219 | u64 s; | ||
220 | ssize_t ret; | ||
221 | |||
222 | if (!dd->ipath_statusp) { | ||
223 | ret = -EINVAL; | ||
224 | goto bail; | ||
225 | } | ||
226 | |||
227 | s = *(dd->ipath_statusp); | ||
228 | *buf = '\0'; | ||
229 | for (any = i = 0; s && ipath_status_str[i]; i++) { | ||
230 | if (s & 1) { | ||
231 | if (any && strlcat(buf, " ", PAGE_SIZE) >= | ||
232 | PAGE_SIZE) | ||
233 | /* overflow */ | ||
234 | break; | ||
235 | if (strlcat(buf, ipath_status_str[i], | ||
236 | PAGE_SIZE) >= PAGE_SIZE) | ||
237 | break; | ||
238 | any = 1; | ||
239 | } | ||
240 | s >>= 1; | ||
241 | } | ||
242 | if (any) | ||
243 | strlcat(buf, "\n", PAGE_SIZE); | ||
244 | |||
245 | ret = strlen(buf); | ||
246 | |||
247 | bail: | ||
248 | return ret; | ||
249 | } | ||
250 | |||
251 | static ssize_t show_boardversion(struct device *dev, | ||
252 | struct device_attribute *attr, | ||
253 | char *buf) | ||
254 | { | ||
255 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
256 | /* The string printed here is already newline-terminated. */ | ||
257 | return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_boardversion); | ||
258 | } | ||
259 | |||
260 | static ssize_t show_lid(struct device *dev, | ||
261 | struct device_attribute *attr, | ||
262 | char *buf) | ||
263 | { | ||
264 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
265 | |||
266 | return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_lid); | ||
267 | } | ||
268 | |||
269 | static ssize_t store_lid(struct device *dev, | ||
270 | struct device_attribute *attr, | ||
271 | const char *buf, | ||
272 | size_t count) | ||
273 | { | ||
274 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
275 | u16 lid; | ||
276 | int ret; | ||
277 | |||
278 | ret = ipath_parse_ushort(buf, &lid); | ||
279 | if (ret < 0) | ||
280 | goto invalid; | ||
281 | |||
282 | if (lid == 0 || lid >= 0xc000) { | ||
283 | ret = -EINVAL; | ||
284 | goto invalid; | ||
285 | } | ||
286 | |||
287 | ipath_set_sps_lid(dd, lid, 0); | ||
288 | |||
289 | goto bail; | ||
290 | invalid: | ||
291 | ipath_dev_err(dd, "attempt to set invalid LID\n"); | ||
292 | bail: | ||
293 | return ret; | ||
294 | } | ||
295 | |||
296 | static ssize_t show_mlid(struct device *dev, | ||
297 | struct device_attribute *attr, | ||
298 | char *buf) | ||
299 | { | ||
300 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
301 | |||
302 | return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_mlid); | ||
303 | } | ||
304 | |||
305 | static ssize_t store_mlid(struct device *dev, | ||
306 | struct device_attribute *attr, | ||
307 | const char *buf, | ||
308 | size_t count) | ||
309 | { | ||
310 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
311 | int unit; | ||
312 | u16 mlid; | ||
313 | int ret; | ||
314 | |||
315 | ret = ipath_parse_ushort(buf, &mlid); | ||
316 | if (ret < 0) | ||
317 | goto invalid; | ||
318 | |||
319 | unit = dd->ipath_unit; | ||
320 | |||
321 | dd->ipath_mlid = mlid; | ||
322 | ipath_stats.sps_mlid[unit] = mlid; | ||
323 | ipath_layer_intr(dd, IPATH_LAYER_INT_BCAST); | ||
324 | |||
325 | goto bail; | ||
326 | invalid: | ||
327 | ipath_dev_err(dd, "attempt to set invalid MLID\n"); | ||
328 | bail: | ||
329 | return ret; | ||
330 | } | ||
331 | |||
332 | static ssize_t show_guid(struct device *dev, | ||
333 | struct device_attribute *attr, | ||
334 | char *buf) | ||
335 | { | ||
336 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
337 | u8 *guid; | ||
338 | |||
339 | guid = (u8 *) & (dd->ipath_guid); | ||
340 | |||
341 | return scnprintf(buf, PAGE_SIZE, | ||
342 | "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", | ||
343 | guid[0], guid[1], guid[2], guid[3], | ||
344 | guid[4], guid[5], guid[6], guid[7]); | ||
345 | } | ||
346 | |||
347 | static ssize_t store_guid(struct device *dev, | ||
348 | struct device_attribute *attr, | ||
349 | const char *buf, | ||
350 | size_t count) | ||
351 | { | ||
352 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
353 | ssize_t ret; | ||
354 | unsigned short guid[8]; | ||
355 | __be64 nguid; | ||
356 | u8 *ng; | ||
357 | int i; | ||
358 | |||
359 | if (sscanf(buf, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx", | ||
360 | &guid[0], &guid[1], &guid[2], &guid[3], | ||
361 | &guid[4], &guid[5], &guid[6], &guid[7]) != 8) | ||
362 | goto invalid; | ||
363 | |||
364 | ng = (u8 *) &nguid; | ||
365 | |||
366 | for (i = 0; i < 8; i++) { | ||
367 | if (guid[i] > 0xff) | ||
368 | goto invalid; | ||
369 | ng[i] = guid[i]; | ||
370 | } | ||
371 | |||
372 | dd->ipath_guid = nguid; | ||
373 | dd->ipath_nguid = 1; | ||
374 | |||
375 | ret = strlen(buf); | ||
376 | goto bail; | ||
377 | |||
378 | invalid: | ||
379 | ipath_dev_err(dd, "attempt to set invalid GUID\n"); | ||
380 | ret = -EINVAL; | ||
381 | |||
382 | bail: | ||
383 | return ret; | ||
384 | } | ||
385 | |||
386 | static ssize_t show_nguid(struct device *dev, | ||
387 | struct device_attribute *attr, | ||
388 | char *buf) | ||
389 | { | ||
390 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
391 | |||
392 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid); | ||
393 | } | ||
394 | |||
395 | static ssize_t show_serial(struct device *dev, | ||
396 | struct device_attribute *attr, | ||
397 | char *buf) | ||
398 | { | ||
399 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
400 | |||
401 | buf[sizeof dd->ipath_serial] = '\0'; | ||
402 | memcpy(buf, dd->ipath_serial, sizeof dd->ipath_serial); | ||
403 | strcat(buf, "\n"); | ||
404 | return strlen(buf); | ||
405 | } | ||
406 | |||
407 | static ssize_t show_unit(struct device *dev, | ||
408 | struct device_attribute *attr, | ||
409 | char *buf) | ||
410 | { | ||
411 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
412 | |||
413 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_unit); | ||
414 | } | ||
415 | |||
416 | #define DEVICE_COUNTER(name, attr) \ | ||
417 | static ssize_t show_counter_##name(struct device *dev, \ | ||
418 | struct device_attribute *attr, \ | ||
419 | char *buf) \ | ||
420 | { \ | ||
421 | struct ipath_devdata *dd = dev_get_drvdata(dev); \ | ||
422 | return scnprintf(\ | ||
423 | buf, PAGE_SIZE, "%llu\n", (unsigned long long) \ | ||
424 | ipath_snap_cntr( \ | ||
425 | dd, offsetof(struct infinipath_counters, \ | ||
426 | attr) / sizeof(u64))); \ | ||
427 | } \ | ||
428 | static DEVICE_ATTR(name, S_IRUGO, show_counter_##name, NULL); | ||
429 | |||
430 | DEVICE_COUNTER(ib_link_downeds, IBLinkDownedCnt); | ||
431 | DEVICE_COUNTER(ib_link_err_recoveries, IBLinkErrRecoveryCnt); | ||
432 | DEVICE_COUNTER(ib_status_changes, IBStatusChangeCnt); | ||
433 | DEVICE_COUNTER(ib_symbol_errs, IBSymbolErrCnt); | ||
434 | DEVICE_COUNTER(lb_flow_stalls, LBFlowStallCnt); | ||
435 | DEVICE_COUNTER(lb_ints, LBIntCnt); | ||
436 | DEVICE_COUNTER(rx_bad_formats, RxBadFormatCnt); | ||
437 | DEVICE_COUNTER(rx_buf_ovfls, RxBufOvflCnt); | ||
438 | DEVICE_COUNTER(rx_data_pkts, RxDataPktCnt); | ||
439 | DEVICE_COUNTER(rx_dropped_pkts, RxDroppedPktCnt); | ||
440 | DEVICE_COUNTER(rx_dwords, RxDwordCnt); | ||
441 | DEVICE_COUNTER(rx_ebps, RxEBPCnt); | ||
442 | DEVICE_COUNTER(rx_flow_ctrl_errs, RxFlowCtrlErrCnt); | ||
443 | DEVICE_COUNTER(rx_flow_pkts, RxFlowPktCnt); | ||
444 | DEVICE_COUNTER(rx_icrc_errs, RxICRCErrCnt); | ||
445 | DEVICE_COUNTER(rx_len_errs, RxLenErrCnt); | ||
446 | DEVICE_COUNTER(rx_link_problems, RxLinkProblemCnt); | ||
447 | DEVICE_COUNTER(rx_lpcrc_errs, RxLPCRCErrCnt); | ||
448 | DEVICE_COUNTER(rx_max_min_len_errs, RxMaxMinLenErrCnt); | ||
449 | DEVICE_COUNTER(rx_p0_hdr_egr_ovfls, RxP0HdrEgrOvflCnt); | ||
450 | DEVICE_COUNTER(rx_p1_hdr_egr_ovfls, RxP1HdrEgrOvflCnt); | ||
451 | DEVICE_COUNTER(rx_p2_hdr_egr_ovfls, RxP2HdrEgrOvflCnt); | ||
452 | DEVICE_COUNTER(rx_p3_hdr_egr_ovfls, RxP3HdrEgrOvflCnt); | ||
453 | DEVICE_COUNTER(rx_p4_hdr_egr_ovfls, RxP4HdrEgrOvflCnt); | ||
454 | DEVICE_COUNTER(rx_p5_hdr_egr_ovfls, RxP5HdrEgrOvflCnt); | ||
455 | DEVICE_COUNTER(rx_p6_hdr_egr_ovfls, RxP6HdrEgrOvflCnt); | ||
456 | DEVICE_COUNTER(rx_p7_hdr_egr_ovfls, RxP7HdrEgrOvflCnt); | ||
457 | DEVICE_COUNTER(rx_p8_hdr_egr_ovfls, RxP8HdrEgrOvflCnt); | ||
458 | DEVICE_COUNTER(rx_pkey_mismatches, RxPKeyMismatchCnt); | ||
459 | DEVICE_COUNTER(rx_tid_full_errs, RxTIDFullErrCnt); | ||
460 | DEVICE_COUNTER(rx_tid_valid_errs, RxTIDValidErrCnt); | ||
461 | DEVICE_COUNTER(rx_vcrc_errs, RxVCRCErrCnt); | ||
462 | DEVICE_COUNTER(tx_data_pkts, TxDataPktCnt); | ||
463 | DEVICE_COUNTER(tx_dropped_pkts, TxDroppedPktCnt); | ||
464 | DEVICE_COUNTER(tx_dwords, TxDwordCnt); | ||
465 | DEVICE_COUNTER(tx_flow_pkts, TxFlowPktCnt); | ||
466 | DEVICE_COUNTER(tx_flow_stalls, TxFlowStallCnt); | ||
467 | DEVICE_COUNTER(tx_len_errs, TxLenErrCnt); | ||
468 | DEVICE_COUNTER(tx_max_min_len_errs, TxMaxMinLenErrCnt); | ||
469 | DEVICE_COUNTER(tx_underruns, TxUnderrunCnt); | ||
470 | DEVICE_COUNTER(tx_unsup_vl_errs, TxUnsupVLErrCnt); | ||
471 | |||
472 | static struct attribute *dev_counter_attributes[] = { | ||
473 | &dev_attr_ib_link_downeds.attr, | ||
474 | &dev_attr_ib_link_err_recoveries.attr, | ||
475 | &dev_attr_ib_status_changes.attr, | ||
476 | &dev_attr_ib_symbol_errs.attr, | ||
477 | &dev_attr_lb_flow_stalls.attr, | ||
478 | &dev_attr_lb_ints.attr, | ||
479 | &dev_attr_rx_bad_formats.attr, | ||
480 | &dev_attr_rx_buf_ovfls.attr, | ||
481 | &dev_attr_rx_data_pkts.attr, | ||
482 | &dev_attr_rx_dropped_pkts.attr, | ||
483 | &dev_attr_rx_dwords.attr, | ||
484 | &dev_attr_rx_ebps.attr, | ||
485 | &dev_attr_rx_flow_ctrl_errs.attr, | ||
486 | &dev_attr_rx_flow_pkts.attr, | ||
487 | &dev_attr_rx_icrc_errs.attr, | ||
488 | &dev_attr_rx_len_errs.attr, | ||
489 | &dev_attr_rx_link_problems.attr, | ||
490 | &dev_attr_rx_lpcrc_errs.attr, | ||
491 | &dev_attr_rx_max_min_len_errs.attr, | ||
492 | &dev_attr_rx_p0_hdr_egr_ovfls.attr, | ||
493 | &dev_attr_rx_p1_hdr_egr_ovfls.attr, | ||
494 | &dev_attr_rx_p2_hdr_egr_ovfls.attr, | ||
495 | &dev_attr_rx_p3_hdr_egr_ovfls.attr, | ||
496 | &dev_attr_rx_p4_hdr_egr_ovfls.attr, | ||
497 | &dev_attr_rx_p5_hdr_egr_ovfls.attr, | ||
498 | &dev_attr_rx_p6_hdr_egr_ovfls.attr, | ||
499 | &dev_attr_rx_p7_hdr_egr_ovfls.attr, | ||
500 | &dev_attr_rx_p8_hdr_egr_ovfls.attr, | ||
501 | &dev_attr_rx_pkey_mismatches.attr, | ||
502 | &dev_attr_rx_tid_full_errs.attr, | ||
503 | &dev_attr_rx_tid_valid_errs.attr, | ||
504 | &dev_attr_rx_vcrc_errs.attr, | ||
505 | &dev_attr_tx_data_pkts.attr, | ||
506 | &dev_attr_tx_dropped_pkts.attr, | ||
507 | &dev_attr_tx_dwords.attr, | ||
508 | &dev_attr_tx_flow_pkts.attr, | ||
509 | &dev_attr_tx_flow_stalls.attr, | ||
510 | &dev_attr_tx_len_errs.attr, | ||
511 | &dev_attr_tx_max_min_len_errs.attr, | ||
512 | &dev_attr_tx_underruns.attr, | ||
513 | &dev_attr_tx_unsup_vl_errs.attr, | ||
514 | NULL | ||
515 | }; | ||
516 | |||
517 | static struct attribute_group dev_counter_attr_group = { | ||
518 | .name = "counters", | ||
519 | .attrs = dev_counter_attributes | ||
520 | }; | ||
521 | |||
522 | static ssize_t store_reset(struct device *dev, | ||
523 | struct device_attribute *attr, | ||
524 | const char *buf, | ||
525 | size_t count) | ||
526 | { | ||
527 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
528 | int ret; | ||
529 | |||
530 | if (count < 5 || memcmp(buf, "reset", 5)) { | ||
531 | ret = -EINVAL; | ||
532 | goto bail; | ||
533 | } | ||
534 | |||
535 | if (dd->ipath_flags & IPATH_DISABLED) { | ||
536 | /* | ||
537 | * post-reset init would re-enable interrupts, etc. | ||
538 | * so don't allow reset on disabled devices. Not | ||
539 | * perfect error, but about the best choice. | ||
540 | */ | ||
541 | dev_info(dev,"Unit %d is disabled, can't reset\n", | ||
542 | dd->ipath_unit); | ||
543 | ret = -EINVAL; | ||
544 | } | ||
545 | ret = ipath_reset_device(dd->ipath_unit); | ||
546 | bail: | ||
547 | return ret<0 ? ret : count; | ||
548 | } | ||
549 | |||
550 | static ssize_t store_link_state(struct device *dev, | ||
551 | struct device_attribute *attr, | ||
552 | const char *buf, | ||
553 | size_t count) | ||
554 | { | ||
555 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
556 | int ret, r; | ||
557 | u16 state; | ||
558 | |||
559 | ret = ipath_parse_ushort(buf, &state); | ||
560 | if (ret < 0) | ||
561 | goto invalid; | ||
562 | |||
563 | r = ipath_layer_set_linkstate(dd, state); | ||
564 | if (r < 0) { | ||
565 | ret = r; | ||
566 | goto bail; | ||
567 | } | ||
568 | |||
569 | goto bail; | ||
570 | invalid: | ||
571 | ipath_dev_err(dd, "attempt to set invalid link state\n"); | ||
572 | bail: | ||
573 | return ret; | ||
574 | } | ||
575 | |||
576 | static ssize_t show_mtu(struct device *dev, | ||
577 | struct device_attribute *attr, | ||
578 | char *buf) | ||
579 | { | ||
580 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
581 | return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_ibmtu); | ||
582 | } | ||
583 | |||
584 | static ssize_t store_mtu(struct device *dev, | ||
585 | struct device_attribute *attr, | ||
586 | const char *buf, | ||
587 | size_t count) | ||
588 | { | ||
589 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
590 | ssize_t ret; | ||
591 | u16 mtu = 0; | ||
592 | int r; | ||
593 | |||
594 | ret = ipath_parse_ushort(buf, &mtu); | ||
595 | if (ret < 0) | ||
596 | goto invalid; | ||
597 | |||
598 | r = ipath_layer_set_mtu(dd, mtu); | ||
599 | if (r < 0) | ||
600 | ret = r; | ||
601 | |||
602 | goto bail; | ||
603 | invalid: | ||
604 | ipath_dev_err(dd, "attempt to set invalid MTU\n"); | ||
605 | bail: | ||
606 | return ret; | ||
607 | } | ||
608 | |||
609 | static ssize_t show_enabled(struct device *dev, | ||
610 | struct device_attribute *attr, | ||
611 | char *buf) | ||
612 | { | ||
613 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
614 | return scnprintf(buf, PAGE_SIZE, "%u\n", | ||
615 | (dd->ipath_flags & IPATH_DISABLED) ? 0 : 1); | ||
616 | } | ||
617 | |||
618 | static ssize_t store_enabled(struct device *dev, | ||
619 | struct device_attribute *attr, | ||
620 | const char *buf, | ||
621 | size_t count) | ||
622 | { | ||
623 | struct ipath_devdata *dd = dev_get_drvdata(dev); | ||
624 | ssize_t ret; | ||
625 | u16 enable = 0; | ||
626 | |||
627 | ret = ipath_parse_ushort(buf, &enable); | ||
628 | if (ret < 0) { | ||
629 | ipath_dev_err(dd, "attempt to use non-numeric on enable\n"); | ||
630 | goto bail; | ||
631 | } | ||
632 | |||
633 | if (enable) { | ||
634 | if (!(dd->ipath_flags & IPATH_DISABLED)) | ||
635 | goto bail; | ||
636 | |||
637 | dev_info(dev, "Enabling unit %d\n", dd->ipath_unit); | ||
638 | /* same as post-reset */ | ||
639 | ret = ipath_init_chip(dd, 1); | ||
640 | if (ret) | ||
641 | ipath_dev_err(dd, "Failed to enable unit %d\n", | ||
642 | dd->ipath_unit); | ||
643 | else { | ||
644 | dd->ipath_flags &= ~IPATH_DISABLED; | ||
645 | *dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED; | ||
646 | } | ||
647 | } | ||
648 | else if (!(dd->ipath_flags & IPATH_DISABLED)) { | ||
649 | dev_info(dev, "Disabling unit %d\n", dd->ipath_unit); | ||
650 | ipath_shutdown_device(dd); | ||
651 | dd->ipath_flags |= IPATH_DISABLED; | ||
652 | *dd->ipath_statusp |= IPATH_STATUS_ADMIN_DISABLED; | ||
653 | } | ||
654 | |||
655 | bail: | ||
656 | return ret; | ||
657 | } | ||
658 | |||
659 | static DRIVER_ATTR(num_units, S_IRUGO, show_num_units, NULL); | ||
660 | static DRIVER_ATTR(version, S_IRUGO, show_version, NULL); | ||
661 | |||
662 | static struct attribute *driver_attributes[] = { | ||
663 | &driver_attr_num_units.attr, | ||
664 | &driver_attr_version.attr, | ||
665 | NULL | ||
666 | }; | ||
667 | |||
668 | static struct attribute_group driver_attr_group = { | ||
669 | .attrs = driver_attributes | ||
670 | }; | ||
671 | |||
672 | static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid); | ||
673 | static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid); | ||
674 | static DEVICE_ATTR(link_state, S_IWUSR, NULL, store_link_state); | ||
675 | static DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid); | ||
676 | static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu); | ||
677 | static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled); | ||
678 | static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL); | ||
679 | static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset); | ||
680 | static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL); | ||
681 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); | ||
682 | static DEVICE_ATTR(status_str, S_IRUGO, show_status_str, NULL); | ||
683 | static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL); | ||
684 | static DEVICE_ATTR(unit, S_IRUGO, show_unit, NULL); | ||
685 | |||
686 | static struct attribute *dev_attributes[] = { | ||
687 | &dev_attr_guid.attr, | ||
688 | &dev_attr_lid.attr, | ||
689 | &dev_attr_link_state.attr, | ||
690 | &dev_attr_mlid.attr, | ||
691 | &dev_attr_mtu.attr, | ||
692 | &dev_attr_nguid.attr, | ||
693 | &dev_attr_serial.attr, | ||
694 | &dev_attr_status.attr, | ||
695 | &dev_attr_status_str.attr, | ||
696 | &dev_attr_boardversion.attr, | ||
697 | &dev_attr_unit.attr, | ||
698 | &dev_attr_enabled.attr, | ||
699 | NULL | ||
700 | }; | ||
701 | |||
702 | static struct attribute_group dev_attr_group = { | ||
703 | .attrs = dev_attributes | ||
704 | }; | ||
705 | |||
706 | /** | ||
707 | * ipath_expose_reset - create a device reset file | ||
708 | * @dev: the device structure | ||
709 | * | ||
710 | * Only expose a file that lets us reset the device after someone | ||
711 | * enters diag mode. A device reset is quite likely to crash the | ||
712 | * machine entirely, so we don't want to normally make it | ||
713 | * available. | ||
714 | */ | ||
715 | int ipath_expose_reset(struct device *dev) | ||
716 | { | ||
717 | return device_create_file(dev, &dev_attr_reset); | ||
718 | } | ||
719 | |||
720 | int ipath_driver_create_group(struct device_driver *drv) | ||
721 | { | ||
722 | int ret; | ||
723 | |||
724 | ret = sysfs_create_group(&drv->kobj, &driver_attr_group); | ||
725 | if (ret) | ||
726 | goto bail; | ||
727 | |||
728 | ret = sysfs_create_group(&drv->kobj, &driver_stat_attr_group); | ||
729 | if (ret) | ||
730 | sysfs_remove_group(&drv->kobj, &driver_attr_group); | ||
731 | |||
732 | bail: | ||
733 | return ret; | ||
734 | } | ||
735 | |||
736 | void ipath_driver_remove_group(struct device_driver *drv) | ||
737 | { | ||
738 | sysfs_remove_group(&drv->kobj, &driver_stat_attr_group); | ||
739 | sysfs_remove_group(&drv->kobj, &driver_attr_group); | ||
740 | } | ||
741 | |||
742 | int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd) | ||
743 | { | ||
744 | int ret; | ||
745 | char unit[5]; | ||
746 | |||
747 | ret = sysfs_create_group(&dev->kobj, &dev_attr_group); | ||
748 | if (ret) | ||
749 | goto bail; | ||
750 | |||
751 | ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group); | ||
752 | if (ret) | ||
753 | goto bail_attrs; | ||
754 | |||
755 | snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit); | ||
756 | ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit); | ||
757 | if (ret == 0) | ||
758 | goto bail; | ||
759 | |||
760 | sysfs_remove_group(&dev->kobj, &dev_counter_attr_group); | ||
761 | bail_attrs: | ||
762 | sysfs_remove_group(&dev->kobj, &dev_attr_group); | ||
763 | bail: | ||
764 | return ret; | ||
765 | } | ||
766 | |||
767 | void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd) | ||
768 | { | ||
769 | char unit[5]; | ||
770 | |||
771 | snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit); | ||
772 | sysfs_remove_link(&dev->driver->kobj, unit); | ||
773 | |||
774 | sysfs_remove_group(&dev->kobj, &dev_counter_attr_group); | ||
775 | sysfs_remove_group(&dev->kobj, &dev_attr_group); | ||
776 | |||
777 | device_remove_file(dev, &dev_attr_reset); | ||
778 | } | ||