Skip to content

Commit

Permalink
[PATCH] IB/mthca: encapsulate mem-free check into mthca_is_memfree()
Browse files Browse the repository at this point in the history
Clean up mem-free mode support by introducing mthca_is_memfree() function,
which encapsulates the logic of deciding if a device is mem-free.

Signed-off-by: Roland Dreier <roland@topspin.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Roland Dreier authored and Linus Torvalds committed Apr 16, 2005
1 parent 6bd6228 commit d10ddbf
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 57 deletions.
6 changes: 3 additions & 3 deletions drivers/infiniband/hw/mthca/mthca_av.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int mthca_create_ah(struct mthca_dev *dev,

ah->type = MTHCA_AH_PCI_POOL;

if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
ah->av = kmalloc(sizeof *ah->av, GFP_ATOMIC);
if (!ah->av)
return -ENOMEM;
Expand Down Expand Up @@ -192,7 +192,7 @@ int __devinit mthca_init_av_table(struct mthca_dev *dev)
{
int err;

if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
return 0;

err = mthca_alloc_init(&dev->av_table.alloc,
Expand Down Expand Up @@ -231,7 +231,7 @@ int __devinit mthca_init_av_table(struct mthca_dev *dev)

void __devexit mthca_cleanup_av_table(struct mthca_dev *dev)
{
if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
return;

if (dev->av_table.av_map)
Expand Down
8 changes: 4 additions & 4 deletions drivers/infiniband/hw/mthca/mthca_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ int mthca_QUERY_FW(struct mthca_dev *dev, u8 *status)
mthca_dbg(dev, "FW version %012llx, max commands %d\n",
(unsigned long long) dev->fw_ver, dev->cmd.max_cmds);

if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
MTHCA_GET(dev->fw.arbel.fw_pages, outbox, QUERY_FW_SIZE_OFFSET);
MTHCA_GET(dev->fw.arbel.clr_int_base, outbox, QUERY_FW_CLR_INT_BASE_OFFSET);
MTHCA_GET(dev->fw.arbel.eq_arm_base, outbox, QUERY_FW_EQ_ARM_BASE_OFFSET);
Expand Down Expand Up @@ -984,7 +984,7 @@ int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,

mthca_dbg(dev, "Flags: %08x\n", dev_lim->flags);

if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
MTHCA_GET(field, outbox, QUERY_DEV_LIM_RSZ_SRQ_OFFSET);
dev_lim->hca.arbel.resize_srq = field & 1;
MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_SG_RQ_OFFSET);
Expand Down Expand Up @@ -1148,7 +1148,7 @@ int mthca_INIT_HCA(struct mthca_dev *dev,
/* TPT attributes */

MTHCA_PUT(inbox, param->mpt_base, INIT_HCA_MPT_BASE_OFFSET);
if (dev->hca_type != ARBEL_NATIVE)
if (!mthca_is_memfree(dev))
MTHCA_PUT(inbox, param->mtt_seg_sz, INIT_HCA_MTT_SEG_SZ_OFFSET);
MTHCA_PUT(inbox, param->log_mpt_sz, INIT_HCA_LOG_MPT_SZ_OFFSET);
MTHCA_PUT(inbox, param->mtt_base, INIT_HCA_MTT_BASE_OFFSET);
Expand All @@ -1161,7 +1161,7 @@ int mthca_INIT_HCA(struct mthca_dev *dev,

MTHCA_PUT(inbox, param->uar_scratch_base, INIT_HCA_UAR_SCATCH_BASE_OFFSET);

if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
MTHCA_PUT(inbox, param->log_uarc_sz, INIT_HCA_UARC_SZ_OFFSET);
MTHCA_PUT(inbox, param->log_uar_sz, INIT_HCA_LOG_UAR_SZ_OFFSET);
MTHCA_PUT(inbox, param->uarc_base, INIT_HCA_UAR_CTX_BASE_OFFSET);
Expand Down
12 changes: 6 additions & 6 deletions drivers/infiniband/hw/mthca/mthca_cq.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static inline void update_cons_index(struct mthca_dev *dev, struct mthca_cq *cq,
{
u32 doorbell[2];

if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
*cq->set_ci_db = cpu_to_be32(cq->cons_index);
wmb();
} else {
Expand Down Expand Up @@ -760,7 +760,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
if (cq->cqn == -1)
return -ENOMEM;

if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
cq->arm_sn = 1;

err = mthca_table_get(dev, dev->cq_table.table, cq->cqn);
Expand Down Expand Up @@ -811,7 +811,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
cq_context->lkey = cpu_to_be32(cq->mr.ibmr.lkey);
cq_context->cqn = cpu_to_be32(cq->cqn);

if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
cq_context->ci_db = cpu_to_be32(cq->set_ci_db_index);
cq_context->state_db = cpu_to_be32(cq->arm_db_index);
}
Expand Down Expand Up @@ -851,11 +851,11 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
err_out_mailbox:
kfree(mailbox);

if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
mthca_free_db(dev, MTHCA_DB_TYPE_CQ_ARM, cq->arm_db_index);

err_out_ci:
if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
mthca_free_db(dev, MTHCA_DB_TYPE_CQ_SET_CI, cq->set_ci_db_index);

err_out_icm:
Expand Down Expand Up @@ -916,7 +916,7 @@ void mthca_free_cq(struct mthca_dev *dev,
mthca_free_mr(dev, &cq->mr);
mthca_free_cq_buf(dev, cq);

if (dev->hca_type == ARBEL_NATIVE) {
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_SET_CI, cq->set_ci_db_index);
mthca_table_put(dev, dev->cq_table.table, cq->cqn);
Expand Down
5 changes: 5 additions & 0 deletions drivers/infiniband/hw/mthca/mthca_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,9 @@ static inline struct mthca_dev *to_mdev(struct ib_device *ibdev)
return container_of(ibdev, struct mthca_dev, ib_dev);
}

static inline int mthca_is_memfree(struct mthca_dev *dev)
{
return dev->hca_type == ARBEL_NATIVE;
}

#endif /* MTHCA_DEV_H */
18 changes: 9 additions & 9 deletions drivers/infiniband/hw/mthca/mthca_eq.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static inline void arbel_set_eq_ci(struct mthca_dev *dev, struct mthca_eq *eq, u

static inline void set_eq_ci(struct mthca_dev *dev, struct mthca_eq *eq, u32 ci)
{
if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
arbel_set_eq_ci(dev, eq, ci);
else
tavor_set_eq_ci(dev, eq, ci);
Expand All @@ -223,7 +223,7 @@ static inline void arbel_eq_req_not(struct mthca_dev *dev, u32 eqn_mask)

static inline void disarm_cq(struct mthca_dev *dev, int eqn, int cqn)
{
if (dev->hca_type != ARBEL_NATIVE) {
if (!mthca_is_memfree(dev)) {
u32 doorbell[2];

doorbell[0] = cpu_to_be32(MTHCA_EQ_DB_DISARM_CQ | eqn);
Expand Down Expand Up @@ -535,11 +535,11 @@ static int __devinit mthca_create_eq(struct mthca_dev *dev,
MTHCA_EQ_OWNER_HW |
MTHCA_EQ_STATE_ARMED |
MTHCA_EQ_FLAG_TR);
if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
eq_context->flags |= cpu_to_be32(MTHCA_EQ_STATE_ARBEL);

eq_context->logsize_usrpage = cpu_to_be32((ffs(nent) - 1) << 24);
if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
eq_context->arbel_pd = cpu_to_be32(dev->driver_pd.pd_num);
} else {
eq_context->logsize_usrpage |= cpu_to_be32(dev->driver_uar.index);
Expand Down Expand Up @@ -686,7 +686,7 @@ static int __devinit mthca_map_eq_regs(struct mthca_dev *dev)

mthca_base = pci_resource_start(dev->pdev, 0);

if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
/*
* We assume that the EQ arm and EQ set CI registers
* fall within the first BAR. We can't trust the
Expand Down Expand Up @@ -756,7 +756,7 @@ static int __devinit mthca_map_eq_regs(struct mthca_dev *dev)

static void __devexit mthca_unmap_eq_regs(struct mthca_dev *dev)
{
if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
mthca_unmap_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) &
dev->fw.arbel.eq_set_ci_base,
MTHCA_EQ_SET_CI_SIZE,
Expand Down Expand Up @@ -880,7 +880,7 @@ int __devinit mthca_init_eq_table(struct mthca_dev *dev)

for (i = 0; i < MTHCA_NUM_EQ; ++i) {
err = request_irq(dev->eq_table.eq[i].msi_x_vector,
dev->hca_type == ARBEL_NATIVE ?
mthca_is_memfree(dev) ?
mthca_arbel_msi_x_interrupt :
mthca_tavor_msi_x_interrupt,
0, eq_name[i], dev->eq_table.eq + i);
Expand All @@ -890,7 +890,7 @@ int __devinit mthca_init_eq_table(struct mthca_dev *dev)
}
} else {
err = request_irq(dev->pdev->irq,
dev->hca_type == ARBEL_NATIVE ?
mthca_is_memfree(dev) ?
mthca_arbel_interrupt :
mthca_tavor_interrupt,
SA_SHIRQ, DRV_NAME, dev);
Expand Down Expand Up @@ -918,7 +918,7 @@ int __devinit mthca_init_eq_table(struct mthca_dev *dev)
dev->eq_table.eq[MTHCA_EQ_CMD].eqn, status);

for (i = 0; i < MTHCA_EQ_CMD; ++i)
if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
arbel_eq_req_not(dev, dev->eq_table.eq[i].eqn_mask);
else
tavor_eq_req_not(dev, dev->eq_table.eq[i].eqn);
Expand Down
6 changes: 3 additions & 3 deletions drivers/infiniband/hw/mthca/mthca_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ static int __devinit mthca_init_arbel(struct mthca_dev *mdev)

static int __devinit mthca_init_hca(struct mthca_dev *mdev)
{
if (mdev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(mdev))
return mthca_init_arbel(mdev);
else
return mthca_init_tavor(mdev);
Expand Down Expand Up @@ -835,7 +835,7 @@ static void mthca_close_hca(struct mthca_dev *mdev)

mthca_CLOSE_HCA(mdev, 0, &status);

if (mdev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(mdev)) {
mthca_free_icm_table(mdev, mdev->cq_table.table);
mthca_free_icm_table(mdev, mdev->qp_table.eqp_table);
mthca_free_icm_table(mdev, mdev->qp_table.qp_table);
Expand Down Expand Up @@ -939,7 +939,7 @@ static int __devinit mthca_init_one(struct pci_dev *pdev,
mdev->pdev = pdev;
mdev->hca_type = id->driver_data;

if (mdev->hca_type == ARBEL_NATIVE && !mthca_memfree_warned++)
if (mthca_is_memfree(mdev) && !mthca_memfree_warned++)
mthca_warn(mdev, "Warning: native MT25208 mode support is incomplete. "
"Your HCA may not work properly.\n");

Expand Down
4 changes: 2 additions & 2 deletions drivers/infiniband/hw/mthca/mthca_memfree.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ int mthca_init_db_tab(struct mthca_dev *dev)
{
int i;

if (dev->hca_type != ARBEL_NATIVE)
if (!mthca_is_memfree(dev))
return 0;

dev->db_tab = kmalloc(sizeof *dev->db_tab, GFP_KERNEL);
Expand Down Expand Up @@ -504,7 +504,7 @@ void mthca_cleanup_db_tab(struct mthca_dev *dev)
int i;
u8 status;

if (dev->hca_type != ARBEL_NATIVE)
if (!mthca_is_memfree(dev))
return;

/*
Expand Down
28 changes: 14 additions & 14 deletions drivers/infiniband/hw/mthca/mthca_mr.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static u32 mthca_alloc_mtt(struct mthca_dev *dev, int order,
if (seg == -1)
return -1;

if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
if (mthca_table_get_range(dev, dev->mr_table.mtt_table, seg,
seg + (1 << order) - 1)) {
mthca_buddy_free(buddy, seg, order);
Expand All @@ -196,7 +196,7 @@ static void mthca_free_mtt(struct mthca_dev *dev, u32 seg, int order,
{
mthca_buddy_free(buddy, seg, order);

if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
mthca_table_put_range(dev, dev->mr_table.mtt_table, seg,
seg + (1 << order) - 1);
}
Expand All @@ -223,15 +223,15 @@ static inline u32 arbel_key_to_hw_index(u32 key)

static inline u32 hw_index_to_key(struct mthca_dev *dev, u32 ind)
{
if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
return arbel_hw_index_to_key(ind);
else
return tavor_hw_index_to_key(ind);
}

static inline u32 key_to_hw_index(struct mthca_dev *dev, u32 key)
{
if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
return arbel_key_to_hw_index(key);
else
return tavor_key_to_hw_index(key);
Expand All @@ -254,7 +254,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
return -ENOMEM;
mr->ibmr.rkey = mr->ibmr.lkey = hw_index_to_key(dev, key);

if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
err = mthca_table_get(dev, dev->mr_table.mpt_table, key);
if (err)
goto err_out_mpt_free;
Expand Down Expand Up @@ -299,7 +299,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
return err;

err_out_table:
if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
mthca_table_put(dev, dev->mr_table.mpt_table, key);

err_out_mpt_free:
Expand Down Expand Up @@ -329,7 +329,7 @@ int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
return -ENOMEM;
mr->ibmr.rkey = mr->ibmr.lkey = hw_index_to_key(dev, key);

if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
err = mthca_table_get(dev, dev->mr_table.mpt_table, key);
if (err)
goto err_out_mpt_free;
Expand Down Expand Up @@ -437,7 +437,7 @@ int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
mthca_free_mtt(dev, mr->first_seg, mr->order, &dev->mr_table.mtt_buddy);

err_out_table:
if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
mthca_table_put(dev, dev->mr_table.mpt_table, key);

err_out_mpt_free:
Expand All @@ -452,7 +452,7 @@ static void mthca_free_region(struct mthca_dev *dev, u32 lkey, int order,
if (order >= 0)
mthca_free_mtt(dev, first_seg, order, buddy);

if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
mthca_table_put(dev, dev->mr_table.mpt_table,
arbel_key_to_hw_index(lkey));

Expand Down Expand Up @@ -498,7 +498,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
return -EINVAL;

/* For Arbel, all MTTs must fit in the same page. */
if (dev->hca_type == ARBEL_NATIVE &&
if (mthca_is_memfree(dev) &&
mr->attr.max_pages * sizeof *mr->mem.arbel.mtts > PAGE_SIZE)
return -EINVAL;

Expand All @@ -511,7 +511,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
idx = key & (dev->limits.num_mpts - 1);
mr->ibmr.rkey = mr->ibmr.lkey = hw_index_to_key(dev, key);

if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
err = mthca_table_get(dev, dev->mr_table.mpt_table, key);
if (err)
goto err_out_mpt_free;
Expand All @@ -534,7 +534,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,

mtt_seg = mr->first_seg * MTHCA_MTT_SEG_SIZE;

if (dev->hca_type == ARBEL_NATIVE) {
if (mthca_is_memfree(dev)) {
mr->mem.arbel.mtts = mthca_table_find(dev->mr_table.mtt_table,
mr->first_seg);
BUG_ON(!mr->mem.arbel.mtts);
Expand Down Expand Up @@ -596,7 +596,7 @@ int mthca_fmr_alloc(struct mthca_dev *dev, u32 pd,
dev->mr_table.fmr_mtt_buddy);

err_out_table:
if (dev->hca_type == ARBEL_NATIVE)
if (mthca_is_memfree(dev))
mthca_table_put(dev, dev->mr_table.mpt_table, key);

err_out_mpt_free:
Expand Down Expand Up @@ -765,7 +765,7 @@ int __devinit mthca_init_mr_table(struct mthca_dev *dev)
if (err)
return err;

if (dev->hca_type != ARBEL_NATIVE &&
if (!mthca_is_memfree(dev) &&
(dev->mthca_flags & MTHCA_FLAG_DDR_HIDDEN))
dev->limits.fmr_reserved_mtts = 0;
else
Expand Down
Loading

0 comments on commit d10ddbf

Please sign in to comment.