1219820Sjeff/*
2219820Sjeff * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
3219820Sjeff *
4219820Sjeff * This software is available to you under a choice of one of two
5219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
6219820Sjeff * General Public License (GPL) Version 2, available from the file
7219820Sjeff * COPYING in the main directory of this source tree, or the
8219820Sjeff * OpenIB.org BSD license below:
9219820Sjeff *
10219820Sjeff *     Redistribution and use in source and binary forms, with or
11219820Sjeff *     without modification, are permitted provided that the following
12219820Sjeff *     conditions are met:
13219820Sjeff *
14219820Sjeff *      - Redistributions of source code must retain the above
15219820Sjeff *        copyright notice, this list of conditions and the following
16219820Sjeff *        disclaimer.
17219820Sjeff *
18219820Sjeff *      - Redistributions in binary form must reproduce the above
19219820Sjeff *        copyright notice, this list of conditions and the following
20219820Sjeff *        disclaimer in the documentation and/or other materials
21219820Sjeff *        provided with the distribution.
22219820Sjeff *
23219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30219820Sjeff * SOFTWARE.
31219820Sjeff *
32219820Sjeff */
33219820Sjeff
34219820Sjeff#include <linux/vmalloc.h>
35219820Sjeff#include <linux/mlx4/qp.h>
36219820Sjeff
37219820Sjeff#include "mlx4_en.h"
38219820Sjeff
39219820Sjeffvoid mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int size, int stride,
40219820Sjeff			     int is_tx, int rss, int qpn, int cqn,
41219820Sjeff			     struct mlx4_qp_context *context)
42219820Sjeff{
43219820Sjeff	struct mlx4_en_dev *mdev = priv->mdev;
44219820Sjeff
45219820Sjeff	memset(context, 0, sizeof *context);
46219820Sjeff	context->flags = cpu_to_be32(7 << 16 | rss << 13);
47219820Sjeff	context->pd = cpu_to_be32(mdev->priv_pdn);
48219820Sjeff	context->mtu_msgmax = 0xff;
49219820Sjeff	if (!is_tx && !rss) {
50219820Sjeff		context->rq_size_stride = ilog2(size) << 3 | (ilog2(stride) - 4);
51219820Sjeff	}
52219820Sjeff	if (is_tx)
53219820Sjeff		context->sq_size_stride = ilog2(size) << 3 | (ilog2(stride) - 4);
54219820Sjeff	else
55219820Sjeff		context->sq_size_stride = ilog2(TXBB_SIZE) - 4;
56219820Sjeff	context->usr_page = cpu_to_be32(mdev->priv_uar.index);
57219820Sjeff	context->local_qpn = cpu_to_be32(qpn);
58219820Sjeff	context->pri_path.ackto = 1 & 0x07;
59219820Sjeff	context->pri_path.sched_queue = 0x83 | (priv->port - 1) << 6;
60219820Sjeff	context->pri_path.counter_index = 0xff;
61219820Sjeff	context->cqn_send = cpu_to_be32(cqn);
62219820Sjeff	context->cqn_recv = cpu_to_be32(cqn);
63219820Sjeff	context->db_rec_addr = cpu_to_be64(priv->res.db.dma << 2);
64219820Sjeff}
65219820Sjeff
66219820Sjeff
67219820Sjeffint mlx4_en_map_buffer(struct mlx4_buf *buf)
68219820Sjeff{
69219820Sjeff	struct page **pages;
70219820Sjeff	int i;
71219820Sjeff
72219820Sjeff	if (buf->direct.buf != NULL || buf->nbufs == 1)
73219820Sjeff		return 0;
74219820Sjeff
75219820Sjeff	pages = kmalloc(sizeof *pages * buf->nbufs, GFP_KERNEL);
76219820Sjeff	if (!pages)
77219820Sjeff		return -ENOMEM;
78219820Sjeff
79219820Sjeff	for (i = 0; i < buf->nbufs; ++i)
80219820Sjeff		pages[i] = virt_to_page(buf->page_list[i].buf);
81219820Sjeff
82219820Sjeff	buf->direct.buf = vmap(pages, buf->nbufs, VM_MAP, PAGE_KERNEL);
83219820Sjeff	kfree(pages);
84219820Sjeff	if (!buf->direct.buf)
85219820Sjeff		return -ENOMEM;
86219820Sjeff
87219820Sjeff	return 0;
88219820Sjeff}
89219820Sjeff
90219820Sjeffvoid mlx4_en_unmap_buffer(struct mlx4_buf *buf)
91219820Sjeff{
92219820Sjeff	if (buf->direct.buf != NULL || buf->nbufs == 1)
93219820Sjeff		return;
94219820Sjeff
95219820Sjeff	vunmap(buf->direct.buf);
96219820Sjeff	buf->direct.buf = NULL;
97219820Sjeff}
98219820Sjeff
99219820Sjeffvoid mlx4_en_sqp_event(struct mlx4_qp *qp, enum mlx4_event event)
100219820Sjeff{
101219820Sjeff    return;
102219820Sjeff}
103219820Sjeff
104