MV_STATUS mvNfpSecInit(MV_U32 dbSize) { if (dbSize == 0) return MV_BAD_PARAM; spdInDb = (struct _mv_nfp_sec_spd_rule *)mvOsMalloc(dbSize * (sizeof(struct _mv_nfp_sec_spd_rule))); spdOutDb = (struct _mv_nfp_sec_spd_rule *)mvOsMalloc(dbSize * (sizeof(struct _mv_nfp_sec_spd_rule))); saInDb = (struct _mv_nfp_sec_sa_entry *)mvOsMalloc(dbSize * (sizeof(struct _mv_nfp_sec_sa_entry))); saOutDb = (struct _mv_nfp_sec_sa_entry *)mvOsMalloc(dbSize * (sizeof(struct _mv_nfp_sec_sa_entry))); if ((spdInDb == NULL) || (spdOutDb == NULL) || (saInDb == NULL) || (saOutDb == NULL)) { mvOsPrintf("NFP-IPSec Rules DB: Not Enough Memory\n"); return MV_NO_RESOURCE; } secDbSize = dbSize; spdInRuleCount = spdOutRuleCount = saInEntryCount = saOutEntryCount = 0; memset(spdInDb, 0, (dbSize * sizeof(struct _mv_nfp_sec_spd_rule))); memset(spdOutDb, 0, (dbSize * sizeof(struct _mv_nfp_sec_spd_rule))); memset(saInDb, 0, (dbSize * sizeof(struct _mv_nfp_sec_sa_entry))); memset(saOutDb, 0, (dbSize * sizeof(struct _mv_nfp_sec_sa_entry))); return MV_OK; }
MV_STATUS mvCesaIfHalInit(int numOfSession, int queueDepth, void *osHandle, MV_CESA_HAL_DATA *halData) { /* Init globals */ memset(chanWeight, 0, (MV_CESA_CHANNELS * sizeof(MV_U64))); memset(chanFlowType, 0, (MV_CESA_CHANNELS * sizeof(MV_CESA_FLOW_TYPE))); currCesaPolicy = CESA_NULL_POLICY; splitChanId = 0; if(MV_CESA_CHANNELS > 1) { currReqId = 0; gReqId = 0; reqEmpty = 0; resQueueDepth = ((MV_CESA_CHANNELS * queueDepth * 2)); /* Allocate reordered results queue */ pResQueue = (MV_CESA_RESULT**)mvOsMalloc(resQueueDepth * sizeof(MV_CESA_RESULT*)); if(pResQueue == NULL) { mvOsPrintf("%s: Error, pResQueue malloc failed\n", __func__); return MV_ERROR; } resQueue = (MV_CESA_RESULT*)mvOsMalloc(resQueueDepth * sizeof(MV_CESA_RESULT)); if(resQueue == NULL) { mvOsPrintf("%s: Error, resQueue malloc failed\n", __func__); return MV_ERROR; } memset(pResQueue, 0, (resQueueDepth * sizeof(MV_CESA_RESULT*))); memset(resQueue, 0, (resQueueDepth * sizeof(MV_CESA_RESULT))); memset(readyStatus, MV_TRUE, (MV_CESA_CHANNELS * sizeof(MV_STATUS))); } return mvCesaHalInit(numOfSession, queueDepth, osHandle, halData); }
int __devinit mv_l2fw_init(void) { int size, port; MV_U32 bytes; MV_U32 regVal; mv_eth_ports_l2fw_num = mvCtrlEthMaxPortGet(); mvOsPrintf("in %s: mv_eth_ports_l2fw_num=%d\n", __func__, mv_eth_ports_l2fw_num); size = mv_eth_ports_l2fw_num * sizeof(struct eth_port_l2fw *); mv_eth_ports_l2fw = mvOsMalloc(size); if (!mv_eth_ports_l2fw) goto oom; memset(mv_eth_ports_l2fw, 0, size); for (port = 0; port < mv_eth_ports_l2fw_num; port++) { mv_eth_ports_l2fw[port] = mvOsMalloc(sizeof(struct eth_port_l2fw)); if (!mv_eth_ports_l2fw[port]) goto oom1; mv_eth_ports_l2fw[port]->cmd = L2FW_DISABLE; mv_eth_ports_l2fw[port]->txPort = -1; } bytes = sizeof(L2FW_RULE *) * L2FW_HASH_SIZE; l2fw_jhash_iv = mvOsRand(); l2fw_hash = (L2FW_RULE **)mvOsMalloc(bytes); if (l2fw_hash == NULL) { mvOsPrintf("l2fw hash: not enough memory\n"); return MV_NO_RESOURCE; } mvOsMemset(l2fw_hash, 0, bytes); mvOsPrintf("L2FW hash init %d entries, %d bytes\n", L2FW_HASH_SIZE, bytes); regVal = 0; #ifdef CONFIG_MV_ETH_L2SEC cesa_init(); #endif #ifdef CONFIG_MV_INCLUDE_XOR setXorDesc(); #endif return 0; oom: mvOsPrintf("%s: out of memory in L2FW initialization\n", __func__); oom1: mvOsFree(mv_eth_ports_l2fw); return -ENOMEM; }
/******************************************************************************* * mvEthTxPolicyDef - Set TX default policy. * * DESCRIPTION: * This function configures TX default policy for packets that * there is no information for them * * INPUT: * void* pTxPolHndl - TX Policy component handler * MV_ETH_TX_POLICY_ENTRY policy - Default TX policy * * RETURN: MV_STATUS * MV_OK - Success * MV_FAIL - Failed. * *******************************************************************************/ MV_STATUS mvEthTxPolicyDef(void* pTxPolHndl, MV_ETH_TX_POLICY_ENTRY* pPolicy) { ETH_TX_POLICY* pTxPolicy = (ETH_TX_POLICY*)pTxPolHndl; /* if Tx header exist */ if(pPolicy->pHeader != NULL) { /* allocate memory for header */ pTxPolicy->txPolDef.pHeader = mvOsMalloc(pPolicy->headerSize ); if(pTxPolicy->txPolDef.pHeader == NULL) { mvOsPrintf("mvEthTxPolicyDef: Alloc failed \n"); return MV_FAIL; } /* copy header */ memcpy(pTxPolicy->txPolDef.pHeader, pPolicy->pHeader , pPolicy->headerSize ); pTxPolicy->txPolDef.headerSize = pPolicy->headerSize; } else { pTxPolicy->txPolDef.pHeader = NULL; pTxPolicy->txPolDef.headerSize = 0; } pTxPolicy->txPolDef.txQ = pPolicy->txQ; return MV_OK; }
/******************************************************************************* * mvEthRxPolicyInit - Initialize RX policy component. * * DESCRIPTION: * Create RX policy database for ethernet port, set to it to default * (FIXED mode) and return port handle. * * INPUT: * int port - Ethernet port number * * * RETURN: * void* pRxPolicyHndl - RX Policy component handler; * *******************************************************************************/ void* mvEthRxPolicyInit(int port, int defQuota, MV_ETH_PRIO_MODE defMode) { int queue; if( (port < 0) || (port >= mvCtrlEthMaxPortGet()) ) { mvOsPrintf("ethRxPolicy: port #%d is not exist\n", port); return NULL; } rxPolicy[port] = mvOsMalloc(sizeof(ETH_RX_POLICY)); if(rxPolicy[port] == NULL) { mvOsPrintf("ethRxPolicy: Port #%d, Can't allocate %d bytes\n", port, sizeof(ETH_RX_POLICY)); return NULL; } /* Set defaults */ memset(rxPolicy[port], 0, sizeof(ETH_RX_POLICY)); for(queue=0; queue<MV_ETH_RX_Q_NUM; queue++) { rxPolicy[port]->rxQuota[queue] = defQuota; } rxPolicy[port]->port = port; rxPolicy[port]->rxPrioMode = defMode; rxPolicy[port]->rxCurQ = MV_ETH_RX_Q_NUM-1; rxPolicy[port]->rxCurQuota = rxPolicy[port]->rxQuota[rxPolicy[port]->rxCurQ]; return rxPolicy[port]; }
/******************************************************************************* * mvEthTxPolicyInit - Initialize TX policy component. * * DESCRIPTION: * Create TX policy database for ethernet port, set to it to default * values and return port handle. * * INPUT: * int port - Ethernet port number * * * RETURN: * void* pTxPolHndl - TX Policy component handler * *******************************************************************************/ void* mvEthTxPolicyInit(int port, MV_ETH_TX_POLICY_ENTRY* pDefPolicy) { int daIdx; if( (port < 0) || (port >= mvCtrlEthMaxPortGet()) ) { mvOsPrintf("ethTxPolicy: port #%d is not exist\n", port); return NULL; } txPolicy[port] = mvOsMalloc(sizeof(ETH_TX_POLICY)); if(txPolicy[port] == NULL) { mvOsPrintf("ethTxPolicy: Port #%d, Can't allocate %d bytes\n", port, sizeof(ETH_TX_POLICY)); return NULL; } /* Set defaults */ memset(txPolicy[port], 0, sizeof(ETH_TX_POLICY)); txPolicy[port]->port = port; mvEthTxPolicyDef(txPolicy[port],pDefPolicy); /* Invalidate all entries */ txPolicy[port]->txPolMaxDa = 0; for(daIdx=0; daIdx<MV_ETH_TX_POLICY_MAX_MACDA; daIdx++) txPolicy[port]->txPolDa[daIdx].policy.txQ = MV_INVALID; return txPolicy[port]; }
/* in the Routing + ARP information table */ MV_STATUS mvFpRuleSet(MV_FP_RULE *pSetRule) { MV_U32 hash, hash_tr; int depth = 0; MV_FP_RULE *pRule, *pNewRule; hash = mv_jhash_3words(pSetRule->routingInfo.dstIp, pSetRule->routingInfo.srcIp, (MV_U32) 0, fp_ip_jhash_iv); hash_tr = hash & (ruleDbSize - 1); pRule = ruleDb[hash_tr].ruleChain; while (pRule) { if ((pRule->routingInfo.srcIp == pSetRule->routingInfo.srcIp && pRule->routingInfo.dstIp == pSetRule->routingInfo.dstIp)) { mvFpRuleCopy(pRule, pSetRule); nfpRuleUpdateCount++; #ifdef MV_FP_DEBUG mvOsPrintf("UpdNFP_%03u: DIP=%u.%u.%u.%u, SIP=%u.%u.%u.%u, hash=0x%04x TOS=0x%x TxQ=%d\n", nfpRuleUpdateCount, MV_IP_QUAD(pSetRule->routingInfo.dstIp), MV_IP_QUAD(pSetRule->routingInfo.srcIp), hash_tr, pRule->routingInfo.dscp, pRule->routingInfo.txq); #endif return MV_OK; } pRule = pRule->next; } /* Allocate new entry */ pNewRule = mvOsMalloc(sizeof(MV_FP_RULE)); if (pNewRule == NULL) { mvOsPrintf("mvFpRuleSet: Can't allocate new rule\n"); return MV_FAIL; } mvFpRuleCopy(pNewRule, pSetRule); pNewRule->next = NULL; if (ruleDb[hash_tr].ruleChain == NULL) ruleDb[hash_tr].ruleChain = pNewRule; else { pRule = ruleDb[hash_tr].ruleChain; while (pRule->next != NULL) { depth++; pRule = pRule->next; } pRule->next = pNewRule; } if (depth > nfpHashMaxDepth) nfpHashMaxDepth = depth; nfpRuleSetCount++; #ifdef MV_FP_DEBUG mvOsPrintf("SetNFP_%03u: DIP=%u.%u.%u.%u, SIP=%u.%u.%u.%u, hash=0x%04x, aware=0x%02x\n", nfpRuleSetCount, MV_IP_QUAD(pSetRule->routingInfo.dstIp), MV_IP_QUAD(pSetRule->routingInfo.srcIp), hash_tr, pSetRule->routingInfo.aware_flags); #endif return MV_OK; }
/* Purpose: Create new stack * Inputs: * - MV_U32 noOfElements - maximum number of elements in the stack. * Each element 4 bytes size * Return: void* - pointer to created stack. */ void* mvStackCreate(int numOfElements) { MV_STACK* pStack; MV_U32* pStackElements; pStack = (MV_STACK*)mvOsMalloc(sizeof(MV_STACK)); pStackElements = (MV_U32*)mvOsMalloc(numOfElements*sizeof(MV_U32)); if( (pStack == NULL) || (pStackElements == NULL) ) { mvOsPrintf("mvStack: Can't create new stack\n"); return NULL; } memset(pStackElements, 0, numOfElements*sizeof(MV_U32)); pStack->numOfElements = numOfElements; pStack->stackIdx = 0; pStack->stackElements = pStackElements; return pStack; }
/******************************************************************************* * mvEthTxPolicyAdd - Add TX policy for packets with special MAC DA. * * DESCRIPTION: * This function adds TX policy for outgoing packets with special MAC DAs. * Support up to 16 entries. * * INPUT: * void* pTxPolHndl - TX Policy component handler * MV_ETH_TX_POLICY_MACDA daPolicy - TX policy for outgoing packets * with specific MACDA * * RETURN: MV_STATUS * MV_OK - Success * MV_FAIL - Failed. * *******************************************************************************/ MV_STATUS mvEthTxPolicyAdd(void* pTxPolHndl, MV_ETH_TX_POLICY_MACDA* pDaPolicy) { int idx, firstEmptyIdx = MV_INVALID; ETH_TX_POLICY* pTxPolicy = (ETH_TX_POLICY*)pTxPolHndl; for(idx=0; idx<MV_ETH_TX_POLICY_MAX_MACDA; idx++) { if( (pTxPolicy->txPolDa[idx].policy.txQ != MV_INVALID) && ( memcmp(pTxPolicy->txPolDa[idx].macDa, pDaPolicy->macDa, MV_MAC_ADDR_SIZE) == 0) ) { /* entry already exist - so replace */ firstEmptyIdx = idx; break; } if( (firstEmptyIdx == MV_INVALID) && (pTxPolicy->txPolDa[idx].policy.txQ == MV_INVALID) ) { firstEmptyIdx = idx; } } if(firstEmptyIdx != MV_INVALID) { memcpy(pTxPolicy->txPolDa[firstEmptyIdx].macDa, pDaPolicy->macDa, MV_MAC_ADDR_SIZE); /* if Tx header exist */ if(pDaPolicy->policy.pHeader != NULL) { /* allocate memory for header */ pTxPolicy->txPolDa[firstEmptyIdx].policy.pHeader = mvOsMalloc(pDaPolicy->policy.headerSize ); if(pTxPolicy->txPolDa[firstEmptyIdx].policy.pHeader == NULL) { mvOsPrintf("ethTxPolicy: Alloc failed \n"); return MV_FAIL; } /* copy header */ memcpy(pTxPolicy->txPolDa[firstEmptyIdx].policy.pHeader , pDaPolicy->policy.pHeader , pDaPolicy->policy.headerSize ); pTxPolicy->txPolDa[firstEmptyIdx].policy.headerSize = pDaPolicy->policy.headerSize; } else { pTxPolicy->txPolDa[firstEmptyIdx].policy.pHeader = NULL; pTxPolicy->txPolDa[firstEmptyIdx].policy.headerSize = 0; } pTxPolicy->txPolDa[firstEmptyIdx].policy.txQ = pDaPolicy->policy.txQ; if(firstEmptyIdx >= pTxPolicy->txPolMaxDa) pTxPolicy->txPolMaxDa = firstEmptyIdx + 1; return MV_OK; } mvOsPrintf("ethTxPolicy: Can't add more MACDA entries\n"); return MV_FULL; }
MV_STATUS mvNfpFibRuleAdd(int family, NFP_RULE_FIB *fib2) { MV_U32 hash; NFP_RULE_FIB *fib; fib = mvNfpFibLookup(family, fib2->srcL3, fib2->dstL3); if (fib) { MV_U32 ref = fib->ref; mvOsMemcpy(fib, fib2, sizeof(NFP_RULE_FIB)); fib->ref = ref; goto out; } hash = mv_jhash_2addr(family, fib2->srcL3, fib2->dstL3, (u32) 0, mgr_rule_jhash_iv); hash &= NFP_FIB_HASH_MASK; fib = (NFP_RULE_FIB *) mvOsMalloc(sizeof(NFP_RULE_FIB)); if (!fib) { mvOsPrintf("%s: NFP (fib) OOM\n", __func__); return MV_FAIL; } mvOsMemcpy(fib, fib2, sizeof(NFP_RULE_FIB)); #if 0 /* Update FIB rule from Bridge DB if needed */ if (fib->flags & NFP_F_INV) { if (fib->flags & NFP_F_BRIDGE) { /* lookup bridge database */ bridge = mvNfpBridgeLookup(fib->bridgeOut, fib->da); if (bridge) { fib->flags &= ~NFP_F_INV; /* copy MH + outport + outdev from bridge */ fib->mh = bridge->mh_out; fib->outport = bridge->outport; fib->outdev = bridge->outdev; } } } #endif fib->next = fib_hash[hash]; fib_hash[hash] = fib; out: NFP_DBG("NFP (fib) add %p\n", fib); #ifdef NFP_PNC if ((fib->flags & NFP_F_INV) == 0) mvNfpPncFibAdd(fib); #endif return MV_OK; }
MV_STATUS mvFpFdbRuleSet(MV_FP_FDB_RULE *newrule) { int depth = 0; MV_U32 hash; MV_FP_FDB_RULE* rule; /* ignore foreign ifindex */ if (newrule->fdbInfo.ifIndex >= ETH_FP_IFINDEX_MAX) return MV_OUT_OF_RANGE; hash = mvFpFdbRuleHash(newrule); hash &= (fdbRuleDbSize - 1); rule = fdbRuleDb[hash].ruleChain; while (rule) { if (!mvFpFdbRuleCmp(&rule->fdbInfo, &newrule->fdbInfo)) { fdbRuleUpdateCount++; goto out; } depth++; rule = rule->next; } fdbRuleSetCount++; if(depth > fdbHashMaxDepth) fdbHashMaxDepth = depth; rule = mvOsMalloc(sizeof(MV_FP_FDB_RULE)); if (!rule) { mvOsPrintf("NFP (fdb): can't allocate new rule\n"); return MV_FAIL; } /* FIXME: No spinlocks */ rule->next = fdbRuleDb[hash].ruleChain; fdbRuleDb[hash].ruleChain = rule; out: mvOsMemcpy(rule, newrule, sizeof(MV_FP_FDB_RULE)); if (rule->fdbInfo.flags & MV_FP_FDB_IS_LOCAL) { fdbMember[rule->fdbInfo.ifIndex] = rule->fdbInfo.bridge; fdbMember[rule->fdbInfo.bridge] = rule->fdbInfo.bridge; } MV_NFP_DBG("NFP (fdb): new bridge=%d ifIndex=%d %02X:%02X:%02X:%02X:%02X:%02X flags=%x\n", rule->fdbInfo.bridge, rule->fdbInfo.ifIndex, rule->fdbInfo.mac[0], rule->fdbInfo.mac[1], rule->fdbInfo.mac[2], rule->fdbInfo.mac[3], rule->fdbInfo.mac[4], rule->fdbInfo.mac[5], rule->fdbInfo.flags); return MV_OK; }
MV_STATUS mvFpFdbInit(MV_U32 dbSize) { fdbRuleDb = (struct fdbRuleHashBucket *)mvOsMalloc(sizeof(struct fdbRuleHashBucket)*dbSize); if (fdbRuleDb == NULL) { mvOsPrintf("NFP (fdb): not enough memory\n"); return MV_NO_RESOURCE; } fdbRuleDbSize = dbSize; memset(fdbRuleDb, 0, sizeof(struct fdbRuleHashBucket)*fdbRuleDbSize); memset(fdbMember, 0, sizeof(fdbMember)); mvOsPrintf("NFP (fdb) init %d entries, %d bytes\n", fdbRuleDbSize, sizeof(struct fdbRuleHashBucket)*fdbRuleDbSize); return MV_OK; }
static MV_STATUS mvTdmChInit(MV_U8 ch) { MV_TDM_CH_INFO *chInfo; MV_U32 buff; MV_TRC_REC("->%s ch%d\n",__FUNCTION__,ch); if(ch >= MV_TDM_TOTAL_CHANNELS) { mvOsPrintf("%s: error, channel(%d) exceeds maximum(%d)\n",__FUNCTION__, ch, MV_TDM_TOTAL_CHANNELS); return MV_BAD_PARAM; } tdmChInfo[ch] = chInfo = (MV_TDM_CH_INFO *)mvOsMalloc(sizeof(MV_TDM_CH_INFO)); if(!chInfo) { mvOsPrintf("%s: error malloc failed\n",__FUNCTION__); return MV_NO_RESOURCE; } chInfo->ch = ch; /* Per channel TDM init */ MV_REG_WRITE(CH_ENABLE_REG(ch),CH_DISABLE); /* disable channel (enable in pcm start) */ MV_REG_WRITE(CH_SAMPLE_REG(ch),CONFIG_CH_SAMPLE(tdmBandMode, factor)); /* set total samples and int sample */ for(buff = 0; buff < TOTAL_BUFFERS; buff++) { /* Buffers must be 32B aligned */ chInfo->rxBuffVirt[buff] = (MV_U8*)mvOsIoUncachedMalloc(NULL, MV_TDM_CH_BUFF_SIZE(pcmFormat, tdmBandMode, factor), &(chInfo->rxBuffPhys[buff]),NULL); chInfo->rxBuffFull[buff] = BUFF_IS_EMPTY; chInfo->txBuffVirt[buff] = (MV_U8*)mvOsIoUncachedMalloc(NULL, MV_TDM_CH_BUFF_SIZE(pcmFormat, tdmBandMode, factor), &(chInfo->txBuffPhys[buff]),NULL); chInfo->txBuffFull[buff] = BUFF_IS_FULL; memset(chInfo->txBuffVirt[buff], 0, MV_TDM_CH_BUFF_SIZE(pcmFormat, tdmBandMode, factor)); if(((MV_ULONG)chInfo->rxBuffVirt[buff] | chInfo->rxBuffPhys[buff] | (MV_ULONG)chInfo->txBuffVirt[buff] | chInfo->txBuffPhys[buff]) & 0x1f) { mvOsPrintf("%s: error, unaligned buffer allocation\n", __FUNCTION__); } } MV_TRC_REC("<-%s\n",__FUNCTION__); return MV_OK; }
MV_STATUS _INIT mvNfpFibInit(void) { MV_U32 bytes = sizeof(NFP_RULE_FIB *) * NFP_FIB_HASH_SIZE; fib_hash = (NFP_RULE_FIB **) mvOsMalloc(bytes); if (fib_hash == NULL) { mvOsPrintf("NFP (fib): not enough memory\n"); return MV_NO_RESOURCE; } mvOsMemset(fib_hash, 0, bytes); mvOsPrintf("NFP (fib) init %d entries, %d bytes\n", NFP_FIB_HASH_SIZE, bytes); return MV_OK; }
MV_STATUS _INIT mvNfpBridgeInit(void) { MV_U32 bytes = sizeof(NFP_RULE_BRIDGE *) * NFP_BRIDGE_HASH_SIZE; nfp_bridge_hash = (NFP_RULE_BRIDGE **)mvOsMalloc(bytes); if (nfp_bridge_hash == NULL) { mvOsPrintf("NFP (bridge): not enough memory\n"); return MV_NO_RESOURCE; } mvOsMemset(nfp_bridge_hash, 0, bytes); mvOsPrintf("NFP (bridge) init %d entries, %d bytes\n", NFP_BRIDGE_HASH_SIZE, bytes); return MV_OK; }
MV_STATUS _INIT mvNfpNatInit(MV_VOID) { MV_U32 bytes = sizeof(NFP_RULE_NAT *) * NFP_NAT_HASH_SIZE; nat_hash = (NFP_RULE_NAT **)mvOsMalloc(bytes); if (nat_hash == NULL) { mvOsPrintf("NFP (nat): not enough memory\n"); return MV_NO_RESOURCE; } mvOsMemset(nat_hash, 0, bytes); mvOsPrintf("NFP (nat) init %d entries, %d bytes\n", NFP_NAT_HASH_SIZE, bytes); return MV_OK; }
void setXorDesc(void) { unsigned int mode; eth_xor_desc = mvOsMalloc(sizeof(MV_XOR_DESC) + XEXDPR_DST_PTR_DMA_MASK + 32); eth_xor_desc = (MV_XOR_DESC *)MV_ALIGN_UP((MV_U32)eth_xor_desc, XEXDPR_DST_PTR_DMA_MASK+1); eth_xor_desc_phys_addr = mvOsIoVirtToPhys(NULL, eth_xor_desc); mvSysXorInit(); mode = MV_REG_READ(XOR_CONFIG_REG(1, XOR_CHAN(0))); mode &= ~XEXCR_OPERATION_MODE_MASK; mode |= XEXCR_OPERATION_MODE_DMA; MV_REG_WRITE(XOR_CONFIG_REG(1, XOR_CHAN(0)), mode); MV_REG_WRITE(XOR_NEXT_DESC_PTR_REG(1, XOR_CHAN(0)), eth_xor_desc_phys_addr); dump_xor(); }
/* Initialize NFP Rule Database (Routing + ARP information table) */ MV_STATUS mvFpRuleDbInit(MV_U32 dbSize) { ruleDb = (struct ruleHashBucket *)mvOsMalloc(sizeof(struct ruleHashBucket) * dbSize); if (ruleDb == NULL) { mvOsPrintf("NFP Rule DB: Not Enough Memory\n"); return MV_NO_RESOURCE; } ruleDbSize = dbSize; memset(ruleDb, 0, sizeof(struct ruleHashBucket) * ruleDbSize); nfpRuleSetCount = nfpRuleUpdateCount = nfpRuleDeleteCount = 0; mvOsPrintf("mvFpRuleDb (%p): %d entries, %d bytes\n", ruleDb, ruleDbSize, sizeof(struct ruleHashBucket) * ruleDbSize); return MV_OK; }
/* Returns the head of the list if successful, NULL otherwise */ MV_LIST_ELEMENT *mvListCreate(MV_VOID) { MV_LIST_ELEMENT *head = (MV_LIST_ELEMENT *)mvOsMalloc(sizeof(MV_LIST_ELEMENT)); if (head) { head->prev = NULL; head->next = NULL; head->data = 0; } #ifdef MV_LIST_SANITY_CHECKS if (!head) mvOsPrintf("%s ERROR: memory allocation for new list failed\n", __func__); #endif /* MV_LIST_SANITY_CHECKS */ return head; }
MV_CPU_CNTRS_EVENT *mvCpuCntrsEventCreate(char *name, MV_U32 print_threshold) { int i; MV_CPU_CNTRS_EVENT *event = mvOsMalloc(sizeof(MV_CPU_CNTRS_EVENT)); if (event) { strncpy(event->name, name, sizeof(event->name)); event->num_of_measurements = 0; event->avg_sample_count = print_threshold; for (i = 0; i < MV_CPU_CNTRS_NUM; i++) { event->counters_before[i] = 0; event->counters_after[i] = 0; event->counters_sum[i] = 0; } } return event; }
MV_STATUS l2fw_add(MV_U32 srcIP, MV_U32 dstIP, int port) { L2FW_RULE *l2fw_rule; MV_U8 *srcIPchr, *dstIPchr; MV_U32 hash = mv_jhash_3words(srcIP, dstIP, (MV_U32) 0, l2fw_jhash_iv); hash &= L2FW_HASH_MASK; if (numHashEntries == L2FW_HASH_SIZE) { printk(KERN_INFO "cannot add entry, hash table is full, there are %d entires \n", L2FW_HASH_SIZE); return MV_ERROR; } srcIPchr = (MV_U8 *)&(srcIP); dstIPchr = (MV_U8 *)&(dstIP); #ifdef CONFIG_MV_ETH_L2FW_DEBUG mvOsPrintf("srcIP=%x dstIP=%x in %s\n", srcIP, dstIP, __func__); mvOsPrintf("srcIp = %u.%u.%u.%u in %s\n", MV_IPQUAD(srcIPchr), __func__); mvOsPrintf("dstIp = %u.%u.%u.%u in %s\n", MV_IPQUAD(dstIPchr), __func__); #endif l2fw_rule = l2fw_lookup(srcIP, dstIP); if (l2fw_rule) return MV_OK; l2fw_rule = (L2FW_RULE *)mvOsMalloc(sizeof(L2FW_RULE)); if (!l2fw_rule) { mvOsPrintf("%s: OOM\n", __func__); return MV_FAIL; } #ifdef CONFIG_MV_ETH_L2FW_DEBUG mvOsPrintf("adding a rule to l2fw hash in %s\n", __func__); #endif l2fw_rule->srcIP = srcIP; l2fw_rule->dstIP = dstIP; l2fw_rule->port = port; l2fw_rule->next = l2fw_hash[hash]; l2fw_hash[hash] = l2fw_rule; numHashEntries++; return MV_OK; }
MV_STATUS mvNfpBridgeRuleAdd(NFP_RULE_BRIDGE *rule2) { MV_U32 hash; NFP_RULE_BRIDGE *rule; hash = mvNfpBridgeRuleHash(rule2->bridgeId, rule2->mac); hash &= NFP_BRIDGE_HASH_MASK; rule = nfp_bridge_hash[hash]; while (rule) { if (mvNfpBridgeRuleCmp(rule2->bridgeId, rule2->mac, rule)) { MV_U32 age = rule->age; /* Update rule, but save age */ mvOsMemcpy(rule, rule2, sizeof(NFP_RULE_BRIDGE)); rule->age = age; goto out; } rule = rule->next; } rule = (NFP_RULE_BRIDGE *)mvOsMalloc(sizeof(NFP_RULE_BRIDGE)); if (!rule) { mvOsPrintf("NFP (bridge) %s OOM\n", __func__); return MV_FAIL; } mvOsMemcpy(rule, rule2, sizeof(NFP_RULE_BRIDGE)); rule->next = nfp_bridge_hash[hash]; nfp_bridge_hash[hash] = rule; /* lookup incomplete FIB entries */ out: NFP_DBG("NFP (bridge) add %p\n", rule); return MV_OK; }
/******************************************************************************* * mvCamSensorInit - Initialize the Camera Sensor * * DESCRIPTION: * this function does the following: * 1. Initializes the internal fields of the data stucture. * 2. initialize the sensor and loads default values. * 3. checks if the senser id match the support device * * INPUT: * Pointer to Camera Sensor Data structure, this sturcture must be allocated * by callee. * OUTPUT: * None * RETURN: * MV_BAD_PTR: if data structure not allocated or have bad external field * MV_FAIL: failed to allocate memory * MV_NOT_FOUND: if sensor id doesn't match * MV_ERROR: I2C failure transaction failure or if the senser reports failure * MV_OK otherwise *******************************************************************************/ MV_STATUS mvCamSensorInit(MV_CAM_SENSOR *pCamSensor) { OV7680_INFO *pInfo; mvOsOutput("mvCamSensorInit\n"); if(!pCamSensor) { mvOsPrintf("mvCamSensorInit: Bad Input\n"); return MV_BAD_PTR; } pInfo = mvOsMalloc(sizeof(OV7680_INFO)); pCamSensor->pInfo = pInfo; if(!pCamSensor->pInfo) { mvOsPrintf("mvCamSensorInit: failed to allocate memory\n"); return MV_FAIL; } pInfo->pixFormat = supportedFormats; pInfo->resolution = supportedResolutions; /* reset */ if (resetSensor(pCamSensor) != MV_OK) { mvOsPrintf("mvCamSensorInit: sensor reset failed\n"); return MV_ERROR; } /*load defaults*/ if(sensorRegsWrite(pCamSensor, ov7680_default_settings, sizeof(ov7680_default_settings)/sizeof(sensorReg_t)) != MV_OK){ mvOsPrintf("mvCamSensorInit: sensor default registers loading failed\n"); return MV_ERROR; } return isOV7680(pCamSensor); }
/******************************************************************************* * mvNetaPmtInit - Init Packet Modification Table driver * * INPUT: * int port - NETA port number * * RETURN: MV_STATUS * MV_OK - Success, Others - Failure *******************************************************************************/ MV_STATUS mvNetaPmtInit(int port, MV_NETA_PMT* pBase) { if ((port < 0) || (port >= mvNetaHalData.maxPort)) { mvOsPrintf("%s: port %d is out of range\n", __FUNCTION__, port); return MV_OUT_OF_RANGE; } if(mvPmtBase == NULL) { mvPmtBase = mvOsMalloc(mvNetaHalData.maxPort*sizeof(MV_NETA_PMT*)); if(mvPmtBase == NULL) { mvOsPrintf("%s: Allocation failed\n", __FUNCTION__); return MV_OUT_OF_CPU_MEM; } memset(mvPmtBase, 0, mvNetaHalData.maxPort*sizeof(MV_NETA_PMT*)); } mvPmtBase[port] = pBase; mvNetaPmtClear(port); return MV_OK; }
MV_STATUS l2fw_add_ip(const char *buf) { char *addr1, *addr2; L2FW_RULE *l2fw_rule; MV_U32 srcIP; MV_U32 dstIP; MV_U8 *srcIPchr, *dstIPchr; char dest1[15]; char dest2[15]; char *portStr; int offset1, offset2, port; MV_U32 hash = 0; if (numHashEntries == L2FW_HASH_SIZE) { printk(KERN_INFO "cannot add entry, hash table is full, there are %d entires \n", L2FW_HASH_SIZE); return MV_ERROR; } memset(dest1, 0, sizeof(dest1)); memset(dest2, 0, sizeof(dest2)); addr1 = strchr(buf, ','); addr2 = strchr(addr1+1, ','); offset1 = addr1-buf; offset2 = addr2-addr1; if (!addr1) { printk(KERN_INFO "first separating comma (',') missing in input in %s\n", __func__); return MV_FAIL; } if (!addr2) { printk(KERN_INFO "second separating comma (',') missing in input in %s\n", __func__); return MV_FAIL; } strncpy(dest1, buf, addr1-buf); srcIP = in_aton(dest1); strncpy(dest2, buf+offset1+1, addr2-addr1-1); dstIP = in_aton(dest2); srcIPchr = (MV_U8 *)&(srcIP); dstIPchr = (MV_U8 *)&(dstIP); portStr = addr2+1; if (*portStr == 'D') { L2FW_RULE *l2fw_rule_to_del, *prev; hash = mv_jhash_3words(srcIP, dstIP, (MV_U32) 0, l2fw_jhash_iv); hash &= L2FW_HASH_MASK; l2fw_rule_to_del = l2fw_hash[hash]; prev = NULL; while (l2fw_rule_to_del) { if ((l2fw_rule_to_del->srcIP == srcIP) && (l2fw_rule_to_del->dstIP == dstIP)) { if (prev) prev->next = l2fw_rule_to_del->next; else l2fw_hash[hash] = l2fw_rule_to_del->next; mvOsPrintf("%u.%u.%u.%u->%u.%u.%u.%u deleted\n", MV_IPQUAD(srcIPchr), MV_IPQUAD(dstIPchr)); mvOsFree(l2fw_rule_to_del); numHashEntries--; return MV_OK; } prev = l2fw_rule_to_del; l2fw_rule_to_del = l2fw_rule_to_del->next; } mvOsPrintf("%u.%u.%u.%u->%u.%u.%u.%u : entry not found\n", MV_IPQUAD(srcIPchr), MV_IPQUAD(dstIPchr)); return MV_NOT_FOUND; } port = atoi(portStr); hash = mv_jhash_3words(srcIP, dstIP, (MV_U32) 0, l2fw_jhash_iv); hash &= L2FW_HASH_MASK; l2fw_rule = l2fw_lookup(srcIP, dstIP); if (l2fw_rule) { mvOsPrintf("%u.%u.%u.%u->%u.%u.%u.%u : entry already exist\n", MV_IPQUAD(srcIPchr), MV_IPQUAD(dstIPchr)); return MV_OK; } l2fw_rule = (L2FW_RULE *)mvOsMalloc(sizeof(L2FW_RULE)); if (!l2fw_rule) { mvOsPrintf("%s: OOM\n", __func__); return MV_FAIL; } #ifdef CONFIG_MV_ETH_L2FW_DEBUG mvOsPrintf("adding a rule to l2fw hash in %s\n", __func__); #endif l2fw_rule->srcIP = srcIP; l2fw_rule->dstIP = dstIP; l2fw_rule->port = port; l2fw_rule->next = l2fw_hash[hash]; l2fw_hash[hash] = l2fw_rule; numHashEntries++; return MV_OK; }
void cesaStart(void) { int bufNum, bufSize; int i, j, idx; MV_CESA_MBUF *pMbufSrc_0, *pMbufDst_0; MV_BUF_INFO *pFragsSrc_0, *pFragsDst_0; char *pBuf_0; MV_CESA_MBUF *pMbufSrc_1, *pMbufDst_1; MV_BUF_INFO *pFragsSrc_1, *pFragsDst_1; char *pBuf_1; printk(KERN_INFO "in %s\n", __func__); cesaCmdArray_0 = mvOsMalloc(sizeof(MV_CESA_COMMAND) * CESA_DEF_REQ_SIZE); if (cesaCmdArray_0 == NULL) { mvOsPrintf("Can't allocate %d bytes of memory\n", (int)(sizeof(MV_CESA_COMMAND) * CESA_DEF_REQ_SIZE)); return; } memset(cesaCmdArray_0, 0, sizeof(MV_CESA_COMMAND) * CESA_DEF_REQ_SIZE); /* CESA_DEF_BUF_NUM */ bufNum = 1; /* CESA_DEF_BUF_SIZE */ bufSize = 1500; pMbufSrc_0 = mvOsMalloc(sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE); pFragsSrc_0 = mvOsMalloc(sizeof(MV_BUF_INFO) * bufNum * CESA_DEF_REQ_SIZE); pMbufDst_0 = mvOsMalloc(sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE); pFragsDst_0 = mvOsMalloc(sizeof(MV_BUF_INFO) * bufNum * CESA_DEF_REQ_SIZE); if ((pMbufSrc_0 == NULL) || (pFragsSrc_0 == NULL) || (pMbufDst_0 == NULL) || (pFragsDst_0 == NULL)) { mvOsPrintf(" Can't malloc Src and Dst pMbuf and pFrags structures.\n"); return; } memset(pMbufSrc_0, 0, sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE); memset(pFragsSrc_0, 0, sizeof(MV_BUF_INFO) * bufNum * CESA_DEF_REQ_SIZE); memset(pMbufDst_0, 0, sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE); memset(pFragsDst_0, 0, sizeof(MV_BUF_INFO) * bufNum * CESA_DEF_REQ_SIZE); idx = 0; for (i = 0; i < CESA_DEF_REQ_SIZE; i++) { pBuf_0 = mvOsIoCachedMalloc(cesaOSHandle, bufSize * bufNum * 2, &cesaBufs_0[i].bufPhysAddr, &cesaBufs_0[i].memHandle); if (pBuf_0 == NULL) { mvOsPrintf("testStart: Can't malloc %d bytes for pBuf\n", bufSize * bufNum * 2); return; } memset(pBuf_0, 0, bufSize * bufNum * 2); mvOsCacheFlush(cesaOSHandle, pBuf_0, bufSize * bufNum * 2); if (pBuf_0 == NULL) { mvOsPrintf("Can't allocate %d bytes for req_%d buffers\n", bufSize * bufNum * 2, i); return; } cesaBufs_0[i].bufVirtPtr = (MV_U8 *) pBuf_0; cesaBufs_0[i].bufSize = bufSize * bufNum * 2; cesaCmdArray_0[i].pSrc = &pMbufSrc_0[i]; cesaCmdArray_0[i].pSrc->pFrags = &pFragsSrc_0[idx]; cesaCmdArray_0[i].pSrc->numFrags = bufNum; cesaCmdArray_0[i].pSrc->mbufSize = 0; cesaCmdArray_0[i].pDst = &pMbufDst_0[i]; cesaCmdArray_0[i].pDst->pFrags = &pFragsDst_0[idx]; cesaCmdArray_0[i].pDst->numFrags = bufNum; cesaCmdArray_0[i].pDst->mbufSize = 0; for (j = 0; j < bufNum; j++) { cesaCmdArray_0[i].pSrc->pFrags[j].bufVirtPtr = (MV_U8 *) pBuf_0; cesaCmdArray_0[i].pSrc->pFrags[j].bufSize = bufSize; pBuf_0 += bufSize; cesaCmdArray_0[i].pDst->pFrags[j].bufVirtPtr = (MV_U8 *) pBuf_0; cesaCmdArray_0[i].pDst->pFrags[j].bufSize = bufSize; pBuf_0 += bufSize; } idx += bufNum; } cesaMbufArray_0 = mvOsMalloc(sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE); if (cesaMbufArray_0 == NULL) { mvOsPrintf("Can't allocate %d bytes of memory\n", (int)(sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE)); return; } memset(cesaMbufArray_0, 0, sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE); cesaPrivArray_0 = mvOsMalloc(sizeof(MV_NFP_SEC_CESA_PRIV_L2FW) * (CESA_DEF_REQ_SIZE + MV_NFP_SEC_REQ_Q_SIZE)); memset(cesaPrivArray_0, 0, sizeof(MV_NFP_SEC_CESA_PRIV_L2FW) * (CESA_DEF_REQ_SIZE + MV_NFP_SEC_REQ_Q_SIZE)); /* second engine */ cesaCmdArray_1 = mvOsMalloc(sizeof(MV_CESA_COMMAND) * CESA_DEF_REQ_SIZE); if (cesaCmdArray_1 == NULL) { mvOsPrintf("Can't allocate %d bytes of memory\n", (int)(sizeof(MV_CESA_COMMAND) * CESA_DEF_REQ_SIZE)); return; } memset(cesaCmdArray_1, 0, sizeof(MV_CESA_COMMAND) * CESA_DEF_REQ_SIZE); /* CESA_DEF_BUF_NUM */ bufNum = 1; /* CESA_DEF_BUF_SIZE */ bufSize = 1500; pMbufSrc_1 = mvOsMalloc(sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE); pFragsSrc_1 = mvOsMalloc(sizeof(MV_BUF_INFO) * bufNum * CESA_DEF_REQ_SIZE); pMbufDst_1 = mvOsMalloc(sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE); pFragsDst_1 = mvOsMalloc(sizeof(MV_BUF_INFO) * bufNum * CESA_DEF_REQ_SIZE); if ((pMbufSrc_1 == NULL) || (pFragsSrc_1 == NULL) || (pMbufDst_1 == NULL) || (pFragsDst_1 == NULL)) { mvOsPrintf(" Can't malloc Src and Dst pMbuf and pFrags structures.\n"); return; } memset(pMbufSrc_1, 0, sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE); memset(pFragsSrc_1, 0, sizeof(MV_BUF_INFO) * bufNum * CESA_DEF_REQ_SIZE); memset(pMbufDst_1, 0, sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE); memset(pFragsDst_1, 0, sizeof(MV_BUF_INFO) * bufNum * CESA_DEF_REQ_SIZE); idx = 0; for (i = 0; i < CESA_DEF_REQ_SIZE; i++) { pBuf_1 = mvOsIoCachedMalloc(cesaOSHandle, bufSize * bufNum * 2, &cesaBufs_1[i].bufPhysAddr, &cesaBufs_1[i].memHandle); if (pBuf_1 == NULL) { mvOsPrintf("testStart: Can't malloc %d bytes for pBuf\n", bufSize * bufNum * 2); return; } memset(pBuf_1, 0, bufSize * bufNum * 2); mvOsCacheFlush(cesaOSHandle, pBuf_1, bufSize * bufNum * 2); if (pBuf_1 == NULL) { mvOsPrintf("Can't allocate %d bytes for req_%d buffers\n", bufSize * bufNum * 2, i); return; } cesaBufs_1[i].bufVirtPtr = (MV_U8 *) pBuf_1; cesaBufs_1[i].bufSize = bufSize * bufNum * 2; cesaCmdArray_1[i].pSrc = &pMbufSrc_1[i]; cesaCmdArray_1[i].pSrc->pFrags = &pFragsSrc_1[idx]; cesaCmdArray_1[i].pSrc->numFrags = bufNum; cesaCmdArray_1[i].pSrc->mbufSize = 0; cesaCmdArray_1[i].pDst = &pMbufDst_1[i]; cesaCmdArray_1[i].pDst->pFrags = &pFragsDst_1[idx]; cesaCmdArray_1[i].pDst->numFrags = bufNum; cesaCmdArray_1[i].pDst->mbufSize = 0; for (j = 0; j < bufNum; j++) { cesaCmdArray_1[i].pSrc->pFrags[j].bufVirtPtr = (MV_U8 *) pBuf_1; cesaCmdArray_1[i].pSrc->pFrags[j].bufSize = bufSize; pBuf_1 += bufSize; cesaCmdArray_1[i].pDst->pFrags[j].bufVirtPtr = (MV_U8 *) pBuf_1; cesaCmdArray_1[i].pDst->pFrags[j].bufSize = bufSize; pBuf_1 += bufSize; } idx += bufNum; } cesaMbufArray_1 = mvOsMalloc(sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE); if (cesaMbufArray_1 == NULL) { mvOsPrintf("Can't allocate %d bytes of memory\n", (int)(sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE)); return; } memset(cesaMbufArray_1, 0, sizeof(MV_CESA_MBUF) * CESA_DEF_REQ_SIZE); cesaPrivArray_1 = mvOsMalloc(sizeof(MV_NFP_SEC_CESA_PRIV_L2FW) * (CESA_DEF_REQ_SIZE + MV_NFP_SEC_REQ_Q_SIZE)); memset(cesaPrivArray_1, 0, sizeof(MV_NFP_SEC_CESA_PRIV_L2FW) * (CESA_DEF_REQ_SIZE + MV_NFP_SEC_REQ_Q_SIZE)); pPktInfoNewArray_0 = mvOsMalloc(sizeof(MV_PKT_INFO) * MV_NFP_SEC_REQ_Q_SIZE); if (!pPktInfoNewArray_0) { printk(KERN_INFO "mvOsMalloc() failed in %s\n", __func__); return; } pBufInfoArray_0 = mvOsMalloc(sizeof(MV_BUF_INFO) * MV_NFP_SEC_REQ_Q_SIZE); if (!pBufInfoArray_0) { printk(KERN_INFO "could not allocate MV_BUF_INFO in %s\n", __func__); return; } pPktInfoNewArray_1 = mvOsMalloc(sizeof(MV_PKT_INFO) * MV_NFP_SEC_REQ_Q_SIZE); if (!pPktInfoNewArray_1) { printk(KERN_INFO "mvOsMalloc() failed in %s\n", __func__); return; } pBufInfoArray_1 = mvOsMalloc(sizeof(MV_BUF_INFO) * MV_NFP_SEC_REQ_Q_SIZE); if (!pBufInfoArray_0) { printk(KERN_INFO "could not allocate MV_BUF_INFO in %s\n", __func__); return; } printk(KERN_INFO "start finished in %s\n", __func__); }
/* Set a NAT rule: create a new rule or update an existing rule in the SNAT + DNAT table */ MV_STATUS mvFpNatRuleSet(MV_FP_NAT_RULE *pSetRule) { int depth = 0; MV_U32 hash, hash_tr; MV_FP_NAT_RULE *pNatRule, *pNewRule; hash = mv_jhash_3words(pSetRule->dstIp, pSetRule->srcIp, (MV_U32)((pSetRule->dstPort << 16) | pSetRule->srcPort), (MV_U32)((fp_ip_jhash_iv << 8) | pSetRule->proto)); hash_tr = hash & (natRuleDbSize - 1); pNatRule = natRuleDb[hash_tr].natRuleChain; while(pNatRule) { /* look for a matching rule */ if( (pNatRule->dstIp == pSetRule->dstIp) && (pNatRule->srcIp == pSetRule->srcIp) && (pNatRule->proto == pSetRule->proto) && (pNatRule->dstPort == pSetRule->dstPort) && (pNatRule->srcPort == pSetRule->srcPort) ) { /* update rule */ mvFpNatRuleUpdate(pNatRule, pSetRule); natRuleUpdateCount++; #ifdef MV_FP_DEBUG mvOsPrintf("UpdNAT_%03u: DIP=0x%08x, SIP=0x%08x, proto=%d, DPort=%d, SPort=%d, hash=0x%04x, flags=0x%02x\n", natRuleUpdateCount, pNatRule->dstIp, pNatRule->srcIp, pNatRule->proto, MV_16BIT_BE(pNatRule->dstPort), MV_16BIT_BE(pNatRule->srcPort), hash_tr, pNatRule->flags); #endif return MV_OK; } pNatRule = pNatRule->next; } /* Allocate new entry */ pNewRule = mvOsMalloc(sizeof(MV_FP_NAT_RULE)); if(pNewRule == NULL) { mvOsPrintf("mvFpNatRuleSet: Can't allocate new rule\n"); return MV_FAIL; } memcpy(pNewRule, pSetRule, sizeof(*pNewRule)); pNewRule->next = NULL; if(natRuleDb[hash_tr].natRuleChain == NULL) { natRuleDb[hash_tr].natRuleChain = pNewRule; } else { pNatRule = natRuleDb[hash_tr].natRuleChain; while (pNatRule->next != NULL) { depth++; pNatRule = pNatRule->next; } pNatRule->next = pNewRule; } if(depth > natHashMaxDepth) natHashMaxDepth = depth; natRuleSetCount++; #ifdef MV_FP_DEBUG mvOsPrintf("SetNAT_%03u: DIP=0x%08x, SIP=0x%08x, proto=%d, DPort=%d, SPort=%d, hash=0x%04x, flags=0x%02x\n", natRuleSetCount, pNewRule->dstIp, pNewRule->srcIp, pNewRule->proto, MV_16BIT_BE(pNewRule->dstPort), MV_16BIT_BE(pNewRule->srcPort), hash_tr, pNewRule->flags); #endif return MV_OK; }
int initDaa(unsigned int *daaDev, unsigned int ch, int workMode, int intMode) { unsigned char reg2 = 0, reg24; long newDelay; MV_DAA_DEV *pDaaDev; int lineSideId; pDaaDev = (MV_DAA_DEV *)mvOsMalloc(sizeof(MV_DAA_DEV)); if(!pDaaDev) { mvOsPrintf("%s: error malloc failed\n",__FUNCTION__); return 1; } work_mode = workMode; interrupt_mode = intMode; pDaaDev->ch = ch; if(work_mode) pDaaDev->dcval = ch + 1; pDaaDev->hook = 0; pDaaDev->ring = 0; pDaaDev->reverse_polarity = 0; pDaaDev->drop_out = 0; *daaDev = (unsigned int)pDaaDev; /* Software reset */ writeDaaDirectReg(*daaDev, 1, 0x80); /* Wait just a bit */ mvOsDelay(100); setDaaDigitalHybrid(COUNTRY_INDEX, *daaDev); /* Set Transmit/Receive timeslot */ /* Configure tx/rx sample in DAA */ pDaaDev->txSample = ((pDaaDev->ch==0) ? CH0_TX_SLOT : CH1_TX_SLOT); pDaaDev->rxSample = ((pDaaDev->ch==0) ? CH0_RX_SLOT : CH1_RX_SLOT); mvOsPrintf("FXO-%d: RX sample %d, TX sample %d\n",pDaaDev->ch, pDaaDev->rxSample, pDaaDev->txSample); pDaaDev->txSample *= 8; pDaaDev->rxSample *= 8; setDaaPcmStartCountRegs(*daaDev); #ifdef MV_TDM_LINEAR_MODE /* Enable PCM, linear 16 bit */ writeDaaDirectReg(*daaDev, 33, 0x38); #else /* Enable PCM, m-Law 8 bit */ writeDaaDirectReg(*daaDev, 33, 0x28); #endif /* Enable full wave rectifier */ writeDaaDirectReg(*daaDev, DAA_INTERNATIONAL_CONTROL_3, DAA_RFWE); /* Disable interrupts */ disableDaaInterrupts(*daaDev); /* Set AOUT/INT pin as hardware interrupt */ reg2 = readDaaDirectReg(*daaDev, DAA_CONTROL_2_REG); writeDaaDirectReg(*daaDev, DAA_CONTROL_2_REG, (reg2 | DAA_INTE)); /* Enable ISO-Cap */ writeDaaDirectReg(*daaDev, DAA_DAA_CONTROL_2, 0); /* Wait 2000ms for ISO-cap to come up */ newDelay = 2000; while(newDelay > 0 && !(readDaaDirectReg(*daaDev, DAA_SYSTEM_AND_LINE_SIDE_REV_REG) & 0xf0)) { mvOsDelay(100); newDelay -= 100; } lineSideId = readDaaDirectReg(*daaDev, DAA_SYSTEM_AND_LINE_SIDE_REV_REG); if (!(lineSideId & 0xf0)) { mvOsPrintf("Error: FXO did not bring up ISO link properly!\n"); return 1; } /* Perform ADC manual calibration */ daaCalibration(*daaDev); /* Enable Ring Validation */ reg24 = readDaaDirectReg(*daaDev, DAA_RING_VALIDATION_CONTROL_3); writeDaaDirectReg(*daaDev,DAA_RING_VALIDATION_CONTROL_3 , reg24 | DAA_RNGV); /* Print DAA info */ printDaaInfo(*daaDev); TRC_REC("ISO-Cap is now up, line side: %02x rev %02x\n", readDaaDirectReg(*daaDev, 11) >> 4, ( readDaaDirectReg(*daaDev, 13) >> 2) & 0xf); /* raise tx gain by 7 dB for NEWZEALAND */ if (!strcmp(daa_modes[COUNTRY_INDEX].name, "NEWZEALAND")) { mvOsPrintf("Adjusting gain\n"); writeDaaDirectReg(*daaDev, 38, 0x7); } return 0; }
static ssize_t tcam_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { const char* name = attr->attr.name; unsigned int err=0, a=0, b=0; unsigned long flags; if (!capable(CAP_NET_ADMIN)) return -EPERM; sscanf(buf,"%x %x",&a, &b); raw_local_irq_save(flags); if (!strcmp(name, "hw_write")) tcam_hw_write(&te, a); else if (!strcmp(name, "hw_read")) tcam_hw_read(&te, a); else if (!strcmp(name, "hw_debug")) tcam_hw_debug(a); else if (!strcmp(name, "hw_inv")) tcam_hw_inv(a); else if (!strcmp(name, "hw_inv_all")) tcam_hw_inv_all(); else if (!strcmp(name, "hw_hits")) tcam_hw_record(a); #ifdef CONFIG_MV_ETH_PNC_AGING else if (!strcmp(name, "age_clear")) mvPncAgingCntrClear(a); else if (!strcmp(name, "age_cntr")) { b = mvPncAgingCntrRead(a); printk("tid=%d: age_cntr = 0x%08x\n", a, b); } #endif /* CONFIG_MV_ETH_PNC_AGING */ else if (!strcmp(name, "sw_clear")) tcam_sw_clear(&te); else if (!strcmp(name, "sw_text")) { /* Remove last byte (new line) from the buffer */ int len = strlen(buf); char* temp = mvOsMalloc(len + 1); strncpy(temp, buf, len-1); temp[len-1] = 0; tcam_sw_text(&te, temp); mvOsFree(temp); } else if (!strcmp(name, "t_port")) tcam_sw_set_port(&te, a, b); else if (!strcmp(name, "t_lookup")) tcam_sw_set_lookup(&te, a); else if (!strcmp(name, "t_ainfo_0")) tcam_sw_set_ainfo(&te, 0<<a, 1<<a); else if (!strcmp(name, "t_ainfo_1")) tcam_sw_set_ainfo(&te, 1<<a, 1<<a); else if (!strcmp(name, "t_ainfo")) tcam_sw_set_ainfo(&te, a, b); else if (!strcmp(name, "t_offset_byte")) tcam_sw_set_byte(&te, a, b); else if (!strcmp(name, "t_offset_mask")) tcam_sw_set_mask(&te, a, b); else if (!strcmp(name, "s_lookup")) sram_sw_set_next_lookup(&te, a); else if (!strcmp(name, "s_ainfo")) sram_sw_set_ainfo(&te, a, b); else if (!strcmp(name, "s_lookup_done")) sram_sw_set_lookup_done(&te, a); else if (!strcmp(name, "s_next_lookup_shift")) sram_sw_set_next_lookup_shift(&te, a); else if (!strcmp(name, "s_rxq")) sram_sw_set_rxq(&te, a, b); else if (!strcmp(name, "s_shift_update")) sram_sw_set_shift_update(&te,a,b); else if (!strcmp(name, "s_rinfo")) sram_sw_set_rinfo(&te, 1 << a); else if (!strcmp(name, "s_rinfo_extra")) sram_sw_set_rinfo_extra(&te, a << (b & ~1)); else if (!strcmp(name, "s_flowid")) sram_sw_set_flowid(&te, a, b); else if (!strcmp(name, "s_flowid_nibble")) sram_sw_set_flowid_nibble(&te, a, b); #ifdef CONFIG_MV_ETH_PNC_AGING else if (!strcmp(name, "age_gr_set")) mvPncAgingCntrGroupSet(a, b); #endif /* CONFIG_MV_ETH_PNC_AGING */ else { err = 1; printk("%s: illegal operation <%s>\n", __FUNCTION__, attr->attr.name); } raw_local_irq_restore(flags); if (err) printk("%s: <%s>, error %d\n", __FUNCTION__, attr->attr.name, err); return err ? -EINVAL : len; }