From: Roland Dreier 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 Signed-off-by: Roland Dreier Signed-off-by: Andrew Morton --- 25-akpm/drivers/infiniband/core/cache.c | 65 ++++++++++++++++----- 25-akpm/drivers/infiniband/hw/mthca/mthca_av.c | 2 25-akpm/drivers/infiniband/hw/mthca/mthca_qp.c | 4 - 25-akpm/drivers/infiniband/include/ib_cache.h | 62 ++++++++++++++++++-- 25-akpm/drivers/infiniband/ulp/ipoib/ipoib_ib.c | 2 25-akpm/drivers/infiniband/ulp/ipoib/ipoib_verbs.c | 4 - 6 files changed, 112 insertions(+), 27 deletions(-) diff -puN drivers/infiniband/core/cache.c~infiniband-core-add-ib_find_cached_gid-function drivers/infiniband/core/cache.c --- 25/drivers/infiniband/core/cache.c~infiniband-core-add-ib_find_cached_gid-function Wed Jan 12 16:32:00 2005 +++ 25-akpm/drivers/infiniband/core/cache.c Wed Jan 12 16:32:00 2005 @@ -65,8 +65,8 @@ static inline int end_port(struct ib_dev 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 * 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 * 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 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 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 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 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) diff -puN drivers/infiniband/hw/mthca/mthca_av.c~infiniband-core-add-ib_find_cached_gid-function drivers/infiniband/hw/mthca/mthca_av.c --- 25/drivers/infiniband/hw/mthca/mthca_av.c~infiniband-core-add-ib_find_cached_gid-function Wed Jan 12 16:32:00 2005 +++ 25-akpm/drivers/infiniband/hw/mthca/mthca_av.c Wed Jan 12 16:32:00 2005 @@ -159,7 +159,7 @@ int mthca_read_ah(struct mthca_dev *dev, (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); diff -puN drivers/infiniband/hw/mthca/mthca_qp.c~infiniband-core-add-ib_find_cached_gid-function drivers/infiniband/hw/mthca/mthca_qp.c --- 25/drivers/infiniband/hw/mthca/mthca_qp.c~infiniband-core-add-ib_find_cached_gid-function Wed Jan 12 16:32:00 2005 +++ 25-akpm/drivers/infiniband/hw/mthca/mthca_qp.c Wed Jan 12 16:32:00 2005 @@ -1190,11 +1190,11 @@ static int build_mlx_header(struct mthca 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); diff -puN drivers/infiniband/include/ib_cache.h~infiniband-core-add-ib_find_cached_gid-function drivers/infiniband/include/ib_cache.h --- 25/drivers/infiniband/include/ib_cache.h~infiniband-core-add-ib_find_cached_gid-function Wed Jan 12 16:32:00 2005 +++ 25-akpm/drivers/infiniband/include/ib_cache.h Wed Jan 12 16:32:00 2005 @@ -37,16 +37,66 @@ #include -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); diff -puN drivers/infiniband/ulp/ipoib/ipoib_ib.c~infiniband-core-add-ib_find_cached_gid-function drivers/infiniband/ulp/ipoib/ipoib_ib.c --- 25/drivers/infiniband/ulp/ipoib/ipoib_ib.c~infiniband-core-add-ib_find_cached_gid-function Wed Jan 12 16:32:00 2005 +++ 25-akpm/drivers/infiniband/ulp/ipoib/ipoib_ib.c Wed Jan 12 16:32:00 2005 @@ -630,7 +630,7 @@ static void ipoib_pkey_dev_check_presenc 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); diff -puN drivers/infiniband/ulp/ipoib/ipoib_verbs.c~infiniband-core-add-ib_find_cached_gid-function drivers/infiniband/ulp/ipoib/ipoib_verbs.c --- 25/drivers/infiniband/ulp/ipoib/ipoib_verbs.c~infiniband-core-add-ib_find_cached_gid-function Wed Jan 12 16:32:00 2005 +++ 25-akpm/drivers/infiniband/ulp/ipoib/ipoib_verbs.c Wed Jan 12 16:32:00 2005 @@ -49,7 +49,7 @@ int ipoib_mcast_attach(struct net_device 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 *d * 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; _