mirror of
https://github.com/adulau/aha.git
synced 2025-01-04 07:03:38 +00:00
IB/mthca: Semaphore to mutex conversions
Convert semaphores to mutexes in mthca. Leave firmware command interface poll_sem and event_sem as semaphores. Signed-off-by: Roland Dreier <rolandd@cisco.com>
This commit is contained in:
parent
e3aa31c517
commit
fd9cfdd11b
6 changed files with 37 additions and 36 deletions
|
@ -199,7 +199,7 @@ static int mthca_cmd_post(struct mthca_dev *dev,
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
down(&dev->cmd.hcr_sem);
|
mutex_lock(&dev->cmd.hcr_mutex);
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
unsigned long end = jiffies + GO_BIT_TIMEOUT;
|
unsigned long end = jiffies + GO_BIT_TIMEOUT;
|
||||||
|
@ -237,7 +237,7 @@ static int mthca_cmd_post(struct mthca_dev *dev,
|
||||||
op), dev->hcr + 6 * 4);
|
op), dev->hcr + 6 * 4);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
up(&dev->cmd.hcr_sem);
|
mutex_unlock(&dev->cmd.hcr_mutex);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,7 +435,7 @@ static int mthca_cmd_imm(struct mthca_dev *dev,
|
||||||
|
|
||||||
int mthca_cmd_init(struct mthca_dev *dev)
|
int mthca_cmd_init(struct mthca_dev *dev)
|
||||||
{
|
{
|
||||||
sema_init(&dev->cmd.hcr_sem, 1);
|
mutex_init(&dev->cmd.hcr_mutex);
|
||||||
sema_init(&dev->cmd.poll_sem, 1);
|
sema_init(&dev->cmd.poll_sem, 1);
|
||||||
dev->cmd.use_events = 0;
|
dev->cmd.use_events = 0;
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,8 @@
|
||||||
#include <linux/pci.h>
|
#include <linux/pci.h>
|
||||||
#include <linux/dma-mapping.h>
|
#include <linux/dma-mapping.h>
|
||||||
#include <linux/timer.h>
|
#include <linux/timer.h>
|
||||||
|
#include <linux/mutex.h>
|
||||||
|
|
||||||
#include <asm/semaphore.h>
|
#include <asm/semaphore.h>
|
||||||
|
|
||||||
#include "mthca_provider.h"
|
#include "mthca_provider.h"
|
||||||
|
@ -111,7 +113,7 @@ enum {
|
||||||
struct mthca_cmd {
|
struct mthca_cmd {
|
||||||
struct pci_pool *pool;
|
struct pci_pool *pool;
|
||||||
int use_events;
|
int use_events;
|
||||||
struct semaphore hcr_sem;
|
struct mutex hcr_mutex;
|
||||||
struct semaphore poll_sem;
|
struct semaphore poll_sem;
|
||||||
struct semaphore event_sem;
|
struct semaphore event_sem;
|
||||||
int max_cmds;
|
int max_cmds;
|
||||||
|
@ -256,7 +258,7 @@ struct mthca_av_table {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mthca_mcg_table {
|
struct mthca_mcg_table {
|
||||||
struct semaphore sem;
|
struct mutex mutex;
|
||||||
struct mthca_alloc alloc;
|
struct mthca_alloc alloc;
|
||||||
struct mthca_icm_table *table;
|
struct mthca_icm_table *table;
|
||||||
};
|
};
|
||||||
|
@ -301,7 +303,7 @@ struct mthca_dev {
|
||||||
u64 ddr_end;
|
u64 ddr_end;
|
||||||
|
|
||||||
MTHCA_DECLARE_DOORBELL_LOCK(doorbell_lock)
|
MTHCA_DECLARE_DOORBELL_LOCK(doorbell_lock)
|
||||||
struct semaphore cap_mask_mutex;
|
struct mutex cap_mask_mutex;
|
||||||
|
|
||||||
void __iomem *hcr;
|
void __iomem *hcr;
|
||||||
void __iomem *kar;
|
void __iomem *kar;
|
||||||
|
|
|
@ -154,7 +154,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
|
||||||
return PTR_ERR(mailbox);
|
return PTR_ERR(mailbox);
|
||||||
mgm = mailbox->buf;
|
mgm = mailbox->buf;
|
||||||
|
|
||||||
down(&dev->mcg_table.sem);
|
mutex_lock(&dev->mcg_table.mutex);
|
||||||
|
|
||||||
err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index);
|
err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index);
|
||||||
if (err)
|
if (err)
|
||||||
|
@ -238,7 +238,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
|
||||||
BUG_ON(index < dev->limits.num_mgms);
|
BUG_ON(index < dev->limits.num_mgms);
|
||||||
mthca_free(&dev->mcg_table.alloc, index);
|
mthca_free(&dev->mcg_table.alloc, index);
|
||||||
}
|
}
|
||||||
up(&dev->mcg_table.sem);
|
mutex_unlock(&dev->mcg_table.mutex);
|
||||||
|
|
||||||
mthca_free_mailbox(dev, mailbox);
|
mthca_free_mailbox(dev, mailbox);
|
||||||
return err;
|
return err;
|
||||||
|
@ -260,7 +260,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
|
||||||
return PTR_ERR(mailbox);
|
return PTR_ERR(mailbox);
|
||||||
mgm = mailbox->buf;
|
mgm = mailbox->buf;
|
||||||
|
|
||||||
down(&dev->mcg_table.sem);
|
mutex_lock(&dev->mcg_table.mutex);
|
||||||
|
|
||||||
err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index);
|
err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index);
|
||||||
if (err)
|
if (err)
|
||||||
|
@ -365,7 +365,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
up(&dev->mcg_table.sem);
|
mutex_unlock(&dev->mcg_table.mutex);
|
||||||
|
|
||||||
mthca_free_mailbox(dev, mailbox);
|
mthca_free_mailbox(dev, mailbox);
|
||||||
return err;
|
return err;
|
||||||
|
@ -383,7 +383,7 @@ int __devinit mthca_init_mcg_table(struct mthca_dev *dev)
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
init_MUTEX(&dev->mcg_table.sem);
|
mutex_init(&dev->mcg_table.mutex);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mthca_user_db_table {
|
struct mthca_user_db_table {
|
||||||
struct semaphore mutex;
|
struct mutex mutex;
|
||||||
struct {
|
struct {
|
||||||
u64 uvirt;
|
u64 uvirt;
|
||||||
struct scatterlist mem;
|
struct scatterlist mem;
|
||||||
|
@ -158,7 +158,7 @@ int mthca_table_get(struct mthca_dev *dev, struct mthca_icm_table *table, int ob
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
u8 status;
|
u8 status;
|
||||||
|
|
||||||
down(&table->mutex);
|
mutex_lock(&table->mutex);
|
||||||
|
|
||||||
if (table->icm[i]) {
|
if (table->icm[i]) {
|
||||||
++table->icm[i]->refcount;
|
++table->icm[i]->refcount;
|
||||||
|
@ -184,7 +184,7 @@ int mthca_table_get(struct mthca_dev *dev, struct mthca_icm_table *table, int ob
|
||||||
++table->icm[i]->refcount;
|
++table->icm[i]->refcount;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
up(&table->mutex);
|
mutex_unlock(&table->mutex);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int o
|
||||||
|
|
||||||
i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE;
|
i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE;
|
||||||
|
|
||||||
down(&table->mutex);
|
mutex_lock(&table->mutex);
|
||||||
|
|
||||||
if (--table->icm[i]->refcount == 0) {
|
if (--table->icm[i]->refcount == 0) {
|
||||||
mthca_UNMAP_ICM(dev, table->virt + i * MTHCA_TABLE_CHUNK_SIZE,
|
mthca_UNMAP_ICM(dev, table->virt + i * MTHCA_TABLE_CHUNK_SIZE,
|
||||||
|
@ -207,7 +207,7 @@ void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int o
|
||||||
table->icm[i] = NULL;
|
table->icm[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
up(&table->mutex);
|
mutex_unlock(&table->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *mthca_table_find(struct mthca_icm_table *table, int obj)
|
void *mthca_table_find(struct mthca_icm_table *table, int obj)
|
||||||
|
@ -220,7 +220,7 @@ void *mthca_table_find(struct mthca_icm_table *table, int obj)
|
||||||
if (!table->lowmem)
|
if (!table->lowmem)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
down(&table->mutex);
|
mutex_lock(&table->mutex);
|
||||||
|
|
||||||
idx = (obj & (table->num_obj - 1)) * table->obj_size;
|
idx = (obj & (table->num_obj - 1)) * table->obj_size;
|
||||||
icm = table->icm[idx / MTHCA_TABLE_CHUNK_SIZE];
|
icm = table->icm[idx / MTHCA_TABLE_CHUNK_SIZE];
|
||||||
|
@ -240,7 +240,7 @@ void *mthca_table_find(struct mthca_icm_table *table, int obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
up(&table->mutex);
|
mutex_unlock(&table->mutex);
|
||||||
return page ? lowmem_page_address(page) + offset : NULL;
|
return page ? lowmem_page_address(page) + offset : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ struct mthca_icm_table *mthca_alloc_icm_table(struct mthca_dev *dev,
|
||||||
table->num_obj = nobj;
|
table->num_obj = nobj;
|
||||||
table->obj_size = obj_size;
|
table->obj_size = obj_size;
|
||||||
table->lowmem = use_lowmem;
|
table->lowmem = use_lowmem;
|
||||||
init_MUTEX(&table->mutex);
|
mutex_init(&table->mutex);
|
||||||
|
|
||||||
for (i = 0; i < num_icm; ++i)
|
for (i = 0; i < num_icm; ++i)
|
||||||
table->icm[i] = NULL;
|
table->icm[i] = NULL;
|
||||||
|
@ -380,7 +380,7 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
|
||||||
if (index < 0 || index > dev->uar_table.uarc_size / 8)
|
if (index < 0 || index > dev->uar_table.uarc_size / 8)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
down(&db_tab->mutex);
|
mutex_lock(&db_tab->mutex);
|
||||||
|
|
||||||
i = index / MTHCA_DB_REC_PER_PAGE;
|
i = index / MTHCA_DB_REC_PER_PAGE;
|
||||||
|
|
||||||
|
@ -424,7 +424,7 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
|
||||||
db_tab->page[i].refcount = 1;
|
db_tab->page[i].refcount = 1;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
up(&db_tab->mutex);
|
mutex_unlock(&db_tab->mutex);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,11 +439,11 @@ void mthca_unmap_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
|
||||||
* pages until we clean up the whole db table.
|
* pages until we clean up the whole db table.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
down(&db_tab->mutex);
|
mutex_lock(&db_tab->mutex);
|
||||||
|
|
||||||
--db_tab->page[index / MTHCA_DB_REC_PER_PAGE].refcount;
|
--db_tab->page[index / MTHCA_DB_REC_PER_PAGE].refcount;
|
||||||
|
|
||||||
up(&db_tab->mutex);
|
mutex_unlock(&db_tab->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mthca_user_db_table *mthca_init_user_db_tab(struct mthca_dev *dev)
|
struct mthca_user_db_table *mthca_init_user_db_tab(struct mthca_dev *dev)
|
||||||
|
@ -460,7 +460,7 @@ struct mthca_user_db_table *mthca_init_user_db_tab(struct mthca_dev *dev)
|
||||||
if (!db_tab)
|
if (!db_tab)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
init_MUTEX(&db_tab->mutex);
|
mutex_init(&db_tab->mutex);
|
||||||
for (i = 0; i < npages; ++i) {
|
for (i = 0; i < npages; ++i) {
|
||||||
db_tab->page[i].refcount = 0;
|
db_tab->page[i].refcount = 0;
|
||||||
db_tab->page[i].uvirt = 0;
|
db_tab->page[i].uvirt = 0;
|
||||||
|
@ -499,7 +499,7 @@ int mthca_alloc_db(struct mthca_dev *dev, enum mthca_db_type type,
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
u8 status;
|
u8 status;
|
||||||
|
|
||||||
down(&dev->db_tab->mutex);
|
mutex_lock(&dev->db_tab->mutex);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MTHCA_DB_TYPE_CQ_ARM:
|
case MTHCA_DB_TYPE_CQ_ARM:
|
||||||
|
@ -585,7 +585,7 @@ found:
|
||||||
*db = (__be32 *) &page->db_rec[j];
|
*db = (__be32 *) &page->db_rec[j];
|
||||||
|
|
||||||
out:
|
out:
|
||||||
up(&dev->db_tab->mutex);
|
mutex_unlock(&dev->db_tab->mutex);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -601,7 +601,7 @@ void mthca_free_db(struct mthca_dev *dev, int type, int db_index)
|
||||||
|
|
||||||
page = dev->db_tab->page + i;
|
page = dev->db_tab->page + i;
|
||||||
|
|
||||||
down(&dev->db_tab->mutex);
|
mutex_lock(&dev->db_tab->mutex);
|
||||||
|
|
||||||
page->db_rec[j] = 0;
|
page->db_rec[j] = 0;
|
||||||
if (i >= dev->db_tab->min_group2)
|
if (i >= dev->db_tab->min_group2)
|
||||||
|
@ -624,7 +624,7 @@ void mthca_free_db(struct mthca_dev *dev, int type, int db_index)
|
||||||
++dev->db_tab->min_group2;
|
++dev->db_tab->min_group2;
|
||||||
}
|
}
|
||||||
|
|
||||||
up(&dev->db_tab->mutex);
|
mutex_unlock(&dev->db_tab->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mthca_init_db_tab(struct mthca_dev *dev)
|
int mthca_init_db_tab(struct mthca_dev *dev)
|
||||||
|
@ -638,7 +638,7 @@ int mthca_init_db_tab(struct mthca_dev *dev)
|
||||||
if (!dev->db_tab)
|
if (!dev->db_tab)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
init_MUTEX(&dev->db_tab->mutex);
|
mutex_init(&dev->db_tab->mutex);
|
||||||
|
|
||||||
dev->db_tab->npages = dev->uar_table.uarc_size / 4096;
|
dev->db_tab->npages = dev->uar_table.uarc_size / 4096;
|
||||||
dev->db_tab->max_group1 = 0;
|
dev->db_tab->max_group1 = 0;
|
||||||
|
|
|
@ -39,8 +39,7 @@
|
||||||
|
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
#include <linux/pci.h>
|
#include <linux/pci.h>
|
||||||
|
#include <linux/mutex.h>
|
||||||
#include <asm/semaphore.h>
|
|
||||||
|
|
||||||
#define MTHCA_ICM_CHUNK_LEN \
|
#define MTHCA_ICM_CHUNK_LEN \
|
||||||
((256 - sizeof (struct list_head) - 2 * sizeof (int)) / \
|
((256 - sizeof (struct list_head) - 2 * sizeof (int)) / \
|
||||||
|
@ -64,7 +63,7 @@ struct mthca_icm_table {
|
||||||
int num_obj;
|
int num_obj;
|
||||||
int obj_size;
|
int obj_size;
|
||||||
int lowmem;
|
int lowmem;
|
||||||
struct semaphore mutex;
|
struct mutex mutex;
|
||||||
struct mthca_icm *icm[0];
|
struct mthca_icm *icm[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -147,7 +146,7 @@ struct mthca_db_table {
|
||||||
int max_group1;
|
int max_group1;
|
||||||
int min_group2;
|
int min_group2;
|
||||||
struct mthca_db_page *page;
|
struct mthca_db_page *page;
|
||||||
struct semaphore mutex;
|
struct mutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum mthca_db_type {
|
enum mthca_db_type {
|
||||||
|
|
|
@ -185,7 +185,7 @@ static int mthca_modify_port(struct ib_device *ibdev,
|
||||||
int err;
|
int err;
|
||||||
u8 status;
|
u8 status;
|
||||||
|
|
||||||
if (down_interruptible(&to_mdev(ibdev)->cap_mask_mutex))
|
if (mutex_lock_interruptible(&to_mdev(ibdev)->cap_mask_mutex))
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
|
|
||||||
err = mthca_query_port(ibdev, port, &attr);
|
err = mthca_query_port(ibdev, port, &attr);
|
||||||
|
@ -207,7 +207,7 @@ static int mthca_modify_port(struct ib_device *ibdev,
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
up(&to_mdev(ibdev)->cap_mask_mutex);
|
mutex_unlock(&to_mdev(ibdev)->cap_mask_mutex);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1185,7 +1185,7 @@ int mthca_register_device(struct mthca_dev *dev)
|
||||||
dev->ib_dev.post_recv = mthca_tavor_post_receive;
|
dev->ib_dev.post_recv = mthca_tavor_post_receive;
|
||||||
}
|
}
|
||||||
|
|
||||||
init_MUTEX(&dev->cap_mask_mutex);
|
mutex_init(&dev->cap_mask_mutex);
|
||||||
|
|
||||||
ret = ib_register_device(&dev->ib_dev);
|
ret = ib_register_device(&dev->ib_dev);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
|
Loading…
Reference in a new issue