mlx4_en_resources.c revision 219820
1115013Smarcel/*
2115013Smarcel * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
3115013Smarcel *
4115013Smarcel * This software is available to you under a choice of one of two
5115013Smarcel * licenses.  You may choose to be licensed under the terms of the GNU
6115013Smarcel * General Public License (GPL) Version 2, available from the file
7115013Smarcel * COPYING in the main directory of this source tree, or the
8115013Smarcel * OpenIB.org BSD license below:
9115013Smarcel *
10115013Smarcel *     Redistribution and use in source and binary forms, with or
11120925Smarcel *     without modification, are permitted provided that the following
12117392Smarcel *     conditions are met:
13115013Smarcel *
14115013Smarcel *      - Redistributions of source code must retain the above
15120925Smarcel *        copyright notice, this list of conditions and the following
16115013Smarcel *        disclaimer.
17115013Smarcel *
18160157Smarcel *      - Redistributions in binary form must reproduce the above
19160157Smarcel *        copyright notice, this list of conditions and the following
20115013Smarcel *        disclaimer in the documentation and/or other materials
21115013Smarcel *        provided with the distribution.
22160157Smarcel *
23160157Smarcel * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24115013Smarcel * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25115013Smarcel * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26115013Smarcel * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27115013Smarcel * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28115013Smarcel * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29115013Smarcel * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30115013Smarcel * SOFTWARE.
31115013Smarcel *
32115013Smarcel */
33115013Smarcel
34115013Smarcel#include <linux/vmalloc.h>
35115013Smarcel#include <linux/mlx4/qp.h>
36115013Smarcel
37115013Smarcel#include "mlx4_en.h"
38160157Smarcel
39160157Smarcelvoid mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int size, int stride,
40160157Smarcel			     int is_tx, int rss, int qpn, int cqn,
41115013Smarcel			     struct mlx4_qp_context *context)
42115013Smarcel{
43120925Smarcel	struct mlx4_en_dev *mdev = priv->mdev;
44115013Smarcel
45115013Smarcel	memset(context, 0, sizeof *context);
46115013Smarcel	context->flags = cpu_to_be32(7 << 16 | rss << 13);
47115013Smarcel	context->pd = cpu_to_be32(mdev->priv_pdn);
48115013Smarcel	context->mtu_msgmax = 0xff;
49115013Smarcel	if (!is_tx && !rss) {
50115013Smarcel		context->rq_size_stride = ilog2(size) << 3 | (ilog2(stride) - 4);
51115013Smarcel	}
52115013Smarcel	if (is_tx)
53115013Smarcel		context->sq_size_stride = ilog2(size) << 3 | (ilog2(stride) - 4);
54115013Smarcel	else
55115013Smarcel		context->sq_size_stride = ilog2(TXBB_SIZE) - 4;
56160157Smarcel	context->usr_page = cpu_to_be32(mdev->priv_uar.index);
57160157Smarcel	context->local_qpn = cpu_to_be32(qpn);
58115013Smarcel	context->pri_path.ackto = 1 & 0x07;
59115013Smarcel	context->pri_path.sched_queue = 0x83 | (priv->port - 1) << 6;
60115013Smarcel	context->pri_path.counter_index = 0xff;
61115013Smarcel	context->cqn_send = cpu_to_be32(cqn);
62115013Smarcel	context->cqn_recv = cpu_to_be32(cqn);
63115013Smarcel	context->db_rec_addr = cpu_to_be64(priv->res.db.dma << 2);
64115013Smarcel}
65160157Smarcel
66160157Smarcel
67115013Smarcelint mlx4_en_map_buffer(struct mlx4_buf *buf)
68115013Smarcel{
69115013Smarcel	struct page **pages;
70115013Smarcel	int i;
71115013Smarcel
72	if (buf->direct.buf != NULL || buf->nbufs == 1)
73		return 0;
74
75	pages = kmalloc(sizeof *pages * buf->nbufs, GFP_KERNEL);
76	if (!pages)
77		return -ENOMEM;
78
79	for (i = 0; i < buf->nbufs; ++i)
80		pages[i] = virt_to_page(buf->page_list[i].buf);
81
82	buf->direct.buf = vmap(pages, buf->nbufs, VM_MAP, PAGE_KERNEL);
83	kfree(pages);
84	if (!buf->direct.buf)
85		return -ENOMEM;
86
87	return 0;
88}
89
90void mlx4_en_unmap_buffer(struct mlx4_buf *buf)
91{
92	if (buf->direct.buf != NULL || buf->nbufs == 1)
93		return;
94
95	vunmap(buf->direct.buf);
96	buf->direct.buf = NULL;
97}
98
99void mlx4_en_sqp_event(struct mlx4_qp *qp, enum mlx4_event event)
100{
101    return;
102}
103
104