IB/mad: pass ib_mad_send_buf explicitly to the recv_handler
[deliverable/linux.git] / drivers / infiniband / core / sysfs.c
CommitLineData
1da177e4
LT
1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
2a1d9b7f
RD
3 * Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved.
4 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
1da177e4
LT
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
1da177e4
LT
33 */
34
35#include "core_priv.h"
36
8c65b4a6 37#include <linux/slab.h>
fc87af74 38#include <linux/stat.h>
8c65b4a6 39#include <linux/string.h>
470be516 40#include <linux/netdevice.h>
8c65b4a6 41
a4d61e84 42#include <rdma/ib_mad.h>
b2788ce5 43#include <rdma/ib_pma.h>
1da177e4 44
470be516
MB
45struct ib_port;
46
47struct gid_attr_group {
48 struct ib_port *port;
49 struct kobject kobj;
50 struct attribute_group ndev;
51 struct attribute_group type;
52};
1da177e4
LT
53struct ib_port {
54 struct kobject kobj;
55 struct ib_device *ibdev;
470be516 56 struct gid_attr_group *gid_attr_group;
1da177e4 57 struct attribute_group gid_group;
1da177e4 58 struct attribute_group pkey_group;
1da177e4 59 u8 port_num;
145d9c54 60 struct attribute_group *pma_table;
1da177e4
LT
61};
62
63struct port_attribute {
64 struct attribute attr;
65 ssize_t (*show)(struct ib_port *, struct port_attribute *, char *buf);
66 ssize_t (*store)(struct ib_port *, struct port_attribute *,
67 const char *buf, size_t count);
68};
69
70#define PORT_ATTR(_name, _mode, _show, _store) \
71struct port_attribute port_attr_##_name = __ATTR(_name, _mode, _show, _store)
72
73#define PORT_ATTR_RO(_name) \
74struct port_attribute port_attr_##_name = __ATTR_RO(_name)
75
76struct port_table_attribute {
d48593bf
DT
77 struct port_attribute attr;
78 char name[8];
79 int index;
65487fdc 80 __be16 attr_id;
1da177e4
LT
81};
82
83static ssize_t port_attr_show(struct kobject *kobj,
84 struct attribute *attr, char *buf)
85{
86 struct port_attribute *port_attr =
87 container_of(attr, struct port_attribute, attr);
88 struct ib_port *p = container_of(kobj, struct ib_port, kobj);
89
90 if (!port_attr->show)
70f2817a 91 return -EIO;
1da177e4
LT
92
93 return port_attr->show(p, port_attr, buf);
94}
95
52cf25d0 96static const struct sysfs_ops port_sysfs_ops = {
1da177e4
LT
97 .show = port_attr_show
98};
99
470be516
MB
100static ssize_t gid_attr_show(struct kobject *kobj,
101 struct attribute *attr, char *buf)
102{
103 struct port_attribute *port_attr =
104 container_of(attr, struct port_attribute, attr);
105 struct ib_port *p = container_of(kobj, struct gid_attr_group,
106 kobj)->port;
107
108 if (!port_attr->show)
109 return -EIO;
110
111 return port_attr->show(p, port_attr, buf);
112}
113
114static const struct sysfs_ops gid_attr_sysfs_ops = {
115 .show = gid_attr_show
116};
117
1da177e4
LT
118static ssize_t state_show(struct ib_port *p, struct port_attribute *unused,
119 char *buf)
120{
121 struct ib_port_attr attr;
122 ssize_t ret;
123
124 static const char *state_name[] = {
125 [IB_PORT_NOP] = "NOP",
126 [IB_PORT_DOWN] = "DOWN",
127 [IB_PORT_INIT] = "INIT",
128 [IB_PORT_ARMED] = "ARMED",
129 [IB_PORT_ACTIVE] = "ACTIVE",
130 [IB_PORT_ACTIVE_DEFER] = "ACTIVE_DEFER"
131 };
132
133 ret = ib_query_port(p->ibdev, p->port_num, &attr);
134 if (ret)
135 return ret;
136
137 return sprintf(buf, "%d: %s\n", attr.state,
048975ac 138 attr.state >= 0 && attr.state < ARRAY_SIZE(state_name) ?
1da177e4
LT
139 state_name[attr.state] : "UNKNOWN");
140}
141
142static ssize_t lid_show(struct ib_port *p, struct port_attribute *unused,
143 char *buf)
144{
145 struct ib_port_attr attr;
146 ssize_t ret;
147
148 ret = ib_query_port(p->ibdev, p->port_num, &attr);
149 if (ret)
150 return ret;
151
152 return sprintf(buf, "0x%x\n", attr.lid);
153}
154
155static ssize_t lid_mask_count_show(struct ib_port *p,
156 struct port_attribute *unused,
157 char *buf)
158{
159 struct ib_port_attr attr;
160 ssize_t ret;
161
162 ret = ib_query_port(p->ibdev, p->port_num, &attr);
163 if (ret)
164 return ret;
165
166 return sprintf(buf, "%d\n", attr.lmc);
167}
168
169static ssize_t sm_lid_show(struct ib_port *p, struct port_attribute *unused,
170 char *buf)
171{
172 struct ib_port_attr attr;
173 ssize_t ret;
174
175 ret = ib_query_port(p->ibdev, p->port_num, &attr);
176 if (ret)
177 return ret;
178
179 return sprintf(buf, "0x%x\n", attr.sm_lid);
180}
181
182static ssize_t sm_sl_show(struct ib_port *p, struct port_attribute *unused,
183 char *buf)
184{
185 struct ib_port_attr attr;
186 ssize_t ret;
187
188 ret = ib_query_port(p->ibdev, p->port_num, &attr);
189 if (ret)
190 return ret;
191
192 return sprintf(buf, "%d\n", attr.sm_sl);
193}
194
195static ssize_t cap_mask_show(struct ib_port *p, struct port_attribute *unused,
196 char *buf)
197{
198 struct ib_port_attr attr;
199 ssize_t ret;
200
201 ret = ib_query_port(p->ibdev, p->port_num, &attr);
202 if (ret)
203 return ret;
204
205 return sprintf(buf, "0x%08x\n", attr.port_cap_flags);
206}
207
208static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused,
209 char *buf)
210{
211 struct ib_port_attr attr;
212 char *speed = "";
0559d8dc 213 int rate; /* in deci-Gb/sec */
1da177e4
LT
214 ssize_t ret;
215
216 ret = ib_query_port(p->ibdev, p->port_num, &attr);
217 if (ret)
218 return ret;
219
220 switch (attr.active_speed) {
2e96691c 221 case IB_SPEED_DDR:
71eeba16 222 speed = " DDR";
e9319b0c 223 rate = 50;
71eeba16 224 break;
2e96691c 225 case IB_SPEED_QDR:
71eeba16 226 speed = " QDR";
e9319b0c 227 rate = 100;
71eeba16 228 break;
2e96691c 229 case IB_SPEED_FDR10:
71eeba16 230 speed = " FDR10";
e9319b0c 231 rate = 100;
71eeba16 232 break;
2e96691c 233 case IB_SPEED_FDR:
71eeba16 234 speed = " FDR";
e9319b0c 235 rate = 140;
71eeba16 236 break;
2e96691c 237 case IB_SPEED_EDR:
71eeba16 238 speed = " EDR";
e9319b0c 239 rate = 250;
71eeba16 240 break;
0559d8dc
RD
241 case IB_SPEED_SDR:
242 default: /* default to SDR for invalid rates */
243 rate = 25;
244 break;
1da177e4
LT
245 }
246
71eeba16 247 rate *= ib_width_enum_to_int(attr.active_width);
1da177e4
LT
248 if (rate < 0)
249 return -EINVAL;
250
251 return sprintf(buf, "%d%s Gb/sec (%dX%s)\n",
e9319b0c 252 rate / 10, rate % 10 ? ".5" : "",
1da177e4
LT
253 ib_width_enum_to_int(attr.active_width), speed);
254}
255
256static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
257 char *buf)
258{
259 struct ib_port_attr attr;
260
261 ssize_t ret;
262
263 ret = ib_query_port(p->ibdev, p->port_num, &attr);
264 if (ret)
265 return ret;
266
267 switch (attr.phys_state) {
268 case 1: return sprintf(buf, "1: Sleep\n");
269 case 2: return sprintf(buf, "2: Polling\n");
270 case 3: return sprintf(buf, "3: Disabled\n");
271 case 4: return sprintf(buf, "4: PortConfigurationTraining\n");
272 case 5: return sprintf(buf, "5: LinkUp\n");
273 case 6: return sprintf(buf, "6: LinkErrorRecovery\n");
274 case 7: return sprintf(buf, "7: Phy Test\n");
275 default: return sprintf(buf, "%d: <unknown>\n", attr.phys_state);
276 }
277}
278
8ad330a0
EC
279static ssize_t link_layer_show(struct ib_port *p, struct port_attribute *unused,
280 char *buf)
281{
282 switch (rdma_port_get_link_layer(p->ibdev, p->port_num)) {
283 case IB_LINK_LAYER_INFINIBAND:
284 return sprintf(buf, "%s\n", "InfiniBand");
285 case IB_LINK_LAYER_ETHERNET:
286 return sprintf(buf, "%s\n", "Ethernet");
287 default:
288 return sprintf(buf, "%s\n", "Unknown");
289 }
290}
291
1da177e4
LT
292static PORT_ATTR_RO(state);
293static PORT_ATTR_RO(lid);
294static PORT_ATTR_RO(lid_mask_count);
295static PORT_ATTR_RO(sm_lid);
296static PORT_ATTR_RO(sm_sl);
297static PORT_ATTR_RO(cap_mask);
298static PORT_ATTR_RO(rate);
299static PORT_ATTR_RO(phys_state);
8ad330a0 300static PORT_ATTR_RO(link_layer);
1da177e4
LT
301
302static struct attribute *port_default_attrs[] = {
303 &port_attr_state.attr,
304 &port_attr_lid.attr,
305 &port_attr_lid_mask_count.attr,
306 &port_attr_sm_lid.attr,
307 &port_attr_sm_sl.attr,
308 &port_attr_cap_mask.attr,
309 &port_attr_rate.attr,
310 &port_attr_phys_state.attr,
8ad330a0 311 &port_attr_link_layer.attr,
1da177e4
LT
312 NULL
313};
314
470be516
MB
315static size_t print_ndev(struct ib_gid_attr *gid_attr, char *buf)
316{
317 if (!gid_attr->ndev)
318 return -EINVAL;
319
320 return sprintf(buf, "%s\n", gid_attr->ndev->name);
321}
322
323static size_t print_gid_type(struct ib_gid_attr *gid_attr, char *buf)
324{
325 return sprintf(buf, "%s\n", ib_cache_gid_type_str(gid_attr->gid_type));
326}
327
328static ssize_t _show_port_gid_attr(struct ib_port *p,
329 struct port_attribute *attr,
330 char *buf,
331 size_t (*print)(struct ib_gid_attr *gid_attr,
332 char *buf))
333{
334 struct port_table_attribute *tab_attr =
335 container_of(attr, struct port_table_attribute, attr);
336 union ib_gid gid;
337 struct ib_gid_attr gid_attr = {};
338 ssize_t ret;
339 va_list args;
340
341 ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid,
342 &gid_attr);
343 if (ret)
344 goto err;
345
346 ret = print(&gid_attr, buf);
347
348err:
349 if (gid_attr.ndev)
350 dev_put(gid_attr.ndev);
351 va_end(args);
352 return ret;
353}
354
1da177e4
LT
355static ssize_t show_port_gid(struct ib_port *p, struct port_attribute *attr,
356 char *buf)
357{
358 struct port_table_attribute *tab_attr =
359 container_of(attr, struct port_table_attribute, attr);
360 union ib_gid gid;
361 ssize_t ret;
362
55ee3ab2 363 ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid, NULL);
1da177e4
LT
364 if (ret)
365 return ret;
366
5b095d98 367 return sprintf(buf, "%pI6\n", gid.raw);
1da177e4
LT
368}
369
470be516
MB
370static ssize_t show_port_gid_attr_ndev(struct ib_port *p,
371 struct port_attribute *attr, char *buf)
372{
373 return _show_port_gid_attr(p, attr, buf, print_ndev);
374}
375
376static ssize_t show_port_gid_attr_gid_type(struct ib_port *p,
377 struct port_attribute *attr,
378 char *buf)
379{
380 return _show_port_gid_attr(p, attr, buf, print_gid_type);
381}
382
1da177e4
LT
383static ssize_t show_port_pkey(struct ib_port *p, struct port_attribute *attr,
384 char *buf)
385{
386 struct port_table_attribute *tab_attr =
387 container_of(attr, struct port_table_attribute, attr);
388 u16 pkey;
389 ssize_t ret;
390
391 ret = ib_query_pkey(p->ibdev, p->port_num, tab_attr->index, &pkey);
392 if (ret)
393 return ret;
394
395 return sprintf(buf, "0x%04x\n", pkey);
396}
397
398#define PORT_PMA_ATTR(_name, _counter, _width, _offset) \
399struct port_table_attribute port_pma_attr_##_name = { \
400 .attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \
b2788ce5
CL
401 .index = (_offset) | ((_width) << 16) | ((_counter) << 24), \
402 .attr_id = IB_PMA_PORT_COUNTERS , \
1da177e4
LT
403}
404
145d9c54
CL
405#define PORT_PMA_ATTR_EXT(_name, _width, _offset) \
406struct port_table_attribute port_pma_attr_ext_##_name = { \
407 .attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \
408 .index = (_offset) | ((_width) << 16), \
409 .attr_id = IB_PMA_PORT_COUNTERS_EXT , \
410}
411
35c4cbb1
CL
412/*
413 * Get a Perfmgmt MAD block of data.
414 * Returns error code or the number of bytes retrieved.
415 */
65487fdc 416static int get_perf_mad(struct ib_device *dev, int port_num, __be16 attr,
35c4cbb1 417 void *data, int offset, size_t size)
1da177e4 418{
35c4cbb1
CL
419 struct ib_mad *in_mad;
420 struct ib_mad *out_mad;
4cd7c947
IW
421 size_t mad_size = sizeof(*out_mad);
422 u16 out_mad_pkey_index = 0;
1da177e4
LT
423 ssize_t ret;
424
35c4cbb1
CL
425 if (!dev->process_mad)
426 return -ENOSYS;
1da177e4 427
de6eb66b 428 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
856c52a7 429 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
1da177e4
LT
430 if (!in_mad || !out_mad) {
431 ret = -ENOMEM;
432 goto out;
433 }
434
1da177e4
LT
435 in_mad->mad_hdr.base_version = 1;
436 in_mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_PERF_MGMT;
437 in_mad->mad_hdr.class_version = 1;
438 in_mad->mad_hdr.method = IB_MGMT_METHOD_GET;
35c4cbb1 439 in_mad->mad_hdr.attr_id = attr;
1da177e4 440
35c4cbb1 441 in_mad->data[41] = port_num; /* PortSelect field */
1da177e4 442
35c4cbb1
CL
443 if ((dev->process_mad(dev, IB_MAD_IGNORE_MKEY,
444 port_num, NULL, NULL,
4cd7c947
IW
445 (const struct ib_mad_hdr *)in_mad, mad_size,
446 (struct ib_mad_hdr *)out_mad, &mad_size,
447 &out_mad_pkey_index) &
1da177e4
LT
448 (IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) !=
449 (IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) {
450 ret = -EINVAL;
451 goto out;
452 }
35c4cbb1
CL
453 memcpy(data, out_mad->data + offset, size);
454 ret = size;
455out:
456 kfree(in_mad);
457 kfree(out_mad);
458 return ret;
459}
460
461static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
462 char *buf)
463{
464 struct port_table_attribute *tab_attr =
465 container_of(attr, struct port_table_attribute, attr);
466 int offset = tab_attr->index & 0xffff;
467 int width = (tab_attr->index >> 16) & 0xff;
468 ssize_t ret;
469 u8 data[8];
470
b2788ce5 471 ret = get_perf_mad(p->ibdev, p->port_num, tab_attr->attr_id, &data,
35c4cbb1
CL
472 40 + offset / 8, sizeof(data));
473 if (ret < 0)
474 return sprintf(buf, "N/A (no PMA)\n");
1da177e4
LT
475
476 switch (width) {
477 case 4:
35c4cbb1 478 ret = sprintf(buf, "%u\n", (*data >>
d8b9f23b 479 (4 - (offset % 8))) & 0xf);
1da177e4
LT
480 break;
481 case 8:
35c4cbb1 482 ret = sprintf(buf, "%u\n", *data);
1da177e4
LT
483 break;
484 case 16:
485 ret = sprintf(buf, "%u\n",
35c4cbb1 486 be16_to_cpup((__be16 *)data));
1da177e4
LT
487 break;
488 case 32:
489 ret = sprintf(buf, "%u\n",
35c4cbb1 490 be32_to_cpup((__be32 *)data));
1da177e4 491 break;
145d9c54
CL
492 case 64:
493 ret = sprintf(buf, "%llu\n",
494 be64_to_cpup((__be64 *)data));
495 break;
496
1da177e4
LT
497 default:
498 ret = 0;
499 }
500
1da177e4
LT
501 return ret;
502}
503
504static PORT_PMA_ATTR(symbol_error , 0, 16, 32);
505static PORT_PMA_ATTR(link_error_recovery , 1, 8, 48);
506static PORT_PMA_ATTR(link_downed , 2, 8, 56);
507static PORT_PMA_ATTR(port_rcv_errors , 3, 16, 64);
508static PORT_PMA_ATTR(port_rcv_remote_physical_errors, 4, 16, 80);
509static PORT_PMA_ATTR(port_rcv_switch_relay_errors , 5, 16, 96);
510static PORT_PMA_ATTR(port_xmit_discards , 6, 16, 112);
511static PORT_PMA_ATTR(port_xmit_constraint_errors , 7, 8, 128);
512static PORT_PMA_ATTR(port_rcv_constraint_errors , 8, 8, 136);
513static PORT_PMA_ATTR(local_link_integrity_errors , 9, 4, 152);
514static PORT_PMA_ATTR(excessive_buffer_overrun_errors, 10, 4, 156);
515static PORT_PMA_ATTR(VL15_dropped , 11, 16, 176);
516static PORT_PMA_ATTR(port_xmit_data , 12, 32, 192);
517static PORT_PMA_ATTR(port_rcv_data , 13, 32, 224);
518static PORT_PMA_ATTR(port_xmit_packets , 14, 32, 256);
519static PORT_PMA_ATTR(port_rcv_packets , 15, 32, 288);
520
145d9c54
CL
521/*
522 * Counters added by extended set
523 */
524static PORT_PMA_ATTR_EXT(port_xmit_data , 64, 64);
525static PORT_PMA_ATTR_EXT(port_rcv_data , 64, 128);
526static PORT_PMA_ATTR_EXT(port_xmit_packets , 64, 192);
527static PORT_PMA_ATTR_EXT(port_rcv_packets , 64, 256);
528static PORT_PMA_ATTR_EXT(unicast_xmit_packets , 64, 320);
529static PORT_PMA_ATTR_EXT(unicast_rcv_packets , 64, 384);
530static PORT_PMA_ATTR_EXT(multicast_xmit_packets , 64, 448);
531static PORT_PMA_ATTR_EXT(multicast_rcv_packets , 64, 512);
532
1da177e4
LT
533static struct attribute *pma_attrs[] = {
534 &port_pma_attr_symbol_error.attr.attr,
535 &port_pma_attr_link_error_recovery.attr.attr,
536 &port_pma_attr_link_downed.attr.attr,
537 &port_pma_attr_port_rcv_errors.attr.attr,
538 &port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
539 &port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
540 &port_pma_attr_port_xmit_discards.attr.attr,
541 &port_pma_attr_port_xmit_constraint_errors.attr.attr,
542 &port_pma_attr_port_rcv_constraint_errors.attr.attr,
543 &port_pma_attr_local_link_integrity_errors.attr.attr,
544 &port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
545 &port_pma_attr_VL15_dropped.attr.attr,
546 &port_pma_attr_port_xmit_data.attr.attr,
547 &port_pma_attr_port_rcv_data.attr.attr,
548 &port_pma_attr_port_xmit_packets.attr.attr,
549 &port_pma_attr_port_rcv_packets.attr.attr,
550 NULL
551};
552
145d9c54
CL
553static struct attribute *pma_attrs_ext[] = {
554 &port_pma_attr_symbol_error.attr.attr,
555 &port_pma_attr_link_error_recovery.attr.attr,
556 &port_pma_attr_link_downed.attr.attr,
557 &port_pma_attr_port_rcv_errors.attr.attr,
558 &port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
559 &port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
560 &port_pma_attr_port_xmit_discards.attr.attr,
561 &port_pma_attr_port_xmit_constraint_errors.attr.attr,
562 &port_pma_attr_port_rcv_constraint_errors.attr.attr,
563 &port_pma_attr_local_link_integrity_errors.attr.attr,
564 &port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
565 &port_pma_attr_VL15_dropped.attr.attr,
566 &port_pma_attr_ext_port_xmit_data.attr.attr,
567 &port_pma_attr_ext_port_rcv_data.attr.attr,
568 &port_pma_attr_ext_port_xmit_packets.attr.attr,
569 &port_pma_attr_ext_port_rcv_packets.attr.attr,
570 &port_pma_attr_ext_unicast_rcv_packets.attr.attr,
571 &port_pma_attr_ext_unicast_xmit_packets.attr.attr,
572 &port_pma_attr_ext_multicast_rcv_packets.attr.attr,
573 &port_pma_attr_ext_multicast_xmit_packets.attr.attr,
574 NULL
575};
576
577static struct attribute *pma_attrs_noietf[] = {
578 &port_pma_attr_symbol_error.attr.attr,
579 &port_pma_attr_link_error_recovery.attr.attr,
580 &port_pma_attr_link_downed.attr.attr,
581 &port_pma_attr_port_rcv_errors.attr.attr,
582 &port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
583 &port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
584 &port_pma_attr_port_xmit_discards.attr.attr,
585 &port_pma_attr_port_xmit_constraint_errors.attr.attr,
586 &port_pma_attr_port_rcv_constraint_errors.attr.attr,
587 &port_pma_attr_local_link_integrity_errors.attr.attr,
588 &port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
589 &port_pma_attr_VL15_dropped.attr.attr,
590 &port_pma_attr_ext_port_xmit_data.attr.attr,
591 &port_pma_attr_ext_port_rcv_data.attr.attr,
592 &port_pma_attr_ext_port_xmit_packets.attr.attr,
593 &port_pma_attr_ext_port_rcv_packets.attr.attr,
594 NULL
595};
596
1da177e4
LT
597static struct attribute_group pma_group = {
598 .name = "counters",
599 .attrs = pma_attrs
600};
601
145d9c54
CL
602static struct attribute_group pma_group_ext = {
603 .name = "counters",
604 .attrs = pma_attrs_ext
605};
606
607static struct attribute_group pma_group_noietf = {
608 .name = "counters",
609 .attrs = pma_attrs_noietf
610};
611
1da177e4
LT
612static void ib_port_release(struct kobject *kobj)
613{
614 struct ib_port *p = container_of(kobj, struct ib_port, kobj);
615 struct attribute *a;
616 int i;
617
cad6d02a
HE
618 if (p->gid_group.attrs) {
619 for (i = 0; (a = p->gid_group.attrs[i]); ++i)
620 kfree(a);
1da177e4 621
cad6d02a
HE
622 kfree(p->gid_group.attrs);
623 }
d48593bf 624
cad6d02a
HE
625 if (p->pkey_group.attrs) {
626 for (i = 0; (a = p->pkey_group.attrs[i]); ++i)
627 kfree(a);
1da177e4 628
cad6d02a
HE
629 kfree(p->pkey_group.attrs);
630 }
d48593bf 631
1da177e4
LT
632 kfree(p);
633}
634
470be516
MB
635static void ib_port_gid_attr_release(struct kobject *kobj)
636{
637 struct gid_attr_group *g = container_of(kobj, struct gid_attr_group,
638 kobj);
639 struct attribute *a;
640 int i;
641
642 if (g->ndev.attrs) {
643 for (i = 0; (a = g->ndev.attrs[i]); ++i)
644 kfree(a);
645
646 kfree(g->ndev.attrs);
647 }
648
649 if (g->type.attrs) {
650 for (i = 0; (a = g->type.attrs[i]); ++i)
651 kfree(a);
652
653 kfree(g->type.attrs);
654 }
655
656 kfree(g);
657}
658
1da177e4
LT
659static struct kobj_type port_type = {
660 .release = ib_port_release,
661 .sysfs_ops = &port_sysfs_ops,
662 .default_attrs = port_default_attrs
663};
664
470be516
MB
665static struct kobj_type gid_attr_type = {
666 .sysfs_ops = &gid_attr_sysfs_ops,
667 .release = ib_port_gid_attr_release
668};
669
d48593bf
DT
670static struct attribute **
671alloc_group_attrs(ssize_t (*show)(struct ib_port *,
672 struct port_attribute *, char *buf),
673 int len)
1da177e4 674{
d48593bf
DT
675 struct attribute **tab_attr;
676 struct port_table_attribute *element;
1da177e4 677 int i;
1da177e4 678
d48593bf
DT
679 tab_attr = kcalloc(1 + len, sizeof(struct attribute *), GFP_KERNEL);
680 if (!tab_attr)
681 return NULL;
1da177e4 682
d48593bf 683 for (i = 0; i < len; i++) {
82ca76b6 684 element = kzalloc(sizeof(struct port_table_attribute),
d48593bf
DT
685 GFP_KERNEL);
686 if (!element)
1da177e4 687 goto err;
1da177e4 688
d48593bf 689 if (snprintf(element->name, sizeof(element->name),
048975ac
RD
690 "%d", i) >= sizeof(element->name)) {
691 kfree(element);
1da177e4 692 goto err;
048975ac 693 }
1da177e4 694
d48593bf
DT
695 element->attr.attr.name = element->name;
696 element->attr.attr.mode = S_IRUGO;
d48593bf
DT
697 element->attr.show = show;
698 element->index = i;
21e3bde9 699 sysfs_attr_init(&element->attr.attr);
1da177e4 700
d48593bf 701 tab_attr[i] = &element->attr.attr;
1da177e4
LT
702 }
703
d48593bf 704 return tab_attr;
1da177e4 705
d48593bf
DT
706err:
707 while (--i >= 0)
708 kfree(tab_attr[i]);
709 kfree(tab_attr);
710 return NULL;
1da177e4
LT
711}
712
145d9c54
CL
713/*
714 * Figure out which counter table to use depending on
715 * the device capabilities.
716 */
717static struct attribute_group *get_counter_table(struct ib_device *dev)
718{
719 struct ib_class_port_info cpi;
720
721 if (get_perf_mad(dev, 0, IB_PMA_CLASS_PORT_INFO,
722 &cpi, 40, sizeof(cpi)) >= 0) {
723
724 if (cpi.capability_mask && IB_PMA_CLASS_CAP_EXT_WIDTH)
725 /* We have extended counters */
726 return &pma_group_ext;
727
728 if (cpi.capability_mask && IB_PMA_CLASS_CAP_EXT_WIDTH_NOIETF)
729 /* But not the IETF ones */
730 return &pma_group_noietf;
731 }
732
733 /* Fall back to normal counters */
734 return &pma_group;
735}
736
9a6edb60
RC
737static int add_port(struct ib_device *device, int port_num,
738 int (*port_callback)(struct ib_device *,
739 u8, struct kobject *))
1da177e4
LT
740{
741 struct ib_port *p;
742 struct ib_port_attr attr;
743 int i;
744 int ret;
745
746 ret = ib_query_port(device, port_num, &attr);
747 if (ret)
748 return ret;
749
de6eb66b 750 p = kzalloc(sizeof *p, GFP_KERNEL);
1da177e4
LT
751 if (!p)
752 return -ENOMEM;
1da177e4
LT
753
754 p->ibdev = device;
755 p->port_num = port_num;
1da177e4 756
35be0681 757 ret = kobject_init_and_add(&p->kobj, &port_type,
373c0ea1 758 device->ports_parent,
35be0681 759 "%d", port_num);
cad6d02a
HE
760 if (ret) {
761 kfree(p);
762 return ret;
763 }
1da177e4 764
470be516
MB
765 p->gid_attr_group = kzalloc(sizeof(*p->gid_attr_group), GFP_KERNEL);
766 if (!p->gid_attr_group) {
767 ret = -ENOMEM;
768 goto err_put;
769 }
770
771 p->gid_attr_group->port = p;
772 ret = kobject_init_and_add(&p->gid_attr_group->kobj, &gid_attr_type,
773 &p->kobj, "gid_attrs");
774 if (ret) {
775 kfree(p->gid_attr_group);
776 goto err_put;
777 }
778
145d9c54
CL
779 p->pma_table = get_counter_table(device);
780 ret = sysfs_create_group(&p->kobj, p->pma_table);
1da177e4 781 if (ret)
470be516 782 goto err_put_gid_attrs;
1da177e4 783
1da177e4 784 p->gid_group.name = "gids";
d48593bf 785 p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len);
80b15043
WY
786 if (!p->gid_group.attrs) {
787 ret = -ENOMEM;
d48593bf 788 goto err_remove_pma;
80b15043 789 }
1da177e4
LT
790
791 ret = sysfs_create_group(&p->kobj, &p->gid_group);
792 if (ret)
793 goto err_free_gid;
794
470be516
MB
795 p->gid_attr_group->ndev.name = "ndevs";
796 p->gid_attr_group->ndev.attrs = alloc_group_attrs(show_port_gid_attr_ndev,
797 attr.gid_tbl_len);
798 if (!p->gid_attr_group->ndev.attrs) {
799 ret = -ENOMEM;
800 goto err_remove_gid;
801 }
802
803 ret = sysfs_create_group(&p->gid_attr_group->kobj,
804 &p->gid_attr_group->ndev);
805 if (ret)
806 goto err_free_gid_ndev;
807
808 p->gid_attr_group->type.name = "types";
809 p->gid_attr_group->type.attrs = alloc_group_attrs(show_port_gid_attr_gid_type,
810 attr.gid_tbl_len);
811 if (!p->gid_attr_group->type.attrs) {
812 ret = -ENOMEM;
813 goto err_remove_gid_ndev;
814 }
815
816 ret = sysfs_create_group(&p->gid_attr_group->kobj,
817 &p->gid_attr_group->type);
818 if (ret)
819 goto err_free_gid_type;
820
1da177e4 821 p->pkey_group.name = "pkeys";
d48593bf
DT
822 p->pkey_group.attrs = alloc_group_attrs(show_port_pkey,
823 attr.pkey_tbl_len);
80b15043
WY
824 if (!p->pkey_group.attrs) {
825 ret = -ENOMEM;
470be516 826 goto err_remove_gid_type;
80b15043 827 }
1da177e4
LT
828
829 ret = sysfs_create_group(&p->kobj, &p->pkey_group);
830 if (ret)
831 goto err_free_pkey;
832
9a6edb60
RC
833 if (port_callback) {
834 ret = port_callback(device, port_num, &p->kobj);
835 if (ret)
836 goto err_remove_pkey;
837 }
838
1da177e4
LT
839 list_add_tail(&p->kobj.entry, &device->port_list);
840
35be0681 841 kobject_uevent(&p->kobj, KOBJ_ADD);
1da177e4
LT
842 return 0;
843
9a6edb60
RC
844err_remove_pkey:
845 sysfs_remove_group(&p->kobj, &p->pkey_group);
846
1da177e4 847err_free_pkey:
d48593bf
DT
848 for (i = 0; i < attr.pkey_tbl_len; ++i)
849 kfree(p->pkey_group.attrs[i]);
1da177e4 850
d48593bf 851 kfree(p->pkey_group.attrs);
cad6d02a 852 p->pkey_group.attrs = NULL;
1da177e4 853
470be516
MB
854err_remove_gid_type:
855 sysfs_remove_group(&p->gid_attr_group->kobj,
856 &p->gid_attr_group->type);
857
858err_free_gid_type:
859 for (i = 0; i < attr.gid_tbl_len; ++i)
860 kfree(p->gid_attr_group->type.attrs[i]);
861
862 kfree(p->gid_attr_group->type.attrs);
863 p->gid_attr_group->type.attrs = NULL;
864
865err_remove_gid_ndev:
866 sysfs_remove_group(&p->gid_attr_group->kobj,
867 &p->gid_attr_group->ndev);
868
869err_free_gid_ndev:
870 for (i = 0; i < attr.gid_tbl_len; ++i)
871 kfree(p->gid_attr_group->ndev.attrs[i]);
872
873 kfree(p->gid_attr_group->ndev.attrs);
874 p->gid_attr_group->ndev.attrs = NULL;
875
1da177e4
LT
876err_remove_gid:
877 sysfs_remove_group(&p->kobj, &p->gid_group);
878
879err_free_gid:
d48593bf
DT
880 for (i = 0; i < attr.gid_tbl_len; ++i)
881 kfree(p->gid_group.attrs[i]);
1da177e4 882
d48593bf 883 kfree(p->gid_group.attrs);
cad6d02a 884 p->gid_group.attrs = NULL;
1da177e4
LT
885
886err_remove_pma:
145d9c54 887 sysfs_remove_group(&p->kobj, p->pma_table);
1da177e4 888
470be516
MB
889err_put_gid_attrs:
890 kobject_put(&p->gid_attr_group->kobj);
891
1da177e4 892err_put:
cad6d02a 893 kobject_put(&p->kobj);
1da177e4
LT
894 return ret;
895}
896
f4e91eb4
TJ
897static ssize_t show_node_type(struct device *device,
898 struct device_attribute *attr, char *buf)
1da177e4 899{
f4e91eb4 900 struct ib_device *dev = container_of(device, struct ib_device, dev);
1da177e4
LT
901
902 switch (dev->node_type) {
07ebafba
TT
903 case RDMA_NODE_IB_CA: return sprintf(buf, "%d: CA\n", dev->node_type);
904 case RDMA_NODE_RNIC: return sprintf(buf, "%d: RNIC\n", dev->node_type);
180771a3 905 case RDMA_NODE_USNIC: return sprintf(buf, "%d: usNIC\n", dev->node_type);
5db5765e 906 case RDMA_NODE_USNIC_UDP: return sprintf(buf, "%d: usNIC UDP\n", dev->node_type);
07ebafba
TT
907 case RDMA_NODE_IB_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type);
908 case RDMA_NODE_IB_ROUTER: return sprintf(buf, "%d: router\n", dev->node_type);
909 default: return sprintf(buf, "%d: <unknown>\n", dev->node_type);
1da177e4
LT
910 }
911}
912
f4e91eb4
TJ
913static ssize_t show_sys_image_guid(struct device *device,
914 struct device_attribute *dev_attr, char *buf)
1da177e4 915{
f4e91eb4 916 struct ib_device *dev = container_of(device, struct ib_device, dev);
1da177e4
LT
917
918 return sprintf(buf, "%04x:%04x:%04x:%04x\n",
86bee4c9
OG
919 be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[0]),
920 be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[1]),
921 be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[2]),
922 be16_to_cpu(((__be16 *) &dev->attrs.sys_image_guid)[3]));
1da177e4
LT
923}
924
f4e91eb4
TJ
925static ssize_t show_node_guid(struct device *device,
926 struct device_attribute *attr, char *buf)
1da177e4 927{
f4e91eb4 928 struct ib_device *dev = container_of(device, struct ib_device, dev);
1da177e4 929
1da177e4 930 return sprintf(buf, "%04x:%04x:%04x:%04x\n",
cf311cd4
SH
931 be16_to_cpu(((__be16 *) &dev->node_guid)[0]),
932 be16_to_cpu(((__be16 *) &dev->node_guid)[1]),
933 be16_to_cpu(((__be16 *) &dev->node_guid)[2]),
934 be16_to_cpu(((__be16 *) &dev->node_guid)[3]));
1da177e4
LT
935}
936
f4e91eb4
TJ
937static ssize_t show_node_desc(struct device *device,
938 struct device_attribute *attr, char *buf)
c5bcbbb9 939{
f4e91eb4 940 struct ib_device *dev = container_of(device, struct ib_device, dev);
c5bcbbb9
RD
941
942 return sprintf(buf, "%.64s\n", dev->node_desc);
943}
944
f4e91eb4
TJ
945static ssize_t set_node_desc(struct device *device,
946 struct device_attribute *attr,
947 const char *buf, size_t count)
c5bcbbb9 948{
f4e91eb4 949 struct ib_device *dev = container_of(device, struct ib_device, dev);
c5bcbbb9
RD
950 struct ib_device_modify desc = {};
951 int ret;
952
953 if (!dev->modify_device)
954 return -EIO;
955
956 memcpy(desc.node_desc, buf, min_t(int, count, 64));
957 ret = ib_modify_device(dev, IB_DEVICE_MODIFY_NODE_DESC, &desc);
958 if (ret)
959 return ret;
960
961 return count;
962}
963
f4e91eb4
TJ
964static DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
965static DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL);
966static DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL);
967static DEVICE_ATTR(node_desc, S_IRUGO | S_IWUSR, show_node_desc, set_node_desc);
968
969static struct device_attribute *ib_class_attributes[] = {
970 &dev_attr_node_type,
971 &dev_attr_sys_image_guid,
972 &dev_attr_node_guid,
973 &dev_attr_node_desc
1da177e4
LT
974};
975
7f624d02
SW
976/* Show a given an attribute in the statistics group */
977static ssize_t show_protocol_stat(const struct device *device,
978 struct device_attribute *attr, char *buf,
979 unsigned offset)
980{
981 struct ib_device *dev = container_of(device, struct ib_device, dev);
982 union rdma_protocol_stats stats;
983 ssize_t ret;
984
985 ret = dev->get_protocol_stats(dev, &stats);
986 if (ret)
987 return ret;
988
989 return sprintf(buf, "%llu\n",
990 (unsigned long long) ((u64 *) &stats)[offset]);
991}
992
993/* generate a read-only iwarp statistics attribute */
994#define IW_STATS_ENTRY(name) \
995static ssize_t show_##name(struct device *device, \
996 struct device_attribute *attr, char *buf) \
997{ \
998 return show_protocol_stat(device, attr, buf, \
999 offsetof(struct iw_protocol_stats, name) / \
1000 sizeof (u64)); \
1001} \
1002static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
1003
1004IW_STATS_ENTRY(ipInReceives);
1005IW_STATS_ENTRY(ipInHdrErrors);
1006IW_STATS_ENTRY(ipInTooBigErrors);
1007IW_STATS_ENTRY(ipInNoRoutes);
1008IW_STATS_ENTRY(ipInAddrErrors);
1009IW_STATS_ENTRY(ipInUnknownProtos);
1010IW_STATS_ENTRY(ipInTruncatedPkts);
1011IW_STATS_ENTRY(ipInDiscards);
1012IW_STATS_ENTRY(ipInDelivers);
1013IW_STATS_ENTRY(ipOutForwDatagrams);
1014IW_STATS_ENTRY(ipOutRequests);
1015IW_STATS_ENTRY(ipOutDiscards);
1016IW_STATS_ENTRY(ipOutNoRoutes);
1017IW_STATS_ENTRY(ipReasmTimeout);
1018IW_STATS_ENTRY(ipReasmReqds);
1019IW_STATS_ENTRY(ipReasmOKs);
1020IW_STATS_ENTRY(ipReasmFails);
1021IW_STATS_ENTRY(ipFragOKs);
1022IW_STATS_ENTRY(ipFragFails);
1023IW_STATS_ENTRY(ipFragCreates);
1024IW_STATS_ENTRY(ipInMcastPkts);
1025IW_STATS_ENTRY(ipOutMcastPkts);
1026IW_STATS_ENTRY(ipInBcastPkts);
1027IW_STATS_ENTRY(ipOutBcastPkts);
1028IW_STATS_ENTRY(tcpRtoAlgorithm);
1029IW_STATS_ENTRY(tcpRtoMin);
1030IW_STATS_ENTRY(tcpRtoMax);
1031IW_STATS_ENTRY(tcpMaxConn);
1032IW_STATS_ENTRY(tcpActiveOpens);
1033IW_STATS_ENTRY(tcpPassiveOpens);
1034IW_STATS_ENTRY(tcpAttemptFails);
1035IW_STATS_ENTRY(tcpEstabResets);
1036IW_STATS_ENTRY(tcpCurrEstab);
1037IW_STATS_ENTRY(tcpInSegs);
1038IW_STATS_ENTRY(tcpOutSegs);
1039IW_STATS_ENTRY(tcpRetransSegs);
1040IW_STATS_ENTRY(tcpInErrs);
1041IW_STATS_ENTRY(tcpOutRsts);
1042
1043static struct attribute *iw_proto_stats_attrs[] = {
1044 &dev_attr_ipInReceives.attr,
1045 &dev_attr_ipInHdrErrors.attr,
1046 &dev_attr_ipInTooBigErrors.attr,
1047 &dev_attr_ipInNoRoutes.attr,
1048 &dev_attr_ipInAddrErrors.attr,
1049 &dev_attr_ipInUnknownProtos.attr,
1050 &dev_attr_ipInTruncatedPkts.attr,
1051 &dev_attr_ipInDiscards.attr,
1052 &dev_attr_ipInDelivers.attr,
1053 &dev_attr_ipOutForwDatagrams.attr,
1054 &dev_attr_ipOutRequests.attr,
1055 &dev_attr_ipOutDiscards.attr,
1056 &dev_attr_ipOutNoRoutes.attr,
1057 &dev_attr_ipReasmTimeout.attr,
1058 &dev_attr_ipReasmReqds.attr,
1059 &dev_attr_ipReasmOKs.attr,
1060 &dev_attr_ipReasmFails.attr,
1061 &dev_attr_ipFragOKs.attr,
1062 &dev_attr_ipFragFails.attr,
1063 &dev_attr_ipFragCreates.attr,
1064 &dev_attr_ipInMcastPkts.attr,
1065 &dev_attr_ipOutMcastPkts.attr,
1066 &dev_attr_ipInBcastPkts.attr,
1067 &dev_attr_ipOutBcastPkts.attr,
1068 &dev_attr_tcpRtoAlgorithm.attr,
1069 &dev_attr_tcpRtoMin.attr,
1070 &dev_attr_tcpRtoMax.attr,
1071 &dev_attr_tcpMaxConn.attr,
1072 &dev_attr_tcpActiveOpens.attr,
1073 &dev_attr_tcpPassiveOpens.attr,
1074 &dev_attr_tcpAttemptFails.attr,
1075 &dev_attr_tcpEstabResets.attr,
1076 &dev_attr_tcpCurrEstab.attr,
1077 &dev_attr_tcpInSegs.attr,
1078 &dev_attr_tcpOutSegs.attr,
1079 &dev_attr_tcpRetransSegs.attr,
1080 &dev_attr_tcpInErrs.attr,
1081 &dev_attr_tcpOutRsts.attr,
1082 NULL
1083};
1084
1085static struct attribute_group iw_stats_group = {
1086 .name = "proto_stats",
1087 .attrs = iw_proto_stats_attrs,
1088};
1089
584482ac
HE
1090static void free_port_list_attributes(struct ib_device *device)
1091{
1092 struct kobject *p, *t;
1093
1094 list_for_each_entry_safe(p, t, &device->port_list, entry) {
1095 struct ib_port *port = container_of(p, struct ib_port, kobj);
1096 list_del(&p->entry);
145d9c54 1097 sysfs_remove_group(p, port->pma_table);
584482ac
HE
1098 sysfs_remove_group(p, &port->pkey_group);
1099 sysfs_remove_group(p, &port->gid_group);
470be516
MB
1100 sysfs_remove_group(&port->gid_attr_group->kobj,
1101 &port->gid_attr_group->ndev);
1102 sysfs_remove_group(&port->gid_attr_group->kobj,
1103 &port->gid_attr_group->type);
1104 kobject_put(&port->gid_attr_group->kobj);
584482ac
HE
1105 kobject_put(p);
1106 }
1107
1108 kobject_put(device->ports_parent);
1109}
1110
9a6edb60
RC
1111int ib_device_register_sysfs(struct ib_device *device,
1112 int (*port_callback)(struct ib_device *,
1113 u8, struct kobject *))
1da177e4 1114{
f4e91eb4 1115 struct device *class_dev = &device->dev;
1da177e4
LT
1116 int ret;
1117 int i;
1118
55aeed06
JG
1119 device->dev.parent = device->dma_device;
1120 ret = dev_set_name(class_dev, "%s", device->name);
1121 if (ret)
1122 return ret;
1da177e4 1123
55aeed06 1124 ret = device_add(class_dev);
1da177e4
LT
1125 if (ret)
1126 goto err;
1127
1128 for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i) {
f4e91eb4 1129 ret = device_create_file(class_dev, ib_class_attributes[i]);
1da177e4
LT
1130 if (ret)
1131 goto err_unregister;
1132 }
1133
35be0681 1134 device->ports_parent = kobject_create_and_add("ports",
373c0ea1 1135 &class_dev->kobj);
c7482b81
LZ
1136 if (!device->ports_parent) {
1137 ret = -ENOMEM;
1da177e4 1138 goto err_put;
c7482b81 1139 }
1da177e4 1140
4139032b 1141 if (rdma_cap_ib_switch(device)) {
9a6edb60 1142 ret = add_port(device, 0, port_callback);
1da177e4
LT
1143 if (ret)
1144 goto err_put;
1145 } else {
1da177e4 1146 for (i = 1; i <= device->phys_port_cnt; ++i) {
9a6edb60 1147 ret = add_port(device, i, port_callback);
1da177e4
LT
1148 if (ret)
1149 goto err_put;
1150 }
1151 }
1152
7f624d02
SW
1153 if (device->node_type == RDMA_NODE_RNIC && device->get_protocol_stats) {
1154 ret = sysfs_create_group(&class_dev->kobj, &iw_stats_group);
1155 if (ret)
1156 goto err_put;
1157 }
1158
1da177e4
LT
1159 return 0;
1160
1161err_put:
584482ac 1162 free_port_list_attributes(device);
1da177e4 1163
1da177e4 1164err_unregister:
f4e91eb4 1165 device_unregister(class_dev);
1da177e4
LT
1166
1167err:
1168 return ret;
1169}
1170
1171void ib_device_unregister_sysfs(struct ib_device *device)
1172{
9206dff1 1173 /* Hold kobject until ib_dealloc_device() */
584482ac
HE
1174 struct kobject *kobj_dev = kobject_get(&device->dev.kobj);
1175 int i;
9206dff1 1176
584482ac
HE
1177 if (device->node_type == RDMA_NODE_RNIC && device->get_protocol_stats)
1178 sysfs_remove_group(kobj_dev, &iw_stats_group);
1179
1180 free_port_list_attributes(device);
1181
1182 for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i)
1183 device_remove_file(&device->dev, ib_class_attributes[i]);
1da177e4 1184
f4e91eb4 1185 device_unregister(&device->dev);
1da177e4 1186}
This page took 0.873494 seconds and 5 git commands to generate.