光电复用口link错误

发布时间 2023-09-25 10:23:19作者: 枝桠

现象:光电复用口,电口和光口接满线,电口与光口各亮一对

serdes_link=0
copper_link=0
get_combo_link_status()
{
    port1=$1
#   local tmp_reg=`bcmsh "linkscan off ; phy ${port1} 0x17 0xf7e ; phy ${port1} 0x15 0; phy ${port1} 0x1e 0x21 ; phy ${port1} 0x1f ; linkscan on" | awk -F "Reg 0x001f: " '{print $2}'`
                                    		|
		                                    |
        			                        ---> 使能RDB访问模式


    local tmp_reg=`bcmsh "phy ${port1} 0x17 0xf7e ; phy ${port1} 0x15 0; phy ${port1} 0x1e 0x21 ; phy ${port1} 0x1f" | awk -F "Reg 0x001f: " '{print $2}'`
    serdes_link=$((${tmp_reg} & (0x1 << 6)))
    copper_link=$((${tmp_reg} & (0x1 << 7)))
}


combo_check()
{
    local port1=$1
    local port2=$2
    local count1=0
    local count2=0
    
    # 首先读一下当前这组光模块的link状态
    get_combo_link_status

    if [ ${serdes_link} -eq 0 -a ${copper_link} -eq 0 ]; then
        echo "port ${port1},${port2} not lnik."
        return
    fi
    
    # 如果link的不是光口对这两个光电复用口重新 disable - enable
    while [ ${serdes_link} -eq 0 -a  ${count1} -lt 5 ]
    do
        # 重新 disable - enable
        bcmsh port ${port1},${port2} e=0 > /dev/null 2&>1
        sleep 6     # 这个时间需要足够长
        bcmsh port ${port1},${port2} e=1 > /dev/null 2&>1
        sleep 3
        
        # 再读取一下端口link状态
        get_combo_link_status
        echo "port ${port1} serdes_link : $serdes_link, copper_link : $copper_link"
        
        count2=0
        while [ ${serdes_link} -eq 0 -a ${copper_link} -eq 0 -a ${count2} -lt 5 ]
        do
            # 如果端口还没起来,那就等它起来
            get_combo_link_status
            echo "port ${port1} serdes_link : $serdes_link, copper_link : $copper_link"
            
            count2=$((${count2} + 1))
            sleep 1
        done

        count1=$((${count1} + 1))
        if [ ${serdes_link} -eq 0 -a ${copper_link} -eq 0 ]; then
            echo "port ${port1},${port2} not lnik."
            continue
        fi
        
        if [ ${serdes_link} -ne 0 ]; then
            break
        fi
    done
}