/**
 * This method will allocate three consecutive remote node context entries. If
 * there are no remaining triple entries the function will return a failure.
 *
 * @param[in] remote_node_table This is the remote node table from which to
 *       allocate the remote node entries.
 * @param[in] group_table_index THis is the group table index which must equal
 *       two (2) for this operation.
 *
 * @return The remote node index that represents three consecutive remote node
 *         entries or an invalid remote node context if none can be found.
 */
static
U16 scic_sds_remote_node_table_allocate_triple_remote_node(
   SCIC_REMOTE_NODE_TABLE_T * remote_node_table,
   U32                        group_table_index
)
{
   U32 group_index;
   U16 remote_node_index = SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX;

   group_index = scic_sds_remote_node_table_get_group_index(
                                             remote_node_table, group_table_index);

   if (group_index != SCIC_SDS_REMOTE_NODE_TABLE_INVALID_INDEX)
   {
      remote_node_index = (U16) group_index * SCU_STP_REMOTE_NODE_COUNT;

      scic_sds_remote_node_table_clear_group_index(
         remote_node_table, group_table_index, group_index
      );

      scic_sds_remote_node_table_clear_group(
         remote_node_table, group_index
      );
   }

   return remote_node_index;
}
/**
 * This method will free a single remote node index back to the remote node
 * table.  This routine will update the remote node groups
 *
 * @param[in] remote_node_table
 * @param[in] remote_node_index
 */
static
void scic_sds_remote_node_table_release_single_remote_node(
   SCIC_REMOTE_NODE_TABLE_T * 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 = scic_sds_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.
   ASSERT(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.
      scic_sds_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
      scic_sds_remote_node_table_clear_group_index(remote_node_table, 0, group_index);
      scic_sds_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.
      scic_sds_remote_node_table_clear_group_index(remote_node_table, 1, group_index);
      scic_sds_remote_node_table_set_group_index(remote_node_table, 2, group_index);
   }

   scic_sds_remote_node_table_set_node_index(remote_node_table, remote_node_index);
}
/**
 * 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.
 *
 * @param[in out] remote_node_table The remote node table from which to
 *       allocate a remote node.
 * @param[in] table_index The group index that is to be used for the search.
 *
 * @return The RNi value or an invalid remote node context if an RNi can not
 *         be found.
 */
static
U16 scic_sds_remote_node_table_allocate_single_remote_node(
   SCIC_REMOTE_NODE_TABLE_T * 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 = scic_sds_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 = scic_sds_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);

            scic_sds_remote_node_table_clear_group_index(
               remote_node_table, group_table_index, group_index
            );

            scic_sds_remote_node_table_clear_node_index(
               remote_node_table, remote_node_index
            );

            if (group_table_index > 0)
            {
               scic_sds_remote_node_table_set_group_index(
                  remote_node_table, group_table_index - 1, group_index
               );
            }

            break;
         }
      }
   }

   return remote_node_index;
}
Ejemplo n.º 4
0
/**
 *
 * @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 scic_sds_remote_node_table_release_single_remote_node(
	struct scic_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 = scic_sds_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. */
		scic_sds_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 */
		scic_sds_remote_node_table_clear_group_index(remote_node_table, 0, group_index);
		scic_sds_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. */
		scic_sds_remote_node_table_clear_group_index(remote_node_table, 1, group_index);
		scic_sds_remote_node_table_set_group_index(remote_node_table, 2, group_index);
	}

	scic_sds_remote_node_table_set_node_index(remote_node_table, remote_node_index);
}