From: Roland Dreier Add per-device "node_type" and per-port "phys_state" sysfs attributes for InfiniBand devices. Signed-off-by: Roland Dreier Signed-off-by: Andrew Morton --- 25-akpm/Documentation/infiniband/sysfs.txt | 2 25-akpm/drivers/infiniband/core/sysfs.c | 39 +++++++++++++++++++ 25-akpm/drivers/infiniband/hw/mthca/mthca_provider.c | 1 25-akpm/drivers/infiniband/include/ib_verbs.h | 1 4 files changed, 43 insertions(+) diff -puN Documentation/infiniband/sysfs.txt~infiniband-core-add-node_type-and-phys_state-sysfs-attrs Documentation/infiniband/sysfs.txt --- 25/Documentation/infiniband/sysfs.txt~infiniband-core-add-node_type-and-phys_state-sysfs-attrs Wed Jan 12 16:31:49 2005 +++ 25-akpm/Documentation/infiniband/sysfs.txt Wed Jan 12 16:31:49 2005 @@ -3,6 +3,7 @@ SYSFS FILES For each InfiniBand device, the InfiniBand drivers create the following files under /sys/class/infiniband/: + node_type - Node type (CA, switch or router) node_guid - Node GUID sys_image_guid - System image GUID @@ -25,6 +26,7 @@ SYSFS FILES sm_lid - Subnet manager LID for port's subnet sm_sl - Subnet manager SL for port's subnet state - Port state (DOWN, INIT, ARMED, ACTIVE or ACTIVE_DEFER) + phys_state - Port physical state (Sleep, Polling, LinkUp, etc) There is also a "counters" subdirectory, with files diff -puN drivers/infiniband/core/sysfs.c~infiniband-core-add-node_type-and-phys_state-sysfs-attrs drivers/infiniband/core/sysfs.c --- 25/drivers/infiniband/core/sysfs.c~infiniband-core-add-node_type-and-phys_state-sysfs-attrs Wed Jan 12 16:31:49 2005 +++ 25-akpm/drivers/infiniband/core/sysfs.c Wed Jan 12 16:31:49 2005 @@ -197,6 +197,29 @@ static ssize_t rate_show(struct ib_port ib_width_enum_to_int(attr.active_width), speed); } +static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused, + char *buf) +{ + struct ib_port_attr attr; + + ssize_t ret; + + ret = ib_query_port(p->ibdev, p->port_num, &attr); + if (ret) + return ret; + + switch (attr.phys_state) { + case 1: return sprintf(buf, "1: Sleep\n"); + case 2: return sprintf(buf, "2: Polling\n"); + case 3: return sprintf(buf, "3: Disabled\n"); + case 4: return sprintf(buf, "4: PortConfigurationTraining\n"); + case 5: return sprintf(buf, "5: LinkUp\n"); + case 6: return sprintf(buf, "6: LinkErrorRecovery\n"); + case 7: return sprintf(buf, "7: Phy Test\n"); + default: return sprintf(buf, "%d: \n", attr.phys_state); + } +} + static PORT_ATTR_RO(state); static PORT_ATTR_RO(lid); static PORT_ATTR_RO(lid_mask_count); @@ -204,6 +227,7 @@ static PORT_ATTR_RO(sm_lid); static PORT_ATTR_RO(sm_sl); static PORT_ATTR_RO(cap_mask); static PORT_ATTR_RO(rate); +static PORT_ATTR_RO(phys_state); static struct attribute *port_default_attrs[] = { &port_attr_state.attr, @@ -213,6 +237,7 @@ static struct attribute *port_default_at &port_attr_sm_sl.attr, &port_attr_cap_mask.attr, &port_attr_rate.attr, + &port_attr_phys_state.attr, NULL }; @@ -572,6 +597,18 @@ err: return ret; } +static ssize_t show_node_type(struct class_device *cdev, char *buf) +{ + struct ib_device *dev = container_of(cdev, struct ib_device, class_dev); + + switch (dev->node_type) { + case IB_NODE_CA: return sprintf(buf, "%d: CA\n", dev->node_type); + case IB_NODE_SWITCH: return sprintf(buf, "%d: switch\n", dev->node_type); + case IB_NODE_ROUTER: return sprintf(buf, "%d: router\n", dev->node_type); + default: return sprintf(buf, "%d: \n", dev->node_type); + } +} + static ssize_t show_sys_image_guid(struct class_device *cdev, char *buf) { struct ib_device *dev = container_of(cdev, struct ib_device, class_dev); @@ -606,10 +643,12 @@ static ssize_t show_node_guid(struct cla be16_to_cpu(((u16 *) &attr.node_guid)[3])); } +static CLASS_DEVICE_ATTR(node_type, S_IRUGO, show_node_type, NULL); static CLASS_DEVICE_ATTR(sys_image_guid, S_IRUGO, show_sys_image_guid, NULL); static CLASS_DEVICE_ATTR(node_guid, S_IRUGO, show_node_guid, NULL); static struct class_device_attribute *ib_class_attributes[] = { + &class_device_attr_node_type, &class_device_attr_sys_image_guid, &class_device_attr_node_guid }; diff -puN drivers/infiniband/hw/mthca/mthca_provider.c~infiniband-core-add-node_type-and-phys_state-sysfs-attrs drivers/infiniband/hw/mthca/mthca_provider.c --- 25/drivers/infiniband/hw/mthca/mthca_provider.c~infiniband-core-add-node_type-and-phys_state-sysfs-attrs Wed Jan 12 16:31:49 2005 +++ 25-akpm/drivers/infiniband/hw/mthca/mthca_provider.c Wed Jan 12 16:31:49 2005 @@ -119,6 +119,7 @@ static int mthca_query_port(struct ib_de props->sm_lid = be16_to_cpup((u16 *) (out_mad->data + 18)); props->sm_sl = out_mad->data[36] & 0xf; props->state = out_mad->data[32] & 0xf; + props->phys_state = out_mad->data[33] >> 4; props->port_cap_flags = be32_to_cpup((u32 *) (out_mad->data + 20)); props->gid_tbl_len = to_mdev(ibdev)->limits.gid_table_len; props->pkey_tbl_len = to_mdev(ibdev)->limits.pkey_table_len; diff -puN drivers/infiniband/include/ib_verbs.h~infiniband-core-add-node_type-and-phys_state-sysfs-attrs drivers/infiniband/include/ib_verbs.h --- 25/drivers/infiniband/include/ib_verbs.h~infiniband-core-add-node_type-and-phys_state-sysfs-attrs Wed Jan 12 16:31:49 2005 +++ 25-akpm/drivers/infiniband/include/ib_verbs.h Wed Jan 12 16:31:49 2005 @@ -212,6 +212,7 @@ struct ib_port_attr { u8 init_type_reply; u8 active_width; u8 active_speed; + u8 phys_state; }; enum ib_device_modify_flags { _