Commit 401b4480 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Jason Gunthorpe

cxgb4: Convert stid_idr to XArray

Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
Acked-by: default avatarSteve Wise <swise@opengridcomputing.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 9f5a9632
...@@ -375,11 +375,11 @@ static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev, ...@@ -375,11 +375,11 @@ static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev,
struct c4iw_listen_ep *ep; struct c4iw_listen_ep *ep;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&dev->lock, flags); xa_lock_irqsave(&dev->stids, flags);
ep = idr_find(&dev->stid_idr, stid); ep = xa_load(&dev->stids, stid);
if (ep) if (ep)
c4iw_get_ep(&ep->com); c4iw_get_ep(&ep->com);
spin_unlock_irqrestore(&dev->lock, flags); xa_unlock_irqrestore(&dev->stids, flags);
return ep; return ep;
} }
...@@ -3561,7 +3561,9 @@ int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog) ...@@ -3561,7 +3561,9 @@ int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
err = -ENOMEM; err = -ENOMEM;
goto fail2; goto fail2;
} }
insert_handle(dev, &dev->stid_idr, ep, ep->stid); err = xa_insert_irq(&dev->stids, ep->stid, ep, GFP_KERNEL);
if (err)
goto fail3;
state_set(&ep->com, LISTEN); state_set(&ep->com, LISTEN);
if (ep->com.local_addr.ss_family == AF_INET) if (ep->com.local_addr.ss_family == AF_INET)
...@@ -3572,7 +3574,8 @@ int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog) ...@@ -3572,7 +3574,8 @@ int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
cm_id->provider_data = ep; cm_id->provider_data = ep;
goto out; goto out;
} }
remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid); xa_erase_irq(&ep->com.dev->stids, ep->stid);
fail3:
cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
ep->com.local_addr.ss_family); ep->com.local_addr.ss_family);
fail2: fail2:
...@@ -3611,7 +3614,7 @@ int c4iw_destroy_listen(struct iw_cm_id *cm_id) ...@@ -3611,7 +3614,7 @@ int c4iw_destroy_listen(struct iw_cm_id *cm_id)
cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0], cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
(const u32 *)&sin6->sin6_addr.s6_addr, 1); (const u32 *)&sin6->sin6_addr.s6_addr, 1);
} }
remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid); xa_erase_irq(&ep->com.dev->stids, ep->stid);
cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
ep->com.local_addr.ss_family); ep->com.local_addr.ss_family);
done: done:
......
...@@ -81,14 +81,6 @@ struct c4iw_debugfs_data { ...@@ -81,14 +81,6 @@ struct c4iw_debugfs_data {
int pos; int pos;
}; };
static int count_idrs(int id, void *p, void *data)
{
int *countp = data;
*countp = *countp + 1;
return 0;
}
static ssize_t debugfs_read(struct file *file, char __user *buf, size_t count, static ssize_t debugfs_read(struct file *file, char __user *buf, size_t count,
loff_t *ppos) loff_t *ppos)
{ {
...@@ -617,10 +609,9 @@ static int dump_ep(struct c4iw_ep *ep, struct c4iw_debugfs_data *epd) ...@@ -617,10 +609,9 @@ static int dump_ep(struct c4iw_ep *ep, struct c4iw_debugfs_data *epd)
return 0; return 0;
} }
static int dump_listen_ep(int id, void *p, void *data) static
int dump_listen_ep(struct c4iw_listen_ep *ep, struct c4iw_debugfs_data *epd)
{ {
struct c4iw_listen_ep *ep = p;
struct c4iw_debugfs_data *epd = data;
int space; int space;
int cc; int cc;
...@@ -675,6 +666,7 @@ static int ep_release(struct inode *inode, struct file *file) ...@@ -675,6 +666,7 @@ static int ep_release(struct inode *inode, struct file *file)
static int ep_open(struct inode *inode, struct file *file) static int ep_open(struct inode *inode, struct file *file)
{ {
struct c4iw_ep *ep; struct c4iw_ep *ep;
struct c4iw_listen_ep *lep;
unsigned long index; unsigned long index;
struct c4iw_debugfs_data *epd; struct c4iw_debugfs_data *epd;
int ret = 0; int ret = 0;
...@@ -692,9 +684,8 @@ static int ep_open(struct inode *inode, struct file *file) ...@@ -692,9 +684,8 @@ static int ep_open(struct inode *inode, struct file *file)
count++; count++;
xa_for_each(&epd->devp->atids, index, ep) xa_for_each(&epd->devp->atids, index, ep)
count++; count++;
spin_lock_irq(&epd->devp->lock); xa_for_each(&epd->devp->stids, index, lep)
idr_for_each(&epd->devp->stid_idr, count_idrs, &count); count++;
spin_unlock_irq(&epd->devp->lock);
epd->bufsize = count * 240; epd->bufsize = count * 240;
epd->buf = vmalloc(epd->bufsize); epd->buf = vmalloc(epd->bufsize);
...@@ -711,9 +702,10 @@ static int ep_open(struct inode *inode, struct file *file) ...@@ -711,9 +702,10 @@ static int ep_open(struct inode *inode, struct file *file)
xa_for_each(&epd->devp->atids, index, ep) xa_for_each(&epd->devp->atids, index, ep)
dump_ep(ep, epd); dump_ep(ep, epd);
xa_unlock_irq(&epd->devp->atids); xa_unlock_irq(&epd->devp->atids);
spin_lock_irq(&epd->devp->lock); xa_lock_irq(&epd->devp->stids);
idr_for_each(&epd->devp->stid_idr, dump_listen_ep, epd); xa_for_each(&epd->devp->stids, index, lep)
spin_unlock_irq(&epd->devp->lock); dump_listen_ep(lep, epd);
xa_unlock_irq(&epd->devp->stids);
file->private_data = epd; file->private_data = epd;
goto out; goto out;
...@@ -945,7 +937,7 @@ void c4iw_dealloc(struct uld_ctx *ctx) ...@@ -945,7 +937,7 @@ void c4iw_dealloc(struct uld_ctx *ctx)
WARN_ON(!xa_empty(&ctx->dev->qps)); WARN_ON(!xa_empty(&ctx->dev->qps));
WARN_ON(!xa_empty(&ctx->dev->mrs)); WARN_ON(!xa_empty(&ctx->dev->mrs));
wait_event(ctx->dev->wait, xa_empty(&ctx->dev->hwtids)); wait_event(ctx->dev->wait, xa_empty(&ctx->dev->hwtids));
idr_destroy(&ctx->dev->stid_idr); WARN_ON(!xa_empty(&ctx->dev->stids));
WARN_ON(!xa_empty(&ctx->dev->atids)); WARN_ON(!xa_empty(&ctx->dev->atids));
if (ctx->dev->rdev.bar2_kva) if (ctx->dev->rdev.bar2_kva)
iounmap(ctx->dev->rdev.bar2_kva); iounmap(ctx->dev->rdev.bar2_kva);
...@@ -1055,8 +1047,7 @@ static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop) ...@@ -1055,8 +1047,7 @@ static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop)
xa_init_flags(&devp->mrs, XA_FLAGS_LOCK_IRQ); xa_init_flags(&devp->mrs, XA_FLAGS_LOCK_IRQ);
xa_init_flags(&devp->hwtids, XA_FLAGS_LOCK_IRQ); xa_init_flags(&devp->hwtids, XA_FLAGS_LOCK_IRQ);
xa_init_flags(&devp->atids, XA_FLAGS_LOCK_IRQ); xa_init_flags(&devp->atids, XA_FLAGS_LOCK_IRQ);
idr_init(&devp->stid_idr); xa_init_flags(&devp->stids, XA_FLAGS_LOCK_IRQ);
spin_lock_init(&devp->lock);
mutex_init(&devp->rdev.stats.lock); mutex_init(&devp->rdev.stats.lock);
mutex_init(&devp->db_mutex); mutex_init(&devp->db_mutex);
INIT_LIST_HEAD(&devp->db_fc_list); INIT_LIST_HEAD(&devp->db_fc_list);
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/idr.h> #include <linux/xarray.h>
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/sched/mm.h> #include <linux/sched/mm.h>
...@@ -318,13 +318,12 @@ struct c4iw_dev { ...@@ -318,13 +318,12 @@ struct c4iw_dev {
struct xarray cqs; struct xarray cqs;
struct xarray qps; struct xarray qps;
struct xarray mrs; struct xarray mrs;
spinlock_t lock;
struct mutex db_mutex; struct mutex db_mutex;
struct dentry *debugfs_root; struct dentry *debugfs_root;
enum db_state db_state; enum db_state db_state;
struct xarray hwtids; struct xarray hwtids;
struct xarray atids; struct xarray atids;
struct idr stid_idr; struct xarray stids;
struct list_head db_fc_list; struct list_head db_fc_list;
u32 avail_ird; u32 avail_ird;
wait_queue_head_t wait; wait_queue_head_t wait;
...@@ -357,60 +356,6 @@ static inline struct c4iw_qp *get_qhp(struct c4iw_dev *rhp, u32 qpid) ...@@ -357,60 +356,6 @@ static inline struct c4iw_qp *get_qhp(struct c4iw_dev *rhp, u32 qpid)
return xa_load(&rhp->qps, qpid); return xa_load(&rhp->qps, qpid);
} }
static inline int _insert_handle(struct c4iw_dev *rhp, struct idr *idr,
void *handle, u32 id, int lock)
{
int ret;
if (lock) {
idr_preload(GFP_KERNEL);
spin_lock_irq(&rhp->lock);
}
ret = idr_alloc(idr, handle, id, id + 1, GFP_ATOMIC);
if (lock) {
spin_unlock_irq(&rhp->lock);
idr_preload_end();
}
return ret < 0 ? ret : 0;
}
static inline int insert_handle(struct c4iw_dev *rhp, struct idr *idr,
void *handle, u32 id)
{
return _insert_handle(rhp, idr, handle, id, 1);
}
static inline int insert_handle_nolock(struct c4iw_dev *rhp, struct idr *idr,
void *handle, u32 id)
{
return _insert_handle(rhp, idr, handle, id, 0);
}
static inline void _remove_handle(struct c4iw_dev *rhp, struct idr *idr,
u32 id, int lock)
{
if (lock)
spin_lock_irq(&rhp->lock);
idr_remove(idr, id);
if (lock)
spin_unlock_irq(&rhp->lock);
}
static inline void remove_handle(struct c4iw_dev *rhp, struct idr *idr, u32 id)
{
_remove_handle(rhp, idr, id, 1);
}
static inline void remove_handle_nolock(struct c4iw_dev *rhp,
struct idr *idr, u32 id)
{
_remove_handle(rhp, idr, id, 0);
}
extern uint c4iw_max_read_depth; extern uint c4iw_max_read_depth;
static inline int cur_max_read_depth(struct c4iw_dev *dev) static inline int cur_max_read_depth(struct c4iw_dev *dev)
......
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