Blame src/vma/dev/qp_mgr_eth_direct.cpp

Packit Service aa3af4
/*
Packit Service aa3af4
 * Copyright (c) 2001-2020 Mellanox Technologies, Ltd. All rights reserved.
Packit Service aa3af4
 *
Packit Service aa3af4
 * This software is available to you under a choice of one of two
Packit Service aa3af4
 * licenses.  You may choose to be licensed under the terms of the GNU
Packit Service aa3af4
 * General Public License (GPL) Version 2, available from the file
Packit Service aa3af4
 * COPYING in the main directory of this source tree, or the
Packit Service aa3af4
 * BSD license below:
Packit Service aa3af4
 *
Packit Service aa3af4
 *     Redistribution and use in source and binary forms, with or
Packit Service aa3af4
 *     without modification, are permitted provided that the following
Packit Service aa3af4
 *     conditions are met:
Packit Service aa3af4
 *
Packit Service aa3af4
 *      - Redistributions of source code must retain the above
Packit Service aa3af4
 *        copyright notice, this list of conditions and the following
Packit Service aa3af4
 *        disclaimer.
Packit Service aa3af4
 *
Packit Service aa3af4
 *      - Redistributions in binary form must reproduce the above
Packit Service aa3af4
 *        copyright notice, this list of conditions and the following
Packit Service aa3af4
 *        disclaimer in the documentation and/or other materials
Packit Service aa3af4
 *        provided with the distribution.
Packit Service aa3af4
 *
Packit Service aa3af4
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit Service aa3af4
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit Service aa3af4
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit Service aa3af4
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit Service aa3af4
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit Service aa3af4
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit Service aa3af4
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit Service aa3af4
 * SOFTWARE.
Packit Service aa3af4
 */
Packit Service aa3af4
#include "qp_mgr_eth_direct.h"
Packit Service aa3af4
#include "vlogger/vlogger.h"
Packit Service aa3af4
#include "vma/util/valgrind.h"
Packit Service aa3af4
#include "cq_mgr_mlx5.h"
Packit Service aa3af4
#include "ring_simple.h"
Packit Service aa3af4
Packit Service aa3af4
#if defined(DEFINED_DIRECT_VERBS)
Packit Service aa3af4
Packit Service aa3af4
#undef  MODULE_NAME
Packit Service aa3af4
#define MODULE_NAME 	"qp_mgr_direct"
Packit Service aa3af4
#define qp_logpanic 	__log_info_panic
Packit Service aa3af4
#define qp_logerr	__log_info_err
Packit Service aa3af4
#define qp_logwarn	__log_info_warn
Packit Service aa3af4
#define qp_loginfo	__log_info_info
Packit Service aa3af4
#define qp_logdbg	__log_info_dbg
Packit Service aa3af4
#define qp_logfunc	__log_info_func
Packit Service aa3af4
#define qp_logfuncall	__log_info_funcall
Packit Service aa3af4
Packit Service aa3af4
qp_mgr_eth_direct::qp_mgr_eth_direct(const ring_simple* p_ring,
Packit Service aa3af4
		const ib_ctx_handler* p_context, const uint8_t port_num,
Packit Service aa3af4
		ibv_comp_channel* p_rx_comp_event_channel,
Packit Service aa3af4
		const uint32_t tx_num_wr, const uint16_t vlan):
Packit Service aa3af4
			qp_mgr_eth_mlx5(p_ring, p_context, port_num,
Packit Service aa3af4
				p_rx_comp_event_channel, tx_num_wr, vlan, false)
Packit Service aa3af4
{
Packit Service aa3af4
	// must be called from this class to call derived prepare_ibv_qp
Packit Service aa3af4
	if (configure(p_rx_comp_event_channel)) {
Packit Service aa3af4
		throw_vma_exception("failed creating qp_mgr_eth");
Packit Service aa3af4
	}
Packit Service aa3af4
Packit Service aa3af4
	qp_logfunc("m_p_qp= %p", m_qp);
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
cq_mgr* qp_mgr_eth_direct::init_tx_cq_mgr()
Packit Service aa3af4
{
Packit Service aa3af4
	m_tx_num_wr = m_p_ib_ctx_handler->get_ibv_device_attr()->max_qp_wr;
Packit Service aa3af4
	return new cq_mgr_mlx5(m_p_ring, m_p_ib_ctx_handler, m_tx_num_wr, m_p_ring->get_tx_comp_event_channel(), false);
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
int qp_mgr_eth_direct::prepare_ibv_qp(vma_ibv_qp_init_attr& qp_init_attr)
Packit Service aa3af4
{
Packit Service aa3af4
	qp_init_attr.cap.max_send_wr = m_p_ib_ctx_handler->get_ibv_device_attr()->max_qp_wr;
Packit Service aa3af4
	qp_init_attr.cap.max_send_sge = 1;
Packit Service aa3af4
	qp_init_attr.cap.max_recv_sge = 1;
Packit Service aa3af4
	qp_init_attr.cap.max_inline_data = 0;
Packit Service aa3af4
#if defined(DEFINED_IBV_DEVICE_CROSS_CHANNEL)
Packit Service aa3af4
	qp_init_attr.comp_mask |= IBV_EXP_QP_INIT_ATTR_CREATE_FLAGS;
Packit Service aa3af4
	qp_init_attr.exp_create_flags |= IBV_EXP_QP_CREATE_CROSS_CHANNEL;
Packit Service aa3af4
	qp_logdbg("Cross-Channel is in qp");
Packit Service aa3af4
#else
Packit Service aa3af4
	qp_logdbg("Cross-Channel is not supported in qp");
Packit Service aa3af4
#endif /* DEFINED_IBV_DEVICE_CROSS_CHANNEL */
Packit Service aa3af4
	return qp_mgr_eth_mlx5::prepare_ibv_qp(qp_init_attr);
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
void qp_mgr_eth_direct::up()
Packit Service aa3af4
{
Packit Service aa3af4
	init_sq();
Packit Service aa3af4
	m_p_last_tx_mem_buf_desc = NULL;
Packit Service aa3af4
	modify_qp_to_ready_state();
Packit Service aa3af4
	m_p_cq_mgr_rx->add_qp_rx(this);
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
void qp_mgr_eth_direct::down()
Packit Service aa3af4
{
Packit Service aa3af4
	qp_logdbg("QP current state: %d", priv_ibv_query_qp_state(m_qp));
Packit Service aa3af4
	modify_qp_to_error_state();
Packit Service aa3af4
Packit Service aa3af4
	// let the QP drain all wqe's to flushed cqe's now that we moved
Packit Service aa3af4
	// it to error state and post_sent final trigger for completion
Packit Service aa3af4
	usleep(1000);
Packit Service aa3af4
Packit Service aa3af4
	m_p_cq_mgr_rx->del_qp_rx(this);
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
bool qp_mgr_eth_direct::fill_hw_descriptors(vma_mlx_hw_device_data &data)
Packit Service aa3af4
{
Packit Service aa3af4
	qp_logdbg("QPN: %d dbrec: %p QP.info.SQ. buf: %p wqe_cnt: %d "
Packit Service aa3af4
		"stride: %d bf.reg: %p",
Packit Service aa3af4
		m_mlx5_qp.qpn, m_mlx5_qp.sq.dbrec, m_mlx5_qp.sq.buf, m_mlx5_qp.sq.wqe_cnt,
Packit Service aa3af4
		m_mlx5_qp.sq.stride, m_mlx5_qp.bf.reg);
Packit Service aa3af4
Packit Service aa3af4
	data.sq_data.sq_num = m_mlx5_qp.qpn;
Packit Service aa3af4
	data.sq_data.wq_data.dbrec = m_mlx5_qp.sq.dbrec;
Packit Service aa3af4
	data.sq_data.wq_data.buf = m_mlx5_qp.sq.buf;
Packit Service aa3af4
	data.sq_data.wq_data.stride = m_mlx5_qp.sq.stride;
Packit Service aa3af4
	data.sq_data.wq_data.wqe_cnt = m_mlx5_qp.sq.wqe_cnt;
Packit Service aa3af4
Packit Service aa3af4
	data.sq_data.bf.reg = m_mlx5_qp.bf.reg;
Packit Service aa3af4
	data.sq_data.bf.offset = m_mlx5_qp.bf.offset;
Packit Service aa3af4
	data.sq_data.bf.size = m_mlx5_qp.bf.size;
Packit Service aa3af4
Packit Service aa3af4
	data.rq_data.wq_data.buf = m_mlx5_qp.rq.buf;
Packit Service aa3af4
	data.rq_data.wq_data.dbrec = m_mlx5_qp.rq.dbrec;
Packit Service aa3af4
	data.rq_data.wq_data.stride = m_mlx5_qp.rq.stride;
Packit Service aa3af4
	data.rq_data.wq_data.wqe_cnt = m_mlx5_qp.rq.wqe_cnt;
Packit Service aa3af4
	data.rq_data.head = &m_mlx5_qp.rq.head;
Packit Service aa3af4
	data.rq_data.tail = &m_mlx5_qp.rq.tail;
Packit Service aa3af4
Packit Service aa3af4
	return true;
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
qp_mgr_eth_direct::~qp_mgr_eth_direct()
Packit Service aa3af4
{
Packit Service aa3af4
	if (m_qp) {
Packit Service aa3af4
		IF_VERBS_FAILURE(ibv_destroy_qp(m_qp)) {
Packit Service aa3af4
			qp_logdbg("QP destroy failure (errno = %d %m)", -errno);
Packit Service aa3af4
		} ENDIF_VERBS_FAILURE;
Packit Service aa3af4
		VALGRIND_MAKE_MEM_UNDEFINED(m_qp, sizeof(ibv_qp));
Packit Service aa3af4
	}
Packit Service aa3af4
	m_qp = NULL;
Packit Service aa3af4
	delete m_p_cq_mgr_tx;
Packit Service aa3af4
	m_p_cq_mgr_tx = NULL;
Packit Service aa3af4
	delete m_p_cq_mgr_rx;
Packit Service aa3af4
	m_p_cq_mgr_rx = NULL;
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
#endif /* DEFINED_DIRECT_VERBS */