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

📄 zl5011xlanlanlink.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 2 页
字号:
   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
            "zl5011xLanLanContextUpdateStructInit:",
            0, 0, 0, 0, 0, 0);

      par->context = ZL5011X_INVALID_CONTEXT;
      par->osExclusionEnable = ZL5011X_TRUE;
   }

   return status;
}

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

 Function:
    zl5011xLanLanContextUpdate

 Description:
   Update the specified Lan-to-Lan context

 Inputs:
    contextNumber          The context number to update

 Outputs:
    None

 Returns:
    zlStatusE              Any valid error code

 Remarks:

*******************************************************************************/
zlStatusE zl5011xLanLanContextUpdate(zl5011xParamsS *zl5011xParams,
         zl5011xContextS *par)
{
   zlStatusE status = ZL5011X_OK;
   zl5011xBooleanE gotDevice = ZL5011X_FALSE;

   /* do some parameter checking */
   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_RUNNING(zl5011xParams);
   }

   if ((status == ZL5011X_OK) && (par->osExclusionEnable == ZL5011X_TRUE))
   {
      /* get access to the device */
      status = zl5011xGetDevice(zl5011xParams, ZL5011X_GET_DEVICE_TIMEOUT_MODE);

      if (status == ZL5011X_OK)
      {
         gotDevice = ZL5011X_TRUE;
      }
   }

   /* check that the Lan context is valid and has been created */
   if (status == ZL5011X_OK)
   {
      status = zl5011xLanLanContextCheck(zl5011xParams, par->context, ZL5011X_CHECK_CONTEXT_INIT);
   }

   /* main function code starts */
   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
            "zl5011xLanLanContextUpdate:",
            0, 0, 0, 0, 0, 0);

      /* If a classifier rule has been set up then enable it now. */
      if (zl5011xParams->packetIf.classifierEnablePending[par->context] == ZL5011X_TRUE)
      {
         Uint32T selMatch = 0;  /* The selected match must be 0 for Lan-to-Lan contexts */
         Uint32T matchNum = zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].pkcClassifyMatchNum[selMatch];

         status = zl5011xPkcClassifyEnableEntry(zl5011xParams, matchNum);
         zl5011xParams->packetIf.classifierEnablePending[par->context] = ZL5011X_FALSE; /* Clear the pending flag */

         /* Set the state of this match to ACTIVE */
         zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[selMatch] = ZL5011X_PKC_STATE_MATCH_ACTIVE;
      }
   }

   if (status == ZL5011X_OK)
   {
      /* Set the state to indicate that update is complete.
         Both the PLA state (Wan Rx) and TFM state (Wan Tx) must be set */
      zl5011xParams->wanIf.plaCurrent.context[par->context].state = ZL5011X_STATE_ACTIVE; /* Set it for the PLA...*/
      zl5011xParams->wanIf.tfmCurrent.context[par->context].state = ZL5011X_STATE_ACTIVE; /* ...and for the TFM */
   }

   if (gotDevice == ZL5011X_TRUE)
   {
      if (status == ZL5011X_OK)
      {
         status = zl5011xReleaseDevice(zl5011xParams);
      }
      else
      {
         /* already have an error code, so don't overwrite it */
         (void)zl5011xReleaseDevice(zl5011xParams);
      }
   }

   return status;
}

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

 Function:
    zl5011xLanLanContextDelete

 Description:
   Teardown the specified context

 Inputs:
    contextNumber           The context number to be deleted
    forceDelete             unused

 Outputs:
    None

 Returns:
    zlStatusE               Any valid error code

 Remarks:

*******************************************************************************/
zlStatusE zl5011xLanLanContextDelete(zl5011xParamsS *zl5011xParams, zl5011xContextDeleteS *par)
{
    zlStatusE status = ZL5011X_OK;
    zl5011xBooleanE gotDevice = ZL5011X_FALSE;
    Uint32T matchNum;      /* The PKC match index used for this context */
    Uint32T selMatch = 0;  /* The actual match rule to use at this index position.
                              Within the PKC there are two possible rules for each match
                              but this must be 0 for Lan-to-Lan contexts */

    /* do some parameter checking */
    status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

    /* Check device is running and therefore initialised OK */
    if (status == ZL5011X_OK)
    {
        status = ZL5011X_CHECK_RUNNING(zl5011xParams);
    }

    /* Obtain exclusive access to the device if required */
    if ((status == ZL5011X_OK) && (par->osExclusionEnable == ZL5011X_TRUE))
    {
        /* get access to the device */
        status = zl5011xGetDevice(zl5011xParams, ZL5011X_GET_DEVICE_TIMEOUT_MODE);

        if (status == ZL5011X_OK)
        {
            gotDevice = ZL5011X_TRUE;
        }
    }

   /* Check Lan context is valid */
   if (status == ZL5011X_OK)
   {
      status = zl5011xLanLanContextCheck(zl5011xParams, par->context, ZL5011X_CHECK_CONTEXT_IN_USE);
   }

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE_CONTEXT(ZL5011X_LAN_FN_ID, par->context,
            "zl5011xLanContextDelete: ctxt %3d",
            par->context, 0, 0, 0, 0, 0);

      /* Disable and free up the context match. Only the first match is used for Lan-to-Lan contexts */
      if (zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[0] != ZL5011X_PKC_STATE_MATCH_NOT_ALLOCATED)
      {
         /* Disable the packet matching */
         selMatch = 0;  /* The selected match must be 0 for Lan-to-Lan contexts */
         matchNum = zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].pkcClassifyMatchNum[selMatch];

         status = zl5011xPkcClassifyDisableEntry(zl5011xParams, matchNum);

         zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[0] = ZL5011X_PKC_STATE_MATCH_UNUSED;
      }

   }

   /* Any context can be used either as a Lan-to-Lan context or as a Wan (TDM) context but not both.
      Therefore the context state for all contexts is stored in the Wan (TDM) part of the device structure.*/

   if (status == ZL5011X_OK)
   {
      /* Reset both the wan Tx and Rx state parameters for this context to ensure it can now
         be reused */
      zl5011xParams->wanIf.plaCurrent.context[par->context].state = ZL5011X_STATE_NOT_IN_USE;
      zl5011xParams->wanIf.tfmCurrent.context[par->context].state = ZL5011X_STATE_NOT_IN_USE;

      /* Clear the LanLan marker flag for this context */
      zl5011xParams->packetIf.lanLanContext[par->context] = ZL5011X_FALSE;

      /* Clear the flag that indicates there is a classifier rule for this context */
      zl5011xParams->packetIf.classifierEnablePending[par->context] = ZL5011X_FALSE;

      /* Purge context match if no longer required */
      (void)zl5011xLanRxPurgeContextHeaders(zl5011xParams, par->context);
   }

   /* Release the device */
   if (gotDevice == ZL5011X_TRUE)
   {
      if (status == ZL5011X_OK)
      {
         status = zl5011xReleaseDevice(zl5011xParams);
      }
      else
      {
         /* already have an error code, so don't overwrite it */
         (void)zl5011xReleaseDevice(zl5011xParams);
      }
   }

   return status;
}

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

 Function:
    zl5011xLanLanContextCheck

 Description:
   Used to check that a Lan-to-Lan context number is valid. Can also check that
   the context is in a valid state for modification - i.e. init

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

 Outputs:
   None

 Returns:
  zlStatusE

 Remarks:
  None

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

zlStatusE zl5011xLanLanContextCheck(zl5011xParamsS *zl5011xParams, Uint32T context,
      zl5011xCheckContextStateE check)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_MISC_FN_ID,
        "zl5011xLanContextCheck: ctxt %d, check %d",
         context, check, 0, 0, 0, 0);

   /* Check context number*/
   if (context >= zl5011xParams->devLimits.numContexts)
   {
      status = ZL5011X_CONTEXTID_RANGE;
   }


   /* Check the state this context is in compared to the requested check */
   if (status == ZL5011X_OK)
   {
      switch (check)
      {
         case ZL5011X_CHECK_CONTEXT_NUMBER:
               break;

         case ZL5011X_CHECK_CONTEXT_INIT:
               if ((zl5011xParams->wanIf.plaCurrent.context[context].state != ZL5011X_STATE_INIT) ||
                   (zl5011xParams->wanIf.tfmCurrent.context[context].state != ZL5011X_STATE_INIT))
               {
                  status = ZL5011X_CONTEXT_NOT_IN_INIT;
               }
               break;

         case ZL5011X_CHECK_CONTEXT_ACTIVE:
               if ((zl5011xParams->wanIf.plaCurrent.context[context].state != ZL5011X_STATE_ACTIVE) ||
                   (zl5011xParams->wanIf.tfmCurrent.context[context].state != ZL5011X_STATE_ACTIVE))
               {
                  status = ZL5011X_CONTEXT_NOT_ACTIVE;
               }
               break;

         case ZL5011X_CHECK_CONTEXT_IN_USE:
               if (((zl5011xParams->wanIf.plaCurrent.context[context].state != ZL5011X_STATE_INIT) &&
                    (zl5011xParams->wanIf.plaCurrent.context[context].state != ZL5011X_STATE_ACTIVE)) ||
                   ((zl5011xParams->wanIf.tfmCurrent.context[context].state != ZL5011X_STATE_INIT) &&
                    (zl5011xParams->wanIf.tfmCurrent.context[context].state != ZL5011X_STATE_ACTIVE)))
               {
                  status = ZL5011X_CONTEXT_NOT_IN_USE;
               }
               break;

         case ZL5011X_CHECK_CONTEXT_MODIFY:
         default:
               status = ZL5011X_PARAMETER_INVALID;
      }
   }

   return status;
}

/*****************   END   ****************************************************/


⌨️ 快捷键说明

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