diff options
Diffstat (limited to 'drivers/infiniband/core/ucm.c')
| -rw-r--r-- | drivers/infiniband/core/ucm.c | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/drivers/infiniband/core/ucm.c b/drivers/infiniband/core/ucm.c index d0f0b0a2edd..b7470f0fe83 100644 --- a/drivers/infiniband/core/ucm.c +++ b/drivers/infiniband/core/ucm.c | |||
| @@ -41,19 +41,52 @@ | |||
| 41 | #include <linux/file.h> | 41 | #include <linux/file.h> |
| 42 | #include <linux/mount.h> | 42 | #include <linux/mount.h> |
| 43 | #include <linux/cdev.h> | 43 | #include <linux/cdev.h> |
| 44 | #include <linux/idr.h> | ||
| 44 | 45 | ||
| 45 | #include <asm/uaccess.h> | 46 | #include <asm/uaccess.h> |
| 46 | 47 | ||
| 47 | #include "ucm.h" | 48 | #include <rdma/ib_cm.h> |
| 49 | #include <rdma/ib_user_cm.h> | ||
| 48 | 50 | ||
| 49 | MODULE_AUTHOR("Libor Michalek"); | 51 | MODULE_AUTHOR("Libor Michalek"); |
| 50 | MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access"); | 52 | MODULE_DESCRIPTION("InfiniBand userspace Connection Manager access"); |
| 51 | MODULE_LICENSE("Dual BSD/GPL"); | 53 | MODULE_LICENSE("Dual BSD/GPL"); |
| 52 | 54 | ||
| 53 | static int ucm_debug_level; | 55 | struct ib_ucm_file { |
| 56 | struct semaphore mutex; | ||
| 57 | struct file *filp; | ||
| 54 | 58 | ||
| 55 | module_param_named(debug_level, ucm_debug_level, int, 0644); | 59 | struct list_head ctxs; /* list of active connections */ |
| 56 | MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0"); | 60 | struct list_head events; /* list of pending events */ |
| 61 | wait_queue_head_t poll_wait; | ||
| 62 | }; | ||
| 63 | |||
| 64 | struct ib_ucm_context { | ||
| 65 | int id; | ||
| 66 | wait_queue_head_t wait; | ||
| 67 | atomic_t ref; | ||
| 68 | int events_reported; | ||
| 69 | |||
| 70 | struct ib_ucm_file *file; | ||
| 71 | struct ib_cm_id *cm_id; | ||
| 72 | __u64 uid; | ||
| 73 | |||
| 74 | struct list_head events; /* list of pending events. */ | ||
| 75 | struct list_head file_list; /* member in file ctx list */ | ||
| 76 | }; | ||
| 77 | |||
| 78 | struct ib_ucm_event { | ||
| 79 | struct ib_ucm_context *ctx; | ||
| 80 | struct list_head file_list; /* member in file event list */ | ||
| 81 | struct list_head ctx_list; /* member in ctx event list */ | ||
| 82 | |||
| 83 | struct ib_cm_id *cm_id; | ||
| 84 | struct ib_ucm_event_resp resp; | ||
| 85 | void *data; | ||
| 86 | void *info; | ||
| 87 | int data_len; | ||
| 88 | int info_len; | ||
| 89 | }; | ||
| 57 | 90 | ||
| 58 | enum { | 91 | enum { |
| 59 | IB_UCM_MAJOR = 231, | 92 | IB_UCM_MAJOR = 231, |
| @@ -62,17 +95,10 @@ enum { | |||
| 62 | 95 | ||
| 63 | #define IB_UCM_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_MINOR) | 96 | #define IB_UCM_DEV MKDEV(IB_UCM_MAJOR, IB_UCM_MINOR) |
| 64 | 97 | ||
| 65 | #define PFX "UCM: " | ||
| 66 | |||
| 67 | #define ucm_dbg(format, arg...) \ | ||
| 68 | do { \ | ||
| 69 | if (ucm_debug_level > 0) \ | ||
| 70 | printk(KERN_DEBUG PFX format, ## arg); \ | ||
| 71 | } while (0) | ||
| 72 | |||
| 73 | static struct semaphore ctx_id_mutex; | 98 | static struct semaphore ctx_id_mutex; |
| 74 | static struct idr ctx_id_table; | 99 | static struct idr ctx_id_table; |
| 75 | 100 | ||
| 101 | |||
| 76 | static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id) | 102 | static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id) |
| 77 | { | 103 | { |
| 78 | struct ib_ucm_context *ctx; | 104 | struct ib_ucm_context *ctx; |
| @@ -152,7 +178,6 @@ static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file) | |||
| 152 | goto error; | 178 | goto error; |
| 153 | 179 | ||
| 154 | list_add_tail(&ctx->file_list, &file->ctxs); | 180 | list_add_tail(&ctx->file_list, &file->ctxs); |
| 155 | ucm_dbg("Allocated CM ID <%d>\n", ctx->id); | ||
| 156 | return ctx; | 181 | return ctx; |
| 157 | 182 | ||
| 158 | error: | 183 | error: |
| @@ -1184,9 +1209,6 @@ static ssize_t ib_ucm_write(struct file *filp, const char __user *buf, | |||
| 1184 | if (copy_from_user(&hdr, buf, sizeof(hdr))) | 1209 | if (copy_from_user(&hdr, buf, sizeof(hdr))) |
| 1185 | return -EFAULT; | 1210 | return -EFAULT; |
| 1186 | 1211 | ||
| 1187 | ucm_dbg("Write. cmd <%d> in <%d> out <%d> len <%Zu>\n", | ||
| 1188 | hdr.cmd, hdr.in, hdr.out, len); | ||
| 1189 | |||
| 1190 | if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table)) | 1212 | if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucm_cmd_table)) |
| 1191 | return -EINVAL; | 1213 | return -EINVAL; |
| 1192 | 1214 | ||
| @@ -1232,8 +1254,6 @@ static int ib_ucm_open(struct inode *inode, struct file *filp) | |||
| 1232 | filp->private_data = file; | 1254 | filp->private_data = file; |
| 1233 | file->filp = filp; | 1255 | file->filp = filp; |
| 1234 | 1256 | ||
| 1235 | ucm_dbg("Created struct\n"); | ||
| 1236 | |||
| 1237 | return 0; | 1257 | return 0; |
| 1238 | } | 1258 | } |
| 1239 | 1259 | ||
| @@ -1281,7 +1301,7 @@ static int __init ib_ucm_init(void) | |||
| 1281 | 1301 | ||
| 1282 | result = register_chrdev_region(IB_UCM_DEV, 1, "infiniband_cm"); | 1302 | result = register_chrdev_region(IB_UCM_DEV, 1, "infiniband_cm"); |
| 1283 | if (result) { | 1303 | if (result) { |
| 1284 | ucm_dbg("Error <%d> registering dev\n", result); | 1304 | printk(KERN_ERR "ucm: Error <%d> registering dev\n", result); |
| 1285 | goto err_chr; | 1305 | goto err_chr; |
| 1286 | } | 1306 | } |
| 1287 | 1307 | ||
| @@ -1289,14 +1309,14 @@ static int __init ib_ucm_init(void) | |||
| 1289 | 1309 | ||
| 1290 | result = cdev_add(&ib_ucm_cdev, IB_UCM_DEV, 1); | 1310 | result = cdev_add(&ib_ucm_cdev, IB_UCM_DEV, 1); |
| 1291 | if (result) { | 1311 | if (result) { |
| 1292 | ucm_dbg("Error <%d> adding cdev\n", result); | 1312 | printk(KERN_ERR "ucm: Error <%d> adding cdev\n", result); |
| 1293 | goto err_cdev; | 1313 | goto err_cdev; |
| 1294 | } | 1314 | } |
| 1295 | 1315 | ||
| 1296 | ib_ucm_class = class_create(THIS_MODULE, "infiniband_cm"); | 1316 | ib_ucm_class = class_create(THIS_MODULE, "infiniband_cm"); |
| 1297 | if (IS_ERR(ib_ucm_class)) { | 1317 | if (IS_ERR(ib_ucm_class)) { |
| 1298 | result = PTR_ERR(ib_ucm_class); | 1318 | result = PTR_ERR(ib_ucm_class); |
| 1299 | ucm_dbg("Error <%d> creating class\n", result); | 1319 | printk(KERN_ERR "Error <%d> creating class\n", result); |
| 1300 | goto err_class; | 1320 | goto err_class; |
| 1301 | } | 1321 | } |
| 1302 | 1322 | ||
