/******************************************************************************* * mvEthWinEnable - Enable/disable a ETH to target address window * * DESCRIPTION: * This function enable/disable a ETH to target address window. * According to parameter 'enable' the routine will enable the * window, thus enabling ETH accesses (before enabling the window it is * tested for overlapping). Otherwise, the window will be disabled. * * INPUT: * winNum - ETH to target address decode window number. * enable - Enable/disable parameter. * * OUTPUT: * N/A * * RETURN: * MV_ERROR if decode window number was wrong or enabled window overlapps. * *******************************************************************************/ MV_STATUS mvEthWinEnable(int port, MV_U32 winNum,MV_BOOL enable) { MV_ETH_DEC_WIN addrDecWin; /* Parameter checking */ if (winNum >= ETH_MAX_DECODE_WIN) { mvOsPrintf("mvEthTargetWinEnable:ERR. Invalid winNum%d\n",winNum); return MV_ERROR; } if (enable == MV_TRUE) { /* First check for overlap with other enabled windows */ /* Get current window */ if (MV_OK != mvEthWinGet(port, winNum, &addrDecWin)) { mvOsPrintf("mvEthTargetWinEnable:ERR. targetWinGet fail\n"); return MV_ERROR; } /* Check for overlapping */ if (MV_FALSE == ethWinOverlapDetect(port, winNum, &(addrDecWin.addrWin))) { /* No Overlap. Enable address decode target window */ MV_REG_BIT_RESET(ETH_BASE_ADDR_ENABLE_REG(port), (1 << winNum)); } else { /* Overlap detected */ mvOsPrintf("mvEthTargetWinEnable:ERR. Overlap detected\n"); return MV_ERROR; } } else { /* Disable address decode target window */ MV_REG_BIT_SET(ETH_BASE_ADDR_ENABLE_REG(port), (1 << winNum)); } return MV_OK; }
/******************************************************************************* * mvPp2WinWrite * * DESCRIPTION: * This function writes the address decoding registers according to the * given window configuration. * * INPUT: * unit - The Ethernet unit number to configure. * winNum - ETH target address decode window number. * pAddrDecWin - ETH target window data structure. * * OUTPUT: * None. * * RETURN: * MV_OK on success, * MV_BAD_PARAM if winNum is invalid. * MV_ERROR otherwise. * *******************************************************************************/ MV_STATUS mvPp2WinWrite(MV_U32 dummy/*backward compability*/, MV_U32 winNum, MV_UNIT_WIN_INFO *pAddrDecWin) { MV_U32 size, alignment; MV_U32 baseReg, sizeReg; /* Parameter checking */ if (winNum >= ETH_MAX_DECODE_WIN) { mvOsPrintf("mvPp2WinSet: ERR. Invalid win num %d\n", winNum); return MV_BAD_PARAM; } /* Check if the requested window overlapps with current windows */ if (MV_TRUE == ethWinOverlapDetect(winNum, &pAddrDecWin->addrWin)) { mvOsPrintf("mvPp2WinWrite: ERR. Window %d overlap\n", winNum); return MV_ERROR; } /* check if address is aligned to the size */ if (MV_IS_NOT_ALIGN(pAddrDecWin->addrWin.baseLow, pAddrDecWin->addrWin.size)) { mvOsPrintf("mvPp2WinSet: Error setting Ethernet window %d.\n" "Address 0x%08x is unaligned to size 0x%x.\n", winNum, pAddrDecWin->addrWin.baseLow, (MV_U32)pAddrDecWin->addrWin.size); return MV_ERROR; } size = pAddrDecWin->addrWin.size; if (!MV_IS_POWER_OF_2(size)) { mvOsPrintf("mvPp2WinWrite: Error setting AUDIO window %d. " "Window size is not a power to 2.", winNum); return MV_BAD_PARAM; } baseReg = (pAddrDecWin->addrWin.baseLow & ETH_WIN_BASE_MASK); sizeReg = MV_REG_READ(ETH_WIN_SIZE_REG(winNum)); /* set size */ alignment = 1 << ETH_WIN_SIZE_OFFS; sizeReg &= ~ETH_WIN_SIZE_MASK; sizeReg |= (((size / alignment) - 1) << ETH_WIN_SIZE_OFFS); /* set attributes */ baseReg &= ~ETH_WIN_ATTR_MASK; baseReg |= pAddrDecWin->attrib << ETH_WIN_ATTR_OFFS; /* set target ID */ baseReg &= ~ETH_WIN_TARGET_MASK; baseReg |= pAddrDecWin->targetId << ETH_WIN_TARGET_OFFS; /* for the safe side we disable the window before writing the new values */ mvPp2WinEnable(0, winNum, MV_FALSE); mvPp2WrReg(ETH_WIN_BASE_REG(winNum), baseReg); /* Write to address decode Size Register */ mvPp2WrReg(ETH_WIN_SIZE_REG(winNum), sizeReg); /* Enable address decode target window */ if (pAddrDecWin->enable == MV_TRUE) mvPp2WinEnable(0, winNum, MV_TRUE); return MV_OK; }
/******************************************************************************* * mvEthWinSet - Set ETH target address window * * DESCRIPTION: * This function sets a peripheral target (e.g. SDRAM bank0, PCI_MEM0) * address window, also known as address decode window. * After setting this target window, the ETH will be able to access the * target within the address window. * * INPUT: * winNum - ETH to target address decode window number. * pAddrDecWin - ETH target window data structure. * * OUTPUT: * None. * * RETURN: * MV_ERROR if address window overlapps with other address decode windows. * MV_BAD_PARAM if base address is invalid parameter or target is * unknown. * *******************************************************************************/ MV_STATUS mvEthWinSet(int port, MV_U32 winNum, MV_ETH_DEC_WIN *pAddrDecWin) { MV_TARGET_ATTRIB targetAttribs; MV_DEC_REGS decRegs; /* Parameter checking */ if (winNum >= ETH_MAX_DECODE_WIN) { mvOsPrintf("mvEthWinSet: ERR. Invalid win num %d\n",winNum); return MV_BAD_PARAM; } /* Check if the requested window overlapps with current windows */ if (MV_TRUE == ethWinOverlapDetect(port, winNum, &pAddrDecWin->addrWin)) { mvOsPrintf("mvEthWinSet: ERR. Window %d overlap\n", winNum); return MV_ERROR; } /* check if address is aligned to the size */ if(MV_IS_NOT_ALIGN(pAddrDecWin->addrWin.baseLow, pAddrDecWin->addrWin.size)) { mvOsPrintf("mvEthWinSet: Error setting Ethernet window %d to "\ "target %s.\nAddress 0x%08x is unaligned to size 0x%x.\n", winNum, mvCtrlTargetNameGet(pAddrDecWin->target), pAddrDecWin->addrWin.baseLow, pAddrDecWin->addrWin.size); return MV_ERROR; } decRegs.baseReg = MV_REG_READ(ETH_WIN_BASE_REG(port, winNum)); decRegs.sizeReg = MV_REG_READ(ETH_WIN_SIZE_REG(port, winNum)); if (MV_OK != mvCtrlAddrDecToReg(&(pAddrDecWin->addrWin),&decRegs)) { mvOsPrintf("mvEthWinSet:mvCtrlAddrDecToReg Failed\n"); return MV_ERROR; } mvCtrlAttribGet(pAddrDecWin->target,&targetAttribs); /* set attributes */ decRegs.baseReg &= ~ETH_WIN_ATTR_MASK; decRegs.baseReg |= targetAttribs.attrib << ETH_WIN_ATTR_OFFS; /* set target ID */ decRegs.baseReg &= ~ETH_WIN_TARGET_MASK; decRegs.baseReg |= targetAttribs.targetId << ETH_WIN_TARGET_OFFS; /* for the safe side we disable the window before writing the new values */ mvEthWinEnable(port, winNum, MV_FALSE); MV_REG_WRITE(ETH_WIN_BASE_REG(port, winNum), decRegs.baseReg); /* Write to address decode Size Register */ MV_REG_WRITE(ETH_WIN_SIZE_REG(port, winNum), decRegs.sizeReg); /* Enable address decode target window */ if (pAddrDecWin->enable == MV_TRUE) { mvEthWinEnable(port, winNum, MV_TRUE); } return MV_OK; }