--- drivers/infiniband/hw/siw/siw_mem.c | 180 +++++++++++++++++++++++++++++++++++ 1 files changed, 180 insertions(+), 0 deletions(-) create mode 100644 drivers/infiniband/hw/siw/siw_mem.c
diff --git a/drivers/infiniband/hw/siw/siw_mem.c b/drivers/infiniband/hw/siw/siw_mem.c new file mode 100644 index 0000000..8a3d65d --- /dev/null +++ b/drivers/infiniband/hw/siw/siw_mem.c @@ -0,0 +1,180 @@ +/* + * Software iWARP device driver for Linux + * + * Authors: Animesh Trivedi <[email protected]> + * Bernard Metzler <[email protected]> + * + * Copyright (c) 2008-2011, IBM Corporation + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of IBM nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include <linux/scatterlist.h> +#include <linux/gfp.h> +#include <rdma/ib_verbs.h> + +#include "siw.h" +#include "siw_verbs.h" + +/* + * DMA mapping/address translation functions. + * Used to populate siw private DMA mapping functions of + * struct ib_dma_mapping_ops in struct ib_dev - see rdma/ib_verbs.h + */ + +static int siw_mapping_error(struct ib_device *dev, u64 dma_addr) +{ + return dma_addr == 0; +} + +static u64 siw_dma_map_single(struct ib_device *dev, void *kva, size_t size, + enum dma_data_direction dir) +{ + /* siw uses kernel virtual addresses for data transfer */ + return (u64) kva; +} + +static void siw_dma_unmap_single(struct ib_device *dev, + u64 addr, size_t size, + enum dma_data_direction dir) +{ + /* NOP */ +} + +static u64 siw_dma_map_page(struct ib_device *dev, struct page *page, + unsigned long offset, size_t size, + enum dma_data_direction dir) +{ + u64 kva = 0; + + BUG_ON(!valid_dma_direction(dir)); + + if (offset + size <= PAGE_SIZE) { + kva = (u64) page_address(page); + if (kva) + kva += offset; + } + return kva; +} + +static void siw_dma_unmap_page(struct ib_device *dev, + u64 addr, size_t size, + enum dma_data_direction dir) +{ + /* NOP */ +} + +static int siw_map_sg(struct ib_device *dev, struct scatterlist *sgl, + int n_sge, enum dma_data_direction dir) +{ + struct scatterlist *sg; + int i; + + BUG_ON(!valid_dma_direction(dir)); + + /* This is just a validity check */ + for_each_sg(sgl, sg, n_sge, i) + if (page_address(sg_page(sg)) == NULL) + return 0; + + return n_sge; +} + +static void siw_unmap_sg(struct ib_device *dev, struct scatterlist *sgl, + int n_sge, enum dma_data_direction dir) +{ + /* NOP */ +} + +static u64 siw_dma_address(struct ib_device *dev, struct scatterlist *sg) +{ + u64 kva = (u64) page_address(sg_page(sg)); + + if (kva) + kva += sg->offset; + + return kva; +} + +static unsigned int siw_dma_len(struct ib_device *dev, + struct scatterlist *sg) +{ + return sg_dma_len(sg); +} + +static void siw_sync_single_for_cpu(struct ib_device *dev, u64 addr, + size_t size, enum dma_data_direction dir) +{ + /* NOP */ +} + +static void siw_sync_single_for_device(struct ib_device *dev, u64 addr, + size_t size, + enum dma_data_direction dir) +{ + /* NOP */ +} + +static void *siw_dma_alloc_coherent(struct ib_device *dev, size_t size, + u64 *dma_addr, gfp_t flag) +{ + struct page *page; + void *kva = NULL; + + page = alloc_pages(flag, get_order(size)); + if (page) + kva = page_address(page); + if (dma_addr) + *dma_addr = (u64)kva; + + return kva; +} + +static void siw_dma_free_coherent(struct ib_device *dev, size_t size, + void *kva, u64 dma_addr) +{ + free_pages((unsigned long) kva, get_order(size)); +} + +struct ib_dma_mapping_ops siw_dma_mapping_ops = { + .mapping_error = siw_mapping_error, + .map_single = siw_dma_map_single, + .unmap_single = siw_dma_unmap_single, + .map_page = siw_dma_map_page, + .unmap_page = siw_dma_unmap_page, + .map_sg = siw_map_sg, + .unmap_sg = siw_unmap_sg, + .dma_address = siw_dma_address, + .dma_len = siw_dma_len, + .sync_single_for_cpu = siw_sync_single_for_cpu, + .sync_single_for_device = siw_sync_single_for_device, + .alloc_coherent = siw_dma_alloc_coherent, + .free_coherent = siw_dma_free_coherent +}; -- 1.5.4.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
