diff options
author | Roland Dreier <rolandd@cisco.com> | 2006-01-30 19:45:11 -0500 |
---|---|---|
committer | Roland Dreier <rolandd@cisco.com> | 2006-01-30 19:45:11 -0500 |
commit | fd9cfdd11be3b37b5c919b64b43990f14a1587bd (patch) | |
tree | 6d36c5927fcf17c98bfc38dccbde90925279c544 | |
parent | e3aa31c517cb6fd0a3d8b23e6a7e71a6aafc2393 (diff) |
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>
-rw-r--r-- | drivers/infiniband/hw/mthca/mthca_cmd.c | 6 | ||||
-rw-r--r-- | drivers/infiniband/hw/mthca/mthca_dev.h | 8 | ||||
-rw-r--r-- | drivers/infiniband/hw/mthca/mthca_mcg.c | 10 | ||||
-rw-r--r-- | drivers/infiniband/hw/mthca/mthca_memfree.c | 36 | ||||
-rw-r--r-- | drivers/infiniband/hw/mthca/mthca_memfree.h | 7 | ||||
-rw-r--r-- | drivers/infiniband/hw/mthca/mthca_provider.c | 6 |
6 files changed, 37 insertions, 36 deletions
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c index 69128fe60c53..f9b9b93dc501 100644 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c | |||
@@ -199,7 +199,7 @@ static int mthca_cmd_post(struct mthca_dev *dev, | |||
199 | { | 199 | { |
200 | int err = 0; | 200 | int err = 0; |
201 | 201 | ||
202 | down(&dev->cmd.hcr_sem); | 202 | mutex_lock(&dev->cmd.hcr_mutex); |
203 | 203 | ||
204 | if (event) { | 204 | if (event) { |
205 | unsigned long end = jiffies + GO_BIT_TIMEOUT; | 205 | unsigned long end = jiffies + GO_BIT_TIMEOUT; |
@@ -237,7 +237,7 @@ static int mthca_cmd_post(struct mthca_dev *dev, | |||
237 | op), dev->hcr + 6 * 4); | 237 | op), dev->hcr + 6 * 4); |
238 | 238 | ||
239 | out: | 239 | out: |
240 | up(&dev->cmd.hcr_sem); | 240 | mutex_unlock(&dev->cmd.hcr_mutex); |
241 | return err; | 241 | return err; |
242 | } | 242 | } |
243 | 243 | ||
@@ -435,7 +435,7 @@ static int mthca_cmd_imm(struct mthca_dev *dev, | |||
435 | 435 | ||
436 | int mthca_cmd_init(struct mthca_dev *dev) | 436 | int mthca_cmd_init(struct mthca_dev *dev) |
437 | { | 437 | { |
438 | sema_init(&dev->cmd.hcr_sem, 1); | 438 | mutex_init(&dev->cmd.hcr_mutex); |
439 | sema_init(&dev->cmd.poll_sem, 1); | 439 | sema_init(&dev->cmd.poll_sem, 1); |
440 | dev->cmd.use_events = 0; | 440 | dev->cmd.use_events = 0; |
441 | 441 | ||
diff --git a/drivers/infiniband/hw/mthca/mthca_dev.h b/drivers/infiniband/hw/mthca/mthca_dev.h index a104ab041ea3..2a165fd06e57 100644 --- a/drivers/infiniband/hw/mthca/mthca_dev.h +++ b/drivers/infiniband/hw/mthca/mthca_dev.h | |||
@@ -44,6 +44,8 @@ | |||
44 | #include <linux/pci.h> | 44 | #include <linux/pci.h> |
45 | #include <linux/dma-mapping.h> | 45 | #include <linux/dma-mapping.h> |
46 | #include <linux/timer.h> | 46 | #include <linux/timer.h> |
47 | #include <linux/mutex.h> | ||
48 | |||
47 | #include <asm/semaphore.h> | 49 | #include <asm/semaphore.h> |
48 | 50 | ||
49 | #include "mthca_provider.h" | 51 | #include "mthca_provider.h" |
@@ -111,7 +113,7 @@ enum { | |||
111 | struct mthca_cmd { | 113 | struct mthca_cmd { |
112 | struct pci_pool *pool; | 114 | struct pci_pool *pool; |
113 | int use_events; | 115 | int use_events; |
114 | struct semaphore hcr_sem; | 116 | struct mutex hcr_mutex; |
115 | struct semaphore poll_sem; | 117 | struct semaphore poll_sem; |
116 | struct semaphore event_sem; | 118 | struct semaphore event_sem; |
117 | int max_cmds; | 119 | int max_cmds; |
@@ -256,7 +258,7 @@ struct mthca_av_table { | |||
256 | }; | 258 | }; |
257 | 259 | ||
258 | struct mthca_mcg_table { | 260 | struct mthca_mcg_table { |
259 | struct semaphore sem; | 261 | struct mutex mutex; |
260 | struct mthca_alloc alloc; | 262 | struct mthca_alloc alloc; |
261 | struct mthca_icm_table *table; | 263 | struct mthca_icm_table *table; |
262 | }; | 264 | }; |
@@ -301,7 +303,7 @@ struct mthca_dev { | |||
301 | u64 ddr_end; | 303 | u64 ddr_end; |
302 | 304 | ||
303 | MTHCA_DECLARE_DOORBELL_LOCK(doorbell_lock) | 305 | MTHCA_DECLARE_DOORBELL_LOCK(doorbell_lock) |
304 | struct semaphore cap_mask_mutex; | 306 | struct mutex cap_mask_mutex; |
305 | 307 | ||
306 | void __iomem *hcr; | 308 | void __iomem *hcr; |
307 | void __iomem *kar; | 309 | void __iomem *kar; |
diff --git a/drivers/infiniband/hw/mthca/mthca_mcg.c b/drivers/infiniband/hw/mthca/mthca_mcg.c index 55ff5e5bcfef..321f11e707f2 100644 --- a/drivers/infiniband/hw/mthca/mthca_mcg.c +++ b/drivers/infiniband/hw/mthca/mthca_mcg.c | |||
@@ -154,7 +154,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) | |||
154 | return PTR_ERR(mailbox); | 154 | return PTR_ERR(mailbox); |
155 | mgm = mailbox->buf; | 155 | mgm = mailbox->buf; |
156 | 156 | ||
157 | down(&dev->mcg_table.sem); | 157 | mutex_lock(&dev->mcg_table.mutex); |
158 | 158 | ||
159 | err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index); | 159 | err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index); |
160 | if (err) | 160 | if (err) |
@@ -238,7 +238,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) | |||
238 | BUG_ON(index < dev->limits.num_mgms); | 238 | BUG_ON(index < dev->limits.num_mgms); |
239 | mthca_free(&dev->mcg_table.alloc, index); | 239 | mthca_free(&dev->mcg_table.alloc, index); |
240 | } | 240 | } |
241 | up(&dev->mcg_table.sem); | 241 | mutex_unlock(&dev->mcg_table.mutex); |
242 | 242 | ||
243 | mthca_free_mailbox(dev, mailbox); | 243 | mthca_free_mailbox(dev, mailbox); |
244 | return err; | 244 | return err; |
@@ -260,7 +260,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) | |||
260 | return PTR_ERR(mailbox); | 260 | return PTR_ERR(mailbox); |
261 | mgm = mailbox->buf; | 261 | mgm = mailbox->buf; |
262 | 262 | ||
263 | down(&dev->mcg_table.sem); | 263 | mutex_lock(&dev->mcg_table.mutex); |
264 | 264 | ||
265 | err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index); | 265 | err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index); |
266 | if (err) | 266 | if (err) |
@@ -365,7 +365,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) | |||
365 | } | 365 | } |
366 | 366 | ||
367 | out: | 367 | out: |
368 | up(&dev->mcg_table.sem); | 368 | mutex_unlock(&dev->mcg_table.mutex); |
369 | 369 | ||
370 | mthca_free_mailbox(dev, mailbox); | 370 | mthca_free_mailbox(dev, mailbox); |
371 | return err; | 371 | return err; |
@@ -383,7 +383,7 @@ int __devinit mthca_init_mcg_table(struct mthca_dev *dev) | |||
383 | if (err) | 383 | if (err) |
384 | return err; | 384 | return err; |
385 | 385 | ||
386 | init_MUTEX(&dev->mcg_table.sem); | 386 | mutex_init(&dev->mcg_table.mutex); |
387 | 387 | ||
388 | return 0; | 388 | return 0; |
389 | } | 389 | } |
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c index 9fb985a016e9..d709cb162a72 100644 --- a/drivers/infiniband/hw/mthca/mthca_memfree.c +++ b/drivers/infiniband/hw/mthca/mthca_memfree.c | |||
@@ -50,7 +50,7 @@ enum { | |||
50 | }; | 50 | }; |
51 | 51 | ||
52 | struct mthca_user_db_table { | 52 | struct mthca_user_db_table { |
53 | struct semaphore mutex; | 53 | struct mutex mutex; |
54 | struct { | 54 | struct { |
55 | u64 uvirt; | 55 | u64 uvirt; |
56 | struct scatterlist mem; | 56 | struct scatterlist mem; |
@@ -158,7 +158,7 @@ int mthca_table_get(struct mthca_dev *dev, struct mthca_icm_table *table, int ob | |||
158 | int ret = 0; | 158 | int ret = 0; |
159 | u8 status; | 159 | u8 status; |
160 | 160 | ||
161 | down(&table->mutex); | 161 | mutex_lock(&table->mutex); |
162 | 162 | ||
163 | if (table->icm[i]) { | 163 | if (table->icm[i]) { |
164 | ++table->icm[i]->refcount; | 164 | ++table->icm[i]->refcount; |
@@ -184,7 +184,7 @@ int mthca_table_get(struct mthca_dev *dev, struct mthca_icm_table *table, int ob | |||
184 | ++table->icm[i]->refcount; | 184 | ++table->icm[i]->refcount; |
185 | 185 | ||
186 | out: | 186 | out: |
187 | up(&table->mutex); | 187 | mutex_unlock(&table->mutex); |
188 | return ret; | 188 | return ret; |
189 | } | 189 | } |
190 | 190 | ||
@@ -198,7 +198,7 @@ void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int o | |||
198 | 198 | ||
199 | i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE; | 199 | i = (obj & (table->num_obj - 1)) * table->obj_size / MTHCA_TABLE_CHUNK_SIZE; |
200 | 200 | ||
201 | down(&table->mutex); | 201 | mutex_lock(&table->mutex); |
202 | 202 | ||
203 | if (--table->icm[i]->refcount == 0) { | 203 | if (--table->icm[i]->refcount == 0) { |
204 | mthca_UNMAP_ICM(dev, table->virt + i * MTHCA_TABLE_CHUNK_SIZE, | 204 | 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 | |||
207 | table->icm[i] = NULL; | 207 | table->icm[i] = NULL; |
208 | } | 208 | } |
209 | 209 | ||
210 | up(&table->mutex); | 210 | mutex_unlock(&table->mutex); |
211 | } | 211 | } |
212 | 212 | ||
213 | void *mthca_table_find(struct mthca_icm_table *table, int obj) | 213 | 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) | |||
220 | if (!table->lowmem) | 220 | if (!table->lowmem) |
221 | return NULL; | 221 | return NULL; |
222 | 222 | ||
223 | down(&table->mutex); | 223 | mutex_lock(&table->mutex); |
224 | 224 | ||
225 | idx = (obj & (table->num_obj - 1)) * table->obj_size; | 225 | idx = (obj & (table->num_obj - 1)) * table->obj_size; |
226 | icm = table->icm[idx / MTHCA_TABLE_CHUNK_SIZE]; | 226 | icm = table->icm[idx / MTHCA_TABLE_CHUNK_SIZE]; |
@@ -240,7 +240,7 @@ void *mthca_table_find(struct mthca_icm_table *table, int obj) | |||
240 | } | 240 | } |
241 | 241 | ||
242 | out: | 242 | out: |
243 | up(&table->mutex); | 243 | mutex_unlock(&table->mutex); |
244 | return page ? lowmem_page_address(page) + offset : NULL; | 244 | return page ? lowmem_page_address(page) + offset : NULL; |
245 | } | 245 | } |
246 | 246 | ||
@@ -301,7 +301,7 @@ struct mthca_icm_table *mthca_alloc_icm_table(struct mthca_dev *dev, | |||
301 | table->num_obj = nobj; | 301 | table->num_obj = nobj; |
302 | table->obj_size = obj_size; | 302 | table->obj_size = obj_size; |
303 | table->lowmem = use_lowmem; | 303 | table->lowmem = use_lowmem; |
304 | init_MUTEX(&table->mutex); | 304 | mutex_init(&table->mutex); |
305 | 305 | ||
306 | for (i = 0; i < num_icm; ++i) | 306 | for (i = 0; i < num_icm; ++i) |
307 | table->icm[i] = NULL; | 307 | table->icm[i] = NULL; |
@@ -380,7 +380,7 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar, | |||
380 | if (index < 0 || index > dev->uar_table.uarc_size / 8) | 380 | if (index < 0 || index > dev->uar_table.uarc_size / 8) |
381 | return -EINVAL; | 381 | return -EINVAL; |
382 | 382 | ||
383 | down(&db_tab->mutex); | 383 | mutex_lock(&db_tab->mutex); |
384 | 384 | ||
385 | i = index / MTHCA_DB_REC_PER_PAGE; | 385 | i = index / MTHCA_DB_REC_PER_PAGE; |
386 | 386 | ||
@@ -424,7 +424,7 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar, | |||
424 | db_tab->page[i].refcount = 1; | 424 | db_tab->page[i].refcount = 1; |
425 | 425 | ||
426 | out: | 426 | out: |
427 | up(&db_tab->mutex); | 427 | mutex_unlock(&db_tab->mutex); |
428 | return ret; | 428 | return ret; |
429 | } | 429 | } |
430 | 430 | ||
@@ -439,11 +439,11 @@ void mthca_unmap_user_db(struct mthca_dev *dev, struct mthca_uar *uar, | |||
439 | * pages until we clean up the whole db table. | 439 | * pages until we clean up the whole db table. |
440 | */ | 440 | */ |
441 | 441 | ||
442 | down(&db_tab->mutex); | 442 | mutex_lock(&db_tab->mutex); |
443 | 443 | ||
444 | --db_tab->page[index / MTHCA_DB_REC_PER_PAGE].refcount; | 444 | --db_tab->page[index / MTHCA_DB_REC_PER_PAGE].refcount; |
445 | 445 | ||
446 | up(&db_tab->mutex); | 446 | mutex_unlock(&db_tab->mutex); |
447 | } | 447 | } |
448 | 448 | ||
449 | struct mthca_user_db_table *mthca_init_user_db_tab(struct mthca_dev *dev) | 449 | 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) | |||
460 | if (!db_tab) | 460 | if (!db_tab) |
461 | return ERR_PTR(-ENOMEM); | 461 | return ERR_PTR(-ENOMEM); |
462 | 462 | ||
463 | init_MUTEX(&db_tab->mutex); | 463 | mutex_init(&db_tab->mutex); |
464 | for (i = 0; i < npages; ++i) { | 464 | for (i = 0; i < npages; ++i) { |
465 | db_tab->page[i].refcount = 0; | 465 | db_tab->page[i].refcount = 0; |
466 | db_tab->page[i].uvirt = 0; | 466 | db_tab->page[i].uvirt = 0; |
@@ -499,7 +499,7 @@ int mthca_alloc_db(struct mthca_dev *dev, enum mthca_db_type type, | |||
499 | int ret = 0; | 499 | int ret = 0; |
500 | u8 status; | 500 | u8 status; |
501 | 501 | ||
502 | down(&dev->db_tab->mutex); | 502 | mutex_lock(&dev->db_tab->mutex); |
503 | 503 | ||
504 | switch (type) { | 504 | switch (type) { |
505 | case MTHCA_DB_TYPE_CQ_ARM: | 505 | case MTHCA_DB_TYPE_CQ_ARM: |
@@ -585,7 +585,7 @@ found: | |||
585 | *db = (__be32 *) &page->db_rec[j]; | 585 | *db = (__be32 *) &page->db_rec[j]; |
586 | 586 | ||
587 | out: | 587 | out: |
588 | up(&dev->db_tab->mutex); | 588 | mutex_unlock(&dev->db_tab->mutex); |
589 | 589 | ||
590 | return ret; | 590 | return ret; |
591 | } | 591 | } |
@@ -601,7 +601,7 @@ void mthca_free_db(struct mthca_dev *dev, int type, int db_index) | |||
601 | 601 | ||
602 | page = dev->db_tab->page + i; | 602 | page = dev->db_tab->page + i; |
603 | 603 | ||
604 | down(&dev->db_tab->mutex); | 604 | mutex_lock(&dev->db_tab->mutex); |
605 | 605 | ||
606 | page->db_rec[j] = 0; | 606 | page->db_rec[j] = 0; |
607 | if (i >= dev->db_tab->min_group2) | 607 | if (i >= dev->db_tab->min_group2) |
@@ -624,7 +624,7 @@ void mthca_free_db(struct mthca_dev *dev, int type, int db_index) | |||
624 | ++dev->db_tab->min_group2; | 624 | ++dev->db_tab->min_group2; |
625 | } | 625 | } |
626 | 626 | ||
627 | up(&dev->db_tab->mutex); | 627 | mutex_unlock(&dev->db_tab->mutex); |
628 | } | 628 | } |
629 | 629 | ||
630 | int mthca_init_db_tab(struct mthca_dev *dev) | 630 | int mthca_init_db_tab(struct mthca_dev *dev) |
@@ -638,7 +638,7 @@ int mthca_init_db_tab(struct mthca_dev *dev) | |||
638 | if (!dev->db_tab) | 638 | if (!dev->db_tab) |
639 | return -ENOMEM; | 639 | return -ENOMEM; |
640 | 640 | ||
641 | init_MUTEX(&dev->db_tab->mutex); | 641 | mutex_init(&dev->db_tab->mutex); |
642 | 642 | ||
643 | dev->db_tab->npages = dev->uar_table.uarc_size / 4096; | 643 | dev->db_tab->npages = dev->uar_table.uarc_size / 4096; |
644 | dev->db_tab->max_group1 = 0; | 644 | dev->db_tab->max_group1 = 0; |
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.h b/drivers/infiniband/hw/mthca/mthca_memfree.h index 4fdca26eea85..36f1141a08aa 100644 --- a/drivers/infiniband/hw/mthca/mthca_memfree.h +++ b/drivers/infiniband/hw/mthca/mthca_memfree.h | |||
@@ -39,8 +39,7 @@ | |||
39 | 39 | ||
40 | #include <linux/list.h> | 40 | #include <linux/list.h> |
41 | #include <linux/pci.h> | 41 | #include <linux/pci.h> |
42 | 42 | #include <linux/mutex.h> | |
43 | #include <asm/semaphore.h> | ||
44 | 43 | ||
45 | #define MTHCA_ICM_CHUNK_LEN \ | 44 | #define MTHCA_ICM_CHUNK_LEN \ |
46 | ((256 - sizeof (struct list_head) - 2 * sizeof (int)) / \ | 45 | ((256 - sizeof (struct list_head) - 2 * sizeof (int)) / \ |
@@ -64,7 +63,7 @@ struct mthca_icm_table { | |||
64 | int num_obj; | 63 | int num_obj; |
65 | int obj_size; | 64 | int obj_size; |
66 | int lowmem; | 65 | int lowmem; |
67 | struct semaphore mutex; | 66 | struct mutex mutex; |
68 | struct mthca_icm *icm[0]; | 67 | struct mthca_icm *icm[0]; |
69 | }; | 68 | }; |
70 | 69 | ||
@@ -147,7 +146,7 @@ struct mthca_db_table { | |||
147 | int max_group1; | 146 | int max_group1; |
148 | int min_group2; | 147 | int min_group2; |
149 | struct mthca_db_page *page; | 148 | struct mthca_db_page *page; |
150 | struct semaphore mutex; | 149 | struct mutex mutex; |
151 | }; | 150 | }; |
152 | 151 | ||
153 | enum mthca_db_type { | 152 | enum mthca_db_type { |
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c index 484a7e6b7f8c..e88e39aef85a 100644 --- a/drivers/infiniband/hw/mthca/mthca_provider.c +++ b/drivers/infiniband/hw/mthca/mthca_provider.c | |||
@@ -185,7 +185,7 @@ static int mthca_modify_port(struct ib_device *ibdev, | |||
185 | int err; | 185 | int err; |
186 | u8 status; | 186 | u8 status; |
187 | 187 | ||
188 | if (down_interruptible(&to_mdev(ibdev)->cap_mask_mutex)) | 188 | if (mutex_lock_interruptible(&to_mdev(ibdev)->cap_mask_mutex)) |
189 | return -ERESTARTSYS; | 189 | return -ERESTARTSYS; |
190 | 190 | ||
191 | err = mthca_query_port(ibdev, port, &attr); | 191 | err = mthca_query_port(ibdev, port, &attr); |
@@ -207,7 +207,7 @@ static int mthca_modify_port(struct ib_device *ibdev, | |||
207 | } | 207 | } |
208 | 208 | ||
209 | out: | 209 | out: |
210 | up(&to_mdev(ibdev)->cap_mask_mutex); | 210 | mutex_unlock(&to_mdev(ibdev)->cap_mask_mutex); |
211 | return err; | 211 | return err; |
212 | } | 212 | } |
213 | 213 | ||
@@ -1185,7 +1185,7 @@ int mthca_register_device(struct mthca_dev *dev) | |||
1185 | dev->ib_dev.post_recv = mthca_tavor_post_receive; | 1185 | dev->ib_dev.post_recv = mthca_tavor_post_receive; |
1186 | } | 1186 | } |
1187 | 1187 | ||
1188 | init_MUTEX(&dev->cap_mask_mutex); | 1188 | mutex_init(&dev->cap_mask_mutex); |
1189 | 1189 | ||
1190 | ret = ib_register_device(&dev->ib_dev); | 1190 | ret = ib_register_device(&dev->ib_dev); |
1191 | if (ret) | 1191 | if (ret) |