?? 3c59x.inc
字號:
;***************************************************************************; Function; e3c59x_rx_reset; Description; resets and enables receiver engine; Parameters:; ebp - io_addr; Return value:; Destroyed registers; eax, ebx, ecx, edx, edi, esi;;*************************************************************************** align 4e3c59x_rx_reset: lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, (0101b shl 11) or 0x4 ; RxReset out dx, ax; wait for RxReset to complete mov ecx, 200000.rx_reset_loop: in ax, dx test ah, 10000b ; check CmdInProgress jz .setup_upd dec ecx jns .rx_reset_loop.setup_upd:; check if full bus mastering test byte [e3c59x_full_bus_master], 0xff jz .rx_enable; create upd ring mov eax, e3c59x_upd_buff zero_to_virt eax mov [e3c59x_curr_upd], eax mov esi, eax virt_to_dma esi mov edi, e3c59x_rx_buff zero_to_dma edi mov ebx, e3c59x_upd_buff+(E3C59X_NUM_RX_DESC-1)*E3C59X_UPD_SIZE zero_to_virt ebx mov cl, E3C59X_NUM_RX_DESC-1.upd_loop: mov [ebx+E3C59X_UPD_UP_NEXT_PTR], esi and dword [eax+E3C59X_UPD_PKT_STATUS], 0 mov [eax+E3C59X_UPD_UP_FRAG_ADDR], edi mov dword [eax+E3C59X_UPD_UP_FRAG_LEN], E3C59X_MAX_ETH_FRAME_SIZE or (1 shl 31) add edi, E3C59X_MAX_ETH_FRAME_SIZE add esi, E3C59X_UPD_SIZE mov ebx, eax add eax, E3C59X_UPD_SIZE dec cl jns .upd_loop mov eax, e3c59x_upd_buff zero_to_dma eax lea edx, [ebp+E3C59X_REG_UP_LIST_PTR] out dx, eax ; write E3C59X_REG_UP_LIST_PTR lea edx, [ebp+E3C59X_REG_COMMAND].rx_enable: mov ax, (00100b shl 11) ; RxEnable out dx, ax ret;***************************************************************************; Function; e3c59x_write_eeprom; Description; reads eeprom; Note : the caller must switch to the register window 0; before calling this function; Parameters:; ax - register to be read (only the first 63 words can be read); cx - value to be read into the register; Return value:; ax - word read; Destroyed registers; ax, ebx, edx;;***************************************************************************; align 4;e3c59x_write_eeprom:; mov edx, [io_addr]; add edx, E3C59X_REG_EEPROM_COMMAND; cmp ah, 11b; ja .finish ; address may have a value of maximal 1023; shl ax, 2; shr al, 2; push eax;; wait for busy; mov ebx, 0xffff;@@:; in ax, dx; test ah, 0x80; jz .write_enable; dec ebx; jns @r;; write enable;.write_enable:; xor eax, eax; mov eax, (11b shl 4); out dx, ax;; wait for busy; mov ebx, 0xffff;@@:; in ax, dx; test ah, 0x80; jz .erase_loop; dec ebx; jns @r;.erase_loop:; pop eax; push eax; or ax, (11b shl 6) ; erase register; out dx, ax; mov ebx, 0xffff;@@:; in ax, dx; test ah, 0x80; jz .write_reg; dec ebx; jns @r;.write_reg:; add edx, E3C59X_REG_EEPROM_DATA-E3C59X_REG_EEPROM_COMMAND; mov eax, ecx; out dx, ax;; write enable; add edx, E3C59X_REG_EEPROM_COMMAND-E3C59X_REG_EEPROM_DATA; xor eax, eax; mov eax, (11b shl 4); out dx, ax; wait for busy; mov ebx, 0xffff;@@:; in ax, dx; test ah, 0x80; jz .issue_write_reg; dec ebx; jns @r;.issue_write_reg:; pop eax; or ax, 01b shl 6; out dx, ax;.finish:; ret;***************************************************************************; Function; e3c59x_read_eeprom; Description; reads eeprom; Parameters:; ax - register to be read (only the first 63 words can be read); ebp - io_addr; Return value:; ax - word read; Destroyed registers; ax, ebx, edx, ebp;;*************************************************************************** align 4e3c59x_read_eeprom: push eax; switch to register window 0 lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+0 out dx, ax pop eax and ax, 111111b ; take only the first 6 bits into account movzx ebx, byte [e3c59x_ver_id] test word [ebx*4+e3c59x_hw_versions+2], EEPROM_8BIT jz @f add ax, 0x230 ; hardware constant jmp .read@@: add ax, E3C59X_EEPROM_CMD_READ test word [ebx*4+e3c59x_hw_versions+2], EEPROM_OFFSET jz .read add ax, 0x30.read: lea edx, [ebp+E3C59X_REG_EEPROM_COMMAND] out dx, ax mov ebx, 0xffff ; duration of about 162 us ;-).wait_for_reading: in ax, dx test ah, 0x80 ; check bit eepromBusy jz .read_data dec ebx jns .wait_for_reading.read_data: lea edx, [ebp+E3C59X_REG_EEPROM_DATA] in ax, dx ret;***************************************************************************; Function; e3c59x_mdio_sync; Description; initial synchronization; Parameters; ebp - io_addr; Return value; Destroyed registers; ax, edx, cl;;*************************************************************************** align 4e3c59x_mdio_sync:; switch to register window 4 lea edx, [ebp+E3C59X_REG_COMMAND] mov ax, E3C59X_SELECT_REGISTER_WINDOW+4 out dx, ax cmp byte [e3c59x_preamble], 0 je .no_preamble; send 32 logic ones lea edx, [ebp+E3C59X_REG_PHYSICAL_MGMT] mov cl, 31.loop: mov ax, (1 shl E3C59X_BIT_MGMT_DATA) or (1 shl E3C59X_BIT_MGMT_DIR) out dx, ax in ax, dx ; delay mov ax, (1 shl E3C59X_BIT_MGMT_DATA) \ or (1 shl E3C59X_BIT_MGMT_DIR) \ or (1 shl E3C59X_BIT_MGMT_CLK) out dx, ax in ax, dx ; delay dec cl jns .loop.no_preamble: ret;***************************************************************************; Function; e3c59x_mdio_read; Description; read MII register; see page 16 in D83840A.pdf; Parameters; ah - PHY addr; al - register addr; ebp - io_addr; Return value; ax - register read; Destroyed registers; eax, ebx, cx, edx;;*************************************************************************** align 4e3c59x_mdio_read: push eax call e3c59x_mdio_sync ; returns with window #4 pop eax lea edx, [ebp+E3C59X_REG_PHYSICAL_MGMT] shl al, 3 shr ax, 3 and ax, not E3C59X_MII_CMD_MASK or ax, E3C59X_MII_CMD_READ mov ebx, eax xor ecx, ecx mov cl, 13.cmd_loop: mov ax, (1 shl E3C59X_BIT_MGMT_DIR) ; write mii bt ebx, ecx jnc .zero_bit or al, (1 shl E3C59X_BIT_MGMT_DATA).zero_bit: out dx, ax push eax in ax, dx ; delay pop eax or al, (1 shl E3C59X_BIT_MGMT_CLK) ; write out dx, ax in ax, dx ; delay dec cl jns .cmd_loop; read data (18 bits with the two transition bits) mov cl, 17 xor ebx, ebx.read_loop: shl ebx, 1 xor eax, eax ; read comand out dx, ax in ax, dx ; delay in ax, dx test al, (1 shl E3C59X_BIT_MGMT_DATA) jz .dont_set inc ebx.dont_set: mov ax, (1 shl E3C59X_BIT_MGMT_CLK) out dx, ax in ax, dx ; delay dec cl jns .read_loop mov eax, ebx ret;***************************************************************************; Function; e3c59x_mdio_write; Description; write MII register; see page 16 in D83840A.pdf; Parameters; ah - PHY addr; al - register addr; bx - word to be written; ebp - io_addr; Return value; ax - register read; Destroyed registers; eax, ebx, cx, edx;;*************************************************************************** align 4e3c59x_mdio_write: push eax call e3c59x_mdio_sync pop eax lea edx, [ebp+E3C59X_REG_PHYSICAL_MGMT] shl al, 3 shr ax, 3 and ax, not E3C59X_MII_CMD_MASK or ax, E3C59X_MII_CMD_WRITE shl eax, 2 or eax, 10b ; transition bits shl eax, 16 mov ax, bx mov ebx, eax mov ecx, 31.cmd_loop: mov ax, (1 shl E3C59X_BIT_MGMT_DIR) ; write mii bt ebx, ecx jnc .zero_bit or al, (1 shl E3C59X_BIT_MGMT_DATA).zero_bit: out dx, ax push eax in ax, dx ; delay pop eax or al, (1 shl E3C59X_BIT_MGMT_CLK) ; write out dx, ax in ax, dx ; delay dec ecx jns .cmd_loop ret;***************************************************************************; Function; e3c59x_transmit; Description; Transmits a packet of data via the ethernet card; edi - Pointer to 48 bit destination address; bx - Type of packet; ecx - size of packet; esi - pointer to packet data; ebp - io_addr; Destroyed registers; eax, ecx, edx, ebp;;*************************************************************************** align 4e3c59x_transmit: jmp dword [e3c59x_transmit_function];***************************************************************************; Function; e3c59x_check_tx_status; Description; Checks TxStatus queue.; Return value; al - 0 no error was found; al - 1 error was found TxReset is needed; Destroyed registers; eax, ecx, edx, ebp;;***************************************************************************e3c59x_check_tx_status: movzx ebp, word [io_addr] ; to be implemented in ETHERNET.INC; clear TxStatus queue lea edx, [ebp+E3C59X_REG_TX_STATUS] mov cl, 31 ; max number of queue entries.tx_status_loop: in al, dx test al, al jz .finish ; no error test al, 0x3f jnz .finish ; error.no_error_found:; clear current TxStatus entry which advances the next one xor al, al out
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -