2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved.
4 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
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:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
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.
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
35 #include "core_priv.h"
37 #include <linux/slab.h>
38 #include <linux/stat.h>
39 #include <linux/string.h>
41 #include <rdma/ib_mad.h>
45 struct ib_device *ibdev;
46 struct attribute_group gid_group;
47 struct attribute_group pkey_group;
51 struct port_attribute {
52 struct attribute attr;
53 ssize_t (*show)(struct ib_port *, struct port_attribute *, char *buf);
54 ssize_t (*store)(struct ib_port *, struct port_attribute *,
55 const char *buf, size_t count);
58 #define PORT_ATTR(_name, _mode, _show, _store) \
59 struct port_attribute port_attr_##_name = __ATTR(_name, _mode, _show, _store)
61 #define PORT_ATTR_RO(_name) \
62 struct port_attribute port_attr_##_name = __ATTR_RO(_name)
64 struct port_table_attribute {
65 struct port_attribute attr;
70 static ssize_t port_attr_show(struct kobject *kobj,
71 struct attribute *attr, char *buf)
73 struct port_attribute *port_attr =
74 container_of(attr, struct port_attribute, attr);
75 struct ib_port *p = container_of(kobj, struct ib_port, kobj);
80 return port_attr->show(p, port_attr, buf);
83 static const struct sysfs_ops port_sysfs_ops = {
84 .show = port_attr_show
87 static ssize_t state_show(struct ib_port *p, struct port_attribute *unused,
90 struct ib_port_attr attr;
93 static const char *state_name[] = {
94 [IB_PORT_NOP] = "NOP",
95 [IB_PORT_DOWN] = "DOWN",
96 [IB_PORT_INIT] = "INIT",
97 [IB_PORT_ARMED] = "ARMED",
98 [IB_PORT_ACTIVE] = "ACTIVE",
99 [IB_PORT_ACTIVE_DEFER] = "ACTIVE_DEFER"
102 ret = ib_query_port(p->ibdev, p->port_num, &attr);
106 return sprintf(buf, "%d: %s\n", attr.state,
107 attr.state >= 0 && attr.state < ARRAY_SIZE(state_name) ?
108 state_name[attr.state] : "UNKNOWN");
111 static ssize_t lid_show(struct ib_port *p, struct port_attribute *unused,
114 struct ib_port_attr attr;
117 ret = ib_query_port(p->ibdev, p->port_num, &attr);
121 return sprintf(buf, "0x%x\n", attr.lid);
124 static ssize_t lid_mask_count_show(struct ib_port *p,
125 struct port_attribute *unused,
128 struct ib_port_attr attr;
131 ret = ib_query_port(p->ibdev, p->port_num, &attr);
135 return sprintf(buf, "%d\n", attr.lmc);
138 static ssize_t sm_lid_show(struct ib_port *p, struct port_attribute *unused,
141 struct ib_port_attr attr;
144 ret = ib_query_port(p->ibdev, p->port_num, &attr);
148 return sprintf(buf, "0x%x\n", attr.sm_lid);
151 static ssize_t sm_sl_show(struct ib_port *p, struct port_attribute *unused,
154 struct ib_port_attr attr;
157 ret = ib_query_port(p->ibdev, p->port_num, &attr);
161 return sprintf(buf, "%d\n", attr.sm_sl);
164 static ssize_t cap_mask_show(struct ib_port *p, struct port_attribute *unused,
167 struct ib_port_attr attr;
170 ret = ib_query_port(p->ibdev, p->port_num, &attr);
174 return sprintf(buf, "0x%08x\n", attr.port_cap_flags);
177 static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused,
180 struct ib_port_attr attr;
182 int rate; /* in deci-Gb/sec */
185 ret = ib_query_port(p->ibdev, p->port_num, &attr);
189 switch (attr.active_speed) {
211 default: /* default to SDR for invalid rates */
216 rate *= ib_width_enum_to_int(attr.active_width);
220 return sprintf(buf, "%d%s Gb/sec (%dX%s)\n",
221 rate / 10, rate % 10 ? ".5" : "",
222 ib_width_enum_to_int(attr.active_width), speed);
225 static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
228 struct ib_port_attr attr;
232 ret = ib_query_port(p->ibdev, p->port_num, &attr);
236 switch (attr.phys_state) {
237 case 1: return sprintf(buf, "1: Sleep\n");
238 case 2: return sprintf(buf, "2: Polling\n");
239 case 3: return sprintf(buf, "3: Disabled\n");
240 case 4: return sprintf(buf, "4: PortConfigurationTraining\n");
241 case 5: return sprintf(buf, "5: LinkUp\n");
242 case 6: return sprintf(buf, "6: LinkErrorRecovery\n");
243 case 7: return sprintf(buf, "7: Phy Test\n");
244 default: return sprintf(buf, "%d: <unknown>\n", attr.phys_state);
248 static ssize_t link_layer_show(struct ib_port *p, struct port_attribute *unused,
251 switch (rdma_port_get_link_layer(p->ibdev, p->port_num)) {
252 case IB_LINK_LAYER_INFINIBAND:
253 return sprintf(buf, "%s\n", "InfiniBand");
254 case IB_LINK_LAYER_ETHERNET:
255 return sprintf(buf, "%s\n", "Ethernet");
257 return sprintf(buf, "%s\n", "Unknown");
261 static PORT_ATTR_RO(state);
262 static PORT_ATTR_RO(lid);
263 static PORT_ATTR_RO(lid_mask_count);
264 static PORT_ATTR_RO(sm_lid);
265 static PORT_ATTR_RO(sm_sl);
266 static PORT_ATTR_RO(cap_mask);
267 static PORT_ATTR_RO(rate);
268 static PORT_ATTR_RO(phys_state);
269 static PORT_ATTR_RO(link_layer);
271 static struct attribute *port_default_attrs[] = {
272 &port_attr_state.attr,
274 &port_attr_lid_mask_count.attr,
275 &port_attr_sm_lid.attr,
276 &port_attr_sm_sl.attr,
277 &port_attr_cap_mask.attr,
278 &port_attr_rate.attr,
279 &port_attr_phys_state.attr,
280 &port_attr_link_layer.attr,
284 static ssize_t show_port_gid(struct ib_port *p, struct port_attribute *attr,
287 struct port_table_attribute *tab_attr =
288 container_of(attr, struct port_table_attribute, attr);
292 ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid);
296 return sprintf(buf, "%pI6\n", gid.raw);
299 static ssize_t show_port_pkey(struct ib_port *p, struct port_attribute *attr,
302 struct port_table_attribute *tab_attr =
303 container_of(attr, struct port_table_attribute, attr);
307 ret = ib_query_pkey(p->ibdev, p->port_num, tab_attr->index, &pkey);
311 return sprintf(buf, "0x%04x\n", pkey);
314 #define PORT_PMA_ATTR(_name, _counter, _width, _offset) \
315 struct port_table_attribute port_pma_attr_##_name = { \
316 .attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \
317 .index = (_offset) | ((_width) << 16) | ((_counter) << 24) \
320 static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
323 struct port_table_attribute *tab_attr =
324 container_of(attr, struct port_table_attribute, attr);
325 int offset = tab_attr->index & 0xffff;
326 int width = (tab_attr->index >> 16) & 0xff;
327 struct ib_mad *in_mad = NULL;
328 struct ib_mad *out_mad = NULL;
331 if (!p->ibdev->process_mad)
332 return sprintf(buf, "N/A (no PMA)\n");
334 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
335 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
336 if (!in_mad || !out_mad) {
341 in_mad->mad_hdr.base_version = 1;
342 in_mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_PERF_MGMT;
343 in_mad->mad_hdr.class_version = 1;
344 in_mad->mad_hdr.method = IB_MGMT_METHOD_GET;
345 in_mad->mad_hdr.attr_id = cpu_to_be16(0x12); /* PortCounters */
347 in_mad->data[41] = p->port_num; /* PortSelect field */
349 if ((p->ibdev->process_mad(p->ibdev, IB_MAD_IGNORE_MKEY,
350 p->port_num, NULL, NULL, in_mad, out_mad) &
351 (IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) !=
352 (IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) {
359 ret = sprintf(buf, "%u\n", (out_mad->data[40 + offset / 8] >>
360 (4 - (offset % 8))) & 0xf);
363 ret = sprintf(buf, "%u\n", out_mad->data[40 + offset / 8]);
366 ret = sprintf(buf, "%u\n",
367 be16_to_cpup((__be16 *)(out_mad->data + 40 + offset / 8)));
370 ret = sprintf(buf, "%u\n",
371 be32_to_cpup((__be32 *)(out_mad->data + 40 + offset / 8)));
384 static PORT_PMA_ATTR(symbol_error , 0, 16, 32);
385 static PORT_PMA_ATTR(link_error_recovery , 1, 8, 48);
386 static PORT_PMA_ATTR(link_downed , 2, 8, 56);
387 static PORT_PMA_ATTR(port_rcv_errors , 3, 16, 64);
388 static PORT_PMA_ATTR(port_rcv_remote_physical_errors, 4, 16, 80);
389 static PORT_PMA_ATTR(port_rcv_switch_relay_errors , 5, 16, 96);
390 static PORT_PMA_ATTR(port_xmit_discards , 6, 16, 112);
391 static PORT_PMA_ATTR(port_xmit_constraint_errors , 7, 8, 128);
392 static PORT_PMA_ATTR(port_rcv_constraint_errors , 8, 8, 136);
393 static PORT_PMA_ATTR(local_link_integrity_errors , 9, 4, 152);
394 static PORT_PMA_ATTR(excessive_buffer_overrun_errors, 10, 4, 156);
395 static PORT_PMA_ATTR(VL15_dropped , 11, 16, 176);
396 static PORT_PMA_ATTR(port_xmit_data , 12, 32, 192);
397 static PORT_PMA_ATTR(port_rcv_data , 13, 32, 224);
398 static PORT_PMA_ATTR(port_xmit_packets , 14, 32, 256);
399 static PORT_PMA_ATTR(port_rcv_packets , 15, 32, 288);
401 static struct attribute *pma_attrs[] = {
402 &port_pma_attr_symbol_error.attr.attr,
403 &port_pma_attr_link_error_recovery.attr.attr,
404 &port_pma_attr_link_downed.attr.attr,
405 &port_pma_attr_port_rcv_errors.attr.attr,
406 &port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
407 &port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
408 &port_pma_attr_port_xmit_discards.attr.attr,
409 &port_pma_attr_port_xmit_constraint_errors.attr.attr,
410 &port_pma_attr_port_rcv_constraint_errors.attr.attr,
411 &port_pma_attr_local_link_integrity_errors.attr.attr,
412 &port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
413 &port_pma_attr_VL15_dropped.attr.attr,
414 &port_pma_attr_port_xmit_data.attr.attr,
415 &port_pma_attr_port_rcv_data.attr.attr,
416 &port_pma_attr_port_xmit_packets.attr.attr,
417 &port_pma_attr_port_rcv_packets.attr.attr,
421 static struct attribute_group pma_group = {
426 static void ib_port_release(struct kobject *kobj)
428 struct ib_port *p = container_of(kobj, struct ib_port, kobj);
432 for (i = 0; (a = p->gid_group.attrs[i]); ++i)
435 kfree(p->gid_group.attrs);
437 for (i = 0; (a = p->pkey_group.attrs[i]); ++i)
440 kfree(p->pkey_group.attrs);
445 static struct kobj_type port_type = {
446 .release = ib_port_release,
447 .sysfs_ops = &port_sysfs_ops,
448 .default_attrs = port_default_attrs
451 static void ib_device_release(struct device *device)
453 struct ib_device *dev = container_of(device, struct ib_device, dev);
458 static int ib_device_uevent(struct device *device,
459 struct kobj_uevent_env *env)
461 struct ib_device *dev = container_of(device, struct ib_device, dev);
463 if (add_uevent_var(env, "NAME=%s", dev->name))
467 * It would be nice to pass the node GUID with the event...
473 static struct attribute **
474 alloc_group_attrs(ssize_t (*show)(struct ib_port *,
475 struct port_attribute *, char *buf),
478 struct attribute **tab_attr;
479 struct port_table_attribute *element;
482 tab_attr = kcalloc(1 + len, sizeof(struct attribute *), GFP_KERNEL);
486 for (i = 0; i < len; i++) {
487 element = kzalloc(sizeof(struct port_table_attribute),
492 if (snprintf(element->name, sizeof(element->name),
493 "%d", i) >= sizeof(element->name)) {
498 element->attr.attr.name = element->name;
499 element->attr.attr.mode = S_IRUGO;
500 element->attr.show = show;
502 sysfs_attr_init(&element->attr.attr);
504 tab_attr[i] = &element->attr.attr;
516 static int add_port(struct ib_device *device, int port_num,
517 int (*port_callback)(struct ib_device *,
518 u8, struct kobject *))
521 struct ib_port_attr attr;
525 ret = ib_query_port(device, port_num, &attr);
529 p = kzalloc(sizeof *p, GFP_KERNEL);
534 p->port_num = port_num;
536 ret = kobject_init_and_add(&p->kobj, &port_type,
537 kobject_get(device->ports_parent),
542 ret = sysfs_create_group(&p->kobj, &pma_group);
546 p->gid_group.name = "gids";
547 p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len);
548 if (!p->gid_group.attrs) {
553 ret = sysfs_create_group(&p->kobj, &p->gid_group);
557 p->pkey_group.name = "pkeys";
558 p->pkey_group.attrs = alloc_group_attrs(show_port_pkey,
560 if (!p->pkey_group.attrs) {
565 ret = sysfs_create_group(&p->kobj, &p->pkey_group);
570 ret = port_callback(device, port_num, &p->kobj);
572 goto err_remove_pkey;
575 list_add_tail(&p->kobj.entry, &device->port_list);
577 kobject_uevent(&p->kobj, KOBJ_ADD);
581 sysfs_remove_group(&p->kobj, &p->pkey_group);
584 for (i = 0; i < attr.pkey_tbl_len; ++i)
585 kfree(p->pkey_group.attrs[i]);
587 kfree(p->pkey_group.attrs);
590 sysfs_remove_group(&p->kobj, &p->gid_group);
593 for (i = 0; i < attr.gid_tbl_len; ++i)
594 kfree(p->gid_group.attrs[i]);
596 kfree(p->gid_group.attrs);
599 sysfs_remove_group(&p->kobj, &pma_group);
602 kobject_put(device->ports_parent);
607 static ssize_t show_node_type(struct device *device,
608 struct device_attribute *attr, char *buf)
610 struct ib_device *dev = container_of(device, struct ib_device, dev);
612 switch (dev->node_type) {
613 case RDMA_NODE_IB_CA: return sprintf(buf, "%d: CA\n", dev->node_type);
614 case RDMA_NODE_RNIC: return sprintf(buf, "%d: RNIC\n", dev->node_type);
615 case RDMA_NODE_USNIC: return sprintf(buf, "%d: usNIC\n", dev->node_type);
616 case RDMA_NODE_USNIC_UDP: return sprintf(buf, "%d: usNIC UDP\n", dev->node_type);
617 case RDMA_NODE_IB_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type);
618 case RDMA_NODE_IB_ROUTER: return sprintf(buf, "%d: router\n", dev->node_type);
619 default: return sprintf(buf, "%d: <unknown>\n", dev->node_type);
623 static ssize_t show_sys_image_guid(struct device *device,
624 struct device_attribute *dev_attr, char *buf)
626 struct ib_device *dev = container_of(device, struct ib_device, dev);
627 struct ib_device_attr attr;
630 ret = ib_query_device(dev, &attr);
634 return sprintf(buf, "%04x:%04x:%04x:%04x\n",
635 be16_to_cpu(((__be16 *) &attr.sys_image_guid)[0]),
636 be16_to_cpu(((__be16 *) &attr.sys_image_guid)[1]),
637 be16_to_cpu(((__be16 *) &attr.sys_image_guid)[2]),
638 be16_to_cpu(((__be16 *) &attr.sys_image_guid)[3]));
641 static ssize_t show_node_guid(struct device *device,
642 struct device_attribute *attr, char *buf)
644 struct ib_device *dev = container_of(device, struct ib_device, dev);
646 return sprintf(buf, "%04x:%04x:%04x:%04x\n",
647 be16_to_cpu(((__be16 *) &dev->node_guid)[0]),
648 be16_to_cpu(((__be16 *) &dev->node_guid)[1]),
649 be16_to_cpu(((__be16 *) &dev->node_guid)[2]),
650 be16_to_cpu(((__be16 *) &dev->node_guid)[3]));
653 static ssize_t show_node_desc(struct device *device,
654 struct device_attribute *attr, char *buf)
656 struct ib_device *dev = container_of(device, struct ib_device, dev);
658 return sprintf(buf, "%.64s\n", dev->node_desc);
661 static ssize_t set_node_desc(struct device *device,
662 struct device_attribute *attr,
663 const char *buf, size_t count)
665 struct ib_device *dev = container_of(device, struct ib_device, dev);
666 struct ib_device_modify desc = {};
669 if (!dev->modify_device)
672 memcpy(desc.node_desc, buf, min_t(int, count, 64));
673 ret = ib_modify_device(dev, IB_DEVICE_MODIFY_NODE_DESC, &desc);
680 static DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
681 static DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL);
682 static DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL);
683 static DEVICE_ATTR(node_desc, S_IRUGO | S_IWUSR, show_node_desc, set_node_desc);
685 static struct device_attribute *ib_class_attributes[] = {
687 &dev_attr_sys_image_guid,
692 static struct class ib_class = {
693 .name = "infiniband",
694 .dev_release = ib_device_release,
695 .dev_uevent = ib_device_uevent,
698 /* Show a given an attribute in the statistics group */
699 static ssize_t show_protocol_stat(const struct device *device,
700 struct device_attribute *attr, char *buf,
703 struct ib_device *dev = container_of(device, struct ib_device, dev);
704 union rdma_protocol_stats stats;
707 ret = dev->get_protocol_stats(dev, &stats);
711 return sprintf(buf, "%llu\n",
712 (unsigned long long) ((u64 *) &stats)[offset]);
715 /* generate a read-only iwarp statistics attribute */
716 #define IW_STATS_ENTRY(name) \
717 static ssize_t show_##name(struct device *device, \
718 struct device_attribute *attr, char *buf) \
720 return show_protocol_stat(device, attr, buf, \
721 offsetof(struct iw_protocol_stats, name) / \
724 static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
726 IW_STATS_ENTRY(ipInReceives);
727 IW_STATS_ENTRY(ipInHdrErrors);
728 IW_STATS_ENTRY(ipInTooBigErrors);
729 IW_STATS_ENTRY(ipInNoRoutes);
730 IW_STATS_ENTRY(ipInAddrErrors);
731 IW_STATS_ENTRY(ipInUnknownProtos);
732 IW_STATS_ENTRY(ipInTruncatedPkts);
733 IW_STATS_ENTRY(ipInDiscards);
734 IW_STATS_ENTRY(ipInDelivers);
735 IW_STATS_ENTRY(ipOutForwDatagrams);
736 IW_STATS_ENTRY(ipOutRequests);
737 IW_STATS_ENTRY(ipOutDiscards);
738 IW_STATS_ENTRY(ipOutNoRoutes);
739 IW_STATS_ENTRY(ipReasmTimeout);
740 IW_STATS_ENTRY(ipReasmReqds);
741 IW_STATS_ENTRY(ipReasmOKs);
742 IW_STATS_ENTRY(ipReasmFails);
743 IW_STATS_ENTRY(ipFragOKs);
744 IW_STATS_ENTRY(ipFragFails);
745 IW_STATS_ENTRY(ipFragCreates);
746 IW_STATS_ENTRY(ipInMcastPkts);
747 IW_STATS_ENTRY(ipOutMcastPkts);
748 IW_STATS_ENTRY(ipInBcastPkts);
749 IW_STATS_ENTRY(ipOutBcastPkts);
750 IW_STATS_ENTRY(tcpRtoAlgorithm);
751 IW_STATS_ENTRY(tcpRtoMin);
752 IW_STATS_ENTRY(tcpRtoMax);
753 IW_STATS_ENTRY(tcpMaxConn);
754 IW_STATS_ENTRY(tcpActiveOpens);
755 IW_STATS_ENTRY(tcpPassiveOpens);
756 IW_STATS_ENTRY(tcpAttemptFails);
757 IW_STATS_ENTRY(tcpEstabResets);
758 IW_STATS_ENTRY(tcpCurrEstab);
759 IW_STATS_ENTRY(tcpInSegs);
760 IW_STATS_ENTRY(tcpOutSegs);
761 IW_STATS_ENTRY(tcpRetransSegs);
762 IW_STATS_ENTRY(tcpInErrs);
763 IW_STATS_ENTRY(tcpOutRsts);
765 static struct attribute *iw_proto_stats_attrs[] = {
766 &dev_attr_ipInReceives.attr,
767 &dev_attr_ipInHdrErrors.attr,
768 &dev_attr_ipInTooBigErrors.attr,
769 &dev_attr_ipInNoRoutes.attr,
770 &dev_attr_ipInAddrErrors.attr,
771 &dev_attr_ipInUnknownProtos.attr,
772 &dev_attr_ipInTruncatedPkts.attr,
773 &dev_attr_ipInDiscards.attr,
774 &dev_attr_ipInDelivers.attr,
775 &dev_attr_ipOutForwDatagrams.attr,
776 &dev_attr_ipOutRequests.attr,
777 &dev_attr_ipOutDiscards.attr,
778 &dev_attr_ipOutNoRoutes.attr,
779 &dev_attr_ipReasmTimeout.attr,
780 &dev_attr_ipReasmReqds.attr,
781 &dev_attr_ipReasmOKs.attr,
782 &dev_attr_ipReasmFails.attr,
783 &dev_attr_ipFragOKs.attr,
784 &dev_attr_ipFragFails.attr,
785 &dev_attr_ipFragCreates.attr,
786 &dev_attr_ipInMcastPkts.attr,
787 &dev_attr_ipOutMcastPkts.attr,
788 &dev_attr_ipInBcastPkts.attr,
789 &dev_attr_ipOutBcastPkts.attr,
790 &dev_attr_tcpRtoAlgorithm.attr,
791 &dev_attr_tcpRtoMin.attr,
792 &dev_attr_tcpRtoMax.attr,
793 &dev_attr_tcpMaxConn.attr,
794 &dev_attr_tcpActiveOpens.attr,
795 &dev_attr_tcpPassiveOpens.attr,
796 &dev_attr_tcpAttemptFails.attr,
797 &dev_attr_tcpEstabResets.attr,
798 &dev_attr_tcpCurrEstab.attr,
799 &dev_attr_tcpInSegs.attr,
800 &dev_attr_tcpOutSegs.attr,
801 &dev_attr_tcpRetransSegs.attr,
802 &dev_attr_tcpInErrs.attr,
803 &dev_attr_tcpOutRsts.attr,
807 static struct attribute_group iw_stats_group = {
808 .name = "proto_stats",
809 .attrs = iw_proto_stats_attrs,
812 int ib_device_register_sysfs(struct ib_device *device,
813 int (*port_callback)(struct ib_device *,
814 u8, struct kobject *))
816 struct device *class_dev = &device->dev;
820 class_dev->class = &ib_class;
821 class_dev->parent = device->dma_device;
822 dev_set_name(class_dev, "%s", device->name);
823 dev_set_drvdata(class_dev, device);
825 INIT_LIST_HEAD(&device->port_list);
827 ret = device_register(class_dev);
831 for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i) {
832 ret = device_create_file(class_dev, ib_class_attributes[i]);
837 device->ports_parent = kobject_create_and_add("ports",
838 kobject_get(&class_dev->kobj));
839 if (!device->ports_parent) {
844 if (device->node_type == RDMA_NODE_IB_SWITCH) {
845 ret = add_port(device, 0, port_callback);
849 for (i = 1; i <= device->phys_port_cnt; ++i) {
850 ret = add_port(device, i, port_callback);
856 if (device->node_type == RDMA_NODE_RNIC && device->get_protocol_stats) {
857 ret = sysfs_create_group(&class_dev->kobj, &iw_stats_group);
866 struct kobject *p, *t;
867 struct ib_port *port;
869 list_for_each_entry_safe(p, t, &device->port_list, entry) {
871 port = container_of(p, struct ib_port, kobj);
872 sysfs_remove_group(p, &pma_group);
873 sysfs_remove_group(p, &port->pkey_group);
874 sysfs_remove_group(p, &port->gid_group);
879 kobject_put(&class_dev->kobj);
882 device_unregister(class_dev);
888 void ib_device_unregister_sysfs(struct ib_device *device)
890 struct kobject *p, *t;
891 struct ib_port *port;
893 /* Hold kobject until ib_dealloc_device() */
894 kobject_get(&device->dev.kobj);
896 list_for_each_entry_safe(p, t, &device->port_list, entry) {
898 port = container_of(p, struct ib_port, kobj);
899 sysfs_remove_group(p, &pma_group);
900 sysfs_remove_group(p, &port->pkey_group);
901 sysfs_remove_group(p, &port->gid_group);
905 kobject_put(device->ports_parent);
906 device_unregister(&device->dev);
909 int ib_sysfs_setup(void)
911 return class_register(&ib_class);
914 void ib_sysfs_cleanup(void)
916 class_unregister(&ib_class);