?? 3c59x.inc
字號:
; auto-negotiation is set; switch to register window 4 lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+4 out dx, ax; PHY==24 is the on-chip auto-negotiation logic; it supports only 10base-T and 100base-TX mov ah, 24 call e3c59x_try_phy test al, al jz .fail_finish mov cl, 24 jmp .check_preamble.mii_device: cmp eax, (0110b shl 20) jne .fail_finish lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+4 out dx, ax lea edx, [ebp+E3C59X_REG_PHYSICAL_MGMT] in ax, dx and al, (1 shl E3C59X_BIT_MGMT_DIR) or (1 shl E3C59X_BIT_MGMT_DATA) cmp al, (1 shl E3C59X_BIT_MGMT_DATA) je .serch_for_phy xor al, al ret.serch_for_phy:; search for PHY mov cl, 31.search_phy_loop: cmp cl, 24 je .next_phy mov ah, cl ; ah = phy mov al, E3C59X_REG_MII_BMCR ; al = Basic Mode Status Register push ecx call e3c59x_mdio_read pop ecx test ax, ax jz .next_phy cmp ax, 0xffff je .next_phy mov ah, cl ; ah = phy push ecx call e3c59x_try_phy pop ecx test al, al jnz .check_preamble.next_phy: dec cl jns .search_phy_loop.fail_finish: xor al, al ret; epilog.check_preamble: push eax ; eax contains the return value of e3c59x_try_phy; check hard coded preamble forcing movzx eax, byte [e3c59x_ver_id] test word [eax*4+e3c59x_hw_versions+2], EXTRA_PREAMBLE setnz [e3c59x_preamble] ; force preamble jnz .finish; check mii for preamble suppression mov ah, cl mov al, E3C59X_REG_MII_BMSR call e3c59x_mdio_read test al, 1000000b ; preamble suppression? setz [e3c59x_preamble] ; no.finish: pop eax ret;***************************************************************************; Function; e3c59x_test_packet; Description; e3c59x_try_loopback try a loopback packet for 10BASE2 or AUI port; Parameters; ebp - io_addr; Return value; al - 0; al - 1; Destroyed registers; eax, ebx, ecx, edx, edi, esi;;*************************************************************************** align 4e3c59x_test_packet:; switch to register window 3 lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+3 out dx, ax; set fullDuplexEnable in MacControl register lea edx, [ebp+E3C59X_REG_MAC_CONTROL] in ax, dx or ax, 0x120 out dx, ax; switch to register window 5 lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+5 out dx, ax; set RxFilter to enable individual address matches mov ax, (10000b shl 11) lea edx, [ebp+E3C59X_REG_RX_FILTER] in al, dx or al, 1 lea edx, [ebp+E3C59X_REG_COMMAND] out dx, ax; issue RxEnable and TxEnable call e3c59x_rx_reset call e3c59x_tx_reset; download a self-directed test packet mov edi, node_addr mov bx, 0x0608 ; packet type mov esi, e3c59x_self_directed_packet mov ecx, 6 ; 6 + 6 + 2 + 6 = 20 bytes call dword [e3c59x_transmit_function]; wait for 2s mov esi, 2000 ; 2000ms = 2s call delay_ms; check if self-directed packet is received call dword [e3c59x_receive_function] test al, al jnz .finish; switch to register window 3 lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+3 out dx, ax; clear fullDuplexEnable in MacControl register lea edx, [ebp+E3C59X_REG_MAC_CONTROL] in ax, dx and ax, not 0x120 out dx, ax xor al, al.finish: ret;***************************************************************************; Function; e3c59x_try_loopback; Description; tries a loopback packet for 10BASE2 or AUI port; Parameters; al - 0: 10Mbps AUI connector; 1: 10BASE-2; ebp - io_addr; Return value; al - 0; al - 1; Destroyed registers; eax, ebx, ecx, edx, edi, esi;;*************************************************************************** align 4e3c59x_try_loopback: push eax; switch to register window 3 lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+3 out dx, ax pop eax push eaxif defined E3C59X_DEBUG mov bl, al inc bl shl bl, 3 or byte [e3c59x_link_type+1], blend if ; defined E3C59X_DEBUG test al, al ; aui or coax? jz .complete_loopback; enable 100BASE-2 DC-DC converter mov ax, (10b shl 11) ; EnableDcConverter out dx, ax.complete_loopback: mov cl, 2 ; give a port 3 chances to complete a loopback.next_try: push ecx call e3c59x_test_packet pop ecx test al, al jnz .finish dec cl jns .next_try.finish: xchg eax, [esp] test al, al jz .aui_finish; issue DisableDcConverter command lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, (10111b shl 11) out dx, ax.aui_finish: pop eax ; al contains the result of operationif defined E3C59X_DEBUG test al, al jnz @f and byte [e3c59x_link_type+1], not 11000b@@:end if ; defined E3C59X_DEBUG ret;***************************************************************************; Function; e3c59x_set_available_media; Description; sets the first available media; Parameters; ebp - io_addr; Return value; al - 0; al - 1; Destroyed registers; eax, edx;;*************************************************************************** align 4e3c59x_set_available_media:; switch to register window 3 lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+3 out dx, ax lea edx, [ebp+E3C59X_REG_INTERNAL_CONFIG] in eax, dx push eax lea edx, [ebp+E3C59X_REG_MEDIA_OPTIONS] in ax, dx test al, 10b jz @f; baseTXAvailable pop eax and eax, not (1111b shl 20) or eax, (100b shl 20)if defined E3C59X_DEBUG & defined E3C59X_FORCE_FD mov word [e3c59x_link_type], (1 shl 8)else if defined E3C59X_DEBUG mov word [e3c59x_link_type], (1 shl 7)end if jmp .set_media@@: test al, 100b jz @f; baseFXAvailable pop eax and eax, not (1111b shl 20) or eax, (101b shl 20)if defined E3C59X_DEBUG mov word [e3c59x_link_type], (1 shl 10)end if jmp .set_media@@: test al, 1000000b jz @f; miiDevice pop eax and eax, not (1111b shl 20) or eax, (0110b shl 20)if defined E3C59X_DEBUG mov word [e3c59x_link_type], (1 shl 13)end if jmp .set_media@@: test al, 1000b jz @f.set_default:; 10bTAvailable pop eax and eax, not (1111b shl 20)if defined E3C59X_DEBUG & defined E3C59X_FORCE_FD mov word [e3c59x_link_type], (1 shl 6)else if defined E3C59X_DEBUG mov word [e3c59x_link_type], (1 shl 5)end if ; E3C59X_FORCE_FD jmp .set_media@@: test al, 10000b jz @f; coaxAvailable lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, (10b shl 11) ; EnableDcConverter out dx, ax pop eax and eax, not (1111b shl 20) or eax, (11b shl 20)if defined E3C59X_DEBUG mov word [e3c59x_link_type], (1 shl 12)end if ; defined E3C59X_DEBUG jmp .set_media@@: test al, 10000b jz .set_default; auiAvailable pop eax and eax, not (1111b shl 20) or eax, (1 shl 20)if defined E3C59X_DEBUG mov word [e3c59x_link_type], (1 shl 11)end if ; defined E3C59X_DEBUG.set_media: lea edx, [ebp+E3C59X_REG_INTERNAL_CONFIG] out dx, eaxif defined E3C59X_FORCE_FD; set fullDuplexEnable in MacControl register lea edx, [ebp+E3C59X_REG_MAC_CONTROL] in ax, dx or ax, 0x120 out dx, axend if ; E3C59X_FORCE_FD mov al, 1 ret;***************************************************************************; Function; e3c59x_set_active_port; Description; It selects the media port (transceiver) to be used; Parameters:; ebp - io_addr; Return value:; Destroyed registers; eax, ebx, ecx, edx, edi, esi;;*************************************************************************** align 4e3c59x_set_active_port:; switch to register window 3 lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+3 out dx, ax lea edx, [ebp+E3C59X_REG_INTERNAL_CONFIG] in eax, dx test eax, (1 shl 24) ; check if autoselect enable jz .set_first_available_media; check 100BASE-TX and 10BASE-T lea edx, [ebp+E3C59X_REG_MEDIA_OPTIONS] in ax, dx test al, 1010b ; check whether 100BASE-TX or 10BASE-T available jz .mii_device ; they are not available; set auto-negotiation lea edx, [ebp+E3C59X_REG_INTERNAL_CONFIG] in eax, dx and eax, not (1111b shl 20) or eax, (1000b shl 20) out dx, eax call e3c59x_try_mii test al, al jz .mii_device ret.mii_device:; switch to register window 3 lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+3 out dx, ax; check for off-chip mii device lea edx, [ebp+E3C59X_REG_MEDIA_OPTIONS] in ax, dx test al, 1000000b ; check miiDevice jz .base_fx lea edx, [ebp+E3C59X_REG_INTERNAL_CONFIG] in eax, dx and eax, not (1111b shl 20) or eax, (0110b shl 20) ; set MIIDevice out dx, eax call e3c59x_try_mii test al, al jz .base_fx ret.base_fx:; switch to register window 3 lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+3 out dx, ax; check for 100BASE-FX lea edx, [ebp+E3C59X_REG_MEDIA_OPTIONS] in ax, dx ; read media option register test al, 100b ; check 100BASE-FX jz .aui_enable lea edx, [ebp+E3C59X_REG_INTERNAL_CONFIG] in eax, dx and eax, not (1111b shl 20) or eax, (0101b shl 20) ; set 100base-FX out dx, eax call e3c59x_try_link_detect test al, al jz .aui_enable ret.aui_enable:; switch to register window 3 lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+3 out dx, ax; check for 10Mbps AUI connector lea edx, [ebp+E3C59X_REG_MEDIA_OPTIONS] in ax, dx ; read media option register
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -