--- /dev/null
+/*\r
+ * Copyright (c) 2009 Intel Corp., Inc.\r
+ *\r
+ * This software is available to you under a choice of one of two\r
+ * licenses. You may choose to be licensed under the terms of the GNU\r
+ * General Public License (GPL) Version 2, available from the file\r
+ * COPYING in the main directory of this source tree, or the\r
+ * OpenIB.org BSD license below:\r
+ *\r
+ * Redistribution and use in source and binary forms, with or\r
+ * without modification, are permitted provided that the following\r
+ * conditions are met:\r
+ *\r
+ * - Redistributions of source code must retain the above\r
+ * copyright notice, this list of conditions and the following\r
+ * disclaimer.\r
+ *\r
+ * - Redistributions in binary form must reproduce the above\r
+ * copyright notice, this list of conditions and the following\r
+ * disclaimer in the documentation and/or other materials\r
+ * provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ *\r
+ */\r
+\r
+#include <stdlib.h>\r
+#include <search.h>\r
+\r
+static int (*compare)(const void *, const void *);\r
+\r
+static intn_t fcompare(const void * const key1, const void * const key2)\r
+{\r
+ return (intn_t) compare((void *) key1, (void *) key2);\r
+}\r
+\r
+void *tsearch(const void *key, void **rootp,\r
+ int (*compar)(const void *, const void *))\r
+{\r
+ cl_fmap_item_t *item, *map_item;\r
+\r
+ if (!*rootp) {\r
+ *rootp = malloc(sizeof(cl_fmap_t));\r
+ cl_fmap_init((cl_fmap_t *) *rootp, fcompare);\r
+ }\r
+\r
+ compare = compar;\r
+ item = malloc(sizeof(cl_fmap_item_t));\r
+ map_item = cl_fmap_insert((cl_fmap_t *) *rootp, key, item);\r
+ if (map_item != item) {\r
+ free(item);\r
+ return (void *) map_item->p_key;\r
+ }\r
+\r
+ return (void *) key;\r
+}\r
+\r
+void *tfind(const void *key, void *const *rootp,\r
+ int (*compar)(const void *, const void *))\r
+{\r
+ cl_fmap_item_t *item;\r
+\r
+ if (!*rootp)\r
+ return NULL;\r
+\r
+ compare = compar;\r
+ item = cl_fmap_get((cl_fmap_t *) *rootp, key);\r
+ if (item == cl_fmap_end((cl_fmap_t *) *rootp))\r
+ return NULL;\r
+\r
+ return (void *) item->p_key;\r
+}\r
+\r
+void *tdelete(const void *key, void **rootp,\r
+ int (*compar)(const void *, const void *))\r
+{\r
+ cl_fmap_item_t *item;\r
+ void *map_key;\r
+\r
+ if (!*rootp)\r
+ return NULL;\r
+\r
+ compare = compar;\r
+ item = cl_fmap_remove((cl_fmap_t *) *rootp, key);\r
+ if (item == cl_fmap_end((cl_fmap_t *) *rootp))\r
+ return NULL;\r
+\r
+ map_key = (void *) item->p_key;\r
+ free(item);\r
+ return map_key;\r
+}\r
+\r
+//void twalk(const void *root,\r
+// void (*action)(const void *, VISIT, int))\r
+//{\r
+//}\r
+\r
+//void tdestroy(void *root, void (*free_node)(void *nodep))\r
+//{\r
+//}\r
int index,
union ib_gid *gid)
{
+ union ib_gid cgid;
struct ib_gid_cache *cache;
unsigned long flags;
- int ret = 0;
if (mlx4_is_barred(device->dma_device))
return -EFAULT;
cache = device->cache.gid_cache[port_num - start_port(device)];
- if (index < 0 || index >= cache->table_len)
- ret = -EINVAL;
- else
- *gid = cache->table[index];
-
+ if (index < 0 || index >= cache->table_len) {
+ read_unlock_irqrestore(&device->cache.lock, flags);
+ return -EINVAL;
+ }
+
+ cgid = cache->table[index];
read_unlock_irqrestore(&device->cache.lock, flags);
+ *gid = cgid;
- return ret;
+ return 0;
}
EXPORT_SYMBOL(ib_get_cached_gid);
struct ib_gid_cache *cache;
unsigned long flags;
int p, i;
- int ret = -ENOENT;
if (mlx4_is_barred(device->dma_device))
return -EFAULT;
- *port_num = (u8)-1;
- if (index)
- *index = (u16)-1;
-
read_lock_irqsave(&device->cache.lock, &flags);
for (p = 0; p <= end_port(device) - start_port(device); ++p) {
cache = device->cache.gid_cache[p];
for (i = 0; i < cache->table_len; ++i) {
if (!memcmp(gid, &cache->table[i], sizeof *gid)) {
- *port_num = (u8)(p + start_port(device));
- if (index)
- *index = (u16)i;
- ret = 0;
goto found;
}
}
}
+
+ read_unlock_irqrestore(&device->cache.lock, flags);
+ *port_num = (u8)-1;
+ if (index)
+ *index = (u16)-1;
+ return -ENOENT;
+
found:
read_unlock_irqrestore(&device->cache.lock, flags);
+ *port_num = (u8)(p + start_port(device));
+ if (index)
+ *index = (u16)i;
- return ret;
+ return 0;
}
EXPORT_SYMBOL(ib_find_cached_gid);
__be16 *pkey)
{
struct ib_pkey_cache *cache;
+ __be16 cpkey;
unsigned long flags;
- int ret = 0;
if (mlx4_is_barred(device->dma_device))
return -EFAULT;
cache = device->cache.pkey_cache[port_num - start_port(device)];
- if (index < 0 || index >= cache->table_len)
- ret = -EINVAL;
- else
- *pkey = cache->table[index];
+ if (index < 0 || index >= cache->table_len) {
+ read_unlock_irqrestore(&device->cache.lock, flags);
+ return -EINVAL;
+ }
+ cpkey = cache->table[index];
read_unlock_irqrestore(&device->cache.lock, flags);
+ *pkey = cpkey;
- return ret;
+ return 0;
}
EXPORT_SYMBOL(ib_get_cached_pkey);
struct ib_pkey_cache *cache;
unsigned long flags;
int i;
- int ret = -ENOENT;
if (mlx4_is_barred(device->dma_device))
return -EFAULT;
for (i = 0; i < cache->table_len; ++i)
if ((cache->table[i] & 0x7fff) == (pkey & 0x7fff)) {
- *index = (u16)i;
- ret = 0;
- break;
+ goto found;
}
read_unlock_irqrestore(&device->cache.lock, flags);
+ *index = (u16)-1;
+ return -ENOENT;
- return ret;
+found:
+ read_unlock_irqrestore(&device->cache.lock, flags);
+ *index = (u16)i;
+ return 0;
}
EXPORT_SYMBOL(ib_find_cached_pkey);
u8 *lmc)
{
unsigned long flags;
+ u8 clmc;
int ret = 0;
if (port_num < start_port(device) || port_num > end_port(device))
return -EINVAL;
read_lock_irqsave(&device->cache.lock, &flags);
- *lmc = device->cache.lmc_cache[port_num - start_port(device)];
+ clmc = device->cache.lmc_cache[port_num - start_port(device)];
read_unlock_irqrestore(&device->cache.lock, flags);
+ *lmc = clmc;
return ret;
}
int index,
union ib_gid *gid)
{
+ union ib_gid cgid;
struct ib_gid_cache *cache;
- int ret = 0;
SPIN_LOCK_PREP(lh);
// sanity checks
cache = device->cache.gid_cache[port_num - start_port(device)];
- if (index < 0 || index >= cache->table_len)
- ret = -EINVAL;
- else
- *gid = cache->table[index];
+ if (index < 0 || index >= cache->table_len) {
+ read_unlock_irqrestore(&lh);
+ return -EINVAL;
+ }
+ cgid = cache->table[index];
read_unlock_irqrestore(&lh);
+ *gid = cgid;
- return ret;
+ return 0;
}
int ib_find_cached_gid(struct ib_device *device,
struct ib_gid_cache *cache;
int i;
u8 p;
- int ret = -ENOENT;
SPIN_LOCK_PREP(lh);
- *port_num = (u8)-1;
- if (index)
- *index = (u16)-1;
-
read_lock_irqsave(&device->cache.lock, &lh);
for (p = 0; p <= end_port(device) - start_port(device); ++p) {
cache = device->cache.gid_cache[p];
for (i = 0; i < cache->table_len; ++i) {
if (!memcmp(gid, &cache->table[i], sizeof *gid)) {
- *port_num = p + start_port(device);
- if (index)
- *index = (u16)i;
- ret = 0;
goto found;
}
}
}
+
+ read_unlock_irqrestore(&lh);
+ *port_num = (u8)-1;
+ if (index)
+ *index = (u16)-1;
+ return -ENOENT;
+
found:
read_unlock_irqrestore(&lh);
+ *port_num = p + start_port(device);
+ if (index)
+ *index = (u16)i;
- return ret;
+ return 0;
}
int ib_get_cached_pkey(struct ib_device *device,
__be16 *pkey)
{
struct ib_pkey_cache *cache;
- int ret = 0;
+ __be16 cpkey;
SPIN_LOCK_PREP(lh);
// sanity checks
cache = device->cache.pkey_cache[port_num - start_port(device)];
- if (index < 0 || index >= cache->table_len)
- ret = -EINVAL;
- else
- *pkey = cache->table[index];
+ if (index < 0 || index >= cache->table_len) {
+ read_unlock_irqrestore(&lh);
+ return -EINVAL;
+ }
+ cpkey = cache->table[index];
read_unlock_irqrestore(&lh);
+ *pkey = cpkey;
- return ret;
+ return 0;
}
int ib_find_cached_pkey(struct ib_device *device,
{
struct ib_pkey_cache *cache;
int i;
- int ret = -ENOENT;
SPIN_LOCK_PREP(lh);
if (port_num < start_port(device) || port_num > end_port(device))
cache = device->cache.pkey_cache[port_num - start_port(device)];
- *index = (u16)-1;
-
for (i = 0; i < cache->table_len; ++i)
if ((cache->table[i] & 0x7fff) == (pkey & 0x7fff)) {
- *index = (u16)i;
- ret = 0;
- break;
+ goto found;
}
read_unlock_irqrestore(&lh);
+ *index = (u16)-1;
+ return -ENOENT;
- return ret;
+found:
+ read_unlock_irqrestore(&lh);
+ *index = (u16)i;
+ return 0;
}
static void ib_cache_update(struct ib_device *device,
--- /dev/null
+/*\r
+ * Copyright (c) 2009 Intel Corp, Inc. All rights reserved.\r
+ *\r
+ * This software is available to you under a choice of one of two\r
+ * licenses. You may choose to be licensed under the terms of the GNU\r
+ * General Public License (GPL) Version 2, available from the file\r
+ * COPYING in the main directory of this source tree, or the\r
+ * OpenIB.org BSD license below:\r
+ *\r
+ * Redistribution and use in source and binary forms, with or\r
+ * without modification, are permitted provided that the following\r
+ * conditions are met:\r
+ *\r
+ * - Redistributions of source code must retain the above\r
+ * copyright notice, this list of conditions and the following\r
+ * disclaimer.\r
+ *\r
+ * - Redistributions in binary form must reproduce the above\r
+ * copyright notice, this list of conditions and the following\r
+ * disclaimer in the documentation and/or other materials\r
+ * provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ *\r
+ */\r
+\r
+#ifndef _SEARCH_H_\r
+#define _SEARCH_H_\r
+\r
+#include <complib/cl_fleximap.h>\r
+\r
+//typedef enum\r
+//{\r
+// preorder,\r
+// postorder,\r
+// endorder,\r
+// leaf\r
+//\r
+//} VISIT;\r
+\r
+void *tsearch(const void *key, void **rootp,\r
+ int (*compar)(const void *, const void *));\r
+void *tfind(const void *key, void *const *rootp,\r
+ int (*compar)(const void *, const void *));\r
+/* tdelete returns key if found (not parent), otherwise NULL */\r
+void *tdelete(const void *key, void **rootp,\r
+ int (*compar)(const void *, const void *));\r
+//void twalk(const void *root,\r
+// void (*action)(const void *, VISIT, int));\r
+//void tdestroy(void *root, void (*free_node)(void *nodep));\r
+\r
+#endif /* _SEARCH_H_ */\r
--- /dev/null
+/*\r
+ * This software is available to you under the OpenFabrics.org BSD license\r
+ * below:\r
+ *\r
+ * Redistribution and use in source and binary forms, with or\r
+ * without modification, are permitted provided that the following\r
+ * conditions are met:\r
+ *\r
+ * - Redistributions of source code must retain the above\r
+ * copyright notice, this list of conditions and the following\r
+ * disclaimer.\r
+ *\r
+ * - Redistributions in binary form must reproduce the above\r
+ * copyright notice, this list of conditions and the following\r
+ * disclaimer in the documentation and/or other materials\r
+ * provided with the distribution.\r
+ *\r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+ * SOFTWARE.\r
+ */\r
+\r
+#ifndef _SOCKET_H_\r
+#define _SOCKET_H_\r
+\r
+#include <winsock2.h>\r
+\r
+#endif\r