Date: Fri, 9 Nov 2007 21:08:21 GMT From: Steve Wise <swise@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 128874 for review Message-ID: <200711092108.lA9L8LQr033892@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=128874 Change 128874 by swise@swise:vic10:iwarp on 2007/11/09 21:08:01 rdma_device.c compiles. Affected files ... .. //depot/projects/iwarp/sys/contrib/rdma/core_priv.h#1 add .. //depot/projects/iwarp/sys/contrib/rdma/ib_verbs.h#3 edit .. //depot/projects/iwarp/sys/contrib/rdma/rdma_cache.c#1 add .. //depot/projects/iwarp/sys/contrib/rdma/rdma_device.c#2 edit .. //depot/projects/iwarp/sys/modules/rdma/core/Makefile#2 edit .. //depot/projects/iwarp/sys/sys/linux_compat.h#5 edit Differences ... ==== //depot/projects/iwarp/sys/contrib/rdma/ib_verbs.h#3 (text+ko) ==== @@ -289,7 +289,7 @@ struct ib_event_handler { struct ib_device *device; void (*handler)(struct ib_event_handler *, struct ib_event *); - TAILQ_ENTRY(ib_event_handler) entry; + TAILQ_ENTRY(ib_event_handler) list; }; #define INIT_IB_EVENT_HANDLER(_ptr, _device, _handler) \ @@ -884,11 +884,11 @@ char name[IB_DEVICE_NAME_MAX]; - TAILQ_ENTRY(ib_device) event_handler_entry; + TAILQ_HEAD(, ib_event_handler) event_handler_list; spinlock_t event_handler_lock; - TAILQ_ENTRY(ib_device) core_entry; - TAILQ_ENTRY(ib_device) client_data_entry; + TAILQ_ENTRY(ib_device) core_list; + TAILQ_HEAD(, ib_client_data) client_data_list; spinlock_t client_data_lock; struct ib_cache cache; @@ -1054,7 +1054,7 @@ char *name; void (*add) (struct ib_device *); void (*remove)(struct ib_device *); - TAILQ_ENTRY(ib_client) entry; + TAILQ_ENTRY(ib_client) list; }; struct ib_device *ib_alloc_device(size_t size); ==== //depot/projects/iwarp/sys/contrib/rdma/rdma_device.c#2 (text+ko) ==== @@ -33,29 +33,38 @@ * $Id: device.c 1349 2004-12-16 21:09:43Z roland $ */ -#include <linux/module.h> -#include <linux/string.h> -#include <linux/errno.h> -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/init.h> -#include <linux/mutex.h> -#include <linux/workqueue.h> +#include <sys/cdefs.h> + +#include <sys/param.h> +#include <sys/condvar.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/libkern.h> +#include <sys/socket.h> +#include <sys/module.h> +#include <sys/linux_compat.h> +#include <sys/lock.h> +#include <sys/mutex.h> +#include <sys/rwlock.h> +#include <sys/queue.h> +#include <sys/taskqueue.h> +#include <sys/priv.h> +#include <sys/syslog.h> -#include "core_priv.h" +#include <contrib/rdma/core_priv.h> MODULE_AUTHOR("Roland Dreier"); MODULE_DESCRIPTION("core kernel InfiniBand API"); MODULE_LICENSE("Dual BSD/GPL"); struct ib_client_data { - struct list_head list; + TAILQ_ENTRY(ib_client_data) list; struct ib_client *client; void * data; }; -static LIST_HEAD(device_list); -static LIST_HEAD(client_list); +static TAILQ_HEAD(, ib_device) device_list; +static TAILQ_HEAD(client_list_s, ib_client) client_list; /* * device_mutex protects access to both device_list and client_list. @@ -64,11 +73,12 @@ * modifying one list or the other list. In any case this is not a * hot path so there's no point in trying to optimize. */ -static DEFINE_MUTEX(device_mutex); +static struct mtx device_mutex; static int ib_device_check_mandatory(struct ib_device *device) { #define IB_MANDATORY_FUNC(x) { offsetof(struct ib_device, x), #x } +#define MANDATORY_TABLE_DEPTH 19 static const struct { size_t offset; char *name; @@ -95,9 +105,9 @@ }; int i; - for (i = 0; i < ARRAY_SIZE(mandatory_table); ++i) { - if (!*(void **) ((void *) device + mandatory_table[i].offset)) { - log(LOG_WARN, "Device %s is missing mandatory function %s\n", + for (i = 0; i < MANDATORY_TABLE_DEPTH; ++i) { + if (!*(void **) ((void *) ((unsigned long)device + mandatory_table[i].offset))) { + log(LOG_WARNING, "Device %s is missing mandatory function %s\n", device->name, mandatory_table[i].name); return (EINVAL); } @@ -110,7 +120,7 @@ { struct ib_device *device; - list_for_each_entry(device, &device_list, core_list) + TAILQ_FOREACH(device, &device_list, core_list) if (!strncmp(name, device->name, IB_DEVICE_NAME_MAX)) return device; @@ -125,11 +135,11 @@ struct ib_device *device; int i; - inuse = (long *) get_zeroed_page(GFP_KERNEL); + inuse = malloc(PAGE_SIZE, M_DEVBUF, M_WAITOK); if (!inuse) return (ENOMEM); - list_for_each_entry(device, &device_list, core_list) { + TAILQ_FOREACH(device, &device_list, core_list) { if (!sscanf(device->name, name, &i)) continue; if (i < 0 || i >= PAGE_SIZE * 8) @@ -140,7 +150,7 @@ } i = find_first_zero_bit(inuse, PAGE_SIZE * 8); - free_page((unsigned long) inuse); + free(inuse, M_DEVBUF); snprintf(buf, sizeof buf, name, i); if (__ib_device_get_by_name(buf)) @@ -174,9 +184,14 @@ */ struct ib_device *ib_alloc_device(size_t size) { + void *dev; + BUG_ON(size < sizeof (struct ib_device)); - return kzalloc(size, GFP_KERNEL); + dev = malloc(size, M_DEVBUF, M_WAITOK); + if (dev) + bzero(dev, size); + return dev; } EXPORT_SYMBOL(ib_alloc_device); @@ -189,24 +204,24 @@ void ib_dealloc_device(struct ib_device *device) { if (device->reg_state == IB_DEV_UNINITIALIZED) { - kfree(device); + free(device, M_DEVBUF); return; } BUG_ON(device->reg_state != IB_DEV_UNREGISTERED); - +#ifdef notyet ib_device_unregister_sysfs(device); +#endif } EXPORT_SYMBOL(ib_dealloc_device); static int add_client_context(struct ib_device *device, struct ib_client *client) { struct ib_client_data *context; - unsigned long flags; - context = kmalloc(sizeof *context, GFP_KERNEL); + context = malloc(sizeof *context, M_DEVBUF, M_WAITOK); if (!context) { - log(LOG_WARN, "Couldn't allocate client context for %s/%s\n", + log(LOG_WARNING, "Couldn't allocate client context for %s/%s\n", device->name, client->name); return (ENOMEM); } @@ -214,9 +229,9 @@ context->client = client; context->data = NULL; - mtx_lock(&device->client_data_lock, flags); - list_add(&context->list, &device->client_data_list); - mtx_unlock(&device->client_data_lock, flags); + mtx_lock_spin(&device->client_data_lock); + TAILQ_INSERT_TAIL(&device->client_data_list, context, list); + mtx_unlock_spin(&device->client_data_lock); return 0; } @@ -227,16 +242,16 @@ int num_ports, ret = ENOMEM; u8 port_index; - tprops = kmalloc(sizeof *tprops, GFP_KERNEL); + tprops = malloc(sizeof *tprops, M_DEVBUF, M_WAITOK); if (!tprops) goto out; num_ports = end_port(device) - start_port(device) + 1; - device->pkey_tbl_len = kmalloc(sizeof *device->pkey_tbl_len * num_ports, - GFP_KERNEL); - device->gid_tbl_len = kmalloc(sizeof *device->gid_tbl_len * num_ports, - GFP_KERNEL); + device->pkey_tbl_len = malloc(sizeof *device->pkey_tbl_len * num_ports, + M_DEVBUF, M_WAITOK); + device->gid_tbl_len = malloc(sizeof *device->gid_tbl_len * num_ports, + M_DEVBUF, M_WAITOK); if (!device->pkey_tbl_len || !device->gid_tbl_len) goto err; @@ -253,10 +268,10 @@ goto out; err: - kfree(device->gid_tbl_len); - kfree(device->pkey_tbl_len); + free(device->gid_tbl_len, M_DEVBUF); + free(device->pkey_tbl_len, M_DEVBUF); out: - kfree(tprops); + free(tprops, M_DEVBUF); return ret; } @@ -273,7 +288,7 @@ { int ret; - mutex_lock(&device_mutex); + mtx_lock(&device_mutex); if (strchr(device->name, '%')) { ret = alloc_name(device->name); @@ -286,41 +301,43 @@ goto out; } - INIT_LIST_HEAD(&device->event_handler_list); - INIT_LIST_HEAD(&device->client_data_list); - mtx_init(&device->event_handler_lock, "ib event handler", NULL, MTX_DUPOK|MTX_DEF); - mtx_init(&device->client_data_lock, "ib client data", NULL, MTX_DUPOK|MTX_DEF); + TAILQ_INIT(&device->event_handler_list); + TAILQ_INIT(&device->client_data_list); + mtx_init(&device->event_handler_lock, "ib event handler", NULL, MTX_DUPOK|MTX_SPIN); + mtx_init(&device->client_data_lock, "ib client data", NULL, MTX_DUPOK|MTX_SPIN); ret = read_port_table_lengths(device); if (ret) { - log(LOG_WARN, "Couldn't create table lengths cache for device %s\n", + log(LOG_WARNING, "Couldn't create table lengths cache for device %s\n", device->name); goto out; } +#ifdef notyet ret = ib_device_register_sysfs(device); if (ret) { - log(LOG_WARN, "Couldn't register device %s with driver model\n", + log(LOG_WARNING, "Couldn't register device %s with driver model\n", device->name); - kfree(device->gid_tbl_len); - kfree(device->pkey_tbl_len); + free(device->gid_tbl_len, M_DEVBUF); + free(device->pkey_tbl_len, M_DEVBUF); goto out; } +#endif - list_add_tail(&device->core_list, &device_list); + TAILQ_INSERT_TAIL(&device_list, device, core_list); device->reg_state = IB_DEV_REGISTERED; { struct ib_client *client; - list_for_each_entry(client, &client_list, list) + TAILQ_FOREACH(client, &client_list, list) if (client->add && !add_client_context(device, client)) client->add(device); } out: - mutex_unlock(&device_mutex); + mtx_unlock(&device_mutex); return ret; } EXPORT_SYMBOL(ib_register_device); @@ -335,25 +352,24 @@ { struct ib_client *client; struct ib_client_data *context, *tmp; - unsigned long flags; - mutex_lock(&device_mutex); + mtx_lock(&device_mutex); - list_for_each_entry_reverse(client, &client_list, list) + TAILQ_FOREACH_REVERSE(client, &client_list, client_list_s, list) if (client->remove) client->remove(device); - list_del(&device->core_list); + TAILQ_REMOVE(&device_list, device, core_list); - kfree(device->gid_tbl_len); - kfree(device->pkey_tbl_len); + free(device->gid_tbl_len, M_DEVBUF); + free(device->pkey_tbl_len, M_DEVBUF); - mutex_unlock(&device_mutex); + mtx_unlock(&device_mutex); - mtx_lock(&device->client_data_lock, flags); - list_for_each_entry_safe(context, tmp, &device->client_data_list, list) - kfree(context); - mtx_unlock(&device->client_data_lock, flags); + mtx_lock_spin(&device->client_data_lock); + TAILQ_FOREACH_SAFE(context, &device->client_data_list, list, tmp) + free(context, M_DEVBUF); + mtx_unlock_spin(&device->client_data_lock); device->reg_state = IB_DEV_UNREGISTERED; } @@ -376,14 +392,14 @@ { struct ib_device *device; - mutex_lock(&device_mutex); + mtx_lock(&device_mutex); - list_add_tail(&client->list, &client_list); - list_for_each_entry(device, &device_list, core_list) + TAILQ_INSERT_TAIL(&client_list, client, list); + TAILQ_FOREACH(device, &device_list, core_list) if (client->add && !add_client_context(device, client)) client->add(device); - mutex_unlock(&device_mutex); + mtx_unlock(&device_mutex); return 0; } @@ -401,25 +417,25 @@ { struct ib_client_data *context, *tmp; struct ib_device *device; - unsigned long flags; - mutex_lock(&device_mutex); + mtx_lock(&device_mutex); - list_for_each_entry(device, &device_list, core_list) { + TAILQ_FOREACH(device, &device_list, core_list) { if (client->remove) client->remove(device); - mtx_lock(&device->client_data_lock, flags); - list_for_each_entry_safe(context, tmp, &device->client_data_list, list) + mtx_lock_spin(&device->client_data_lock); + TAILQ_FOREACH_SAFE(context, &device->client_data_list, list,tmp) if (context->client == client) { - list_del(&context->list); - kfree(context); + TAILQ_REMOVE(&device->client_data_list, context, + list); + free(context, M_DEVBUF); } - mtx_unlock(&device->client_data_lock, flags); + mtx_unlock_spin(&device->client_data_lock); } - list_del(&client->list); + TAILQ_REMOVE(&client_list, client, list); - mutex_unlock(&device_mutex); + mtx_unlock(&device_mutex); } EXPORT_SYMBOL(ib_unregister_client); @@ -435,15 +451,14 @@ { struct ib_client_data *context; void *ret = NULL; - unsigned long flags; - mtx_lock(&device->client_data_lock, flags); - list_for_each_entry(context, &device->client_data_list, list) + mtx_lock_spin(&device->client_data_lock); + TAILQ_FOREACH(context, &device->client_data_list, list) if (context->client == client) { ret = context->data; break; } - mtx_unlock(&device->client_data_lock, flags); + mtx_unlock_spin(&device->client_data_lock); return ret; } @@ -462,20 +477,19 @@ void *data) { struct ib_client_data *context; - unsigned long flags; - mtx_lock(&device->client_data_lock, flags); - list_for_each_entry(context, &device->client_data_list, list) + mtx_lock_spin(&device->client_data_lock); + TAILQ_FOREACH(context, &device->client_data_list, list) if (context->client == client) { context->data = data; goto out; } - log(LOG_WARN, "No client context found for %s/%s\n", + log(LOG_WARNING, "No client context found for %s/%s\n", device->name, client->name); out: - mtx_unlock(&device->client_data_lock, flags); + mtx_unlock_spin(&device->client_data_lock); } EXPORT_SYMBOL(ib_set_client_data); @@ -490,12 +504,10 @@ */ int ib_register_event_handler (struct ib_event_handler *event_handler) { - unsigned long flags; - - mtx_lock(&event_handler->device->event_handler_lock, flags); - list_add_tail(&event_handler->list, - &event_handler->device->event_handler_list); - mtx_unlock(&event_handler->device->event_handler_lock, flags); + mtx_lock_spin(&event_handler->device->event_handler_lock); + TAILQ_INSERT_TAIL(&event_handler->device->event_handler_list, + event_handler, list); + mtx_unlock_spin(&event_handler->device->event_handler_lock); return 0; } @@ -510,12 +522,11 @@ */ int ib_unregister_event_handler(struct ib_event_handler *event_handler) { - unsigned long flags; + mtx_lock_spin(&event_handler->device->event_handler_lock); + TAILQ_REMOVE(&event_handler->device->event_handler_list, event_handler, + list); + mtx_unlock_spin(&event_handler->device->event_handler_lock); - mtx_lock(&event_handler->device->event_handler_lock, flags); - list_del(&event_handler->list); - mtx_unlock(&event_handler->device->event_handler_lock, flags); - return 0; } EXPORT_SYMBOL(ib_unregister_event_handler); @@ -530,15 +541,14 @@ */ void ib_dispatch_event(struct ib_event *event) { - unsigned long flags; struct ib_event_handler *handler; - mtx_lock(&event->device->event_handler_lock, flags); + mtx_lock_spin(&event->device->event_handler_lock); - list_for_each_entry(handler, &event->device->event_handler_list, list) + TAILQ_FOREACH(handler, &event->device->event_handler_list, list) handler->handler(handler, event); - mtx_unlock(&event->device->event_handler_lock, flags); + mtx_unlock_spin(&event->device->event_handler_lock); } EXPORT_SYMBOL(ib_dispatch_event); @@ -712,30 +722,69 @@ } EXPORT_SYMBOL(ib_find_pkey); -static int __init ib_core_init(void) +static int __init rdma_core_init(void) { int ret; - +#ifdef notyet ret = ib_sysfs_setup(); if (ret) - log(LOG_WARN, "Couldn't create InfiniBand device class\n"); + log(LOG_WARNING, "Couldn't create InfiniBand device class\n"); +#endif + mtx_init(&device_mutex, "rdma_device mutex", NULL, MTX_DUPOK|MTX_DEF); ret = ib_cache_setup(); if (ret) { - log(LOG_WARN, "Couldn't set up InfiniBand P_Key/GID cache\n"); + log(LOG_WARNING, "Couldn't set up InfiniBand P_Key/GID cache\n"); +#ifdef notyet ib_sysfs_cleanup(); +#endif } return ret; } -static void __exit ib_core_cleanup(void) +static void __exit rdma_core_cleanup(void) { ib_cache_cleanup(); +#ifdef notyet ib_sysfs_cleanup(); /* Make sure that any pending umem accounting work is done. */ flush_scheduled_work(); +#endif +} + +static int +rdma_core_load(module_t mod, int cmd, void *arg) +{ + int err = 0; + + switch (cmd) { + case MOD_LOAD: + printf("Loading iwcm.\n"); + + rdma_core_init(); + break; + case MOD_QUIESCE: + break; + case MOD_UNLOAD: + printf("Unloading iwcm.\n"); + rdma_core_cleanup(); + break; + case MOD_SHUTDOWN: + break; + default: + err = EOPNOTSUPP; + break; + } + + return (err); } -module_init(ib_core_init); -module_exit(ib_core_cleanup); +static moduledata_t mod_data = { + "rdma_core", + rdma_core_load, + 0 +}; + +MODULE_VERSION(rdma_core, 1); +DECLARE_MODULE(rdma_core, mod_data, SI_SUB_EXEC, SI_ORDER_ANY); ==== //depot/projects/iwarp/sys/modules/rdma/core/Makefile#2 (text+ko) ==== @@ -5,6 +5,8 @@ KMOD= rdma_core SRCS= device_if.h bus_if.h pci_if.h pcib_if.h -SRCS+= rdma_verbs.c rdma_device.c +SRCS+= rdma_device.c +#SRCS+= rdma_verbs.c +#SRCS+= rdma_cache.c .include <bsd.kmod.mk> ==== //depot/projects/iwarp/sys/sys/linux_compat.h#5 (text+ko) ==== @@ -178,6 +178,24 @@ atomic_clear_int(((volatile int *)p) + (b >> 5), 1 << (b & 0x1f)); } +static __inline int +find_first_zero_bit(volatile void *p, int max) +{ + int b; + volatile int *ptr = (volatile int *)p; + + for (b = 0; b < max; b += 32) { + if (ptr[b >> 5] != ~0) { + for (;;) { + if ((ptr[b >> 5] & (1 << (b & 0x1f))) == 0) + return b; + b++; + } + } + } + return max; +} + #define copy_from_user(a,b,c) copyin(b,a,c) #define copy_to_user(a,b,c) copyout(b,a,c) #define __user
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200711092108.lA9L8LQr033892>