197549c34SHans Petter Selasky /*
297549c34SHans Petter Selasky * Copyright (c) 2007, 2014 Mellanox Technologies. All rights reserved.
397549c34SHans Petter Selasky *
497549c34SHans Petter Selasky * This software is available to you under a choice of one of two
597549c34SHans Petter Selasky * licenses. You may choose to be licensed under the terms of the GNU
697549c34SHans Petter Selasky * General Public License (GPL) Version 2, available from the file
797549c34SHans Petter Selasky * COPYING in the main directory of this source tree, or the
897549c34SHans Petter Selasky * OpenIB.org BSD license below:
997549c34SHans Petter Selasky *
1097549c34SHans Petter Selasky * Redistribution and use in source and binary forms, with or
1197549c34SHans Petter Selasky * without modification, are permitted provided that the following
1297549c34SHans Petter Selasky * conditions are met:
1397549c34SHans Petter Selasky *
1497549c34SHans Petter Selasky * - Redistributions of source code must retain the above
1597549c34SHans Petter Selasky * copyright notice, this list of conditions and the following
1697549c34SHans Petter Selasky * disclaimer.
1797549c34SHans Petter Selasky *
1897549c34SHans Petter Selasky * - Redistributions in binary form must reproduce the above
1997549c34SHans Petter Selasky * copyright notice, this list of conditions and the following
2097549c34SHans Petter Selasky * disclaimer in the documentation and/or other materials
2197549c34SHans Petter Selasky * provided with the distribution.
2297549c34SHans Petter Selasky *
2397549c34SHans Petter Selasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2497549c34SHans Petter Selasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2597549c34SHans Petter Selasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2697549c34SHans Petter Selasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2797549c34SHans Petter Selasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2897549c34SHans Petter Selasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2997549c34SHans Petter Selasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3097549c34SHans Petter Selasky * SOFTWARE.
3197549c34SHans Petter Selasky *
3297549c34SHans Petter Selasky */
3397549c34SHans Petter Selasky
3497549c34SHans Petter Selasky #include <linux/slab.h>
3597549c34SHans Petter Selasky #include <linux/vmalloc.h>
3697549c34SHans Petter Selasky #include <dev/mlx4/qp.h>
3797549c34SHans Petter Selasky
3897549c34SHans Petter Selasky #include "en.h"
3997549c34SHans Petter Selasky
4097549c34SHans Petter Selasky
mlx4_en_fill_qp_context(struct mlx4_en_priv * priv,int size,int stride,int is_tx,int rss,int qpn,int cqn,int user_prio,struct mlx4_qp_context * context)4197549c34SHans Petter Selasky void mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int size, int stride,
4297549c34SHans Petter Selasky int is_tx, int rss, int qpn, int cqn,
4397549c34SHans Petter Selasky int user_prio, struct mlx4_qp_context *context)
4497549c34SHans Petter Selasky {
4597549c34SHans Petter Selasky struct mlx4_en_dev *mdev = priv->mdev;
46*0b281376SJustin Hibbits if_t dev = priv->dev;
4797549c34SHans Petter Selasky
4897549c34SHans Petter Selasky memset(context, 0, sizeof *context);
4997549c34SHans Petter Selasky context->flags = cpu_to_be32(7 << 16 | rss << MLX4_RSS_QPC_FLAG_OFFSET);
5097549c34SHans Petter Selasky context->pd = cpu_to_be32(mdev->priv_pdn);
5197549c34SHans Petter Selasky context->mtu_msgmax = 0xff;
5297549c34SHans Petter Selasky if (!is_tx && !rss)
5397549c34SHans Petter Selasky context->rq_size_stride = ilog2(size) << 3 | (ilog2(stride) - 4);
5497549c34SHans Petter Selasky if (is_tx)
5597549c34SHans Petter Selasky context->sq_size_stride = ilog2(size) << 3 | (ilog2(stride) - 4);
5697549c34SHans Petter Selasky else
5797549c34SHans Petter Selasky context->sq_size_stride = ilog2(TXBB_SIZE) - 4;
5897549c34SHans Petter Selasky context->usr_page = cpu_to_be32(mdev->priv_uar.index);
5997549c34SHans Petter Selasky context->local_qpn = cpu_to_be32(qpn);
6097549c34SHans Petter Selasky context->pri_path.ackto = 1 & 0x07;
6197549c34SHans Petter Selasky context->pri_path.sched_queue = 0x83 | (priv->port - 1) << 6;
6297549c34SHans Petter Selasky if (user_prio >= 0) {
6397549c34SHans Petter Selasky context->pri_path.sched_queue |= user_prio << 3;
6497549c34SHans Petter Selasky context->pri_path.feup = 1 << 6;
6597549c34SHans Petter Selasky }
6697549c34SHans Petter Selasky context->pri_path.counter_index = (u8)(priv->counter_index);
6797549c34SHans Petter Selasky if (!rss &&
6897549c34SHans Petter Selasky (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_LB_SRC_CHK) &&
6997549c34SHans Petter Selasky context->pri_path.counter_index != 0xFF) {
7097549c34SHans Petter Selasky /* disable multicast loopback to qp with same counter */
7197549c34SHans Petter Selasky context->pri_path.fl |= MLX4_FL_ETH_SRC_CHECK_MC_LB;
7297549c34SHans Petter Selasky context->pri_path.vlan_control |=
73c3191c2eSHans Petter Selasky MLX4_CTRL_ETH_SRC_CHECK_IF_COUNTER;
7497549c34SHans Petter Selasky }
7597549c34SHans Petter Selasky
7697549c34SHans Petter Selasky context->cqn_send = cpu_to_be32(cqn);
7797549c34SHans Petter Selasky context->cqn_recv = cpu_to_be32(cqn);
7897549c34SHans Petter Selasky context->db_rec_addr = cpu_to_be64(priv->res.db.dma << 2);
79*0b281376SJustin Hibbits if (!(if_getcapabilities(dev) & IFCAP_VLAN_HWCSUM))
8097549c34SHans Petter Selasky context->param3 |= cpu_to_be32(1 << 30);
8197549c34SHans Petter Selasky }
8297549c34SHans Petter Selasky
8397549c34SHans Petter Selasky
mlx4_en_map_buffer(struct mlx4_buf * buf)8497549c34SHans Petter Selasky int mlx4_en_map_buffer(struct mlx4_buf *buf)
8597549c34SHans Petter Selasky {
8697549c34SHans Petter Selasky struct page **pages;
8797549c34SHans Petter Selasky int i;
8897549c34SHans Petter Selasky
8997549c34SHans Petter Selasky // if nbufs == 1 - there is no need to vmap
9097549c34SHans Petter Selasky // if buf->direct.buf is not NULL it means that vmap was already done by mlx4_alloc_buff
9197549c34SHans Petter Selasky if (buf->direct.buf != NULL || buf->nbufs == 1)
9297549c34SHans Petter Selasky return 0;
9397549c34SHans Petter Selasky
9497549c34SHans Petter Selasky pages = kmalloc(sizeof *pages * buf->nbufs, GFP_KERNEL);
9597549c34SHans Petter Selasky if (!pages)
9697549c34SHans Petter Selasky return -ENOMEM;
9797549c34SHans Petter Selasky
9897549c34SHans Petter Selasky for (i = 0; i < buf->nbufs; ++i)
9997549c34SHans Petter Selasky pages[i] = virt_to_page(buf->page_list[i].buf);
10097549c34SHans Petter Selasky
10197549c34SHans Petter Selasky buf->direct.buf = vmap(pages, buf->nbufs, VM_MAP, PAGE_KERNEL);
10297549c34SHans Petter Selasky kfree(pages);
10397549c34SHans Petter Selasky if (!buf->direct.buf)
10497549c34SHans Petter Selasky return -ENOMEM;
10597549c34SHans Petter Selasky
10697549c34SHans Petter Selasky return 0;
10797549c34SHans Petter Selasky }
10897549c34SHans Petter Selasky
mlx4_en_unmap_buffer(struct mlx4_buf * buf)10997549c34SHans Petter Selasky void mlx4_en_unmap_buffer(struct mlx4_buf *buf)
11097549c34SHans Petter Selasky {
11197549c34SHans Petter Selasky if (BITS_PER_LONG == 64 || buf->nbufs == 1)
11297549c34SHans Petter Selasky return;
11397549c34SHans Petter Selasky
11497549c34SHans Petter Selasky vunmap(buf->direct.buf);
11597549c34SHans Petter Selasky }
11697549c34SHans Petter Selasky
mlx4_en_sqp_event(struct mlx4_qp * qp,enum mlx4_event event)11797549c34SHans Petter Selasky void mlx4_en_sqp_event(struct mlx4_qp *qp, enum mlx4_event event)
11897549c34SHans Petter Selasky {
11997549c34SHans Petter Selasky return;
12097549c34SHans Petter Selasky }
12197549c34SHans Petter Selasky
122