Commit 246b4c10 authored by Roland Dreier's avatar Roland Dreier Committed by Linus Torvalds

[PATCH] InfiniBand/core: add ib_find_cached_gid function

Add a new function to find a port on a device given a GID by searching the
cached GID tables.  Document all cache functions in ib_cache.h.  Rename
existing functions to better match format of verb routines.

Signed-off by: Sean Hefty <sean.hefty@intel.com>
Signed-off-by: default avatarRoland Dreier <roland@topspin.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 76e696e0
......@@ -65,8 +65,8 @@ static inline int end_port(struct ib_device *device)
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 @@ int ib_cached_gid_get(struct ib_device *device,
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 @@ int ib_cached_gid_get(struct ib_device *device,
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 @@ int ib_cached_pkey_get(struct ib_device *device,
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 @@ int ib_cached_pkey_get(struct ib_device *device,
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 ib_cached_pkey_find(struct ib_device *device,
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 @@ int ib_cached_pkey_find(struct ib_device *device,
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)
......
......@@ -159,7 +159,7 @@ int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
(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);
......
......@@ -1190,11 +1190,11 @@ static int build_mlx_header(struct mthca_dev *dev, struct mthca_sqp *sqp,
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);
......
......@@ -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);
......
......@@ -630,7 +630,7 @@ static void ipoib_pkey_dev_check_presence(struct net_device *dev)
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);
......
......@@ -49,7 +49,7 @@ int ipoib_mcast_attach(struct net_device *dev, u16 mlid, union ib_gid *mgid)
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 @@ int ipoib_qp_create(struct net_device *dev)
* 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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment