📄 core_swxor.c
字号:
if ( minSize>targetSize[tId] ) minSize=targetSize[tId]; }*/ } pXORReq->Request_Status = XOR_STATUS_SUCCESS;}//TBD: consolidate compare and writevoid mvXORCompare (MV_PVOID This, PMV_XOR_Request pXORReq){ PMV_SG_Entry pSourceSG[XOR_SOURCE_SG_COUNT]; MV_U32 sourceSize[XOR_SOURCE_SG_COUNT]; MV_U32 totalSize, remainSize, minSize, size, i; MV_U8 sId;#ifdef SUPPORT_XOR_DWORD MV_PU32 pSourceVir[XOR_SOURCE_SG_COUNT]; MV_U32 xorResult, Dword_size;#else MV_PU8 pSourceVir[XOR_SOURCE_SG_COUNT]; MV_U8 xorResult;#endif /* All the SG table should have same Byte_Count */ totalSize = remainSize = minSize = pXORReq->Source_SG_Table_List[0].Byte_Count; mvXORInit(pSourceSG, sourceSize, (MV_PVOID*)pSourceVir, pXORReq->Source_SG_Table_List, pXORReq->Source_SG_Table_Count, &minSize); while ( remainSize>0 ) { size = minSize;#ifdef SUPPORT_XOR_DWORD MV_DASSERT( !(size%4) ); Dword_size = size/4; for ( i=0; i<Dword_size; i++ ) { xorResult = mvXORDWord(pSourceVir, pXORReq, 0);#else for ( i=0; i<size; i++ ) { xorResult = mvXORByte(pSourceVir, pXORReq, 0);#endif if (xorResult != 0) { pXORReq->Request_Status = XOR_STATUS_ERROR;#ifdef SUPPORT_XOR_DWORD pXORReq->Error_Offset = totalSize - remainSize + i*4;#else pXORReq->Error_Offset = totalSize - remainSize + i;#endif return; } for ( sId=0; sId<pXORReq->Source_SG_Table_Count; sId++ ) pSourceVir[sId]++; } /* Update entry pointer, size */ MV_DASSERT( remainSize>=size ); remainSize -= size; minSize = remainSize; mvXORUpdateEntry(pSourceSG, sourceSize, (MV_PVOID*)pSourceVir, size, pXORReq->Source_SG_Table_Count, &minSize); }}void mvXORDMA (MV_PVOID This, PMV_XOR_Request pXORReq){ MV_ASSERT( MV_FALSE );}#endif /* SUPPORT_RAID6 */#else /*!USE_NEW_SGTABLE*//* * CompareSGs needs not to be changed for SGD_PCTX since RAID always * use memory with known virtual address. */voidCompareSGs( PCore_Driver_Extension pCore, PMV_XOR_Request pXORReq, PMV_SG_Table srctbl ){ MV_PU32 pSrc[2] = { NULL, }; sgd_t sgd[2]; sgd_iter_t sg_iter[2]; MV_U32 wCount[2]; MV_BOOLEAN bFinished = MV_FALSE; MV_U8 bIndex; MV_U32 offset = 0; MV_PVOID p; MV_ASSERT( srctbl[0].Byte_Count == srctbl[1].Byte_Count ); for( bIndex = 0; bIndex < 2; bIndex++ ) { sgd_iter_init( &sg_iter[bIndex], srctbl[bIndex].Entry_Ptr, 0, srctbl[bIndex].Byte_Count ); sgd_iter_get_next( &sg_iter[bIndex], sgd ); sgd_get_vaddr( sgd, p ); pSrc[bIndex] = (MV_PU32) p; sgd_getsz( sgd, wCount[bIndex] ); } while( !bFinished ) { if( *pSrc[0] != *pSrc[1] ) { pXORReq->Request_Status = XOR_STATUS_ERROR; pXORReq->Error_Offset = offset; return; } offset += sizeof( MV_U32 ); for( bIndex = 0; bIndex < 2; bIndex++ ) { pSrc[bIndex]++; wCount[bIndex] -= sizeof( MV_U32 ); if( wCount[bIndex] == 0 ) { if( !sgd_iter_get_next( &sg_iter[bIndex], sgd ) ) { bFinished = MV_TRUE; /* for( bIndex = 0; bIndex < srcCount + dstCount; bIndex++ ) { MV_ASSERT( !sgd_iter_get_next( &sg_iter[bIndex], sgd ) ); } */ break; } sgd_get_vaddr( sgd, p ); pSrc[bIndex] = (MV_PU32) p; sgd_getsz( sgd, wCount[bIndex] ); } } }}#if defined(XOR_AS_GF)typedef MV_U8 XORUNIT;#elsetypedef MV_U32 XORUNIT;#endifvoid sg_xor( PCore_Driver_Extension pCore, xor_strm_t* strm, MV_U8 src_cnt, MV_U8 dst_cnt, MV_U32 byte_cnt ){ XORUNIT *pSrc, *pDst, *p; int i; XORUNIT value; MV_BOOLEAN mapped; MV_U32 off = 0; while( byte_cnt ) { for( i = 0; i < src_cnt+dst_cnt; i++ ) { mapped = MV_FALSE; if( strm[i].sgd[0].flags & SGD_PCTX ) { p = (XORUNIT*) sgd_kmap(pCore,strm[i].sgd); mapped = MV_TRUE; } else { MV_PVOID ptmp; sgd_get_vaddr( strm[i].sgd, ptmp ); p = (XORUNIT*) ptmp; } p = (XORUNIT*) (((MV_PU8) p) + strm[i].off + off); if( i == 0 ) value = *p; else if( i >= src_cnt ) *p = value; else value ^= *p; if( mapped ) sgd_kunmap( pCore, strm[i].sgd, p ); } byte_cnt -= sizeof(XORUNIT); off += sizeof(XORUNIT); }}MV_U32 min_of(MV_U32* ele, MV_U32 cnt){ MV_U32 v = *ele++; while( --cnt ) { if( *ele < v ) v = *ele; ele++; } return v;}voidXorSGs( PCore_Driver_Extension pCore, MV_U8 srcCount, MV_U8 dstCount, PMV_SG_Table srctbl, PMV_SG_Table dsttbl, XOR_COEF Coef[XOR_TARGET_SG_COUNT][XOR_SOURCE_SG_COUNT] ){ xor_strm_t strm[XOR_SOURCE_SG_COUNT+ XOR_TARGET_SG_COUNT]; sgd_iter_t sg_iter[XOR_SOURCE_SG_COUNT + XOR_TARGET_SG_COUNT]; MV_U32 wCount[XOR_SOURCE_SG_COUNT + XOR_TARGET_SG_COUNT]; MV_U8 bIndex; MV_BOOLEAN bFinished = MV_FALSE; MV_U32 tmp = srctbl[0].Byte_Count; MV_U32 count = 0xffffffffL; for( bIndex = 0; bIndex < srcCount; bIndex++ ) { MV_ASSERT( srctbl[bIndex].Byte_Count == tmp ); sgd_iter_init( &sg_iter[bIndex], srctbl[bIndex].Entry_Ptr, 0, srctbl[bIndex].Byte_Count ); } for( bIndex = 0; bIndex < dstCount; bIndex++ ) { MV_ASSERT( dsttbl[bIndex].Byte_Count == tmp ); sgd_iter_init( &sg_iter[srcCount+bIndex], dsttbl[bIndex].Entry_Ptr, 0, dsttbl[bIndex].Byte_Count ); } for( bIndex = 0; bIndex < srcCount + dstCount; bIndex++ ) { strm[bIndex].off = 0; sgd_iter_get_next( &sg_iter[bIndex], strm[bIndex].sgd ); sgd_getsz( strm[bIndex].sgd, wCount[bIndex] ); if( wCount[bIndex] < count ) count = wCount[bIndex]; } while( !bFinished ) { sg_xor( pCore, strm, srcCount, dstCount, count ); for( bIndex = 0; bIndex < srcCount + dstCount; bIndex++ ) { wCount[bIndex] -= count; if( wCount[bIndex] == 0 ) { if( !sgd_iter_get_next( &sg_iter[bIndex], strm[bIndex].sgd ) ) { bFinished = MV_TRUE; break; } strm[bIndex].off = 0; sgd_getsz( strm[bIndex].sgd, wCount[bIndex] ); } else strm[bIndex].off += count; } count = min_of( wCount, srcCount + dstCount ); }}#ifdef SIMULATORvoid _Core_ModuleSendXORRequest(MV_PVOID This, PMV_XOR_Request pXORReq)#else /*SIMULATOR*/void Core_ModuleSendXORRequest(MV_PVOID This, PMV_XOR_Request pXORReq)#endif /*!SIMULATOR*/{ PCore_Driver_Extension pCore = (PCore_Driver_Extension)This; switch (pXORReq->Request_Type) { case XOR_REQUEST_WRITE: XorSGs( pCore, pXORReq->Source_SG_Table_Count, pXORReq->Target_SG_Table_Count, pXORReq->Source_SG_Table_List, pXORReq->Target_SG_Table_List, pXORReq->Coef ); break; case XOR_REQUEST_COMPARE: MV_ASSERT( pXORReq->Source_SG_Table_Count == 2 ); CompareSGs( pCore, pXORReq, pXORReq->Source_SG_Table_List ); break; case XOR_REQUEST_DMA: CopySGs( pCore, pXORReq->Source_SG_Table_List, pXORReq->Target_SG_Table_List ); break; default: pXORReq->Request_Status = XOR_STATUS_INVALID_REQUEST; break; }#ifndef SIMULATOR pXORReq->Completion( pXORReq->Cmd_Initiator, pXORReq );#endif /*!SIMULATOR*/}#endif /*USE_NEW_SGTABLE*/#endif /* RAID_DRIVER && SOFTWARE_XOR */#if defined(RAID_DRIVER) && defined(USE_NEW_SGTABLE)static void sg_memcpy( PCore_Driver_Extension pCore, xor_strm_t *strm, /*strm[0]:source, strm[1]:destination*/ MV_U32 byte_cnt ){ MV_U32 sz; MV_PU32 pSrc[2] = { NULL, NULL }; MV_BOOLEAN mapped[2] = { MV_FALSE, MV_FALSE }; MV_PVOID p; int i; for( i = 0; i < 2; i++ ) { sgd_getsz(strm[i].sgd,sz); MV_DASSERT( strm[i].off < sz ); MV_DASSERT( strm[i].off+byte_cnt <= sz ); } for( i = 0; i < 2; i++ ) { if( strm[i].sgd[0].flags & SGD_PCTX ) { pSrc[i] = (MV_PU32) sgd_kmap(pCore,strm[i].sgd); mapped[i] = MV_TRUE; } else { sgd_get_vaddr( strm[i].sgd, p ); pSrc[i] = (MV_PU32) p; } } MV_CopyMemory( pSrc[1]+strm[1].off/sizeof(MV_U32), pSrc[0]+strm[0].off/sizeof(MV_U32), byte_cnt ); for( i = 0; i < 2; i++ ) if( mapped[i] ) sgd_kunmap(pCore,strm[i].sgd,pSrc[i]);}void CopySGs( PCore_Driver_Extension pCore, PMV_SG_Table srctbl, PMV_SG_Table dsttbl ){ MV_PU32 pSrc[2] = { NULL, }; sgd_iter_t sg_iter[2]; MV_U32 wCount[2], count; MV_BOOLEAN bFinished = MV_FALSE; MV_U8 bIndex; MV_PVOID p; xor_strm_t strm[2]; MV_ASSERT( srctbl->Byte_Count == dsttbl->Byte_Count ); sgd_iter_init( &sg_iter[0], srctbl->Entry_Ptr, 0, srctbl->Byte_Count ); sgd_iter_init( &sg_iter[1], dsttbl->Entry_Ptr, 0, dsttbl->Byte_Count ); for( bIndex = 0; bIndex < 2; bIndex++ ) { strm[bIndex].off = 0; sgd_iter_get_next( &sg_iter[bIndex], strm[bIndex].sgd ); sgd_getsz( strm[bIndex].sgd, wCount[bIndex] ); } while( !bFinished ) { count = MV_MIN( wCount[0], wCount[1] ); sg_memcpy( pCore, strm, count ); for( bIndex = 0; bIndex < 2; bIndex++ ) { wCount[bIndex] -= count; if( wCount[bIndex] == 0 ) { if( !sgd_iter_get_next( &sg_iter[bIndex], strm[bIndex].sgd ) ) { bFinished = MV_TRUE; break; } sgd_getsz( strm[bIndex].sgd, wCount[bIndex] ); strm[bIndex].off = 0; } else strm[bIndex].off += count; } }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -