[openib-general] [PATCH] update to GID/PKey cache
Sean Hefty
mshefty at ichips.intel.com
Mon Jan 10 17:50:26 PST 2005
This patch adds a new call to find a port on a device given a GID.
It also adds documentation for the calls in ib_cache.h, and renames
the calls to better match the format of the core API routines.
(The CM needs the new routine even if the name changes are not
accepted.)
- Sean
Index: core/cache.c
===================================================================
--- core/cache.c (revision 1505)
+++ core/cache.c (working copy)
@@ -65,8 +65,8 @@
return device->node_type == IB_NODE_SWITCH ? 0 : device->phys_port_cnt;
}
-int ib_cached_gid_get(struct ib_device *device,
- u8 port,
+int ib_get_cached_gid(struct ib_device *device,
+ u8 port_num,
int index,
union ib_gid *gid)
{
@@ -74,12 +74,12 @@
unsigned long flags;
int ret = 0;
- if (port < start_port(device) || port > end_port(device))
+ if (port_num < start_port(device) || port_num > end_port(device))
return -EINVAL;
read_lock_irqsave(&device->cache.lock, flags);
- cache = device->cache.gid_cache[port - start_port(device)];
+ cache = device->cache.gid_cache[port_num - start_port(device)];
if (index < 0 || index >= cache->table_len)
ret = -EINVAL;
@@ -90,10 +90,45 @@
return ret;
}
-EXPORT_SYMBOL(ib_cached_gid_get);
+EXPORT_SYMBOL(ib_get_cached_gid);
-int ib_cached_pkey_get(struct ib_device *device,
- u8 port,
+int ib_find_cached_gid(struct ib_device *device,
+ union ib_gid *gid,
+ u8 *port_num,
+ u16 *index)
+{
+ struct ib_gid_cache *cache;
+ unsigned long flags;
+ int p, i;
+ int ret = -ENOENT;
+
+ *port_num = -1;
+ if (index)
+ *index = -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 = p;
+ if (index)
+ *index = i;
+ ret = 0;
+ goto found;
+ }
+ }
+ }
+found:
+ read_unlock_irqrestore(&device->cache.lock, flags);
+
+ return ret;
+}
+EXPORT_SYMBOL(ib_find_cached_gid);
+
+int ib_get_cached_pkey(struct ib_device *device,
+ u8 port_num,
int index,
u16 *pkey)
{
@@ -101,12 +136,12 @@
unsigned long flags;
int ret = 0;
- if (port < start_port(device) || port > end_port(device))
+ if (port_num < start_port(device) || port_num > end_port(device))
return -EINVAL;
read_lock_irqsave(&device->cache.lock, flags);
- cache = device->cache.pkey_cache[port - start_port(device)];
+ cache = device->cache.pkey_cache[port_num - start_port(device)];
if (index < 0 || index >= cache->table_len)
ret = -EINVAL;
@@ -117,10 +152,10 @@
return ret;
}
-EXPORT_SYMBOL(ib_cached_pkey_get);
+EXPORT_SYMBOL(ib_get_cached_pkey);
-int ib_cached_pkey_find(struct ib_device *device,
- u8 port,
+int ib_find_cached_pkey(struct ib_device *device,
+ u8 port_num,
u16 pkey,
u16 *index)
{
@@ -129,12 +164,12 @@
int i;
int ret = -ENOENT;
- if (port < start_port(device) || port > end_port(device))
+ if (port_num < start_port(device) || port_num > end_port(device))
return -EINVAL;
read_lock_irqsave(&device->cache.lock, flags);
- cache = device->cache.pkey_cache[port - start_port(device)];
+ cache = device->cache.pkey_cache[port_num - start_port(device)];
*index = -1;
@@ -149,7 +184,7 @@
return ret;
}
-EXPORT_SYMBOL(ib_cached_pkey_find);
+EXPORT_SYMBOL(ib_find_cached_pkey);
static void ib_cache_update(struct ib_device *device,
u8 port)
Index: include/ib_cache.h
===================================================================
--- include/ib_cache.h (revision 1505)
+++ include/ib_cache.h (working copy)
@@ -37,16 +37,66 @@
#include <ib_verbs.h>
-int ib_cached_gid_get(struct ib_device *device,
- u8 port,
+/**
+ * ib_get_cached_gid - Returns a cached GID table entry
+ * @device: The device to query.
+ * @port_num: The port number of the device to query.
+ * @index: The index into the cached GID table to query.
+ * @gid: The GID value found at the specified index.
+ *
+ * ib_get_cached_gid() fetches the specified GID table entry stored in
+ * the local software cache.
+ */
+int ib_get_cached_gid(struct ib_device *device,
+ u8 port_num,
int index,
union ib_gid *gid);
-int ib_cached_pkey_get(struct ib_device *device_handle,
- u8 port,
+
+/**
+ * ib_find_cached_gid - Returns the port number and GID table index where
+ * a specified GID value occurs.
+ * @device: The device to query.
+ * @gid: The GID value to search for.
+ * @port_num: The port number of the device where the GID value was found.
+ * @index: The index into the cached GID table where the GID was found. This
+ * parameter may be NULL.
+ *
+ * ib_find_cached_gid() searches for the specified GID value in
+ * the local software cache.
+ */
+int ib_find_cached_gid(struct ib_device *device,
+ union ib_gid *gid,
+ u8 *port_num,
+ u16 *index);
+
+/**
+ * ib_get_cached_pkey - Returns a cached PKey table entry
+ * @device: The device to query.
+ * @port_num: The port number of the device to query.
+ * @index: The index into the cached PKey table to query.
+ * @pkey: The PKey value found at the specified index.
+ *
+ * ib_get_cached_pkey() fetches the specified PKey table entry stored in
+ * the local software cache.
+ */
+int ib_get_cached_pkey(struct ib_device *device_handle,
+ u8 port_num,
int index,
u16 *pkey);
-int ib_cached_pkey_find(struct ib_device *device,
- u8 port,
+
+/**
+ * ib_find_cached_pkey - Returns the PKey table index where a specified
+ * PKey value occurs.
+ * @device: The device to query.
+ * @port_num: The port number of the device to search for the PKey.
+ * @pkey: The PKey value to search for.
+ * @index: The index into the cached PKey table where the PKey was found.
+ *
+ * ib_find_cached_pkey() searches the specified PKey table in
+ * the local software cache.
+ */
+int ib_find_cached_pkey(struct ib_device *device,
+ u8 port_num,
u16 pkey,
u16 *index);
Index: hw/mthca/mthca_av.c
===================================================================
--- hw/mthca/mthca_av.c (revision 1505)
+++ hw/mthca/mthca_av.c (working copy)
@@ -159,7 +159,7 @@
(be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 20) & 0xff;
header->grh.flow_label =
ah->av->sl_tclass_flowlabel & cpu_to_be32(0xfffff);
- ib_cached_gid_get(&dev->ib_dev,
+ ib_get_cached_gid(&dev->ib_dev,
be32_to_cpu(ah->av->port_pd) >> 24,
ah->av->gid_index,
&header->grh.source_gid);
Index: hw/mthca/mthca_qp.c
===================================================================
--- hw/mthca/mthca_qp.c (revision 1505)
+++ hw/mthca/mthca_qp.c (working copy)
@@ -1190,11 +1190,11 @@
sqp->ud_header.lrh.source_lid = 0xffff;
sqp->ud_header.bth.solicited_event = !!(wr->send_flags & IB_SEND_SOLICITED);
if (!sqp->qp.ibqp.qp_num)
- ib_cached_pkey_get(&dev->ib_dev, sqp->port,
+ ib_get_cached_pkey(&dev->ib_dev, sqp->port,
sqp->pkey_index,
&sqp->ud_header.bth.pkey);
else
- ib_cached_pkey_get(&dev->ib_dev, sqp->port,
+ ib_get_cached_pkey(&dev->ib_dev, sqp->port,
wr->wr.ud.pkey_index,
&sqp->ud_header.bth.pkey);
cpu_to_be16s(&sqp->ud_header.bth.pkey);
Index: ulp/ipoib/ipoib_verbs.c
===================================================================
--- ulp/ipoib/ipoib_verbs.c (revision 1505)
+++ ulp/ipoib/ipoib_verbs.c (working copy)
@@ -49,7 +49,7 @@
if (!qp_attr)
goto out;
- if (ib_cached_pkey_find(priv->ca, priv->port, priv->pkey, &pkey_index)) {
+ if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index)) {
clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
ret = -ENXIO;
goto out;
@@ -104,7 +104,7 @@
* The port has to be assigned to the respective IB partition in
* advance.
*/
- ret = ib_cached_pkey_find(priv->ca, priv->port, priv->pkey, &pkey_index);
+ ret = ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index);
if (ret) {
clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
return ret;
Index: ulp/ipoib/ipoib_ib.c
===================================================================
--- ulp/ipoib/ipoib_ib.c (revision 1505)
+++ ulp/ipoib/ipoib_ib.c (working copy)
@@ -630,7 +630,7 @@
struct ipoib_dev_priv *priv = netdev_priv(dev);
u16 pkey_index = 0;
- if (ib_cached_pkey_find(priv->ca, priv->port, priv->pkey, &pkey_index))
+ if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index))
clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
else
set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
More information about the general
mailing list