@@ -38,7 +38,7 @@
#include <rdma/ib_verbs.h>
-int ib_device_register_sysfs(struct ib_device *device);
+int ib_device_register_sysfs(struct ib_device *device, sysfs_cb cb);
void ib_device_unregister_sysfs(struct ib_device *device);
int ib_sysfs_setup(void);
@@ -267,7 +267,7 @@ out:
* callback for each device that is added. @device must be allocated
* with ib_alloc_device().
*/
-int ib_register_device(struct ib_device *device)
+int ib_register_device(struct ib_device *device, sysfs_cb cb)
{
int ret;
@@ -296,7 +296,7 @@ int ib_register_device(struct ib_device *device)
goto out;
}
- ret = ib_device_register_sysfs(device);
+ ret = ib_device_register_sysfs(device, cb);
if (ret) {
printk(KERN_WARNING "Couldn't register device %s with driver model\n",
device->name);
@@ -754,7 +754,23 @@ static struct attribute_group iw_stats_group = {
.attrs = iw_proto_stats_attrs,
};
-int ib_device_register_sysfs(struct ib_device *device)
+static int sysfs_create_port_files(struct ib_device *device, sysfs_cb cb)
+{
+ struct kobject *p;
+ struct ib_port *port;
+ int ret = 0;
+
+ list_for_each_entry(p, &device->port_list, entry) {
+ port = container_of(p, struct ib_port, kobj);
+ ret = cb(device, port->port_num, &port->kobj);
+ if (ret)
+ break;
+ }
+
+ return ret;
+}
+
+int ib_device_register_sysfs(struct ib_device *device, sysfs_cb cb)
{
struct device *class_dev = &device->dev;
int ret;
@@ -802,6 +818,12 @@ int ib_device_register_sysfs(struct ib_device *device)
goto err_put;
}
+ if (cb) {
+ ret = sysfs_create_port_files(device, cb);
+ if (ret)
+ goto err_put;
+ }
+
return 0;
err_put:
@@ -1189,7 +1189,10 @@ struct ib_client {
struct ib_device *ib_alloc_device(size_t size);
void ib_dealloc_device(struct ib_device *device);
-int ib_register_device (struct ib_device *device);
+typedef int (*sysfs_cb)(struct ib_device *dev, u8 port_num,
+ struct kobject *kobj);
+
+int ib_register_device (struct ib_device *device, sysfs_cb cb);
void ib_unregister_device(struct ib_device *device);
int ib_register_client (struct ib_client *client);