Path: blob/master/drivers/infiniband/hw/mthca/mthca_pd.c
15112 views
/*1* Copyright (c) 2004 Topspin Communications. All rights reserved.2* Copyright (c) 2005 Cisco Systems. All rights reserved.3* Copyright (c) 2005 Mellanox Technologies. All rights reserved.4*5* This software is available to you under a choice of one of two6* licenses. You may choose to be licensed under the terms of the GNU7* General Public License (GPL) Version 2, available from the file8* COPYING in the main directory of this source tree, or the9* OpenIB.org BSD license below:10*11* Redistribution and use in source and binary forms, with or12* without modification, are permitted provided that the following13* conditions are met:14*15* - Redistributions of source code must retain the above16* copyright notice, this list of conditions and the following17* disclaimer.18*19* - Redistributions in binary form must reproduce the above20* copyright notice, this list of conditions and the following21* disclaimer in the documentation and/or other materials22* provided with the distribution.23*24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE31* SOFTWARE.32*/3334#include <linux/errno.h>3536#include "mthca_dev.h"3738int mthca_pd_alloc(struct mthca_dev *dev, int privileged, struct mthca_pd *pd)39{40int err = 0;4142pd->privileged = privileged;4344atomic_set(&pd->sqp_count, 0);45pd->pd_num = mthca_alloc(&dev->pd_table.alloc);46if (pd->pd_num == -1)47return -ENOMEM;4849if (privileged) {50err = mthca_mr_alloc_notrans(dev, pd->pd_num,51MTHCA_MPT_FLAG_LOCAL_READ |52MTHCA_MPT_FLAG_LOCAL_WRITE,53&pd->ntmr);54if (err)55mthca_free(&dev->pd_table.alloc, pd->pd_num);56}5758return err;59}6061void mthca_pd_free(struct mthca_dev *dev, struct mthca_pd *pd)62{63if (pd->privileged)64mthca_free_mr(dev, &pd->ntmr);65mthca_free(&dev->pd_table.alloc, pd->pd_num);66}6768int mthca_init_pd_table(struct mthca_dev *dev)69{70return mthca_alloc_init(&dev->pd_table.alloc,71dev->limits.num_pds,72(1 << 24) - 1,73dev->limits.reserved_pds);74}7576void mthca_cleanup_pd_table(struct mthca_dev *dev)77{78/* XXX check if any PDs are still allocated? */79mthca_alloc_cleanup(&dev->pd_table.alloc);80}818283