Path: blob/master/drivers/infiniband/hw/mthca/mthca_uar.c
15112 views
/*1* Copyright (c) 2005 Topspin Communications. All rights reserved.2*3* This software is available to you under a choice of one of two4* licenses. You may choose to be licensed under the terms of the GNU5* General Public License (GPL) Version 2, available from the file6* COPYING in the main directory of this source tree, or the7* OpenIB.org BSD license below:8*9* Redistribution and use in source and binary forms, with or10* without modification, are permitted provided that the following11* conditions are met:12*13* - Redistributions of source code must retain the above14* copyright notice, this list of conditions and the following15* disclaimer.16*17* - Redistributions in binary form must reproduce the above18* copyright notice, this list of conditions and the following19* disclaimer in the documentation and/or other materials20* provided with the distribution.21*22* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,23* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF24* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND25* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS26* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN27* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN28* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE29* SOFTWARE.30*/3132#include <asm/page.h> /* PAGE_SHIFT */3334#include "mthca_dev.h"35#include "mthca_memfree.h"3637int mthca_uar_alloc(struct mthca_dev *dev, struct mthca_uar *uar)38{39uar->index = mthca_alloc(&dev->uar_table.alloc);40if (uar->index == -1)41return -ENOMEM;4243uar->pfn = (pci_resource_start(dev->pdev, 2) >> PAGE_SHIFT) + uar->index;4445return 0;46}4748void mthca_uar_free(struct mthca_dev *dev, struct mthca_uar *uar)49{50mthca_free(&dev->uar_table.alloc, uar->index);51}5253int mthca_init_uar_table(struct mthca_dev *dev)54{55int ret;5657ret = mthca_alloc_init(&dev->uar_table.alloc,58dev->limits.num_uars,59dev->limits.num_uars - 1,60dev->limits.reserved_uars + 1);61if (ret)62return ret;6364ret = mthca_init_db_tab(dev);65if (ret)66mthca_alloc_cleanup(&dev->uar_table.alloc);6768return ret;69}7071void mthca_cleanup_uar_table(struct mthca_dev *dev)72{73mthca_cleanup_db_tab(dev);7475/* XXX check if any UARs are still allocated? */76mthca_alloc_cleanup(&dev->uar_table.alloc);77}787980