Date: Fri, 9 Nov 2007 22:16:35 GMT From: Steve Wise <swise@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 128876 for review Message-ID: <200711092216.lA9MGZ3J037866@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=128876 Change 128876 by swise@swise:vic10:iwarp on 2007/11/09 22:16:24 rdma_cache.c compiles. Affected files ... .. //depot/projects/iwarp/sys/contrib/rdma/ib_verbs.h#4 edit .. //depot/projects/iwarp/sys/contrib/rdma/rdma_cache.c#2 edit .. //depot/projects/iwarp/sys/modules/rdma/core/Makefile#3 edit Differences ... ==== //depot/projects/iwarp/sys/contrib/rdma/ib_verbs.h#4 (text+ko) ==== @@ -296,7 +296,6 @@ do { \ (_ptr)->device = _device; \ (_ptr)->handler = _handler; \ - INIT_LIST_HEAD(&(_ptr)->list); \ } while (0) struct ib_global_route { @@ -827,7 +826,7 @@ #define IB_DEVICE_NAME_MAX 64 struct ib_cache { - rwlock_t lock; + struct mtx lock; struct ib_event_handler event_handler; struct ib_pkey_cache **pkey_cache; struct ib_gid_cache **gid_cache; ==== //depot/projects/iwarp/sys/contrib/rdma/rdma_cache.c#2 (text+ko) ==== @@ -35,12 +35,26 @@ * $Id: cache.c 1349 2004-12-16 21:09:43Z roland $ */ -#include <linux/module.h> -#include <linux/errno.h> -#include <linux/slab.h> -#include <linux/workqueue.h> +#include <sys/cdefs.h> +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/taskqueue.h> +#include <sys/lock.h> +#include <sys/rwlock.h> +#include <sys/mutex.h> +#include <sys/module.h> +#include <sys/syslog.h> + + +#ifdef needed +#include <sys/condvar.h> +#include <sys/socket.h> +#include <sys/linux_compat.h> +#include <sys/condvar.h> +#endif -#include <rdma/ib_cache.h> +#include <contrib/rdma/ib_cache.h> #include "core_priv.h" @@ -55,7 +69,7 @@ }; struct ib_update_work { - struct work_struct work; + struct task task; struct ib_device *device; u8 port_num; }; @@ -77,13 +91,12 @@ union ib_gid *gid) { struct ib_gid_cache *cache; - unsigned long flags; int ret = 0; if (port_num < start_port(device) || port_num > end_port(device)) return -EINVAL; - read_lock_irqsave(&device->cache.lock, flags); + mtx_lock_spin(&device->cache.lock); cache = device->cache.gid_cache[port_num - start_port(device)]; @@ -92,7 +105,7 @@ else *gid = cache->table[index]; - read_unlock_irqrestore(&device->cache.lock, flags); + mtx_unlock_spin(&device->cache.lock); return ret; } @@ -104,7 +117,6 @@ u16 *index) { struct ib_gid_cache *cache; - unsigned long flags; int p, i; int ret = -ENOENT; @@ -112,7 +124,7 @@ if (index) *index = -1; - read_lock_irqsave(&device->cache.lock, flags); + mtx_lock_spin(&device->cache.lock); for (p = 0; p <= end_port(device) - start_port(device); ++p) { cache = device->cache.gid_cache[p]; @@ -127,7 +139,7 @@ } } found: - read_unlock_irqrestore(&device->cache.lock, flags); + mtx_unlock_spin(&device->cache.lock); return ret; } @@ -139,13 +151,12 @@ u16 *pkey) { struct ib_pkey_cache *cache; - unsigned long flags; int ret = 0; if (port_num < start_port(device) || port_num > end_port(device)) return -EINVAL; - read_lock_irqsave(&device->cache.lock, flags); + mtx_lock_spin(&device->cache.lock); cache = device->cache.pkey_cache[port_num - start_port(device)]; @@ -154,7 +165,7 @@ else *pkey = cache->table[index]; - read_unlock_irqrestore(&device->cache.lock, flags); + mtx_unlock_spin(&device->cache.lock); return ret; } @@ -166,14 +177,13 @@ u16 *index) { struct ib_pkey_cache *cache; - unsigned long flags; int i; int ret = -ENOENT; if (port_num < start_port(device) || port_num > end_port(device)) return -EINVAL; - read_lock_irqsave(&device->cache.lock, flags); + mtx_lock_spin(&device->cache.lock); cache = device->cache.pkey_cache[port_num - start_port(device)]; @@ -186,7 +196,7 @@ break; } - read_unlock_irqrestore(&device->cache.lock, flags); + mtx_unlock_spin(&device->cache.lock); return ret; } @@ -196,15 +206,14 @@ u8 port_num, u8 *lmc) { - unsigned long flags; int ret = 0; if (port_num < start_port(device) || port_num > end_port(device)) return -EINVAL; - read_lock_irqsave(&device->cache.lock, flags); + mtx_lock_spin(&device->cache.lock); *lmc = device->cache.lmc_cache[port_num - start_port(device)]; - read_unlock_irqrestore(&device->cache.lock, flags); + mtx_unlock_spin(&device->cache.lock); return ret; } @@ -219,26 +228,26 @@ int i; int ret; - tprops = kmalloc(sizeof *tprops, GFP_KERNEL); + tprops = malloc(sizeof *tprops, M_DEVBUF, M_WAITOK); if (!tprops) return; ret = ib_query_port(device, port, tprops); if (ret) { - printk(KERN_WARNING "ib_query_port failed (%d) for %s\n", + log(LOG_WARNING, "ib_query_port failed (%d) for %s\n", ret, device->name); goto err; } - pkey_cache = kmalloc(sizeof *pkey_cache + tprops->pkey_tbl_len * - sizeof *pkey_cache->table, GFP_KERNEL); + pkey_cache = malloc(sizeof *pkey_cache + tprops->pkey_tbl_len * + sizeof *pkey_cache->table, M_DEVBUF, M_WAITOK); if (!pkey_cache) goto err; pkey_cache->table_len = tprops->pkey_tbl_len; - gid_cache = kmalloc(sizeof *gid_cache + tprops->gid_tbl_len * - sizeof *gid_cache->table, GFP_KERNEL); + gid_cache = malloc(sizeof *gid_cache + tprops->gid_tbl_len * + sizeof *gid_cache->table, M_DEVBUF, M_WAITOK); if (!gid_cache) goto err; @@ -247,7 +256,7 @@ for (i = 0; i < pkey_cache->table_len; ++i) { ret = ib_query_pkey(device, port, i, pkey_cache->table + i); if (ret) { - printk(KERN_WARNING "ib_query_pkey failed (%d) for %s (index %d)\n", + log(LOG_WARNING, "ib_query_pkey failed (%d) for %s (index %d)\n", ret, device->name, i); goto err; } @@ -256,13 +265,13 @@ for (i = 0; i < gid_cache->table_len; ++i) { ret = ib_query_gid(device, port, i, gid_cache->table + i); if (ret) { - printk(KERN_WARNING "ib_query_gid failed (%d) for %s (index %d)\n", + log(LOG_WARNING, "ib_query_gid failed (%d) for %s (index %d)\n", ret, device->name, i); goto err; } } - write_lock_irq(&device->cache.lock); + mtx_lock_spin(&device->cache.lock); old_pkey_cache = device->cache.pkey_cache[port - start_port(device)]; old_gid_cache = device->cache.gid_cache [port - start_port(device)]; @@ -272,26 +281,25 @@ device->cache.lmc_cache[port - start_port(device)] = tprops->lmc; - write_unlock_irq(&device->cache.lock); + mtx_unlock_spin(&device->cache.lock); - kfree(old_pkey_cache); - kfree(old_gid_cache); - kfree(tprops); + free(old_pkey_cache, M_DEVBUF); + free(old_gid_cache, M_DEVBUF); + free(tprops, M_DEVBUF); return; err: - kfree(pkey_cache); - kfree(gid_cache); - kfree(tprops); + free(pkey_cache, M_DEVBUF); + free(gid_cache, M_DEVBUF); + free(tprops, M_DEVBUF); } -static void ib_cache_task(struct work_struct *_work) +static void ib_cache_task(void *context, int pending) { - struct ib_update_work *work = - container_of(_work, struct ib_update_work, work); + struct ib_update_work *work = context; ib_cache_update(work->device, work->port_num); - kfree(work); + free(work, M_DEVBUF); } static void ib_cache_event(struct ib_event_handler *handler, @@ -305,12 +313,12 @@ event->event == IB_EVENT_PKEY_CHANGE || event->event == IB_EVENT_SM_CHANGE || event->event == IB_EVENT_CLIENT_REREGISTER) { - work = kmalloc(sizeof *work, GFP_ATOMIC); + work = malloc(sizeof *work, M_DEVBUF, M_WAITOK); if (work) { - INIT_WORK(&work->work, ib_cache_task); + TASK_INIT(&work->task, 0, ib_cache_task, work); work->device = event->device; work->port_num = event->element.port_num; - schedule_work(&work->work); + taskqueue_enqueue(taskqueue_thread, &work->task); } } } @@ -319,23 +327,26 @@ { int p; - rwlock_init(&device->cache.lock); + mtx_init(&device->cache.lock, "ib device cache", NULL, + MTX_DUPOK|MTX_SPIN); device->cache.pkey_cache = - kmalloc(sizeof *device->cache.pkey_cache * - (end_port(device) - start_port(device) + 1), GFP_KERNEL); + malloc(sizeof *device->cache.pkey_cache * + (end_port(device) - start_port(device) + 1), M_DEVBUF, + M_WAITOK); device->cache.gid_cache = - kmalloc(sizeof *device->cache.gid_cache * - (end_port(device) - start_port(device) + 1), GFP_KERNEL); + malloc(sizeof *device->cache.gid_cache * + (end_port(device) - start_port(device) + 1), M_DEVBUF, + M_WAITOK); - device->cache.lmc_cache = kmalloc(sizeof *device->cache.lmc_cache * + device->cache.lmc_cache = malloc(sizeof *device->cache.lmc_cache * (end_port(device) - - start_port(device) + 1), - GFP_KERNEL); + start_port(device) + 1), + M_DEVBUF, M_WAITOK); if (!device->cache.pkey_cache || !device->cache.gid_cache || !device->cache.lmc_cache) { - printk(KERN_WARNING "Couldn't allocate cache " + log(LOG_WARNING, "Couldn't allocate cache " "for %s\n", device->name); goto err; } @@ -355,14 +366,14 @@ err_cache: for (p = 0; p <= end_port(device) - start_port(device); ++p) { - kfree(device->cache.pkey_cache[p]); - kfree(device->cache.gid_cache[p]); + free(device->cache.pkey_cache[p], M_DEVBUF); + free(device->cache.gid_cache[p], M_DEVBUF); } err: - kfree(device->cache.pkey_cache); - kfree(device->cache.gid_cache); - kfree(device->cache.lmc_cache); + free(device->cache.pkey_cache, M_DEVBUF); + free(device->cache.gid_cache, M_DEVBUF); + free(device->cache.lmc_cache, M_DEVBUF); } static void ib_cache_cleanup_one(struct ib_device *device) @@ -370,16 +381,18 @@ int p; ib_unregister_event_handler(&device->cache.event_handler); +#ifdef XXX flush_scheduled_work(); +#endif for (p = 0; p <= end_port(device) - start_port(device); ++p) { - kfree(device->cache.pkey_cache[p]); - kfree(device->cache.gid_cache[p]); + free(device->cache.pkey_cache[p], M_DEVBUF); + free(device->cache.gid_cache[p], M_DEVBUF); } - kfree(device->cache.pkey_cache); - kfree(device->cache.gid_cache); - kfree(device->cache.lmc_cache); + free(device->cache.pkey_cache, M_DEVBUF); + free(device->cache.gid_cache, M_DEVBUF); + free(device->cache.lmc_cache, M_DEVBUF); } static struct ib_client cache_client = { ==== //depot/projects/iwarp/sys/modules/rdma/core/Makefile#3 (text+ko) ==== @@ -6,7 +6,7 @@ KMOD= rdma_core SRCS= device_if.h bus_if.h pci_if.h pcib_if.h SRCS+= rdma_device.c +SRCS+= rdma_cache.c #SRCS+= rdma_verbs.c -#SRCS+= rdma_cache.c .include <bsd.kmod.mk>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200711092216.lA9MGZ3J037866>