1219820Sjeff/* 2272027Shselasky * Copyright (c) 2007, 2014 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 34272027Shselasky#include <linux/slab.h> 35219820Sjeff#include <linux/vmalloc.h> 36306486Shselasky#include <dev/mlx4/qp.h> 37219820Sjeff 38306486Shselasky#include "en.h" 39219820Sjeff 40272027Shselasky 41219820Sjeffvoid mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int size, int stride, 42219820Sjeff int is_tx, int rss, int qpn, int cqn, 43272027Shselasky int user_prio, struct mlx4_qp_context *context) 44219820Sjeff{ 45219820Sjeff struct mlx4_en_dev *mdev = priv->mdev; 46272027Shselasky struct net_device *dev = priv->dev; 47219820Sjeff 48219820Sjeff memset(context, 0, sizeof *context); 49272027Shselasky context->flags = cpu_to_be32(7 << 16 | rss << MLX4_RSS_QPC_FLAG_OFFSET); 50219820Sjeff context->pd = cpu_to_be32(mdev->priv_pdn); 51219820Sjeff context->mtu_msgmax = 0xff; 52272027Shselasky if (!is_tx && !rss) 53219820Sjeff context->rq_size_stride = ilog2(size) << 3 | (ilog2(stride) - 4); 54219820Sjeff if (is_tx) 55219820Sjeff context->sq_size_stride = ilog2(size) << 3 | (ilog2(stride) - 4); 56219820Sjeff else 57219820Sjeff context->sq_size_stride = ilog2(TXBB_SIZE) - 4; 58219820Sjeff context->usr_page = cpu_to_be32(mdev->priv_uar.index); 59219820Sjeff context->local_qpn = cpu_to_be32(qpn); 60219820Sjeff context->pri_path.ackto = 1 & 0x07; 61219820Sjeff context->pri_path.sched_queue = 0x83 | (priv->port - 1) << 6; 62272027Shselasky if (user_prio >= 0) { 63272027Shselasky context->pri_path.sched_queue |= user_prio << 3; 64272027Shselasky context->pri_path.feup = 1 << 6; 65272027Shselasky } 66272027Shselasky context->pri_path.counter_index = (u8)(priv->counter_index); 67272027Shselasky if (!rss && 68272027Shselasky (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_LB_SRC_CHK) && 69272027Shselasky context->pri_path.counter_index != 0xFF) { 70272027Shselasky /* disable multicast loopback to qp with same counter */ 71272027Shselasky context->pri_path.fl |= MLX4_FL_ETH_SRC_CHECK_MC_LB; 72272027Shselasky context->pri_path.vlan_control |= 73329159Shselasky MLX4_CTRL_ETH_SRC_CHECK_IF_COUNTER; 74272027Shselasky } 75272027Shselasky 76219820Sjeff context->cqn_send = cpu_to_be32(cqn); 77219820Sjeff context->cqn_recv = cpu_to_be32(cqn); 78219820Sjeff context->db_rec_addr = cpu_to_be64(priv->res.db.dma << 2); 79272027Shselasky if (!(dev->if_capabilities & IFCAP_VLAN_HWCSUM)) 80272027Shselasky context->param3 |= cpu_to_be32(1 << 30); 81219820Sjeff} 82219820Sjeff 83219820Sjeff 84219820Sjeffint mlx4_en_map_buffer(struct mlx4_buf *buf) 85219820Sjeff{ 86219820Sjeff struct page **pages; 87219820Sjeff int i; 88219820Sjeff 89272027Shselasky // if nbufs == 1 - there is no need to vmap 90272027Shselasky // if buf->direct.buf is not NULL it means that vmap was already done by mlx4_alloc_buff 91219820Sjeff if (buf->direct.buf != NULL || buf->nbufs == 1) 92219820Sjeff return 0; 93219820Sjeff 94219820Sjeff pages = kmalloc(sizeof *pages * buf->nbufs, GFP_KERNEL); 95219820Sjeff if (!pages) 96219820Sjeff return -ENOMEM; 97219820Sjeff 98219820Sjeff for (i = 0; i < buf->nbufs; ++i) 99219820Sjeff pages[i] = virt_to_page(buf->page_list[i].buf); 100219820Sjeff 101219820Sjeff buf->direct.buf = vmap(pages, buf->nbufs, VM_MAP, PAGE_KERNEL); 102219820Sjeff kfree(pages); 103219820Sjeff if (!buf->direct.buf) 104219820Sjeff return -ENOMEM; 105219820Sjeff 106219820Sjeff return 0; 107219820Sjeff} 108219820Sjeff 109219820Sjeffvoid mlx4_en_unmap_buffer(struct mlx4_buf *buf) 110219820Sjeff{ 111272027Shselasky if (BITS_PER_LONG == 64 || buf->nbufs == 1) 112219820Sjeff return; 113219820Sjeff 114219820Sjeff vunmap(buf->direct.buf); 115219820Sjeff} 116219820Sjeff 117219820Sjeffvoid mlx4_en_sqp_event(struct mlx4_qp *qp, enum mlx4_event event) 118219820Sjeff{ 119219820Sjeff return; 120219820Sjeff} 121219820Sjeff 122