/******************************************************************************* * mvNflashPageProg - Program flash page. * * DESCRIPTION: * This function programs up to one page. It could program partial page * as well. * * INPUT: * pFlash - Flash information. * offset - Page offset in bytes. * size - Data size in bytes for x8 and in words for x16 devices. * pData - Buffer to copy data. * * OUTPUT: * None * * RETURN: * MV_TIMEOUT in case the device is not in ready state within timeout. * MV_OK if the operation succeeded * MV_FAIL if the operation failed. * MV_WRITE_PROTECT if the operation failed because of write protection. * *******************************************************************************/ MV_STATUS mvNflashPageProg(MV_NFLASH_INFO *pFlash, MV_U32 offset, MV_U32 size, MV_U8 *pData) { MV_U32 tmpSize; /* Set first program command */ mvNflashCommandSet(&pFlash->nflashHwIf, PAGE_PROGRAM_CMD1); /* Set address: 1) Column address */ mvNflashAddrSet(&pFlash->nflashHwIf, (offset & 0xFF)); /* Set address: 2.1) Row (page) address */ mvNflashAddrSet(&pFlash->nflashHwIf, ((offset >> 9) & 0xFF)); /* Set address: 2.2) Row (page) address */ mvNflashAddrSet(&pFlash->nflashHwIf, ((offset >> 17) & 0xFF)); /* 1st phase. Calculate first page data left size */ tmpSize = pFlash->pNflashStruct->pageDataSize + pFlash->pNflashStruct->spareSize - (offset & 0xFF); /* We can copy maximum page Size Left, but actual size can be smaller */ tmpSize = MV_MIN(tmpSize, size); /* Write the data to Flash register */ (*pFlash->nflashHwIf.nfDataSetRtn) (&pFlash->nflashHwIf, (void*)pData, tmpSize); /* Set second program command */ mvNflashCommandSet(&pFlash->nflashHwIf, PAGE_PROGRAM_CMD2); return(prgmEraseStsGet(pFlash)); }
/* no need to use in tool */ void mvCesaDebugMbuf(const char* str, MV_CESA_MBUF *pMbuf, int offset, int size) { int frag, len, fragOffset; if(str != NULL) mvOsPrintf("%s: pMbuf=%p, numFrags=%d, mbufSize=%d\n", str, pMbuf, pMbuf->numFrags, pMbuf->mbufSize); frag = mvCesaMbufOffset(pMbuf, offset, &fragOffset); if(frag == MV_INVALID) { mvOsPrintf("CESA Mbuf Error: offset (%d) out of range\n", offset); return; } for(; frag<pMbuf->numFrags; frag++) { mvOsPrintf("#%2d. bufVirt=%p, bufSize=%d\n", frag, pMbuf->pFrags[frag].bufVirtPtr, pMbuf->pFrags[frag].bufSize); if(size > 0) { len = MV_MIN(pMbuf->pFrags[frag].bufSize, size); mvDebugMemDump(pMbuf->pFrags[frag].bufVirtPtr+fragOffset, len, 1); size -= len; fragOffset = 0; } } }
/******************************************************************************* * mvEthTxPolicyGet - Get TX policy of ethernet port for the outgoing packet. * * DESCRIPTION: * This function gets existing TX policy for outgoing packets. * * INPUT: * void* pPortHndl - Pointer to port specific handler * MV_U8* pPktInfo - Pointer to outgoing packet * * OUTPUT: * MV_ETH_TX_POLICY_ENTRY* pTxPolEntry - pointer to TX policy entry for * this packet * * RETURN: * int txQ - TX queue to place the outgoing packet. * *******************************************************************************/ int mvEthTxPolicyGet(void* pTxPolicyHndl, MV_PKT_INFO* pPktInfo, MV_ETH_TX_POLICY_ENTRY* pTxPolicyEntry) { MV_U8 mac_da[MV_MAC_ADDR_SIZE]; MV_U32 bufCount, tot_size = 0, size; MV_BUF_INFO* pBufInfo = pPktInfo->pFrags; /* extract the destination MAC address */ for(bufCount=0; bufCount<pPktInfo->numFrags; bufCount++) { size = MV_MIN((MV_MAC_ADDR_SIZE - tot_size), pBufInfo[bufCount].bufSize); memcpy(&mac_da[tot_size], pBufInfo[bufCount].bufVirtPtr, size); tot_size += size; if(tot_size == MV_MAC_ADDR_SIZE) break; } return mvEthDATxPolicyGet(pTxPolicyHndl, mac_da, pTxPolicyEntry); }
/******************************************************************************* * readData - Read the data from flash port into user buffer. * * DESCRIPTION: * This function Read the data from flash port into user buffer. * The data is ready in the flash buffers. This function supports the * K9F5608D0C and K9F5608U0C devices sequential page reads. * Note that the offset parameter does not concerns the page spare section. * Nevertheless, the size does include the spare section. This is why * we use maxSize to describe the total page size that can be read * (528 bytes) and maxDataSize to describe the total data in page that * can be read (512). When using read 2 operation this is not the case * as both total size and data size are the same (16 bytes) * * INPUT: * pFlash - Flash information. * readType - Read operation type 1 (page) or 2 (spare area) * offset - Flash data offset in bytes for x8 and in words for x16 devs. * pData - Buffer to copy data. * size - Data size in bytes for x8 and in words for x16 devices. * * OUTPUT: * None * * RETURN: * Size of copied data. * *******************************************************************************/ static MV_U32 readData(MV_NFLASH_INFO *pFlash, MV_U32 readType, MV_U32 offset, MV_U32 size, MV_U8 *pData) { int i; MV_U32 tmpSize; MV_U32 maxSize; /* total page size that can be read */ MV_U32 maxDataSize; /* total data in page that can be read */ MV_U32 numOfFullPages; /* Number of full pages to read */ if (READ_SPARE == readType) { maxDataSize = pFlash->pNflashStruct->spareSize; maxSize = maxDataSize; } else { maxDataSize = pFlash->pNflashStruct->pageDataSize; maxSize = maxDataSize + pFlash->pNflashStruct->spareSize; } /* Start copy data. Copying data is done on page boundry, thus copying */ /* is done in three phases. */ /* 1) Copy data from first page. */ /* 2) If the size overflow to the next pages copy full pages data */ /* 3) Copy the last page data. */ /* 1st phase. Calculate first page data left size */ tmpSize = maxSize - (offset & 0xFF); /* We can copy maximum pageSizeLeft, but actual size can be smaller */ tmpSize = MV_MIN(tmpSize, size); /* Copy data from first page */ (*pFlash->nflashHwIf.nfDataGetRtn) (&pFlash->nflashHwIf, (void*)pData, tmpSize); /* Size is limited to page baundry. For K9F5608D0C and K9F5608U0C */ /* size is unlimited (sequential page read) */ if (K9F5608D0C != pFlash->pNflashStruct->devId) { return tmpSize; } /* must wait at the end of page read */ if (MV_TIMEOUT == prgmEraseStsGet(pFlash)) return tmpSize; /* Set Read command */ mvNflashCommandSet(&pFlash->nflashHwIf, readType); /* Move forward the data pointer */ pData += tmpSize; /* calculate the size left after the first page */ tmpSize = size - tmpSize; /* Calculate number of full pages to read */ numOfFullPages = tmpSize / maxSize; /* 2nd pase. If the size overflow to the next pages copy full pages data */ for (i = 0; i < numOfFullPages; i++, pData += maxSize) { (*pFlash->nflashHwIf.nfDataGetRtn) (&pFlash->nflashHwIf, (void*)pData, maxSize); tmpSize-= maxSize; /* Wait for device to be ready for next loop */ if (MV_TIMEOUT == prgmEraseStsGet(pFlash)) return tmpSize; /* Set Read command */ mvNflashCommandSet(&pFlash->nflashHwIf, readType); } /* No third phase. tmpSize was aligned to page size. */ if (0 == tmpSize) { return size; } /* 3rd phase. Copy the last page data */ (*pFlash->nflashHwIf.nfDataGetRtn) (&pFlash->nflashHwIf, (void*)pData, tmpSize); /* must wait at the end of page read */ if (MV_TIMEOUT == prgmEraseStsGet(pFlash)) return tmpSize; return size; }
void sgdt_copy_partial( sgd_tbl_t* sgdt, sgd_t** ppsgd, MV_PU32 poff, MV_U32 size ) { MV_U32 sgdsz; MV_U32 tmpSize; sgd_t sgd[2]; while( size ) { sgd_getsz( *ppsgd, sgdsz ); MV_ASSERT( sgdsz > *poff ); tmpSize = MV_MIN( size, sgdsz - *poff ); if( sgdt ) { sgd_copy( sgd, *ppsgd ); sgd_setsz( sgd, tmpSize ); if( *poff ) { if( sgd->flags & (SGD_REFTBL|SGD_REFSGD) ) { MV_U32 refoff; sgd_get_refoff( sgd, refoff ); sgd_set_refoff( sgd, refoff+(*poff) ); } else { sgd->baseAddr = U64_ADD_U32( sgd->baseAddr, (*poff) ); if( sgd->flags & SGD_VP ) { sgd_vp_t* vp = (sgd_vp_t*) sgd; vp->u.vaddr = ((MV_U8*)vp->u.vaddr) + (*poff); } if (sgd->flags & SGD_PCTX) { sgd_pctx_t *pctx = (sgd_pctx_t *)sgd; pctx->rsvd += (*poff); } } } sgdt_append_sgd( sgdt, sgd ); } if( size == sgdsz - *poff || tmpSize == sgdsz - *poff ) { sgd_inc( *ppsgd ); (*poff) = 0; } else (*poff) += tmpSize; size -= tmpSize; } }