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/string.h>
41 #include <rdma/ib_mad.h>
42 #include <rdma/ib_pma.h>
46 struct ib_device *ibdev;
47 struct attribute_group gid_group;
48 struct attribute_group pkey_group;
52 struct port_attribute {
53 struct attribute attr;
54 ssize_t (*show)(struct ib_port *, struct port_attribute *, char *buf);
55 ssize_t (*store)(struct ib_port *, struct port_attribute *,
56 const char *buf, size_t count);
59 #define PORT_ATTR(_name, _mode, _show, _store) \
60 struct port_attribute port_attr_##_name = __ATTR(_name, _mode, _show, _store)
62 #define PORT_ATTR_RO(_name) \
63 struct port_attribute port_attr_##_name = __ATTR_RO(_name)
65 struct port_table_attribute {
66 struct port_attribute attr;
71 static ssize_t port_attr_show(struct kobject *kobj,
72 struct attribute *attr, char *buf)
74 struct port_attribute *port_attr =
75 container_of(attr, struct port_attribute, attr);
76 struct ib_port *p = container_of(kobj, struct ib_port, kobj);
81 return port_attr->show(p, port_attr, buf);
84 static const struct sysfs_ops port_sysfs_ops = {
85 .show = port_attr_show
88 static ssize_t state_show(struct ib_port *p, struct port_attribute *unused,
91 struct ib_port_attr attr;
94 static const char *state_name[] = {
95 [IB_PORT_NOP] = "NOP",
96 [IB_PORT_DOWN] = "DOWN",
97 [IB_PORT_INIT] = "INIT",
98 [IB_PORT_ARMED] = "ARMED",
99 [IB_PORT_ACTIVE] = "ACTIVE",
100 [IB_PORT_ACTIVE_DEFER] = "ACTIVE_DEFER"
103 ret = ib_query_port(p->ibdev, p->port_num, &attr);
107 return sprintf(buf, "%d: %s\n", attr.state,
108 attr.state < ARRAY_SIZE(state_name) ?
109 state_name[attr.state] : "UNKNOWN");
112 static ssize_t lid_show(struct ib_port *p, struct port_attribute *unused,
115 struct ib_port_attr attr;
118 ret = ib_query_port(p->ibdev, p->port_num, &attr);
122 return sprintf(buf, "0x%x\n", attr.lid);
125 static ssize_t lid_mask_count_show(struct ib_port *p,
126 struct port_attribute *unused,
129 struct ib_port_attr attr;
132 ret = ib_query_port(p->ibdev, p->port_num, &attr);
136 return sprintf(buf, "%d\n", attr.lmc);
139 static ssize_t sm_lid_show(struct ib_port *p, struct port_attribute *unused,
142 struct ib_port_attr attr;
145 ret = ib_query_port(p->ibdev, p->port_num, &attr);
149 return sprintf(buf, "0x%x\n", attr.sm_lid);
152 static ssize_t sm_sl_show(struct ib_port *p, struct port_attribute *unused,
155 struct ib_port_attr attr;
158 ret = ib_query_port(p->ibdev, p->port_num, &attr);
162 return sprintf(buf, "%d\n", attr.sm_sl);
165 static ssize_t cap_mask_show(struct ib_port *p, struct port_attribute *unused,
168 struct ib_port_attr attr;
171 ret = ib_query_port(p->ibdev, p->port_num, &attr);
175 return sprintf(buf, "0x%08x\n", attr.port_cap_flags);
178 static ssize_t rate_show(struct ib_port *p, struct port_attribute *unused,
181 struct ib_port_attr attr;
186 ret = ib_query_port(p->ibdev, p->port_num, &attr);
190 switch (attr.active_speed) {
191 case 2: speed = " DDR"; break;
192 case 4: speed = " QDR"; break;
195 rate = 25 * ib_width_enum_to_int(attr.active_width) * attr.active_speed;
199 return sprintf(buf, "%d%s Gb/sec (%dX%s)\n",
200 rate / 10, rate % 10 ? ".5" : "",
201 ib_width_enum_to_int(attr.active_width), speed);
204 static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
207 struct ib_port_attr attr;
211 ret = ib_query_port(p->ibdev, p->port_num, &attr);
215 switch (attr.phys_state) {
216 case 1: return sprintf(buf, "1: Sleep\n");
217 case 2: return sprintf(buf, "2: Polling\n");
218 case 3: return sprintf(buf, "3: Disabled\n");
219 case 4: return sprintf(buf, "4: PortConfigurationTraining\n");
220 case 5: return sprintf(buf, "5: LinkUp\n");
221 case 6: return sprintf(buf, "6: LinkErrorRecovery\n");
222 case 7: return sprintf(buf, "7: Phy Test\n");
223 default: return sprintf(buf, "%d: <unknown>\n", attr.phys_state);
227 static ssize_t link_layer_show(struct ib_port *p, struct port_attribute *unused,
230 switch (rdma_port_get_link_layer(p->ibdev, p->port_num)) {
231 case IB_LINK_LAYER_INFINIBAND:
232 return sprintf(buf, "%s\n", "IB");
233 case IB_LINK_LAYER_ETHERNET:
234 return sprintf(buf, "%s\n", "Ethernet");
236 return sprintf(buf, "%s\n", "Unknown");
240 static PORT_ATTR_RO(state);
241 static PORT_ATTR_RO(lid);
242 static PORT_ATTR_RO(lid_mask_count);
243 static PORT_ATTR_RO(sm_lid);
244 static PORT_ATTR_RO(sm_sl);
245 static PORT_ATTR_RO(cap_mask);
246 static PORT_ATTR_RO(rate);
247 static PORT_ATTR_RO(phys_state);
248 static PORT_ATTR_RO(link_layer);
250 static struct attribute *port_default_attrs[] = {
251 &port_attr_state.attr,
253 &port_attr_lid_mask_count.attr,
254 &port_attr_sm_lid.attr,
255 &port_attr_sm_sl.attr,
256 &port_attr_cap_mask.attr,
257 &port_attr_rate.attr,
258 &port_attr_phys_state.attr,
259 &port_attr_link_layer.attr,
263 static ssize_t show_port_gid(struct ib_port *p, struct port_attribute *attr,
266 struct port_table_attribute *tab_attr =
267 container_of(attr, struct port_table_attribute, attr);
272 ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid);
276 raw = (u16 *)gid.raw;
277 return sprintf(buf, "%.4x:%.4x:%.4x:%.4x:%.4x:%.4x:%.4x:%.4x\n",
278 htons(raw[0]), htons(raw[1]), htons(raw[2]), htons(raw[3]),
279 htons(raw[4]), htons(raw[5]), htons(raw[6]), htons(raw[7]));
282 static ssize_t show_port_pkey(struct ib_port *p, struct port_attribute *attr,
285 struct port_table_attribute *tab_attr =
286 container_of(attr, struct port_table_attribute, attr);
290 ret = ib_query_pkey(p->ibdev, p->port_num, tab_attr->index, &pkey);
294 return sprintf(buf, "0x%04x\n", pkey);
297 static ssize_t get_pma_counters(struct ib_port *p, struct port_attribute *attr,
298 char *buf, int c_ext)
300 struct port_table_attribute *tab_attr =
301 container_of(attr, struct port_table_attribute, attr);
302 int offset = tab_attr->index & 0xffff;
303 int width = (tab_attr->index >> 16) & 0xff;
304 struct ib_mad *in_mad = NULL;
305 struct ib_mad *out_mad = NULL;
308 if (!p->ibdev->process_mad)
311 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
312 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
313 if (!in_mad || !out_mad) {
318 in_mad->mad_hdr.base_version = 1;
319 in_mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_PERF_MGMT;
320 in_mad->mad_hdr.class_version = 1;
321 in_mad->mad_hdr.method = IB_MGMT_METHOD_GET;
323 in_mad->mad_hdr.attr_id = IB_PMA_PORT_COUNTERS_EXT;
325 in_mad->mad_hdr.attr_id = IB_PMA_PORT_COUNTERS;
327 in_mad->data[41] = p->port_num; /* PortSelect field */
329 if ((p->ibdev->process_mad(p->ibdev, IB_MAD_IGNORE_MKEY,
330 p->port_num, NULL, NULL, in_mad, out_mad) &
331 (IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) !=
332 (IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) {
339 ret = sprintf(buf, "%u\n", (out_mad->data[40 + offset / 8] >>
340 (4 - (offset % 8))) & 0xf);
343 ret = sprintf(buf, "%u\n", out_mad->data[40 + offset / 8]);
346 ret = sprintf(buf, "%u\n",
347 be16_to_cpup((__be16 *)(out_mad->data + 40 + offset / 8)));
350 ret = sprintf(buf, "%u\n",
351 be32_to_cpup((__be32 *)(out_mad->data + 40 + offset / 8)));
354 ret = sprintf(buf, "%llu\n", (unsigned long long)
355 be64_to_cpup((__be64 *)(out_mad->data + 40 + offset / 8)));
368 #define PORT_PMA_ATTR(_name, _counter, _width, _offset) \
369 struct port_table_attribute port_pma_attr_##_name = { \
370 .attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \
371 .index = (_offset) | ((_width) << 16) | ((_counter) << 24) \
374 static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
377 return get_pma_counters(p, attr, buf, 0);
380 static PORT_PMA_ATTR(symbol_error , 0, 16, 32);
381 static PORT_PMA_ATTR(link_error_recovery , 1, 8, 48);
382 static PORT_PMA_ATTR(link_downed , 2, 8, 56);
383 static PORT_PMA_ATTR(port_rcv_errors , 3, 16, 64);
384 static PORT_PMA_ATTR(port_rcv_remote_physical_errors, 4, 16, 80);
385 static PORT_PMA_ATTR(port_rcv_switch_relay_errors , 5, 16, 96);
386 static PORT_PMA_ATTR(port_xmit_discards , 6, 16, 112);
387 static PORT_PMA_ATTR(port_xmit_constraint_errors , 7, 8, 128);
388 static PORT_PMA_ATTR(port_rcv_constraint_errors , 8, 8, 136);
389 static PORT_PMA_ATTR(local_link_integrity_errors , 9, 4, 152);
390 static PORT_PMA_ATTR(excessive_buffer_overrun_errors, 10, 4, 156);
391 static PORT_PMA_ATTR(VL15_dropped , 11, 16, 176);
392 static PORT_PMA_ATTR(port_xmit_data , 12, 32, 192);
393 static PORT_PMA_ATTR(port_rcv_data , 13, 32, 224);
394 static PORT_PMA_ATTR(port_xmit_packets , 14, 32, 256);
395 static PORT_PMA_ATTR(port_rcv_packets , 15, 32, 288);
397 static struct attribute *pma_attrs[] = {
398 &port_pma_attr_symbol_error.attr.attr,
399 &port_pma_attr_link_error_recovery.attr.attr,
400 &port_pma_attr_link_downed.attr.attr,
401 &port_pma_attr_port_rcv_errors.attr.attr,
402 &port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
403 &port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
404 &port_pma_attr_port_xmit_discards.attr.attr,
405 &port_pma_attr_port_xmit_constraint_errors.attr.attr,
406 &port_pma_attr_port_rcv_constraint_errors.attr.attr,
407 &port_pma_attr_local_link_integrity_errors.attr.attr,
408 &port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
409 &port_pma_attr_VL15_dropped.attr.attr,
410 &port_pma_attr_port_xmit_data.attr.attr,
411 &port_pma_attr_port_rcv_data.attr.attr,
412 &port_pma_attr_port_xmit_packets.attr.attr,
413 &port_pma_attr_port_rcv_packets.attr.attr,
417 static struct attribute_group pma_group = {
422 #define PORT_PMA_ATTR_EXT(_name, _counter, _width, _offset) \
423 struct port_table_attribute port_pma_attr_ext_##_name = { \
424 .attr = __ATTR(_name, S_IRUGO, show_pma_counter_ext, NULL), \
425 .index = (_offset) | ((_width) << 16) | ((_counter) << 24) \
428 static ssize_t show_pma_counter_ext(struct ib_port *p,
429 struct port_attribute *attr, char *buf)
431 return get_pma_counters(p, attr, buf, 1);
434 static PORT_PMA_ATTR_EXT(port_xmit_data_64 , 0, 64, 64);
435 static PORT_PMA_ATTR_EXT(port_rcv_data_64 , 0, 64, 128);
436 static PORT_PMA_ATTR_EXT(port_xmit_packets_64 , 0, 64, 192);
437 static PORT_PMA_ATTR_EXT(port_rcv_packets_64 , 0, 64, 256);
438 static PORT_PMA_ATTR_EXT(port_unicast_xmit_packets , 0, 64, 320);
439 static PORT_PMA_ATTR_EXT(port_unicast_rcv_packets , 0, 64, 384);
440 static PORT_PMA_ATTR_EXT(port_multicast_xmit_packets , 0, 64, 448);
441 static PORT_PMA_ATTR_EXT(port_multicast_rcv_packets , 0, 64, 512);
443 static struct attribute *pma_attrs_ext[] = {
444 &port_pma_attr_ext_port_xmit_data_64.attr.attr,
445 &port_pma_attr_ext_port_rcv_data_64.attr.attr,
446 &port_pma_attr_ext_port_xmit_packets_64.attr.attr,
447 &port_pma_attr_ext_port_rcv_packets_64.attr.attr,
448 &port_pma_attr_ext_port_unicast_xmit_packets.attr.attr,
449 &port_pma_attr_ext_port_unicast_rcv_packets.attr.attr,
450 &port_pma_attr_ext_port_multicast_xmit_packets.attr.attr,
451 &port_pma_attr_ext_port_multicast_rcv_packets.attr.attr,
455 static struct attribute_group pma_ext_group = {
456 .name = "counters_ext",
457 .attrs = pma_attrs_ext
460 static void ib_port_release(struct kobject *kobj)
462 struct ib_port *p = container_of(kobj, struct ib_port, kobj);
466 for (i = 0; (a = p->gid_group.attrs[i]); ++i)
469 kfree(p->gid_group.attrs);
471 for (i = 0; (a = p->pkey_group.attrs[i]); ++i)
474 kfree(p->pkey_group.attrs);
479 static struct kobj_type port_type = {
480 .release = ib_port_release,
481 .sysfs_ops = &port_sysfs_ops,
482 .default_attrs = port_default_attrs
485 static void ib_device_release(struct device *device)
487 struct ib_device *dev = container_of(device, struct ib_device, dev);
493 /* BSD supports this through devfs(5) and devd(8). */
494 static int ib_device_uevent(struct device *device,
495 struct kobj_uevent_env *env)
497 struct ib_device *dev = container_of(device, struct ib_device, dev);
499 if (add_uevent_var(env, "NAME=%s", dev->name))
503 * It would be nice to pass the node GUID with the event...
510 static struct attribute **
511 alloc_group_attrs(ssize_t (*show)(struct ib_port *,
512 struct port_attribute *, char *buf),
515 struct attribute **tab_attr;
516 struct port_table_attribute *element;
519 tab_attr = kcalloc(1 + len, sizeof(struct attribute *), GFP_KERNEL);
523 for (i = 0; i < len; i++) {
524 element = kzalloc(sizeof(struct port_table_attribute),
529 if (snprintf(element->name, sizeof(element->name),
530 "%d", i) >= sizeof(element->name)) {
535 element->attr.attr.name = element->name;
536 element->attr.attr.mode = S_IRUGO;
537 element->attr.show = show;
540 tab_attr[i] = &element->attr.attr;
552 static int add_port(struct ib_device *device, int port_num,
553 int (*port_callback)(struct ib_device *,
554 u8, struct kobject *))
557 struct ib_port_attr attr;
561 ret = ib_query_port(device, port_num, &attr);
565 p = kzalloc(sizeof *p, GFP_KERNEL);
570 p->port_num = port_num;
572 ret = kobject_init_and_add(&p->kobj, &port_type,
573 kobject_get(device->ports_parent),
578 ret = sysfs_create_group(&p->kobj, &pma_group);
582 ret = sysfs_create_group(&p->kobj, &pma_ext_group);
586 p->gid_group.name = "gids";
587 p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len);
588 if (!p->gid_group.attrs)
589 goto err_remove_pma_ext;
591 ret = sysfs_create_group(&p->kobj, &p->gid_group);
595 p->pkey_group.name = "pkeys";
596 p->pkey_group.attrs = alloc_group_attrs(show_port_pkey,
598 if (!p->pkey_group.attrs)
601 ret = sysfs_create_group(&p->kobj, &p->pkey_group);
606 ret = port_callback(device, port_num, &p->kobj);
608 goto err_remove_pkey;
611 list_add_tail(&p->kobj.entry, &device->port_list);
614 kobject_uevent(&p->kobj, KOBJ_ADD);
619 sysfs_remove_group(&p->kobj, &p->pkey_group);
622 for (i = 0; i < attr.pkey_tbl_len; ++i)
623 kfree(p->pkey_group.attrs[i]);
625 kfree(p->pkey_group.attrs);
628 sysfs_remove_group(&p->kobj, &p->gid_group);
631 for (i = 0; i < attr.gid_tbl_len; ++i)
632 kfree(p->gid_group.attrs[i]);
634 kfree(p->gid_group.attrs);
637 sysfs_remove_group(&p->kobj, &pma_ext_group);
640 sysfs_remove_group(&p->kobj, &pma_group);
643 kobject_put(device->ports_parent);
648 static ssize_t show_node_type(struct device *device,
649 struct device_attribute *attr, char *buf)
651 struct ib_device *dev = container_of(device, struct ib_device, dev);
653 switch (dev->node_type) {
654 case RDMA_NODE_IB_CA: return sprintf(buf, "%d: CA\n", dev->node_type);
655 case RDMA_NODE_RNIC: return sprintf(buf, "%d: RNIC\n", dev->node_type);
656 case RDMA_NODE_IB_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type);
657 case RDMA_NODE_IB_ROUTER: return sprintf(buf, "%d: router\n", dev->node_type);
658 default: return sprintf(buf, "%d: <unknown>\n", dev->node_type);
662 static ssize_t show_sys_image_guid(struct device *device,
663 struct device_attribute *dev_attr, char *buf)
665 struct ib_device *dev = container_of(device, struct ib_device, dev);
666 struct ib_device_attr attr;
669 ret = ib_query_device(dev, &attr);
673 return sprintf(buf, "%04x:%04x:%04x:%04x\n",
674 be16_to_cpu(((__be16 *) &attr.sys_image_guid)[0]),
675 be16_to_cpu(((__be16 *) &attr.sys_image_guid)[1]),
676 be16_to_cpu(((__be16 *) &attr.sys_image_guid)[2]),
677 be16_to_cpu(((__be16 *) &attr.sys_image_guid)[3]));
680 static ssize_t show_node_guid(struct device *device,
681 struct device_attribute *attr, char *buf)
683 struct ib_device *dev = container_of(device, struct ib_device, dev);
685 return sprintf(buf, "%04x:%04x:%04x:%04x\n",
686 be16_to_cpu(((__be16 *) &dev->node_guid)[0]),
687 be16_to_cpu(((__be16 *) &dev->node_guid)[1]),
688 be16_to_cpu(((__be16 *) &dev->node_guid)[2]),
689 be16_to_cpu(((__be16 *) &dev->node_guid)[3]));
692 static ssize_t show_node_desc(struct device *device,
693 struct device_attribute *attr, char *buf)
695 struct ib_device *dev = container_of(device, struct ib_device, dev);
697 return sprintf(buf, "%.64s\n", dev->node_desc);
700 static ssize_t set_node_desc(struct device *device,
701 struct device_attribute *attr,
702 const char *buf, size_t count)
704 struct ib_device *dev = container_of(device, struct ib_device, dev);
705 struct ib_device_modify desc = {};
708 if (!dev->modify_device)
711 memcpy(desc.node_desc, buf, min_t(int, count, 64));
712 ret = ib_modify_device(dev, IB_DEVICE_MODIFY_NODE_DESC, &desc);
719 static DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
720 static DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL);
721 static DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL);
722 static DEVICE_ATTR(node_desc, S_IRUGO | S_IWUSR, show_node_desc, set_node_desc);
724 static struct device_attribute *ib_class_attributes[] = {
726 &dev_attr_sys_image_guid,
731 static struct class ib_class = {
732 .name = "infiniband",
733 .dev_release = ib_device_release,
735 .dev_uevent = ib_device_uevent,
739 /* Show a given an attribute in the statistics group */
740 static ssize_t show_protocol_stat(const struct device *device,
741 struct device_attribute *attr, char *buf,
744 struct ib_device *dev = container_of(__DECONST(struct device *, device), struct ib_device, dev);
745 union rdma_protocol_stats stats;
748 ret = dev->get_protocol_stats(dev, &stats);
752 return sprintf(buf, "%llu\n",
753 (unsigned long long) ((u64 *) &stats)[offset]);
756 /* generate a read-only iwarp statistics attribute */
757 #define IW_STATS_ENTRY(name) \
758 static ssize_t show_##name(struct device *device, \
759 struct device_attribute *attr, char *buf) \
761 return show_protocol_stat(device, attr, buf, \
762 offsetof(struct iw_protocol_stats, name) / \
765 static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
767 IW_STATS_ENTRY(ipInReceives);
768 IW_STATS_ENTRY(ipInHdrErrors);
769 IW_STATS_ENTRY(ipInTooBigErrors);
770 IW_STATS_ENTRY(ipInNoRoutes);
771 IW_STATS_ENTRY(ipInAddrErrors);
772 IW_STATS_ENTRY(ipInUnknownProtos);
773 IW_STATS_ENTRY(ipInTruncatedPkts);
774 IW_STATS_ENTRY(ipInDiscards);
775 IW_STATS_ENTRY(ipInDelivers);
776 IW_STATS_ENTRY(ipOutForwDatagrams);
777 IW_STATS_ENTRY(ipOutRequests);
778 IW_STATS_ENTRY(ipOutDiscards);
779 IW_STATS_ENTRY(ipOutNoRoutes);
780 IW_STATS_ENTRY(ipReasmTimeout);
781 IW_STATS_ENTRY(ipReasmReqds);
782 IW_STATS_ENTRY(ipReasmOKs);
783 IW_STATS_ENTRY(ipReasmFails);
784 IW_STATS_ENTRY(ipFragOKs);
785 IW_STATS_ENTRY(ipFragFails);
786 IW_STATS_ENTRY(ipFragCreates);
787 IW_STATS_ENTRY(ipInMcastPkts);
788 IW_STATS_ENTRY(ipOutMcastPkts);
789 IW_STATS_ENTRY(ipInBcastPkts);
790 IW_STATS_ENTRY(ipOutBcastPkts);
791 IW_STATS_ENTRY(tcpRtoAlgorithm);
792 IW_STATS_ENTRY(tcpRtoMin);
793 IW_STATS_ENTRY(tcpRtoMax);
794 IW_STATS_ENTRY(tcpMaxConn);
795 IW_STATS_ENTRY(tcpActiveOpens);
796 IW_STATS_ENTRY(tcpPassiveOpens);
797 IW_STATS_ENTRY(tcpAttemptFails);
798 IW_STATS_ENTRY(tcpEstabResets);
799 IW_STATS_ENTRY(tcpCurrEstab);
800 IW_STATS_ENTRY(tcpInSegs);
801 IW_STATS_ENTRY(tcpOutSegs);
802 IW_STATS_ENTRY(tcpRetransSegs);
803 IW_STATS_ENTRY(tcpInErrs);
804 IW_STATS_ENTRY(tcpOutRsts);
806 static struct attribute *iw_proto_stats_attrs[] = {
807 &dev_attr_ipInReceives.attr,
808 &dev_attr_ipInHdrErrors.attr,
809 &dev_attr_ipInTooBigErrors.attr,
810 &dev_attr_ipInNoRoutes.attr,
811 &dev_attr_ipInAddrErrors.attr,
812 &dev_attr_ipInUnknownProtos.attr,
813 &dev_attr_ipInTruncatedPkts.attr,
814 &dev_attr_ipInDiscards.attr,
815 &dev_attr_ipInDelivers.attr,
816 &dev_attr_ipOutForwDatagrams.attr,
817 &dev_attr_ipOutRequests.attr,
818 &dev_attr_ipOutDiscards.attr,
819 &dev_attr_ipOutNoRoutes.attr,
820 &dev_attr_ipReasmTimeout.attr,
821 &dev_attr_ipReasmReqds.attr,
822 &dev_attr_ipReasmOKs.attr,
823 &dev_attr_ipReasmFails.attr,
824 &dev_attr_ipFragOKs.attr,
825 &dev_attr_ipFragFails.attr,
826 &dev_attr_ipFragCreates.attr,
827 &dev_attr_ipInMcastPkts.attr,
828 &dev_attr_ipOutMcastPkts.attr,
829 &dev_attr_ipInBcastPkts.attr,
830 &dev_attr_ipOutBcastPkts.attr,
831 &dev_attr_tcpRtoAlgorithm.attr,
832 &dev_attr_tcpRtoMin.attr,
833 &dev_attr_tcpRtoMax.attr,
834 &dev_attr_tcpMaxConn.attr,
835 &dev_attr_tcpActiveOpens.attr,
836 &dev_attr_tcpPassiveOpens.attr,
837 &dev_attr_tcpAttemptFails.attr,
838 &dev_attr_tcpEstabResets.attr,
839 &dev_attr_tcpCurrEstab.attr,
840 &dev_attr_tcpInSegs.attr,
841 &dev_attr_tcpOutSegs.attr,
842 &dev_attr_tcpRetransSegs.attr,
843 &dev_attr_tcpInErrs.attr,
844 &dev_attr_tcpOutRsts.attr,
848 static struct attribute_group iw_stats_group = {
849 .name = "proto_stats",
850 .attrs = iw_proto_stats_attrs,
853 int ib_device_register_sysfs(struct ib_device *device,
854 int (*port_callback)(struct ib_device *, u8, struct kobject *))
856 struct device *class_dev = &device->dev;
860 class_dev->class = &ib_class;
861 class_dev->parent = device->dma_device;
862 dev_set_name(class_dev, device->name);
863 dev_set_drvdata(class_dev, device);
865 INIT_LIST_HEAD(&device->port_list);
867 ret = device_register(class_dev);
871 for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i) {
872 ret = device_create_file(class_dev, ib_class_attributes[i]);
877 device->ports_parent = kobject_create_and_add("ports",
878 kobject_get(&class_dev->kobj));
879 if (!device->ports_parent) {
884 if (device->node_type == RDMA_NODE_IB_SWITCH) {
885 ret = add_port(device, 0, port_callback);
889 for (i = 1; i <= device->phys_port_cnt; ++i) {
890 ret = add_port(device, i, port_callback);
896 if (device->node_type == RDMA_NODE_RNIC && device->get_protocol_stats) {
897 ret = sysfs_create_group(&class_dev->kobj, &iw_stats_group);
906 struct kobject *p, *t;
907 struct ib_port *port;
909 list_for_each_entry_safe(p, t, &device->port_list, entry) {
911 port = container_of(p, struct ib_port, kobj);
912 sysfs_remove_group(p, &pma_group);
913 sysfs_remove_group(p, &port->pkey_group);
914 sysfs_remove_group(p, &port->gid_group);
919 kobject_put(&class_dev->kobj);
922 device_unregister(class_dev);
928 void ib_device_unregister_sysfs(struct ib_device *device)
930 struct kobject *p, *t;
931 struct ib_port *port;
934 /* Hold kobject until ib_dealloc_device() */
935 kobject_get(&device->dev.kobj);
937 for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i) {
938 device_remove_file(&device->dev, ib_class_attributes[i]);
941 list_for_each_entry_safe(p, t, &device->port_list, entry) {
943 port = container_of(p, struct ib_port, kobj);
944 sysfs_remove_group(p, &pma_group);
945 sysfs_remove_group(p, &port->pkey_group);
946 sysfs_remove_group(p, &port->gid_group);
950 kobject_put(device->ports_parent);
951 device_unregister(&device->dev);
954 int ib_sysfs_setup(void)
956 return class_register(&ib_class);
959 void ib_sysfs_cleanup(void)
961 class_unregister(&ib_class);
964 /*int ib_sysfs_create_port_files(struct ib_device *device,
965 int (*create)(struct ib_device *dev, u8 port_num,
966 struct kobject *kobj))
969 struct ib_port *port;
972 list_for_each_entry(p, &device->port_list, entry) {
973 port = container_of(p, struct ib_port, kobj);
974 ret = create(device, port->port_num, &port->kobj);
981 EXPORT_SYMBOL(ib_sysfs_create_port_files);*/