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

📄 le1veconfig.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
      zl5011xLanRxDeleteContextMatchS *par)
{
   Uint32T matchNum;
   zlStatusE status = ZL5011X_OK;
   Uint8T hdrLoop = 0;
   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;
      }
   }
#if 0
   /* check that the Wan Tx context is valid */
   if (status == ZL5011X_OK)
   {
      status = zl5011xContextCheckTx(zl5011xParams, par->context, ZL5011X_CHECK_CONTEXT_MODIFY);
   }
#endif
   /* main function code starts */

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

   for (hdrLoop = 0; hdrLoop < ZL5011X_LAN_RX_NUM_MATCHES_PER_CONTEXT; hdrLoop++)
   {
      if (status != ZL5011X_OK)
      {
         break;
      }

      switch (zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[hdrLoop])
      {
         case ZL5011X_PKC_STATE_MATCH_ACTIVE:           /* intentional fall through */
         case ZL5011X_PKC_STATE_MATCH_NOT_ALLOCATED:    /* intentional fall through */
         case ZL5011X_PKC_STATE_MATCH_UNUSED:
            /* no action required for these states */
            break;

         case ZL5011X_PKC_STATE_MATCH_NEW_UPDATING:
            zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[hdrLoop] = ZL5011X_PKC_STATE_MATCH_UNUSED;
            break;

         case ZL5011X_PKC_STATE_MATCH_OLD_UPDATING:
            zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[hdrLoop] = ZL5011X_PKC_STATE_MATCH_ACTIVE;
            break;

         default :
            status = ZL5011X_PKT_RX_CTXT_ERROR;
      }
      /*shf modify 2005.10.10*/
      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[hdrLoop] != ZL5011X_PKC_STATE_MATCH_NOT_ALLOCATED)
          {
             /* Disable the packet matching */
               /* The selected match must be 0 for Lan-to-Lan contexts */
             matchNum = zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].pkcClassifyMatchNum[hdrLoop];
    
             status = zl5011xPkcClassifyDisableEntry(zl5011xParams, matchNum);
    
             zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[hdrLoop] = ZL5011X_PKC_STATE_MATCH_UNUSED;
          }

      }
   }
   
   if (status == ZL5011X_OK)
   {
      status = zl5011xLanRxPurgeContextHeaders(zl5011xParams, par->context);
   }

   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;
}
/*****************************
*drv_Le1vePacketForwardSetContextMatch - set context match
*Description:
*                to set the context match for icmp or arp
*
*Arguement:
*                 IN: par->context, par->portnum, par->quenenum, par->header
*                       par->enableVlan , par->ethernetSrcAddressFromMac
*
*return:
* OK or ERROR
*------------------------------
*modify history
*------------------------------
*2005.7.5 shf created
*
******************************/
zlStatusE drv_Le1vePacketForwardSetContextMatch(zl5011xParamsS *zl5011xParams,
      zl5011xLanRxSetContextMatchS *par)
{
   zlStatusE status = ZL5011X_OK;
   zl5011xBooleanE assignedMatch;
   Uint8T selHeader = 0;
   zl5011xBooleanE gotDevice = ZL5011X_FALSE;
   zl5011xBooleanE foundHeader;    /* Flag for whether we have a free header */

   /* 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;
      }
   }
#if 0
   /* check that the Wan Tx context is valid */
   if (status == ZL5011X_OK)
   {
      status = zl5011xContextCheckTx(zl5011xParams, par->context, ZL5011X_CHECK_CONTEXT_MODIFY);
   }
#endif

   /* main function code starts */


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

      /* Find a free header for this context */
      selHeader = 0;
      foundHeader = ZL5011X_FALSE;
      while (selHeader < ZL5011X_LAN_RX_NUM_MATCHES_PER_CONTEXT)
      {
          /* determine whether the header is available */
          if ((zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[selHeader] == ZL5011X_PKC_STATE_MATCH_NOT_ALLOCATED) ||
                (zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[selHeader] == ZL5011X_PKC_STATE_MATCH_UNUSED))
          {
             foundHeader = ZL5011X_TRUE;
             break;
          }
          selHeader++;
      }
      /* Check whether we found one or not */
      if (foundHeader == ZL5011X_FALSE)
      {
         status = ZL5011X_PKT_HEADER_IN_USE;
      }
   }

   if (status ==ZL5011X_OK)
   {
      /* if the header already has a match associated, then check that it is
         consistent with the one requested */
      if (zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[selHeader] == ZL5011X_PKC_STATE_MATCH_UNUSED)
      {
         /* this header is not in use, so use for this setup, provided the match number requested is okay */
         if (par->matchNum == (Uint32T)ZL5011X_INVALID)
         {
            /* automatically allocate a match, so take the one from the device structure */
            par->matchNum = zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].pkcClassifyMatchNum[selHeader];
         }
         else
         {
            /* check that the requested number is the same as the one already allocated */
            if (par->matchNum != zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].pkcClassifyMatchNum[selHeader])
            {
               status = ZL5011X_PKT_INVALID_MATCH_NUM;
            }
         }
      }
   }
   /* reserve the match entry in the pkc classifier */
   if (status == ZL5011X_OK)
   {
      status = zl5011xPkcClassifyGetFreeEntry(zl5011xParams, &(par->matchNum));

      /* if there are no available matches in the PKC classifier, then go
         through and purge any unused matches and try again */
      if (status == ZL5011X_NO_AVAIL_CLASSIFY_MATCH)
      {
         /* setting the context number to ZL5011X_INVALID for this function
            call forces the check for unused matches to take place on
            all contexts */
         status = zl5011xLanRxPurgeContextHeaders(zl5011xParams, ZL5011X_INVALID);

         if (status == ZL5011X_OK)
         {
            /* some matches should have been free'd up so try again */
            status = zl5011xPkcClassifyGetFreeEntry(zl5011xParams, &(par->matchNum));
         }
      }

      /* if a match has been reserved then remember, so that it can be
         free'd up if things go wrong */
      if (status == ZL5011X_OK)
      {
         assignedMatch = ZL5011X_TRUE;
      }
      else
      {
         /* if the classifier match had already been allocated and used by this header
            then just continue, but disable the entry before re-programming it. */
         if (status == ZL5011X_CLASSIFY_MATCH_IN_USE)
         {
            if (par->matchNum == zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].pkcClassifyMatchNum[selHeader])
            {
               status = zl5011xPkcClassifyDisableEntry(zl5011xParams, par->matchNum);
            }
         }
      }
   }

   /* setup the classifier match */
   if (status == ZL5011X_OK)
   {
      if (par->output.classifyMpid == (Uint32T)ZL5011X_INVALID)
      {
         /* if the mpid hasn't been explicitly set, then set the MPID field to
            represent the context number */
         par->output.classifyMpid = (par->context & ZL5011X_PKC_CLASSIFY_CONTEXT_MASK);

         /* Add in the state of the context switch bit */
         par->output.classifyMpid |= ((selHeader & ZL5011X_1BIT_MASK) << ZL5011X_PKC_CLASSIFY_CONTEXT_SWITCH_BIT);
      }

      if ((int)(par->output.classifyFlow) == ZL5011X_INVALID)
      {
         /* if the flow hasn't been explicitly set, then use the value
            as set during context creation */
         par->output.classifyFlow = zl5011xParams->wanIf.wanTxFlow[par->context];
      }

      status = zl5011xPkcClassifySetContextMatch(zl5011xParams,
            par->context, par->matchNum, &(par->match), &(par->output));
   }

   /* enable the classifier match if it has been set up successfully */
   if (status == ZL5011X_OK)
   {
      status = zl5011xPkcClassifyEnableEntry(zl5011xParams, par->matchNum);

      /* update the state variables for the match */
     /* Set state of the new header to indicate it will become active on next context switch */
      zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[selHeader] = ZL5011X_PKC_STATE_MATCH_NEW_UPDATING;
      zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].pkcClassifyMatchNum[selHeader] = par->matchNum;

      /* Set the state of the other header to indicate it is going to become inactive */
      if (zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[selHeader ^ 1] == ZL5011X_PKC_STATE_MATCH_ACTIVE)
      {
         zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].contextMatchState[selHeader ^ 1] = ZL5011X_PKC_STATE_MATCH_OLD_UPDATING;
      }
   }
   else
   {
      /* failed, so free up the match number if it was allocated by this
         function */
      if (assignedMatch == ZL5011X_TRUE)
      {
         /* ignore the return code, since we already have an error. Just
            recover as best as possible */
         (void)zl5011xPkcClassifyDeleteEntry(zl5011xParams, par->matchNum);
      }
   }

   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;
}
/*****************************
*drv_Le1vePacketForwardTxSetHeader - set packettx header
*Description:
*                to set the packettx head for icmp or arp
*
*Arguement:
*                 IN: par->context, par->portnum, par->quenenum, par->header
*                       par->enableVlan , par->ethernetSrcAddressFromMac
*
*return:
* OK or ERROR
*------------------------------
*modify history
*------------------------------
*2005.7.5 shf created
*
******************************/
zlStatusE drv_Le1vePacketForwardTxSetHeader(zl5011xParamsS *zl5011xParams,
      Le1vePacketForwardConfigs *par)
{
	zlStatusE status = ZL5011X_OK;
	/*zl5011xLanTxSetLayer2and3HeaderS  *layer2and3Header = NULL;*/
 	status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
	if (status == ZL5011X_OK)
	{
	  status = ZL5011X_CHECK_RUNNING(zl5011xParams);
	}

	if (status == ZL5011X_OK)
	{
	  if (par->portNum >= zl5011xParams->devLimits.lanNumLanPorts)
	  {
	     status = ZL5011X_PARAMETER_INVALID;
	  }
	}
    #if 0
	if (status == ZL5011X_OK)
	{
	 /* Allocate memory for the header structure */
	  layer2and3Header = (zl5011xLanTxSetLayer2and3HeaderS *)calloc(
	        sizeof(zl5011xLanTxSetLayer2and3HeaderS), 1);

	  if (layer2and3Header == NULL)
	  {
	     status = ZL5011X_RTOS_MEMORY_FAIL;
	  }
	}

	if (status == ZL5011X_OK)
	{
	  status = zl5011xLanTxSetLayer2and3HeaderStructInit(zl5011xParams, layer2and3Header);
	}

	/* Copy structure members across for the header construction functions */
	if (status == ZL5011X_OK)
	{

⌨️ 快捷键说明

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