15a2cc190SJeff Kirsher /*
25a2cc190SJeff Kirsher  * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
35a2cc190SJeff Kirsher  *
45a2cc190SJeff Kirsher  * This software is available to you under a choice of one of two
55a2cc190SJeff Kirsher  * licenses.  You may choose to be licensed under the terms of the GNU
65a2cc190SJeff Kirsher  * General Public License (GPL) Version 2, available from the file
75a2cc190SJeff Kirsher  * COPYING in the main directory of this source tree, or the
85a2cc190SJeff Kirsher  * OpenIB.org BSD license below:
95a2cc190SJeff Kirsher  *
105a2cc190SJeff Kirsher  *     Redistribution and use in source and binary forms, with or
115a2cc190SJeff Kirsher  *     without modification, are permitted provided that the following
125a2cc190SJeff Kirsher  *     conditions are met:
135a2cc190SJeff Kirsher  *
145a2cc190SJeff Kirsher  *      - Redistributions of source code must retain the above
155a2cc190SJeff Kirsher  *        copyright notice, this list of conditions and the following
165a2cc190SJeff Kirsher  *        disclaimer.
175a2cc190SJeff Kirsher  *
185a2cc190SJeff Kirsher  *      - Redistributions in binary form must reproduce the above
195a2cc190SJeff Kirsher  *        copyright notice, this list of conditions and the following
205a2cc190SJeff Kirsher  *        disclaimer in the documentation and/or other materials
215a2cc190SJeff Kirsher  *        provided with the distribution.
225a2cc190SJeff Kirsher  *
235a2cc190SJeff Kirsher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
245a2cc190SJeff Kirsher  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
255a2cc190SJeff Kirsher  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
265a2cc190SJeff Kirsher  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
275a2cc190SJeff Kirsher  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
285a2cc190SJeff Kirsher  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
295a2cc190SJeff Kirsher  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
305a2cc190SJeff Kirsher  * SOFTWARE.
315a2cc190SJeff Kirsher  *
325a2cc190SJeff Kirsher  */
335a2cc190SJeff Kirsher 
345a2cc190SJeff Kirsher #include <linux/slab.h>
355a2cc190SJeff Kirsher #include <linux/vmalloc.h>
365a2cc190SJeff Kirsher #include <linux/mlx4/qp.h>
375a2cc190SJeff Kirsher 
385a2cc190SJeff Kirsher #include "mlx4_en.h"
395a2cc190SJeff Kirsher 
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)405a2cc190SJeff Kirsher void mlx4_en_fill_qp_context(struct mlx4_en_priv *priv, int size, int stride,
415a2cc190SJeff Kirsher 			     int is_tx, int rss, int qpn, int cqn,
420e98b523SAmir Vadai 			     int user_prio, struct mlx4_qp_context *context)
435a2cc190SJeff Kirsher {
445a2cc190SJeff Kirsher 	struct mlx4_en_dev *mdev = priv->mdev;
45ec693d47SAmir Vadai 	struct net_device *dev = priv->dev;
465a2cc190SJeff Kirsher 
4731975e27Sstephen hemminger 	memset(context, 0, sizeof(*context));
48876f6e67SOr Gerlitz 	context->flags = cpu_to_be32(7 << 16 | rss << MLX4_RSS_QPC_FLAG_OFFSET);
495a2cc190SJeff Kirsher 	context->pd = cpu_to_be32(mdev->priv_pdn);
505a2cc190SJeff Kirsher 	context->mtu_msgmax = 0xff;
515a2cc190SJeff Kirsher 	if (!is_tx && !rss)
525a2cc190SJeff Kirsher 		context->rq_size_stride = ilog2(size) << 3 | (ilog2(stride) - 4);
5353f33ae2SMoni Shoua 	if (is_tx) {
545a2cc190SJeff Kirsher 		context->sq_size_stride = ilog2(size) << 3 | (ilog2(stride) - 4);
5553f33ae2SMoni Shoua 		if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PORT_REMAP)
56bb428a5cSTariq Toukan 			context->params2 |= cpu_to_be32(MLX4_QP_BIT_FPP);
5753f33ae2SMoni Shoua 
5853f33ae2SMoni Shoua 	} else {
595a2cc190SJeff Kirsher 		context->sq_size_stride = ilog2(TXBB_SIZE) - 4;
6053f33ae2SMoni Shoua 	}
6185743f1eSHuy Nguyen 	context->usr_page = cpu_to_be32(mlx4_to_hw_uar_index(mdev->dev,
6285743f1eSHuy Nguyen 					mdev->priv_uar.index));
635a2cc190SJeff Kirsher 	context->local_qpn = cpu_to_be32(qpn);
645a2cc190SJeff Kirsher 	context->pri_path.ackto = 1 & 0x07;
655a2cc190SJeff Kirsher 	context->pri_path.sched_queue = 0x83 | (priv->port - 1) << 6;
66ec327f7aSInbar Karmy 	/* force user priority per tx ring */
67ec327f7aSInbar Karmy 	if (user_prio >= 0 && priv->prof->num_up == MLX4_EN_NUM_UP_HIGH) {
680e98b523SAmir Vadai 		context->pri_path.sched_queue |= user_prio << 3;
697677fc96SRony Efraim 		context->pri_path.feup = MLX4_FEUP_FORCE_ETH_UP;
700e98b523SAmir Vadai 	}
716de5f7f6SEran Ben Elisha 	context->pri_path.counter_index = priv->counter_index;
725a2cc190SJeff Kirsher 	context->cqn_send = cpu_to_be32(cqn);
735a2cc190SJeff Kirsher 	context->cqn_recv = cpu_to_be32(cqn);
7474194fb9SMaor Gottlieb 	if (!rss &&
7574194fb9SMaor Gottlieb 	    (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_LB_SRC_CHK) &&
7674194fb9SMaor Gottlieb 	    context->pri_path.counter_index !=
7774194fb9SMaor Gottlieb 			    MLX4_SINK_COUNTER_INDEX(mdev->dev)) {
7874194fb9SMaor Gottlieb 		/* disable multicast loopback to qp with same counter */
7974194fb9SMaor Gottlieb 		if (!(dev->features & NETIF_F_LOOPBACK))
8074194fb9SMaor Gottlieb 			context->pri_path.fl |= MLX4_FL_ETH_SRC_CHECK_MC_LB;
8174194fb9SMaor Gottlieb 		context->pri_path.control |= MLX4_CTRL_ETH_SRC_CHECK_IF_COUNTER;
8274194fb9SMaor Gottlieb 	}
835a2cc190SJeff Kirsher 	context->db_rec_addr = cpu_to_be64(priv->res.db.dma << 2);
84ec693d47SAmir Vadai 	if (!(dev->features & NETIF_F_HW_VLAN_CTAG_RX))
85ec693d47SAmir Vadai 		context->param3 |= cpu_to_be32(1 << 30);
86837052d0SOr Gerlitz 
87837052d0SOr Gerlitz 	if (!is_tx && !rss &&
88837052d0SOr Gerlitz 	    (mdev->dev->caps.tunnel_offload_mode ==  MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)) {
89837052d0SOr Gerlitz 		en_dbg(HW, priv, "Setting RX qp %x tunnel mode to RX tunneled & non-tunneled\n", qpn);
90837052d0SOr Gerlitz 		context->srqn = cpu_to_be32(7 << 28); /* this fills bits 30:28 */
91837052d0SOr Gerlitz 	}
925a2cc190SJeff Kirsher }
935a2cc190SJeff Kirsher 
mlx4_en_change_mcast_lb(struct mlx4_en_priv * priv,struct mlx4_qp * qp,int loopback)9474194fb9SMaor Gottlieb int mlx4_en_change_mcast_lb(struct mlx4_en_priv *priv, struct mlx4_qp *qp,
9574194fb9SMaor Gottlieb 			    int loopback)
9674194fb9SMaor Gottlieb {
9774194fb9SMaor Gottlieb 	int ret;
9874194fb9SMaor Gottlieb 	struct mlx4_update_qp_params qp_params;
9974194fb9SMaor Gottlieb 
10074194fb9SMaor Gottlieb 	memset(&qp_params, 0, sizeof(qp_params));
10174194fb9SMaor Gottlieb 	if (!loopback)
10274194fb9SMaor Gottlieb 		qp_params.flags = MLX4_UPDATE_QP_PARAMS_FLAGS_ETH_CHECK_MC_LB;
10374194fb9SMaor Gottlieb 
10474194fb9SMaor Gottlieb 	ret = mlx4_update_qp(priv->mdev->dev, qp->qpn,
10574194fb9SMaor Gottlieb 			     MLX4_UPDATE_QP_ETH_SRC_CHECK_MC_LB,
10674194fb9SMaor Gottlieb 			     &qp_params);
10774194fb9SMaor Gottlieb 
10874194fb9SMaor Gottlieb 	return ret;
10974194fb9SMaor Gottlieb }
1105a2cc190SJeff Kirsher 
mlx4_en_sqp_event(struct mlx4_qp * qp,enum mlx4_event event)1115a2cc190SJeff Kirsher void mlx4_en_sqp_event(struct mlx4_qp *qp, enum mlx4_event event)
1125a2cc190SJeff Kirsher {
1135a2cc190SJeff Kirsher     return;
1145a2cc190SJeff Kirsher }
1155a2cc190SJeff Kirsher 
116