static void sci_remote_node_table_release_single_remote_node( struct sci_remote_node_table *remote_node_table, u16 remote_node_index) { u32 group_index; u8 group_value; group_index = remote_node_index / SCU_STP_REMOTE_NODE_COUNT; group_value = sci_remote_node_table_get_group_value(remote_node_table, group_index); BUG_ON(group_value == SCIC_SDS_REMOTE_NODE_TABLE_FULL_SLOT_VALUE); if (group_value == 0x00) { sci_remote_node_table_set_group_index(remote_node_table, 0, group_index); } else if ((group_value & (group_value - 1)) == 0) { sci_remote_node_table_clear_group_index(remote_node_table, 0, group_index); sci_remote_node_table_set_group_index(remote_node_table, 1, group_index); } else { sci_remote_node_table_clear_group_index(remote_node_table, 1, group_index); sci_remote_node_table_set_group_index(remote_node_table, 2, group_index); } sci_remote_node_table_set_node_index(remote_node_table, remote_node_index); }
static u16 sci_remote_node_table_allocate_single_remote_node( struct sci_remote_node_table *remote_node_table, u32 group_table_index) { u8 index; u8 group_value; u32 group_index; u16 remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX; group_index = sci_remote_node_table_get_group_index( remote_node_table, group_table_index); if (group_index != SCIC_SDS_REMOTE_NODE_TABLE_INVALID_INDEX) { group_value = sci_remote_node_table_get_group_value( remote_node_table, group_index); for (index = 0; index < SCU_STP_REMOTE_NODE_COUNT; index++) { if (((1 << index) & group_value) != 0) { remote_node_index = (u16)(group_index * SCU_STP_REMOTE_NODE_COUNT + index); sci_remote_node_table_clear_group_index( remote_node_table, group_table_index, group_index ); sci_remote_node_table_clear_node_index( remote_node_table, remote_node_index ); if (group_table_index > 0) { sci_remote_node_table_set_group_index( remote_node_table, group_table_index - 1, group_index ); } break; } } } return remote_node_index; }
/** * * @out]: remote_node_table The remote node table from which to allocate a * remote node. * @table_index: The group index that is to be used for the search. * * This method will allocate a single RNi from the remote node table. The * table index will determine from which remote node group table to search. * This search may fail and another group node table can be specified. The * function is designed to allow a serach of the available single remote node * group up to the triple remote node group. If an entry is found in the * specified table the remote node is removed and the remote node groups are * updated. The RNi value or an invalid remote node context if an RNi can not * be found. */ static u16 sci_remote_node_table_allocate_single_remote_node( struct sci_remote_node_table *remote_node_table, u32 group_table_index) { u8 index; u8 group_value; u32 group_index; u16 remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX; group_index = sci_remote_node_table_get_group_index( remote_node_table, group_table_index); /* We could not find an available slot in the table selector 0 */ if (group_index != SCIC_SDS_REMOTE_NODE_TABLE_INVALID_INDEX) { group_value = sci_remote_node_table_get_group_value( remote_node_table, group_index); for (index = 0; index < SCU_STP_REMOTE_NODE_COUNT; index++) { if (((1 << index) & group_value) != 0) { /* We have selected a bit now clear it */ remote_node_index = (u16)(group_index * SCU_STP_REMOTE_NODE_COUNT + index); sci_remote_node_table_clear_group_index( remote_node_table, group_table_index, group_index ); sci_remote_node_table_clear_node_index( remote_node_table, remote_node_index ); if (group_table_index > 0) { sci_remote_node_table_set_group_index( remote_node_table, group_table_index - 1, group_index ); } break; } } } return remote_node_index; }
/** * * @remote_node_table: * * This method will free a single remote node index back to the remote node * table. This routine will update the remote node groups */ static void sci_remote_node_table_release_single_remote_node( struct sci_remote_node_table *remote_node_table, u16 remote_node_index) { u32 group_index; u8 group_value; group_index = remote_node_index / SCU_STP_REMOTE_NODE_COUNT; group_value = sci_remote_node_table_get_group_value(remote_node_table, group_index); /* * Assert that we are not trying to add an entry to a slot that is already * full. */ BUG_ON(group_value == SCIC_SDS_REMOTE_NODE_TABLE_FULL_SLOT_VALUE); if (group_value == 0x00) { /* * There are no entries in this slot so it must be added to the single * slot table. */ sci_remote_node_table_set_group_index(remote_node_table, 0, group_index); } else if ((group_value & (group_value - 1)) == 0) { /* * There is only one entry in this slot so it must be moved from the * single slot table to the dual slot table */ sci_remote_node_table_clear_group_index(remote_node_table, 0, group_index); sci_remote_node_table_set_group_index(remote_node_table, 1, group_index); } else { /* * There are two entries in the slot so it must be moved from the dual * slot table to the tripple slot table. */ sci_remote_node_table_clear_group_index(remote_node_table, 1, group_index); sci_remote_node_table_set_group_index(remote_node_table, 2, group_index); } sci_remote_node_table_set_node_index(remote_node_table, remote_node_index); }