Blame opensm/osm_pkey_mgr.c

Packit 13e616
/*
Packit 13e616
 * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
Packit 13e616
 * Copyright (c) 2002-2011 Mellanox Technologies LTD. All rights reserved.
Packit 13e616
 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
Packit 13e616
 * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
Packit 13e616
 *
Packit 13e616
 * This software is available to you under a choice of one of two
Packit 13e616
 * licenses.  You may choose to be licensed under the terms of the GNU
Packit 13e616
 * General Public License (GPL) Version 2, available from the file
Packit 13e616
 * COPYING in the main directory of this source tree, or the
Packit 13e616
 * OpenIB.org BSD license below:
Packit 13e616
 *
Packit 13e616
 *     Redistribution and use in source and binary forms, with or
Packit 13e616
 *     without modification, are permitted provided that the following
Packit 13e616
 *     conditions are met:
Packit 13e616
 *
Packit 13e616
 *      - Redistributions of source code must retain the above
Packit 13e616
 *        copyright notice, this list of conditions and the following
Packit 13e616
 *        disclaimer.
Packit 13e616
 *
Packit 13e616
 *      - Redistributions in binary form must reproduce the above
Packit 13e616
 *        copyright notice, this list of conditions and the following
Packit 13e616
 *        disclaimer in the documentation and/or other materials
Packit 13e616
 *        provided with the distribution.
Packit 13e616
 *
Packit 13e616
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 13e616
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 13e616
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 13e616
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit 13e616
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit 13e616
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit 13e616
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit 13e616
 * SOFTWARE.
Packit 13e616
 *
Packit 13e616
 */
Packit 13e616
Packit 13e616
/*
Packit 13e616
 * Abstract:
Packit 13e616
 * Implementation of the P_Key Manager (Partition Manager).
Packit 13e616
 * This is part of the OpenSM.
Packit 13e616
 */
Packit 13e616
Packit 13e616
#if HAVE_CONFIG_H
Packit 13e616
#  include <config.h>
Packit 13e616
#endif				/* HAVE_CONFIG_H */
Packit 13e616
Packit 13e616
#include <string.h>
Packit 13e616
#include <iba/ib_types.h>
Packit 13e616
#include <complib/cl_qmap.h>
Packit 13e616
#include <complib/cl_debug.h>
Packit 13e616
#include <opensm/osm_file_ids.h>
Packit 13e616
#define FILE_ID OSM_FILE_PKEY_MGR_C
Packit 13e616
#include <opensm/osm_node.h>
Packit 13e616
#include <opensm/osm_switch.h>
Packit 13e616
#include <opensm/osm_partition.h>
Packit 13e616
#include <opensm/osm_opensm.h>
Packit 13e616
Packit 13e616
static void clear_accum_pkey_index(osm_pkey_tbl_t * p_pkey_tbl,
Packit 13e616
				   uint16_t pkey_index);
Packit 13e616
Packit 13e616
/*
Packit 13e616
  The max number of pkeys/pkey blocks for a physical port is located
Packit 13e616
  in a different place for switch external ports (SwitchInfo) and the
Packit 13e616
  rest of the ports (NodeInfo).
Packit 13e616
*/
Packit 13e616
static uint16_t
Packit 13e616
pkey_mgr_get_physp_max_pkeys(IN const osm_physp_t * p_physp)
Packit 13e616
{
Packit 13e616
	osm_node_t *p_node = osm_physp_get_node_ptr(p_physp);
Packit 13e616
	uint16_t num_pkeys = 0;
Packit 13e616
Packit 13e616
	if (!p_node->sw || (osm_physp_get_port_num(p_physp) == 0))
Packit 13e616
		num_pkeys = cl_ntoh16(p_node->node_info.partition_cap);
Packit 13e616
	else
Packit 13e616
		num_pkeys = cl_ntoh16(p_node->sw->switch_info.enforce_cap);
Packit 13e616
	return num_pkeys;
Packit 13e616
}
Packit 13e616
Packit 13e616
static uint16_t
Packit 13e616
pkey_mgr_get_physp_max_blocks(IN const osm_physp_t * p_physp)
Packit 13e616
{
Packit 13e616
	return ((pkey_mgr_get_physp_max_pkeys(p_physp) + 31) / 32);
Packit 13e616
}
Packit 13e616
Packit 13e616
/*
Packit 13e616
 * Insert new pending pkey entry to the specific port pkey table
Packit 13e616
 * pending pkeys. New entries are inserted at the back.
Packit 13e616
 */
Packit 13e616
static void
Packit 13e616
pkey_mgr_process_physical_port(IN osm_log_t * p_log,
Packit 13e616
			       IN osm_sm_t * sm,
Packit 13e616
			       IN const ib_net16_t pkey,
Packit 13e616
			       IN osm_physp_t * p_physp)
Packit 13e616
{
Packit 13e616
	osm_node_t *p_node = osm_physp_get_node_ptr(p_physp);
Packit 13e616
	osm_pkey_tbl_t *p_pkey_tbl;
Packit 13e616
	ib_net16_t *p_orig_pkey;
Packit 13e616
	osm_pending_pkey_t *p_pending;
Packit 13e616
Packit 13e616
	p_pkey_tbl = &p_physp->pkeys;
Packit 13e616
	p_pending = (osm_pending_pkey_t *) calloc(1, sizeof(osm_pending_pkey_t));
Packit 13e616
	if (!p_pending) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0502: "
Packit 13e616
			"Failed to allocate new pending pkey entry for node "
Packit 13e616
			"0x%016" PRIx64 " port %u\n",
Packit 13e616
			cl_ntoh64(osm_node_get_node_guid(p_node)),
Packit 13e616
			osm_physp_get_port_num(p_physp));
Packit 13e616
		return;
Packit 13e616
	}
Packit 13e616
	p_pending->pkey = pkey;
Packit 13e616
	if (sm->p_subn->opt.allow_both_pkeys)
Packit 13e616
		p_orig_pkey = cl_map_get(&p_pkey_tbl->keys, pkey);
Packit 13e616
	else
Packit 13e616
		p_orig_pkey = cl_map_get(&p_pkey_tbl->keys,
Packit 13e616
					 ib_pkey_get_base(pkey));
Packit 13e616
Packit 13e616
	if (!p_orig_pkey) {
Packit 13e616
		p_pending->is_new = TRUE;
Packit 13e616
	} else {
Packit 13e616
		CL_ASSERT(ib_pkey_get_base(*p_orig_pkey) ==
Packit 13e616
			  ib_pkey_get_base(pkey));
Packit 13e616
		p_pending->is_new = FALSE;
Packit 13e616
		if (osm_pkey_tbl_get_block_and_idx(p_pkey_tbl, p_orig_pkey,
Packit 13e616
						   &p_pending->block,
Packit 13e616
						   &p_pending->index) !=
Packit 13e616
		    IB_SUCCESS) {
Packit 13e616
			OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0503: "
Packit 13e616
				"Failed to obtain P_Key 0x%04x block and index "
Packit 13e616
				"for node 0x%016" PRIx64 " port %u\n",
Packit 13e616
				cl_ntoh16(ib_pkey_get_base(pkey)),
Packit 13e616
				cl_ntoh64(osm_node_get_node_guid(p_node)),
Packit 13e616
				osm_physp_get_port_num(p_physp));
Packit 13e616
			free(p_pending);
Packit 13e616
			return;
Packit 13e616
		}
Packit 13e616
		if (p_physp->pkeys.indx0_pkey) {
Packit 13e616
			/*
Packit 13e616
			 * Remove the pkey that should be at index 0 from
Packit 13e616
			 * accum pkey if current position is not index 0
Packit 13e616
			 */
Packit 13e616
			if (((sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
			      pkey == p_physp->pkeys.indx0_pkey) ||
Packit 13e616
			     (!sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
			      ib_pkey_get_base(pkey) == ib_pkey_get_base(p_physp->pkeys.indx0_pkey))) &&
Packit 13e616
			    (p_pending->block != 0 || p_pending->index != 0)) {
Packit 13e616
					p_pending->is_new = TRUE;
Packit 13e616
					clear_accum_pkey_index(p_pkey_tbl,
Packit 13e616
							       p_pending->block *
Packit 13e616
							       IB_NUM_PKEY_ELEMENTS_IN_BLOCK +
Packit 13e616
							       p_pending->index);
Packit 13e616
			}
Packit 13e616
Packit 13e616
			if (p_pending->block == 0 && p_pending->index == 0) {
Packit 13e616
				/* Move the pkey away from index 0 */
Packit 13e616
				if ((sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
				     pkey != p_physp->pkeys.indx0_pkey) ||
Packit 13e616
				    (!sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
				     ib_pkey_get_base(pkey) != ib_pkey_get_base(p_physp->pkeys.indx0_pkey))) {
Packit 13e616
					p_pending->is_new = TRUE;
Packit 13e616
					clear_accum_pkey_index(p_pkey_tbl, 0);
Packit 13e616
				}
Packit 13e616
			}
Packit 13e616
		 } else {
Packit 13e616
			/* If index 0 is occupied by non-default, it should reoccupied by pkey 0x7FFF */
Packit 13e616
			if (p_pending->block == 0 && p_pending->index == 0) {
Packit 13e616
				if (ib_pkey_get_base(pkey) != IB_DEFAULT_PARTIAL_PKEY) {
Packit 13e616
					p_pending->is_new = TRUE;
Packit 13e616
					clear_accum_pkey_index(p_pkey_tbl, 0);
Packit 13e616
				}
Packit 13e616
			/* Need to move default pkey to index 0 */
Packit 13e616
			} else if ((sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
				    pkey == IB_DEFAULT_PKEY) ||
Packit 13e616
				   (!sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
				    ib_pkey_get_base(pkey) == IB_DEFAULT_PARTIAL_PKEY)) {
Packit 13e616
					p_pending->is_new = TRUE;
Packit 13e616
					clear_accum_pkey_index(p_pkey_tbl,
Packit 13e616
							       p_pending->block *
Packit 13e616
							       IB_NUM_PKEY_ELEMENTS_IN_BLOCK +
Packit 13e616
							       p_pending->index);
Packit 13e616
			}
Packit 13e616
		}
Packit 13e616
Packit 13e616
	}
Packit 13e616
	if (p_pending->is_new == TRUE)
Packit 13e616
		 cl_qlist_insert_tail(&p_pkey_tbl->pending,
Packit 13e616
				      (cl_list_item_t *) p_pending);
Packit 13e616
	else
Packit 13e616
		cl_qlist_insert_head(&p_pkey_tbl->pending,
Packit 13e616
				     (cl_list_item_t *) p_pending);
Packit 13e616
Packit 13e616
	OSM_LOG(p_log, OSM_LOG_DEBUG,
Packit 13e616
		"pkey 0x%04x was %s for node 0x%016" PRIx64 " port %u\n",
Packit 13e616
		cl_ntoh16(pkey), p_pending->is_new ? "inserted" : "updated",
Packit 13e616
		cl_ntoh64(osm_node_get_node_guid(p_node)),
Packit 13e616
		osm_physp_get_port_num(p_physp));
Packit 13e616
}
Packit 13e616
Packit 13e616
static void
Packit 13e616
pkey_mgr_process_partition_table(osm_log_t * p_log, osm_sm_t * sm,
Packit 13e616
				 const osm_prtn_t * p_prtn,
Packit 13e616
				 const boolean_t full)
Packit 13e616
{
Packit 13e616
	const cl_map_t *p_tbl =
Packit 13e616
	    full ? &p_prtn->full_guid_tbl : &p_prtn->part_guid_tbl;
Packit 13e616
	cl_map_iterator_t i, i_next;
Packit 13e616
	ib_net16_t pkey = p_prtn->pkey;
Packit 13e616
	osm_physp_t *p_physp;
Packit 13e616
Packit 13e616
	if (full)
Packit 13e616
		pkey |= cl_hton16(0x8000);
Packit 13e616
Packit 13e616
	i_next = cl_map_head(p_tbl);
Packit 13e616
	while (i_next != cl_map_end(p_tbl)) {
Packit 13e616
		i = i_next;
Packit 13e616
		i_next = cl_map_next(i);
Packit 13e616
		p_physp = cl_map_obj(i);
Packit 13e616
		if (p_physp)
Packit 13e616
			pkey_mgr_process_physical_port(p_log, sm, pkey,
Packit 13e616
						       p_physp);
Packit 13e616
	}
Packit 13e616
}
Packit 13e616
Packit 13e616
static ib_api_status_t
Packit 13e616
pkey_mgr_update_pkey_entry(IN osm_sm_t * sm,
Packit 13e616
			   IN const osm_physp_t * p_physp,
Packit 13e616
			   IN const ib_pkey_table_t * block,
Packit 13e616
			   IN const uint16_t block_index)
Packit 13e616
{
Packit 13e616
	osm_madw_context_t context;
Packit 13e616
	osm_node_t *p_node = osm_physp_get_node_ptr(p_physp);
Packit 13e616
	osm_physp_t *physp0;
Packit 13e616
	uint32_t attr_mod;
Packit 13e616
	ib_net64_t m_key;
Packit 13e616
Packit 13e616
	context.pkey_context.node_guid = osm_node_get_node_guid(p_node);
Packit 13e616
	context.pkey_context.port_guid = osm_physp_get_port_guid(p_physp);
Packit 13e616
	context.pkey_context.set_method = TRUE;
Packit 13e616
	attr_mod = block_index;
Packit 13e616
	if (osm_node_get_type(p_node) == IB_NODE_TYPE_SWITCH &&
Packit 13e616
	    osm_physp_get_port_num(p_physp) != 0) {
Packit 13e616
		attr_mod |= osm_physp_get_port_num(p_physp) << 16;
Packit 13e616
		physp0 = osm_node_get_physp_ptr(p_node, 0);
Packit 13e616
		m_key = ib_port_info_get_m_key(&physp0->port_info);
Packit 13e616
	} else
Packit 13e616
		m_key = ib_port_info_get_m_key(&p_physp->port_info);
Packit 13e616
	return osm_req_set(sm, osm_physp_get_dr_path_ptr(p_physp),
Packit 13e616
			   (uint8_t *) block, sizeof(*block),
Packit 13e616
			   IB_MAD_ATTR_P_KEY_TABLE,
Packit 13e616
			   cl_hton32(attr_mod), FALSE, m_key,
Packit 13e616
			   0, CL_DISP_MSGID_NONE, &context);
Packit 13e616
}
Packit 13e616
Packit 13e616
static ib_api_status_t
Packit 13e616
pkey_mgr_enforce_partition(IN osm_log_t * p_log, osm_sm_t * sm,
Packit 13e616
			   IN osm_physp_t * p_physp,
Packit 13e616
			   IN osm_partition_enforce_type_enum enforce_type)
Packit 13e616
{
Packit 13e616
	osm_madw_context_t context;
Packit 13e616
	uint8_t payload[IB_SMP_DATA_SIZE];
Packit 13e616
	ib_port_info_t *p_pi;
Packit 13e616
	ib_net64_t m_key;
Packit 13e616
	osm_physp_t *physp0;
Packit 13e616
	ib_api_status_t status;
Packit 13e616
	uint8_t enforce_bits;
Packit 13e616
Packit 13e616
	p_pi = &p_physp->port_info;
Packit 13e616
Packit 13e616
	if (enforce_type == OSM_PARTITION_ENFORCE_TYPE_BOTH)
Packit 13e616
		enforce_bits = 0xc;
Packit 13e616
	else if (enforce_type == OSM_PARTITION_ENFORCE_TYPE_IN)
Packit 13e616
		enforce_bits = 0x8;
Packit 13e616
	else
Packit 13e616
		enforce_bits = 0x4;
Packit 13e616
Packit 13e616
	if ((p_pi->vl_enforce & 0xc) == enforce_bits *
Packit 13e616
	    (enforce_type != OSM_PARTITION_ENFORCE_TYPE_OFF)) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_DEBUG,
Packit 13e616
			"No need to update PortInfo for "
Packit 13e616
			"node 0x%016" PRIx64 " port %u (%s)\n",
Packit 13e616
			cl_ntoh64(osm_node_get_node_guid
Packit 13e616
				  (osm_physp_get_node_ptr(p_physp))),
Packit 13e616
			osm_physp_get_port_num(p_physp),
Packit 13e616
			p_physp->p_node->print_desc);
Packit 13e616
		return IB_SUCCESS;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	memcpy(payload, p_pi, sizeof(ib_port_info_t));
Packit 13e616
Packit 13e616
	p_pi = (ib_port_info_t *) payload;
Packit 13e616
	p_pi->vl_enforce &= ~0xc;
Packit 13e616
	if (enforce_type != OSM_PARTITION_ENFORCE_TYPE_OFF)
Packit 13e616
		p_pi->vl_enforce |= enforce_bits;
Packit 13e616
Packit 13e616
	p_pi->state_info2 = 0;
Packit 13e616
	ib_port_info_set_port_state(p_pi, IB_LINK_NO_CHANGE);
Packit 13e616
Packit 13e616
	physp0 = osm_node_get_physp_ptr(p_physp->p_node, 0);
Packit 13e616
	m_key = ib_port_info_get_m_key(&physp0->port_info);
Packit 13e616
Packit 13e616
	context.pi_context.node_guid =
Packit 13e616
	    osm_node_get_node_guid(osm_physp_get_node_ptr(p_physp));
Packit 13e616
	context.pi_context.port_guid = osm_physp_get_port_guid(p_physp);
Packit 13e616
	context.pi_context.set_method = TRUE;
Packit 13e616
	context.pi_context.light_sweep = FALSE;
Packit 13e616
	context.pi_context.active_transition = FALSE;
Packit 13e616
	context.pi_context.client_rereg = FALSE;
Packit 13e616
Packit 13e616
	status = osm_req_set(sm, osm_physp_get_dr_path_ptr(p_physp),
Packit 13e616
			     payload, sizeof(payload),
Packit 13e616
			     IB_MAD_ATTR_PORT_INFO,
Packit 13e616
			     cl_hton32(osm_physp_get_port_num(p_physp)),
Packit 13e616
			     FALSE, m_key,
Packit 13e616
			     0, CL_DISP_MSGID_NONE, &context);
Packit 13e616
	if (status != IB_SUCCESS)
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0511: "
Packit 13e616
			"Failed to set PortInfo for "
Packit 13e616
			"node 0x%016" PRIx64 " port %u (%s)\n",
Packit 13e616
			cl_ntoh64(osm_node_get_node_guid
Packit 13e616
				  (osm_physp_get_node_ptr(p_physp))),
Packit 13e616
			osm_physp_get_port_num(p_physp),
Packit 13e616
			p_physp->p_node->print_desc);
Packit 13e616
	else
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_DEBUG,
Packit 13e616
			"Set PortInfo for node 0x%016" PRIx64 " port %u (%s)\n",
Packit 13e616
			cl_ntoh64(osm_node_get_node_guid
Packit 13e616
				  (osm_physp_get_node_ptr(p_physp))),
Packit 13e616
			osm_physp_get_port_num(p_physp),
Packit 13e616
			p_physp->p_node->print_desc);
Packit 13e616
	return status;
Packit 13e616
}
Packit 13e616
Packit 13e616
static void clear_accum_pkey_index(osm_pkey_tbl_t * p_pkey_tbl,
Packit 13e616
				   uint16_t pkey_index)
Packit 13e616
{
Packit 13e616
	uint16_t pkey_idx_bias, pkey_idx;
Packit 13e616
	void *ptr;
Packit 13e616
	uintptr_t pkey_idx_ptr;
Packit 13e616
	cl_map_iterator_t map_iter, map_iter_temp;
Packit 13e616
Packit 13e616
	map_iter = cl_map_head(&p_pkey_tbl->accum_pkeys);
Packit 13e616
Packit 13e616
	pkey_idx_bias = pkey_index + 1; // adjust for pkey index bias in accum_pkeys
Packit 13e616
Packit 13e616
	while (map_iter != cl_map_end(&p_pkey_tbl->accum_pkeys)) {
Packit 13e616
		map_iter_temp = cl_map_next(map_iter);
Packit 13e616
		ptr = (uint16_t *) cl_map_obj(map_iter);
Packit 13e616
		CL_ASSERT(ptr);
Packit 13e616
		pkey_idx_ptr = (uintptr_t) ptr;
Packit 13e616
		pkey_idx = pkey_idx_ptr;
Packit 13e616
		if (pkey_idx == pkey_idx_bias) {
Packit 13e616
			cl_map_remove_item(&p_pkey_tbl->accum_pkeys, map_iter);
Packit 13e616
			if (p_pkey_tbl->last_pkey_idx == pkey_idx)
Packit 13e616
				osm_pkey_find_last_accum_pkey_index(p_pkey_tbl);
Packit 13e616
			break;
Packit 13e616
		}
Packit 13e616
		map_iter = map_iter_temp;
Packit 13e616
	}
Packit 13e616
}
Packit 13e616
Packit 13e616
static int last_accum_pkey_index(osm_pkey_tbl_t * p_pkey_tbl,
Packit 13e616
				 uint16_t * p_block_idx,
Packit 13e616
				 uint8_t * p_pkey_idx)
Packit 13e616
{
Packit 13e616
	if (p_pkey_tbl->last_pkey_idx) {
Packit 13e616
		*p_block_idx = (p_pkey_tbl->last_pkey_idx - 1) / IB_NUM_PKEY_ELEMENTS_IN_BLOCK;
Packit 13e616
		*p_pkey_idx = (p_pkey_tbl->last_pkey_idx - 1) % IB_NUM_PKEY_ELEMENTS_IN_BLOCK;
Packit 13e616
		return 1;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	return 0;
Packit 13e616
}
Packit 13e616
Packit 13e616
static int pkey_mgr_update_port(osm_log_t * p_log, osm_sm_t * sm,
Packit 13e616
				const osm_port_t * const p_port)
Packit 13e616
{
Packit 13e616
	osm_physp_t *p_physp;
Packit 13e616
	osm_node_t *p_node;
Packit 13e616
	ib_pkey_table_t *block, *new_block;
Packit 13e616
	osm_pkey_tbl_t *p_pkey_tbl;
Packit 13e616
	uint16_t block_index;
Packit 13e616
	uint8_t pkey_index;
Packit 13e616
	uint16_t last_free_block_index = 0;
Packit 13e616
	uint8_t last_free_pkey_index = 0;
Packit 13e616
	uint16_t num_of_blocks;
Packit 13e616
	uint16_t max_num_of_blocks;
Packit 13e616
	ib_api_status_t status;
Packit 13e616
	osm_pending_pkey_t *p_pending;
Packit 13e616
	boolean_t found;
Packit 13e616
	ib_pkey_table_t empty_block;
Packit 13e616
	int ret = 0, full = 0;
Packit 13e616
	void *ptr;
Packit 13e616
	uintptr_t pkey_idx_ptr;
Packit 13e616
	uint16_t pkey_idx;
Packit 13e616
Packit 13e616
	p_physp = p_port->p_physp;
Packit 13e616
	if (!p_physp)
Packit 13e616
		return FALSE;
Packit 13e616
Packit 13e616
	memset(&empty_block, 0, sizeof(ib_pkey_table_t));
Packit 13e616
Packit 13e616
	p_node = osm_physp_get_node_ptr(p_physp);
Packit 13e616
	p_pkey_tbl = &p_physp->pkeys;
Packit 13e616
	num_of_blocks = osm_pkey_tbl_get_num_blocks(p_pkey_tbl);
Packit 13e616
	max_num_of_blocks = pkey_mgr_get_physp_max_blocks(p_physp);
Packit 13e616
	if (p_pkey_tbl->max_blocks > max_num_of_blocks) {
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_INFO,
Packit 13e616
			"Max number of blocks reduced from %u to %u "
Packit 13e616
			"for node 0x%016" PRIx64 " port %u (%s)\n",
Packit 13e616
			p_pkey_tbl->max_blocks, max_num_of_blocks,
Packit 13e616
			cl_ntoh64(osm_node_get_node_guid(p_node)),
Packit 13e616
			osm_physp_get_port_num(p_physp),
Packit 13e616
			p_physp->p_node->print_desc);
Packit 13e616
	}
Packit 13e616
	p_pkey_tbl->max_blocks = max_num_of_blocks;
Packit 13e616
Packit 13e616
	osm_pkey_tbl_init_new_blocks(p_pkey_tbl);
Packit 13e616
	p_pkey_tbl->used_blocks = 0;
Packit 13e616
Packit 13e616
	/*
Packit 13e616
	   process every pending pkey in order -
Packit 13e616
	   first must be "updated" last are "new"
Packit 13e616
	 */
Packit 13e616
	p_pending =
Packit 13e616
	    (osm_pending_pkey_t *) cl_qlist_remove_head(&p_pkey_tbl->pending);
Packit 13e616
	while (p_pending !=
Packit 13e616
	       (osm_pending_pkey_t *) cl_qlist_end(&p_pkey_tbl->pending)) {
Packit 13e616
Packit 13e616
		found = FALSE;
Packit 13e616
		ptr = NULL;
Packit 13e616
Packit 13e616
		if (p_pending->is_new == FALSE) {
Packit 13e616
			block_index = p_pending->block;
Packit 13e616
			pkey_index = p_pending->index;
Packit 13e616
			found = TRUE;
Packit 13e616
		} else {
Packit 13e616
			ptr = cl_map_get(&p_pkey_tbl->accum_pkeys,p_pending->pkey);
Packit 13e616
			if (ptr != NULL) {
Packit 13e616
				pkey_idx_ptr = (uintptr_t) ptr;
Packit 13e616
				pkey_idx = pkey_idx_ptr;
Packit 13e616
				pkey_idx--; /* adjust pkey index for bias */
Packit 13e616
				block_index = pkey_idx / IB_NUM_PKEY_ELEMENTS_IN_BLOCK;
Packit 13e616
				pkey_index = pkey_idx % IB_NUM_PKEY_ELEMENTS_IN_BLOCK;
Packit 13e616
Packit 13e616
				if (((sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
				      p_pending->pkey == p_physp->pkeys.indx0_pkey) ||
Packit 13e616
				     (!sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
				      ib_pkey_get_base(p_pending->pkey) == ib_pkey_get_base(p_physp->pkeys.indx0_pkey))) ||
Packit 13e616
				    ((p_pending->pkey != p_physp->pkeys.indx0_pkey &&
Packit 13e616
				      pkey_idx == 0))) {
Packit 13e616
					clear_accum_pkey_index(p_pkey_tbl, pkey_idx);
Packit 13e616
					cl_qlist_insert_tail(&p_pkey_tbl->pending,
Packit 13e616
							     (cl_list_item_t *)p_pending);
Packit 13e616
					p_pending =
Packit 13e616
                                            (osm_pending_pkey_t *) cl_qlist_remove_head(&p_pkey_tbl->pending);
Packit 13e616
					continue;
Packit 13e616
				} else
Packit 13e616
					found = TRUE;
Packit 13e616
			}
Packit 13e616
Packit 13e616
			if (!found) {
Packit 13e616
				if (!p_pkey_tbl->indx0_pkey &&
Packit 13e616
				    ((sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
				      p_pending->pkey == IB_DEFAULT_PKEY) ||
Packit 13e616
				     (!sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
				      ib_pkey_get_base(p_pending->pkey) == IB_DEFAULT_PARTIAL_PKEY))) {
Packit 13e616
					block_index = 0;
Packit 13e616
					pkey_index = 0;
Packit 13e616
				} else if ((sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
					    p_pending->pkey == p_pkey_tbl->indx0_pkey) ||
Packit 13e616
					   (!sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
					    ib_pkey_get_base(p_pending->pkey) ==
Packit 13e616
					    ib_pkey_get_base(p_pkey_tbl->indx0_pkey))) {
Packit 13e616
					block_index = 0;
Packit 13e616
					pkey_index = 0;
Packit 13e616
				} else if (last_accum_pkey_index(p_pkey_tbl,
Packit 13e616
								 &last_free_block_index,
Packit 13e616
								 &last_free_pkey_index)) {
Packit 13e616
					block_index = last_free_block_index;
Packit 13e616
					pkey_index = last_free_pkey_index + 1;
Packit 13e616
					if (pkey_index >= IB_NUM_PKEY_ELEMENTS_IN_BLOCK) {
Packit 13e616
						block_index++;
Packit 13e616
						pkey_index -= IB_NUM_PKEY_ELEMENTS_IN_BLOCK;
Packit 13e616
					}
Packit 13e616
				} else {
Packit 13e616
					block_index = 0;
Packit 13e616
					pkey_index = 1;
Packit 13e616
				}
Packit 13e616
Packit 13e616
				if (block_index * IB_NUM_PKEY_ELEMENTS_IN_BLOCK + pkey_index >= pkey_mgr_get_physp_max_pkeys(p_physp)) {
Packit 13e616
					if ((sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
					     p_pending->pkey != IB_DEFAULT_PKEY) ||
Packit 13e616
					    (!sm->p_subn->opt.allow_both_pkeys &&
Packit 13e616
					     ib_pkey_get_base(p_pending->pkey) != IB_DEFAULT_PARTIAL_PKEY)) {
Packit 13e616
						last_free_block_index = 0;
Packit 13e616
						last_free_pkey_index = 1;
Packit 13e616
						found = osm_pkey_find_next_free_entry(p_pkey_tbl, &last_free_block_index, &last_free_pkey_index);
Packit 13e616
					} else
Packit 13e616
						found = FALSE;
Packit 13e616
					if (!found)
Packit 13e616
						full = 1;
Packit 13e616
					else {
Packit 13e616
						block_index = last_free_block_index;
Packit 13e616
						pkey_index = last_free_pkey_index;
Packit 13e616
						if (block_index * IB_NUM_PKEY_ELEMENTS_IN_BLOCK + pkey_index >= pkey_mgr_get_physp_max_pkeys(p_physp)) {
Packit 13e616
							full = 1;
Packit 13e616
							found = FALSE;
Packit 13e616
						} else {
Packit 13e616
							OSM_LOG(p_log, OSM_LOG_INFO,
Packit 13e616
								"Reusing PKeyTable block index %u pkey index %u "
Packit 13e616
								"for pkey 0x%x on 0x%016" PRIx64 " port %u (%s)\n",
Packit 13e616
								block_index,
Packit 13e616
								pkey_index,
Packit 13e616
								cl_ntoh16(p_pending->pkey),
Packit 13e616
								cl_ntoh64(osm_node_get_node_guid(p_node)),
Packit 13e616
								osm_physp_get_port_num(p_physp),
Packit 13e616
								p_physp->p_node->print_desc);
Packit 13e616
Packit 13e616
							clear_accum_pkey_index(p_pkey_tbl, block_index * IB_NUM_PKEY_ELEMENTS_IN_BLOCK + pkey_index);
Packit 13e616
						}
Packit 13e616
					}
Packit 13e616
					if (full)
Packit 13e616
						OSM_LOG(p_log, OSM_LOG_ERROR,
Packit 13e616
							"ERR 0512: "
Packit 13e616
							"Failed to set PKey 0x%04x because Pkey table is full "
Packit 13e616
							"for node 0x%016" PRIx64 " port %u (%s)\n",
Packit 13e616
							cl_ntoh16(p_pending->pkey),
Packit 13e616
							cl_ntoh64(osm_node_get_node_guid(p_node)),
Packit 13e616
							osm_physp_get_port_num(p_physp),
Packit 13e616
							p_physp->p_node->print_desc);
Packit 13e616
				} else
Packit 13e616
					found = TRUE;
Packit 13e616
			}
Packit 13e616
		}
Packit 13e616
Packit 13e616
		if (found) {
Packit 13e616
			if (IB_SUCCESS !=
Packit 13e616
			    osm_pkey_tbl_set_new_entry(p_pkey_tbl, block_index,
Packit 13e616
						       pkey_index,
Packit 13e616
						       p_pending->pkey)) {
Packit 13e616
				OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0505: "
Packit 13e616
					"Failed to set PKey 0x%04x in block %u idx %u "
Packit 13e616
					"for node 0x%016" PRIx64 " port %u (%s)\n",
Packit 13e616
					cl_ntoh16(p_pending->pkey), block_index,
Packit 13e616
					pkey_index,
Packit 13e616
					cl_ntoh64(osm_node_get_node_guid
Packit 13e616
						  (p_node)),
Packit 13e616
					osm_physp_get_port_num(p_physp),
Packit 13e616
					p_physp->p_node->print_desc);
Packit 13e616
			}
Packit 13e616
			if (ptr == NULL &&
Packit 13e616
			    CL_SUCCESS !=
Packit 13e616
			    osm_pkey_tbl_set_accum_pkeys(p_pkey_tbl,
Packit 13e616
							 p_pending->pkey,
Packit 13e616
							 block_index * IB_NUM_PKEY_ELEMENTS_IN_BLOCK + pkey_index)) {
Packit 13e616
				OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0508: "
Packit 13e616
					"Failed to set accum_pkeys PKey 0x%04x "
Packit 13e616
					"in block %u idx %u for node 0x%016"
Packit 13e616
					PRIx64 " port %u (%s)\n",
Packit 13e616
					cl_ntoh16(p_pending->pkey), block_index,
Packit 13e616
					pkey_index,
Packit 13e616
					cl_ntoh64(osm_node_get_node_guid(p_node)),
Packit 13e616
					osm_physp_get_port_num(p_physp),
Packit 13e616
					p_physp->p_node->print_desc);
Packit 13e616
			}
Packit 13e616
		}
Packit 13e616
		free(p_pending);
Packit 13e616
		p_pending =
Packit 13e616
		    (osm_pending_pkey_t *) cl_qlist_remove_head(&p_pkey_tbl->
Packit 13e616
								pending);
Packit 13e616
	}
Packit 13e616
Packit 13e616
	p_pkey_tbl->indx0_pkey = 0;
Packit 13e616
	/* now look for changes and store */
Packit 13e616
	for (block_index = 0; block_index < num_of_blocks; block_index++) {
Packit 13e616
		block = osm_pkey_tbl_block_get(p_pkey_tbl, block_index);
Packit 13e616
		new_block = osm_pkey_tbl_new_block_get(p_pkey_tbl, block_index);
Packit 13e616
		if (!new_block)
Packit 13e616
			new_block = &empty_block;
Packit 13e616
		if (block && !memcmp(new_block, block, sizeof(*block)))
Packit 13e616
			continue;
Packit 13e616
Packit 13e616
		status =
Packit 13e616
		    pkey_mgr_update_pkey_entry(sm, p_physp, new_block,
Packit 13e616
					       block_index);
Packit 13e616
		if (status == IB_SUCCESS)
Packit 13e616
			OSM_LOG(p_log, OSM_LOG_DEBUG,
Packit 13e616
				"Updated pkey table block %u for node 0x%016"
Packit 13e616
				PRIx64 " port %u (%s)\n", block_index,
Packit 13e616
				cl_ntoh64(osm_node_get_node_guid(p_node)),
Packit 13e616
				osm_physp_get_port_num(p_physp),
Packit 13e616
				p_physp->p_node->print_desc);
Packit 13e616
		else {
Packit 13e616
			OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0506: "
Packit 13e616
				"pkey_mgr_update_pkey_entry() failed to update "
Packit 13e616
				"pkey table block %u for node 0x%016" PRIx64
Packit 13e616
				" port %u (%s)\n", block_index,
Packit 13e616
				cl_ntoh64(osm_node_get_node_guid(p_node)),
Packit 13e616
				osm_physp_get_port_num(p_physp),
Packit 13e616
				p_physp->p_node->print_desc);
Packit 13e616
			ret = -1;
Packit 13e616
		}
Packit 13e616
	}
Packit 13e616
Packit 13e616
	return ret;
Packit 13e616
}
Packit 13e616
Packit 13e616
static int last_used_pkey_index(const osm_port_t * const p_port,
Packit 13e616
				const osm_pkey_tbl_t * p_pkey_tbl,
Packit 13e616
				uint16_t * p_last_index)
Packit 13e616
{
Packit 13e616
	ib_pkey_table_t *last_block;
Packit 13e616
	uint16_t index, last_index = 0;
Packit 13e616
Packit 13e616
	CL_ASSERT(p_last_index);
Packit 13e616
Packit 13e616
	last_block = osm_pkey_tbl_new_block_get(p_pkey_tbl,
Packit 13e616
						p_pkey_tbl->used_blocks - 1);
Packit 13e616
	if (!last_block)
Packit 13e616
		return 1;
Packit 13e616
Packit 13e616
	if (p_pkey_tbl->used_blocks == p_pkey_tbl->max_blocks)
Packit 13e616
		last_index = cl_ntoh16(p_port->p_node->node_info.partition_cap) % IB_NUM_PKEY_ELEMENTS_IN_BLOCK;
Packit 13e616
	if (last_index == 0)
Packit 13e616
		last_index = IB_NUM_PKEY_ELEMENTS_IN_BLOCK;
Packit 13e616
	index = last_index;
Packit 13e616
	do {
Packit 13e616
		index--;
Packit 13e616
		if (!ib_pkey_is_invalid(last_block->pkey_entry[index]))
Packit 13e616
			break;
Packit 13e616
	} while (index != 0);
Packit 13e616
Packit 13e616
	*p_last_index = index;
Packit 13e616
	return 0;
Packit 13e616
}
Packit 13e616
Packit 13e616
static int update_peer_block(osm_log_t * p_log, osm_sm_t * sm,
Packit 13e616
			     osm_physp_t * peer,
Packit 13e616
			     osm_pkey_tbl_t * p_peer_pkey_tbl,
Packit 13e616
			     ib_pkey_table_t * new_peer_block,
Packit 13e616
			     uint16_t peer_block_idx, osm_node_t * p_node)
Packit 13e616
{
Packit 13e616
	int ret = 0;
Packit 13e616
	ib_pkey_table_t *peer_block;
Packit 13e616
Packit 13e616
	peer_block = osm_pkey_tbl_block_get(p_peer_pkey_tbl, peer_block_idx);
Packit 13e616
	if (!peer_block ||
Packit 13e616
	    memcmp(peer_block, new_peer_block, sizeof(*peer_block))) {
Packit 13e616
		if (pkey_mgr_update_pkey_entry(sm, peer, new_peer_block,
Packit 13e616
					       peer_block_idx) != IB_SUCCESS) {
Packit 13e616
			OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0509: "
Packit 13e616
				"pkey_mgr_update_pkey_entry() failed to update "
Packit 13e616
				"pkey table block %u for node 0x%016"
Packit 13e616
				PRIx64 " port %u (%s)\n",
Packit 13e616
				peer_block_idx,
Packit 13e616
				cl_ntoh64(osm_node_get_node_guid(p_node)),
Packit 13e616
				osm_physp_get_port_num(peer),
Packit 13e616
				p_node->print_desc);
Packit 13e616
			ret = -1;
Packit 13e616
		}
Packit 13e616
	}
Packit 13e616
Packit 13e616
	return ret;
Packit 13e616
}
Packit 13e616
Packit 13e616
static int new_pkey_exists(osm_pkey_tbl_t * p_pkey_tbl, ib_net16_t pkey)
Packit 13e616
{
Packit 13e616
	uint16_t num_blocks;
Packit 13e616
	uint16_t block_index;
Packit 13e616
	ib_pkey_table_t *block;
Packit 13e616
	uint16_t pkey_idx;
Packit 13e616
Packit 13e616
	num_blocks = (uint16_t) cl_ptr_vector_get_size(&p_pkey_tbl->new_blocks);
Packit 13e616
	for (block_index = 0; block_index < num_blocks; block_index++) {
Packit 13e616
		block = osm_pkey_tbl_new_block_get(p_pkey_tbl, block_index);
Packit 13e616
		if (!block)
Packit 13e616
			continue;
Packit 13e616
Packit 13e616
		for (pkey_idx = 0; pkey_idx < IB_NUM_PKEY_ELEMENTS_IN_BLOCK;
Packit 13e616
		     pkey_idx++) {
Packit 13e616
			if (block->pkey_entry[pkey_idx] == pkey)
Packit 13e616
				return 1;
Packit 13e616
		}
Packit 13e616
	}
Packit 13e616
	return 0;
Packit 13e616
}
Packit 13e616
Packit 13e616
static int pkey_mgr_update_peer_port(osm_log_t * p_log, osm_sm_t * sm,
Packit 13e616
				     const osm_subn_t * p_subn,
Packit 13e616
				     const osm_port_t * const p_port,
Packit 13e616
				     osm_partition_enforce_type_enum enforce_type)
Packit 13e616
{
Packit 13e616
	osm_physp_t *p_physp, *peer;
Packit 13e616
	osm_node_t *p_node;
Packit 13e616
	ib_pkey_table_t *block;
Packit 13e616
	const osm_pkey_tbl_t *p_pkey_tbl;
Packit 13e616
	osm_pkey_tbl_t *p_peer_pkey_tbl;
Packit 13e616
	uint16_t block_index, peer_block_idx;
Packit 13e616
	uint16_t peer_max_blocks;
Packit 13e616
	uint16_t last_index;
Packit 13e616
	ib_pkey_table_t new_peer_block;
Packit 13e616
	uint16_t pkey_idx, peer_pkey_idx;
Packit 13e616
	ib_net16_t pkey, full_pkey;
Packit 13e616
	int ret = 0, loop_exit = 0;
Packit 13e616
Packit 13e616
	p_physp = p_port->p_physp;
Packit 13e616
	if (!p_physp)
Packit 13e616
		return -1;
Packit 13e616
	peer = osm_physp_get_remote(p_physp);
Packit 13e616
	if (!peer)
Packit 13e616
		return -1;
Packit 13e616
	p_node = osm_physp_get_node_ptr(peer);
Packit 13e616
	if (!p_node->sw || !p_node->sw->switch_info.enforce_cap)
Packit 13e616
		return 0;
Packit 13e616
Packit 13e616
	if (enforce_type == OSM_PARTITION_ENFORCE_TYPE_OFF) {
Packit 13e616
		pkey_mgr_enforce_partition(p_log, sm, peer, OSM_PARTITION_ENFORCE_TYPE_OFF);
Packit 13e616
		return ret;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	p_pkey_tbl = osm_physp_get_pkey_tbl(p_physp);
Packit 13e616
	peer_max_blocks = pkey_mgr_get_physp_max_blocks(peer);
Packit 13e616
	p_peer_pkey_tbl = &peer->pkeys;
Packit 13e616
	peer_block_idx = 0;
Packit 13e616
	peer_pkey_idx = 0;
Packit 13e616
	for (block_index = 0; block_index < p_pkey_tbl->used_blocks;
Packit 13e616
	     block_index++) {
Packit 13e616
		if (loop_exit)
Packit 13e616
			break;
Packit 13e616
		block = osm_pkey_tbl_new_block_get(p_pkey_tbl, block_index);
Packit 13e616
		if (!block)
Packit 13e616
			continue;
Packit 13e616
		for (pkey_idx = 0; pkey_idx < IB_NUM_PKEY_ELEMENTS_IN_BLOCK;
Packit 13e616
		     pkey_idx++) {
Packit 13e616
			pkey = block->pkey_entry[pkey_idx];
Packit 13e616
			if (ib_pkey_is_invalid(pkey))
Packit 13e616
				continue;
Packit 13e616
			if (!ib_pkey_is_full_member(pkey)) {
Packit 13e616
				full_pkey = pkey | IB_PKEY_TYPE_MASK;
Packit 13e616
				if (new_pkey_exists(&p_physp->pkeys, full_pkey))
Packit 13e616
					continue;
Packit 13e616
			}
Packit 13e616
			new_peer_block.pkey_entry[peer_pkey_idx] = pkey;
Packit 13e616
			if (peer_block_idx >= peer_max_blocks) {
Packit 13e616
				loop_exit = 1;
Packit 13e616
				break;
Packit 13e616
			}
Packit 13e616
			if (++peer_pkey_idx == IB_NUM_PKEY_ELEMENTS_IN_BLOCK) {
Packit 13e616
				if (update_peer_block(p_log, sm, peer,
Packit 13e616
						      p_peer_pkey_tbl,
Packit 13e616
						      &new_peer_block,
Packit 13e616
						      peer_block_idx, p_node))
Packit 13e616
					ret = -1;
Packit 13e616
				peer_pkey_idx = 0;
Packit 13e616
				peer_block_idx++;
Packit 13e616
			}
Packit 13e616
		}
Packit 13e616
	}
Packit 13e616
Packit 13e616
	if (peer_block_idx < peer_max_blocks) {
Packit 13e616
		if (peer_pkey_idx) {
Packit 13e616
			/* Handle partial last block */
Packit 13e616
			for (; peer_pkey_idx < IB_NUM_PKEY_ELEMENTS_IN_BLOCK;
Packit 13e616
			     peer_pkey_idx++)
Packit 13e616
				new_peer_block.pkey_entry[peer_pkey_idx] = 0;
Packit 13e616
			if (update_peer_block(p_log, sm, peer, p_peer_pkey_tbl,
Packit 13e616
					      &new_peer_block, peer_block_idx,
Packit 13e616
					      p_node))
Packit 13e616
				ret = -1;
Packit 13e616
		} else
Packit 13e616
			peer_block_idx--;
Packit 13e616
Packit 13e616
		p_peer_pkey_tbl->used_blocks = peer_block_idx + 1;
Packit 13e616
		if (p_peer_pkey_tbl->used_blocks == peer_max_blocks) {
Packit 13e616
			/* Is last used pkey index beyond switch peer port capacity ? */
Packit 13e616
			if (!last_used_pkey_index(p_port, p_peer_pkey_tbl,
Packit 13e616
						  &last_index)) {
Packit 13e616
				last_index += peer_block_idx * IB_NUM_PKEY_ELEMENTS_IN_BLOCK;
Packit 13e616
				if (cl_ntoh16(p_node->sw->switch_info.enforce_cap) <= last_index) {
Packit 13e616
					OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 0507: "
Packit 13e616
						"Not enough pkey entries (%u <= %u) on switch 0x%016"
Packit 13e616
						PRIx64 " port %u (%s). Clearing Enforcement bit\n",
Packit 13e616
						cl_ntoh16(p_node->sw->switch_info.enforce_cap),
Packit 13e616
						last_index,
Packit 13e616
						cl_ntoh64(osm_node_get_node_guid(p_node)),
Packit 13e616
						osm_physp_get_port_num(peer),
Packit 13e616
						p_node->print_desc);
Packit 13e616
					enforce_type = OSM_PARTITION_ENFORCE_TYPE_OFF;
Packit 13e616
					ret = -1;
Packit 13e616
				}
Packit 13e616
			}
Packit 13e616
		}
Packit 13e616
	} else {
Packit 13e616
		p_peer_pkey_tbl->used_blocks = peer_max_blocks;
Packit 13e616
		enforce_type = OSM_PARTITION_ENFORCE_TYPE_OFF;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	if (!ret)
Packit 13e616
		OSM_LOG(p_log, OSM_LOG_DEBUG,
Packit 13e616
			"Pkey table was successfully updated for node 0x%016"
Packit 13e616
			PRIx64 " port %u (%s)\n",
Packit 13e616
			cl_ntoh64(osm_node_get_node_guid(p_node)),
Packit 13e616
			osm_physp_get_port_num(peer), p_node->print_desc);
Packit 13e616
Packit 13e616
	if (pkey_mgr_enforce_partition(p_log, sm, peer, enforce_type))
Packit 13e616
		ret = -1;
Packit 13e616
Packit 13e616
	return ret;
Packit 13e616
}
Packit 13e616
Packit 13e616
int osm_pkey_mgr_process(IN osm_opensm_t * p_osm)
Packit 13e616
{
Packit 13e616
	cl_qmap_t *p_tbl;
Packit 13e616
	cl_map_item_t *p_next;
Packit 13e616
	osm_prtn_t *p_prtn;
Packit 13e616
	osm_port_t *p_port;
Packit 13e616
	osm_switch_t *p_sw;
Packit 13e616
	osm_physp_t *p_physp;
Packit 13e616
	osm_pkey_tbl_t *p_pkey_tbl;
Packit 13e616
	osm_node_t *p_remote_node;
Packit 13e616
	uint8_t i;
Packit 13e616
	int ret = 0;
Packit 13e616
Packit 13e616
	CL_ASSERT(p_osm);
Packit 13e616
Packit 13e616
	OSM_LOG_ENTER(&p_osm->log);
Packit 13e616
Packit 13e616
	CL_PLOCK_EXCL_ACQUIRE(&p_osm->lock);
Packit 13e616
Packit 13e616
	if (osm_prtn_make_partitions(&p_osm->log, &p_osm->subn) != IB_SUCCESS) {
Packit 13e616
		OSM_LOG(&p_osm->log, OSM_LOG_ERROR, "ERR 0510: "
Packit 13e616
			"osm_prtn_make_partitions() failed\n");
Packit 13e616
		ret = -1;
Packit 13e616
		goto _err;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	if (!p_osm->subn.opt.keep_pkey_indexes) {
Packit 13e616
		p_tbl = &p_osm->subn.port_guid_tbl;
Packit 13e616
		p_next = cl_qmap_head(p_tbl);
Packit 13e616
		while (p_next != cl_qmap_end(p_tbl)) {
Packit 13e616
			p_port = (osm_port_t *) p_next;
Packit 13e616
			p_next = cl_qmap_next(p_next);
Packit 13e616
			if (!(p_physp = p_port->p_physp))
Packit 13e616
				continue;
Packit 13e616
			p_pkey_tbl = &p_physp->pkeys;
Packit 13e616
			cl_map_remove_all(&p_pkey_tbl->keys);
Packit 13e616
			cl_map_remove_all(&p_pkey_tbl->accum_pkeys);
Packit 13e616
			p_pkey_tbl->last_pkey_idx=0;
Packit 13e616
		}
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* populate the pending pkey entries by scanning all partitions */
Packit 13e616
	p_tbl = &p_osm->subn.prtn_pkey_tbl;
Packit 13e616
	p_next = cl_qmap_head(p_tbl);
Packit 13e616
	while (p_next != cl_qmap_end(p_tbl)) {
Packit 13e616
		p_prtn = (osm_prtn_t *) p_next;
Packit 13e616
		p_next = cl_qmap_next(p_next);
Packit 13e616
		pkey_mgr_process_partition_table(&p_osm->log, &p_osm->sm,
Packit 13e616
						 p_prtn, FALSE);
Packit 13e616
		pkey_mgr_process_partition_table(&p_osm->log, &p_osm->sm,
Packit 13e616
						 p_prtn, TRUE);
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* calculate and set new pkey tables */
Packit 13e616
	p_tbl = &p_osm->subn.port_guid_tbl;
Packit 13e616
	p_next = cl_qmap_head(p_tbl);
Packit 13e616
	while (p_next != cl_qmap_end(p_tbl)) {
Packit 13e616
		p_port = (osm_port_t *) p_next;
Packit 13e616
		p_next = cl_qmap_next(p_next);
Packit 13e616
		if (pkey_mgr_update_port(&p_osm->log, &p_osm->sm, p_port))
Packit 13e616
			ret = -1;
Packit 13e616
		if ((osm_node_get_type(p_port->p_node) != IB_NODE_TYPE_SWITCH)
Packit 13e616
		    && pkey_mgr_update_peer_port(&p_osm->log, &p_osm->sm,
Packit 13e616
						 &p_osm->subn, p_port,
Packit 13e616
						 p_osm->subn.opt.part_enforce_enum))
Packit 13e616
			ret = -1;
Packit 13e616
	}
Packit 13e616
Packit 13e616
	/* clear partition enforcement on inter-switch links */
Packit 13e616
	p_tbl = &p_osm->subn.sw_guid_tbl;
Packit 13e616
	p_next = cl_qmap_head(p_tbl);
Packit 13e616
	while (p_next != cl_qmap_end(p_tbl)) {
Packit 13e616
		p_sw = (osm_switch_t *) p_next;
Packit 13e616
		p_next = cl_qmap_next(p_next);
Packit 13e616
		for (i = 1; i < p_sw->num_ports; i++) {
Packit 13e616
			p_physp = osm_node_get_physp_ptr(p_sw->p_node, i);
Packit 13e616
			if (p_physp && p_physp->p_remote_physp)
Packit 13e616
				p_remote_node = p_physp->p_remote_physp->p_node;
Packit 13e616
			else
Packit 13e616
				continue;
Packit 13e616
Packit 13e616
			if (osm_node_get_type(p_remote_node) != IB_NODE_TYPE_SWITCH)
Packit 13e616
				continue;
Packit 13e616
Packit 13e616
			if(! (p_physp->port_info.vl_enforce & 0xc ))
Packit 13e616
				continue;
Packit 13e616
Packit 13e616
			/* clear partition enforcement */
Packit 13e616
			if (pkey_mgr_enforce_partition(&p_osm->log, &p_osm->sm, p_physp, OSM_PARTITION_ENFORCE_TYPE_OFF))
Packit 13e616
				ret = -1;
Packit 13e616
		}
Packit 13e616
	}
Packit 13e616
_err:
Packit 13e616
	CL_PLOCK_RELEASE(&p_osm->lock);
Packit 13e616
	OSM_LOG_EXIT(&p_osm->log);
Packit 13e616
	return ret;
Packit 13e616
}