Commit ed878458 authored by Roland Dreier's avatar Roland Dreier Committed by Linus Torvalds

[PATCH] IB/mthca: Align FW command mailboxes to 4K

Future versions of Mellanox HCA firmware will require command mailboxes to be
aligned to 4K.  Support this by using a pci_pool to allocate all mailboxes.
This has the added benefit of shrinking the source and text of mthca.
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 80fd8238
This diff is collapsed.
...@@ -37,8 +37,7 @@ ...@@ -37,8 +37,7 @@
#include <ib_verbs.h> #include <ib_verbs.h>
#define MTHCA_CMD_MAILBOX_ALIGN 16UL #define MTHCA_MAILBOX_SIZE 4096
#define MTHCA_CMD_MAILBOX_EXTRA (MTHCA_CMD_MAILBOX_ALIGN - 1)
enum { enum {
/* command completed successfully: */ /* command completed successfully: */
...@@ -112,6 +111,11 @@ enum { ...@@ -112,6 +111,11 @@ enum {
DEV_LIM_FLAG_UD_MULTI = 1 << 21, DEV_LIM_FLAG_UD_MULTI = 1 << 21,
}; };
struct mthca_mailbox {
dma_addr_t dma;
void *buf;
};
struct mthca_dev_lim { struct mthca_dev_lim {
int max_srq_sz; int max_srq_sz;
int max_qp_sz; int max_qp_sz;
...@@ -242,6 +246,10 @@ void mthca_cmd_use_polling(struct mthca_dev *dev); ...@@ -242,6 +246,10 @@ void mthca_cmd_use_polling(struct mthca_dev *dev);
void mthca_cmd_event(struct mthca_dev *dev, u16 token, void mthca_cmd_event(struct mthca_dev *dev, u16 token,
u8 status, u64 out_param); u8 status, u64 out_param);
struct mthca_mailbox *mthca_alloc_mailbox(struct mthca_dev *dev,
unsigned int gfp_mask);
void mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox);
int mthca_SYS_EN(struct mthca_dev *dev, u8 *status); int mthca_SYS_EN(struct mthca_dev *dev, u8 *status);
int mthca_SYS_DIS(struct mthca_dev *dev, u8 *status); int mthca_SYS_DIS(struct mthca_dev *dev, u8 *status);
int mthca_MAP_FA(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status); int mthca_MAP_FA(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status);
...@@ -272,41 +280,39 @@ int mthca_MAP_ICM_AUX(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status); ...@@ -272,41 +280,39 @@ int mthca_MAP_ICM_AUX(struct mthca_dev *dev, struct mthca_icm *icm, u8 *status);
int mthca_UNMAP_ICM_AUX(struct mthca_dev *dev, u8 *status); int mthca_UNMAP_ICM_AUX(struct mthca_dev *dev, u8 *status);
int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages, int mthca_SET_ICM_SIZE(struct mthca_dev *dev, u64 icm_size, u64 *aux_pages,
u8 *status); u8 *status);
int mthca_SW2HW_MPT(struct mthca_dev *dev, void *mpt_entry, int mthca_SW2HW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
int mpt_index, u8 *status); int mpt_index, u8 *status);
int mthca_HW2SW_MPT(struct mthca_dev *dev, void *mpt_entry, int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
int mpt_index, u8 *status); int mpt_index, u8 *status);
int mthca_WRITE_MTT(struct mthca_dev *dev, u64 *mtt_entry, int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
int num_mtt, u8 *status); int num_mtt, u8 *status);
int mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status); int mthca_SYNC_TPT(struct mthca_dev *dev, u8 *status);
int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap, int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
int eq_num, u8 *status); int eq_num, u8 *status);
int mthca_SW2HW_EQ(struct mthca_dev *dev, void *eq_context, int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
int eq_num, u8 *status); int eq_num, u8 *status);
int mthca_HW2SW_EQ(struct mthca_dev *dev, void *eq_context, int mthca_HW2SW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
int eq_num, u8 *status); int eq_num, u8 *status);
int mthca_SW2HW_CQ(struct mthca_dev *dev, void *cq_context, int mthca_SW2HW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
int cq_num, u8 *status); int cq_num, u8 *status);
int mthca_HW2SW_CQ(struct mthca_dev *dev, void *cq_context, int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
int cq_num, u8 *status); int cq_num, u8 *status);
int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num, int mthca_MODIFY_QP(struct mthca_dev *dev, int trans, u32 num,
int is_ee, void *qp_context, u32 optmask, int is_ee, struct mthca_mailbox *mailbox, u32 optmask,
u8 *status); u8 *status);
int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee, int mthca_QUERY_QP(struct mthca_dev *dev, u32 num, int is_ee,
void *qp_context, u8 *status); struct mthca_mailbox *mailbox, u8 *status);
int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn, int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn,
u8 *status); u8 *status);
int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey, int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
int port, struct ib_wc* in_wc, struct ib_grh* in_grh, int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
void *in_mad, void *response_mad, u8 *status); void *in_mad, void *response_mad, u8 *status);
int mthca_READ_MGM(struct mthca_dev *dev, int index, void *mgm, int mthca_READ_MGM(struct mthca_dev *dev, int index,
u8 *status); struct mthca_mailbox *mailbox, u8 *status);
int mthca_WRITE_MGM(struct mthca_dev *dev, int index, void *mgm, int mthca_WRITE_MGM(struct mthca_dev *dev, int index,
u8 *status); struct mthca_mailbox *mailbox, u8 *status);
int mthca_MGID_HASH(struct mthca_dev *dev, void *gid, u16 *hash, int mthca_MGID_HASH(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
u8 *status); u16 *hash, u8 *status);
int mthca_NOP(struct mthca_dev *dev, u8 *status); int mthca_NOP(struct mthca_dev *dev, u8 *status);
#define MAILBOX_ALIGN(x) ((void *) ALIGN((unsigned long) (x), MTHCA_CMD_MAILBOX_ALIGN))
#endif /* MTHCA_CMD_H */ #endif /* MTHCA_CMD_H */
...@@ -745,7 +745,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent, ...@@ -745,7 +745,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
struct mthca_cq *cq) struct mthca_cq *cq)
{ {
int size = nent * MTHCA_CQ_ENTRY_SIZE; int size = nent * MTHCA_CQ_ENTRY_SIZE;
void *mailbox = NULL; struct mthca_mailbox *mailbox;
struct mthca_cq_context *cq_context; struct mthca_cq_context *cq_context;
int err = -ENOMEM; int err = -ENOMEM;
u8 status; u8 status;
...@@ -779,12 +779,11 @@ int mthca_init_cq(struct mthca_dev *dev, int nent, ...@@ -779,12 +779,11 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
goto err_out_ci; goto err_out_ci;
} }
mailbox = kmalloc(sizeof (struct mthca_cq_context) + MTHCA_CMD_MAILBOX_EXTRA, mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
GFP_KERNEL); if (IS_ERR(mailbox))
if (!mailbox) goto err_out_arm;
goto err_out_mailbox;
cq_context = MAILBOX_ALIGN(mailbox); cq_context = mailbox->buf;
err = mthca_alloc_cq_buf(dev, size, cq); err = mthca_alloc_cq_buf(dev, size, cq);
if (err) if (err)
...@@ -815,7 +814,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent, ...@@ -815,7 +814,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
cq_context->state_db = cpu_to_be32(cq->arm_db_index); cq_context->state_db = cpu_to_be32(cq->arm_db_index);
} }
err = mthca_SW2HW_CQ(dev, cq_context, cq->cqn, &status); err = mthca_SW2HW_CQ(dev, mailbox, cq->cqn, &status);
if (err) { if (err) {
mthca_warn(dev, "SW2HW_CQ failed (%d)\n", err); mthca_warn(dev, "SW2HW_CQ failed (%d)\n", err);
goto err_out_free_mr; goto err_out_free_mr;
...@@ -839,7 +838,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent, ...@@ -839,7 +838,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
cq->cons_index = 0; cq->cons_index = 0;
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
return 0; return 0;
...@@ -848,8 +847,9 @@ int mthca_init_cq(struct mthca_dev *dev, int nent, ...@@ -848,8 +847,9 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
mthca_free_cq_buf(dev, cq); mthca_free_cq_buf(dev, cq);
err_out_mailbox: err_out_mailbox:
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
err_out_arm:
if (mthca_is_memfree(dev)) if (mthca_is_memfree(dev))
mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index); mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index);
...@@ -869,28 +869,26 @@ int mthca_init_cq(struct mthca_dev *dev, int nent, ...@@ -869,28 +869,26 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
void mthca_free_cq(struct mthca_dev *dev, void mthca_free_cq(struct mthca_dev *dev,
struct mthca_cq *cq) struct mthca_cq *cq)
{ {
void *mailbox; struct mthca_mailbox *mailbox;
int err; int err;
u8 status; u8 status;
might_sleep(); might_sleep();
mailbox = kmalloc(sizeof (struct mthca_cq_context) + MTHCA_CMD_MAILBOX_EXTRA, mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
GFP_KERNEL); if (IS_ERR(mailbox)) {
if (!mailbox) {
mthca_warn(dev, "No memory for mailbox to free CQ.\n"); mthca_warn(dev, "No memory for mailbox to free CQ.\n");
return; return;
} }
err = mthca_HW2SW_CQ(dev, MAILBOX_ALIGN(mailbox), cq->cqn, &status); err = mthca_HW2SW_CQ(dev, mailbox, cq->cqn, &status);
if (err) if (err)
mthca_warn(dev, "HW2SW_CQ failed (%d)\n", err); mthca_warn(dev, "HW2SW_CQ failed (%d)\n", err);
else if (status) else if (status)
mthca_warn(dev, "HW2SW_CQ returned status 0x%02x\n", mthca_warn(dev, "HW2SW_CQ returned status 0x%02x\n", status);
status);
if (0) { if (0) {
u32 *ctx = MAILBOX_ALIGN(mailbox); u32 *ctx = mailbox->buf;
int j; int j;
printk(KERN_ERR "context for CQN %x (cons index %x, next sw %d)\n", printk(KERN_ERR "context for CQN %x (cons index %x, next sw %d)\n",
...@@ -922,7 +920,7 @@ void mthca_free_cq(struct mthca_dev *dev, ...@@ -922,7 +920,7 @@ void mthca_free_cq(struct mthca_dev *dev,
mthca_table_put(dev, dev->cq_table.table, cq->cqn); mthca_table_put(dev, dev->cq_table.table, cq->cqn);
mthca_free(&dev->cq_table.alloc, cq->cqn); mthca_free(&dev->cq_table.alloc, cq->cqn);
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
} }
int __devinit mthca_init_cq_table(struct mthca_dev *dev) int __devinit mthca_init_cq_table(struct mthca_dev *dev)
......
...@@ -99,6 +99,7 @@ enum { ...@@ -99,6 +99,7 @@ enum {
}; };
struct mthca_cmd { struct mthca_cmd {
struct pci_pool *pool;
int use_events; int use_events;
struct semaphore hcr_sem; struct semaphore hcr_sem;
struct semaphore poll_sem; struct semaphore poll_sem;
......
...@@ -469,7 +469,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev, ...@@ -469,7 +469,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
PAGE_SIZE; PAGE_SIZE;
u64 *dma_list = NULL; u64 *dma_list = NULL;
dma_addr_t t; dma_addr_t t;
void *mailbox = NULL; struct mthca_mailbox *mailbox;
struct mthca_eq_context *eq_context; struct mthca_eq_context *eq_context;
int err = -ENOMEM; int err = -ENOMEM;
int i; int i;
...@@ -494,17 +494,16 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev, ...@@ -494,17 +494,16 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
if (!dma_list) if (!dma_list)
goto err_out_free; goto err_out_free;
mailbox = kmalloc(sizeof *eq_context + MTHCA_CMD_MAILBOX_EXTRA, mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
GFP_KERNEL); if (IS_ERR(mailbox))
if (!mailbox)
goto err_out_free; goto err_out_free;
eq_context = MAILBOX_ALIGN(mailbox); eq_context = mailbox->buf;
for (i = 0; i < npages; ++i) { for (i = 0; i < npages; ++i) {
eq->page_list[i].buf = dma_alloc_coherent(&dev->pdev->dev, eq->page_list[i].buf = dma_alloc_coherent(&dev->pdev->dev,
PAGE_SIZE, &t, GFP_KERNEL); PAGE_SIZE, &t, GFP_KERNEL);
if (!eq->page_list[i].buf) if (!eq->page_list[i].buf)
goto err_out_free; goto err_out_free_pages;
dma_list[i] = t; dma_list[i] = t;
pci_unmap_addr_set(&eq->page_list[i], mapping, t); pci_unmap_addr_set(&eq->page_list[i], mapping, t);
...@@ -517,7 +516,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev, ...@@ -517,7 +516,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
eq->eqn = mthca_alloc(&dev->eq_table.alloc); eq->eqn = mthca_alloc(&dev->eq_table.alloc);
if (eq->eqn == -1) if (eq->eqn == -1)
goto err_out_free; goto err_out_free_pages;
err = mthca_mr_alloc_phys(dev, dev->driver_pd.pd_num, err = mthca_mr_alloc_phys(dev, dev->driver_pd.pd_num,
dma_list, PAGE_SHIFT, npages, dma_list, PAGE_SHIFT, npages,
...@@ -548,7 +547,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev, ...@@ -548,7 +547,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
eq_context->intr = intr; eq_context->intr = intr;
eq_context->lkey = cpu_to_be32(eq->mr.ibmr.lkey); eq_context->lkey = cpu_to_be32(eq->mr.ibmr.lkey);
err = mthca_SW2HW_EQ(dev, eq_context, eq->eqn, &status); err = mthca_SW2HW_EQ(dev, mailbox, eq->eqn, &status);
if (err) { if (err) {
mthca_warn(dev, "SW2HW_EQ failed (%d)\n", err); mthca_warn(dev, "SW2HW_EQ failed (%d)\n", err);
goto err_out_free_mr; goto err_out_free_mr;
...@@ -561,7 +560,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev, ...@@ -561,7 +560,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
} }
kfree(dma_list); kfree(dma_list);
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
eq->eqn_mask = swab32(1 << eq->eqn); eq->eqn_mask = swab32(1 << eq->eqn);
eq->cons_index = 0; eq->cons_index = 0;
...@@ -579,7 +578,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev, ...@@ -579,7 +578,7 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
err_out_free_eq: err_out_free_eq:
mthca_free(&dev->eq_table.alloc, eq->eqn); mthca_free(&dev->eq_table.alloc, eq->eqn);
err_out_free: err_out_free_pages:
for (i = 0; i < npages; ++i) for (i = 0; i < npages; ++i)
if (eq->page_list[i].buf) if (eq->page_list[i].buf)
dma_free_coherent(&dev->pdev->dev, PAGE_SIZE, dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
...@@ -587,9 +586,11 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev, ...@@ -587,9 +586,11 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
pci_unmap_addr(&eq->page_list[i], pci_unmap_addr(&eq->page_list[i],
mapping)); mapping));
mthca_free_mailbox(dev, mailbox);
err_out_free:
kfree(eq->page_list); kfree(eq->page_list);
kfree(dma_list); kfree(dma_list);
kfree(mailbox);
err_out: err_out:
return err; return err;
...@@ -598,20 +599,18 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev, ...@@ -598,20 +599,18 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
static void mthca_free_eq(struct mthca_dev *dev, static void mthca_free_eq(struct mthca_dev *dev,
struct mthca_eq *eq) struct mthca_eq *eq)
{ {
void *mailbox = NULL; struct mthca_mailbox *mailbox;
int err; int err;
u8 status; u8 status;
int npages = (eq->nent * MTHCA_EQ_ENTRY_SIZE + PAGE_SIZE - 1) / int npages = (eq->nent * MTHCA_EQ_ENTRY_SIZE + PAGE_SIZE - 1) /
PAGE_SIZE; PAGE_SIZE;
int i; int i;
mailbox = kmalloc(sizeof (struct mthca_eq_context) + MTHCA_CMD_MAILBOX_EXTRA, mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
GFP_KERNEL); if (IS_ERR(mailbox))
if (!mailbox)
return; return;
err = mthca_HW2SW_EQ(dev, MAILBOX_ALIGN(mailbox), err = mthca_HW2SW_EQ(dev, mailbox, eq->eqn, &status);
eq->eqn, &status);
if (err) if (err)
mthca_warn(dev, "HW2SW_EQ failed (%d)\n", err); mthca_warn(dev, "HW2SW_EQ failed (%d)\n", err);
if (status) if (status)
...@@ -624,7 +623,7 @@ static void mthca_free_eq(struct mthca_dev *dev, ...@@ -624,7 +623,7 @@ static void mthca_free_eq(struct mthca_dev *dev,
for (i = 0; i < sizeof (struct mthca_eq_context) / 4; ++i) { for (i = 0; i < sizeof (struct mthca_eq_context) / 4; ++i) {
if (i % 4 == 0) if (i % 4 == 0)
printk("[%02x] ", i * 4); printk("[%02x] ", i * 4);
printk(" %08x", be32_to_cpup(MAILBOX_ALIGN(mailbox) + i * 4)); printk(" %08x", be32_to_cpup(mailbox->buf + i * 4));
if ((i + 1) % 4 == 0) if ((i + 1) % 4 == 0)
printk("\n"); printk("\n");
} }
...@@ -637,7 +636,7 @@ static void mthca_free_eq(struct mthca_dev *dev, ...@@ -637,7 +636,7 @@ static void mthca_free_eq(struct mthca_dev *dev,
pci_unmap_addr(&eq->page_list[i], mapping)); pci_unmap_addr(&eq->page_list[i], mapping));
kfree(eq->page_list); kfree(eq->page_list);
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
} }
static void mthca_free_irqs(struct mthca_dev *dev) static void mthca_free_irqs(struct mthca_dev *dev)
......
...@@ -66,22 +66,23 @@ static const u8 zero_gid[16]; /* automatically initialized to 0 */ ...@@ -66,22 +66,23 @@ static const u8 zero_gid[16]; /* automatically initialized to 0 */
* entry in hash chain and *mgm holds end of hash chain. * entry in hash chain and *mgm holds end of hash chain.
*/ */
static int find_mgm(struct mthca_dev *dev, static int find_mgm(struct mthca_dev *dev,
u8 *gid, struct mthca_mgm *mgm, u8 *gid, struct mthca_mailbox *mgm_mailbox,
u16 *hash, int *prev, int *index) u16 *hash, int *prev, int *index)
{ {
void *mailbox; struct mthca_mailbox *mailbox;
struct mthca_mgm *mgm = mgm_mailbox->buf;
u8 *mgid; u8 *mgid;
int err; int err;
u8 status; u8 status;
mailbox = kmalloc(16 + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL); mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
if (!mailbox) if (IS_ERR(mailbox))
return -ENOMEM; return -ENOMEM;
mgid = MAILBOX_ALIGN(mailbox); mgid = mailbox->buf;
memcpy(mgid, gid, 16); memcpy(mgid, gid, 16);
err = mthca_MGID_HASH(dev, mgid, hash, &status); err = mthca_MGID_HASH(dev, mailbox, hash, &status);
if (err) if (err)
goto out; goto out;
if (status) { if (status) {
...@@ -103,7 +104,7 @@ static int find_mgm(struct mthca_dev *dev, ...@@ -103,7 +104,7 @@ static int find_mgm(struct mthca_dev *dev,
*prev = -1; *prev = -1;
do { do {
err = mthca_READ_MGM(dev, *index, mgm, &status); err = mthca_READ_MGM(dev, *index, mgm_mailbox, &status);
if (err) if (err)
goto out; goto out;
if (status) { if (status) {
...@@ -129,14 +130,14 @@ static int find_mgm(struct mthca_dev *dev, ...@@ -129,14 +130,14 @@ static int find_mgm(struct mthca_dev *dev,
*index = -1; *index = -1;
out: out:
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
return err; return err;
} }
int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
{ {
struct mthca_dev *dev = to_mdev(ibqp->device); struct mthca_dev *dev = to_mdev(ibqp->device);
void *mailbox; struct mthca_mailbox *mailbox;
struct mthca_mgm *mgm; struct mthca_mgm *mgm;
u16 hash; u16 hash;
int index, prev; int index, prev;
...@@ -145,15 +146,15 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -145,15 +146,15 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
int err; int err;
u8 status; u8 status;
mailbox = kmalloc(sizeof *mgm + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL); mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
if (!mailbox) if (IS_ERR(mailbox))
return -ENOMEM; return PTR_ERR(mailbox);
mgm = MAILBOX_ALIGN(mailbox); mgm = mailbox->buf;
if (down_interruptible(&dev->mcg_table.sem)) if (down_interruptible(&dev->mcg_table.sem))
return -EINTR; return -EINTR;
err = find_mgm(dev, gid->raw, mgm, &hash, &prev, &index); err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index);
if (err) if (err)
goto out; goto out;
...@@ -170,7 +171,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -170,7 +171,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
goto out; goto out;
} }
err = mthca_READ_MGM(dev, index, mgm, &status); err = mthca_READ_MGM(dev, index, mailbox, &status);
if (err) if (err)
goto out; goto out;
if (status) { if (status) {
...@@ -195,7 +196,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -195,7 +196,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
goto out; goto out;
} }
err = mthca_WRITE_MGM(dev, index, mgm, &status); err = mthca_WRITE_MGM(dev, index, mailbox, &status);
if (err) if (err)
goto out; goto out;
if (status) { if (status) {
...@@ -206,7 +207,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -206,7 +207,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
if (!link) if (!link)
goto out; goto out;
err = mthca_READ_MGM(dev, prev, mgm, &status); err = mthca_READ_MGM(dev, prev, mailbox, &status);
if (err) if (err)
goto out; goto out;
if (status) { if (status) {
...@@ -217,7 +218,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -217,7 +218,7 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
mgm->next_gid_index = cpu_to_be32(index << 5); mgm->next_gid_index = cpu_to_be32(index << 5);
err = mthca_WRITE_MGM(dev, prev, mgm, &status); err = mthca_WRITE_MGM(dev, prev, mailbox, &status);
if (err) if (err)
goto out; goto out;
if (status) { if (status) {
...@@ -227,14 +228,14 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -227,14 +228,14 @@ int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
out: out:
up(&dev->mcg_table.sem); up(&dev->mcg_table.sem);
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
return err; return err;
} }
int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
{ {
struct mthca_dev *dev = to_mdev(ibqp->device); struct mthca_dev *dev = to_mdev(ibqp->device);
void *mailbox; struct mthca_mailbox *mailbox;
struct mthca_mgm *mgm; struct mthca_mgm *mgm;
u16 hash; u16 hash;
int prev, index; int prev, index;
...@@ -242,15 +243,15 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -242,15 +243,15 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
int err; int err;
u8 status; u8 status;
mailbox = kmalloc(sizeof *mgm + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL); mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
if (!mailbox) if (IS_ERR(mailbox))
return -ENOMEM; return PTR_ERR(mailbox);
mgm = MAILBOX_ALIGN(mailbox); mgm = mailbox->buf;
if (down_interruptible(&dev->mcg_table.sem)) if (down_interruptible(&dev->mcg_table.sem))
return -EINTR; return -EINTR;
err = find_mgm(dev, gid->raw, mgm, &hash, &prev, &index); err = find_mgm(dev, gid->raw, mailbox, &hash, &prev, &index);
if (err) if (err)
goto out; goto out;
...@@ -285,7 +286,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -285,7 +286,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
mgm->qp[loc] = mgm->qp[i - 1]; mgm->qp[loc] = mgm->qp[i - 1];
mgm->qp[i - 1] = 0; mgm->qp[i - 1] = 0;
err = mthca_WRITE_MGM(dev, index, mgm, &status); err = mthca_WRITE_MGM(dev, index, mailbox, &status);
if (err) if (err)
goto out; goto out;
if (status) { if (status) {
...@@ -304,7 +305,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -304,7 +305,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
if (be32_to_cpu(mgm->next_gid_index) >> 5) { if (be32_to_cpu(mgm->next_gid_index) >> 5) {
err = mthca_READ_MGM(dev, err = mthca_READ_MGM(dev,
be32_to_cpu(mgm->next_gid_index) >> 5, be32_to_cpu(mgm->next_gid_index) >> 5,
mgm, &status); mailbox, &status);
if (err) if (err)
goto out; goto out;
if (status) { if (status) {
...@@ -316,7 +317,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -316,7 +317,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
} else } else
memset(mgm->gid, 0, 16); memset(mgm->gid, 0, 16);
err = mthca_WRITE_MGM(dev, index, mgm, &status); err = mthca_WRITE_MGM(dev, index, mailbox, &status);
if (err) if (err)
goto out; goto out;
if (status) { if (status) {
...@@ -327,7 +328,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -327,7 +328,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
} else { } else {
/* Remove entry from AMGM */ /* Remove entry from AMGM */
index = be32_to_cpu(mgm->next_gid_index) >> 5; index = be32_to_cpu(mgm->next_gid_index) >> 5;
err = mthca_READ_MGM(dev, prev, mgm, &status); err = mthca_READ_MGM(dev, prev, mailbox, &status);
if (err) if (err)
goto out; goto out;
if (status) { if (status) {
...@@ -338,7 +339,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -338,7 +339,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
mgm->next_gid_index = cpu_to_be32(index << 5); mgm->next_gid_index = cpu_to_be32(index << 5);
err = mthca_WRITE_MGM(dev, prev, mgm, &status); err = mthca_WRITE_MGM(dev, prev, mailbox, &status);
if (err) if (err)
goto out; goto out;
if (status) { if (status) {
...@@ -350,7 +351,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) ...@@ -350,7 +351,7 @@ int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
out: out:
up(&dev->mcg_table.sem); up(&dev->mcg_table.sem);
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
return err; return err;
} }
......
...@@ -246,21 +246,23 @@ void mthca_free_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt) ...@@ -246,21 +246,23 @@ void mthca_free_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt)
int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt, int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt,
int start_index, u64 *buffer_list, int list_len) int start_index, u64 *buffer_list, int list_len)
{ {
struct mthca_mailbox *mailbox;
u64 *mtt_entry; u64 *mtt_entry;
int err = 0; int err = 0;
u8 status; u8 status;
int i; int i;
mtt_entry = (u64 *) __get_free_page(GFP_KERNEL); mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
if (!mtt_entry) if (IS_ERR(mailbox))
return -ENOMEM; return PTR_ERR(mailbox);
mtt_entry = mailbox->buf;
while (list_len > 0) { while (list_len > 0) {
mtt_entry[0] = cpu_to_be64(dev->mr_table.mtt_base + mtt_entry[0] = cpu_to_be64(dev->mr_table.mtt_base +
mtt->first_seg * MTHCA_MTT_SEG_SIZE + mtt->first_seg * MTHCA_MTT_SEG_SIZE +
start_index * 8); start_index * 8);
mtt_entry[1] = 0; mtt_entry[1] = 0;
for (i = 0; i < list_len && i < PAGE_SIZE / 8 - 2; ++i) for (i = 0; i < list_len && i < MTHCA_MAILBOX_SIZE / 8 - 2; ++i)
mtt_entry[i + 2] = cpu_to_be64(buffer_list[i] | mtt_entry[i + 2] = cpu_to_be64(buffer_list[i] |
MTHCA_MTT_FLAG_PRESENT); MTHCA_MTT_FLAG_PRESENT);
...@@ -271,7 +273,7 @@ int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt, ...@@ -271,7 +273,7 @@ int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt,
if (i & 1) if (i & 1)
mtt_entry[i + 2] = 0; mtt_entry[i + 2] = 0;
err = mthca_WRITE_MTT(dev, mtt_entry, (i + 1) & ~1, &status); err = mthca_WRITE_MTT(dev, mailbox, (i + 1) & ~1, &status);
if (err) { if (err) {
mthca_warn(dev, "WRITE_MTT failed (%d)\n", err); mthca_warn(dev, "WRITE_MTT failed (%d)\n", err);
goto out; goto out;
...@@ -289,7 +291,7 @@ int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt, ...@@ -289,7 +291,7 @@ int mthca_write_mtt(struct mthca_dev *dev, struct mthca_mtt *mtt,
} }
out: out:
free_page((unsigned long) mtt_entry); mthca_free_mailbox(dev, mailbox);
return err; return err;
} }
...@@ -332,7 +334,7 @@ static inline u32 key_to_hw_index(struct mthca_dev *dev, u32 key) ...@@ -332,7 +334,7 @@ static inline u32 key_to_hw_index(struct mthca_dev *dev, u32 key)
int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift, int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
u64 iova, u64 total_size, u32 access, struct mthca_mr *mr) u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
{ {
void *mailbox; struct mthca_mailbox *mailbox;
struct mthca_mpt_entry *mpt_entry; struct mthca_mpt_entry *mpt_entry;
u32 key; u32 key;
int i; int i;
...@@ -354,13 +356,12 @@ int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift, ...@@ -354,13 +356,12 @@ int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
goto err_out_mpt_free; goto err_out_mpt_free;
} }
mailbox = kmalloc(sizeof *mpt_entry + MTHCA_CMD_MAILBOX_EXTRA, mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
GFP_KERNEL); if (IS_ERR(mailbox)) {
if (!mailbox) { err = PTR_ERR(mailbox);
err = -ENOMEM;
goto err_out_table; goto err_out_table;
} }
mpt_entry = MAILBOX_ALIGN(mailbox); mpt_entry = mailbox->buf;
mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS | mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS |
MTHCA_MPT_FLAG_MIO | MTHCA_MPT_FLAG_MIO |
...@@ -394,7 +395,7 @@ int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift, ...@@ -394,7 +395,7 @@ int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
} }
} }
err = mthca_SW2HW_MPT(dev, mpt_entry, err = mthca_SW2HW_MPT(dev, mailbox,
key & (dev->limits.num_mpts - 1), key & (dev->limits.num_mpts - 1),
&status); &status);
if (err) { if (err) {
...@@ -407,11 +408,11 @@ int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift, ...@@ -407,11 +408,11 @@ int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
goto err_out_mailbox; goto err_out_mailbox;
} }
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
return err; return err;
err_out_mailbox: err_out_mailbox:
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
err_out_table: err_out_table:
mthca_table_put(dev, dev->mr_table.mpt_table, key); mthca_table_put(dev, dev->mr_table.mpt_table, key);
...@@ -487,7 +488,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd, ...@@ -487,7 +488,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
u32 access, struct mthca_fmr *mr) u32 access, struct mthca_fmr *mr)
{ {
struct mthca_mpt_entry *mpt_entry; struct mthca_mpt_entry *mpt_entry;
void *mailbox; struct mthca_mailbox *mailbox;
u64 mtt_seg; u64 mtt_seg;
u32 key, idx; u32 key, idx;
u8 status; u8 status;
...@@ -538,12 +539,11 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd, ...@@ -538,12 +539,11 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
} else } else
mr->mem.tavor.mtts = dev->mr_table.tavor_fmr.mtt_base + mtt_seg; mr->mem.tavor.mtts = dev->mr_table.tavor_fmr.mtt_base + mtt_seg;
mailbox = kmalloc(sizeof *mpt_entry + MTHCA_CMD_MAILBOX_EXTRA, mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
GFP_KERNEL); if (IS_ERR(mailbox))
if (!mailbox)
goto err_out_free_mtt; goto err_out_free_mtt;
mpt_entry = MAILBOX_ALIGN(mailbox); mpt_entry = mailbox->buf;
mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS | mpt_entry->flags = cpu_to_be32(MTHCA_MPT_FLAG_SW_OWNS |
MTHCA_MPT_FLAG_MIO | MTHCA_MPT_FLAG_MIO |
...@@ -568,7 +568,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd, ...@@ -568,7 +568,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
} }
} }
err = mthca_SW2HW_MPT(dev, mpt_entry, err = mthca_SW2HW_MPT(dev, mailbox,
key & (dev->limits.num_mpts - 1), key & (dev->limits.num_mpts - 1),
&status); &status);
if (err) { if (err) {
...@@ -582,11 +582,11 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd, ...@@ -582,11 +582,11 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
goto err_out_mailbox_free; goto err_out_mailbox_free;
} }
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
return 0; return 0;
err_out_mailbox_free: err_out_mailbox_free:
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
err_out_free_mtt: err_out_free_mtt:
mthca_free_mtt(dev, mr->mtt); mthca_free_mtt(dev, mr->mtt);
......
...@@ -589,7 +589,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask) ...@@ -589,7 +589,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
struct mthca_dev *dev = to_mdev(ibqp->device); struct mthca_dev *dev = to_mdev(ibqp->device);
struct mthca_qp *qp = to_mqp(ibqp); struct mthca_qp *qp = to_mqp(ibqp);
enum ib_qp_state cur_state, new_state; enum ib_qp_state cur_state, new_state;
void *mailbox = NULL; struct mthca_mailbox *mailbox;
struct mthca_qp_param *qp_param; struct mthca_qp_param *qp_param;
struct mthca_qp_context *qp_context; struct mthca_qp_context *qp_context;
u32 req_param, opt_param; u32 req_param, opt_param;
...@@ -646,10 +646,10 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask) ...@@ -646,10 +646,10 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
return -EINVAL; return -EINVAL;
} }
mailbox = kmalloc(sizeof (*qp_param) + MTHCA_CMD_MAILBOX_EXTRA, GFP_KERNEL); mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
if (!mailbox) if (IS_ERR(mailbox))
return -ENOMEM; return PTR_ERR(mailbox);
qp_param = MAILBOX_ALIGN(mailbox); qp_param = mailbox->buf;
qp_context = &qp_param->context; qp_context = &qp_param->context;
memset(qp_param, 0, sizeof *qp_param); memset(qp_param, 0, sizeof *qp_param);
...@@ -872,7 +872,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask) ...@@ -872,7 +872,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
} }
err = mthca_MODIFY_QP(dev, state_table[cur_state][new_state].trans, err = mthca_MODIFY_QP(dev, state_table[cur_state][new_state].trans,
qp->qpn, 0, qp_param, 0, &status); qp->qpn, 0, mailbox, 0, &status);
if (status) { if (status) {
mthca_warn(dev, "modify QP %d returned status %02x.\n", mthca_warn(dev, "modify QP %d returned status %02x.\n",
state_table[cur_state][new_state].trans, status); state_table[cur_state][new_state].trans, status);
...@@ -882,7 +882,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask) ...@@ -882,7 +882,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
if (!err) if (!err)
qp->state = new_state; qp->state = new_state;
kfree(mailbox); mthca_free_mailbox(dev, mailbox);
if (is_sqp(dev, qp)) if (is_sqp(dev, qp))
store_attrs(to_msqp(qp), attr, attr_mask); store_attrs(to_msqp(qp), attr, attr_mask);
......
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