⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zl5011xtfm.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
   }

   /* if the channel is associated with a context, then check if it is still in use */
   if (tempContext != (Uint32T)ZL5011X_INVALID_CONTEXT)
   {
      if (zl5011xParams->wanIf.tfmCurrent.context[tempContext].state == ZL5011X_STATE_TEARING_DOWN)
      {
         status = zl5011xTfmCheckContextTeardown(zl5011xParams, tempContext);

         /* if the return code indicates that the teardown completed, then this is not
            an error, so don't proliferate it */
         if (status == ZL5011X_CONTEXT_TEARDOWN_COMPLETE)
         {
            status = ZL5011X_OK;
         }
      }
      else
      {
         if (zl5011xParams->wanIf.tfmCurrent.context[tempContext].state == ZL5011X_STATE_UPDATING)
         {
            status = zl5011xTfmCheckContextUpdate(zl5011xParams, tempContext);

            /* if the return code indicates that the update completed, then this is not
               an error, so don't proliferate it */
            if (status == ZL5011X_CONTEXT_UPDATE_COMPLETE)
            {
               status = ZL5011X_OK;
            }
         }
      }

      /* the current and active structures will have been updated if any change
         had completed, so just check the structures */
      if (status == ZL5011X_OK)
      {
         *context = zl5011xParams->wanIf.tfmActive.channel[chanIndex].context;

         /* check the modification buffer if active is unused */
         if (*context == (Uint32T)ZL5011X_INVALID_CONTEXT)
         {
            *context = zl5011xParams->wanIf.tfmCurrent.channel[chanIndex].context;
         }
      }
   }
   else
   {
      *context = (Uint32T)ZL5011X_INVALID_CONTEXT;
   }

   return(status);
}

/*****************************************************************************

Function:
   zl5011xTfmCheckContextTeardown

Description:
   Reads from the device to see if the teardown has completed. If it has
   then the routine to clean up the structures is called.

Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context     which context to check

Outputs:
   None

Returns:
   zlStatusE

*****************************************************************************/

zlStatusE zl5011xTfmCheckContextTeardown(zl5011xParamsS *zl5011xParams, Uint32T context)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T readValue;

   ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmCheckContextTeardown: ctxt %3d",
         context, 0, 0, 0, 0, 0);

   if (zl5011xParams->wanIf.tfmCurrent.context[context].state != ZL5011X_STATE_TEARING_DOWN)
   {
      status = ZL5011X_CONTEXT_NOT_IN_TEARDOWN;
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams,
            ZL5011X_TFM_CONTEXT_MEMORY + (context * ZL5011X_TFM_CTXT_MEM_SIZE),
            &readValue);
   }

   if (status == ZL5011X_OK)
   {
      if ((readValue & (ZL5011X_1BIT_MASK << ZL5011X_TFM_TEARDOWN_BIT)) == 0)
      {
         /* the teardown bit is now clear, so update the current and active TFM
            structures */
         status = zl5011xTfmTearoutContext(zl5011xParams, context);

         if (status == ZL5011X_OK)
         {
            status = ZL5011X_CONTEXT_TEARDOWN_COMPLETE;
         }
      }
   }

   return(status);
}

/*****************************************************************************

Function:
   zl5011xTfmCheckContextUpdate

Description:
   Reads from the device to see if the update has completed. If it has
   then the routine to clean up the structures is called.

Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context     which context to check

Outputs:
   None

Returns:
   zlStatusE

*****************************************************************************/

zlStatusE zl5011xTfmCheckContextUpdate(zl5011xParamsS *zl5011xParams, Uint32T context)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T readValue;

   ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmCheckContextUpdate: ctxt %3d",
         context, 0, 0, 0, 0, 0);

   if (zl5011xParams->wanIf.tfmCurrent.context[context].state != ZL5011X_STATE_UPDATING)
   {
      status = ZL5011X_CONTEXT_NOT_IN_UPDATE;
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams,
            ZL5011X_TFM_CONTEXT_MEMORY + (context * ZL5011X_TFM_CTXT_MEM_SIZE),
            &readValue);
   }

   if (status == ZL5011X_OK)
   {
      if ((readValue & (ZL5011X_1BIT_MASK << ZL5011X_TFM_UPDATE_BIT)) == 0)
      {
         /* the update bit is now clear, so update the current and active TFM
            structures */
         status = zl5011xTfmUpdateActiveContext(zl5011xParams, context);

         if (status == ZL5011X_OK)
         {
            status = ZL5011X_CONTEXT_UPDATE_COMPLETE;
         }
      }
   }

   return(status);
}

/*****************************************************************************

Function:
   zl5011xTfmTearoutContext

Description:
   Removes all references to a context from both the active and current channel
   structures. Then resets the entries in the active and current context
   structures. Sets the state for the context to be not in use.

Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context     which context to clear up

Outputs:
   None

Returns:
   zlStatusE

*****************************************************************************/

zlStatusE zl5011xTfmTearoutContext(zl5011xParamsS *zl5011xParams, Uint32T context)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T loop;

   ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmTearoutContext: ctxt %3d",
         context, 0, 0, 0, 0, 0);

   /* reset the channel information for this context from the current and
      active structures */
   for (loop = 0; loop < ZL5011X_MAX_NUMBER_CHANNELS; loop++)
   {
      if ((zl5011xParams->wanIf.tfmCurrent.channel[loop].context == context) ||
         (zl5011xParams->wanIf.tfmActive.channel[loop].context == context))
      {
         zl5011xParams->wanIf.tfmCurrent.channel[loop].context = (Uint32T)ZL5011X_INVALID_CONTEXT;
         zl5011xParams->wanIf.tfmActive.channel[loop].context = (Uint32T)ZL5011X_INVALID_CONTEXT;
      }
   }

   zl5011xParams->wanIf.tfmCurrent.context[context].numChannels = 0;
   zl5011xParams->wanIf.tfmCurrent.context[context].firstChannelIndex = (Uint32T)ZL5011X_INVALID_CHANNEL;

   zl5011xParams->wanIf.tfmActive.context[context].numChannels = 0;
   zl5011xParams->wanIf.tfmActive.context[context].firstChannelIndex = (Uint32T)ZL5011X_INVALID_CHANNEL;

   /* the context now has no channels associated, the queue has flushed,
      so mark the context as no longer in use */
   zl5011xParams->wanIf.tfmCurrent.context[context].state = ZL5011X_STATE_NOT_IN_USE;
   zl5011xParams->wanIf.tfmActive.context[context].state = ZL5011X_STATE_NOT_IN_USE;

   return(status);
}

/*****************************************************************************

Function:
   zl5011xTfmUpdateActiveContext

Description:
   Copies the context setup from the current structures to the active
   structures. This frees up any channels that were used in the active channel
   but are no longer used.
   Sets the state for the context to be active.

Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context     which context to update

Outputs:
   None

Returns:
   zlStatusE

*****************************************************************************/

zlStatusE zl5011xTfmUpdateActiveContext(zl5011xParamsS *zl5011xParams, Uint32T context)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T loop;
   Uint8T activeHeader;

   ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmUpdateActiveContext: ctxt %3d",
         context, 0, 0, 0, 0, 0);

   /* copy the channel information from current to active structure */
   for (loop = 0; loop < ZL5011X_MAX_NUMBER_CHANNELS; loop++)
   {
      if ((zl5011xParams->wanIf.tfmCurrent.channel[loop].context == context) ||
         (zl5011xParams->wanIf.tfmActive.channel[loop].context == context))
      {
         zl5011xParams->wanIf.tfmActive.channel[loop].context =
               zl5011xParams->wanIf.tfmCurrent.channel[loop].context;
      }
   }

   /* copy the context information from current to active structure */
   (void)memcpy(zl5011xParams->wanIf.tfmActive.context + context,
         zl5011xParams->wanIf.tfmCurrent.context + context,
         sizeof(zl5011xWanTxContextS));

   zl5011xParams->wanIf.tfmCurrent.context[context].state = ZL5011X_STATE_ACTIVE;

   status = zl5011xTfmGetCurrentHeader(zl5011xParams, context, &activeHeader);

   if (status == ZL5011X_OK)
   {
      /* handle the header which is now active */
      switch (zl5011xParams->packetIf.packetRx.contextRxPacketMatch[context].contextMatchState[activeHeader])
      {
         case ZL5011X_PKC_STATE_MATCH_NOT_ALLOCATED:    /* intentional fall through */
         case ZL5011X_PKC_STATE_MATCH_UNUSED:
            /* do not return an error in this check, since these states indicate
               that the API is NOT being used to co-ordinate PKC and TFM updates */
            break;

         case ZL5011X_PKC_STATE_MATCH_NEW_UPDATING:
            zl5011xParams->packetIf.packetRx.contextRxPacketMatch[context].contextMatchState[activeHeader] = ZL5011X_PKC_STATE_MATCH_ACTIVE;
            break;

         case ZL5011X_PKC_STATE_MATCH_OLD_UPDATING:     /* intentional fall through */
         case ZL5011X_PKC_STATE_MATCH_ACTIVE:           /* intentional fall through */
         default :
            /* if the old match is still in use, then must be an error */
            status = ZL5011X_PKT_RX_CTXT_ERROR;
      }
   }

   if (status == ZL5011X_OK)
   {
      /* handle the header which is now inactive */
      switch (zl5011xParams->packetIf.packetRx.contextRxPacketMatch[context].contextMatchState[activeHeader ^ 1])
      {
         case ZL5011X_PKC_STATE_MATCH_NOT_ALLOCATED:    /* intentional fall through */
         case ZL5011X_PKC_STATE_MATCH_UNUSED:
            /* do not return an error in this check, since these states indicate
               that the API is NOT being used to co-ordinate PKC and TFM updates */
            break;

         case ZL5011X_PKC_STATE_MATCH_OLD_UPDATING:     /* intentional fall through */
         case ZL5011X_PKC_STATE_MATCH_NEW_UPDATING:
            /* the old match is now finished or the new match is not required - this would be the
               case when starting up a context switch type header */
            zl5011xParams->packetIf.packetRx.contextRxPacketMatch[context].contextMatchState[activeHeader ^ 1] = ZL5011X_PKC_STATE_MATCH_UNUSED;
            break;

         case ZL5011X_PKC_STATE_MATCH_ACTIVE:           /* intentional fall through */
         default :
            status = ZL5011X_PKT_RX_CTXT_ERROR;
      }
   }

   return(status);
}

/*****************************************************************************

Function:
   zl5011xTfmTeardownContext

Description:
   Sets the teardown bit for the context. If an update has been requested, then
   clear that and set the teardown bit.

Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context     which context

Outputs:
   None

Returns:
   zlStatusE

*****************************************************************************/

zlStatusE zl5011xTfmTeardownContext(zl5011xParamsS *zl5011xParams, Uint32T context)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T temp;
   Uint32T loop;

   ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmTeardownContext: ctxt %3d",
         context, 0, 0, 0, 0, 0);

   if (zl5011xParams->wanIf.tfmCurrent.context[context].state != ZL5011X_STATE_TAKEN)
   {
      status = ZL5011X_CONTEXT_NOT_TAKEN;
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams,
            ZL5011X_TFM_CONTEXT_MEMORY + (context * ZL5011X_TFM_CTXT_MEM_SIZE),
            &temp);
   }

   if (status == ZL5011X_OK)
   {
      /* if a teardown is requested, then cancel the update bit if it were
         set, since teardown is a higher priority */
      temp |= ZL5011X_1BIT_MASK << ZL5011X_TFM_TEARDOWN_BIT;
      temp &= ~(ZL5011X_1BIT_MASK << ZL5011X_TFM_UPDATE_BIT);

      status = zl5011xWrite(zl5011xParams,
            ZL5011X_TFM_CONTEXT_MEMORY + (context * ZL5011X_TFM_CTXT_MEM_SIZE),
            temp);

      zl5011xParams->wanIf.tfmCurrent.context[context].state = ZL5011X_STATE_TEARING_DOWN;

      /* update the packet matching variables, since the teardown has finished.
         There are potentially 2 Packet matching entries attached to a context, so
         update them both */
      for (loop = 0; loop < 2; loop++)
      {
         if (zl5011xParams->packetIf.packetRx.contextRxPacketMatch[context].contextMatchState[loop] != ZL5011X_PKC_STATE_MATCH_NOT_ALLOCATED)
         {
            zl5011xParams->packetIf.packetRx.contextRxPacketMatch[context].contextMatchState[loop] = ZL5011X_PKC_STATE_MATCH_UNUSED;
         }
      }
   }

   return(status);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -