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

📄 ixhssacccommon.c

📁 有关ARM开发板上的IXP400网络驱动程序的源码以。
💻 C
📖 第 1 页 / 共 4 页
字号:
/** * @file IxHssAccCommon.c * * @author Intel Corporation * @date 30-Jan-02 * * @brief HssAccess Common Interface * *  * @par * IXP400 SW Release version 2.1 *  * -- Copyright Notice -- *  * @par * Copyright (c) 2001-2005, Intel Corporation. * All rights reserved. *  * @par * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. Neither the name of the Intel Corporation nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. *  *  * @par * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *  *  * @par * -- End of Copyright Notice --*//** * Put the system defined include files required. *//** * Put the user defined include files required. */#include "IxHssAccError_p.h"#include "IxNpeA.h"#include "IxOsal.h"#include "IxHssAccCommon_p.h"#include "IxHssAccNpeA_p.h"/* * Global variables */IxHssAccHssPort hssPortMax = IX_HSSACC_SINGLE_HSS_PORT; /**< Max no. of HSS ports available *//** * #defines and macros used in this file. */#define IX_HSSACC_LUT_TS_PER_WORD     (IX_HSSACC_LUT_BITS_PER_WORD / IX_HSSACC_LUT_BITS_PER_TS)#define IX_HSSACC_LUT_BYTES_PER_TRUNK 2#define IX_HSSACC_NUM_PORT_CONFIG_WORDS 22#define IX_HSSACC_COM_BYTE0_OFFSET 24#define IX_HSSACC_COM_BYTE1_OFFSET 16#define IX_HSSACC_COM_BYTE2_OFFSET  8#define IX_HSSACC_COM_BYTE3_OFFSET  0#define IX_HSSACC_PKT_PIPES_1 1#define IX_HSSACC_PKT_PIPES_2 2#define IX_HSSACC_PKT_PIPES_4 4/* maximum number of attempts to send messages to NpeMh */#define IX_HSSACC_NPEMH_SEND_RETRIES 16/* macros for mutex control for IxNpeMh responses */#define IX_HSSACC_COM_MUT_UNLOCK() ixOsalMutexUnlock (&ixHssAccComMutex)#define IX_HSSACC_COM_MUT_LOCK() ixOsalMutexLock (&ixHssAccComMutex, IX_OSAL_WAIT_FOREVER)/** * @def IX_HSSACC_TSLOTUSAGE_GET (HSSPORTID, TSLOTID, TSLOTUSAGE) * * @brief To extract the timeslot usage info for TSLOTID from HSS LUT words.  * There are total 16 HSS LUT Words per HSS port. They are equally shared by  * both tx and rx directions (i.e. one direction uses 8 HSS LUT Words). In  * order to find which LUT Word does TDM slot Id locate in, we divide the  * TDM slot Id with IX_HSSACC_LUT_TS_PER_WORD. In order to locate which bit  * position in the LUT Word that TDM slot Id is in, TDM slot Id is modulus  * with IX_HSSACC_LUT_TS_PER_WORD. Lastly, we use these Word and Bit  * positions that we calculated above to extract the timeslot usage for the  * specified TDM timeslot. * * @note Example of usage: IX_HSSACC_TSLOTUSAGE_GET(hssPortId,  * tdmSlot, tslotUsage) * * @param IxHssAccHssPort HSSPORTID (in) - The HSS port Id. There are two * identical ports (0-1). Only port 0 will be supported. * @param UINT32 TSLOTID (in) - TDM slot that is configured as * channelised timeslot (0-127). * @param IxHssAccTdmSlotUsage TSLOTUSAGE (out) - Timeslot usage of the  * specified TDM slot. * * @return  *         - IxHssAccTdmSlotUsage Timeslot usage for the specified TDM slot. * */#define IX_HSSACC_TSLOTUSAGE_GET(HSSPORTID, TSLOTID, TSLOTUSAGE) \{ \    UINT32 lutWordIndex; \    UINT32 lutTslotIndex; \    \    lutWordIndex  = (TSLOTID / IX_HSSACC_LUT_TS_PER_WORD); \    lutTslotIndex = (TSLOTID % IX_HSSACC_LUT_TS_PER_WORD); \    TSLOTUSAGE = ((ixHssAccComConfiguration[HSSPORTID].hssTxLUT[lutWordIndex]) >> \	(lutTslotIndex * IX_HSSACC_LUT_BITS_PER_TS)) & IX_HSSACC_LUT_TS_MASK; \}/** * Typedefs whose scope is limited to this file. */typedef enum{    IX_HSSACC_TX_PCR,    IX_HSSACC_RX_PCR} IxHssAccPcrType;/* IxHssAccComSysClk is used to program the HSS Co-p HSSCLKCR */typedef struct{    unsigned main;    unsigned num;    unsigned denom;} IxHssAccComSysClk;typedef struct{    unsigned validConfigs;    unsigned invalidConfigs;    unsigned emptyLastErrCbs;    unsigned npeCmdSends;    unsigned npeCmdResps;    unsigned npeReadResps;    unsigned npeCmdInvResps;    unsigned npeReadInvResps;} IxHssAccComStats;/* * The following structure will store the HSS configuration details as * written to the NPE during configuration for reference. The format of the * members map directly to that defined by the HSS co-processor.  */typedef struct{    UINT32 txPCR;         /* HSSTXPCR - tx port configuration register */    UINT32 rxPCR;         /* HSSRXRCR - rx port configuration register */    UINT32 cCR;           /* HSSCCR - core configuration register */    UINT32 clkCR;         /* HSSCLKCR - clock configuration register */    UINT32 txFCR;         /* HSSTXFCR - tx frame configuration register */    UINT32 rxFCR;         /* HSSRXFCR - rx frame configuration register */    UINT32 hssTxLUT[IX_HSSACC_LUT_WORDS_PER_LUT]; /* tx look-up-table for TDM slot 						   assignments */    UINT32 hssRxLUT[IX_HSSACC_LUT_WORDS_PER_LUT]; /* rx look-up-table for TDM slot 						   assignments */    unsigned numChannelised; /* The number of clients of the channelised 				service */    unsigned numPacketised;  /* The number of clients of the packetised 				service */    IxHssAccLastErrorCallback lastErrorCallback;  /* Client callback for 						     last error presentation */} IxHssAccComConfiguration;/** * Variable declarations global to this file only.  Externs are followed by * static variables. *//* the following mutex is used to block for NpeMh responses */static IxOsalMutex ixHssAccComMutex;static IxHssAccComStats ixHssAccComStats;static IxHssAccComConfiguration ixHssAccComConfiguration[IX_HSSACC_HSS_PORT_MAX];/* HSS Co-p clock divider for a 133MHz system clk */static IxHssAccComSysClk ixHssAccComSysClk133M[IX_HSSACC_CLK_SPEED_MAX] = {    { 130,   2,  15  }, /* 512KHz */    {  43,  18,  47  }, /* 1.536MHz */    {  43,  33, 192  }, /* 1.544MHz */    {  32,  34,  63  }, /* 2.048MHz */    {  16,  34, 127  }, /* 4.096MHz */    {   8,  34, 255  }  /* 8.192MHz */};/* HSSCCR HFIFO values in relation to number of packetised clients */static unsigned ixHssAccComHfifoValues[] = {    IX_HSSACC_NPE_HFIFO_ONE_BUFFER,   /* one packetised client */    IX_HSSACC_NPE_HFIFO_TWO_BUFFERS,  /* two packetised clients */    IX_HSSACC_NPE_HFIFO_FOUR_BUFFERS, /* three packetised clients */    IX_HSSACC_NPE_HFIFO_FOUR_BUFFERS  /* four packetised clients */};/* num pktPipes in relation to number of packetised clients */static unsigned ixHssAccComPktPipeValues[] = {    IX_HSSACC_PKT_PIPES_1, /* one packetised client */    IX_HSSACC_PKT_PIPES_2, /* two packetised clients */    IX_HSSACC_PKT_PIPES_4, /* three packetised clients */    IX_HSSACC_PKT_PIPES_4  /* four packetised clients */};static unsigned ixHssAccComPipeFifoSizew[][IX_HSSACC_HDLC_PORT_MAX] = {    { 4, 0, 0, 0 }, /* pipe0, pipe1, pipe2, pipe3 */    { 2, 2, 0, 0 },    { 1, 1, 1, 1 }};/* * This is required for un-init */static BOOL ixHssAccMutexInitialised = FALSE;/** * Extern function prototypes. *//** * Static function prototypes. */PRIVATE IX_STATUS ixHssAccComPortConfigWrite (IxHssAccHssPort hssPortId, 			    IxHssAccConfigParams *configParams, 			    IxHssAccTdmSlotUsage *tdmMap,			    unsigned *maxPktTrunkInTdmMap);PRIVATE IX_STATUS ixHssAccComPipeInfoWrite (IxHssAccHssPort hssPortId, 			  unsigned hfifoValue,			  unsigned packetizedIdlePattern);PRIVATE IX_STATUS ixHssAccComPCRCreate (IxHssAccPcrType type, 		      IxHssAccPortConfig *txPortConfig, 		      unsigned *txPCR);PRIVATE IX_STATUS ixHssAccComCCRCreate (unsigned hdlcPortCount, 		      BOOL loopback, 		      IxHssAccHssPort hssPortId, 		      unsigned *ccr);PRIVATE IX_STATUS ixHssAccComClkCRCreate (IxHssAccClkSpeed clkRate, unsigned *clkCR);PRIVATE IX_STATUS ixHssAccComFCRCreate (unsigned offset, unsigned size, unsigned *fcr);PRIVATE IX_STATUS ixHssAccComHssLUTCreate (IxHssAccTdmSlotUsage *tdmMap, 			 unsigned numHdlcClients,			 unsigned numChans,			 IxHssAccClkSpeed clkSpeed,			 unsigned *pHssLUT,			 unsigned *maxPktTrunkInTdmMap);PRIVATE IX_STATUS ixHssAccComPortConfigLoad (IxHssAccHssPort hssPortId);PRIVATE voidixHssAccComNpeErrorTranslate (unsigned lastNpeError, unsigned *lastError, 			      unsigned *servicePort);PRIVATE BOOLixHssAccComPCRCreateComParamsInvalid (IxHssAccPortConfig *portConfig);PRIVATE BOOL ixHssAccComPCRCreateTxParamsInvalid (IxHssAccPortConfig *portConfig);PRIVATE voidixHssAccComEmptyLastErrorCallback (unsigned lastHssError, 				   unsigned servicePort);PRIVATE voidixHssAccComClkSpeedToNumTrunks (IxHssAccClkSpeed clkSpeed,                                 unsigned *numTrunks);void ixHssAccComNpeCmdRespCallback (IxNpeMhNpeId npeId, IxNpeMhMessage msg);void ixHssAccComNpeReadRespCallback (IxNpeMhNpeId npeId, IxNpeMhMessage msg);/** * Function definition: ixHssAccComPortInit */IX_STATUS ixHssAccComPortInit (IxHssAccHssPort hssPortId, 		     IxHssAccConfigParams *configParams, 		     IxHssAccTdmSlotUsage *tdmMap, 		     IxHssAccLastErrorCallback lastErrorCallback){    IX_STATUS status = IX_SUCCESS;    unsigned chanIdlePattern;    unsigned hssPktChannelCount = configParams->hssPktChannelCount;    unsigned hfifoValue;    unsigned maxPktTrunkInTdmMap;    unsigned msgData;    IxNpeMhMessage npeMhMsg;    IX_HSSACC_TRACE0 (IX_HSSACC_FN_ENTRY_EXIT, "Entering ixHssAccComPortInit\n");    /* Parameters error checked in the service interface already */    /*      * the following functionality creates HSS Co-p register formats and writes      * them to the NPE via the Message Handler. When all have been written, a     * config cmd is sent.     */    if (status == IX_SUCCESS)    {	/* create and send the port configuration details */	status = ixHssAccComPortConfigWrite (hssPortId, configParams, tdmMap,					     &maxPktTrunkInTdmMap);    }    if (status == IX_SUCCESS)    {	/* Create the channelised idle pattern (1word) from the byte passed */	chanIdlePattern = 	    (configParams->channelisedIdlePattern << IX_HSSACC_COM_BYTE0_OFFSET) |	    (configParams->channelisedIdlePattern << IX_HSSACC_COM_BYTE1_OFFSET) |	    (configParams->channelisedIdlePattern << IX_HSSACC_COM_BYTE2_OFFSET) |	    (configParams->channelisedIdlePattern << IX_HSSACC_COM_BYTE3_OFFSET);	/* Send the channelised idle pattern to the NPE via the message handler */	ixHssAccComNpeCmdMsgCreate (IX_NPE_A_MSSG_HSS_CHAN_IDLE_PATTERN_WRITE,				       0, hssPortId, 0, chanIdlePattern, &npeMhMsg);				       	status = ixHssAccComNpeCmdMsgSend (npeMhMsg, 					   FALSE, /* no response expected */					   IX_NPE_A_MSSG_HSS_CHAN_IDLE_PATTERN_WRITE);    }    if (status == IX_SUCCESS)    {	/* Send the num channelised clients to the NPE via the message handler */	/* save for reference */	ixHssAccComConfiguration[hssPortId].numChannelised = 	    configParams->numChannelised;	msgData = configParams->numChannelised <<	    IX_HSSACC_NPE_CHAN_NUMCHANS_OFFSET;	ixHssAccComNpeCmdMsgCreate (IX_NPE_A_MSSG_HSS_CHAN_NUM_CHANS_WRITE,				    0, hssPortId, 0, 				    msgData, &npeMhMsg);				       	status = ixHssAccComNpeCmdMsgSend (npeMhMsg, 					   FALSE, /* no response expected */					   IX_NPE_A_MSSG_HSS_CHAN_NUM_CHANS_WRITE);    }    if (status == IX_SUCCESS)    {	/* Send the num packetised clients to the NPE via the message handler */	/* save for reference */	ixHssAccComConfiguration[hssPortId].numPacketised = hssPktChannelCount;	msgData = ixHssAccComPktPipeValues[maxPktTrunkInTdmMap] <<	    IX_HSSACC_NPE_PKT_NUMPIPES_OFFSET;	ixHssAccComNpeCmdMsgCreate (IX_NPE_A_MSSG_HSS_PKT_NUM_PIPES_WRITE,				    0, hssPortId, 0, 				    msgData, 				    &npeMhMsg);				       	status = ixHssAccComNpeCmdMsgSend (npeMhMsg, 					   FALSE, /* no response expected */					   IX_NPE_A_MSSG_HSS_PKT_NUM_PIPES_WRITE);    }    /* write the pipe info values to the NPE via the message handler */    if (status == IX_SUCCESS)    {	hfifoValue = ixHssAccComHfifoValues[maxPktTrunkInTdmMap];	status = ixHssAccComPipeInfoWrite (hssPortId, hfifoValue,					   configParams->packetizedIdlePattern);    }    if (status == IX_SUCCESS)    {	/* inform the NPE that all config params have been loaded */	status = ixHssAccComPortConfigLoad (hssPortId);    }    /* save for reference */

⌨️ 快捷键说明

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