📄 skxmac2.c
字号:
/****************************************************************************** * * SkGmHardRst() - Do a GMAC hardware reset * * Description: * * Returns: * nothing */static void SkGmHardRst(SK_AC *pAC, /* adapter context */SK_IOC IoC, /* IO context */int Port) /* Port Index (MAC_1 + n) */{ SK_U32 DWord; /* WA code for COMA mode */ if (pAC->GIni.GIYukonLite && pAC->GIni.GIChipRev >= CHIP_REV_YU_LITE_A3) { SK_IN32(IoC, B2_GP_IO, &DWord); DWord |= (GP_DIR_9 | GP_IO_9); /* set PHY reset */ SK_OUT32(IoC, B2_GP_IO, DWord); } /* set GPHY Control reset */ SK_OUT32(IoC, MR_ADDR(Port, GPHY_CTRL), GPC_RST_SET); /* set GMAC Control reset */ SK_OUT32(IoC, MR_ADDR(Port, GMAC_CTRL), GMC_RST_SET);} /* SkGmHardRst *//****************************************************************************** * * SkGmClearRst() - Release the GPHY & GMAC reset * * Description: * * Returns: * nothing */static void SkGmClearRst(SK_AC *pAC, /* adapter context */SK_IOC IoC, /* IO context */int Port) /* Port Index (MAC_1 + n) */{ SK_U32 DWord; #ifdef XXX /* clear GMAC Control reset */ SK_OUT32(IoC, MR_ADDR(Port, GMAC_CTRL), GMC_RST_CLR); /* set GMAC Control reset */ SK_OUT32(IoC, MR_ADDR(Port, GMAC_CTRL), GMC_RST_SET);#endif /* XXX */ /* WA code for COMA mode */ if (pAC->GIni.GIYukonLite && pAC->GIni.GIChipRev >= CHIP_REV_YU_LITE_A3) { SK_IN32(IoC, B2_GP_IO, &DWord); DWord |= GP_DIR_9; /* set to output */ DWord &= ~GP_IO_9; /* clear PHY reset (active high) */ /* clear PHY reset */ SK_OUT32(IoC, B2_GP_IO, DWord); } /* set HWCFG_MODE */ DWord = GPC_INT_POL_HI | GPC_DIS_FC | GPC_DIS_SLEEP | GPC_ENA_XC | GPC_ANEG_ADV_ALL_M | GPC_ENA_PAUSE | (pAC->GIni.GICopperType ? GPC_HWCFG_GMII_COP : GPC_HWCFG_GMII_FIB); /* set GPHY Control reset */ SK_OUT32(IoC, MR_ADDR(Port, GPHY_CTRL), DWord | GPC_RST_SET); /* release GPHY Control reset */ SK_OUT32(IoC, MR_ADDR(Port, GPHY_CTRL), DWord | GPC_RST_CLR);#ifdef VCPU VCpuWait(9000);#endif /* VCPU */ /* clear GMAC Control reset */ SK_OUT32(IoC, MR_ADDR(Port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR);#ifdef VCPU VCpuWait(2000); SK_IN32(IoC, MR_ADDR(Port, GPHY_CTRL), &DWord); SK_IN32(IoC, B0_ISRC, &DWord);#endif /* VCPU */} /* SkGmClearRst */#endif /* YUKON *//****************************************************************************** * * SkMacSoftRst() - Do a MAC software reset * * Description: calls a MAC software reset routine dep. on board type * * Returns: * nothing */void SkMacSoftRst(SK_AC *pAC, /* adapter context */SK_IOC IoC, /* IO context */int Port) /* Port Index (MAC_1 + n) */{ SK_GEPORT *pPrt; pPrt = &pAC->GIni.GP[Port]; /* disable receiver and transmitter */ SkMacRxTxDisable(pAC, IoC, Port);#ifdef GENESIS if (pAC->GIni.GIGenesis) { SkXmSoftRst(pAC, IoC, Port); }#endif /* GENESIS */ #ifdef YUKON if (pAC->GIni.GIYukon) { SkGmSoftRst(pAC, IoC, Port); }#endif /* YUKON */ /* flush the MAC's Rx and Tx FIFOs */ SkMacFlushTxFifo(pAC, IoC, Port); SkMacFlushRxFifo(pAC, IoC, Port); pPrt->PState = SK_PRT_STOP;} /* SkMacSoftRst *//****************************************************************************** * * SkMacHardRst() - Do a MAC hardware reset * * Description: calls a MAC hardware reset routine dep. on board type * * Returns: * nothing */void SkMacHardRst(SK_AC *pAC, /* adapter context */SK_IOC IoC, /* IO context */int Port) /* Port Index (MAC_1 + n) */{ #ifdef GENESIS if (pAC->GIni.GIGenesis) { SkXmHardRst(pAC, IoC, Port); }#endif /* GENESIS */ #ifdef YUKON if (pAC->GIni.GIYukon) { SkGmHardRst(pAC, IoC, Port); }#endif /* YUKON */ pAC->GIni.GP[Port].PState = SK_PRT_RESET;} /* SkMacHardRst *//****************************************************************************** * * SkMacClearRst() - Clear the MAC reset * * Description: calls a clear MAC reset routine dep. on board type * * Returns: * nothing */void SkMacClearRst(SK_AC *pAC, /* adapter context */SK_IOC IoC, /* IO context */int Port) /* Port Index (MAC_1 + n) */{ #ifdef GENESIS if (pAC->GIni.GIGenesis) { SkXmClearRst(pAC, IoC, Port); }#endif /* GENESIS */ #ifdef YUKON if (pAC->GIni.GIYukon) { SkGmClearRst(pAC, IoC, Port); }#endif /* YUKON */} /* SkMacClearRst */#ifdef GENESIS/****************************************************************************** * * SkXmInitMac() - Initialize the XMAC II * * Description: * Initialize the XMAC of the specified port. * The XMAC must be reset or stopped before calling this function. * * Note: * The XMAC's Rx and Tx state machine is still disabled when returning. * * Returns: * nothing */void SkXmInitMac(SK_AC *pAC, /* adapter context */SK_IOC IoC, /* IO context */int Port) /* Port Index (MAC_1 + n) */{ SK_GEPORT *pPrt; int i; SK_U16 SWord; pPrt = &pAC->GIni.GP[Port]; if (pPrt->PState == SK_PRT_STOP) { /* Port State: SK_PRT_STOP */ /* Verify that the reset bit is cleared */ SK_IN16(IoC, MR_ADDR(Port, TX_MFF_CTRL1), &SWord); if ((SWord & MFF_SET_MAC_RST) != 0) { /* PState does not match HW state */ SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E006, SKERR_HWI_E006MSG); /* Correct it */ pPrt->PState = SK_PRT_RESET; } } if (pPrt->PState == SK_PRT_RESET) { SkXmClearRst(pAC, IoC, Port); if (pPrt->PhyType != SK_PHY_XMAC) { /* read Id from external PHY (all have the same address) */ SkXmPhyRead(pAC, IoC, Port, PHY_XMAC_ID1, &pPrt->PhyId1); /* * Optimize MDIO transfer by suppressing preamble. * Must be done AFTER first access to BCOM chip. */ XM_IN16(IoC, Port, XM_MMU_CMD, &SWord); XM_OUT16(IoC, Port, XM_MMU_CMD, SWord | XM_MMU_NO_PRE); if (pPrt->PhyId1 == PHY_BCOM_ID1_C0) { /* * Workaround BCOM Errata for the C0 type. * Write magic patterns to reserved registers. */ i = 0; while (BcomRegC0Hack[i].PhyReg != 0) { SkXmPhyWrite(pAC, IoC, Port, BcomRegC0Hack[i].PhyReg, BcomRegC0Hack[i].PhyVal); i++; } } else if (pPrt->PhyId1 == PHY_BCOM_ID1_A1) { /* * Workaround BCOM Errata for the A1 type. * Write magic patterns to reserved registers. */ i = 0; while (BcomRegA1Hack[i].PhyReg != 0) { SkXmPhyWrite(pAC, IoC, Port, BcomRegA1Hack[i].PhyReg, BcomRegA1Hack[i].PhyVal); i++; } } /* * Workaround BCOM Errata (#10523) for all BCom PHYs. * Disable Power Management after reset. */ SkXmPhyRead(pAC, IoC, Port, PHY_BCOM_AUX_CTRL, &SWord); SkXmPhyWrite(pAC, IoC, Port, PHY_BCOM_AUX_CTRL, (SK_U16)(SWord | PHY_B_AC_DIS_PM)); /* PHY LED initialization is done in SkGeXmitLED() */ } /* Dummy read the Interrupt source register */ XM_IN16(IoC, Port, XM_ISRC, &SWord); /* * The auto-negotiation process starts immediately after * clearing the reset. The auto-negotiation process should be * started by the SIRQ, therefore stop it here immediately. */ SkMacInitPhy(pAC, IoC, Port, SK_FALSE);#ifdef TEST_ONLY /* temp. code: enable signal detect */ /* WARNING: do not override GMII setting above */ XM_OUT16(IoC, Port, XM_HW_CFG, XM_HW_COM4SIG);#endif } /* * configure the XMACs Station Address * B2_MAC_2 = xx xx xx xx xx x1 is programmed to XMAC A * B2_MAC_3 = xx xx xx xx xx x2 is programmed to XMAC B */ for (i = 0; i < 3; i++) { /* * The following 2 statements are together endianess * independent. Remember this when changing. */ SK_IN16(IoC, (B2_MAC_2 + Port * 8 + i * 2), &SWord); XM_OUT16(IoC, Port, (XM_SA + i * 2), SWord); } /* Tx Inter Packet Gap (XM_TX_IPG): use default */ /* Tx High Water Mark (XM_TX_HI_WM): use default */ /* Tx Low Water Mark (XM_TX_LO_WM): use default */ /* Host Request Threshold (XM_HT_THR): use default */ /* Rx Request Threshold (XM_RX_THR): use default */ /* Rx Low Water Mark (XM_RX_LO_WM): use default */ /* configure Rx High Water Mark (XM_RX_HI_WM) */ XM_OUT16(IoC, Port, XM_RX_HI_WM, SK_XM_RX_HI_WM); /* Configure Tx Request Threshold */ SWord = SK_XM_THR_SL; /* for single port */ if (pAC->GIni.GIMacsFound > 1) { switch (pAC->GIni.GIPortUsage) { case SK_RED_LINK: SWord = SK_XM_THR_REDL; /* redundant link */ break; case SK_MUL_LINK: SWord = SK_XM_THR_MULL; /* load balancing */ break; case SK_JUMBO_LINK: SWord = SK_XM_THR_JUMBO; /* jumbo frames */ break; default: SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E014, SKERR_HWI_E014MSG); break; } } XM_OUT16(IoC, Port, XM_TX_THR, SWord); /* setup register defaults for the Tx Command Register */ XM_OUT16(IoC, Port, XM_TX_CMD, XM_TX_AUTO_PAD); /* setup register defaults for the Rx Command Register */ SWord = XM_RX_STRIP_FCS | XM_RX_LENERR_OK; if (pAC->GIni.GIPortUsage == SK_JUMBO_LINK) { SWord |= XM_RX_BIG_PK_OK; } if (pPrt->PLinkMode == SK_LMODE_HALF) { /* * If in manual half duplex mode the other side might be in * full duplex mode, so ignore if a carrier extension is not seen * on frames received */ SWord |= XM_RX_DIS_CEXT; } XM_OUT16(IoC, Port, XM_RX_CMD, SWord); /* * setup register defaults for the Mode Register * - Don't strip error frames to avoid Store & Forward * on the Rx side. * - Enable 'Check Station Address' bit * - Enable 'Check Address Array' bit */ XM_OUT32(IoC, Port, XM_MODE, XM_DEF_MODE); /* * Initialize the Receive Counter Event Mask (XM_RX_EV_MSK) * - Enable all bits excepting 'Octets Rx OK Low CntOv' * and 'Octets Rx OK Hi Cnt Ov'. */ XM_OUT32(IoC, Port, XM_RX_EV_MSK, XMR_DEF_MSK); /* * Initialize the Transmit Counter Event Mask (XM_TX_EV_MSK) * - Enable all bits excepting 'Octets Tx OK Low CntOv' * and 'Octets Tx OK Hi Cnt Ov'. */ XM_OUT32(IoC, Port, XM_TX_EV_MSK, XMT_DEF_MSK); /* * Do NOT init XMAC interrupt mask here. * All interrupts remain disable until link comes up! */ /* * Any additional configuration changes may be done now. * The last action is to enable the Rx and Tx state machine. * This should be done after the auto-negotiation process * has been completed successfully. */} /* SkXmInitMac */#endif /* GENESIS */#ifdef YUKON/****************************************************************************** * * SkGmInitMac() - Initialize the GMAC * * Description: * Initialize the GMAC of the specified port. * The GMAC must be reset or stopped before calling this function. * * Note: * The GMAC's Rx and Tx state machine is still disabled when returning. * * Returns: * nothing */void SkGmInitMac(SK_AC *pAC, /* adapter context */SK_IOC IoC, /* IO context */int Port) /* Port Index (MAC_1 + n) */{ SK_GEPORT *pPrt; int i; SK_U16 SWord; SK_U32 DWord; pPrt = &pAC->GIni.GP[Port]; if (pPrt->PState == SK_PRT_STOP) { /* Port State: SK_PRT_STOP */ /* Verify that the reset bit is cleared */ SK_IN32(IoC, MR_ADDR(Port, GMAC_CTRL), &DWord); if ((DWord & GMC_RST_SET) != 0) { /* PState does not match HW state */ SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E006, SKERR_HWI_E006MSG); /* Correct it */ pPrt->PState = SK_PRT_RESET; } } if (pPrt->PState == SK_PRT_RESET) { SkGmHardRst(pAC, IoC, Port); SkGmClearRst(pAC, IoC, Port); /* Auto-negotiation ? */ if (pPrt->PLinkMode == SK_LMODE_HALF || pPrt->PLinkMode == SK_LMODE_FULL) { /* Auto-negotiation disabled */ /* get General Purpose Control */ GM_IN16(IoC, Port, GM_GP_CTRL, &SWord); /* disable auto-update for speed, duplex and flow-control */ SWord |= GM_GPCR_AU_ALL_DIS; /* setup General Purpose Control Register */ GM_OUT16(IoC, Port, GM_GP_CTRL, SWord); SWord = GM_GPCR_AU_ALL_DIS; } else { SWord = 0; } /* speed settings */ switch (pPrt->PLinkSpeed) { case SK_LSPEED_AUTO: case SK_LSPEED_1000MBPS: SWord |= GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100; break; case SK_LSPEED_100MBPS: SWord |= GM_GPCR_SPEED_100; break; case SK_LSPEED_10MBPS: break; } /* duplex settings */ if (pPrt->PLinkMode != SK_LMODE_HALF) { /* set full duplex */ SWord |= GM_GPCR_DUP_FULL; } /* flow-control settings */ switch (pPrt->PFlowCtrlMode) { case SK_FLOW_MODE_NONE: /* set Pause Off */ SK_OUT32(IoC, MR_ADDR(Port, GMAC_CTRL), GMC_PAUSE_OFF); /* disable Tx & Rx flow-control */ SWord |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS | GM_GPCR_AU_FCT_DIS; break; case SK_FLOW_MODE_LOC_SEND:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -