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>
40 #include <rdma/ib_mad.h>
41 #include <rdma/ib_pma.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 < 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;
185 ret = ib_query_port(p->ibdev, p->port_num, &attr);
189 switch (attr.active_speed) {
190 case 2: speed = " DDR"; break;
191 case 4: speed = " QDR"; break;
194 rate = 25 * ib_width_enum_to_int(attr.active_width) * attr.active_speed;
198 return sprintf(buf, "%d%s Gb/sec (%dX%s)\n",
199 rate / 10, rate % 10 ? ".5" : "",
200 ib_width_enum_to_int(attr.active_width), speed);
203 static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
206 struct ib_port_attr attr;
210 ret = ib_query_port(p->ibdev, p->port_num, &attr);
214 switch (attr.phys_state) {
215 case 1: return sprintf(buf, "1: Sleep\n");
216 case 2: return sprintf(buf, "2: Polling\n");
217 case 3: return sprintf(buf, "3: Disabled\n");
218 case 4: return sprintf(buf, "4: PortConfigurationTraining\n");
219 case 5: return sprintf(buf, "5: LinkUp\n");
220 case 6: return sprintf(buf, "6: LinkErrorRecovery\n");
221 case 7: return sprintf(buf, "7: Phy Test\n");
222 default: return sprintf(buf, "%d: <unknown>\n", attr.phys_state);
226 static ssize_t link_layer_show(struct ib_port *p, struct port_attribute *unused,
229 switch (rdma_port_get_link_layer(p->ibdev, p->port_num)) {
230 case IB_LINK_LAYER_INFINIBAND:
231 return sprintf(buf, "%s\n", "IB");
232 case IB_LINK_LAYER_ETHERNET:
233 return sprintf(buf, "%s\n", "Ethernet");
235 return sprintf(buf, "%s\n", "Unknown");
239 static PORT_ATTR_RO(state);
240 static PORT_ATTR_RO(lid);
241 static PORT_ATTR_RO(lid_mask_count);
242 static PORT_ATTR_RO(sm_lid);
243 static PORT_ATTR_RO(sm_sl);
244 static PORT_ATTR_RO(cap_mask);
245 static PORT_ATTR_RO(rate);
246 static PORT_ATTR_RO(phys_state);
247 static PORT_ATTR_RO(link_layer);
249 static struct attribute *port_default_attrs[] = {
250 &port_attr_state.attr,
252 &port_attr_lid_mask_count.attr,
253 &port_attr_sm_lid.attr,
254 &port_attr_sm_sl.attr,
255 &port_attr_cap_mask.attr,
256 &port_attr_rate.attr,
257 &port_attr_phys_state.attr,
258 &port_attr_link_layer.attr,
262 static ssize_t show_port_gid(struct ib_port *p, struct port_attribute *attr,
265 struct port_table_attribute *tab_attr =
266 container_of(attr, struct port_table_attribute, attr);
271 ret = ib_query_gid(p->ibdev, p->port_num, tab_attr->index, &gid);
275 raw = (u16 *)gid.raw;
276 return sprintf(buf, "%.4x:%.4x:%.4x:%.4x:%.4x:%.4x:%.4x:%.4x\n",
277 htons(raw[0]), htons(raw[1]), htons(raw[2]), htons(raw[3]),
278 htons(raw[4]), htons(raw[5]), htons(raw[6]), htons(raw[7]));
281 static ssize_t show_port_pkey(struct ib_port *p, struct port_attribute *attr,
284 struct port_table_attribute *tab_attr =
285 container_of(attr, struct port_table_attribute, attr);
289 ret = ib_query_pkey(p->ibdev, p->port_num, tab_attr->index, &pkey);
293 return sprintf(buf, "0x%04x\n", pkey);
296 static ssize_t get_pma_counters(struct ib_port *p, struct port_attribute *attr,
297 char *buf, int c_ext)
299 struct port_table_attribute *tab_attr =
300 container_of(attr, struct port_table_attribute, attr);
301 int offset = tab_attr->index & 0xffff;
302 int width = (tab_attr->index >> 16) & 0xff;
303 struct ib_mad *in_mad = NULL;
304 struct ib_mad *out_mad = NULL;
307 if (!p->ibdev->process_mad)
310 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
311 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
312 if (!in_mad || !out_mad) {
317 in_mad->mad_hdr.base_version = 1;
318 in_mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_PERF_MGMT;
319 in_mad->mad_hdr.class_version = 1;
320 in_mad->mad_hdr.method = IB_MGMT_METHOD_GET;
322 in_mad->mad_hdr.attr_id = IB_PMA_PORT_COUNTERS_EXT;
324 in_mad->mad_hdr.attr_id = IB_PMA_PORT_COUNTERS;
326 in_mad->data[41] = p->port_num; /* PortSelect field */
328 if ((p->ibdev->process_mad(p->ibdev, IB_MAD_IGNORE_MKEY,
329 p->port_num, NULL, NULL, in_mad, out_mad) &
330 (IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) !=
331 (IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY)) {
338 ret = sprintf(buf, "%u\n", (out_mad->data[40 + offset / 8] >>
339 (4 - (offset % 8))) & 0xf);
342 ret = sprintf(buf, "%u\n", out_mad->data[40 + offset / 8]);
345 ret = sprintf(buf, "%u\n",
346 be16_to_cpup((__be16 *)(out_mad->data + 40 + offset / 8)));
349 ret = sprintf(buf, "%u\n",
350 be32_to_cpup((__be32 *)(out_mad->data + 40 + offset / 8)));
353 ret = sprintf(buf, "%llu\n", (unsigned long long)
354 be64_to_cpup((__be64 *)(out_mad->data + 40 + offset / 8)));
367 #define PORT_PMA_ATTR(_name, _counter, _width, _offset) \
368 struct port_table_attribute port_pma_attr_##_name = { \
369 .attr = __ATTR(_name, S_IRUGO, show_pma_counter, NULL), \
370 .index = (_offset) | ((_width) << 16) | ((_counter) << 24) \
373 static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
376 return get_pma_counters(p, attr, buf, 0);
379 static PORT_PMA_ATTR(symbol_error , 0, 16, 32);
380 static PORT_PMA_ATTR(link_error_recovery , 1, 8, 48);
381 static PORT_PMA_ATTR(link_downed , 2, 8, 56);
382 static PORT_PMA_ATTR(port_rcv_errors , 3, 16, 64);
383 static PORT_PMA_ATTR(port_rcv_remote_physical_errors, 4, 16, 80);
384 static PORT_PMA_ATTR(port_rcv_switch_relay_errors , 5, 16, 96);
385 static PORT_PMA_ATTR(port_xmit_discards , 6, 16, 112);
386 static PORT_PMA_ATTR(port_xmit_constraint_errors , 7, 8, 128);
387 static PORT_PMA_ATTR(port_rcv_constraint_errors , 8, 8, 136);
388 static PORT_PMA_ATTR(local_link_integrity_errors , 9, 4, 152);
389 static PORT_PMA_ATTR(excessive_buffer_overrun_errors, 10, 4, 156);
390 static PORT_PMA_ATTR(VL15_dropped , 11, 16, 176);
391 static PORT_PMA_ATTR(port_xmit_data , 12, 32, 192);
392 static PORT_PMA_ATTR(port_rcv_data , 13, 32, 224);
393 static PORT_PMA_ATTR(port_xmit_packets , 14, 32, 256);
394 static PORT_PMA_ATTR(port_rcv_packets , 15, 32, 288);
396 static struct attribute *pma_attrs[] = {
397 &port_pma_attr_symbol_error.attr.attr,
398 &port_pma_attr_link_error_recovery.attr.attr,
399 &port_pma_attr_link_downed.attr.attr,
400 &port_pma_attr_port_rcv_errors.attr.attr,
401 &port_pma_attr_port_rcv_remote_physical_errors.attr.attr,
402 &port_pma_attr_port_rcv_switch_relay_errors.attr.attr,
403 &port_pma_attr_port_xmit_discards.attr.attr,
404 &port_pma_attr_port_xmit_constraint_errors.attr.attr,
405 &port_pma_attr_port_rcv_constraint_errors.attr.attr,
406 &port_pma_attr_local_link_integrity_errors.attr.attr,
407 &port_pma_attr_excessive_buffer_overrun_errors.attr.attr,
408 &port_pma_attr_VL15_dropped.attr.attr,
409 &port_pma_attr_port_xmit_data.attr.attr,
410 &port_pma_attr_port_rcv_data.attr.attr,
411 &port_pma_attr_port_xmit_packets.attr.attr,
412 &port_pma_attr_port_rcv_packets.attr.attr,
416 static struct attribute_group pma_group = {
421 #define PORT_PMA_ATTR_EXT(_name, _counter, _width, _offset) \
422 struct port_table_attribute port_pma_attr_ext_##_name = { \
423 .attr = __ATTR(_name, S_IRUGO, show_pma_counter_ext, NULL), \
424 .index = (_offset) | ((_width) << 16) | ((_counter) << 24) \
427 static ssize_t show_pma_counter_ext(struct ib_port *p,
428 struct port_attribute *attr, char *buf)
430 return get_pma_counters(p, attr, buf, 1);
433 static PORT_PMA_ATTR_EXT(port_xmit_data_64 , 0, 64, 64);
434 static PORT_PMA_ATTR_EXT(port_rcv_data_64 , 0, 64, 128);
435 static PORT_PMA_ATTR_EXT(port_xmit_packets_64 , 0, 64, 192);
436 static PORT_PMA_ATTR_EXT(port_rcv_packets_64 , 0, 64, 256);
437 static PORT_PMA_ATTR_EXT(port_unicast_xmit_packets , 0, 64, 320);
438 static PORT_PMA_ATTR_EXT(port_unicast_rcv_packets , 0, 64, 384);
439 static PORT_PMA_ATTR_EXT(port_multicast_xmit_packets , 0, 64, 448);
440 static PORT_PMA_ATTR_EXT(port_multicast_rcv_packets , 0, 64, 512);
442 static struct attribute *pma_attrs_ext[] = {
443 &port_pma_attr_ext_port_xmit_data_64.attr.attr,
444 &port_pma_attr_ext_port_rcv_data_64.attr.attr,
445 &port_pma_attr_ext_port_xmit_packets_64.attr.attr,
446 &port_pma_attr_ext_port_rcv_packets_64.attr.attr,
447 &port_pma_attr_ext_port_unicast_xmit_packets.attr.attr,
448 &port_pma_attr_ext_port_unicast_rcv_packets.attr.attr,
449 &port_pma_attr_ext_port_multicast_xmit_packets.attr.attr,
450 &port_pma_attr_ext_port_multicast_rcv_packets.attr.attr,
454 static struct attribute_group pma_ext_group = {
455 .name = "counters_ext",
456 .attrs = pma_attrs_ext
459 static void ib_port_release(struct kobject *kobj)
461 struct ib_port *p = container_of(kobj, struct ib_port, kobj);
465 for (i = 0; (a = p->gid_group.attrs[i]); ++i)
468 kfree(p->gid_group.attrs);
470 for (i = 0; (a = p->pkey_group.attrs[i]); ++i)
473 kfree(p->pkey_group.attrs);
478 static struct kobj_type port_type = {
479 .release = ib_port_release,
480 .sysfs_ops = &port_sysfs_ops,
481 .default_attrs = port_default_attrs
484 static void ib_device_release(struct device *device)
486 struct ib_device *dev = container_of(device, struct ib_device, dev);
492 /* BSD supports this through devfs(5) and devd(8). */
493 static int ib_device_uevent(struct device *device,
494 struct kobj_uevent_env *env)
496 struct ib_device *dev = container_of(device, struct ib_device, dev);
498 if (add_uevent_var(env, "NAME=%s", dev->name))
502 * It would be nice to pass the node GUID with the event...
509 static struct attribute **
510 alloc_group_attrs(ssize_t (*show)(struct ib_port *,
511 struct port_attribute *, char *buf),
514 struct attribute **tab_attr;
515 struct port_table_attribute *element;
518 tab_attr = kcalloc(1 + len, sizeof(struct attribute *), GFP_KERNEL);
522 for (i = 0; i < len; i++) {
523 element = kzalloc(sizeof(struct port_table_attribute),
528 if (snprintf(element->name, sizeof(element->name),
529 "%d", i) >= sizeof(element->name)) {
534 element->attr.attr.name = element->name;
535 element->attr.attr.mode = S_IRUGO;
536 element->attr.show = show;
539 tab_attr[i] = &element->attr.attr;
551 static int add_port(struct ib_device *device, int port_num,
552 int (*port_callback)(struct ib_device *,
553 u8, struct kobject *))
556 struct ib_port_attr attr;
560 ret = ib_query_port(device, port_num, &attr);
564 p = kzalloc(sizeof *p, GFP_KERNEL);
569 p->port_num = port_num;
571 ret = kobject_init_and_add(&p->kobj, &port_type,
572 kobject_get(device->ports_parent),
577 ret = sysfs_create_group(&p->kobj, &pma_group);
581 ret = sysfs_create_group(&p->kobj, &pma_ext_group);
585 p->gid_group.name = "gids";
586 p->gid_group.attrs = alloc_group_attrs(show_port_gid, attr.gid_tbl_len);
587 if (!p->gid_group.attrs)
588 goto err_remove_pma_ext;
590 ret = sysfs_create_group(&p->kobj, &p->gid_group);
594 p->pkey_group.name = "pkeys";
595 p->pkey_group.attrs = alloc_group_attrs(show_port_pkey,
597 if (!p->pkey_group.attrs)
600 ret = sysfs_create_group(&p->kobj, &p->pkey_group);
605 ret = port_callback(device, port_num, &p->kobj);
607 goto err_remove_pkey;
610 list_add_tail(&p->kobj.entry, &device->port_list);
613 kobject_uevent(&p->kobj, KOBJ_ADD);
618 sysfs_remove_group(&p->kobj, &p->pkey_group);
621 for (i = 0; i < attr.pkey_tbl_len; ++i)
622 kfree(p->pkey_group.attrs[i]);
624 kfree(p->pkey_group.attrs);
627 sysfs_remove_group(&p->kobj, &p->gid_group);
630 for (i = 0; i < attr.gid_tbl_len; ++i)
631 kfree(p->gid_group.attrs[i]);
633 kfree(p->gid_group.attrs);
636 sysfs_remove_group(&p->kobj, &pma_ext_group);
639 sysfs_remove_group(&p->kobj, &pma_group);
642 kobject_put(device->ports_parent);
647 static ssize_t show_node_type(struct device *device,
648 struct device_attribute *attr, char *buf)
650 struct ib_device *dev = container_of(device, struct ib_device, dev);
652 switch (dev->node_type) {
653 case RDMA_NODE_IB_CA: return sprintf(buf, "%d: CA\n", dev->node_type);
654 case RDMA_NODE_RNIC: return sprintf(buf, "%d: RNIC\n", dev->node_type);
655 case RDMA_NODE_IB_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type);
656 case RDMA_NODE_IB_ROUTER: return sprintf(buf, "%d: router\n", dev->node_type);
657 default: return sprintf(buf, "%d: <unknown>\n", dev->node_type);
661 static ssize_t show_sys_image_guid(struct device *device,
662 struct device_attribute *dev_attr, char *buf)
664 struct ib_device *dev = container_of(device, struct ib_device, dev);
665 struct ib_device_attr attr;
668 ret = ib_query_device(dev, &attr);
672 return sprintf(buf, "%04x:%04x:%04x:%04x\n",
673 be16_to_cpu(((__be16 *) &attr.sys_image_guid)[0]),
674 be16_to_cpu(((__be16 *) &attr.sys_image_guid)[1]),
675 be16_to_cpu(((__be16 *) &attr.sys_image_guid)[2]),
676 be16_to_cpu(((__be16 *) &attr.sys_image_guid)[3]));
679 static ssize_t show_node_guid(struct device *device,
680 struct device_attribute *attr, char *buf)
682 struct ib_device *dev = container_of(device, struct ib_device, dev);
684 return sprintf(buf, "%04x:%04x:%04x:%04x\n",
685 be16_to_cpu(((__be16 *) &dev->node_guid)[0]),
686 be16_to_cpu(((__be16 *) &dev->node_guid)[1]),
687 be16_to_cpu(((__be16 *) &dev->node_guid)[2]),
688 be16_to_cpu(((__be16 *) &dev->node_guid)[3]));
691 static ssize_t show_node_desc(struct device *device,
692 struct device_attribute *attr, char *buf)
694 struct ib_device *dev = container_of(device, struct ib_device, dev);
696 return sprintf(buf, "%.64s\n", dev->node_desc);
699 static ssize_t set_node_desc(struct device *device,
700 struct device_attribute *attr,
701 const char *buf, size_t count)
703 struct ib_device *dev = container_of(device, struct ib_device, dev);
704 struct ib_device_modify desc = {};
707 if (!dev->modify_device)
710 memcpy(desc.node_desc, buf, min_t(int, count, 64));
711 ret = ib_modify_device(dev, IB_DEVICE_MODIFY_NODE_DESC, &desc);
718 static DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL);
719 static DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL);
720 static DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL);
721 static DEVICE_ATTR(node_desc, S_IRUGO | S_IWUSR, show_node_desc, set_node_desc);
723 static struct device_attribute *ib_class_attributes[] = {
725 &dev_attr_sys_image_guid,
730 static struct class ib_class = {
731 .name = "infiniband",
732 .dev_release = ib_device_release,
734 .dev_uevent = ib_device_uevent,
738 /* Show a given an attribute in the statistics group */
739 static ssize_t show_protocol_stat(const struct device *device,
740 struct device_attribute *attr, char *buf,
743 struct ib_device *dev = container_of(__DECONST(struct device *, device), struct ib_device, dev);
744 union rdma_protocol_stats stats;
747 ret = dev->get_protocol_stats(dev, &stats);
751 return sprintf(buf, "%llu\n",
752 (unsigned long long) ((u64 *) &stats)[offset]);
755 /* generate a read-only iwarp statistics attribute */
756 #define IW_STATS_ENTRY(name) \
757 static ssize_t show_##name(struct device *device, \
758 struct device_attribute *attr, char *buf) \
760 return show_protocol_stat(device, attr, buf, \
761 offsetof(struct iw_protocol_stats, name) / \
764 static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
766 IW_STATS_ENTRY(ipInReceives);
767 IW_STATS_ENTRY(ipInHdrErrors);
768 IW_STATS_ENTRY(ipInTooBigErrors);
769 IW_STATS_ENTRY(ipInNoRoutes);
770 IW_STATS_ENTRY(ipInAddrErrors);
771 IW_STATS_ENTRY(ipInUnknownProtos);
772 IW_STATS_ENTRY(ipInTruncatedPkts);
773 IW_STATS_ENTRY(ipInDiscards);
774 IW_STATS_ENTRY(ipInDelivers);
775 IW_STATS_ENTRY(ipOutForwDatagrams);
776 IW_STATS_ENTRY(ipOutRequests);
777 IW_STATS_ENTRY(ipOutDiscards);
778 IW_STATS_ENTRY(ipOutNoRoutes);
779 IW_STATS_ENTRY(ipReasmTimeout);
780 IW_STATS_ENTRY(ipReasmReqds);
781 IW_STATS_ENTRY(ipReasmOKs);
782 IW_STATS_ENTRY(ipReasmFails);
783 IW_STATS_ENTRY(ipFragOKs);
784 IW_STATS_ENTRY(ipFragFails);
785 IW_STATS_ENTRY(ipFragCreates);
786 IW_STATS_ENTRY(ipInMcastPkts);
787 IW_STATS_ENTRY(ipOutMcastPkts);
788 IW_STATS_ENTRY(ipInBcastPkts);
789 IW_STATS_ENTRY(ipOutBcastPkts);
790 IW_STATS_ENTRY(tcpRtoAlgorithm);
791 IW_STATS_ENTRY(tcpRtoMin);
792 IW_STATS_ENTRY(tcpRtoMax);
793 IW_STATS_ENTRY(tcpMaxConn);
794 IW_STATS_ENTRY(tcpActiveOpens);
795 IW_STATS_ENTRY(tcpPassiveOpens);
796 IW_STATS_ENTRY(tcpAttemptFails);
797 IW_STATS_ENTRY(tcpEstabResets);
798 IW_STATS_ENTRY(tcpCurrEstab);
799 IW_STATS_ENTRY(tcpInSegs);
800 IW_STATS_ENTRY(tcpOutSegs);
801 IW_STATS_ENTRY(tcpRetransSegs);
802 IW_STATS_ENTRY(tcpInErrs);
803 IW_STATS_ENTRY(tcpOutRsts);
805 static struct attribute *iw_proto_stats_attrs[] = {
806 &dev_attr_ipInReceives.attr,
807 &dev_attr_ipInHdrErrors.attr,
808 &dev_attr_ipInTooBigErrors.attr,
809 &dev_attr_ipInNoRoutes.attr,
810 &dev_attr_ipInAddrErrors.attr,
811 &dev_attr_ipInUnknownProtos.attr,
812 &dev_attr_ipInTruncatedPkts.attr,
813 &dev_attr_ipInDiscards.attr,
814 &dev_attr_ipInDelivers.attr,
815 &dev_attr_ipOutForwDatagrams.attr,
816 &dev_attr_ipOutRequests.attr,
817 &dev_attr_ipOutDiscards.attr,
818 &dev_attr_ipOutNoRoutes.attr,
819 &dev_attr_ipReasmTimeout.attr,
820 &dev_attr_ipReasmReqds.attr,
821 &dev_attr_ipReasmOKs.attr,
822 &dev_attr_ipReasmFails.attr,
823 &dev_attr_ipFragOKs.attr,
824 &dev_attr_ipFragFails.attr,
825 &dev_attr_ipFragCreates.attr,
826 &dev_attr_ipInMcastPkts.attr,
827 &dev_attr_ipOutMcastPkts.attr,
828 &dev_attr_ipInBcastPkts.attr,
829 &dev_attr_ipOutBcastPkts.attr,
830 &dev_attr_tcpRtoAlgorithm.attr,
831 &dev_attr_tcpRtoMin.attr,
832 &dev_attr_tcpRtoMax.attr,
833 &dev_attr_tcpMaxConn.attr,
834 &dev_attr_tcpActiveOpens.attr,
835 &dev_attr_tcpPassiveOpens.attr,
836 &dev_attr_tcpAttemptFails.attr,
837 &dev_attr_tcpEstabResets.attr,
838 &dev_attr_tcpCurrEstab.attr,
839 &dev_attr_tcpInSegs.attr,
840 &dev_attr_tcpOutSegs.attr,
841 &dev_attr_tcpRetransSegs.attr,
842 &dev_attr_tcpInErrs.attr,
843 &dev_attr_tcpOutRsts.attr,
847 static struct attribute_group iw_stats_group = {
848 .name = "proto_stats",
849 .attrs = iw_proto_stats_attrs,
852 int ib_device_register_sysfs(struct ib_device *device,
853 int (*port_callback)(struct ib_device *, u8, struct kobject *))
855 struct device *class_dev = &device->dev;
859 class_dev->class = &ib_class;
860 class_dev->parent = device->dma_device;
861 dev_set_name(class_dev, device->name);
862 dev_set_drvdata(class_dev, device);
864 INIT_LIST_HEAD(&device->port_list);
866 ret = device_register(class_dev);
870 for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i) {
871 ret = device_create_file(class_dev, ib_class_attributes[i]);
876 device->ports_parent = kobject_create_and_add("ports",
877 kobject_get(&class_dev->kobj));
878 if (!device->ports_parent) {
883 if (device->node_type == RDMA_NODE_IB_SWITCH) {
884 ret = add_port(device, 0, port_callback);
888 for (i = 1; i <= device->phys_port_cnt; ++i) {
889 ret = add_port(device, i, port_callback);
895 if (device->node_type == RDMA_NODE_RNIC && device->get_protocol_stats) {
896 ret = sysfs_create_group(&class_dev->kobj, &iw_stats_group);
905 struct kobject *p, *t;
906 struct ib_port *port;
908 list_for_each_entry_safe(p, t, &device->port_list, entry) {
910 port = container_of(p, struct ib_port, kobj);
911 sysfs_remove_group(p, &pma_group);
912 sysfs_remove_group(p, &port->pkey_group);
913 sysfs_remove_group(p, &port->gid_group);
918 kobject_put(&class_dev->kobj);
921 device_unregister(class_dev);
927 void ib_device_unregister_sysfs(struct ib_device *device)
929 struct kobject *p, *t;
930 struct ib_port *port;
933 /* Hold kobject until ib_dealloc_device() */
934 kobject_get(&device->dev.kobj);
936 for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i) {
937 device_remove_file(&device->dev, ib_class_attributes[i]);
940 list_for_each_entry_safe(p, t, &device->port_list, entry) {
942 port = container_of(p, struct ib_port, kobj);
943 sysfs_remove_group(p, &pma_group);
944 sysfs_remove_group(p, &port->pkey_group);
945 sysfs_remove_group(p, &port->gid_group);
949 kobject_put(device->ports_parent);
950 device_unregister(&device->dev);
953 int ib_sysfs_setup(void)
955 return class_register(&ib_class);
958 void ib_sysfs_cleanup(void)
960 class_unregister(&ib_class);
963 /*int ib_sysfs_create_port_files(struct ib_device *device,
964 int (*create)(struct ib_device *dev, u8 port_num,
965 struct kobject *kobj))
968 struct ib_port *port;
971 list_for_each_entry(p, &device->port_list, entry) {
972 port = container_of(p, struct ib_port, kobj);
973 ret = create(device, port->port_num, &port->kobj);
980 EXPORT_SYMBOL(ib_sysfs_create_port_files);*/