Blame src/vma/dev/ring_profile.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
Packit Service aa3af4
#include <dev/ring_profile.h>
Packit Service aa3af4
Packit Service aa3af4
ring_profiles_collection *g_p_ring_profile = NULL;
Packit Service aa3af4
Packit Service aa3af4
Packit Service aa3af4
ring_profile::ring_profile(const vma_ring_type_attr *ring_desc) {
Packit Service aa3af4
	m_ring_desc.comp_mask = ring_desc->comp_mask;
Packit Service aa3af4
	m_ring_desc.ring_type = ring_desc->ring_type;
Packit Service aa3af4
	switch (ring_desc->ring_type) {
Packit Service aa3af4
	case VMA_RING_CYCLIC_BUFFER: {
Packit Service aa3af4
		vma_cyclic_buffer_ring_attr &r = m_ring_desc.ring_cyclicb;
Packit Service aa3af4
Packit Service aa3af4
		memset(&r, 0, sizeof(m_ring_desc.ring_cyclicb));
Packit Service aa3af4
		r.comp_mask = ring_desc->ring_cyclicb.comp_mask;
Packit Service aa3af4
		r.num = ring_desc->ring_cyclicb.num;
Packit Service aa3af4
		r.stride_bytes = ring_desc->ring_cyclicb.stride_bytes;
Packit Service aa3af4
		r.packet_receive_mode = ring_desc->ring_cyclicb.packet_receive_mode;
Packit Service aa3af4
Packit Service aa3af4
		if (r.comp_mask & VMA_CB_HDR_BYTE) {
Packit Service aa3af4
			r.hdr_bytes = ring_desc->ring_cyclicb.hdr_bytes;
Packit Service aa3af4
		}
Packit Service aa3af4
		break;
Packit Service aa3af4
	}
Packit Service aa3af4
	case VMA_RING_PACKET:
Packit Service aa3af4
		m_ring_desc.ring_pktq.comp_mask = ring_desc->ring_pktq.comp_mask;
Packit Service aa3af4
		break;
Packit Service aa3af4
	case VMA_RING_EXTERNAL_MEM:
Packit Service aa3af4
		m_ring_desc.ring_ext.comp_mask = ring_desc->ring_ext.comp_mask;
Packit Service aa3af4
		break;
Packit Service aa3af4
	default:
Packit Service aa3af4
		break;
Packit Service aa3af4
	}
Packit Service aa3af4
	create_string();
Packit Service aa3af4
};
Packit Service aa3af4
Packit Service aa3af4
const char* ring_profile::get_vma_ring_type_str()
Packit Service aa3af4
{
Packit Service aa3af4
	switch (m_ring_desc.ring_type) {
Packit Service aa3af4
	case VMA_RING_PACKET:	return "VMA_PKTS_RING";
Packit Service aa3af4
	case VMA_RING_CYCLIC_BUFFER:	return "VMA_CB_RING";
Packit Service aa3af4
	case VMA_RING_EXTERNAL_MEM:	return "VMA_EXTERNAL_MEM_RING";
Packit Service aa3af4
	default:		return "";
Packit Service aa3af4
	}
Packit Service aa3af4
};
Packit Service aa3af4
Packit Service aa3af4
ring_profile::ring_profile()
Packit Service aa3af4
{
Packit Service aa3af4
	m_ring_desc.ring_type = VMA_RING_PACKET;
Packit Service aa3af4
	m_ring_desc.comp_mask = 0;
Packit Service aa3af4
	m_ring_desc.ring_pktq.comp_mask = 0;
Packit Service aa3af4
	create_string();
Packit Service aa3af4
};
Packit Service aa3af4
Packit Service aa3af4
Packit Service aa3af4
void ring_profile::create_string()
Packit Service aa3af4
{
Packit Service aa3af4
	ostringstream s;
Packit Service aa3af4
Packit Service aa3af4
	s<
Packit Service aa3af4
	if (m_ring_desc.ring_type == VMA_RING_CYCLIC_BUFFER) {
Packit Service aa3af4
		s<<" packets_num:"<
Packit Service aa3af4
		 <<" stride_bytes:"<
Packit Service aa3af4
		 <<" hdr size:"<
Packit Service aa3af4
	}
Packit Service aa3af4
	m_str = s.str();
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
bool ring_profile::operator==(const vma_ring_type_attr &p2)
Packit Service aa3af4
{
Packit Service aa3af4
	ring_profile other(&p2;;
Packit Service aa3af4
Packit Service aa3af4
	return (m_str.compare(other.to_str()) == 0);
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
ring_profiles_collection::ring_profiles_collection(): m_curr_idx(START_RING_INDEX) {
Packit Service aa3af4
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
vma_ring_profile_key ring_profiles_collection::add_profile(vma_ring_type_attr *profile)
Packit Service aa3af4
{
Packit Service aa3af4
	// first check if this profile exists
Packit Service aa3af4
	ring_profile_map_t::iterator it = m_profs_map.begin();
Packit Service aa3af4
	for (;it != m_profs_map.end(); it++) {
Packit Service aa3af4
		if (*it->second == *profile) {
Packit Service aa3af4
			return it->first;
Packit Service aa3af4
		}
Packit Service aa3af4
	}
Packit Service aa3af4
	// key 0 is invalid
Packit Service aa3af4
	vma_ring_profile_key key = m_curr_idx;
Packit Service aa3af4
	m_curr_idx++;
Packit Service aa3af4
	ring_profile *prof = new ring_profile(profile);
Packit Service aa3af4
	m_profs_map[key] = prof;
Packit Service aa3af4
	return key;
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
ring_profile* ring_profiles_collection::get_profile(vma_ring_profile_key key)
Packit Service aa3af4
{
Packit Service aa3af4
	ring_profile_map_t::iterator iter = m_profs_map.find(key);
Packit Service aa3af4
	if (iter != m_profs_map.end()) {
Packit Service aa3af4
		return iter->second;
Packit Service aa3af4
	}
Packit Service aa3af4
	return NULL;
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
ring_profiles_collection::~ring_profiles_collection()
Packit Service aa3af4
{
Packit Service aa3af4
	ring_profile_map_t::iterator iter;
Packit Service aa3af4
Packit Service aa3af4
	while ((iter = m_profs_map.begin()) != m_profs_map.end()) {
Packit Service aa3af4
		delete (iter->second);
Packit Service aa3af4
		m_profs_map.erase(iter);
Packit Service aa3af4
	}
Packit Service aa3af4
}