diff --git a/kernel/branches/net/drivers/3c59x.asm b/kernel/branches/net/drivers/3c59x.asm index 8303381d9..7f87a7963 100644 --- a/kernel/branches/net/drivers/3c59x.asm +++ b/kernel/branches/net/drivers/3c59x.asm @@ -82,16 +82,16 @@ format MS COFF - API_VERSION equ 0x01000100 - DRIVER_VERSION equ 5 + API_VERSION equ 0x01000100 + DRIVER_VERSION equ 5 - MAX_DEVICES equ 16 - FORCE_FD equ 0 ; forcing full duplex mode makes sense at some cards and link types - PROMISCIOUS equ 0 ; enables promiscous mode + MAX_DEVICES equ 16 + FORCE_FD equ 0 ; forcing full duplex mode makes sense at some cards and link types + PROMISCIOUS equ 0 ; enables promiscous mode - DEBUG equ 1 - __DEBUG__ equ 1 - __DEBUG_LEVEL__ equ 1 + DEBUG equ 1 + __DEBUG__ equ 1 + __DEBUG_LEVEL__ equ 1 include 'proc32.inc' include 'imports.inc' @@ -102,14 +102,14 @@ public START public service_proc public version -struc DPD { ; Download Packet Descriptor +struc DPD { ; Download Packet Descriptor - .next_ptr dd ? - .frame_start_hdr dd ? - .frag_addr dd ? ; for packet data - .frag_len dd ? ; for packet data - .realaddr dd ? - .size = 32 + .next_ptr dd ? + .frame_start_hdr dd ? + .frag_addr dd ? ; for packet data + .frag_len dd ? ; for packet data + .realaddr dd ? + .size = 32 } virtual at 0 @@ -117,14 +117,14 @@ virtual at 0 end virtual -struc UPD { ; Upload Packet Descriptor +struc UPD { ; Upload Packet Descriptor - .next_ptr dd ? - .pkt_status dd ? - .frag_addr dd ? - .frag_len dd ? ; for packet data - .realaddr dd ? - .size = 32 + .next_ptr dd ? + .pkt_status dd ? + .frag_addr dd ? + .frag_len dd ? ; for packet data + .realaddr dd ? + .size = 32 } @@ -133,232 +133,232 @@ virtual at 0 end virtual ; Ethernet frame symbols - ETH_ALEN equ 6 - ETH_HLEN equ (2*ETH_ALEN+2) - ETH_ZLEN equ 60 ; 60 + 4bytes auto payload for - ; mininmum 64bytes frame length + ETH_ALEN equ 6 + ETH_HLEN equ (2*ETH_ALEN+2) + ETH_ZLEN equ 60 ; 60 + 4bytes auto payload for + ; mininmum 64bytes frame length ; Registers - REG_POWER_MGMT_CTRL equ 0x7c - REG_UP_LIST_PTR equ 0x38 - REG_UP_PKT_STATUS equ 0x30 - REG_TX_FREE_THRESH equ 0x2f - REG_DN_LIST_PTR equ 0x24 - REG_DMA_CTRL equ 0x20 - REG_TX_STATUS equ 0x1b - REG_RX_STATUS equ 0x18 - REG_TX_DATA equ 0x10 + REG_POWER_MGMT_CTRL equ 0x7c + REG_UP_LIST_PTR equ 0x38 + REG_UP_PKT_STATUS equ 0x30 + REG_TX_FREE_THRESH equ 0x2f + REG_DN_LIST_PTR equ 0x24 + REG_DMA_CTRL equ 0x20 + REG_TX_STATUS equ 0x1b + REG_RX_STATUS equ 0x18 + REG_TX_DATA equ 0x10 ; Common window registers - REG_INT_STATUS equ 0xe - REG_COMMAND equ 0xe + REG_INT_STATUS equ 0xe + REG_COMMAND equ 0xe ; Register window 7 - REG_MASTER_STATUS equ 0xc - REG_POWER_MGMT_EVENT equ 0xc - REG_MASTER_LEN equ 0x6 - REG_VLAN_ETHER_TYPE equ 0x4 - REG_VLAN_MASK equ 0x0 - REG_MASTER_ADDRESS equ 0x0 + REG_MASTER_STATUS equ 0xc + REG_POWER_MGMT_EVENT equ 0xc + REG_MASTER_LEN equ 0x6 + REG_VLAN_ETHER_TYPE equ 0x4 + REG_VLAN_MASK equ 0x0 + REG_MASTER_ADDRESS equ 0x0 ; Register window 6 - REG_BYTES_XMITTED_OK equ 0xc - REG_BYTES_RCVD_OK equ 0xa - REG_UPPER_FRAMES_OK equ 0x9 - REG_FRAMES_DEFERRED equ 0x8 - REG_FRAMES_RCVD_OK equ 0x7 - REG_FRAMES_XMITTED_OK equ 0x6 - REG_RX_OVERRUNS equ 0x5 - REG_LATE_COLLISIONS equ 0x4 - REG_SINGLE_COLLISIONS equ 0x3 - REG_MULTIPLE_COLLISIONS equ 0x2 - REG_SQE_ERRORS equ 0x1 - REG_CARRIER_LOST equ 0x0 + REG_BYTES_XMITTED_OK equ 0xc + REG_BYTES_RCVD_OK equ 0xa + REG_UPPER_FRAMES_OK equ 0x9 + REG_FRAMES_DEFERRED equ 0x8 + REG_FRAMES_RCVD_OK equ 0x7 + REG_FRAMES_XMITTED_OK equ 0x6 + REG_RX_OVERRUNS equ 0x5 + REG_LATE_COLLISIONS equ 0x4 + REG_SINGLE_COLLISIONS equ 0x3 + REG_MULTIPLE_COLLISIONS equ 0x2 + REG_SQE_ERRORS equ 0x1 + REG_CARRIER_LOST equ 0x0 ; Register window 5 - REG_INDICATION_ENABLE equ 0xc - REG_INTERRUPT_ENABLE equ 0xa - REG_TX_RECLAIM_THRESH equ 0x9 - REG_RX_FILTER equ 0x8 - REG_RX_EARLY_THRESH equ 0x6 - REG_TX_START_THRESH equ 0x0 + REG_INDICATION_ENABLE equ 0xc + REG_INTERRUPT_ENABLE equ 0xa + REG_TX_RECLAIM_THRESH equ 0x9 + REG_RX_FILTER equ 0x8 + REG_RX_EARLY_THRESH equ 0x6 + REG_TX_START_THRESH equ 0x0 ; Register window 4 - REG_UPPER_BYTES_OK equ 0xe - REG_BAD_SSD equ 0xc - REG_MEDIA_STATUS equ 0xa - REG_PHYSICAL_MGMT equ 0x8 - REG_NETWORK_DIAGNOSTIC equ 0x6 - REG_FIFO_DIAGNOSTIC equ 0x4 - REG_VCO_DIAGNOSTIC equ 0x2 ; may not supported + REG_UPPER_BYTES_OK equ 0xe + REG_BAD_SSD equ 0xc + REG_MEDIA_STATUS equ 0xa + REG_PHYSICAL_MGMT equ 0x8 + REG_NETWORK_DIAGNOSTIC equ 0x6 + REG_FIFO_DIAGNOSTIC equ 0x4 + REG_VCO_DIAGNOSTIC equ 0x2 ; may not supported ; Bits in register window 4 - BIT_AUTOSELECT equ 24 + BIT_AUTOSELECT equ 24 ; Register window 3 - REG_TX_FREE equ 0xc - REG_RX_FREE equ 0xa - REG_MEDIA_OPTIONS equ 0x8 - REG_MAC_CONTROL equ 0x6 - REG_MAX_PKT_SIZE equ 0x4 - REG_INTERNAL_CONFIG equ 0x0 + REG_TX_FREE equ 0xc + REG_RX_FREE equ 0xa + REG_MEDIA_OPTIONS equ 0x8 + REG_MAC_CONTROL equ 0x6 + REG_MAX_PKT_SIZE equ 0x4 + REG_INTERNAL_CONFIG equ 0x0 ; Register window 2 - REG_RESET_OPTIONS equ 0xc - REG_STATION_MASK_HI equ 0xa - REG_STATION_MASK_MID equ 0x8 - REG_STATION_MASK_LO equ 0x6 - REG_STATION_ADDRESS_HI equ 0x4 - REG_STATION_ADDRESS_MID equ 0x2 - REG_STATION_ADDRESS_LO equ 0x0 + REG_RESET_OPTIONS equ 0xc + REG_STATION_MASK_HI equ 0xa + REG_STATION_MASK_MID equ 0x8 + REG_STATION_MASK_LO equ 0x6 + REG_STATION_ADDRESS_HI equ 0x4 + REG_STATION_ADDRESS_MID equ 0x2 + REG_STATION_ADDRESS_LO equ 0x0 ; Register window 1 - REG_TRIGGER_BITS equ 0xc - REG_SOS_BITS equ 0xa - REG_WAKE_ON_TIMER equ 0x8 - REG_SMB_RXBYTES equ 0x7 - REG_SMB_DIAG equ 0x5 - REG_SMB_ARB equ 0x4 - REG_SMB_STATUS equ 0x2 - REG_SMB_ADDRESS equ 0x1 - REG_SMB_FIFO_DATA equ 0x0 + REG_TRIGGER_BITS equ 0xc + REG_SOS_BITS equ 0xa + REG_WAKE_ON_TIMER equ 0x8 + REG_SMB_RXBYTES equ 0x7 + REG_SMB_DIAG equ 0x5 + REG_SMB_ARB equ 0x4 + REG_SMB_STATUS equ 0x2 + REG_SMB_ADDRESS equ 0x1 + REG_SMB_FIFO_DATA equ 0x0 ; Register window 0 - REG_EEPROM_DATA equ 0xc - REG_EEPROM_COMMAND equ 0xa - REG_BIOS_ROM_DATA equ 0x8 - REG_BIOS_ROM_ADDR equ 0x4 + REG_EEPROM_DATA equ 0xc + REG_EEPROM_COMMAND equ 0xa + REG_BIOS_ROM_DATA equ 0x8 + REG_BIOS_ROM_ADDR equ 0x4 ; Physical management bits - BIT_MGMT_DIR equ 2 ; drive with the data written in mgmtData - BIT_MGMT_DATA equ 1 ; MII management data bit - BIT_MGMT_CLK equ 0 ; MII management clock + BIT_MGMT_DIR equ 2 ; drive with the data written in mgmtData + BIT_MGMT_DATA equ 1 ; MII management data bit + BIT_MGMT_CLK equ 0 ; MII management clock ; MII commands - MII_CMD_MASK equ (1111b shl 10) - MII_CMD_READ equ (0110b shl 10) - MII_CMD_WRITE equ (0101b shl 10) + MII_CMD_MASK equ (1111b shl 10) + MII_CMD_READ equ (0110b shl 10) + MII_CMD_WRITE equ (0101b shl 10) ; MII registers - REG_MII_BMCR equ 0 ; basic mode control register - REG_MII_BMSR equ 1 ; basic mode status register - REG_MII_ANAR equ 4 ; auto negotiation advertisement register - REG_MII_ANLPAR equ 5 ; auto negotiation link partner ability register - REG_MII_ANER equ 6 ; auto negotiation expansion register + REG_MII_BMCR equ 0 ; basic mode control register + REG_MII_BMSR equ 1 ; basic mode status register + REG_MII_ANAR equ 4 ; auto negotiation advertisement register + REG_MII_ANLPAR equ 5 ; auto negotiation link partner ability register + REG_MII_ANER equ 6 ; auto negotiation expansion register ; MII bits - BIT_MII_AUTONEG_COMPLETE equ 5 ; auto-negotiation complete - BIT_MII_PREAMBLE_SUPPRESSION equ 6 + BIT_MII_AUTONEG_COMPLETE equ 5 ; auto-negotiation complete + BIT_MII_PREAMBLE_SUPPRESSION equ 6 ; eeprom bits and commands - EEPROM_CMD_READ equ 0x80 - EEPROM_BIT_BUSY equ 15 + EEPROM_CMD_READ equ 0x80 + EEPROM_BIT_BUSY equ 15 ; eeprom registers - EEPROM_REG_OEM_NODE_ADDR equ 0xa - EEPROM_REG_CAPABILITIES equ 0x10 + EEPROM_REG_OEM_NODE_ADDR equ 0xa + EEPROM_REG_CAPABILITIES equ 0x10 ; Commands for command register - SELECT_REGISTER_WINDOW equ (1 shl 11) + SELECT_REGISTER_WINDOW equ (1 shl 11) - IS_VORTEX equ 0x1 - IS_BOOMERANG equ 0x2 - IS_CYCLONE equ 0x4 - IS_TORNADO equ 0x8 - EEPROM_8BIT equ 0x10 - HAS_PWR_CTRL equ 0x20 - HAS_MII equ 0x40 - HAS_NWAY equ 0x80 - HAS_CB_FNS equ 0x100 - INVERT_MII_PWR equ 0x200 - INVERT_LED_PWR equ 0x400 - MAX_COLLISION_RESET equ 0x800 - EEPROM_OFFSET equ 0x1000 - HAS_HWCKSM equ 0x2000 - EXTRA_PREAMBLE equ 0x4000 + IS_VORTEX equ 0x1 + IS_BOOMERANG equ 0x2 + IS_CYCLONE equ 0x4 + IS_TORNADO equ 0x8 + EEPROM_8BIT equ 0x10 + HAS_PWR_CTRL equ 0x20 + HAS_MII equ 0x40 + HAS_NWAY equ 0x80 + HAS_CB_FNS equ 0x100 + INVERT_MII_PWR equ 0x200 + INVERT_LED_PWR equ 0x400 + MAX_COLLISION_RESET equ 0x800 + EEPROM_OFFSET equ 0x1000 + HAS_HWCKSM equ 0x2000 + EXTRA_PREAMBLE equ 0x4000 ; Status - IntLatch equ 0x0001 - HostError equ 0x0002 - TxComplete equ 0x0004 - TxAvailable equ 0x0008 - RxComplete equ 0x0010 - RxEarly equ 0x0020 - IntReq equ 0x0040 - StatsFull equ 0x0080 - DMADone equ 0x0100 - DownComplete equ 0x0200 - UpComplete equ 0x0400 - DMAInProgress equ 0x0800 ; 1 shl 11 (DMA controller is still busy) - CmdInProgress equ 0x1000 ; 1 shl 12 (EL3_CMD is still busy) + IntLatch equ 0x0001 + HostError equ 0x0002 + TxComplete equ 0x0004 + TxAvailable equ 0x0008 + RxComplete equ 0x0010 + RxEarly equ 0x0020 + IntReq equ 0x0040 + StatsFull equ 0x0080 + DMADone equ 0x0100 + DownComplete equ 0x0200 + UpComplete equ 0x0400 + DMAInProgress equ 0x0800 ; 1 shl 11 (DMA controller is still busy) + CmdInProgress equ 0x1000 ; 1 shl 12 (EL3_CMD is still busy) - S_5_INTS equ HostError + RxEarly + UpComplete + DownComplete ;+ TxComplete + RxComplete + TxAvailable + S_5_INTS equ HostError + RxEarly + UpComplete + DownComplete ;+ TxComplete + RxComplete + TxAvailable ; Commands - TotalReset equ 0 shl 11 - SelectWindow equ 1 shl 11 - StartCoax equ 2 shl 11 - RxDisable equ 3 shl 11 - RxEnable equ 4 shl 11 - RxReset equ 5 shl 11 - UpStall equ 6 shl 11 - UpUnstall equ (6 shl 11)+1 - DownStall equ (6 shl 11)+2 - DownUnstall equ (6 shl 11)+3 - RxDiscard equ 8 shl 11 - TxEnable equ 9 shl 11 - TxDisable equ 10 shl 11 - TxReset equ 11 shl 11 - FakeIntr equ 12 shl 11 - AckIntr equ 13 shl 11 - SetIntrEnb equ 14 shl 11 - SetStatusEnb equ 15 shl 11 - SetRxFilter equ 16 shl 11 - SetRxThreshold equ 17 shl 11 - SetTxThreshold equ 18 shl 11 - SetTxStart equ 19 shl 11 - StartDMAUp equ 20 shl 11 - StartDMADown equ (20 shl 11)+1 - StatsEnable equ 21 shl 11 - StatsDisable equ 22 shl 11 - StopCoax equ 23 shl 11 - SetFilterBit equ 25 shl 11 + TotalReset equ 0 shl 11 + SelectWindow equ 1 shl 11 + StartCoax equ 2 shl 11 + RxDisable equ 3 shl 11 + RxEnable equ 4 shl 11 + RxReset equ 5 shl 11 + UpStall equ 6 shl 11 + UpUnstall equ (6 shl 11)+1 + DownStall equ (6 shl 11)+2 + DownUnstall equ (6 shl 11)+3 + RxDiscard equ 8 shl 11 + TxEnable equ 9 shl 11 + TxDisable equ 10 shl 11 + TxReset equ 11 shl 11 + FakeIntr equ 12 shl 11 + AckIntr equ 13 shl 11 + SetIntrEnb equ 14 shl 11 + SetStatusEnb equ 15 shl 11 + SetRxFilter equ 16 shl 11 + SetRxThreshold equ 17 shl 11 + SetTxThreshold equ 18 shl 11 + SetTxStart equ 19 shl 11 + StartDMAUp equ 20 shl 11 + StartDMADown equ (20 shl 11)+1 + StatsEnable equ 21 shl 11 + StatsDisable equ 22 shl 11 + StopCoax equ 23 shl 11 + SetFilterBit equ 25 shl 11 ; Rx mode bits - RxStation equ 1 - RxMulticast equ 2 - RxBroadcast equ 4 - RxProm equ 8 + RxStation equ 1 + RxMulticast equ 2 + RxBroadcast equ 4 + RxProm equ 8 ; RX/TX buffers sizes - MAX_ETH_PKT_SIZE equ 1536 ; max packet size - NUM_RX_DESC equ 4 ; a power of 2 number - NUM_TX_DESC equ 4 ; a power of 2 number - MAX_ETH_FRAME_SIZE equ 1520 ; size of ethernet frame + bytes alignment + MAX_ETH_PKT_SIZE equ 1536 ; max packet size + NUM_RX_DESC equ 4 ; a power of 2 number + NUM_TX_DESC equ 4 ; a power of 2 number + MAX_ETH_FRAME_SIZE equ 1520 ; size of ethernet frame + bytes alignment virtual at ebx - device: + device: - ETH_DEVICE + ETH_DEVICE - .dpd_buffer rd (dpd.size*NUM_TX_DESC)/4 - .upd_buffer rd (upd.size*NUM_RX_DESC)/4 - .curr_upd dd ? - .prev_dpd dd ? + .dpd_buffer rd (dpd.size*NUM_TX_DESC)/4 + .upd_buffer rd (upd.size*NUM_RX_DESC)/4 + .curr_upd dd ? + .prev_dpd dd ? - .io_addr dd ? - .pci_bus db ? - .pci_dev db ? - .irq_line db ? + .io_addr dd ? + .pci_bus db ? + .pci_dev db ? + .irq_line db ? - .prev_tx_frame dd ? - .ver_id db ? - .full_bus_master db ? - .has_hwcksm db ? - .preamble db ? - .dn_list_ptr_cleared db ? + .prev_tx_frame dd ? + .ver_id db ? + .full_bus_master db ? + .has_hwcksm db ? + .preamble db ? + .dn_list_ptr_cleared db ? - .size = $ - device + .size = $ - device end virtual @@ -374,19 +374,19 @@ section '.flat' code readable align 16 align 4 proc START stdcall, state:dword - cmp [state], 1 - jne .exit + cmp [state], 1 + jne .exit .entry: - DEBUGF 1,"Loading 3com network driver\n" - stdcall RegService, my_service, service_proc - ret + DEBUGF 1,"Loading 3com network driver\n" + stdcall RegService, my_service, service_proc + ret .fail: .exit: - xor eax, eax - ret + xor eax, eax + ret endp @@ -404,155 +404,155 @@ endp align 4 proc service_proc stdcall, ioctl:dword - mov edx, [ioctl] - mov eax, [IOCTL.io_code] + mov edx, [ioctl] + mov eax, [IOCTL.io_code] ;------------------------------------------------------ - cmp eax, 0 ;SRV_GETVERSION - jne @F + cmp eax, 0 ;SRV_GETVERSION + jne @F - cmp [IOCTL.out_size], 4 - jl .fail - mov eax, [IOCTL.output] - mov [eax], dword API_VERSION + cmp [IOCTL.out_size], 4 + jl .fail + mov eax, [IOCTL.output] + mov [eax], dword API_VERSION - xor eax, eax - ret + xor eax, eax + ret ;------------------------------------------------------ @@: - cmp eax, 1 ;SRV_HOOK - jne .fail + cmp eax, 1 ;SRV_HOOK + jne .fail - cmp [IOCTL.inp_size], 3 ; Data input must be at least 3 bytes - jl .fail + cmp [IOCTL.inp_size], 3 ; Data input must be at least 3 bytes + jl .fail - mov eax, [IOCTL.input] - cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given - jne .fail ; other types of this hardware dont exist + mov eax, [IOCTL.input] + cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given + jne .fail ; other types of this hardware dont exist ; check if the device is already listed - mov ecx, [VORTEX_DEVICES] - test ecx, ecx - jz .maybeboomerang + mov ecx, [VORTEX_DEVICES] + test ecx, ecx + jz .maybeboomerang - mov esi, VORTEX_LIST - mov eax, [IOCTL.input] ; get the pci bus and device numbers - mov ax , [eax+1] ; + mov esi, VORTEX_LIST + mov eax, [IOCTL.input] ; get the pci bus and device numbers + mov ax , [eax+1] ; .nextdevice: - mov ebx, [esi] - cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) - je .find_devicenum ; Device is already loaded, let's find it's device number - add esi, 4 - loop .nextdevice + mov ebx, [esi] + cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) + je .find_devicenum ; Device is already loaded, let's find it's device number + add esi, 4 + loop .nextdevice .maybeboomerang: - mov ecx, [BOOMERANG_DEVICES] - test ecx, ecx - jz .firstdevice + mov ecx, [BOOMERANG_DEVICES] + test ecx, ecx + jz .firstdevice - mov esi, BOOMERANG_LIST - mov eax, [IOCTL.input] ; get the pci bus and device numbers - mov ax , [eax+1] ; + mov esi, BOOMERANG_LIST + mov eax, [IOCTL.input] ; get the pci bus and device numbers + mov ax , [eax+1] ; .nextdevice2: - mov ebx, [esi] - cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) - je .find_devicenum ; Device is already loaded, let's find it's device number - add esi, 4 - loop .nextdevice2 + mov ebx, [esi] + cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) + je .find_devicenum ; Device is already loaded, let's find it's device number + add esi, 4 + loop .nextdevice2 ; This device doesnt have its own eth_device structure yet, lets create one .firstdevice: - mov ecx, [BOOMERANG_DEVICES] - add ecx, [VORTEX_DEVICES] - cmp ecx, MAX_DEVICES ; First check if the driver can handle one more card - jge .fail + mov ecx, [BOOMERANG_DEVICES] + add ecx, [VORTEX_DEVICES] + cmp ecx, MAX_DEVICES ; First check if the driver can handle one more card + jge .fail - allocate_and_clear ebx, device.size, .fail ; Allocate the buffer for device structure + allocate_and_clear ebx, device.size, .fail ; Allocate the buffer for device structure ; Fill in the direct call addresses into the struct - mov [device.reset], reset - mov [device.transmit], null_op - mov [device.get_MAC], read_mac - mov [device.set_MAC], write_mac - mov [device.unload], null_op - mov [device.name], my_service + mov [device.reset], reset + mov [device.transmit], null_op + mov [device.get_MAC], read_mac + mov [device.set_MAC], write_mac + mov [device.unload], null_op + mov [device.name], my_service ; save the pci bus and device numbers - mov eax, [IOCTL.input] - mov cl , [eax+1] - mov [device.pci_bus], cl - mov cl , [eax+2] - mov [device.pci_dev], cl + mov eax, [IOCTL.input] + mov cl , [eax+1] + mov [device.pci_bus], cl + mov cl , [eax+2] + mov [device.pci_dev], cl ; Now, it's time to find the base io addres of the PCI device - find_io [device.pci_bus], [device.pci_dev], [device.io_addr] + find_io [device.pci_bus], [device.pci_dev], [device.io_addr] ; We've found the io address, find IRQ now - find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] + find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] - DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ - [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 + DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ + [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 ; Ok, the eth_device structure is ready, let's probe the device - call probe ; this function will output in eax - test eax, eax - jnz .err ; If an error occured, exit + call probe ; this function will output in eax + test eax, eax + jnz .err ; If an error occured, exit - movzx ecx, [device.ver_id] - test word [hw_versions+2+ecx*4], IS_VORTEX - jz .not_vortex + movzx ecx, [device.ver_id] + test word [hw_versions+2+ecx*4], IS_VORTEX + jz .not_vortex - mov eax, [VORTEX_DEVICES] ; Add the device structure to our device list - mov [VORTEX_LIST+4*eax], ebx ; (IRQ handler uses this list to find device) - inc [VORTEX_DEVICES] ; + mov eax, [VORTEX_DEVICES] ; Add the device structure to our device list + mov [VORTEX_LIST+4*eax], ebx ; (IRQ handler uses this list to find device) + inc [VORTEX_DEVICES] ; .register: - mov [device.type], NET_TYPE_ETH - call NetRegDev + mov [device.type], NET_TYPE_ETH + call NetRegDev - cmp eax, -1 - je .destroy + cmp eax, -1 + je .destroy - call start_device - ret + call start_device + ret .not_vortex: - mov eax, [BOOMERANG_DEVICES] ; Add the device structure to our device list - mov [BOOMERANG_LIST+4*eax], ebx ; (IRQ handler uses this list to find device) - inc [BOOMERANG_DEVICES] + mov eax, [BOOMERANG_DEVICES] ; Add the device structure to our device list + mov [BOOMERANG_LIST+4*eax], ebx ; (IRQ handler uses this list to find device) + inc [BOOMERANG_DEVICES] - jmp .register + jmp .register ; If the device was already loaded, find the device number and return it in eax .find_devicenum: - DEBUGF 1,"Trying to find device number of already registered device\n" - call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx - ; into a device number in edi - mov eax, edi ; Application wants it in eax instead - DEBUGF 1,"Kernel says: %u\n", eax - ret + DEBUGF 1,"Trying to find device number of already registered device\n" + call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx + ; into a device number in edi + mov eax, edi ; Application wants it in eax instead + DEBUGF 1,"Kernel says: %u\n", eax + ret ; If an error occured, remove all allocated data and exit (returning -1 in eax) .destroy: - ; todo: reset device into virgin state + ; todo: reset device into virgin state .err: - stdcall KernelFree, ebx + stdcall KernelFree, ebx .fail: - or eax, -1 - ret + or eax, -1 + ret ;------------------------------------------------------ endp @@ -581,100 +581,100 @@ endp align 4 probe: - DEBUGF 1,"Probing 3com card\n" + DEBUGF 1,"Probing 3com card\n" - make_bus_master [device.pci_bus], [device.pci_dev] + make_bus_master [device.pci_bus], [device.pci_dev] ; wake up the card - call wake_up + call wake_up - movzx ecx, [device.pci_bus] - movzx edx, [device.pci_dev] - stdcall PciRead32, ecx ,edx ,0 ; get device/vendor id + movzx ecx, [device.pci_bus] + movzx edx, [device.pci_dev] + stdcall PciRead32, ecx ,edx ,0 ; get device/vendor id - DEBUGF 1,"Vendor id: 0x%x\n", ax + DEBUGF 1,"Vendor id: 0x%x\n", ax - cmp ax , 0x10B7 - jne .notfound - shr eax, 16 + cmp ax , 0x10B7 + jne .notfound + shr eax, 16 - DEBUGF 1,"Vendor ok!, device id: 0x%x\n", ax + DEBUGF 1,"Vendor ok!, device id: 0x%x\n", ax ; get chip version - mov ecx, HW_VERSIONS_SIZE/4-1 + mov ecx, HW_VERSIONS_SIZE/4-1 .loop: - cmp ax , [hw_versions+ecx*4] - jz .found - loop .loop - DEBUGF 1,"ecx: %u\n", ecx + cmp ax , [hw_versions+ecx*4] + jz .found + loop .loop + DEBUGF 1,"ecx: %u\n", ecx .notfound: - DEBUGF 1,"Device id not found in list!\n" - or eax, -1 - ret + DEBUGF 1,"Device id not found in list!\n" + or eax, -1 + ret .found: - mov esi, [hw_str+ecx*4] - DEBUGF 1,"Hardware type: %s\n", esi - mov [device.name], esi + mov esi, [hw_str+ecx*4] + DEBUGF 1,"Hardware type: %s\n", esi + mov [device.name], esi - mov [device.ver_id], cl - test word [hw_versions+2+ecx*4], HAS_HWCKSM - setnz [device.has_hwcksm] + mov [device.ver_id], cl + test word [hw_versions+2+ecx*4], HAS_HWCKSM + setnz [device.has_hwcksm] ; set pci latency for vortex cards - test word [hw_versions+2+ecx*4], IS_VORTEX - jz .not_vortex + test word [hw_versions+2+ecx*4], IS_VORTEX + jz .not_vortex - mov eax, 11111000b ; 248 = max latency - movzx ecx, [device.pci_bus] - movzx edx, [device.pci_dev] - stdcall PciWrite32, ecx, edx, PCI_REG_LATENCY, eax + mov eax, 11111000b ; 248 = max latency + movzx ecx, [device.pci_bus] + movzx edx, [device.pci_dev] + stdcall PciWrite32, ecx, edx, PCI_REG_LATENCY, eax .not_vortex: ; set RX/TX functions - mov ax, EEPROM_REG_CAPABILITIES - call read_eeprom - test al, 100000b ; full bus master? - setnz [device.full_bus_master] - jnz .boomerang_func - mov [device.transmit], vortex_transmit - DEBUGF 1,"Device is a vortex type\n" - DEBUGF 1,"I'm sorry but vortex code hasnt been tested yet\n" - DEBUGF 1,"Please contact me on hidnplayr@kolibrios.org\n" - DEBUGF 1,"If you can help me finish it!\n" - or eax, -1 - ret - jmp @f + mov ax, EEPROM_REG_CAPABILITIES + call read_eeprom + test al, 100000b ; full bus master? + setnz [device.full_bus_master] + jnz .boomerang_func + mov [device.transmit], vortex_transmit + DEBUGF 1,"Device is a vortex type\n" + DEBUGF 1,"I'm sorry but vortex code hasnt been tested yet\n" + DEBUGF 1,"Please contact me on hidnplayr@kolibrios.org\n" + DEBUGF 1,"If you can help me finish it!\n" + or eax, -1 + ret + jmp @f .boomerang_func: ; full bus master, so use boomerang functions - mov [device.transmit], boomerang_transmit - DEBUGF 1,"Device is a boomerang type\n" + mov [device.transmit], boomerang_transmit + DEBUGF 1,"Device is a boomerang type\n" @@: - call read_mac_eeprom + call read_mac_eeprom - test byte [device.full_bus_master], 0xff - jz .set_preamble + test byte [device.full_bus_master], 0xff + jz .set_preamble ; switch to register window 2 - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+2 - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+2 + out dx, ax ; activate xcvr by setting some magic bits - set_io REG_RESET_OPTIONS - in ax, dx - and ax, not 0x4010 - movzx ecx, [device.ver_id] - test word [ecx*4+hw_versions+2], INVERT_LED_PWR - jz @f - or al, 0x10 + set_io REG_RESET_OPTIONS + in ax, dx + and ax, not 0x4010 + movzx ecx, [device.ver_id] + test word [ecx*4+hw_versions+2], INVERT_LED_PWR + jz @f + or al, 0x10 @@: - test word [ecx*4+hw_versions+2], INVERT_MII_PWR - jz @f - or ah, 0x40 + test word [ecx*4+hw_versions+2], INVERT_MII_PWR + jz @f + or ah, 0x40 @@: - out dx, ax + out dx, ax .set_preamble: ; use preamble as default - mov byte [device.preamble], 1 ; enable preamble + mov byte [device.preamble], 1 ; enable preamble - call global_reset + call global_reset ;-------------------------- ; RESET @@ -682,119 +682,119 @@ probe: align 4 reset: - movzx eax, [device.irq_line] - DEBUGF 1,"Attaching int handler to irq %x\n",eax:1 + movzx eax, [device.irq_line] + DEBUGF 1,"Attaching int handler to irq %x\n",eax:1 - movzx ecx, [device.ver_id] - test word [hw_versions+2+ecx*4], IS_VORTEX - jz .not_vortex + movzx ecx, [device.ver_id] + test word [hw_versions+2+ecx*4], IS_VORTEX + jz .not_vortex - mov esi, int_vortex - jmp .reg_int + mov esi, int_vortex + jmp .reg_int .not_vortex: - mov esi, int_boomerang + mov esi, int_boomerang .reg_int: - stdcall AttachIntHandler, eax, esi, dword 0 - test eax, eax - jnz @f - DEBUGF 1,"\nCould not attach int handler!\n" + stdcall AttachIntHandler, eax, esi, dword 0 + test eax, eax + jnz @f + DEBUGF 1,"\nCould not attach int handler!\n" ; or eax, -1 ; ret @@: - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW + 0 - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW + 0 + out dx, ax - mov ax, StopCoax - out dx, ax ; stop transceiver + mov ax, StopCoax + out dx, ax ; stop transceiver - mov ax, SELECT_REGISTER_WINDOW + 4 - out dx, ax ; disable UTP + mov ax, SELECT_REGISTER_WINDOW + 4 + out dx, ax ; disable UTP - set_io REG_MEDIA_STATUS - mov ax, 0x0 + set_io REG_MEDIA_STATUS + mov ax, 0x0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW + 0 - out dx, ax + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW + 0 + out dx, ax - set_io REG_FIFO_DIAGNOSTIC - mov ax, 0 - out dx, ax ; disable card + set_io REG_FIFO_DIAGNOSTIC + mov ax, 0 + out dx, ax ; disable card - mov ax, 1 - out dx, ax ; enable card + mov ax, 1 + out dx, ax ; enable card - call write_mac + call write_mac ;<<<<<<<<<<<<<< - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW + 1 - out dx, ax + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW + 1 + out dx, ax - mov ecx, 32 - set_io 0x0b + mov ecx, 32 + set_io 0x0b .loop: - in al, dx - loop .loop + in al, dx + loop .loop ; Get rid of stary ints - set_io REG_COMMAND - mov ax, AckIntr + 0xff - out dx, ax + set_io REG_COMMAND + mov ax, AckIntr + 0xff + out dx, ax - mov ax, SetStatusEnb + S_5_INTS - out dx, ax + mov ax, SetStatusEnb + S_5_INTS + out dx, ax - mov ax, SetIntrEnb + S_5_INTS - out dx, ax + mov ax, SetIntrEnb + S_5_INTS + out dx, ax - call set_rx_mode - call set_active_port + call set_rx_mode + call set_active_port ;>>>>>>>>>> - call create_rx_ring - call rx_reset - call tx_reset + call create_rx_ring + call rx_reset + call tx_reset ;>>>>>>>>>>>>>>>>>> - set_io 0 - set_io REG_COMMAND - mov ax, RxEnable - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, RxEnable + out dx, ax - mov ax, TxEnable - out dx, ax + mov ax, TxEnable + out dx, ax - set_io REG_COMMAND - mov ax, SetRxThreshold + 208 - out dx, ax + set_io REG_COMMAND + mov ax, SetRxThreshold + 208 + out dx, ax - mov ax, SetTxThreshold + 60 ;16 ; recommended by the manual :) - out dx, ax + mov ax, SetTxThreshold + 60 ;16 ; recommended by the manual :) + out dx, ax - mov ax, SELECT_REGISTER_WINDOW + 1 - out dx, ax + mov ax, SELECT_REGISTER_WINDOW + 1 + out dx, ax - xor eax, eax + xor eax, eax ; clear packet/byte counters - lea edi, [device.bytes_tx] - mov ecx, 6 - rep stosd + lea edi, [device.bytes_tx] + mov ecx, 6 + rep stosd ; Set the mtu, kernel will be able to send now - mov [device.mtu], 1514 + mov [device.mtu], 1514 - ret + ret @@ -802,60 +802,60 @@ reset: align 4 start_device: - DEBUGF 1,"Starting the device\n" + DEBUGF 1,"Starting the device\n" - set_io 0 - set_io REG_COMMAND - mov ax, SetTxThreshold + 60 ;2047 ; recommended by the manual :) - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, SetTxThreshold + 60 ;2047 ; recommended by the manual :) + out dx, ax - call check_tx_status + call check_tx_status - set_io 0 - set_io REG_COMMAND + set_io 0 + set_io REG_COMMAND ; switch to register window 4 - mov ax, SELECT_REGISTER_WINDOW+4 - out dx, ax + mov ax, SELECT_REGISTER_WINDOW+4 + out dx, ax ; wait for linkDetect - set_io REG_MEDIA_STATUS - mov ecx, 20 ; wait for max 2s + set_io REG_MEDIA_STATUS + mov ecx, 20 ; wait for max 2s .link_detect_loop: - mov esi, 100 - call Sleep ; 100 ms - in ax, dx - test ah, 1000b ; linkDetect - jnz @f - loop .link_detect_loop - DEBUGF 1,"Link detect timed-out!\n" + mov esi, 100 + call Sleep ; 100 ms + in ax, dx + test ah, 1000b ; linkDetect + jnz @f + loop .link_detect_loop + DEBUGF 1,"Link detect timed-out!\n" @@: ; print link type - xor eax, eax - bsr ax, word [device.mode] - jz @f - sub ax, 4 + xor eax, eax + bsr ax, word [device.mode] + jz @f + sub ax, 4 @@: - mov esi, [link_str+eax*4] - DEBUGF 1,"Established Link type: %s\n", esi + mov esi, [link_str+eax*4] + DEBUGF 1,"Established Link type: %s\n", esi ; enable interrupts - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW + 1 - out dx, ax + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW + 1 + out dx, ax - mov ax, AckIntr + 0xff - out dx, ax + mov ax, AckIntr + 0xff + out dx, ax - mov ax, SetStatusEnb + S_5_INTS - out dx, ax + mov ax, SetStatusEnb + S_5_INTS + out dx, ax - mov ax, SetIntrEnb + S_5_INTS - out dx, ax + mov ax, SetIntrEnb + S_5_INTS + out dx, ax - ret + ret @@ -866,21 +866,21 @@ start_device: align 4 set_rx_mode: - DEBUGF 1,"Setting RX mode\n" + DEBUGF 1,"Setting RX mode\n" - set_io 0 - set_io REG_COMMAND + set_io 0 + set_io REG_COMMAND -if defined PROMISCIOUS - mov ax, SetRxFilter + RxStation + RxMulticast + RxBroadcast + RxProm +if defined PROMISCIOUS + mov ax, SetRxFilter + RxStation + RxMulticast + RxBroadcast + RxProm else if defined ALLMULTI - mov ax, SetRxFilter + RxStation + RxMulticast + RxBroadcast + mov ax, SetRxFilter + RxStation + RxMulticast + RxBroadcast else - mov ax, SetRxFilter + RxStation + RxBroadcast + mov ax, SetRxFilter + RxStation + RxBroadcast end if - out dx, ax + out dx, ax - ret + ret @@ -902,29 +902,29 @@ end if align 4 global_reset: - DEBUGF 1,"Global reset..\n" + DEBUGF 1,"Global reset..\n" ; GlobalReset - set_io 0 - set_io REG_COMMAND - xor eax, eax + set_io 0 + set_io REG_COMMAND + xor eax, eax ; or al, 0x14 - out dx, ax + out dx, ax ; wait for GlobalReset to complete - mov ecx, 64000 + mov ecx, 64000 .loop: - in ax , dx - test ah , 10000b ; check CmdInProgress - loopz .loop + in ax , dx + test ah , 10000b ; check CmdInProgress + loopz .loop - DEBUGF 1,"Waiting for nic to boot..\n" + DEBUGF 1,"Waiting for nic to boot..\n" ; wait for 2 seconds for NIC to boot - mov esi, 2000 - call Sleep ; 2 seconds + mov esi, 2000 + call Sleep ; 2 seconds - DEBUGF 1,"Ok!\n" + DEBUGF 1,"Ok!\n" - ret + ret @@ -938,28 +938,28 @@ global_reset: align 4 tx_reset: - DEBUGF 1,"tx reset\n" + DEBUGF 1,"tx reset\n" ; TxReset - set_io 0 - set_io REG_COMMAND - mov ax, TxReset - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, TxReset + out dx, ax ; Wait for TxReset to complete - mov ecx, 200000 + mov ecx, 200000 .tx_reset_loop: - in ax, dx - test ah, 10000b ; check CmdInProgress - jz .tx_set_prev - dec ecx - jnz .tx_reset_loop + in ax, dx + test ah, 10000b ; check CmdInProgress + jz .tx_set_prev + dec ecx + jnz .tx_reset_loop .tx_set_prev: ; init last_dpd - lea eax, [device.dpd_buffer + (NUM_TX_DESC-1)*dpd.size] - mov [device.prev_dpd], eax + lea eax, [device.dpd_buffer + (NUM_TX_DESC-1)*dpd.size] + mov [device.prev_dpd], eax .tx_enable: - ret + ret @@ -974,68 +974,68 @@ tx_reset: align 4 rx_reset: - DEBUGF 1,"rx reset\n" + DEBUGF 1,"rx reset\n" - set_io 0 - set_io REG_COMMAND - mov ax, RxReset or 0x4 - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, RxReset or 0x4 + out dx, ax ; wait for RxReset to complete - mov ecx, 200000 + mov ecx, 200000 .loop: - in ax, dx - test ah, 10000b ; check CmdInProgress - jz .done - dec ecx - jnz .loop + in ax, dx + test ah, 10000b ; check CmdInProgress + jz .done + dec ecx + jnz .loop .done: - lea eax, [device.upd_buffer] - mov [device.curr_upd], eax - GetRealAddr - set_io 0 - set_io REG_UP_LIST_PTR - out dx, eax + lea eax, [device.upd_buffer] + mov [device.curr_upd], eax + GetRealAddr + set_io 0 + set_io REG_UP_LIST_PTR + out dx, eax .rx_enable: - ret + ret align 4 create_rx_ring: ; create upd ring - lea eax, [device.upd_buffer] - GetRealAddr - mov edi, eax ; real addr of first descr + lea eax, [device.upd_buffer] + GetRealAddr + mov edi, eax ; real addr of first descr - lea esi, [device.upd_buffer] ; ptr to first descr - lea edx, [device.upd_buffer + (NUM_RX_DESC-1)*upd.size] ; ptr to last descr + lea esi, [device.upd_buffer] ; ptr to first descr + lea edx, [device.upd_buffer + (NUM_RX_DESC-1)*upd.size] ; ptr to last descr - mov ecx, NUM_RX_DESC + mov ecx, NUM_RX_DESC .upd_loop: - mov [edx + upd.next_ptr], edi + mov [edx + upd.next_ptr], edi - push ecx edx - stdcall KernelAlloc, MAX_ETH_FRAME_SIZE - pop edx ecx - mov [esi + upd.realaddr], eax - call GetPgAddr - mov [esi + upd.frag_addr], eax - and [esi + upd.pkt_status], 0 - mov [esi + upd.frag_len], MAX_ETH_FRAME_SIZE or (1 shl 31) + push ecx edx + stdcall KernelAlloc, MAX_ETH_FRAME_SIZE + pop edx ecx + mov [esi + upd.realaddr], eax + call GetPgAddr + mov [esi + upd.frag_addr], eax + and [esi + upd.pkt_status], 0 + mov [esi + upd.frag_len], MAX_ETH_FRAME_SIZE or (1 shl 31) - DEBUGF 1,"UPD: lin=%x phys=%x len=%x next ptr=%x\n", [esi+upd.realaddr]:8, [esi+upd.frag_addr]:8, [esi+upd.frag_len]:8, edi - DEBUGF 1,"UPD: cur=%x prev=%x\n", esi, edx + DEBUGF 1,"UPD: lin=%x phys=%x len=%x next ptr=%x\n", [esi+upd.realaddr]:8, [esi+upd.frag_addr]:8, [esi+upd.frag_len]:8, edi + DEBUGF 1,"UPD: cur=%x prev=%x\n", esi, edx - mov edx, esi - add esi, upd.size - add edi, upd.size - dec ecx - jnz .upd_loop + mov edx, esi + add esi, upd.size + add edi, upd.size + dec ecx + jnz .upd_loop - ret + ret @@ -1057,66 +1057,66 @@ create_rx_ring: align 4 try_link_detect: - DEBUGF 1,"trying to detect link\n" + DEBUGF 1,"trying to detect link\n" ; create self-directed packet - stdcall KernelAlloc, 20 ; create a buffer for the self-directed packet - test eax, eax - jz .fail + stdcall KernelAlloc, 20 ; create a buffer for the self-directed packet + test eax, eax + jz .fail - pushd 20 ; Packet parameters for device.transmit - push eax ; + pushd 20 ; Packet parameters for device.transmit + push eax ; - mov edi, eax + mov edi, eax - lea esi, [device.mac] - movsw - movsd - sub esi, 6 - movsw - movsd - mov ax , 0x0608 - stosw + lea esi, [device.mac] + movsw + movsd + sub esi, 6 + movsw + movsd + mov ax , 0x0608 + stosw ; download self-directed packet - call [device.transmit] + call [device.transmit] ; switch to register window 4 - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+4 - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+4 + out dx, ax ; See if we have received the packet by now.. - cmp [device.packets_rx], 0 - jnz .link_detected + cmp [device.packets_rx], 0 + jnz .link_detected ; switch to register window 4 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+4 - out dx, ax + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+4 + out dx, ax ; read linkbeatdetect - set_io REG_MEDIA_STATUS - in ax, dx - test ah, 1000b ; test linkBeatDetect - jnz .link_detected - xor al, al - jmp .finish + set_io REG_MEDIA_STATUS + in ax, dx + test ah, 1000b ; test linkBeatDetect + jnz .link_detected + xor al, al + jmp .finish .link_detected: - DEBUGF 1,"link detected!\n" - setb al + DEBUGF 1,"link detected!\n" + setb al .finish: - test al, al - jz @f - or byte [device.mode+1], 100b + test al, al + jz @f + or byte [device.mode+1], 100b @@: - ret + ret .fail: - ret + ret @@ -1142,126 +1142,126 @@ try_link_detect: align 4 try_phy: - DEBUGF 1,"PHY=%u\n", ah - DEBUGF 1,"Detecting if device is auto-negotiation capable\n" + DEBUGF 1,"PHY=%u\n", ah + DEBUGF 1,"Detecting if device is auto-negotiation capable\n" - mov al, REG_MII_BMCR - push eax - call mdio_read ; returns with window #4 - or ah , 0x80 ; software reset - mov esi, eax - mov eax, dword [esp] - call mdio_write ; returns with window #4 + mov al, REG_MII_BMCR + push eax + call mdio_read ; returns with window #4 + or ah , 0x80 ; software reset + mov esi, eax + mov eax, dword [esp] + call mdio_write ; returns with window #4 ; wait for reset to complete - mov esi, 2000 - stdcall Sleep ; 2s - mov eax, [esp] - call mdio_read ; returns with window #4 - test ah , 0x80 - jnz .fail1 - mov eax, [esp] + mov esi, 2000 + stdcall Sleep ; 2s + mov eax, [esp] + call mdio_read ; returns with window #4 + test ah , 0x80 + jnz .fail1 + mov eax, [esp] ; wait for a while after reset - mov esi, 20 - stdcall Sleep ; 20ms - mov eax, [esp] - mov al , REG_MII_BMSR - call mdio_read ; returns with window #4 - test al , 1 ; extended capability supported? - jz .fail2 + mov esi, 20 + stdcall Sleep ; 20ms + mov eax, [esp] + mov al , REG_MII_BMSR + call mdio_read ; returns with window #4 + test al , 1 ; extended capability supported? + jz .fail2 ; auto-neg capable? - test al , 1000b - jz .fail2 ; not auto-negotiation capable + test al , 1000b + jz .fail2 ; not auto-negotiation capable - DEBUGF 1,"Device is auto-negotiation capable\n" + DEBUGF 1,"Device is auto-negotiation capable\n" ; auto-neg complete? - test al , 100000b - jnz .auto_neg_ok + test al , 100000b + jnz .auto_neg_ok - DEBUGF 1,"Restarting auto-negotiation\n" + DEBUGF 1,"Restarting auto-negotiation\n" ; restart auto-negotiation - mov eax, [esp] - mov al , REG_MII_ANAR - push eax - call mdio_read ; returns with window #4 - or ax , 1111b shl 5; advertise only 10base-T and 100base-TX - mov esi, eax - pop eax - call mdio_write ; returns with window #4 - mov eax, [esp] - call mdio_read ; returns with window #4 - mov esi, eax - or bh , 10010b ; restart auto-negotiation - mov eax, [esp] - call mdio_write ; returns with window #4 - mov esi, 4000 - stdcall Sleep ; 4 seconds - mov eax, [esp] - mov al , REG_MII_BMSR - call mdio_read ; returns with window #4 - test al , 100000b ; auto-neg complete? - jnz .auto_neg_ok - jmp .fail3 + mov eax, [esp] + mov al , REG_MII_ANAR + push eax + call mdio_read ; returns with window #4 + or ax , 1111b shl 5; advertise only 10base-T and 100base-TX + mov esi, eax + pop eax + call mdio_write ; returns with window #4 + mov eax, [esp] + call mdio_read ; returns with window #4 + mov esi, eax + or bh , 10010b ; restart auto-negotiation + mov eax, [esp] + call mdio_write ; returns with window #4 + mov esi, 4000 + stdcall Sleep ; 4 seconds + mov eax, [esp] + mov al , REG_MII_BMSR + call mdio_read ; returns with window #4 + test al , 100000b ; auto-neg complete? + jnz .auto_neg_ok + jmp .fail3 .auto_neg_ok: - DEBUGF 1,"Auto-negotiation complete\n" + DEBUGF 1,"Auto-negotiation complete\n" ; compare advertisement and link partner ability registers - mov eax, [esp] - mov al , REG_MII_ANAR - call mdio_read ; returns with window #4 - xchg eax, [esp] - mov al , REG_MII_ANLPAR - call mdio_read ; returns with window #4 - pop esi - and eax, esi - and eax, 1111100000b - push eax + mov eax, [esp] + mov al , REG_MII_ANAR + call mdio_read ; returns with window #4 + xchg eax, [esp] + mov al , REG_MII_ANLPAR + call mdio_read ; returns with window #4 + pop esi + and eax, esi + and eax, 1111100000b + push eax - mov word[device.mode+2], ax + mov word[device.mode+2], ax ; switch to register window 3 - set_io 0 - set_io REG_COMMAND - mov ax , SELECT_REGISTER_WINDOW+3 - out dx , ax + set_io 0 + set_io REG_COMMAND + mov ax , SELECT_REGISTER_WINDOW+3 + out dx , ax ; set full-duplex mode - set_io REG_MAC_CONTROL - in ax , dx - and ax , not 0x120 ; clear full duplex and flow control - pop esi - test esi, 1010b shl 5; check for full-duplex - jz .half_duplex - or ax , 0x120 ; set full duplex and flow control + set_io REG_MAC_CONTROL + in ax , dx + and ax , not 0x120 ; clear full duplex and flow control + pop esi + test esi, 1010b shl 5; check for full-duplex + jz .half_duplex + or ax , 0x120 ; set full duplex and flow control .half_duplex: - DEBUGF 1,"Using half-duplex\n" - out dx , ax - mov al , 1 - ret + DEBUGF 1,"Using half-duplex\n" + out dx , ax + mov al , 1 + ret .fail1: - DEBUGF 1,"reset failed!\n" - pop eax - xor al, al - ret + DEBUGF 1,"reset failed!\n" + pop eax + xor al, al + ret .fail2: - DEBUGF 1,"This device is not auto-negotiation capable!\n" - pop eax - xor al, al - ret + DEBUGF 1,"This device is not auto-negotiation capable!\n" + pop eax + xor al, al + ret .fail3: - DEBUGF 1,"auto-negotiation reset failed!\n" - pop eax - xor al, al - ret + DEBUGF 1,"auto-negotiation reset failed!\n" + pop eax + xor al, al + ret @@ -1286,102 +1286,102 @@ try_phy: align 4 try_mii: - DEBUGF 1,"trying to find MII PHY\n" + DEBUGF 1,"trying to find MII PHY\n" ; switch to register window 3 - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+3 - out dx, ax - set_io REG_INTERNAL_CONFIG - in eax, dx - and eax, (1111b shl 20) - cmp eax, (1000b shl 20) ; is auto-negotiation set? - jne .mii_device + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+3 + out dx, ax + set_io REG_INTERNAL_CONFIG + in eax, dx + and eax, (1111b shl 20) + cmp eax, (1000b shl 20) ; is auto-negotiation set? + jne .mii_device - DEBUGF 1,"auto-negotiation is set\n" + DEBUGF 1,"auto-negotiation is set\n" ; switch to register window 4 - set_io REG_COMMAND - mov ax , SELECT_REGISTER_WINDOW+4 - out dx , ax + set_io REG_COMMAND + mov ax , 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 try_phy - test al , al - jz .fail_finish + mov ah , 24 + call try_phy + test al , al + jz .fail_finish - mov cl , 24 - jmp .check_preamble + mov cl , 24 + jmp .check_preamble .mii_device: - cmp eax, (0110b shl 20) - jne .fail_finish + cmp eax, (0110b shl 20) + jne .fail_finish - set_io 0 - set_io REG_COMMAND - mov ax , SELECT_REGISTER_WINDOW+4 - out dx , ax + set_io 0 + set_io REG_COMMAND + mov ax , SELECT_REGISTER_WINDOW+4 + out dx , ax - set_io REG_PHYSICAL_MGMT - in ax , dx - and al , (1 shl BIT_MGMT_DIR) or (1 shl BIT_MGMT_DATA) - cmp al , (1 shl BIT_MGMT_DATA) - je .search_for_phy + set_io REG_PHYSICAL_MGMT + in ax , dx + and al , (1 shl BIT_MGMT_DIR) or (1 shl BIT_MGMT_DATA) + cmp al , (1 shl BIT_MGMT_DATA) + je .search_for_phy - xor al , al - ret + xor al , al + ret .search_for_phy: ; search for PHY - mov cx , 31 + mov cx , 31 .search_phy_loop: - DEBUGF 1,"Searching the PHY\n" - cmp cx , 24 - je .next_phy - mov ah , cl ; ah = phy - mov al , REG_MII_BMCR ; al = Basic Mode Status Register - push cx - call mdio_read - pop cx - test ax , ax - jz .next_phy - cmp ax , 0xffff - je .next_phy - mov ah , cl ; ah = phy - push cx - call try_phy - pop cx - test al , al - jnz .check_preamble + DEBUGF 1,"Searching the PHY\n" + cmp cx , 24 + je .next_phy + mov ah , cl ; ah = phy + mov al , REG_MII_BMCR ; al = Basic Mode Status Register + push cx + call mdio_read + pop cx + test ax , ax + jz .next_phy + cmp ax , 0xffff + je .next_phy + mov ah , cl ; ah = phy + push cx + call try_phy + pop cx + test al , al + jnz .check_preamble .next_phy: - loopw .search_phy_loop + loopw .search_phy_loop .fail_finish: - xor al, al - ret + xor al, al + ret ; epilog .check_preamble: - DEBUGF 1,"Using PHY: %u\nChecking PreAmble\n", cl - push eax ; eax contains the return value of try_phy + DEBUGF 1,"Using PHY: %u\nChecking PreAmble\n", cl + push eax ; eax contains the return value of try_phy ; check hard coded preamble forcing - movzx eax, [device.ver_id] - test word [eax*4+hw_versions+2], EXTRA_PREAMBLE - setnz [device.preamble] ; force preamble - jnz .finish + movzx eax, [device.ver_id] + test word [eax*4+hw_versions+2], EXTRA_PREAMBLE + setnz [device.preamble] ; force preamble + jnz .finish ; check mii for preamble suppression - mov ah, cl - mov al, REG_MII_BMSR - call mdio_read - test al, 1000000b ; preamble suppression? - setz [device.preamble] ; no + mov ah, cl + mov al, REG_MII_BMSR + call mdio_read + test al, 1000000b ; preamble suppression? + setz [device.preamble] ; no .finish: - pop eax - ret + pop eax + ret @@ -1398,83 +1398,83 @@ try_mii: align 4 test_packet: - DEBUGF 1,"sending test packet\n" + DEBUGF 1,"sending test packet\n" ; switch to register window 3 - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+3 - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+3 + out dx, ax ; set fullDuplexEnable in MacControl register - set_io REG_MAC_CONTROL - in ax, dx - or ax, 0x120 - out dx, ax + set_io REG_MAC_CONTROL + in ax, dx + or ax, 0x120 + out dx, ax ; switch to register window 5 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+5 - out dx, ax + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+5 + out dx, ax ; set RxFilter to enable individual address matches - mov ax, (10000b shl 11) - set_io REG_RX_FILTER - in al, dx - or al, 1 - set_io REG_COMMAND - out dx, ax + mov ax, (10000b shl 11) + set_io REG_RX_FILTER + in al, dx + or al, 1 + set_io REG_COMMAND + out dx, ax ; issue RxEnable and TxEnable - call rx_reset - call tx_reset + call rx_reset + call tx_reset ; create self-directed packet - stdcall KernelAlloc, 20 ; create a buffer for the self-directed packet - test eax, eax - jz .fail + stdcall KernelAlloc, 20 ; create a buffer for the self-directed packet + test eax, eax + jz .fail - pushd 20 ; Packet parameters for device.transmit - push eax ; + pushd 20 ; Packet parameters for device.transmit + push eax ; - mov edi, eax - lea esi, [device.mac] - movsw - movsd - sub esi, 6 - movsw - movsd - mov ax , 0x0608 - stosw + mov edi, eax + lea esi, [device.mac] + movsw + movsd + sub esi, 6 + movsw + movsd + mov ax , 0x0608 + stosw ; download self-directed packet - call [device.transmit] + call [device.transmit] ; wait for 2s - mov esi, 2000 - call Sleep + mov esi, 2000 + call Sleep ; check if self-directed packet is received - mov eax, [device.packets_rx] - test eax, eax - jnz .finish + mov eax, [device.packets_rx] + test eax, eax + jnz .finish ; switch to register window 3 - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+3 - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+3 + out dx, ax ; clear fullDuplexEnable in MacControl register - set_io REG_MAC_CONTROL - in ax , dx - and ax , not 0x120 - out dx , ax + set_io REG_MAC_CONTROL + in ax , dx + and ax , not 0x120 + out dx , ax .fail: - xor eax, eax + xor eax, eax .finish: - ret + ret @@ -1498,55 +1498,55 @@ test_packet: align 4 try_loopback: - DEBUGF 1,"trying loopback\n" + DEBUGF 1,"trying loopback\n" - push eax + push eax ; switch to register window 3 - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+3 - out dx, ax - mov eax, [esp] + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+3 + out dx, ax + mov eax, [esp] - mov cl, al - inc cl - shl cl, 3 - or byte [device.mode+1], cl + mov cl, al + inc cl + shl cl, 3 + or byte [device.mode+1], cl - test al, al ; aui or coax? - jz .complete_loopback + test al, al ; aui or coax? + jz .complete_loopback ; enable 100BASE-2 DC-DC converter - mov ax, (10b shl 11) ; EnableDcConverter - out dx, ax + mov ax, (10b shl 11) ; EnableDcConverter + out dx, ax .complete_loopback: - mov cx, 2 ; give a port 3 chances to complete a loopback + mov cx, 2 ; give a port 3 chances to complete a loopback .next_try: - push ecx - call test_packet - pop ecx - test eax, eax - loopzw .next_try + push ecx + call test_packet + pop ecx + test eax, eax + loopzw .next_try .finish: - xchg eax, [esp] - test al, al - jz .aui_finish + xchg eax, [esp] + test al, al + jz .aui_finish ; issue DisableDcConverter command - set_io 0 - set_io REG_COMMAND - mov ax, (10111b shl 11) - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, (10111b shl 11) + out dx, ax .aui_finish: - pop eax ; al contains the result of operation + pop eax ; al contains the result of operation - test al, al - jnz @f - and byte [device.mode+1], not 11000b + test al, al + jnz @f + and byte [device.mode+1], not 11000b @@: - ret + ret ;*************************************************************************** @@ -1563,118 +1563,118 @@ try_loopback: align 4 set_active_port: - DEBUGF 1,"Trying to find the active port\n" + DEBUGF 1,"Trying to find the active port\n" ; switch to register window 3 - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW + 3 - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW + 3 + out dx, ax - set_io REG_INTERNAL_CONFIG - in eax, dx - test eax, (1 shl 24) ; check if autoselect enable - jz .set_first_available_media + set_io 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 - set_io 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_io 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 - set_io REG_INTERNAL_CONFIG - in eax, dx - and eax, not (1111b shl 20) - or eax, (1000b shl 20) - out dx, eax - call try_mii - test al, al - jz .mii_device - DEBUGF 1,"Using auto negotiation\n" - ret + set_io REG_INTERNAL_CONFIG + in eax, dx + and eax, not (1111b shl 20) + or eax, (1000b shl 20) + out dx, eax + call try_mii + test al, al + jz .mii_device + DEBUGF 1,"Using auto negotiation\n" + ret .mii_device: ; switch to register window 3 - set_io 0 + set_io 0 ; check for off-chip mii device - set_io REG_MEDIA_OPTIONS - in ax, dx - test al, 1000000b ; check miiDevice - jz .base_fx - set_io REG_INTERNAL_CONFIG - in eax, dx - and eax, not (1111b shl 20) - or eax, (0110b shl 20) ; set MIIDevice - out dx, eax - call try_mii - test al, al - jz .base_fx - DEBUGF 1,"Using off-chip mii device\n" - ret + set_io REG_MEDIA_OPTIONS + in ax, dx + test al, 1000000b ; check miiDevice + jz .base_fx + set_io REG_INTERNAL_CONFIG + in eax, dx + and eax, not (1111b shl 20) + or eax, (0110b shl 20) ; set MIIDevice + out dx, eax + call try_mii + test al, al + jz .base_fx + DEBUGF 1,"Using off-chip mii device\n" + ret .base_fx: ; switch to register window 3 - set_io 0 + set_io 0 ; check for 100BASE-FX - set_io REG_MEDIA_OPTIONS - in ax, dx ; read media option register - test al, 100b ; check 100BASE-FX - jz .aui_enable - set_io REG_INTERNAL_CONFIG - in eax, dx - and eax, not (1111b shl 20) - or eax, (0101b shl 20) ; set 100base-FX - out dx, eax - call try_link_detect - test al, al - jz .aui_enable - DEBUGF 1,"Using 100Base-FX\n" - ret + set_io REG_MEDIA_OPTIONS + in ax, dx ; read media option register + test al, 100b ; check 100BASE-FX + jz .aui_enable + set_io REG_INTERNAL_CONFIG + in eax, dx + and eax, not (1111b shl 20) + or eax, (0101b shl 20) ; set 100base-FX + out dx, eax + call try_link_detect + test al, al + jz .aui_enable + DEBUGF 1,"Using 100Base-FX\n" + ret .aui_enable: ; switch to register window 3 - set_io 0 + set_io 0 ; check for 10Mbps AUI connector - set_io REG_MEDIA_OPTIONS - in ax, dx ; read media option register - test al, 100000b ; check 10Mbps AUI connector - jz .coax_available - set_io REG_INTERNAL_CONFIG - in eax, dx - and eax, not (1111b shl 20) - or eax, (0001b shl 20) ; set 10Mbps AUI connector - out dx, eax - xor al, al ; try 10Mbps AUI connector - call try_loopback - test al, al - jz .coax_available - DEBUGF 1,"Using 10Mbps aui\n" - ret + set_io REG_MEDIA_OPTIONS + in ax, dx ; read media option register + test al, 100000b ; check 10Mbps AUI connector + jz .coax_available + set_io REG_INTERNAL_CONFIG + in eax, dx + and eax, not (1111b shl 20) + or eax, (0001b shl 20) ; set 10Mbps AUI connector + out dx, eax + xor al, al ; try 10Mbps AUI connector + call try_loopback + test al, al + jz .coax_available + DEBUGF 1,"Using 10Mbps aui\n" + ret .coax_available: ; switch to register window 3 - set_io 0 + set_io 0 ; check for coaxial 10BASE-2 port - set_io REG_MEDIA_OPTIONS - in ax, dx ; read media option register - test al, 10000b ; check 10BASE-2 - jz .set_first_available_media + set_io REG_MEDIA_OPTIONS + in ax, dx ; read media option register + test al, 10000b ; check 10BASE-2 + jz .set_first_available_media - set_io REG_INTERNAL_CONFIG - in eax, dx - and eax, not (1111b shl 20) - or eax, (0011b shl 20) ; set 10BASE-2 - out dx, eax - mov al, 1 - call try_loopback - test al, al - jz .set_first_available_media - DEBUGF 1,"Using 10BASE-2 port\n" - ret + set_io REG_INTERNAL_CONFIG + in eax, dx + and eax, not (1111b shl 20) + or eax, (0011b shl 20) ; set 10BASE-2 + out dx, eax + mov al, 1 + call try_loopback + test al, al + jz .set_first_available_media + DEBUGF 1,"Using 10BASE-2 port\n" + ret .set_first_available_media: - DEBUGF 1,"Using the first available media\n" + DEBUGF 1,"Using the first available media\n" ;*************************************************************************** ; Function @@ -1694,103 +1694,103 @@ set_active_port: align 4 set_available_media: - DEBUGF 1,"Setting the available media\n" + DEBUGF 1,"Setting the available media\n" ; switch to register window 3 - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+3 - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+3 + out dx, ax - set_io REG_MEDIA_OPTIONS - in ax, dx - DEBUGF 1,"available media:%x\n", al - mov cl, al + set_io REG_MEDIA_OPTIONS + in ax, dx + DEBUGF 1,"available media:%x\n", al + mov cl, al - set_io REG_INTERNAL_CONFIG - in eax, dx - and eax, not (1111b shl 20) ; these bits hold the 'transceiver select' value + set_io REG_INTERNAL_CONFIG + in eax, dx + and eax, not (1111b shl 20) ; these bits hold the 'transceiver select' value - test cl, 10b ; baseTXAvailable - jz @f + test cl, 10b ; baseTXAvailable + jz @f - DEBUGF 1,"base TX is available\n" - or eax, (100b shl 20) + DEBUGF 1,"base TX is available\n" + or eax, (100b shl 20) if defined FORCE_FD - mov word [device.mode], (1 shl 8) + mov word [device.mode], (1 shl 8) else - mov word [device.mode], (1 shl 7) + mov word [device.mode], (1 shl 7) end if - jmp .set_media + jmp .set_media @@: - test cl, 100b ; baseFXAvailable - jz @f + test cl, 100b ; baseFXAvailable + jz @f - DEBUGF 1,"base FX is available\n" - or eax, (101b shl 20) - mov word [device.mode], (1 shl 10) - jmp .set_media + DEBUGF 1,"base FX is available\n" + or eax, (101b shl 20) + mov word [device.mode], (1 shl 10) + jmp .set_media @@: - test cl, 1000000b ; miiDevice - jz @f + test cl, 1000000b ; miiDevice + jz @f - DEBUGF 1,"mii-device is available\n" - or eax, (0110b shl 20) - mov word [device.mode], (1 shl 13) - jmp .set_media + DEBUGF 1,"mii-device is available\n" + or eax, (0110b shl 20) + mov word [device.mode], (1 shl 13) + jmp .set_media @@: - test cl, 1000b ; 10bTAvailable - jz @f + test cl, 1000b ; 10bTAvailable + jz @f - DEBUGF 1,"10base-T is available\n" + DEBUGF 1,"10base-T is available\n" .set_default: if FORCE_FD - mov word [device.mode], (1 shl 6) + mov word [device.mode], (1 shl 6) else - mov word [device.mode], (1 shl 5) + mov word [device.mode], (1 shl 5) end if - jmp .set_media + jmp .set_media @@: - test cl, 10000b ; coaxAvailable - jz @f + test cl, 10000b ; coaxAvailable + jz @f - DEBUGF 1,"coax is available\n" - push eax - set_io REG_COMMAND - mov ax, (10b shl 11) ; EnableDcConverter - out dx, ax - pop eax + DEBUGF 1,"coax is available\n" + push eax + set_io REG_COMMAND + mov ax, (10b shl 11) ; EnableDcConverter + out dx, ax + pop eax - or eax, (11b shl 20) - mov word [device.mode], (1 shl 12) - jmp .set_media + or eax, (11b shl 20) + mov word [device.mode], (1 shl 12) + jmp .set_media @@: - test cl, 10000b ; auiAvailable - jz .set_default + test cl, 10000b ; auiAvailable + jz .set_default - DEBUGF 1,"AUI is available\n" - or eax, (1 shl 20) - mov word [device.mode], (1 shl 11) + DEBUGF 1,"AUI is available\n" + or eax, (1 shl 20) + mov word [device.mode], (1 shl 11) .set_media: - set_io 0 - set_io REG_INTERNAL_CONFIG - out dx, eax + set_io 0 + set_io REG_INTERNAL_CONFIG + out dx, eax if FORCE_FD - DEBUGF 1,"Forcing full duplex\n" - set_io REG_MAC_CONTROL - in ax, dx - or ax, 0x120 - out dx, ax + DEBUGF 1,"Forcing full duplex\n" + set_io REG_MAC_CONTROL + in ax, dx + or ax, 0x120 + out dx, ax end if - mov al, 1 - ret + mov al, 1 + ret @@ -1805,50 +1805,50 @@ end if align 4 wake_up: - DEBUGF 1,"Waking up NIC: " + DEBUGF 1,"Waking up NIC: " ; wake up - we directly do it by programming PCI ; check if the device is power management capable - movzx ecx, [device.pci_bus] - movzx edx, [device.pci_dev] - stdcall PciRead32, ecx, edx, PCI_REG_STATUS + movzx ecx, [device.pci_bus] + movzx edx, [device.pci_dev] + stdcall PciRead32, ecx, edx, PCI_REG_STATUS - test al, 10000b ; is there "new capabilities" linked list? - jz .device_awake + test al, 10000b ; is there "new capabilities" linked list? + jz .device_awake ; search for power management register - stdcall PciRead16, ecx, edx, PCI_REG_CAP_PTR - cmp al, 0x3f - jbe .device_awake + stdcall PciRead16, ecx, edx, PCI_REG_CAP_PTR + cmp al, 0x3f + jbe .device_awake ; traverse the list - movzx esi, al + movzx esi, al .pm_loop: - stdcall PciRead32, ecx, edx, esi + stdcall PciRead32, ecx, edx, esi - cmp al , 1 - je .set_pm_state + cmp al , 1 + je .set_pm_state - movzx esi, ah + movzx esi, ah - test ah , ah - jnz .pm_loop - jmp .device_awake + test ah , ah + jnz .pm_loop + jmp .device_awake ; waku up the device if necessary .set_pm_state: - add esi, PCI_REG_PM_CTRL - stdcall PciRead32, ecx, edx, esi - test al, 3 - jz .device_awake - and al, not 11b ; set state to D0 - stdcall PciWrite32, ecx, edx, esi, eax + add esi, PCI_REG_PM_CTRL + stdcall PciRead32, ecx, edx, esi + test al, 3 + jz .device_awake + and al, not 11b ; set state to D0 + stdcall PciWrite32, ecx, edx, esi, eax .device_awake: - DEBUGF 1,"Device is awake\n" + DEBUGF 1,"Device is awake\n" - ret + ret @@ -1954,45 +1954,45 @@ wake_up: align 4 read_eeprom: - DEBUGF 1,"Reading from eeprom.. " + DEBUGF 1,"Reading from eeprom.. " - push eax + push eax ; switch to register window 0 - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+0 - out dx, ax - pop eax - and ax, 111111b ; take only the first 6 bits into account - movzx esi, [device.ver_id] + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+0 + out dx, ax + pop eax + and ax, 111111b ; take only the first 6 bits into account + movzx esi, [device.ver_id] - test word [esi*4+hw_versions+2], EEPROM_8BIT - jz @f - add ax, 0x230 ; hardware constant - jmp .read + test word [esi*4+hw_versions+2], EEPROM_8BIT + jz @f + add ax, 0x230 ; hardware constant + jmp .read @@: - add ax, EEPROM_CMD_READ - test word [esi*4+hw_versions+2], EEPROM_OFFSET - jz .read - add ax, 0x30 + add ax, EEPROM_CMD_READ + test word [esi*4+hw_versions+2], EEPROM_OFFSET + jz .read + add ax, 0x30 .read: - set_io REG_EEPROM_COMMAND - out dx, ax - mov ecx, 0xffff ; duration of about 162 us ;-) + set_io REG_EEPROM_COMMAND + out dx, ax + mov ecx, 0xffff ; duration of about 162 us ;-) .wait_for_reading: - in ax, dx - test ah, 0x80 ; check bit eepromBusy - jz .read_data - loop .wait_for_reading + in ax, dx + test ah, 0x80 ; check bit eepromBusy + jz .read_data + loop .wait_for_reading .read_data: - set_io REG_EEPROM_DATA - in ax, dx + set_io REG_EEPROM_DATA + in ax, dx - DEBUGF 1,"ok!\n" + DEBUGF 1,"ok!\n" - ret + ret ;*************************************************************************** ; Function @@ -2010,29 +2010,29 @@ read_eeprom: align 4 mdio_sync: - DEBUGF 1,"syncing mdio\n" + DEBUGF 1,"syncing mdio\n" ; switch to register window 4 - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+4 - out dx, ax - cmp [device.preamble], 0 - je .no_preamble + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+4 + out dx, ax + cmp [device.preamble], 0 + je .no_preamble ; send 32 logic ones - set_io REG_PHYSICAL_MGMT - mov ecx, 31 + set_io REG_PHYSICAL_MGMT + mov ecx, 31 .loop: - mov ax, (1 shl BIT_MGMT_DATA) or (1 shl BIT_MGMT_DIR) - out dx, ax - in ax, dx ; delay - mov ax, (1 shl BIT_MGMT_DATA) or (1 shl BIT_MGMT_DIR) or (1 shl BIT_MGMT_CLK) - out dx, ax - in ax, dx ; delay - loop .loop + mov ax, (1 shl BIT_MGMT_DATA) or (1 shl BIT_MGMT_DIR) + out dx, ax + in ax, dx ; delay + mov ax, (1 shl BIT_MGMT_DATA) or (1 shl BIT_MGMT_DIR) or (1 shl BIT_MGMT_CLK) + out dx, ax + in ax, dx ; delay + loop .loop .no_preamble: - ret + ret ;*************************************************************************** ; Function @@ -2052,56 +2052,56 @@ mdio_sync: align 4 mdio_read: - DEBUGF 1,"Reading MII registers\n" + DEBUGF 1,"Reading MII registers\n" - push eax - call mdio_sync ; returns with window #4 - pop eax - set_io 0 - set_io REG_PHYSICAL_MGMT - shl al, 3 - shr ax, 3 - and ax, not MII_CMD_MASK - or ax, MII_CMD_READ + push eax + call mdio_sync ; returns with window #4 + pop eax + set_io 0 + set_io REG_PHYSICAL_MGMT + shl al, 3 + shr ax, 3 + and ax, not MII_CMD_MASK + or ax, MII_CMD_READ - mov esi, eax - mov ecx, 13 + mov esi, eax + mov ecx, 13 .cmd_loop: - mov ax, (1 shl BIT_MGMT_DIR) ; write mii - bt esi, ecx - jnc .zero_bit - or al, (1 shl BIT_MGMT_DATA) + mov ax, (1 shl BIT_MGMT_DIR) ; write mii + bt esi, ecx + jnc .zero_bit + or al, (1 shl BIT_MGMT_DATA) .zero_bit: - out dx, ax - push ax - in ax, dx ; delay - pop ax - or al, (1 shl BIT_MGMT_CLK) ; write - out dx, ax - in ax, dx ; delay - loop .cmd_loop + out dx, ax + push ax + in ax, dx ; delay + pop ax + or al, (1 shl BIT_MGMT_CLK) ; write + out dx, ax + in ax, dx ; delay + loop .cmd_loop ; read data (18 bits with the two transition bits) - mov ecx, 17 - xor esi, esi + mov ecx, 17 + xor esi, esi .read_loop: - shl esi, 1 - xor eax, eax ; read comand - out dx, ax - in ax, dx ; delay - in ax, dx - test al, (1 shl BIT_MGMT_DATA) - jz .dont_set - inc esi + shl esi, 1 + xor eax, eax ; read comand + out dx, ax + in ax, dx ; delay + in ax, dx + test al, (1 shl BIT_MGMT_DATA) + jz .dont_set + inc esi .dont_set: - mov ax, (1 shl BIT_MGMT_CLK) - out dx, ax - in ax, dx ; delay - loop .read_loop - mov eax, esi + mov ax, (1 shl BIT_MGMT_CLK) + out dx, ax + in ax, dx ; delay + loop .read_loop + mov eax, esi - ret + ret @@ -2123,40 +2123,40 @@ mdio_read: align 4 mdio_write: - DEBUGF 1,"Writing MII registers\n" + DEBUGF 1,"Writing MII registers\n" - push eax - call mdio_sync - pop eax - set_io 0 - set_io REG_PHYSICAL_MGMT - shl al, 3 - shr ax, 3 - and ax, not MII_CMD_MASK - or ax, MII_CMD_WRITE - shl eax, 2 - or eax, 10b ; transition bits - shl eax, 16 - mov ax, si - mov esi, eax - mov ecx, 31 + push eax + call mdio_sync + pop eax + set_io 0 + set_io REG_PHYSICAL_MGMT + shl al, 3 + shr ax, 3 + and ax, not MII_CMD_MASK + or ax, MII_CMD_WRITE + shl eax, 2 + or eax, 10b ; transition bits + shl eax, 16 + mov ax, si + mov esi, eax + mov ecx, 31 .cmd_loop: - mov ax, (1 shl BIT_MGMT_DIR) ; write mii - bt esi, ecx - jnc @f - or al, (1 shl BIT_MGMT_DATA) + mov ax, (1 shl BIT_MGMT_DIR) ; write mii + bt esi, ecx + jnc @f + or al, (1 shl BIT_MGMT_DATA) @@: - out dx, ax - push eax - in ax, dx ; delay - pop eax - or al, (1 shl BIT_MGMT_CLK) ; write - out dx, ax - in ax, dx ; delay - loop .cmd_loop + out dx, ax + push eax + in ax, dx ; delay + pop eax + or al, (1 shl BIT_MGMT_CLK) ; write + out dx, ax + in ax, dx ; delay + loop .cmd_loop - ret + ret ;*************************************************************************** @@ -2175,32 +2175,32 @@ mdio_write: align 4 check_tx_status: - DEBUGF 1,"Checking TX status\n" + DEBUGF 1,"Checking TX status\n" ; clear TxStatus queue - set_io 0 - set_io REG_TX_STATUS - mov ecx, 31 ; max number of queue entries + set_io 0 + set_io REG_TX_STATUS + mov ecx, 31 ; max number of queue entries .tx_status_loop: - in al, dx - test al, al - jz .finish ; no error - test al, 0x3f - jnz .error + in al, dx + test al, al + jz .finish ; no error + test al, 0x3f + jnz .error .no_error_found: ; clear current TxStatus entry which advances the next one - xor al, al - out dx, al - loop .tx_status_loop + xor al, al + out dx, al + loop .tx_status_loop .finish: - ret + ret .error: - call tx_reset - ret + call tx_reset + ret @@ -2217,41 +2217,41 @@ check_tx_status: align 4 vortex_transmit: - DEBUGF 1,"Sending packet (vortex)\n" + DEBUGF 1,"Sending packet (vortex)\n" - cmp dword [esp+8], MAX_ETH_FRAME_SIZE - ja .finish ; packet is too long + cmp dword [esp+8], MAX_ETH_FRAME_SIZE + ja .finish ; packet is too long - call check_tx_status + call check_tx_status ; switch to register window 7 - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+7 - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+7 + out dx, ax ; check for master operation in progress - set_io REG_MASTER_STATUS - in ax, dx - test ah, 0x80 - jnz .finish ; no DMA for sending + set_io REG_MASTER_STATUS + in ax, dx + test ah, 0x80 + jnz .finish ; no DMA for sending ; program frame address to be sent - set_io REG_MASTER_ADDRESS - mov eax, [esp+4] - call GetPgAddr - out dx, eax + set_io REG_MASTER_ADDRESS + mov eax, [esp+4] + call GetPgAddr + out dx, eax ; program frame length - set_io REG_MASTER_LEN - mov eax, [esp+8] + set_io REG_MASTER_LEN + mov eax, [esp+8] ;;; and eax, not 3 - out dx, ax + out dx, ax ; start DMA Down - set_io REG_COMMAND - mov ax, (10100b shl 11) + 1 ; StartDMADown - out dx, ax + set_io REG_COMMAND + mov ax, (10100b shl 11) + 1 ; StartDMADown + out dx, ax .finish: - call KernelFree - add esp, 4 - ret + call KernelFree + add esp, 4 + ret @@ -2268,133 +2268,134 @@ vortex_transmit: align 4 boomerang_transmit: - DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8] - mov eax, [esp+4] - DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ - [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ - [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ - [eax+13]:2,[eax+12]:2 + DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8] + mov eax, [esp+4] + DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ + [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ + [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ + [eax+13]:2,[eax+12]:2 - cmp dword [esp+8], MAX_ETH_FRAME_SIZE - jg .fail + cmp dword [esp+8], MAX_ETH_FRAME_SIZE + jg .fail - call check_tx_status + call check_tx_status ; calculate descriptor address - mov esi, [device.prev_dpd] - DEBUGF 1,"Previous DPD: %x\n", esi - add esi, dpd.size - lea ecx, [device.dpd_buffer + (NUM_TX_DESC)*dpd.size] - cmp esi, ecx - jl @f - lea esi, [device.dpd_buffer] ; Wrap if needed + mov esi, [device.prev_dpd] + DEBUGF 1,"Previous DPD: %x\n", esi + add esi, dpd.size + lea ecx, [device.dpd_buffer + (NUM_TX_DESC)*dpd.size] + cmp esi, ecx + jl @f + lea esi, [device.dpd_buffer] ; Wrap if needed @@: - DEBUGF 1,"Found a free DPD: %x\n", esi + DEBUGF 1,"Found a free DPD: %x\n", esi ; check DnListPtr - set_io 0 - set_io REG_DN_LIST_PTR - in eax, dx + set_io 0 + set_io REG_DN_LIST_PTR + in eax, dx ; mark if Dn_List_Ptr is cleared - test eax, eax - setz [device.dn_list_ptr_cleared] + test eax, eax + setz [device.dn_list_ptr_cleared] ; finish if no more free descriptor is available - FIXME! ; cmp eax, esi ; jz .finish ; update statistics - inc [device.packets_tx] - mov ecx, [esp+8] ; buffer size - add dword [device.bytes_tx], ecx - adc dword [device.bytes_tx + 4], 0 + inc [device.packets_tx] + mov ecx, [esp+8] ; buffer size + add dword [device.bytes_tx], ecx + adc dword [device.bytes_tx + 4], 0 ; program DPD - and [esi+dpd.next_ptr], 0 - mov eax, [esp+4] ; Tx buffer address - mov [esi+dpd.realaddr], eax - call GetPgAddr - mov [esi+dpd.frag_addr], eax - mov ecx, [esp+8] ; packet size - or ecx, 0x80000000 ; last fragment - mov [esi+dpd.frag_len], ecx + and [esi+dpd.next_ptr], 0 + mov eax, [esp+4] ; Tx buffer address + mov [esi+dpd.realaddr], eax + call GetPgAddr + mov [esi+dpd.frag_addr], eax + mov ecx, [esp+8] ; packet size + or ecx, 0x80000000 ; last fragment + mov [esi+dpd.frag_len], ecx - mov ecx, [esp+8] ; packet size + mov ecx, [esp+8] ; packet size ; or ecx, 0x8000 ; transmission complete notification - or ecx, 1 shl 31 + or ecx, 1 shl 31 ; test byte [device.has_hwcksm], 0xff ; jz @f ; or ecx, (1 shl 26) ; set AddTcpChecksum ;@@: - mov [esi+dpd.frame_start_hdr], ecx + mov [esi+dpd.frame_start_hdr], ecx - DEBUGF 1,"DPD: lin=%x phys=%x len=%x start hdr=%x\n", [esi+dpd.realaddr]:8, [esi+dpd.frag_addr]:8, [esi+dpd.frag_len]:8, [esi+dpd.frame_start_hdr]:8 + DEBUGF 1,"DPD: lin=%x phys=%x len=%x start hdr=%x\n", [esi+dpd.realaddr]:8, [esi+dpd.frag_addr]:8, [esi+dpd.frag_len]:8, [esi+dpd.frame_start_hdr]:8 ; calculate physical address of dpd - mov eax, esi - GetRealAddr - cmp [device.dn_list_ptr_cleared], 0 - jz .add_to_list + mov eax, esi + GetRealAddr + cmp [device.dn_list_ptr_cleared], 0 + jz .add_to_list ; write Dn_List_Ptr - DEBUGF 1,"DPD phys addr=%x\n", eax - set_io 0 - set_io REG_DN_LIST_PTR - out dx, eax - jmp .finish + DEBUGF 1,"DPD phys addr=%x\n", eax + set_io 0 + set_io REG_DN_LIST_PTR + out dx, eax + jmp .finish .add_to_list: - DEBUGF 1,"Adding To list\n" - push eax + DEBUGF 1,"Adding To list\n" + push eax ; DnStall - set_io 0 - set_io REG_COMMAND - mov ax, ((110b shl 11)+2) - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, ((110b shl 11)+2) + out dx, ax ; wait for DnStall to complete - DEBUGF 1,"Waiting for DnStall\n" - mov ecx, 6000 + DEBUGF 1,"Waiting for DnStall\n" + mov ecx, 6000 .wait_for_stall: - in ax, dx ; read REG_INT_STATUS - test ah, 10000b - jz .dnstall_ok - dec ecx - jnz .wait_for_stall + in ax, dx ; read REG_INT_STATUS + test ah, 10000b + jz .dnstall_ok + dec ecx + jnz .wait_for_stall .dnstall_ok: - DEBUGF 1,"DnStall ok!\n" - mov ecx, [device.prev_dpd] - mov [ecx+dpd.next_ptr], eax + DEBUGF 1,"DnStall ok!\n" + mov ecx, [device.prev_dpd] + mov [ecx+dpd.next_ptr], eax - set_io 0 - set_io REG_DN_LIST_PTR - in eax, dx - test eax, eax - pop eax - jnz .dnunstall + set_io 0 + set_io REG_DN_LIST_PTR + in eax, dx + test eax, eax + pop eax + jnz .dnunstall ; if Dn_List_Ptr has been cleared fill it up - DEBUGF 1,"DnList Ptr has been cleared\n" - out dx, eax + DEBUGF 1,"DnList Ptr has been cleared\n" + out dx, eax .dnunstall: ; DnUnStall - set_io 0 - set_io REG_COMMAND - mov ax, ((110b shl 11)+3) - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, ((110b shl 11)+3) + out dx, ax .finish: - mov [device.prev_dpd], esi - xor eax, eax - ret 8 + mov [device.prev_dpd], esi + xor eax, eax + ret 8 .fail: - stdcall KernelFree, [esp+4] - ret 8 + stdcall KernelFree, [esp+4] + or eax, -1 + ret 8 ;--------------------------------- @@ -2403,25 +2404,25 @@ boomerang_transmit: align 4 write_mac: - DEBUGF 1,"Writing mac\n" + DEBUGF 1,"Writing mac\n" - set_io 0 - set_io REG_COMMAND + set_io 0 + set_io REG_COMMAND ; switch to register window 2 - mov ax, SELECT_REGISTER_WINDOW+2 - out dx, ax + mov ax, SELECT_REGISTER_WINDOW+2 + out dx, ax ; write MAC addres back into the station address registers - set_io REG_STATION_ADDRESS_LO - lea esi, [device.mac] - outsw - inc dx - inc dx - outsw - inc dx - inc dx - outsw + set_io REG_STATION_ADDRESS_LO + lea esi, [device.mac] + outsw + inc dx + inc dx + outsw + inc dx + inc dx + outsw ;---------------------------- @@ -2430,51 +2431,51 @@ write_mac: align 4 read_mac: - set_io 0 - set_io REG_COMMAND + set_io 0 + set_io REG_COMMAND ; switch to register window 2 - mov ax, SELECT_REGISTER_WINDOW+2 - out dx, ax + mov ax, SELECT_REGISTER_WINDOW+2 + out dx, ax ; write MAC addres back into the station address registers - set_io REG_STATION_ADDRESS_LO - lea edi, [device.mac] - insw - inc dx - inc dx - insw - inc dx - inc dx - insw + set_io REG_STATION_ADDRESS_LO + lea edi, [device.mac] + insw + inc dx + inc dx + insw + inc dx + inc dx + insw - DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",[device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 + DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",[device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 - ret + ret ;------------------------------------ ; Read MAC from eeprom align 4 -read_mac_eeprom: ; Tested - ok +read_mac_eeprom: ; Tested - ok - DEBUGF 1,"Reading mac from eeprom\n" + DEBUGF 1,"Reading mac from eeprom\n" ; read MAC from eeprom - mov ecx, 3 + mov ecx, 3 .mac_loop: - lea ax, [EEPROM_REG_OEM_NODE_ADDR+ecx-1] - push ecx - call read_eeprom - pop ecx - xchg ah, al ; htons - mov word [device.mac+ecx*2-2], ax - loop .mac_loop + lea ax, [EEPROM_REG_OEM_NODE_ADDR+ecx-1] + push ecx + call read_eeprom + pop ecx + xchg ah, al ; htons + mov word [device.mac+ecx*2-2], ax + loop .mac_loop - DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",[device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 + DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",[device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 - ret + ret @@ -2489,147 +2490,147 @@ read_mac_eeprom: ; Tested - ok align 4 int_vortex: - DEBUGF 1,"vortex IRQ %x ",eax:2 + DEBUGF 1,"vortex IRQ %x ",eax:2 ; find pointer of device wich made IRQ occur - mov esi, VORTEX_LIST - mov ecx, [VORTEX_DEVICES] - test ecx, ecx - jz .fail + mov esi, VORTEX_LIST + mov ecx, [VORTEX_DEVICES] + test ecx, ecx + jz .fail .nextdevice: - mov ebx, dword [esi] + mov ebx, dword [esi] - set_io 0 - set_io REG_INT_STATUS - in ax, dx + set_io 0 + set_io REG_INT_STATUS + in ax, dx ;; and ax, INT_MASK - jnz .got_it + jnz .got_it - add esi, 4 + add esi, 4 - test ax , ax - jnz .got_it - loop .nextdevice + test ax , ax + jnz .got_it + loop .nextdevice .fail: - ret + ret .got_it: - DEBUGF 1,"Device: %x Status: %x ",ebx,eax:4 + DEBUGF 1,"Device: %x Status: %x ",ebx,eax:4 - test ax, RxComplete - jz .noRX + test ax, RxComplete + jz .noRX - set_io 0 + set_io 0 .rx_status_loop: ; examine RxStatus - set_io REG_RX_STATUS - in ax, dx - test ax, ax - jz .finish + set_io REG_RX_STATUS + in ax, dx + test ax, ax + jz .finish - test ah, 0x80 ; rxIncomplete - jnz .finish + test ah, 0x80 ; rxIncomplete + jnz .finish - test ah, 0x40 - jz .check_length + test ah, 0x40 + jz .check_length ; discard the top frame received advancing the next one - set_io REG_COMMAND - mov ax, (01000b shl 11) - out dx, ax - jmp .rx_status_loop + set_io REG_COMMAND + mov ax, (01000b shl 11) + out dx, ax + jmp .rx_status_loop .check_length: - and eax, 0x1fff - cmp eax, MAX_ETH_PKT_SIZE - ja .discard_frame ; frame is too long discard it + and eax, 0x1fff + cmp eax, MAX_ETH_PKT_SIZE + ja .discard_frame ; frame is too long discard it .check_dma: - mov ecx, eax + mov ecx, eax ; switch to register window 7 - set_io 0 - set_io REG_COMMAND - mov ax, SELECT_REGISTER_WINDOW+7 - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, SELECT_REGISTER_WINDOW+7 + out dx, ax ; check for master operation in progress - set_io REG_MASTER_STATUS - in ax, dx + set_io REG_MASTER_STATUS + in ax, dx - test ah, 0x80 - jnz .finish + test ah, 0x80 + jnz .finish .read_frame: ; program buffer address to read in - push ecx - stdcall KernelAlloc, MAX_ETH_FRAME_SIZE - pop ecx - test eax, eax - jz .finish + push ecx + stdcall KernelAlloc, MAX_ETH_FRAME_SIZE + pop ecx + test eax, eax + jz .finish - push .discard_frame - push ecx - push eax + push .discard_frame + push ecx + push eax ; zero_to_dma eax - set_io REG_MASTER_ADDRESS - out dx, eax + set_io REG_MASTER_ADDRESS + out dx, eax ; program frame length - set_io REG_MASTER_LEN - mov ax, 1560 - out dx, ax + set_io REG_MASTER_LEN + mov ax, 1560 + out dx, ax ; start DMA Up - set_io REG_COMMAND - mov ax, (10100b shl 11) ; StartDMAUp - out dx, ax + set_io REG_COMMAND + mov ax, (10100b shl 11) ; StartDMAUp + out dx, ax ; check for master operation in progress - set_io REG_MASTER_STATUS ; TODO: use timeout and reset after timeout expired + set_io REG_MASTER_STATUS ; TODO: use timeout and reset after timeout expired .dma_loop: - in ax, dx - test ah, 0x80 - jnz .dma_loop + in ax, dx + test ah, 0x80 + jnz .dma_loop ; registrate the received packet to kernel - jmp EthReceiver + jmp EthReceiver ; discard the top frame received .discard_frame: - set_io 0 - set_io REG_COMMAND - mov ax, (01000b shl 11) - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, (01000b shl 11) + out dx, ax .finish: .noRX: - test ax, DMADone - jz .noDMA + test ax, DMADone + jz .noDMA - push ax + push ax - set_io 0 - set_io 12 - in ax, dx - test ax, 0x1000 - jz .nodmaclear + set_io 0 + set_io 12 + in ax, dx + test ax, 0x1000 + jz .nodmaclear - mov ax, 0x1000 - out dx, ax + mov ax, 0x1000 + out dx, ax .nodmaclear: - pop ax + pop ax - DEBUGF 1, "DMA Done!\n", cx + DEBUGF 1, "DMA Done!\n", cx @@ -2638,12 +2639,12 @@ int_vortex: .ACK: - set_io 0 - set_io REG_COMMAND - mov ax, AckIntr + IntReq + IntLatch - out dx, ax + set_io 0 + set_io REG_COMMAND + mov ax, AckIntr + IntReq + IntLatch + out dx, ax - ret + ret @@ -2657,69 +2658,69 @@ int_vortex: align 4 int_boomerang: - DEBUGF 1,"\nIRQ %x Boomerang\n",eax:2 + DEBUGF 1,"\nIRQ %x Boomerang\n",eax:2 ; find pointer of device wich made IRQ occur - mov esi, BOOMERANG_LIST - mov ecx, [BOOMERANG_DEVICES] + mov esi, BOOMERANG_LIST + mov ecx, [BOOMERANG_DEVICES] - test ecx, ecx - jz .fail + test ecx, ecx + jz .fail .nextdevice: - mov ebx, dword[esi] + mov ebx, dword[esi] - set_io 0 - set_io REG_INT_STATUS - in ax, dx - test ax, IntLatch - jnz .got_it + set_io 0 + set_io REG_INT_STATUS + in ax, dx + test ax, IntLatch + jnz .got_it - add esi, 4 + add esi, 4 - test ax , ax - jnz .got_it - dec ecx - jnz .nextdevice + test ax , ax + jnz .got_it + dec ecx + jnz .nextdevice .fail: - DEBUGF 1,"Failed!\n" - ret + DEBUGF 1,"Failed!\n" + ret .got_it: - DEBUGF 1,"Device: %x Status: %x ", ebx, eax - push ax + DEBUGF 1,"Device: %x Status: %x ", ebx, eax + push ax ; disable all INTS - set_io REG_COMMAND - mov ax, SetIntrEnb - out dx, ax + set_io REG_COMMAND + mov ax, SetIntrEnb + out dx, ax ;-------------------------------------------------------------------------- - test word[esp], UpComplete - jz .noRX + test word[esp], UpComplete + jz .noRX - push ebx + push ebx .receive: - DEBUGF 1,"UpComplete\n" + DEBUGF 1,"UpComplete\n" ; check if packet is uploaded - mov esi, [device.curr_upd] - test byte [esi+upd.pkt_status+1], 0x80 ; upPktComplete - jz .finish - DEBUGF 1, "Current upd: %x\n", esi + mov esi, [device.curr_upd] + test byte [esi+upd.pkt_status+1], 0x80 ; upPktComplete + jz .finish + DEBUGF 1, "Current upd: %x\n", esi ; packet is uploaded check for any error .check_error: - test byte [esi+upd.pkt_status+1], 0x40 ; upError - jz .copy_packet_length - DEBUGF 1,"Error in packet\n" - and [esi+upd.pkt_status], 0 ; mark packet as read - jmp .finish + test byte [esi+upd.pkt_status+1], 0x40 ; upError + jz .copy_packet_length + DEBUGF 1,"Error in packet\n" + and [esi+upd.pkt_status], 0 ; mark packet as read + jmp .finish .copy_packet_length: - mov ecx, [esi+upd.pkt_status] - and ecx, 0x1fff + mov ecx, [esi+upd.pkt_status] + and ecx, 0x1fff ; cmp ecx, MAX_ETH_PKT_SIZE ; jbe .copy_packet @@ -2727,174 +2728,174 @@ int_boomerang: ; jmp .finish ; .copy_packet: - DEBUGF 1, "Received %u bytes in buffer %x\n", ecx, [esi+upd.realaddr]:8 + DEBUGF 1, "Received %u bytes in buffer %x\n", ecx, [esi+upd.realaddr]:8 - push dword .loop ;.finish - push ecx - push [esi+upd.realaddr] + push dword .loop ;.finish + push ecx + push [esi+upd.realaddr] ; update statistics - inc [device.packets_rx] - add dword [device.bytes_rx], ecx - adc dword [device.bytes_rx + 4], 0 + inc [device.packets_rx] + add dword [device.bytes_rx], ecx + adc dword [device.bytes_rx + 4], 0 ; update UPD (Alloc new buffer for next packet) - stdcall KernelAlloc, MAX_ETH_FRAME_SIZE - mov [esi + upd.realaddr], eax - GetRealAddr - mov [esi + upd.frag_addr], eax - and [esi + upd.pkt_status], 0 - mov [esi + upd.frag_len], MAX_ETH_FRAME_SIZE or (1 shl 31) + stdcall KernelAlloc, MAX_ETH_FRAME_SIZE + mov [esi + upd.realaddr], eax + GetRealAddr + mov [esi + upd.frag_addr], eax + and [esi + upd.pkt_status], 0 + mov [esi + upd.frag_len], MAX_ETH_FRAME_SIZE or (1 shl 31) ; Update UPD pointer - add esi, upd.size - lea ecx, [device.upd_buffer+(NUM_RX_DESC)*upd.size] - cmp esi, ecx - jl @f - lea esi, [device.upd_buffer] + add esi, upd.size + lea ecx, [device.upd_buffer+(NUM_RX_DESC)*upd.size] + cmp esi, ecx + jl @f + lea esi, [device.upd_buffer] @@: - mov [device.curr_upd], esi - DEBUGF 1, "Next upd: %x\n", esi + mov [device.curr_upd], esi + DEBUGF 1, "Next upd: %x\n", esi - jmp EthReceiver + jmp EthReceiver .loop: - mov ebx, [esp] - jmp .receive + mov ebx, [esp] + jmp .receive .finish: - pop ebx + pop ebx ; check if the NIC is in the upStall state - set_io 0 - set_io REG_UP_PKT_STATUS - in eax, dx - test ah, 0x20 ; UpStalled - jz .noUpUnStall + set_io 0 + set_io REG_UP_PKT_STATUS + in eax, dx + test ah, 0x20 ; UpStalled + jz .noUpUnStall - DEBUGF 1, "upUnStalling\n" + DEBUGF 1, "upUnStalling\n" ; issue upUnStall command - set_io REG_COMMAND - mov ax, ((11b shl 12)+1) ; upUnStall - out dx, ax + set_io REG_COMMAND + mov ax, ((11b shl 12)+1) ; upUnStall + out dx, ax - ;;;; FIXME: make upunstall work + ;;;; FIXME: make upunstall work .noUpUnStall: .noRX: - test word[esp], DownComplete - jz .noTX - DEBUGF 1, "Downcomplete!\n" + test word[esp], DownComplete + jz .noTX + DEBUGF 1, "Downcomplete!\n" - mov ecx, NUM_TX_DESC - lea esi, [device.dpd_buffer] + mov ecx, NUM_TX_DESC + lea esi, [device.dpd_buffer] .txloop: - test [esi+dpd.frame_start_hdr], 1 shl 31 - jz .maybenext + test [esi+dpd.frame_start_hdr], 1 shl 31 + jz .maybenext - and [esi+dpd.frame_start_hdr], 0 - push ecx - stdcall KernelFree, [esi+dpd.realaddr] - pop ecx + and [esi+dpd.frame_start_hdr], 0 + push ecx + stdcall KernelFree, [esi+dpd.realaddr] + pop ecx .maybenext: - add esi, dpd.size - dec ecx - jnz .txloop + add esi, dpd.size + dec ecx + jnz .txloop .noTX: - pop ax + pop ax - set_io 0 - set_io REG_COMMAND - or ax, AckIntr - out dx, ax + set_io 0 + set_io REG_COMMAND + or ax, AckIntr + out dx, ax - set_io REG_INT_STATUS - in ax, dx - test ax, S_5_INTS - jnz .got_it + set_io REG_INT_STATUS + in ax, dx + test ax, S_5_INTS + jnz .got_it ;re-enable ints - set_io REG_COMMAND - mov ax, SetIntrEnb + S_5_INTS - out dx, ax + set_io REG_COMMAND + mov ax, SetIntrEnb + S_5_INTS + out dx, ax - ret + ret ; End of code -align 4 ; Place all initialised data here +align 4 ; Place all initialised data here macro strtbl name, [string] { common - label name dword + label name dword forward - local label - dd label + local label + dd label forward - label db string, 0 + label db string, 0 } -VORTEX_DEVICES dd 0 +VORTEX_DEVICES dd 0 BOOMERANG_DEVICES dd 0 -version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) -my_service db '3C59X',0 ; max 16 chars include zero +version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) +my_service db '3C59X',0 ; max 16 chars include zero strtbl link_str, \ - "No valid link type detected", \ - "10BASE-T half duplex", \ - "10BASE-T full-duplex", \ - "100BASE-TX half duplex", \ - "100BASE-TX full duplex", \ - "100BASE-T4", \ - "100BASE-FX", \ - "10Mbps AUI", \ - "10Mbps COAX (BNC)", \ - "miiDevice - not supported" + "No valid link type detected", \ + "10BASE-T half duplex", \ + "10BASE-T full-duplex", \ + "100BASE-TX half duplex", \ + "100BASE-TX full duplex", \ + "100BASE-T4", \ + "100BASE-FX", \ + "10Mbps AUI", \ + "10Mbps COAX (BNC)", \ + "miiDevice - not supported" strtbl hw_str, \ - "3c590 Vortex 10Mbps", \ - "3c592 EISA 10Mbps Demon/Vortex", \ - "3c597 EISA Fast Demon/Vortex", \ - "3c595 Vortex 100baseTx", \ - "3c595 Vortex 100baseT4", \ - "3c595 Vortex 100base-MII", \ - "3c900 Boomerang 10baseT", \ - "3c900 Boomerang 10Mbps Combo", \ - "3c900 Cyclone 10Mbps TPO", \ - "3c900 Cyclone 10Mbps Combo", \ - "3c900 Cyclone 10Mbps TPC", \ - "3c900B-FL Cyclone 10base-FL", \ - "3c905 Boomerang 100baseTx", \ - "3c905 Boomerang 100baseT4", \ - "3c905B Cyclone 100baseTx", \ - "3c905B Cyclone 10/100/BNC", \ - "3c905B-FX Cyclone 100baseFx", \ - "3c905C Tornado", \ - "3c980 Cyclone", \ - "3c982 Dual Port Server Cyclone", \ - "3cSOHO100-TX Hurricane", \ - "3c555 Laptop Hurricane", \ - "3c556 Laptop Tornado", \ - "3c556B Laptop Hurricane", \ - "3c575 [Megahertz] 10/100 LAN CardBus", \ - "3c575 Boomerang CardBus", \ - "3CCFE575BT Cyclone CardBus", \ - "3CCFE575CT Tornado CardBus", \ - "3CCFE656 Cyclone CardBus", \ - "3CCFEM656B Cyclone+Winmodem CardBus", \ - "3CXFEM656C Tornado+Winmodem CardBus", \ - "3c450 HomePNA Tornado", \ - "3c920 Tornado", \ - "3c982 Hydra Dual Port A", \ - "3c982 Hydra Dual Port B", \ - "3c905B-T4", \ - "3c920B-EMB-WNM Tornado" + "3c590 Vortex 10Mbps", \ + "3c592 EISA 10Mbps Demon/Vortex", \ + "3c597 EISA Fast Demon/Vortex", \ + "3c595 Vortex 100baseTx", \ + "3c595 Vortex 100baseT4", \ + "3c595 Vortex 100base-MII", \ + "3c900 Boomerang 10baseT", \ + "3c900 Boomerang 10Mbps Combo", \ + "3c900 Cyclone 10Mbps TPO", \ + "3c900 Cyclone 10Mbps Combo", \ + "3c900 Cyclone 10Mbps TPC", \ + "3c900B-FL Cyclone 10base-FL", \ + "3c905 Boomerang 100baseTx", \ + "3c905 Boomerang 100baseT4", \ + "3c905B Cyclone 100baseTx", \ + "3c905B Cyclone 10/100/BNC", \ + "3c905B-FX Cyclone 100baseFx", \ + "3c905C Tornado", \ + "3c980 Cyclone", \ + "3c982 Dual Port Server Cyclone", \ + "3cSOHO100-TX Hurricane", \ + "3c555 Laptop Hurricane", \ + "3c556 Laptop Tornado", \ + "3c556B Laptop Hurricane", \ + "3c575 [Megahertz] 10/100 LAN CardBus", \ + "3c575 Boomerang CardBus", \ + "3CCFE575BT Cyclone CardBus", \ + "3CCFE575CT Tornado CardBus", \ + "3CCFE656 Cyclone CardBus", \ + "3CCFEM656B Cyclone+Winmodem CardBus", \ + "3CXFEM656C Tornado+Winmodem CardBus", \ + "3c450 HomePNA Tornado", \ + "3c920 Tornado", \ + "3c982 Hydra Dual Port A", \ + "3c982 Hydra Dual Port B", \ + "3c905B-T4", \ + "3c920B-EMB-WNM Tornado" @@ -2976,11 +2977,11 @@ dw 0x9210, IS_TORNADO or HAS_NWAY or HAS_HWCKSM ; 3c920B-EMB-WNM Tornado HW_VERSIONS_SIZE = $ - hw_versions -include_debug_strings ; All data wich FDO uses will be included here +include_debug_strings ; All data wich FDO uses will be included here section '.data' data readable writable align 16 ; place all uninitialized data place here -VORTEX_LIST rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling +VORTEX_LIST rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling BOOMERANG_LIST rd MAX_DEVICES diff --git a/kernel/branches/net/drivers/RTL8029.asm b/kernel/branches/net/drivers/RTL8029.asm index ea1ce0182..1b8a1745f 100644 --- a/kernel/branches/net/drivers/RTL8029.asm +++ b/kernel/branches/net/drivers/RTL8029.asm @@ -18,14 +18,14 @@ format MS COFF - API_VERSION equ 0x01000100 - DRIVER_VERSION equ 5 + API_VERSION equ 0x01000100 + DRIVER_VERSION equ 5 - MAX_DEVICES equ 16 + MAX_DEVICES equ 16 - DEBUG equ 1 - __DEBUG__ equ 1 - __DEBUG_LEVEL__ equ 1 + DEBUG equ 1 + __DEBUG__ equ 1 + __DEBUG_LEVEL__ equ 1 include 'proc32.inc' include 'imports.inc' @@ -34,26 +34,26 @@ include 'netdrv.inc' virtual at ebx - device: + device: - ETH_DEVICE + ETH_DEVICE - .io_addr dd ? - .irq_line db ? - .pci_bus db ? - .pci_dev db ? + .io_addr dd ? + .irq_line db ? + .pci_bus db ? + .pci_dev db ? - .flags db ? - .vendor db ? - .asic_base dw ? - .memsize db ? - .rx_start db ? - .tx_start db ? - .bmem dd ? - .rmem dd ? - .romdata rb 16 + .flags db ? + .vendor db ? + .asic_base dw ? + .memsize db ? + .rx_start db ? + .tx_start db ? + .bmem dd ? + .rmem dd ? + .romdata rb 16 - .size = $ - device + .size = $ - device end virtual @@ -62,92 +62,92 @@ public START public service_proc public version - P0_PSTART equ 0x01 - P0_PSTOP equ 0x02 - P0_BOUND equ 0x03 - P0_TSR equ 0x04 - P0_TPSR equ 0x04 - P0_TBCR0 equ 0x05 - P0_TBCR1 equ 0x06 - P0_ISR equ 0x07 - P0_RSAR0 equ 0x08 - P0_RSAR1 equ 0x09 - P0_RBCR0 equ 0x0A - P0_RBCR1 equ 0x0B - P0_RSR equ 0x0C - P0_RCR equ 0x0C - P0_TCR equ 0x0D - P0_DCR equ 0x0E - P0_IMR equ 0x0F + P0_PSTART equ 0x01 + P0_PSTOP equ 0x02 + P0_BOUND equ 0x03 + P0_TSR equ 0x04 + P0_TPSR equ 0x04 + P0_TBCR0 equ 0x05 + P0_TBCR1 equ 0x06 + P0_ISR equ 0x07 + P0_RSAR0 equ 0x08 + P0_RSAR1 equ 0x09 + P0_RBCR0 equ 0x0A + P0_RBCR1 equ 0x0B + P0_RSR equ 0x0C + P0_RCR equ 0x0C + P0_TCR equ 0x0D + P0_DCR equ 0x0E + P0_IMR equ 0x0F - P1_PAR0 equ 0x01 - P1_PAR1 equ 0x02 - P1_PAR2 equ 0x03 - P1_PAR3 equ 0x04 - P1_PAR4 equ 0x05 - P1_PAR5 equ 0x06 - P1_CURR equ 0x07 - P1_MAR0 equ 0x08 + P1_PAR0 equ 0x01 + P1_PAR1 equ 0x02 + P1_PAR2 equ 0x03 + P1_PAR3 equ 0x04 + P1_PAR4 equ 0x05 + P1_PAR5 equ 0x06 + P1_CURR equ 0x07 + P1_MAR0 equ 0x08 - CMD_PS0 equ 0x00 ; Page 0 select - CMD_PS1 equ 0x40 ; Page 1 select - CMD_PS2 equ 0x80 ; Page 2 select - CMD_RD2 equ 0x20 ; Remote DMA control - CMD_RD1 equ 0x10 - CMD_RD0 equ 0x08 - CMD_TXP equ 0x04 ; transmit packet - CMD_STA equ 0x02 ; start - CMD_STP equ 0x01 ; stop + CMD_PS0 equ 0x00 ; Page 0 select + CMD_PS1 equ 0x40 ; Page 1 select + CMD_PS2 equ 0x80 ; Page 2 select + CMD_RD2 equ 0x20 ; Remote DMA control + CMD_RD1 equ 0x10 + CMD_RD0 equ 0x08 + CMD_TXP equ 0x04 ; transmit packet + CMD_STA equ 0x02 ; start + CMD_STP equ 0x01 ; stop - RCR_MON equ 0x20 ; monitor mode + RCR_MON equ 0x20 ; monitor mode - DCR_FT1 equ 0x40 - DCR_LS equ 0x08 ; Loopback select - DCR_WTS equ 0x01 ; Word transfer select + DCR_FT1 equ 0x40 + DCR_LS equ 0x08 ; Loopback select + DCR_WTS equ 0x01 ; Word transfer select - ISR_PRX equ 0x01 ; successful recv - ISR_PTX equ 0x02 ; successful xmit - ISR_RXE equ 0x04 ; receive error - ISR_TXE equ 0x08 ; transmit error - ISR_OVW equ 0x10 ; Overflow - ISR_CNT equ 0x20 ; Counter overflow - ISR_RDC equ 0x40 ; Remote DMA complete - ISR_RST equ 0x80 ; reset + ISR_PRX equ 0x01 ; successful recv + ISR_PTX equ 0x02 ; successful xmit + ISR_RXE equ 0x04 ; receive error + ISR_TXE equ 0x08 ; transmit error + ISR_OVW equ 0x10 ; Overflow + ISR_CNT equ 0x20 ; Counter overflow + ISR_RDC equ 0x40 ; Remote DMA complete + ISR_RST equ 0x80 ; reset - IRQ_MASK equ ISR_PRX ; + ISR_PTX + ISR_TXE + IRQ_MASK equ ISR_PRX ; + ISR_PTX + ISR_TXE - RSTAT_PRX equ 0x01 ; successful recv - RSTAT_CRC equ 0x02 ; CRC error - RSTAT_FAE equ 0x04 ; Frame alignment error - RSTAT_OVER equ 0x08 ; FIFO overrun + RSTAT_PRX equ 0x01 ; successful recv + RSTAT_CRC equ 0x02 ; CRC error + RSTAT_FAE equ 0x04 ; Frame alignment error + RSTAT_OVER equ 0x08 ; FIFO overrun - TXBUF_SIZE equ 6 - RXBUF_END equ 32 - PAGE_SIZE equ 256 + TXBUF_SIZE equ 6 + RXBUF_END equ 32 + PAGE_SIZE equ 256 - ETH_ALEN equ 6 - ETH_HLEN equ 14 - ETH_ZLEN equ 60 - ETH_FRAME_LEN equ 1514 + ETH_ALEN equ 6 + ETH_HLEN equ 14 + ETH_ZLEN equ 60 + ETH_FRAME_LEN equ 1514 - FLAG_PIO equ 0x01 - FLAG_16BIT equ 0x02 - ASIC_PIO equ 0 + FLAG_PIO equ 0x01 + FLAG_16BIT equ 0x02 + ASIC_PIO equ 0 - VENDOR_NONE equ 0 - VENDOR_WD equ 1 - VENDOR_NOVELL equ 2 - VENDOR_3COM equ 3 + VENDOR_NONE equ 0 + VENDOR_WD equ 1 + VENDOR_NOVELL equ 2 + VENDOR_3COM equ 3 - NE_ASIC_OFFSET equ 0x10 - NE_RESET equ 0x0F ; Used to reset card - NE_DATA equ 0x00 ; Used to read/write NIC mem + NE_ASIC_OFFSET equ 0x10 + NE_RESET equ 0x0F ; Used to reset card + NE_DATA equ 0x00 ; Used to read/write NIC mem - MEM_8192 equ 32 - MEM_16384 equ 64 - MEM_32768 equ 128 + MEM_8192 equ 32 + MEM_16384 equ 64 + MEM_32768 equ 128 - ISA_MAX_ADDR equ 0x400 + ISA_MAX_ADDR equ 0x400 @@ -162,16 +162,16 @@ section '.flat' code readable align 16 align 4 proc START stdcall, state:dword - cmp [state], 1 - jne .exit + cmp [state], 1 + jne .exit .entry: - DEBUGF 2,"Registering rtl8029 service \n" - stdcall RegService, my_service, service_proc - ret + DEBUGF 2,"Registering rtl8029 service \n" + stdcall RegService, my_service, service_proc + ret .fail: .exit: - xor eax, eax - ret + xor eax, eax + ret endp @@ -185,152 +185,152 @@ endp align 4 proc service_proc stdcall, ioctl:dword - mov edx, [ioctl] - mov eax, [IOCTL.io_code] + mov edx, [ioctl] + mov eax, [IOCTL.io_code] ;------------------------------------------------------ - ;--------------- - cmp eax, 0 ;SRV_GETVERSION - jne @F ;--------------- + ;--------------- + cmp eax, 0 ;SRV_GETVERSION + jne @F ;--------------- - cmp [IOCTL.out_size], 4 - jl .fail - mov eax, [IOCTL.output] - mov [eax], dword API_VERSION + cmp [IOCTL.out_size], 4 + jl .fail + mov eax, [IOCTL.output] + mov [eax], dword API_VERSION - xor eax, eax - ret 4 + xor eax, eax + ret 4 ;------------------------------------------------------ - @@: ;--------- - cmp eax, 1 ;SRV_HOOK - jne @F ;--------- + @@: ;--------- + cmp eax, 1 ;SRV_HOOK + jne @F ;--------- - DEBUGF 2,"Checking if device is already listed..\n" + DEBUGF 2,"Checking if device is already listed..\n" - mov eax, [IOCTL.input] + mov eax, [IOCTL.input] - cmp [IOCTL.inp_size], 3 - jl .fail - cmp byte [eax], 1 - je .pci + cmp [IOCTL.inp_size], 3 + jl .fail + cmp byte [eax], 1 + je .pci - cmp [IOCTL.inp_size], 4 - jl .fail - cmp byte [eax], 0 - je .isa + cmp [IOCTL.inp_size], 4 + jl .fail + cmp byte [eax], 0 + je .isa - jmp .fail + jmp .fail .pci: ; check if the device is already listed - mov esi, device_list - mov ecx, [devices] - test ecx, ecx - jz .firstdevice_pci + mov esi, device_list + mov ecx, [devices] + test ecx, ecx + jz .firstdevice_pci ; mov eax, [IOCTL.input] ; get the pci bus and device numbers - mov ax , [eax+1] ; + mov ax , [eax+1] ; .nextdevice: - mov ebx, [esi] - cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) - je .find_devicenum ; Device is already loaded, let's find it's device number - add esi, 4 - loop .nextdevice + mov ebx, [esi] + cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) + je .find_devicenum ; Device is already loaded, let's find it's device number + add esi, 4 + loop .nextdevice .firstdevice_pci: - call create_new_struct + call create_new_struct - mov eax, [IOCTL.input] - mov cl , [eax+1] - mov [device.pci_bus], cl - mov cl , [eax+2] - mov [device.pci_dev], cl + mov eax, [IOCTL.input] + mov cl , [eax+1] + mov [device.pci_bus], cl + mov cl , [eax+2] + mov [device.pci_dev], cl ; Now, it's time to find the base io addres of the PCI device - find_io [device.pci_bus], [device.pci_dev], [device.io_addr] + find_io [device.pci_bus], [device.pci_dev], [device.io_addr] ; We've found the io address, find IRQ now - find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] + find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] - jmp .hook + jmp .hook .isa: - mov esi, device_list - mov ecx, [devices] - test ecx, ecx - jz .firstdevice_isa - mov al , [eax+3] - movzx edi, word [eax+1] + mov esi, device_list + mov ecx, [devices] + test ecx, ecx + jz .firstdevice_isa + mov al , [eax+3] + movzx edi, word [eax+1] .nextdevice_isa: - mov ebx, [esi] - cmp edi, [device.io_addr] - jne .maybenext - cmp al , [device.irq_line] - je find_device_num + mov ebx, [esi] + cmp edi, [device.io_addr] + jne .maybenext + cmp al , [device.irq_line] + je find_device_num .maybenext: - add esi, 4 - loop .nextdevice_isa + add esi, 4 + loop .nextdevice_isa .firstdevice_isa: - call create_new_struct + call create_new_struct - mov eax, [IOCTL.input] - movzx ecx , word [eax+1] - mov [device.io_addr], ecx - mov cl, [eax+3] - mov [device.irq_line], cl + mov eax, [IOCTL.input] + movzx ecx , word [eax+1] + mov [device.io_addr], ecx + mov cl, [eax+3] + mov [device.irq_line], cl .hook: - DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ - [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 + DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ + [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 - call probe ; this function will output in eax - test eax, eax - jnz .err ; If an error occured, exit + call probe ; this function will output in eax + test eax, eax + jnz .err ; If an error occured, exit - mov eax, [devices] - mov [device_list+4*eax], ebx - inc [devices] + mov eax, [devices] + mov [device_list+4*eax], ebx + inc [devices] - mov [device.type], NET_TYPE_ETH - call NetRegDev + mov [device.type], NET_TYPE_ETH + call NetRegDev - cmp eax, -1 - jz .err - ret 4 + cmp eax, -1 + jz .err + ret 4 ; If the device was already loaded, find the device number and return it in eax .find_devicenum: - DEBUGF 1,"Trying to find device number of already registered device\n" - mov ebx, eax - call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx - ; into a device number in edi - mov eax, edi ; Application wants it in eax instead - DEBUGF 1,"Kernel says: %u\n", eax - ret + DEBUGF 1,"Trying to find device number of already registered device\n" + mov ebx, eax + call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx + ; into a device number in edi + mov eax, edi ; Application wants it in eax instead + DEBUGF 1,"Kernel says: %u\n", eax + ret .err: - DEBUGF 1,"Failed, removing device structure\n" - stdcall KernelFree, ebx + DEBUGF 1,"Failed, removing device structure\n" + stdcall KernelFree, ebx - jmp .fail + jmp .fail ;------------------------------------------------------ @@: .fail: - or eax, -1 - ret 4 + or eax, -1 + ret 4 ;------------------------------------------------------ endp @@ -338,34 +338,34 @@ endp create_new_struct: - cmp [devices], MAX_DEVICES - jge .fail + cmp [devices], MAX_DEVICES + jge .fail - allocate_and_clear ebx, device.size, .fail ; Allocate the buffer for device structure + allocate_and_clear ebx, device.size, .fail ; Allocate the buffer for device structure - mov [device.reset], reset - mov [device.transmit], transmit - mov [device.get_MAC], read_mac - mov [device.set_MAC], write_mac - mov [device.unload], unload - mov [device.name], my_service + mov [device.reset], reset + mov [device.transmit], transmit + mov [device.get_MAC], read_mac + mov [device.set_MAC], write_mac + mov [device.unload], unload + mov [device.name], my_service - ret + ret .fail: - add esp, 4 ; return to caller of 'hook' - or eax, -1 - ret + add esp, 4 ; return to caller of 'hook' + or eax, -1 + ret find_device_num: - DEBUGF 1,"Trying to find device number of already registered device\n" - mov ebx, eax - call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx - ; into a device number in edi - mov eax, edi ; Application wants it in eax instead - DEBUGF 1,"Kernel says: %u\n", eax - ret + DEBUGF 1,"Trying to find device number of already registered device\n" + mov ebx, eax + call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx + ; into a device number in edi + mov eax, edi ; Application wants it in eax instead + DEBUGF 1,"Kernel says: %u\n", eax + ret ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; @@ -376,8 +376,8 @@ find_device_num: unload: ; TODO - or eax, -1 - ret + or eax, -1 + ret @@ -388,141 +388,141 @@ unload: ; TODO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; probe: - mov [device.vendor], VENDOR_NONE - mov [device.bmem], 0 - mov eax,[device.io_addr] - add eax, NE_ASIC_OFFSET - mov [device.asic_base], ax + mov [device.vendor], VENDOR_NONE + mov [device.bmem], 0 + mov eax,[device.io_addr] + add eax, NE_ASIC_OFFSET + mov [device.asic_base], ax - DEBUGF 2,"Trying 16-bit mode\n" + DEBUGF 2,"Trying 16-bit mode\n" - or [device.flags], FLAG_16BIT or FLAG_PIO - mov [device.memsize], MEM_32768 - mov [device.tx_start], 64 - mov [device.rx_start], TXBUF_SIZE + 64 + or [device.flags], FLAG_16BIT or FLAG_PIO + mov [device.memsize], MEM_32768 + mov [device.tx_start], 64 + mov [device.rx_start], TXBUF_SIZE + 64 - set_io 0 - set_io P0_DCR - mov al, DCR_WTS + DCR_FT1 + DCR_LS - out dx, al + set_io 0 + set_io P0_DCR + mov al, DCR_WTS + DCR_FT1 + DCR_LS + out dx, al - set_io P0_PSTART - mov al, MEM_16384 - out dx, al + set_io P0_PSTART + mov al, MEM_16384 + out dx, al - set_io P0_PSTOP - mov al, MEM_32768 - out dx, al + set_io P0_PSTOP + mov al, MEM_32768 + out dx, al - mov esi, test_data - mov di, 16384 - mov cx, 14 - call eth_pio_write + mov esi, test_data + mov di, 16384 + mov cx, 14 + call eth_pio_write - mov si, 16384 - mov cx, 14 - lea edi, [device.romdata] - call eth_pio_read + mov si, 16384 + mov cx, 14 + lea edi, [device.romdata] + call eth_pio_read - lea esi, [device.romdata] - mov edi, test_data - mov ecx, 13 + lea esi, [device.romdata] + mov edi, test_data + mov ecx, 13 repz cmpsb jz ep_set_vendor - DEBUGF 2,"Trying 8-bit mode\n" + DEBUGF 2,"Trying 8-bit mode\n" - mov [device.flags], FLAG_PIO - mov [device.memsize], MEM_16384 - mov [device.tx_start], 32 - mov [device.rx_start], TXBUF_SIZE + 32 + mov [device.flags], FLAG_PIO + mov [device.memsize], MEM_16384 + mov [device.tx_start], 32 + mov [device.rx_start], TXBUF_SIZE + 32 - mov dx, [device.asic_base] - add dx, NE_RESET + mov dx, [device.asic_base] + add dx, NE_RESET - in al, dx - out dx, al + in al, dx + out dx, al - in al, 0x84 + in al, 0x84 - set_io 0 - mov al, CMD_RD2 + CMD_STP - out dx, al + set_io 0 + mov al, CMD_RD2 + CMD_STP + out dx, al - set_io P0_RCR - mov al, RCR_MON - out dx, al + set_io P0_RCR + mov al, RCR_MON + out dx, al - set_io P0_DCR - mov al, DCR_FT1 + DCR_LS - out dx, al + set_io P0_DCR + mov al, DCR_FT1 + DCR_LS + out dx, al - set_io P0_PSTART - mov al, MEM_8192 - out dx, al + set_io P0_PSTART + mov al, MEM_8192 + out dx, al - set_io P0_PSTOP - mov al, MEM_16384 - out dx, al + set_io P0_PSTOP + mov al, MEM_16384 + out dx, al - mov esi, test_data - mov di, 8192 - mov cx, 14 - call eth_pio_write + mov esi, test_data + mov di, 8192 + mov cx, 14 + call eth_pio_write - mov si, 8192 - mov cx, 14 - lea edi, [device.romdata] - call eth_pio_read + mov si, 8192 + mov cx, 14 + lea edi, [device.romdata] + call eth_pio_read - mov esi, test_data - lea edi, [device.romdata] - mov ecx, 13 + mov esi, test_data + lea edi, [device.romdata] + mov ecx, 13 repz cmpsb - jz ep_set_vendor + jz ep_set_vendor - DEBUGF 2,"This is not a valid ne2000 device!\n" - or eax, -1 - ret + DEBUGF 2,"This is not a valid ne2000 device!\n" + or eax, -1 + ret ep_set_vendor: - cmp [device.io_addr], ISA_MAX_ADDR - jbe ep_001 + cmp [device.io_addr], ISA_MAX_ADDR + jbe ep_001 - DEBUGF 2,"Card is using PCI bus\n" + DEBUGF 2,"Card is using PCI bus\n" ; or [flags], FLAG_16BIT ep_001: - mov [device.vendor], VENDOR_NOVELL + mov [device.vendor], VENDOR_NOVELL ep_check_have_vendor: - mov al, [device.vendor] - cmp al, VENDOR_NONE + mov al, [device.vendor] + cmp al, VENDOR_NONE ; je rtl8029_exit - cmp al, VENDOR_3COM - je reset + cmp al, VENDOR_3COM + je reset - mov eax, [device.bmem] - mov [device.rmem], eax + mov eax, [device.bmem] + mov [device.rmem], eax - call read_mac + call read_mac - push .hack - sub esp, 6 - mov edi, esp - lea esi, [device.mac] - movsd - movsw - jmp write_mac + push .hack + sub esp, 6 + mov edi, esp + lea esi, [device.mac] + movsd + movsw + jmp write_mac .hack: @@ -533,81 +533,81 @@ ep_check_have_vendor: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; reset: - DEBUGF 2,"Resetting device\n" + DEBUGF 2,"Resetting device\n" ; attach int handler - movzx eax, [device.irq_line] - DEBUGF 1,"Attaching int handler to irq %x\n",eax:1 - stdcall AttachIntHandler, eax, int_handler, dword 0 + movzx eax, [device.irq_line] + DEBUGF 1,"Attaching int handler to irq %x\n",eax:1 + stdcall AttachIntHandler, eax, int_handler, dword 0 ; Stop mode - set_io 0 - mov al, CMD_PS0 + CMD_RD2 + CMD_STP - out dx, al + set_io 0 + mov al, CMD_PS0 + CMD_RD2 + CMD_STP + out dx, al - set_io P0_DCR - test [device.flags], FLAG_16BIT - jz nsr_001 + set_io P0_DCR + test [device.flags], FLAG_16BIT + jz nsr_001 - mov al, 0x49 - jmp nsr_002 + mov al, 0x49 + jmp nsr_002 nsr_001: - mov al, 0x48 + mov al, 0x48 nsr_002: - out dx, al + out dx, al ; clear remote bytes count - set_io 0 + set_io 0 - xor al, al + xor al, al - set_io P0_RBCR0 - out dx, al + set_io P0_RBCR0 + out dx, al - set_io P0_RBCR1 - out dx, al + set_io P0_RBCR1 + out dx, al ; initialize Receive configuration register - set_io P0_RCR - mov al, 0x20 ; monitor mode - out dx, al + set_io P0_RCR + mov al, 0x20 ; monitor mode + out dx, al ; transmit configuration register - set_io P0_TCR - mov al, 2 ; internal loopback - out dx, al + set_io P0_TCR + mov al, 2 ; internal loopback + out dx, al ; transmit page stuff - set_io P0_TPSR - mov al, [device.tx_start] - out dx, al + set_io P0_TPSR + mov al, [device.tx_start] + out dx, al ; set receive control register ;;;; - set_io P0_RCR - mov al, 4 ; accept broadcast - out dx, al + set_io P0_RCR + mov al, 4 ; accept broadcast + out dx, al ; pagestart - set_io P0_PSTART - mov al, [device.rx_start] - out dx, al + set_io P0_PSTART + mov al, [device.rx_start] + out dx, al ; pagestop - set_io P0_PSTOP - mov al, [device.memsize] - out dx, al + set_io P0_PSTOP + mov al, [device.memsize] + out dx, al ; page boundary - set_io P0_BOUND - mov al, [device.memsize] - dec al - out dx, al + set_io P0_BOUND + mov al, [device.memsize] + dec al + out dx, al ;;clear IRQ mask @@ -615,31 +615,31 @@ nsr_002: ; xor al, al ; out dx, al - set_io 0 - mov al, CMD_PS1 + CMD_RD2 + CMD_STP ; page 1, stop mode - out dx, al + set_io 0 + mov al, CMD_PS1 + CMD_RD2 + CMD_STP ; page 1, stop mode + out dx, al - set_io P1_CURR - mov al, [device.rx_start] - out dx, al + set_io P1_CURR + mov al, [device.rx_start] + out dx, al - set_io 0 - mov al, CMD_PS0 + CMD_RD2 + CMD_STA ; go to page 0 - out dx, al + set_io 0 + mov al, CMD_PS0 + CMD_RD2 + CMD_STA ; go to page 0 + out dx, al ; Read MAC address - call read_mac + call read_mac ; clear interupt status - set_io 0 - set_io P0_ISR - mov al, 0xff - out dx, al + set_io 0 + set_io P0_ISR + mov al, 0xff + out dx, al ; set IRQ mask - set_io P0_IMR - mov al, IRQ_MASK - out dx, al + set_io P0_IMR + mov al, IRQ_MASK + out dx, al ;; start mode ; set_io 0 @@ -647,23 +647,23 @@ nsr_002: ; out dx, al ; clear transmit control register - set_io P0_TCR - mov al, 0 ; no loopback - out dx, al + set_io P0_TCR + mov al, 0 ; no loopback + out dx, al ; clear packet/byte counters - xor eax, eax - lea edi, [device.bytes_tx] - mov ecx, 6 - rep stosd + xor eax, eax + lea edi, [device.bytes_tx] + mov ecx, 6 + rep stosd ; Set the mtu, kernel will be able to send now - mov [device.mtu], 1514 + mov [device.mtu], 1514 ; Indicate that we have successfully reset the card - DEBUGF 2,"Done!\n" + DEBUGF 2,"Done!\n" - ret + ret @@ -676,55 +676,58 @@ nsr_002: align 4 transmit: - mov esi, [esp + 4] - mov ecx, [esp + 8] - DEBUGF 2,"Transmitting packet, buffer:%x, size:%u\n",esi, ecx - DEBUGF 2,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",[esi+0]:2,[esi+1]:2,[esi+2]:2,[esi+3]:2,[esi+4]:2,[esi+5]:2,[esi+6]:2,[esi+7]:2,[esi+8]:2,[esi+9]:2,[esi+10]:2,[esi+11]:2,[esi+13]:2,[esi+12]:2 + mov esi, [esp + 4] + mov ecx, [esp + 8] + DEBUGF 2,"Transmitting packet, buffer:%x, size:%u\n",esi, ecx + DEBUGF 2,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",[esi+0]:2,[esi+1]:2,[esi+2]:2,[esi+3]:2,[esi+4]:2,[esi+5]:2,[esi+6]:2,[esi+7]:2,[esi+8]:2,[esi+9]:2,[esi+10]:2,[esi+11]:2,[esi+13]:2,[esi+12]:2 - cmp ecx, ETH_FRAME_LEN - jg .err ; packet is too long - cmp ecx, 60 - jl .err ; packet is too short + cmp ecx, ETH_FRAME_LEN + jg .err ; packet is too long + cmp ecx, 60 + jl .err ; packet is too short - movzx edi, [device.tx_start] - shl edi, 8 - push cx - call eth_pio_write - pop cx + movzx edi, [device.tx_start] + shl edi, 8 + push cx + call eth_pio_write + pop cx - set_io 0 - mov al, CMD_PS0 + CMD_RD2 + CMD_STA - out dx, al + set_io 0 + mov al, CMD_PS0 + CMD_RD2 + CMD_STA + out dx, al - set_io P0_TPSR - mov al, [device.tx_start] - out dx, al + set_io P0_TPSR + mov al, [device.tx_start] + out dx, al - set_io P0_TBCR0 - mov al, cl - out dx, al + set_io P0_TBCR0 + mov al, cl + out dx, al - set_io P0_TBCR1 - mov al, ch - out dx, al + set_io P0_TBCR1 + mov al, ch + out dx, al - set_io 0 - mov al, CMD_PS0 + CMD_TXP + CMD_RD2 + CMD_STA - out dx, al + set_io 0 + mov al, CMD_PS0 + CMD_TXP + CMD_RD2 + CMD_STA + out dx, al - DEBUGF 2," - Packet Sent!\n" + DEBUGF 2," - Packet Sent!\n" - inc [device.packets_tx] - mov eax, [esp + 8] ; Get packet size in eax + inc [device.packets_tx] + mov eax, [esp + 8] ; Get packet size in eax - add dword [device.bytes_tx], eax - adc dword [device.bytes_tx + 4], 0 + add dword [device.bytes_tx], eax + adc dword [device.bytes_tx + 4], 0 + + stdcall KernelFree, [esp+4] + xor eax, eax + ret 8 .err: - or eax, -1 -.finish: - stdcall KernelFree, [esp+4] - ret 8 + or eax, -1 + stdcall KernelFree, [esp+4] + ret 8 @@ -736,205 +739,205 @@ transmit: align 4 int_handler: - DEBUGF 2,"IRQ %x ",eax:2 + DEBUGF 2,"IRQ %x ",eax:2 ; find pointer of device wich made INT occur - mov esi, device_list - mov ecx, [devices] + mov esi, device_list + mov ecx, [devices] .nextdevice: - mov ebx, [esi] + mov ebx, [esi] - set_io 0 - set_io P0_ISR - in al, dx + set_io 0 + set_io P0_ISR + in al, dx - DEBUGF 2,"isr %x ",eax:2 + DEBUGF 2,"isr %x ",eax:2 - test al, ISR_PRX ; packet received ok ? - jnz .rx + test al, ISR_PRX ; packet received ok ? + jnz .rx - add esi, 4 + add esi, 4 - loop .nextdevice - ret + loop .nextdevice + ret ; looks like we've found a device wich received a packet.. .rx: - stdcall KernelAlloc, ETH_FRAME_LEN ; size doesnt really matter as packet size is smaller then kernel's page size - test eax, eax - jz .fail_2 + stdcall KernelAlloc, ETH_FRAME_LEN ; size doesnt really matter as packet size is smaller then kernel's page size + test eax, eax + jz .fail_2 ;-------------------------------------- ; allocate memory for temp variables in stack - sub esp, 14+8 + sub esp, 14+8 - eth_type equ esp - pkthdr equ esp + 2 - pktoff equ esp + 6 - eth_rx_data_ptr equ esp + 8 - eth_tmp_len equ esp + 12 + eth_type equ esp + pkthdr equ esp + 2 + pktoff equ esp + 6 + eth_rx_data_ptr equ esp + 8 + eth_tmp_len equ esp + 12 ; These will be used by eth_receiver when the packet gets there - pointer equ esp + 14 - size equ esp + 18 + pointer equ esp + 14 + size equ esp + 18 ;------------------------------------- - mov [pointer], eax - mov [eth_rx_data_ptr], eax + mov [pointer], eax + mov [eth_rx_data_ptr], eax - set_io P0_BOUND - in al, dx - inc al + set_io P0_BOUND + in al, dx + inc al - cmp al, [device.memsize] - jb .nsp_001 + cmp al, [device.memsize] + jb .nsp_001 - mov al, [device.rx_start] + mov al, [device.rx_start] .nsp_001: - mov ch, al + mov ch, al - set_io 0 - mov al, CMD_PS1 - out dx, al + set_io 0 + mov al, CMD_PS1 + out dx, al - set_io P1_CURR - in al, dx ; get current page - mov cl, al + set_io P1_CURR + in al, dx ; get current page + mov cl, al - set_io 0 - mov al, CMD_PS0 - out dx, al + set_io 0 + mov al, CMD_PS0 + out dx, al - cmp cl, [device.memsize] - jb .nsp_002 + cmp cl, [device.memsize] + jb .nsp_002 - mov cl, [device.rx_start] + mov cl, [device.rx_start] .nsp_002: - cmp cl, ch - je .fail + cmp cl, ch + je .fail - xor ax, ax - mov ah, ch + xor ax, ax + mov ah, ch - mov [pktoff], ax + mov [pktoff], ax - mov al, [device.flags] - test al, FLAG_PIO - jz .nsp_003 + mov al, [device.flags] + test al, FLAG_PIO + jz .nsp_003 - mov si, word [pktoff] - lea edi, [pkthdr] - mov cx, 4 - call eth_pio_read - jmp .nsp_004 + mov si, word [pktoff] + lea edi, [pkthdr] + mov cx, 4 + call eth_pio_read + jmp .nsp_004 .nsp_003: - mov edi, [device.rmem] - movzx eax, word [pktoff] - add edi, eax - mov eax, [edi] - mov [pkthdr], eax + mov edi, [device.rmem] + movzx eax, word [pktoff] + add edi, eax + mov eax, [edi] + mov [pkthdr], eax .nsp_004: - add word[pktoff] , 4 + add word[pktoff] , 4 - xor eax, eax - mov ax , [pkthdr + 2] - sub ax , 4 + xor eax, eax + mov ax , [pkthdr + 2] + sub ax , 4 - DEBUGF 2,"Received %u bytes\n",eax + DEBUGF 2,"Received %u bytes\n",eax - add dword [device.bytes_rx], eax ; Update stats - adc dword [device.bytes_rx + 4], 0 - inc dword [device.packets_rx] ; + add dword [device.bytes_rx], eax ; Update stats + adc dword [device.bytes_rx + 4], 0 + inc dword [device.packets_rx] ; - mov [eth_tmp_len], ax - mov dword[size], eax + mov [eth_tmp_len], ax + mov dword[size], eax - cmp ax, ETH_ZLEN - jb .fail + cmp ax, ETH_ZLEN + jb .fail - cmp ax , ETH_FRAME_LEN - ja .fail + cmp ax , ETH_FRAME_LEN + ja .fail - mov al , [pkthdr] - test al , RSTAT_PRX - jz .fail + mov al , [pkthdr] + test al , RSTAT_PRX + jz .fail ; Right, we can now get the data - movzx esi, [device.memsize] - sub si , [pktoff] + movzx esi, [device.memsize] + sub si , [pktoff] - cmp [eth_tmp_len], si - jbe .nsp_005 + cmp [eth_tmp_len], si + jbe .nsp_005 - DEBUGF 2,"WRAP!\n" + DEBUGF 2,"WRAP!\n" - mov al , [device.flags] - test al , FLAG_PIO - jz .nsp_006 + mov al , [device.flags] + test al , FLAG_PIO + jz .nsp_006 - push esi - mov cx , si - mov si , [pktoff+4] - mov edi, [eth_rx_data_ptr+4] - call eth_pio_read - pop esi - jmp .nsp_007 + push esi + mov cx , si + mov si , [pktoff+4] + mov edi, [eth_rx_data_ptr+4] + call eth_pio_read + pop esi + jmp .nsp_007 .nsp_006: - DEBUGF 2,"PIO mode not supported by HW!\n" + DEBUGF 2,"PIO mode not supported by HW!\n" ; Not implemented, as we are using PIO mode on this card .nsp_007: - xor al, al - mov ah, [device.rx_start] - mov [pktoff], ax + xor al, al + mov ah, [device.rx_start] + mov [pktoff], ax - add [eth_rx_data_ptr], esi - sub [eth_tmp_len], si + add [eth_rx_data_ptr], esi + sub [eth_tmp_len], si .nsp_005: - test [device.flags], FLAG_PIO - jz .nsp_008 + test [device.flags], FLAG_PIO + jz .nsp_008 - movzx esi, word [pktoff] - movzx ecx, word [eth_tmp_len] - mov edi, [eth_rx_data_ptr] - call eth_pio_read - jmp .nsp_009 + movzx esi, word [pktoff] + movzx ecx, word [eth_tmp_len] + mov edi, [eth_rx_data_ptr] + call eth_pio_read + jmp .nsp_009 .nsp_008: - DEBUGF 2,"PIO mode not supported by HW!\n" + DEBUGF 2,"PIO mode not supported by HW!\n" ; Not implemented, as we are using PIO mode on this card .nsp_009: - mov al, [pkthdr+1] - cmp al, [device.rx_start] - jne .nsp_010 + mov al, [pkthdr+1] + cmp al, [device.rx_start] + jne .nsp_010 - mov al, [device.memsize] + mov al, [device.memsize] .nsp_010: - set_io 0 - set_io P0_BOUND - dec al - out dx, al + set_io 0 + set_io P0_BOUND + dec al + out dx, al - add esp, 14 - jmp EthReceiver ; send it to the kernel + add esp, 14 + jmp EthReceiver ; send it to the kernel .fail: - add esp, 14+8 + add esp, 14+8 .fail_2: - DEBUGF 2,"done\n" + DEBUGF 2,"done\n" ret @@ -948,24 +951,24 @@ ret ;;;;;;;;;;;;;;;;;;;;;;; align 4 -write_mac: ; in: mac on stack (6 bytes) +write_mac: ; in: mac on stack (6 bytes) - DEBUGF 1,"Writing MAC: " + DEBUGF 1,"Writing MAC: " - set_io 0 - mov al, CMD_PS1; + CMD_RD2 + CMD_STP - out dx, al + set_io 0 + mov al, CMD_PS1; + CMD_RD2 + CMD_STP + out dx, al - set_io P1_PAR0 - mov esi, esp - mov cx, 6 + set_io P1_PAR0 + mov esi, esp + mov cx, 6 @@: - lodsb - out dx, al - inc dx - loopw @r + lodsb + out dx, al + inc dx + loopw @r - add esp, 6 + add esp, 6 ; Notice this procedure does not ret, but continues to read_mac instead. @@ -977,7 +980,7 @@ write_mac: ; in: mac on stack (6 bytes) read_mac: - DEBUGF 1,"Reading MAC: " + DEBUGF 1,"Reading MAC: " ; set_io 0 ; mov al, CMD_PS1; + CMD_RD2 + CMD_STP ; select page 1 @@ -997,26 +1000,26 @@ read_mac: ; mov al, CMD_PS0; + CMD_RD2 + CMD_STA ; set page back to 0 ; out dx, al - mov si, 0 - mov cx, 16 - lea edi, [device.romdata] - call eth_pio_read + mov si, 0 + mov cx, 16 + lea edi, [device.romdata] + call eth_pio_read - lea esi, [device.romdata] - lea edi, [device.mac] - mov ecx, 6 + lea esi, [device.romdata] + lea edi, [device.mac] + mov ecx, 6 .loop: - movsb - test [device.flags], FLAG_16BIT - jz .8bit - inc esi + movsb + test [device.flags], FLAG_16BIT + jz .8bit + inc esi .8bit: - loop .loop + loop .loop - DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",[edi-6]:2,[edi-5]:2,[edi-4]:2,[edi-3]:2,[edi-2]:2,[edi-1]:2 + DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",[edi-6]:2,[edi-5]:2,[edi-4]:2,[edi-3]:2,[edi-2]:2,[edi-1]:2 - ret + ret ;*************************************************************************** @@ -1031,70 +1034,70 @@ read_mac: ;*************************************************************************** eth_pio_read: - DEBUGF 1,"Eth PIO Read from %x to %x, %u bytes ",si,edi,cx + DEBUGF 1,"Eth PIO Read from %x to %x, %u bytes ",si,edi,cx - set_io 0 - mov al, CMD_RD2 + CMD_STA - out dx, al + set_io 0 + mov al, CMD_RD2 + CMD_STA + out dx, al - mov al, cl - set_io P0_RBCR0 - out dx, al + mov al, cl + set_io P0_RBCR0 + out dx, al - mov al, ch - set_io P0_RBCR1 - out dx, al + mov al, ch + set_io P0_RBCR1 + out dx, al - mov ax, si - set_io P0_RSAR0 - out dx, al - shr ax, 8 - set_io P0_RSAR1 - out dx, al + mov ax, si + set_io P0_RSAR0 + out dx, al + shr ax, 8 + set_io P0_RSAR1 + out dx, al - mov al, CMD_RD0 + CMD_STA - set_io 0 - out dx, al + mov al, CMD_RD0 + CMD_STA + set_io 0 + out dx, al - mov dx, [device.asic_base] + mov dx, [device.asic_base] - test [device.flags], FLAG_16BIT - jz epr_003 + test [device.flags], FLAG_16BIT + jz epr_003 - DEBUGF 1,"in 16-bits mode" + DEBUGF 1,"in 16-bits mode" - shr cx, 1 ; note that if the number was odd, carry flag will be set - pushf ; save the flags for later + shr cx, 1 ; note that if the number was odd, carry flag will be set + pushf ; save the flags for later epr_002: - in ax, dx - stosw - loopw epr_002 + in ax, dx + stosw + loopw epr_002 - inc cx - popf - jnc epr_004 + inc cx + popf + jnc epr_004 epr_003: - in al, dx - stosb - loopw epr_003 + in al, dx + stosb + loopw epr_003 epr_004: - set_io 0 - set_io P0_ISR + set_io 0 + set_io P0_ISR -epr_005: ; Wait for Remote DMA Complete - in al, dx - test al, ISR_RDC - jz epr_005 +epr_005: ; Wait for Remote DMA Complete + in al, dx + test al, ISR_RDC + jz epr_005 ; and al, not ISR_RDC - out dx, al ; clear the bit + out dx, al ; clear the bit - DEBUGF 1,"\n" - ret + DEBUGF 1,"\n" + ret @@ -1111,95 +1114,95 @@ epr_005: ; Wait for Remote DMA Complete ;*************************************************************************** eth_pio_write: - DEBUGF 1,"Eth PIO Write from %x to %x, %u bytes ",esi,di,cx + DEBUGF 1,"Eth PIO Write from %x to %x, %u bytes ",esi,di,cx - set_io 0 - mov al, CMD_RD2 + CMD_STA - out dx, al + set_io 0 + mov al, CMD_RD2 + CMD_STA + out dx, al - set_io P0_ISR - mov al, ISR_RDC - out dx, al + set_io P0_ISR + mov al, ISR_RDC + out dx, al - set_io P0_RBCR0 - mov al, cl - out dx, al + set_io P0_RBCR0 + mov al, cl + out dx, al - set_io P0_RBCR1 - mov al, ch - out dx, al + set_io P0_RBCR1 + mov al, ch + out dx, al - mov ax, di - set_io P0_RSAR0 - out dx, al - shr ax, 8 - set_io P0_RSAR1 - out dx, al + mov ax, di + set_io P0_RSAR0 + out dx, al + shr ax, 8 + set_io P0_RSAR1 + out dx, al - set_io 0 - mov al, CMD_RD1 + CMD_STA - out dx, al + set_io 0 + mov al, CMD_RD1 + CMD_STA + out dx, al - mov dx, [device.asic_base] - test [device.flags], FLAG_16BIT - jz epw_003 + mov dx, [device.asic_base] + test [device.flags], FLAG_16BIT + jz epw_003 - DEBUGF 1,"in 16-bits mode" + DEBUGF 1,"in 16-bits mode" - shr cx, 1 ; note that if the number was odd, carry flag will be set - pushf ; save the flags for later + shr cx, 1 ; note that if the number was odd, carry flag will be set + pushf ; save the flags for later epw_002: - lodsw - out dx, ax - loopw epw_002 + lodsw + out dx, ax + loopw epw_002 - popf - jnc epw_004 - inc cx + popf + jnc epw_004 + inc cx epw_003: - lodsb - out dx, al - loopw epw_003 + lodsb + out dx, al + loopw epw_003 epw_004: - set_io 0 - set_io P0_ISR + set_io 0 + set_io P0_ISR -epw_005: ; Wait for Remote DMA Complete - in al, dx - test al, ISR_RDC - jz epw_005 +epw_005: ; Wait for Remote DMA Complete + in al, dx + test al, ISR_RDC + jz epw_005 ; and al, not ISR_RDC - out dx, al ; clear the bit + out dx, al ; clear the bit - DEBUGF 1,"\n" - ret + DEBUGF 1,"\n" + ret ;all initialized data place here align 4 -devices dd 0 -version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) -my_service db 'RTL8029/ne2000',0 ;max 16 chars include zero +devices dd 0 +version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) +my_service db 'RTL8029/ne2000',0 ;max 16 chars include zero -device_1 db 'Realtek 8029',0 -device_2 db 'Realtek 8019',0 -device_3 db 'Realtek 8019AS',0 -device_4 db 'ne2000',0 -device_5 db 'DP8390',0 +device_1 db 'Realtek 8029',0 +device_2 db 'Realtek 8019',0 +device_3 db 'Realtek 8019AS',0 +device_4 db 'ne2000',0 +device_5 db 'DP8390',0 -test_data db 'NE*000 memory',0 +test_data db 'NE*000 memory',0 include_debug_strings section '.data' data readable writable align 16 ;place all uninitialized data place here -device_list rd MAX_DEVICES +device_list rd MAX_DEVICES diff --git a/kernel/branches/net/drivers/RTL8139.asm b/kernel/branches/net/drivers/RTL8139.asm index 24e5e17ac..fc09cfb7c 100644 --- a/kernel/branches/net/drivers/RTL8139.asm +++ b/kernel/branches/net/drivers/RTL8139.asm @@ -17,16 +17,16 @@ format MS COFF - API_VERSION equ 0x01000100 - DRIVER_VERSION equ 5 + API_VERSION equ 0x01000100 + DRIVER_VERSION equ 5 - MAX_DEVICES equ 16 + MAX_DEVICES equ 16 - RBLEN equ 3 ; Receive buffer size: 0==8K 1==16k 2==32k 3==64k + RBLEN equ 3 ; Receive buffer size: 0==8K 1==16k 2==32k 3==64k - DEBUG equ 1 - __DEBUG__ equ 1 - __DEBUG_LEVEL__ equ 2 + DEBUG equ 1 + __DEBUG__ equ 1 + __DEBUG_LEVEL__ equ 2 include 'proc32.inc' include 'imports.inc' @@ -37,184 +37,184 @@ public START public service_proc public version - REG_IDR0 equ 0x00 - REG_MAR0 equ 0x08 ; multicast filter register 0 - REG_MAR4 equ 0x0c ; multicast filter register 4 - REG_TSD0 equ 0x10 ; transmit status of descriptor - REG_TSAD0 equ 0x20 ; transmit start address of descriptor - REG_RBSTART equ 0x30 ; RxBuffer start address - REG_COMMAND equ 0x37 ; command register - REG_CAPR equ 0x38 ; current address of packet read (word) R/W - REG_IMR equ 0x3c ; interrupt mask register - REG_ISR equ 0x3e ; interrupt status register - REG_TXCONFIG equ 0x40 ; transmit configuration register - REG_RXCONFIG equ 0x44 ; receive configuration register 0 - REG_MPC equ 0x4c ; missed packet counter - REG_9346CR equ 0x50 ; serial eeprom 93C46 command register - REG_CONFIG1 equ 0x52 ; configuration register 1 - REG_MSR equ 0x58 - REG_CONFIG4 equ 0x5a ; configuration register 4 - REG_HLTCLK equ 0x5b ; undocumented halt clock register - REG_BMCR equ 0x62 ; basic mode control register - REG_ANAR equ 0x66 ; auto negotiation advertisement register - REG_9346CR_WE equ 11b SHL 6 + REG_IDR0 equ 0x00 + REG_MAR0 equ 0x08 ; multicast filter register 0 + REG_MAR4 equ 0x0c ; multicast filter register 4 + REG_TSD0 equ 0x10 ; transmit status of descriptor + REG_TSAD0 equ 0x20 ; transmit start address of descriptor + REG_RBSTART equ 0x30 ; RxBuffer start address + REG_COMMAND equ 0x37 ; command register + REG_CAPR equ 0x38 ; current address of packet read (word) R/W + REG_IMR equ 0x3c ; interrupt mask register + REG_ISR equ 0x3e ; interrupt status register + REG_TXCONFIG equ 0x40 ; transmit configuration register + REG_RXCONFIG equ 0x44 ; receive configuration register 0 + REG_MPC equ 0x4c ; missed packet counter + REG_9346CR equ 0x50 ; serial eeprom 93C46 command register + REG_CONFIG1 equ 0x52 ; configuration register 1 + REG_MSR equ 0x58 + REG_CONFIG4 equ 0x5a ; configuration register 4 + REG_HLTCLK equ 0x5b ; undocumented halt clock register + REG_BMCR equ 0x62 ; basic mode control register + REG_ANAR equ 0x66 ; auto negotiation advertisement register + REG_9346CR_WE equ 11b SHL 6 - BIT_RUNT equ 4 ; total packet length < 64 bytes - BIT_LONG equ 3 ; total packet length > 4k - BIT_CRC equ 2 ; crc error occured - BIT_FAE equ 1 ; frame alignment error occured - BIT_ROK equ 0 ; received packet is ok + BIT_RUNT equ 4 ; total packet length < 64 bytes + BIT_LONG equ 3 ; total packet length > 4k + BIT_CRC equ 2 ; crc error occured + BIT_FAE equ 1 ; frame alignment error occured + BIT_ROK equ 0 ; received packet is ok - BIT_RST equ 4 ; reset bit - BIT_RE equ 3 ; receiver enabled - BIT_TE equ 2 ; transmitter enabled - BUFE equ 1 ; rx buffer is empty, no packet stored + BIT_RST equ 4 ; reset bit + BIT_RE equ 3 ; receiver enabled + BIT_TE equ 2 ; transmitter enabled + BUFE equ 1 ; rx buffer is empty, no packet stored - BIT_ISR_TOK equ 2 ; transmit ok - BIT_ISR_RER equ 1 ; receive error interrupt - BIT_ISR_ROK equ 0 ; receive ok + BIT_ISR_TOK equ 2 ; transmit ok + BIT_ISR_RER equ 1 ; receive error interrupt + BIT_ISR_ROK equ 0 ; receive ok - BIT_TX_MXDMA equ 8 ; Max DMA burst size per Tx DMA burst - BIT_TXRR equ 4 ; Tx Retry count 16+(TXRR*16) + BIT_TX_MXDMA equ 8 ; Max DMA burst size per Tx DMA burst + BIT_TXRR equ 4 ; Tx Retry count 16+(TXRR*16) - BIT_RXFTH equ 13 ; Rx fifo threshold - BIT_RBLEN equ 11 ; Ring buffer length indicator - BIT_RX_MXDMA equ 8 ; Max DMA burst size per Rx DMA burst - BIT_NOWRAP equ 7 ; transfered data wrapping - BIT_9356SEL equ 6 ; eeprom selector 9346/9356 - BIT_AER equ 5 ; accept error packets - BIT_AR equ 4 ; accept runt packets - BIT_AB equ 3 ; accept broadcast packets - BIT_AM equ 2 ; accept multicast packets - BIT_APM equ 1 ; accept physical match packets - BIT_AAP equ 0 ; accept all packets + BIT_RXFTH equ 13 ; Rx fifo threshold + BIT_RBLEN equ 11 ; Ring buffer length indicator + BIT_RX_MXDMA equ 8 ; Max DMA burst size per Rx DMA burst + BIT_NOWRAP equ 7 ; transfered data wrapping + BIT_9356SEL equ 6 ; eeprom selector 9346/9356 + BIT_AER equ 5 ; accept error packets + BIT_AR equ 4 ; accept runt packets + BIT_AB equ 3 ; accept broadcast packets + BIT_AM equ 2 ; accept multicast packets + BIT_APM equ 1 ; accept physical match packets + BIT_AAP equ 0 ; accept all packets - BIT_93C46_EEM1 equ 7 ; RTL8139 eeprom operating mode1 - BIT_93C46_EEM0 equ 6 ; RTL8139 eeprom operating mode0 - BIT_93C46_EECS equ 3 ; chip select - BIT_93C46_EESK equ 2 ; serial data clock - BIT_93C46_EEDI equ 1 ; serial data input - BIT_93C46_EEDO equ 0 ; serial data output + BIT_93C46_EEM1 equ 7 ; RTL8139 eeprom operating mode1 + BIT_93C46_EEM0 equ 6 ; RTL8139 eeprom operating mode0 + BIT_93C46_EECS equ 3 ; chip select + BIT_93C46_EESK equ 2 ; serial data clock + BIT_93C46_EEDI equ 1 ; serial data input + BIT_93C46_EEDO equ 0 ; serial data output - BIT_LWACT equ 4 ; see REG_CONFIG1 - BIT_SLEEP equ 1 ; sleep bit at older chips - BIT_PWRDWN equ 0 ; power down bit at older chips - BIT_PMEn equ 0 ; power management enabled + BIT_LWACT equ 4 ; see REG_CONFIG1 + BIT_SLEEP equ 1 ; sleep bit at older chips + BIT_PWRDWN equ 0 ; power down bit at older chips + BIT_PMEn equ 0 ; power management enabled - BIT_LWPTN equ 2 ; see REG_CONFIG4 + BIT_LWPTN equ 2 ; see REG_CONFIG4 - BIT_ERTXTH equ 16 ; early TX threshold - BIT_TOK equ 15 ; transmit ok - BIT_OWN equ 13 ; tx DMA operation is completed + BIT_ERTXTH equ 16 ; early TX threshold + BIT_TOK equ 15 ; transmit ok + BIT_OWN equ 13 ; tx DMA operation is completed - BIT_ANE equ 12 ; auto negotiation enable + BIT_ANE equ 12 ; auto negotiation enable - BIT_TXFD equ 8 ; 100base-T full duplex - BIT_TX equ 7 ; 100base-T - BIT_10FD equ 6 ; 10base-T full duplex - BIT_10 equ 5 ; 10base-T - BIT_SELECTOR equ 0 ; binary encoded selector CSMA/CD=00001 + BIT_TXFD equ 8 ; 100base-T full duplex + BIT_TX equ 7 ; 100base-T + BIT_10FD equ 6 ; 10base-T full duplex + BIT_10 equ 5 ; 10base-T + BIT_SELECTOR equ 0 ; binary encoded selector CSMA/CD=00001 - BIT_IFG1 equ 25 - BIT_IFG0 equ 24 + BIT_IFG1 equ 25 + BIT_IFG0 equ 24 - TXRR equ 8 ; total retries = 16+(TXRR*16) - TX_MXDMA equ 6 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=2048 - ERTXTH equ 8 ; in unit of 32 bytes e.g:(8*32)=256 - RX_MXDMA equ 7 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=unlimited - RXFTH equ 7 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=no threshold + TXRR equ 8 ; total retries = 16+(TXRR*16) + TX_MXDMA equ 6 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=2048 + ERTXTH equ 8 ; in unit of 32 bytes e.g:(8*32)=256 + RX_MXDMA equ 7 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=unlimited + RXFTH equ 7 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=no threshold - RX_CONFIG equ (RBLEN shl BIT_RBLEN) or \ - (RX_MXDMA shl BIT_RX_MXDMA) or \ - (1 shl BIT_NOWRAP) or \ - (RXFTH shl BIT_RXFTH) or\ - (1 shl BIT_AB) or \ ; Accept broadcast packets - (1 shl BIT_APM) or \ ; Accept physical match packets - (1 shl BIT_AER) or \ ; Accept error packets - (1 shl BIT_AR) or \ ; Accept Runt packets (smaller then 64 bytes) - (1 shl BIT_AM) ; Accept multicast packets + RX_CONFIG equ (RBLEN shl BIT_RBLEN) or \ + (RX_MXDMA shl BIT_RX_MXDMA) or \ + (1 shl BIT_NOWRAP) or \ + (RXFTH shl BIT_RXFTH) or\ + (1 shl BIT_AB) or \ ; Accept broadcast packets + (1 shl BIT_APM) or \ ; Accept physical match packets + (1 shl BIT_AER) or \ ; Accept error packets + (1 shl BIT_AR) or \ ; Accept Runt packets (smaller then 64 bytes) + (1 shl BIT_AM) ; Accept multicast packets - RX_BUFFER_SIZE equ (8192 shl RBLEN);+16 - MAX_ETH_FRAME_SIZE equ 1516 ; exactly 1514 wthout CRC - NUM_TX_DESC equ 4 + RX_BUFFER_SIZE equ (8192 shl RBLEN);+16 + MAX_ETH_FRAME_SIZE equ 1516 ; exactly 1514 wthout CRC + NUM_TX_DESC equ 4 - EE_93C46_REG_ETH_ID equ 7 ; MAC offset - EE_93C46_READ_CMD equ (6 shl 6) ; 110b + 6bit address - EE_93C56_READ_CMD equ (6 shl 8) ; 110b + 8bit address - EE_93C46_CMD_LENGTH equ 9 ; start bit + cmd + 6bit address - EE_93C56_CMD_LENGTH equ 11 ; start bit + cmd + 8bit ddress + EE_93C46_REG_ETH_ID equ 7 ; MAC offset + EE_93C46_READ_CMD equ (6 shl 6) ; 110b + 6bit address + EE_93C56_READ_CMD equ (6 shl 8) ; 110b + 8bit address + EE_93C46_CMD_LENGTH equ 9 ; start bit + cmd + 6bit address + EE_93C56_CMD_LENGTH equ 11 ; start bit + cmd + 8bit ddress - VER_RTL8139 equ 1100000b - VER_RTL8139A equ 1110000b - VER_RTL8139AG equ 1110100b - VER_RTL8139B equ 1111000b - VER_RTL8130 equ VER_RTL8139B - VER_RTL8139C equ 1110100b - VER_RTL8100 equ 1111010b - VER_RTL8100B equ 1110101b - VER_RTL8139D equ VER_RTL8100B - VER_RTL8139CP equ 1110110b - VER_RTL8101 equ 1110111b + VER_RTL8139 equ 1100000b + VER_RTL8139A equ 1110000b + VER_RTL8139AG equ 1110100b + VER_RTL8139B equ 1111000b + VER_RTL8130 equ VER_RTL8139B + VER_RTL8139C equ 1110100b + VER_RTL8100 equ 1111010b + VER_RTL8100B equ 1110101b + VER_RTL8139D equ VER_RTL8100B + VER_RTL8139CP equ 1110110b + VER_RTL8101 equ 1110111b - IDX_RTL8139 equ 0 - IDX_RTL8139A equ 1 - IDX_RTL8139B equ 2 - IDX_RTL8139C equ 3 - IDX_RTL8100 equ 4 - IDX_RTL8139D equ 5 - IDX_RTL8139D equ 6 - IDX_RTL8101 equ 7 + IDX_RTL8139 equ 0 + IDX_RTL8139A equ 1 + IDX_RTL8139B equ 2 + IDX_RTL8139C equ 3 + IDX_RTL8100 equ 4 + IDX_RTL8139D equ 5 + IDX_RTL8139D equ 6 + IDX_RTL8101 equ 7 - ISR_SERR equ 1 SHL 15 - ISR_TIMEOUT equ 1 SHL 14 - ISR_LENCHG equ 1 SHL 13 - ISR_FIFOOVW equ 1 SHL 6 - ISR_PUN equ 1 SHL 5 - ISR_RXOVW equ 1 SHL 4 - ISR_TER equ 1 SHL 3 - ISR_TOK equ 1 SHL 2 - ISR_RER equ 1 SHL 1 - ISR_ROK equ 1 SHL 0 + ISR_SERR equ 1 SHL 15 + ISR_TIMEOUT equ 1 SHL 14 + ISR_LENCHG equ 1 SHL 13 + ISR_FIFOOVW equ 1 SHL 6 + ISR_PUN equ 1 SHL 5 + ISR_RXOVW equ 1 SHL 4 + ISR_TER equ 1 SHL 3 + ISR_TOK equ 1 SHL 2 + ISR_RER equ 1 SHL 1 + ISR_ROK equ 1 SHL 0 - INTERRUPT_MASK equ ISR_ROK or \ - ISR_RXOVW or \ - ISR_PUN or \ - ISR_FIFOOVW or \ - ISR_LENCHG or \ - ISR_TOK or \ - ISR_TER + INTERRUPT_MASK equ ISR_ROK or \ + ISR_RXOVW or \ + ISR_PUN or \ + ISR_FIFOOVW or \ + ISR_LENCHG or \ + ISR_TOK or \ + ISR_TER - TSR_OWN equ 1 SHL 13 - TSR_TUN equ 1 SHL 14 - TSR_TOK equ 1 SHL 15 + TSR_OWN equ 1 SHL 13 + TSR_TUN equ 1 SHL 14 + TSR_TOK equ 1 SHL 15 - TSR_CDH equ 1 SHL 28 - TSR_OWC equ 1 SHL 29 - TSR_TABT equ 1 SHL 30 - TSR_CRS equ 1 SHL 31 + TSR_CDH equ 1 SHL 28 + TSR_OWC equ 1 SHL 29 + TSR_TABT equ 1 SHL 30 + TSR_CRS equ 1 SHL 31 virtual at ebx - device: + device: - ETH_DEVICE + ETH_DEVICE - .rx_buffer dd ? - .tx_buffer dd ? + .rx_buffer dd ? + .tx_buffer dd ? - .rx_data_offset dd ? - .io_addr dd ? + .rx_data_offset dd ? + .io_addr dd ? - .curr_tx_desc db ? - .pci_bus db ? - .pci_dev db ? - .irq_line db ? - .hw_ver_id db ? + .curr_tx_desc db ? + .pci_bus db ? + .pci_dev db ? + .irq_line db ? + .hw_ver_id db ? - .TX_DESC rd NUM_TX_DESC + .TX_DESC rd NUM_TX_DESC - .size = $ - device + .size = $ - device end virtual @@ -232,19 +232,19 @@ section '.flat' code readable align 16 align 4 proc START stdcall, state:dword - cmp [state], 1 - jne .exit + cmp [state], 1 + jne .exit .entry: - DEBUGF 2,"Loading rtl8139 driver\n" - stdcall RegService, my_service, service_proc - ret + DEBUGF 2,"Loading rtl8139 driver\n" + stdcall RegService, my_service, service_proc + ret .fail: .exit: - xor eax, eax - ret + xor eax, eax + ret endp @@ -259,133 +259,133 @@ endp align 4 proc service_proc stdcall, ioctl:dword - mov edx, [ioctl] - mov eax, [IOCTL.io_code] + mov edx, [ioctl] + mov eax, [IOCTL.io_code] ;------------------------------------------------------ - cmp eax, 0 ;SRV_GETVERSION - jne @F + cmp eax, 0 ;SRV_GETVERSION + jne @F - cmp [IOCTL.out_size], 4 - jl .fail - mov eax, [IOCTL.output] - mov [eax], dword API_VERSION + cmp [IOCTL.out_size], 4 + jl .fail + mov eax, [IOCTL.output] + mov [eax], dword API_VERSION - xor eax, eax - ret + xor eax, eax + ret ;------------------------------------------------------ @@: - cmp eax, 1 ;SRV_HOOK - jne .fail + cmp eax, 1 ;SRV_HOOK + jne .fail - cmp [IOCTL.inp_size], 3 ; Data input must be at least 3 bytes - jl .fail + cmp [IOCTL.inp_size], 3 ; Data input must be at least 3 bytes + jl .fail - mov eax, [IOCTL.input] - cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given - jne .fail ; other types arent supported for this card yet + mov eax, [IOCTL.input] + cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given + jne .fail ; other types arent supported for this card yet ; check if the device is already listed - mov esi, device_list - mov ecx, [devices] - test ecx, ecx - jz .firstdevice + mov esi, device_list + mov ecx, [devices] + test ecx, ecx + jz .firstdevice ; mov eax, [IOCTL.input] ; get the pci bus and device numbers - mov ax , [eax+1] ; + mov ax , [eax+1] ; .nextdevice: - mov ebx, [esi] - cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) - je .find_devicenum ; Device is already loaded, let's find it's device number - add esi, 4 - loop .nextdevice + mov ebx, [esi] + cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) + je .find_devicenum ; Device is already loaded, let's find it's device number + add esi, 4 + loop .nextdevice ; This device doesnt have its own eth_device structure yet, lets create one .firstdevice: - cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card - jge .fail + cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card + jge .fail - allocate_and_clear ebx, device.size, .fail ; Allocate the buffer for device structure + allocate_and_clear ebx, device.size, .fail ; Allocate the buffer for device structure ; Fill in the direct call addresses into the struct - mov [device.reset], reset - mov [device.transmit], transmit - mov [device.get_MAC], read_mac - mov [device.set_MAC], write_mac - mov [device.unload], unload - mov [device.name], my_service + mov [device.reset], reset + mov [device.transmit], transmit + mov [device.get_MAC], read_mac + mov [device.set_MAC], write_mac + mov [device.unload], unload + mov [device.name], my_service ; save the pci bus and device numbers - mov eax, [IOCTL.input] - mov cl , [eax+1] - mov [device.pci_bus], cl - mov cl , [eax+2] - mov [device.pci_dev], cl + mov eax, [IOCTL.input] + mov cl , [eax+1] + mov [device.pci_bus], cl + mov cl , [eax+2] + mov [device.pci_dev], cl ; Now, it's time to find the base io addres of the PCI device - find_io [device.pci_bus], [device.pci_dev], [device.io_addr] + find_io [device.pci_bus], [device.pci_dev], [device.io_addr] ; We've found the io address, find IRQ now - find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] + find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] - DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ - [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 + DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ + [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 ; Allocate the receive buffer - stdcall CreateRingBuffer, dword (RX_BUFFER_SIZE), dword PG_SW - test eax, eax - jz .err - mov [device.rx_buffer], eax + stdcall CreateRingBuffer, dword (RX_BUFFER_SIZE), dword PG_SW + test eax, eax + jz .err + mov [device.rx_buffer], eax ; Ok, the eth_device structure is ready, let's probe the device - call probe ; this function will output in eax - test eax, eax - jnz .err ; If an error occured, exit + call probe ; this function will output in eax + test eax, eax + jnz .err ; If an error occured, exit - mov eax, [devices] ; Add the device structure to our device list - mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) - inc [devices] ; + mov eax, [devices] ; Add the device structure to our device list + mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) + inc [devices] ; - mov [device.type], NET_TYPE_ETH - call NetRegDev + mov [device.type], NET_TYPE_ETH + call NetRegDev - cmp eax, -1 - je .destroy + cmp eax, -1 + je .destroy - ret + ret ; If the device was already loaded, find the device number and return it in eax .find_devicenum: - DEBUGF 2,"Trying to find device number of already registered device\n" - call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx - ; into a device number in edi - mov eax, edi ; Application wants it in eax instead - DEBUGF 2,"Kernel says: %u\n", eax - ret + DEBUGF 2,"Trying to find device number of already registered device\n" + call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx + ; into a device number in edi + mov eax, edi ; Application wants it in eax instead + DEBUGF 2,"Kernel says: %u\n", eax + ret ; If an error occured, remove all allocated data and exit (returning -1 in eax) .destroy: - ; todo: reset device into virgin state + ; todo: reset device into virgin state .err: - stdcall KernelFree, dword [device.rx_buffer] - stdcall KernelFree, ebx + stdcall KernelFree, dword [device.rx_buffer] + stdcall KernelFree, ebx .fail: - or eax, -1 - ret + or eax, -1 + ret ;------------------------------------------------------ endp @@ -399,15 +399,15 @@ endp align 4 unload: - ; TODO: (in this particular order) - ; - ; - Stop the device - ; - Detach int handler - ; - Remove device from local list (RTL8139_LIST) - ; - call unregister function in kernel - ; - Remove all allocated structures and buffers the card used + ; TODO: (in this particular order) + ; + ; - Stop the device + ; - Detach int handler + ; - Remove device from local list (RTL8139_LIST) + ; - call unregister function in kernel + ; - Remove all allocated structures and buffers the card used - or eax,-1 + or eax,-1 ret @@ -420,88 +420,88 @@ ret align 4 probe: - DEBUGF 2,"Probing rtl8139 device: " + DEBUGF 2,"Probing rtl8139 device: " - make_bus_master [device.pci_bus], [device.pci_dev] + make_bus_master [device.pci_bus], [device.pci_dev] ; get chip version - set_io 0 - set_io REG_TXCONFIG + 2 - in ax , dx - shr ah , 2 - shr ax , 6 - and al , 01111111b + set_io 0 + set_io REG_TXCONFIG + 2 + in ax , dx + shr ah , 2 + shr ax , 6 + and al , 01111111b - mov ecx, HW_VER_ARRAY_SIZE-1 + mov ecx, HW_VER_ARRAY_SIZE-1 .chip_ver_loop: - cmp al , [hw_ver_array + ecx] - je .chip_ver_found - dec ecx - jns .chip_ver_loop + cmp al , [hw_ver_array + ecx] + je .chip_ver_found + dec ecx + jns .chip_ver_loop .unknown: - mov ecx, 8 + mov ecx, 8 .chip_ver_found: - cmp ecx, 8 - jg .unknown + cmp ecx, 8 + jg .unknown - mov [device.hw_ver_id], cl + mov [device.hw_ver_id], cl - mov ecx, [crosslist + ecx*4] - mov [device.name], ecx + mov ecx, [crosslist + ecx*4] + mov [device.name], ecx - DEBUGF 2,"Chip version: %s\n", ecx + DEBUGF 2,"Chip version: %s\n", ecx ; wake up the chip - set_io 0 - set_io REG_HLTCLK - mov al , 'R' ; run the clock - out dx , al + set_io 0 + set_io REG_HLTCLK + mov al , 'R' ; run the clock + out dx , al ; unlock config and BMCR registers - set_io REG_9346CR - mov al , (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0) - out dx , al + set_io REG_9346CR + mov al , (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0) + out dx , al ; enable power management - set_io REG_CONFIG1 - in al , dx - cmp [device.hw_ver_id], IDX_RTL8139B - jl .old_chip + set_io REG_CONFIG1 + in al , dx + cmp [device.hw_ver_id], IDX_RTL8139B + jl .old_chip ; set LWAKE pin to active high (default value). ; it is for Wake-On-LAN functionality of some motherboards. ; this signal is used to inform the motherboard to execute a wake-up process. ; only at newer chips. - or al , (1 shl BIT_PMEn) - and al , not (1 shl BIT_LWACT) - out dx , al + or al , (1 shl BIT_PMEn) + and al , not (1 shl BIT_LWACT) + out dx , al - set_io REG_CONFIG4 - in al , dx - and al , not (1 shl BIT_LWPTN) - out dx , al + set_io REG_CONFIG4 + in al , dx + and al , not (1 shl BIT_LWPTN) + out dx , al - jmp .finish_wake_up + jmp .finish_wake_up .old_chip: ; wake up older chips - and al , not ((1 shl BIT_SLEEP) or (1 shl BIT_PWRDWN)) - out dx , al + and al , not ((1 shl BIT_SLEEP) or (1 shl BIT_PWRDWN)) + out dx , al .finish_wake_up: ; lock config and BMCR registers - xor al , al - set_io 0 - set_io REG_9346CR - out dx , al - DEBUGF 2,"done!\n" + xor al , al + set_io 0 + set_io REG_9346CR + out dx , al + DEBUGF 2,"done!\n" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -511,139 +511,139 @@ probe: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; reset: - DEBUGF 2,"Resetting rtl8139: " + DEBUGF 2,"Resetting rtl8139: " ; attach int handler - movzx eax, [device.irq_line] - DEBUGF 1,"Attaching int handler to irq %x, ",eax:1 - stdcall AttachIntHandler, eax, int_handler, dword 0 - test eax, eax - jnz @f - DEBUGF 1,"\nCould not attach int handler!\n" + movzx eax, [device.irq_line] + DEBUGF 1,"Attaching int handler to irq %x, ",eax:1 + stdcall AttachIntHandler, eax, int_handler, dword 0 + test eax, eax + jnz @f + DEBUGF 1,"\nCould not attach int handler!\n" ; or eax, -1 ; ret @@: ; reset chip - DEBUGF 1,"Resetting chip\n" - set_io 0 - set_io REG_COMMAND - mov al , 1 shl BIT_RST - out dx , al - mov cx , 1000 ; wait no longer for the reset + DEBUGF 1,"Resetting chip\n" + set_io 0 + set_io REG_COMMAND + mov al , 1 shl BIT_RST + out dx , al + mov cx , 1000 ; wait no longer for the reset .wait_for_reset: - in al , dx - test al , 1 shl BIT_RST - jz .reset_completed ; RST remains 1 during reset - dec cx - jns .wait_for_reset + in al , dx + test al , 1 shl BIT_RST + jz .reset_completed ; RST remains 1 during reset + dec cx + jns .wait_for_reset .reset_completed: ; unlock config and BMCR registers - set_io REG_9346CR - mov al , (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0) - out dx , al + set_io REG_9346CR + mov al , (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0) + out dx , al ; initialize multicast registers (no filtering) - mov eax, 0xffffffff - set_io REG_MAR0 - out dx , eax - set_io REG_MAR4 - out dx , eax + mov eax, 0xffffffff + set_io REG_MAR0 + out dx , eax + set_io REG_MAR4 + out dx , eax ; enable Rx/Tx - mov al , (1 shl BIT_RE) or (1 shl BIT_TE) - set_io REG_COMMAND - out dx , al + mov al , (1 shl BIT_RE) or (1 shl BIT_TE) + set_io REG_COMMAND + out dx , al ; Rxbuffer size, unlimited dma burst, no wrapping, no rx threshold ; accept broadcast packets, accept physical match packets - mov ax , RX_CONFIG - set_io REG_RXCONFIG - out dx , ax + mov ax , RX_CONFIG + set_io REG_RXCONFIG + out dx , ax ; 1024 bytes DMA burst, total retries = 16 + 8 * 16 = 144 - mov eax , (TX_MXDMA shl BIT_TX_MXDMA) or (TXRR shl BIT_TXRR) or BIT_IFG1 or BIT_IFG0 - set_io REG_TXCONFIG - out dx , eax + mov eax , (TX_MXDMA shl BIT_TX_MXDMA) or (TXRR shl BIT_TXRR) or BIT_IFG1 or BIT_IFG0 + set_io REG_TXCONFIG + out dx , eax ; enable auto negotiation - set_io REG_BMCR - in ax , dx - or ax , (1 shl BIT_ANE) - out dx , ax + set_io REG_BMCR + in ax , dx + or ax , (1 shl BIT_ANE) + out dx , ax ; set auto negotiation advertisement - set_io REG_ANAR - in ax , dx - or ax , (1 shl BIT_SELECTOR) or (1 shl BIT_10) or (1 shl BIT_10FD) or (1 shl BIT_TX) or (1 shl BIT_TXFD) - out dx , ax + set_io REG_ANAR + in ax , dx + or ax , (1 shl BIT_SELECTOR) or (1 shl BIT_10) or (1 shl BIT_10FD) or (1 shl BIT_TX) or (1 shl BIT_TXFD) + out dx , ax ; lock config and BMCR registers - xor eax, eax - set_io REG_9346CR - out dx , al + xor eax, eax + set_io REG_9346CR + out dx , al ; init RX/TX pointers - mov [device.rx_data_offset], eax - mov [device.curr_tx_desc], al + mov [device.rx_data_offset], eax + mov [device.curr_tx_desc], al ; set_io REG_CAPR ; out dx , ax ; clear packet/byte counters - lea edi, [device.bytes_tx] - mov ecx, 6 - rep stosd + lea edi, [device.bytes_tx] + mov ecx, 6 + rep stosd ; clear missing packet counter - set_io REG_MPC - out dx , eax + set_io REG_MPC + out dx , eax ; set RxBuffer address, init RX buffer offset - mov eax, [device.rx_buffer] - mov dword[eax], 0 - DEBUGF 2,"RX buffer:%x\n", eax - GetRealAddr - DEBUGF 2,"RX buffer:%X\n", eax - set_io REG_RBSTART - out dx , eax + mov eax, [device.rx_buffer] + mov dword[eax], 0 + DEBUGF 2,"RX buffer:%x\n", eax + GetRealAddr + DEBUGF 2,"RX buffer:%X\n", eax + set_io REG_RBSTART + out dx , eax ; Read MAC address - call read_mac + call read_mac ; enable interrupts - set_io 0 - set_io REG_IMR - mov eax, INTERRUPT_MASK - out dx , ax + set_io 0 + set_io REG_IMR + mov eax, INTERRUPT_MASK + out dx , ax ; Set the mtu, kernel will be able to send now - mov [device.mtu], 1514 + mov [device.mtu], 1514 ; Indicate that we have successfully reset the card - DEBUGF 2,"Done!\n" - xor eax, eax + DEBUGF 2,"Done!\n" + xor eax, eax - ret + ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -657,78 +657,79 @@ reset: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; align 4 transmit: - DEBUGF 1,"\nTransmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8] - mov eax, [esp+4] - DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ - [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ - [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ - [eax+13]:2,[eax+12]:2 + DEBUGF 1,"\nTransmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8] + mov eax, [esp+4] + DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ + [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ + [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ + [eax+13]:2,[eax+12]:2 - cmp dword [esp+8], MAX_ETH_FRAME_SIZE - jg .fail - cmp dword [esp+8], 60 - jl .fail + cmp dword [esp+8], MAX_ETH_FRAME_SIZE + jg .fail + cmp dword [esp+8], 60 + jl .fail ; check if we own the current discriptor - set_io 0 - set_io REG_TSD0 - movzx ecx, [device.curr_tx_desc] - shl ecx, 2 - add edx, ecx - in eax, dx - test eax, (1 shl BIT_OWN) - jz .wait_to_send + set_io 0 + set_io REG_TSD0 + movzx ecx, [device.curr_tx_desc] + shl ecx, 2 + add edx, ecx + in eax, dx + test eax, (1 shl BIT_OWN) + jz .wait_to_send .send_packet: ; get next descriptor - inc [device.curr_tx_desc] - and [device.curr_tx_desc], NUM_TX_DESC-1 + inc [device.curr_tx_desc] + and [device.curr_tx_desc], NUM_TX_DESC-1 ; Update stats - inc [device.packets_tx] - mov eax, [esp+8] - add dword [device.bytes_tx], eax - adc dword [device.bytes_tx + 4], 0 + inc [device.packets_tx] + mov eax, [esp+8] + add dword [device.bytes_tx], eax + adc dword [device.bytes_tx + 4], 0 ; Set the buffer address - set_io REG_TSAD0 - mov eax, [esp+4] - mov [device.TX_DESC+ecx], eax - GetRealAddr - out dx, eax + set_io REG_TSAD0 + mov eax, [esp+4] + mov [device.TX_DESC+ecx], eax + GetRealAddr + out dx, eax ; And the size of the buffer - set_io REG_TSD0 - mov eax, [esp+8] - or eax, (ERTXTH shl BIT_ERTXTH) ; Early threshold - out dx, eax + set_io REG_TSD0 + mov eax, [esp+8] + or eax, (ERTXTH shl BIT_ERTXTH) ; Early threshold + out dx, eax - DEBUGF 1,"Packet Sent!\n" - xor eax, eax - ret 8 + DEBUGF 1,"Packet Sent!\n" + xor eax, eax + ret 8 .wait_to_send: - DEBUGF 1,"Waiting for timeout\n" + DEBUGF 1,"Waiting for timeout\n" - push edx - mov esi, 300 - stdcall Sleep - pop edx + push edx + mov esi, 300 + stdcall Sleep + pop edx - in ax, dx - test ax, (1 shl BIT_OWN) - jnz .send_packet + in ax, dx + test ax, (1 shl BIT_OWN) + jnz .send_packet - pusha - call reset ; if chip hung, reset it - popa + pusha + call reset ; if chip hung, reset it + popa - jmp .send_packet + jmp .send_packet .fail: - DEBUGF 1,"failed!\n" - stdcall KernelFree, [esp+4] - ret 8 + DEBUGF 1,"failed!\n" + stdcall KernelFree, [esp+4] + or eax, -1 + ret 8 @@ -742,31 +743,31 @@ transmit: align 4 int_handler: - DEBUGF 1,"\nIRQ %x\n", eax:2 ; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO + DEBUGF 1,"\nIRQ %x\n", eax:2 ; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO ; find pointer of device wich made IRQ occur - mov esi, device_list - mov ecx, [devices] - test ecx, ecx - jz .fail + mov esi, device_list + mov ecx, [devices] + test ecx, ecx + jz .fail .nextdevice: - mov ebx, dword [esi] + mov ebx, dword [esi] - set_io 0 - set_io REG_ISR - in ax , dx - out dx , ax ; send it back to ACK + set_io 0 + set_io REG_ISR + in ax , dx + out dx , ax ; send it back to ACK - add esi, 4 + add esi, 4 - test ax , ax - jnz .got_it + test ax , ax + jnz .got_it - dec ecx - jnz .nextdevice + dec ecx + jnz .nextdevice - ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) + ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) .got_it: @@ -776,135 +777,135 @@ int_handler: ;---------------------------------------------------- ; Received packet ok? - test ax, ISR_ROK - jz @f - push ax + test ax, ISR_ROK + jz @f + push ax .receive: - set_io 0 - set_io REG_COMMAND - in al , dx - test al , BUFE ; test if RX buffer is empty - jnz .finish ; + set_io 0 + set_io REG_COMMAND + in al , dx + test al , BUFE ; test if RX buffer is empty + jnz .finish ; - DEBUGF 1,"RX: " + DEBUGF 1,"RX: " - mov eax, [device.rx_buffer] - add eax, [device.rx_data_offset] - test byte [eax], (1 shl BIT_ROK) ; check if packet is ok - jz .reset_rx + mov eax, [device.rx_buffer] + add eax, [device.rx_data_offset] + test byte [eax], (1 shl BIT_ROK) ; check if packet is ok + jz .reset_rx ; packet is ok, copy it - movzx ecx, word [eax+2] ; packet length + movzx ecx, word [eax+2] ; packet length - sub ecx, 4 ; don't copy CRC + sub ecx, 4 ; don't copy CRC ; Update stats - add dword [device.bytes_rx], ecx - adc dword [device.bytes_rx + 4], 0 - inc dword [device.packets_rx] + add dword [device.bytes_rx], ecx + adc dword [device.bytes_rx + 4], 0 + inc dword [device.packets_rx] - DEBUGF 1,"Received %u bytes\n", ecx + DEBUGF 1,"Received %u bytes\n", ecx - push ebx eax ecx - stdcall KernelAlloc, ecx ; Allocate a buffer to put packet into - pop ecx - test eax, eax ; Test if we allocated succesfully - jz .abort + push ebx eax ecx + stdcall KernelAlloc, ecx ; Allocate a buffer to put packet into + pop ecx + test eax, eax ; Test if we allocated succesfully + jz .abort - mov edi, eax ; Where we will copy too + mov edi, eax ; Where we will copy too - mov esi, [esp] ; The buffer we will copy from - add esi, 4 ; Dont copy CRC + mov esi, [esp] ; The buffer we will copy from + add esi, 4 ; Dont copy CRC - push dword .abort ; Kernel will return to this address after EthReceiver - push ecx edi ; Save buffer pointer and size, to pass to kernel + push dword .abort ; Kernel will return to this address after EthReceiver + push ecx edi ; Save buffer pointer and size, to pass to kernel .copy: - shr ecx, 1 - jnc .nb - movsb + shr ecx, 1 + jnc .nb + movsb .nb: - shr ecx, 1 - jnc .nw - movsw + shr ecx, 1 + jnc .nw + movsw .nw: - jz .nd - rep movsd + jz .nd + rep movsd .nd: - jmp EthReceiver ; Send it to kernel + jmp EthReceiver ; Send it to kernel .abort: - pop eax ebx - ; update eth_data_start_offset - movzx eax, word [eax+2] ; packet length - add eax, [device.rx_data_offset] - add eax, 4+3 ; packet header is 4 bytes long + dword alignment - and eax, not 3 ; dword alignment + pop eax ebx + ; update eth_data_start_offset + movzx eax, word [eax+2] ; packet length + add eax, [device.rx_data_offset] + add eax, 4+3 ; packet header is 4 bytes long + dword alignment + and eax, not 3 ; dword alignment - cmp eax, RX_BUFFER_SIZE - jl .no_wrap - DEBUGF 2,"Wrapping" - sub eax, RX_BUFFER_SIZE + cmp eax, RX_BUFFER_SIZE + jl .no_wrap + DEBUGF 2,"Wrapping" + sub eax, RX_BUFFER_SIZE .no_wrap: - mov [device.rx_data_offset], eax - DEBUGF 1,"New RX ptr: %d\n", eax + mov [device.rx_data_offset], eax + DEBUGF 1,"New RX ptr: %d\n", eax - set_io 0 - set_io REG_CAPR ; update 'Current Address of Packet Read register' - sub eax, 0x10 ; value 0x10 is a constant for CAPR - out dx , ax + set_io 0 + set_io REG_CAPR ; update 'Current Address of Packet Read register' + sub eax, 0x10 ; value 0x10 is a constant for CAPR + out dx , ax - jmp .receive ; check for multiple packets + jmp .receive ; check for multiple packets .reset_rx: - test byte [eax], (1 shl BIT_CRC) - jz .no_crc_error - DEBUGF 2,"\nCRC error!\n" + test byte [eax], (1 shl BIT_CRC) + jz .no_crc_error + DEBUGF 2,"\nCRC error!\n" .no_crc_error: - test byte [eax], (1 shl BIT_FAE) - jz .no_fae_error - DEBUGF 1,"\nFrame alignment error!\n" + test byte [eax], (1 shl BIT_FAE) + jz .no_fae_error + DEBUGF 1,"\nFrame alignment error!\n" .no_fae_error: - DEBUGF 1,"Reset RX\n" - in al , dx ; read command register - push ax + DEBUGF 1,"Reset RX\n" + in al , dx ; read command register + push ax - and al , not (1 shl BIT_RE) ; Clear the RE bit - out dx , al + and al , not (1 shl BIT_RE) ; Clear the RE bit + out dx , al - pop ax - out dx , al ; write original command back + pop ax + out dx , al ; write original command back - add edx, REG_RXCONFIG - REG_COMMAND ; Restore RX configuration - mov ax , RX_CONFIG - out dx , ax + add edx, REG_RXCONFIG - REG_COMMAND ; Restore RX configuration + mov ax , RX_CONFIG + out dx , ax .finish: - pop ax + pop ax ;---------------------------------------------------- ; Transmit ok / Transmit error @@: - test ax, ISR_TOK + ISR_TER - jz @f + test ax, ISR_TOK + ISR_TER + jz @f - push ax - xor ecx, ecx + push ax + xor ecx, ecx .txdesloop: - set_io 0 - set_io REG_TSD0 - add edx, ecx - in eax, dx + set_io 0 + set_io REG_TSD0 + add edx, ecx + in eax, dx - test eax, TSR_OWN ; DMA operation completed - jz .notthisone + test eax, TSR_OWN ; DMA operation completed + jz .notthisone - cmp [device.TX_DESC+ecx], 0 - je .notthisone + cmp [device.TX_DESC+ecx], 0 + je .notthisone ; .notxd: ; test eax, TSR_TUN @@ -928,67 +929,67 @@ int_handler: ; ; .nocsl: - DEBUGF 1,"TX OK: free buffer %x\n", [device.TX_DESC+ecx]:8 - push ecx ebx - stdcall KernelFree, [device.TX_DESC+ecx] - pop ebx ecx - mov [device.TX_DESC+ecx], 0 + DEBUGF 1,"TX OK: free buffer %x\n", [device.TX_DESC+ecx]:8 + push ecx ebx + stdcall KernelFree, [device.TX_DESC+ecx] + pop ebx ecx + mov [device.TX_DESC+ecx], 0 .notthisone: - add ecx, 4 - cmp ecx, 16 - jl .txdesloop - pop ax + add ecx, 4 + cmp ecx, 16 + jl .txdesloop + pop ax ;---------------------------------------------------- ; Rx buffer overflow ? @@: - test ax, ISR_RXOVW - jz @f + test ax, ISR_RXOVW + jz @f - push ax - DEBUGF 2,"RX-buffer overflow!\n" + push ax + DEBUGF 2,"RX-buffer overflow!\n" - set_io 0 - set_io REG_ISR - mov ax , ISR_FIFOOVW or ISR_RXOVW - out dx , ax - pop ax + set_io 0 + set_io REG_ISR + mov ax , ISR_FIFOOVW or ISR_RXOVW + out dx , ax + pop ax ;---------------------------------------------------- ; Packet underrun? @@: - test ax, ISR_PUN - jz @f + test ax, ISR_PUN + jz @f - DEBUGF 2,"Packet underrun!\n" + DEBUGF 2,"Packet underrun!\n" ;---------------------------------------------------- ; Receive FIFO overflow ? @@: - test ax, ISR_FIFOOVW - jz @f + test ax, ISR_FIFOOVW + jz @f - push ax - DEBUGF 2,"RX fifo overflow!\n" + push ax + DEBUGF 2,"RX fifo overflow!\n" - set_io 0 - set_io REG_ISR - mov ax , ISR_FIFOOVW or ISR_RXOVW - out dx , ax - pop ax + set_io 0 + set_io REG_ISR + mov ax , ISR_FIFOOVW or ISR_RXOVW + out dx , ax + pop ax ;---------------------------------------------------- ; Something about Cable changed ? @@: - test ax, ISR_LENCHG - jz .fail + test ax, ISR_LENCHG + jz .fail - DEBUGF 2,"Cable changed!\n" - call cable + DEBUGF 2,"Cable changed!\n" + call cable .fail: - ret + ret @@ -1001,11 +1002,11 @@ int_handler: align 4 cable: - DEBUGF 1,"Checking Cable status: " + DEBUGF 1,"Checking Cable status: " - mov edx, dword [device.io_addr] - add edx, REG_MSR - in al , dx + mov edx, dword [device.io_addr] + add edx, REG_MSR + in al , dx ; test al , 1 SHL 2 ; 0 = link ok 1 = link fail ; jnz .notconnected @@ -1013,11 +1014,11 @@ cable: ; test al , 1 SHL 3 ; 0 = 100 Mbps 1 = 10 Mbps ; jnz .10mbps - shr al, 2 - and al, 3 + shr al, 2 + and al, 3 - mov byte [device.mode+3], al - DEBUGF 1,"Done!\n" + mov byte [device.mode+3], al + DEBUGF 1,"Done!\n" ret @@ -1029,49 +1030,49 @@ ret ;;;;;;;;;;;;;;;;;;;;;;; align 4 -write_mac: ; in: mac pushed onto stack (as 3 words) +write_mac: ; in: mac pushed onto stack (as 3 words) - DEBUGF 2,"Writing MAC: " + DEBUGF 2,"Writing MAC: " ; disable all in command registers - set_io 0 - set_io REG_9346CR - xor eax, eax - out dx , al + set_io 0 + set_io REG_9346CR + xor eax, eax + out dx , al - set_io REG_IMR - xor eax, eax - out dx , ax + set_io REG_IMR + xor eax, eax + out dx , ax - set_io REG_ISR - mov eax, -1 - out dx , ax + set_io REG_ISR + mov eax, -1 + out dx , ax ; enable writing - set_io REG_9346CR - mov eax, REG_9346CR_WE - out dx , al + set_io REG_9346CR + mov eax, REG_9346CR_WE + out dx , al ; write the mac ... - set_io REG_IDR0 - pop eax - out dx , eax + set_io REG_IDR0 + pop eax + out dx , eax - set_io REG_IDR0+4 - xor eax, eax - pop ax - out dx , eax + set_io REG_IDR0+4 + xor eax, eax + pop ax + out dx , eax ; disable writing - set_io REG_9346CR - xor eax, eax - out dx , al + set_io REG_9346CR + xor eax, eax + out dx , al - DEBUGF 2,"ok!\n" + DEBUGF 2,"ok!\n" ; Notice this procedure does not ret, but continues to read_mac instead. @@ -1083,65 +1084,65 @@ write_mac: ; in: mac pushed onto stack (as 3 words) ;;;;;;;;;;;;;;;;;;;;;; read_mac: - DEBUGF 2,"Reading MAC: " + DEBUGF 2,"Reading MAC: " - set_io 0 - lea edi, [device.mac] - in eax, dx - stosd - add edx, 4 - in ax, dx - stosw + set_io 0 + lea edi, [device.mac] + in eax, dx + stosd + add edx, 4 + in ax, dx + stosw - DEBUGF 2,"%x-%x-%x-%x-%x-%x\n",[edi-6]:2,[edi-5]:2,[edi-4]:2,[edi-3]:2,[edi-2]:2,[edi-1]:2 + DEBUGF 2,"%x-%x-%x-%x-%x-%x\n",[edi-6]:2,[edi-5]:2,[edi-4]:2,[edi-3]:2,[edi-2]:2,[edi-1]:2 - ret + ret ; End of code section '.data' data readable writable align 16 ; place all uninitialized data place here -align 4 ; Place all initialised data here +align 4 ; Place all initialised data here -devices dd 0 -version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) -my_service db 'RTL8139',0 ; max 16 chars include zero +devices dd 0 +version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) +my_service db 'RTL8139',0 ; max 16 chars include zero -device_1 db 'Realtek 8139',0 -device_2 db 'Realtek 8139A',0 -device_3 db 'Realtek 8139B',0 -device_4 db 'Realtek 8139C',0 -device_5 db 'Realtek 8100',0 -device_6 db 'Realtek 8139D',0 -device_7 db 'Realtek 8139CP',0 -device_8 db 'Realtek 8101',0 -device_unknown db 'Unknown RTL8139 clone', 0 +device_1 db 'Realtek 8139',0 +device_2 db 'Realtek 8139A',0 +device_3 db 'Realtek 8139B',0 +device_4 db 'Realtek 8139C',0 +device_5 db 'Realtek 8100',0 +device_6 db 'Realtek 8139D',0 +device_7 db 'Realtek 8139CP',0 +device_8 db 'Realtek 8101',0 +device_unknown db 'Unknown RTL8139 clone', 0 crosslist: - dd device_1 - dd device_2 - dd device_3 - dd device_4 - dd device_5 - dd device_6 - dd device_7 - dd device_8 - dd device_unknown + dd device_1 + dd device_2 + dd device_3 + dd device_4 + dd device_5 + dd device_6 + dd device_7 + dd device_8 + dd device_unknown -hw_ver_array: ; This array is used by the probe routine to find out wich version of the RTL8139 we are working with - db VER_RTL8139 - db VER_RTL8139A - db VER_RTL8139B - db VER_RTL8139C - db VER_RTL8100 - db VER_RTL8139D - db VER_RTL8139CP - db VER_RTL8101 - db 0 +hw_ver_array: ; This array is used by the probe routine to find out wich version of the RTL8139 we are working with + db VER_RTL8139 + db VER_RTL8139A + db VER_RTL8139B + db VER_RTL8139C + db VER_RTL8100 + db VER_RTL8139D + db VER_RTL8139CP + db VER_RTL8101 + db 0 HW_VER_ARRAY_SIZE = $-hw_ver_array -include_debug_strings ; All data wich FDO uses will be included here +include_debug_strings ; All data wich FDO uses will be included here -device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling +device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling diff --git a/kernel/branches/net/drivers/RTL8169.asm b/kernel/branches/net/drivers/RTL8169.asm index 165ae8702..4c76f50c5 100644 --- a/kernel/branches/net/drivers/RTL8169.asm +++ b/kernel/branches/net/drivers/RTL8169.asm @@ -22,17 +22,17 @@ format MS COFF - API_VERSION equ 0x01000100 - DRIVER_VERSION equ 5 + API_VERSION equ 0x01000100 + DRIVER_VERSION equ 5 - MAX_DEVICES equ 16 + MAX_DEVICES equ 16 - DEBUG equ 1 - __DEBUG__ equ 1 - __DEBUG_LEVEL__ equ 1 + DEBUG equ 1 + __DEBUG__ equ 1 + __DEBUG_LEVEL__ equ 1 - NUM_TX_DESC equ 4 - NUM_RX_DESC equ 4 + NUM_TX_DESC equ 4 + NUM_RX_DESC equ 4 include 'proc32.inc' include 'imports.inc' @@ -44,174 +44,174 @@ public service_proc public version - REG_MAC0 equ 0x0 ; Ethernet hardware address - REG_MAR0 equ 0x8 ; Multicast filter - REG_TxDescStartAddr equ 0x20 - REG_TxHDescStartAddr equ 0x28 - REG_FLASH equ 0x30 - REG_ERSR equ 0x36 - REG_ChipCmd equ 0x37 - REG_TxPoll equ 0x38 - REG_IntrMask equ 0x3C - REG_IntrStatus equ 0x3E - REG_TxConfig equ 0x40 - REG_RxConfig equ 0x44 - REG_RxMissed equ 0x4C - REG_Cfg9346 equ 0x50 - REG_Config0 equ 0x51 - REG_Config1 equ 0x52 - REG_Config2 equ 0x53 - REG_Config3 equ 0x54 - REG_Config4 equ 0x55 - REG_Config5 equ 0x56 - REG_MultiIntr equ 0x5C - REG_PHYAR equ 0x60 - REG_TBICSR equ 0x64 - REG_TBI_ANAR equ 0x68 - REG_TBI_LPAR equ 0x6A - REG_PHYstatus equ 0x6C - REG_RxMaxSize equ 0xDA - REG_CPlusCmd equ 0xE0 - REG_RxDescStartAddr equ 0xE4 - REG_ETThReg equ 0xEC - REG_FuncEvent equ 0xF0 - REG_FuncEventMask equ 0xF4 - REG_FuncPresetState equ 0xF8 - REG_FuncForceEvent equ 0xFC + REG_MAC0 equ 0x0 ; Ethernet hardware address + REG_MAR0 equ 0x8 ; Multicast filter + REG_TxDescStartAddr equ 0x20 + REG_TxHDescStartAddr equ 0x28 + REG_FLASH equ 0x30 + REG_ERSR equ 0x36 + REG_ChipCmd equ 0x37 + REG_TxPoll equ 0x38 + REG_IntrMask equ 0x3C + REG_IntrStatus equ 0x3E + REG_TxConfig equ 0x40 + REG_RxConfig equ 0x44 + REG_RxMissed equ 0x4C + REG_Cfg9346 equ 0x50 + REG_Config0 equ 0x51 + REG_Config1 equ 0x52 + REG_Config2 equ 0x53 + REG_Config3 equ 0x54 + REG_Config4 equ 0x55 + REG_Config5 equ 0x56 + REG_MultiIntr equ 0x5C + REG_PHYAR equ 0x60 + REG_TBICSR equ 0x64 + REG_TBI_ANAR equ 0x68 + REG_TBI_LPAR equ 0x6A + REG_PHYstatus equ 0x6C + REG_RxMaxSize equ 0xDA + REG_CPlusCmd equ 0xE0 + REG_RxDescStartAddr equ 0xE4 + REG_ETThReg equ 0xEC + REG_FuncEvent equ 0xF0 + REG_FuncEventMask equ 0xF4 + REG_FuncPresetState equ 0xF8 + REG_FuncForceEvent equ 0xFC - ; InterruptStatusBits - ISB_SYSErr equ 0x8000 - ISB_PCSTimeout equ 0x4000 - ISB_SWInt equ 0x0100 - ISB_TxDescUnavail equ 0x80 - ISB_RxFIFOOver equ 0x40 - ISB_LinkChg equ 0x20 - ISB_RxOverflow equ 0x10 - ISB_TxErr equ 0x08 - ISB_TxOK equ 0x04 - ISB_RxErr equ 0x02 - ISB_RxOK equ 0x01 + ; InterruptStatusBits + ISB_SYSErr equ 0x8000 + ISB_PCSTimeout equ 0x4000 + ISB_SWInt equ 0x0100 + ISB_TxDescUnavail equ 0x80 + ISB_RxFIFOOver equ 0x40 + ISB_LinkChg equ 0x20 + ISB_RxOverflow equ 0x10 + ISB_TxErr equ 0x08 + ISB_TxOK equ 0x04 + ISB_RxErr equ 0x02 + ISB_RxOK equ 0x01 - ; RxStatusDesc - SD_RxRES equ 0x00200000 - SD_RxCRC equ 0x00080000 - SD_RxRUNT equ 0x00100000 - SD_RxRWT equ 0x00400000 + ; RxStatusDesc + SD_RxRES equ 0x00200000 + SD_RxCRC equ 0x00080000 + SD_RxRUNT equ 0x00100000 + SD_RxRWT equ 0x00400000 - ; ChipCmdBits - CMD_Reset equ 0x10 - CMD_RxEnb equ 0x08 - CMD_TxEnb equ 0x04 - CMD_RxBufEmpty equ 0x01 + ; ChipCmdBits + CMD_Reset equ 0x10 + CMD_RxEnb equ 0x08 + CMD_TxEnb equ 0x04 + CMD_RxBufEmpty equ 0x01 - ; Cfg9346Bits - CFG_9346_Lock equ 0x00 - CFG_9346_Unlock equ 0xC0 + ; Cfg9346Bits + CFG_9346_Lock equ 0x00 + CFG_9346_Unlock equ 0xC0 - ; rx_mode_bits - RXM_AcceptErr equ 0x20 - RXM_AcceptRunt equ 0x10 - RXM_AcceptBroadcast equ 0x08 - RXM_AcceptMulticast equ 0x04 - RXM_AcceptMyPhys equ 0x02 - RXM_AcceptAllPhys equ 0x01 + ; rx_mode_bits + RXM_AcceptErr equ 0x20 + RXM_AcceptRunt equ 0x10 + RXM_AcceptBroadcast equ 0x08 + RXM_AcceptMulticast equ 0x04 + RXM_AcceptMyPhys equ 0x02 + RXM_AcceptAllPhys equ 0x01 - ; RxConfigBits - RXC_FIFOShift equ 13 - RXC_DMAShift equ 8 + ; RxConfigBits + RXC_FIFOShift equ 13 + RXC_DMAShift equ 8 - ; TxConfigBits - TXC_InterFrameGapShift equ 24 - TXC_DMAShift equ 8 ; DMA burst value (0-7) is shift this many bits + ; TxConfigBits + TXC_InterFrameGapShift equ 24 + TXC_DMAShift equ 8 ; DMA burst value (0-7) is shift this many bits - ; PHYstatus - PHYS_TBI_Enable equ 0x80 - PHYS_TxFlowCtrl equ 0x40 - PHYS_RxFlowCtrl equ 0x20 - PHYS_1000bpsF equ 0x10 - PHYS_100bps equ 0x08 - PHYS_10bps equ 0x04 - PHYS_LinkStatus equ 0x02 - PHYS_FullDup equ 0x01 + ; PHYstatus + PHYS_TBI_Enable equ 0x80 + PHYS_TxFlowCtrl equ 0x40 + PHYS_RxFlowCtrl equ 0x20 + PHYS_1000bpsF equ 0x10 + PHYS_100bps equ 0x08 + PHYS_10bps equ 0x04 + PHYS_LinkStatus equ 0x02 + PHYS_FullDup equ 0x01 - ; GIGABIT_PHY_registers - PHY_CTRL_REG equ 0 - PHY_STAT_REG equ 1 - PHY_AUTO_NEGO_REG equ 4 - PHY_1000_CTRL_REG equ 9 + ; GIGABIT_PHY_registers + PHY_CTRL_REG equ 0 + PHY_STAT_REG equ 1 + PHY_AUTO_NEGO_REG equ 4 + PHY_1000_CTRL_REG equ 9 - ; GIGABIT_PHY_REG_BIT - PHY_Restart_Auto_Nego equ 0x0200 - PHY_Enable_Auto_Nego equ 0x1000 + ; GIGABIT_PHY_REG_BIT + PHY_Restart_Auto_Nego equ 0x0200 + PHY_Enable_Auto_Nego equ 0x1000 - ; PHY_STAT_REG = 1; - PHY_Auto_Neco_Comp equ 0x0020 + ; PHY_STAT_REG = 1; + PHY_Auto_Neco_Comp equ 0x0020 - ; PHY_AUTO_NEGO_REG = 4; - PHY_Cap_10_Half equ 0x0020 - PHY_Cap_10_Full equ 0x0040 - PHY_Cap_100_Half equ 0x0080 - PHY_Cap_100_Full equ 0x0100 + ; PHY_AUTO_NEGO_REG = 4; + PHY_Cap_10_Half equ 0x0020 + PHY_Cap_10_Full equ 0x0040 + PHY_Cap_100_Half equ 0x0080 + PHY_Cap_100_Full equ 0x0100 - ; PHY_1000_CTRL_REG = 9; - PHY_Cap_1000_Full equ 0x0200 - PHY_Cap_1000_Half equ 0x0100 + ; PHY_1000_CTRL_REG = 9; + PHY_Cap_1000_Full equ 0x0200 + PHY_Cap_1000_Half equ 0x0100 - PHY_Cap_PAUSE equ 0x0400 - PHY_Cap_ASYM_PAUSE equ 0x0800 + PHY_Cap_PAUSE equ 0x0400 + PHY_Cap_ASYM_PAUSE equ 0x0800 - PHY_Cap_Null equ 0x0 + PHY_Cap_Null equ 0x0 - ; _MediaType - MT_10_Half equ 0x01 - MT_10_Full equ 0x02 - MT_100_Half equ 0x04 - MT_100_Full equ 0x08 - MT_1000_Full equ 0x10 + ; _MediaType + MT_10_Half equ 0x01 + MT_10_Full equ 0x02 + MT_100_Half equ 0x04 + MT_100_Full equ 0x08 + MT_1000_Full equ 0x10 - ; _TBICSRBit - TBI_LinkOK equ 0x02000000 + ; _TBICSRBit + TBI_LinkOK equ 0x02000000 - ; _DescStatusBit - DSB_OWNbit equ 0x80000000 - DSB_EORbit equ 0x40000000 - DSB_FSbit equ 0x20000000 - DSB_LSbit equ 0x10000000 + ; _DescStatusBit + DSB_OWNbit equ 0x80000000 + DSB_EORbit equ 0x40000000 + DSB_FSbit equ 0x20000000 + DSB_LSbit equ 0x10000000 - RX_BUF_SIZE equ 1536 ; Rx Buffer size + RX_BUF_SIZE equ 1536 ; Rx Buffer size -ETH_ALEN equ 6 -ETH_HLEN equ (2 * ETH_ALEN + 2) -ETH_ZLEN equ 60 ; 60 + 4bytes auto payload for - ; mininmum 64bytes frame length +ETH_ALEN equ 6 +ETH_HLEN equ (2 * ETH_ALEN + 2) +ETH_ZLEN equ 60 ; 60 + 4bytes auto payload for + ; mininmum 64bytes frame length ; MAC address length -MAC_ADDR_LEN equ 6 +MAC_ADDR_LEN equ 6 ; max supported gigabit ethernet frame size -- must be at least (dev->mtu+14+4) MAX_ETH_FRAME_SIZE equ 1536 -TX_FIFO_THRESH equ 256 ; In bytes +TX_FIFO_THRESH equ 256 ; In bytes -RX_FIFO_THRESH equ 7 ; 7 means NO threshold, Rx buffer level before first PCI xfer -RX_DMA_BURST equ 7 ; Maximum PCI burst, '6' is 1024 -TX_DMA_BURST equ 7 ; Maximum PCI burst, '6' is 1024 -ETTh equ 0x3F ; 0x3F means NO threshold +RX_FIFO_THRESH equ 7 ; 7 means NO threshold, Rx buffer level before first PCI xfer +RX_DMA_BURST equ 7 ; Maximum PCI burst, '6' is 1024 +TX_DMA_BURST equ 7 ; Maximum PCI burst, '6' is 1024 +ETTh equ 0x3F ; 0x3F means NO threshold -EarlyTxThld equ 0x3F ; 0x3F means NO early transmit -RxPacketMaxSize equ 0x0800 ; Maximum size supported is 16K-1 -InterFrameGap equ 0x03 ; 3 means InterFrameGap = the shortest one +EarlyTxThld equ 0x3F ; 0x3F means NO early transmit +RxPacketMaxSize equ 0x0800 ; Maximum size supported is 16K-1 +InterFrameGap equ 0x03 ; 3 means InterFrameGap = the shortest one -HZ equ 1000 +HZ equ 1000 RTL_MIN_IO_SIZE equ 0x80 -TX_TIMEOUT equ (6*HZ) +TX_TIMEOUT equ (6*HZ) TIMER_EXPIRE_TIME equ 100 -ETH_HDR_LEN equ 14 -DEFAULT_MTU equ 1500 +ETH_HDR_LEN equ 14 +DEFAULT_MTU equ 1500 DEFAULT_RX_BUF_LEN equ 1536 @@ -222,20 +222,20 @@ DEFAULT_RX_BUF_LEN equ 1536 MAX_RX_SKBDATA_SIZE equ 1600 ;#endif //end #ifdef JUMBO_FRAME_SUPPORT -MCFG_METHOD_01 equ 0x01 -MCFG_METHOD_02 equ 0x02 -MCFG_METHOD_03 equ 0x03 -MCFG_METHOD_04 equ 0x04 -MCFG_METHOD_05 equ 0x05 -MCFG_METHOD_11 equ 0x0b -MCFG_METHOD_12 equ 0x0c -MCFG_METHOD_13 equ 0x0d -MCFG_METHOD_14 equ 0x0e -MCFG_METHOD_15 equ 0x0f +MCFG_METHOD_01 equ 0x01 +MCFG_METHOD_02 equ 0x02 +MCFG_METHOD_03 equ 0x03 +MCFG_METHOD_04 equ 0x04 +MCFG_METHOD_05 equ 0x05 +MCFG_METHOD_11 equ 0x0b +MCFG_METHOD_12 equ 0x0c +MCFG_METHOD_13 equ 0x0d +MCFG_METHOD_14 equ 0x0e +MCFG_METHOD_15 equ 0x0f -PCFG_METHOD_1 equ 0x01 ; PHY Reg 0x03 bit0-3 == 0x0000 -PCFG_METHOD_2 equ 0x02 ; PHY Reg 0x03 bit0-3 == 0x0001 -PCFG_METHOD_3 equ 0x03 ; PHY Reg 0x03 bit0-3 == 0x0002 +PCFG_METHOD_1 equ 0x01 ; PHY Reg 0x03 bit0-3 == 0x0000 +PCFG_METHOD_2 equ 0x02 ; PHY Reg 0x03 bit0-3 == 0x0001 +PCFG_METHOD_3 equ 0x03 ; PHY Reg 0x03 bit0-3 == 0x0002 virtual at 0 tx_desc: @@ -243,8 +243,8 @@ virtual at 0 .vlan_tag dd ? .buf_addr dq ? .size = $ - rb (NUM_TX_DESC-1)*tx_desc.size - .buf_soft_addr dd ? + rb (NUM_TX_DESC-1)*tx_desc.size + .buf_soft_addr dd ? end virtual virtual at 0 @@ -253,40 +253,40 @@ virtual at 0 .vlan_tag dd ? .buf_addr dq ? .size = $ - rb (NUM_RX_DESC-1)*rx_desc.size - .buf_soft_addr dd ? + rb (NUM_RX_DESC-1)*rx_desc.size + .buf_soft_addr dd ? end virtual virtual at ebx - device: + device: - ETH_DEVICE + ETH_DEVICE - .io_addr dd ? - .pci_bus db ? - .pci_dev db ? - .irq_line db ? + .io_addr dd ? + .pci_bus db ? + .pci_dev db ? + .irq_line db ? - tpc: - .mmio_addr dd ? ; memory map physical address - .chipset dd ? - .pcfg dd ? - .mcfg dd ? - .cur_rx dd ? ; Index into the Rx descriptor buffer of next Rx pkt - .cur_tx dd ? ; Index into the Tx descriptor buffer of next Rx pkt - .TxDescArrays dd ? ; Index of Tx Descriptor buffer - .RxDescArrays dd ? ; Index of Rx Descriptor buffer - .TxDescArray dd ? ; Index of 256-alignment Tx Descriptor buffer - .RxDescArray dd ? ; Index of 256-alignment Rx Descriptor buffer + tpc: + .mmio_addr dd ? ; memory map physical address + .chipset dd ? + .pcfg dd ? + .mcfg dd ? + .cur_rx dd ? ; Index into the Rx descriptor buffer of next Rx pkt + .cur_tx dd ? ; Index into the Tx descriptor buffer of next Rx pkt + .TxDescArrays dd ? ; Index of Tx Descriptor buffer + .RxDescArrays dd ? ; Index of Rx Descriptor buffer + .TxDescArray dd ? ; Index of 256-alignment Tx Descriptor buffer + .RxDescArray dd ? ; Index of 256-alignment Rx Descriptor buffer - rb 256-(($ - device) and 255) ; align 256 - tx_ring rb NUM_TX_DESC * tx_desc.size * 2 + rb 256-(($ - device) and 255) ; align 256 + tx_ring rb NUM_TX_DESC * tx_desc.size * 2 - rb 256-(($ - device) and 255) ; align 256 - rx_ring rb NUM_RX_DESC * rx_desc.size * 2 + rb 256-(($ - device) and 255) ; align 256 + rx_ring rb NUM_RX_DESC * rx_desc.size * 2 - device_size = $ - device + device_size = $ - device end virtual @@ -294,66 +294,66 @@ intr_mask = ISB_LinkChg or ISB_RxOverflow or ISB_RxFIFOOver or ISB_TxErr or ISB_ rx_config = (RX_FIFO_THRESH shl RXC_FIFOShift) or (RX_DMA_BURST shl RXC_DMAShift) or 0x0000000E -macro udelay msec { +macro udelay msec { - push esi - mov esi, msec - call Sleep - pop esi + push esi + mov esi, msec + call Sleep + pop esi } -macro WRITE_GMII_REG RegAddr, value { +macro WRITE_GMII_REG RegAddr, value { - set_io REG_PHYAR - if value eq ax - and eax, 0x0000ffff - or eax, 0x80000000 + (RegAddr shl 16) - else - mov eax, 0x80000000 + (RegAddr shl 16) + value - end if - out dx, eax + set_io REG_PHYAR + if value eq ax + and eax, 0x0000ffff + or eax, 0x80000000 + (RegAddr shl 16) + else + mov eax, 0x80000000 + (RegAddr shl 16) + value + end if + out dx, eax - call PHY_WAIT + call PHY_WAIT } -macro READ_GMII_REG RegAddr { +macro READ_GMII_REG RegAddr { -local .error, .done +local .error, .done - set_io REG_PHYAR - mov eax, RegAddr shl 16 - out dx, eax + set_io REG_PHYAR + mov eax, RegAddr shl 16 + out dx, eax - call PHY_WAIT - jz .error + call PHY_WAIT + jz .error - in eax, dx - and eax, 0xFFFF - jmp .done + in eax, dx + and eax, 0xFFFF + jmp .done .error: - or eax, -1 + or eax, -1 .done: } align 4 -PHY_WAIT: ; io addr must already be set to REG_PHYAR +PHY_WAIT: ; io addr must already be set to REG_PHYAR - udelay 1 ;;;1000 + udelay 1 ;;;1000 - push ecx - mov ecx, 2000 - ; Check if the RTL8169 has completed writing/reading to the specified MII register + push ecx + mov ecx, 2000 + ; Check if the RTL8169 has completed writing/reading to the specified MII register @@: - in eax, dx - test eax, 0x80000000 - jz .exit - udelay 1 ;;;100 - loop @b + in eax, dx + test eax, 0x80000000 + jz .exit + udelay 1 ;;;100 + loop @b .exit: - pop ecx - ret + pop ecx + ret @@ -369,19 +369,19 @@ section '.flat' code readable align 16 align 4 proc START stdcall, state:dword - cmp [state], 1 - jne .exit + cmp [state], 1 + jne .exit .entry: - DEBUGF 2,"Loading rtl8169 driver\n" - stdcall RegService, my_service, service_proc - ret + DEBUGF 2,"Loading rtl8169 driver\n" + stdcall RegService, my_service, service_proc + ret .fail: .exit: - xor eax, eax - ret + xor eax, eax + ret endp @@ -396,133 +396,133 @@ endp align 4 proc service_proc stdcall, ioctl:dword - mov edx, [ioctl] - mov eax, [IOCTL.io_code] + mov edx, [ioctl] + mov eax, [IOCTL.io_code] ;------------------------------------------------------ - cmp eax, 0 ;SRV_GETVERSION - jne @F + cmp eax, 0 ;SRV_GETVERSION + jne @F - cmp [IOCTL.out_size], 4 - jl .fail - mov eax, [IOCTL.output] - mov [eax], dword API_VERSION + cmp [IOCTL.out_size], 4 + jl .fail + mov eax, [IOCTL.output] + mov [eax], dword API_VERSION - xor eax, eax - ret + xor eax, eax + ret ;------------------------------------------------------ @@: - cmp eax, 1 ;SRV_HOOK - jne .fail + cmp eax, 1 ;SRV_HOOK + jne .fail - cmp [IOCTL.inp_size], 3 ; Data input must be at least 3 bytes - jl .fail + cmp [IOCTL.inp_size], 3 ; Data input must be at least 3 bytes + jl .fail - mov eax, [IOCTL.input] - cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given - jne .fail ; other types arent supported for this card yet + mov eax, [IOCTL.input] + cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given + jne .fail ; other types arent supported for this card yet ; check if the device is already listed - mov esi, device_list - mov ecx, [devices] - test ecx, ecx - jz .firstdevice + mov esi, device_list + mov ecx, [devices] + test ecx, ecx + jz .firstdevice ; mov eax, [IOCTL.input] ; get the pci bus and device numbers - mov ax , [eax+1] ; + mov ax , [eax+1] ; .nextdevice: - mov ebx, [esi] - cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) - je .find_devicenum ; Device is already loaded, let's find it's device number - add esi, 4 - loop .nextdevice + mov ebx, [esi] + cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) + je .find_devicenum ; Device is already loaded, let's find it's device number + add esi, 4 + loop .nextdevice ; This device doesnt have its own eth_device structure yet, lets create one .firstdevice: - cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card - jge .fail + cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card + jge .fail - allocate_and_clear ebx, device_size, .fail ; Allocate memory to put the device structure in + allocate_and_clear ebx, device_size, .fail ; Allocate memory to put the device structure in ; Fill in the direct call addresses into the struct - mov [device.reset], reset - mov [device.transmit], transmit - mov [device.get_MAC], read_mac - mov [device.set_MAC], write_mac - mov [device.unload], unload - mov [device.name], my_service + mov [device.reset], reset + mov [device.transmit], transmit + mov [device.get_MAC], read_mac + mov [device.set_MAC], write_mac + mov [device.unload], unload + mov [device.name], my_service ; save the pci bus and device numbers - mov eax, [IOCTL.input] - mov cl , [eax+1] - mov [device.pci_bus], cl - mov cl , [eax+2] - mov [device.pci_dev], cl + mov eax, [IOCTL.input] + mov cl , [eax+1] + mov [device.pci_bus], cl + mov cl , [eax+2] + mov [device.pci_dev], cl ; Now, it's time to find the base io addres of the PCI device - find_io [device.pci_bus], [device.pci_dev], [device.io_addr] - mov eax, [device.io_addr] - mov [tpc.mmio_addr], eax + find_io [device.pci_bus], [device.pci_dev], [device.io_addr] + mov eax, [device.io_addr] + mov [tpc.mmio_addr], eax ; We've found the io address, find IRQ now - find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] + find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] - DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ - [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:8 + DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ + [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:8 ; Ok, the eth_device structure is ready, let's probe the device ; Because initialization fires IRQ, IRQ handler must be aware of this device - mov eax, [devices] ; Add the device structure to our device list - mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) - inc [devices] ; + mov eax, [devices] ; Add the device structure to our device list + mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) + inc [devices] ; - call probe ; this function will output in eax - test eax, eax - jnz .err2 ; If an error occured, exit + call probe ; this function will output in eax + test eax, eax + jnz .err2 ; If an error occured, exit - mov [device.type], NET_TYPE_ETH - call NetRegDev + mov [device.type], NET_TYPE_ETH + call NetRegDev - cmp eax, -1 - je .destroy + cmp eax, -1 + je .destroy - ret + ret ; If the device was already loaded, find the device number and return it in eax .find_devicenum: - DEBUGF 2,"Trying to find device number of already registered device\n" - mov ebx, eax - call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx - ; into a device number in edi - mov eax, edi ; Application wants it in eax instead - DEBUGF 2,"Kernel says: %u\n", eax - ret + DEBUGF 2,"Trying to find device number of already registered device\n" + mov ebx, eax + call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx + ; into a device number in edi + mov eax, edi ; Application wants it in eax instead + DEBUGF 2,"Kernel says: %u\n", eax + ret ; If an error occured, remove all allocated data and exit (returning -1 in eax) .destroy: - ; todo: reset device into virgin state + ; todo: reset device into virgin state .err2: - dec [devices] + dec [devices] .err: - DEBUGF 2,"removing device structure\n" - stdcall KernelFree, ebx + DEBUGF 2,"removing device structure\n" + stdcall KernelFree, ebx .fail: - or eax, -1 - ret + or eax, -1 + ret ;------------------------------------------------------ endp @@ -531,83 +531,83 @@ endp align 4 unload: - ret + ret align 4 init_board: - DEBUGF 1,"init_board\n" + DEBUGF 1,"init_board\n" - make_bus_master [device.pci_bus], [device.pci_dev] + make_bus_master [device.pci_bus], [device.pci_dev] - ; Soft reset the chip - set_io 0 - set_io REG_ChipCmd - mov al, CMD_Reset - out dx, al + ; Soft reset the chip + set_io 0 + set_io REG_ChipCmd + mov al, CMD_Reset + out dx, al - ; Check that the chip has finished the reset - mov ecx, 1000 - set_io REG_ChipCmd - @@: in al, dx - test al, CMD_Reset - jz @f - udelay 10 - loop @b + ; Check that the chip has finished the reset + mov ecx, 1000 + set_io REG_ChipCmd + @@: in al, dx + test al, CMD_Reset + jz @f + udelay 10 + loop @b @@: - ; identify config method - set_io REG_TxConfig - in eax, dx - and eax, 0x7c800000 - DEBUGF 1,"init_board: TxConfig & 0x7c800000 = 0x%x\n", eax - mov esi, mac_info-8 - @@: add esi, 8 - mov ecx, eax - and ecx, [esi] - cmp ecx, [esi] - jne @b - mov eax, [esi+4] - mov [tpc.mcfg], eax + ; identify config method + set_io REG_TxConfig + in eax, dx + and eax, 0x7c800000 + DEBUGF 1,"init_board: TxConfig & 0x7c800000 = 0x%x\n", eax + mov esi, mac_info-8 + @@: add esi, 8 + mov ecx, eax + and ecx, [esi] + cmp ecx, [esi] + jne @b + mov eax, [esi+4] + mov [tpc.mcfg], eax - mov [tpc.pcfg], PCFG_METHOD_3 - READ_GMII_REG 3 - and al, 0x0f - or al, al - jnz @f - mov [tpc.pcfg], PCFG_METHOD_1 - jmp .pconf - @@: dec al - jnz .pconf - mov [tpc.pcfg], PCFG_METHOD_2 + mov [tpc.pcfg], PCFG_METHOD_3 + READ_GMII_REG 3 + and al, 0x0f + or al, al + jnz @f + mov [tpc.pcfg], PCFG_METHOD_1 + jmp .pconf + @@: dec al + jnz .pconf + mov [tpc.pcfg], PCFG_METHOD_2 .pconf: - ; identify chip attached to board - mov ecx, 10 - mov eax, [tpc.mcfg] - @@: dec ecx - js @f - cmp eax, [rtl_chip_info+ecx*8] - jne @b - mov [tpc.chipset], ecx - jmp .match + ; identify chip attached to board + mov ecx, 10 + mov eax, [tpc.mcfg] + @@: dec ecx + js @f + cmp eax, [rtl_chip_info+ecx*8] + jne @b + mov [tpc.chipset], ecx + jmp .match @@: - ; if unknown chip, assume array element #0, original RTL-8169 in this case - DEBUGF 1,"init_board: PCI device: unknown chip version, assuming RTL-8169\n" - set_io REG_TxConfig - in eax, dx - DEBUGF 1,"init_board: PCI device: TxConfig = 0x%x\n", eax + ; if unknown chip, assume array element #0, original RTL-8169 in this case + DEBUGF 1,"init_board: PCI device: unknown chip version, assuming RTL-8169\n" + set_io REG_TxConfig + in eax, dx + DEBUGF 1,"init_board: PCI device: TxConfig = 0x%x\n", eax - mov [tpc.chipset], 0 + mov [tpc.chipset], 0 - xor eax, eax - inc eax - ret + xor eax, eax + inc eax + ret .match: - DEBUGF 1,"init_board: chipset=%u\n", ecx - xor eax,eax - ret + DEBUGF 1,"init_board: chipset=%u\n", ecx + xor eax,eax + ret @@ -624,67 +624,67 @@ init_board: align 4 probe: - DEBUGF 1,"probe\n" + DEBUGF 1,"probe\n" - call init_board + call init_board - call read_mac + call read_mac - call PHY_config + call PHY_config ; DEBUGF 1,"K : Set MAC Reg C+CR Offset 0x82h = 0x01h\n" - set_io 0 - set_io 0x82 - mov al, 0x01 - out dx, al - cmp [tpc.mcfg], MCFG_METHOD_03 - jae @f + set_io 0 + set_io 0x82 + mov al, 0x01 + out dx, al + cmp [tpc.mcfg], MCFG_METHOD_03 + jae @f ; DEBUGF 1,"K : Set PCI Latency=0x40\n" ; stdcall pci_write_config_byte,PCI_LATENCY_TIMER,0x40 @@: - cmp [tpc.mcfg], MCFG_METHOD_02 - jne @f + cmp [tpc.mcfg], MCFG_METHOD_02 + jne @f ; DEBUGF 1,"K : Set MAC Reg C+CR Offset 0x82h = 0x01h\n" - set_io 0x82 - mov al, 0x01 - out dx, al + set_io 0x82 + mov al, 0x01 + out dx, al ; DEBUGF 1,"K : Set PHY Reg 0x0bh = 0x00h\n" - WRITE_GMII_REG 0x0b, 0x0000 ; w 0x0b 15 0 0 + WRITE_GMII_REG 0x0b, 0x0000 ; w 0x0b 15 0 0 @@: - ; if TBI is not enabled - set_io 0 - set_io REG_PHYstatus - in al, dx - test al, PHYS_TBI_Enable - jz .tbi_dis - READ_GMII_REG PHY_AUTO_NEGO_REG + ; if TBI is not enabled + set_io 0 + set_io REG_PHYstatus + in al, dx + test al, PHYS_TBI_Enable + jz .tbi_dis + READ_GMII_REG PHY_AUTO_NEGO_REG - ; enable 10/100 Full/Half Mode, leave PHY_AUTO_NEGO_REG bit4:0 unchanged - and eax, 0x0C1F - or eax, PHY_Cap_10_Half or PHY_Cap_10_Full or PHY_Cap_100_Half or PHY_Cap_100_Full - WRITE_GMII_REG PHY_AUTO_NEGO_REG, ax + ; enable 10/100 Full/Half Mode, leave PHY_AUTO_NEGO_REG bit4:0 unchanged + and eax, 0x0C1F + or eax, PHY_Cap_10_Half or PHY_Cap_10_Full or PHY_Cap_100_Half or PHY_Cap_100_Full + WRITE_GMII_REG PHY_AUTO_NEGO_REG, ax - ; enable 1000 Full Mode - WRITE_GMII_REG PHY_1000_CTRL_REG, PHY_Cap_1000_Full or PHY_Cap_1000_Half ; rtl8168 + ; enable 1000 Full Mode + WRITE_GMII_REG PHY_1000_CTRL_REG, PHY_Cap_1000_Full or PHY_Cap_1000_Half ; rtl8168 - ; Enable auto-negotiation and restart auto-nigotiation - WRITE_GMII_REG PHY_CTRL_REG, PHY_Enable_Auto_Nego or PHY_Restart_Auto_Nego + ; Enable auto-negotiation and restart auto-nigotiation + WRITE_GMII_REG PHY_CTRL_REG, PHY_Enable_Auto_Nego or PHY_Restart_Auto_Nego - udelay 100 - mov ecx, 10000 - ; wait for auto-negotiation process - @@: dec ecx - jz @f - set_io 0 - READ_GMII_REG PHY_STAT_REG - udelay 100 - test eax, PHY_Auto_Neco_Comp - jz @b - set_io REG_PHYstatus - in al, dx - jmp @f + udelay 100 + mov ecx, 10000 + ; wait for auto-negotiation process + @@: dec ecx + jz @f + set_io 0 + READ_GMII_REG PHY_STAT_REG + udelay 100 + test eax, PHY_Auto_Neco_Comp + jz @b + set_io REG_PHYstatus + in al, dx + jmp @f .tbi_dis: - udelay 100 + udelay 100 @@: @@ -700,30 +700,30 @@ probe: align 4 reset: - DEBUGF 1,"reset\n" + DEBUGF 1,"reset\n" - lea eax, [tx_ring] - mov [tpc.TxDescArrays], eax - mov [tpc.TxDescArray], eax + lea eax, [tx_ring] + mov [tpc.TxDescArrays], eax + mov [tpc.TxDescArray], eax - lea eax, [rx_ring] - mov [tpc.RxDescArrays], eax - mov [tpc.RxDescArray], eax + lea eax, [rx_ring] + mov [tpc.RxDescArrays], eax + mov [tpc.RxDescArray], eax - call init_ring - call hw_start + call init_ring + call hw_start ; clear packet/byte counters - xor eax, eax - lea edi, [device.bytes_tx] - mov ecx, 6 - rep stosd + xor eax, eax + lea edi, [device.bytes_tx] + mov ecx, 6 + rep stosd - mov [device.mtu], 1500 + mov [device.mtu], 1500 - xor eax, eax - ret + xor eax, eax + ret @@ -732,282 +732,282 @@ reset: align 4 PHY_config: - DEBUGF 1,"hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n",[tpc.mcfg],[tpc.pcfg] + DEBUGF 1,"hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n",[tpc.mcfg],[tpc.pcfg] - cmp [tpc.mcfg], MCFG_METHOD_04 - jne .not_4 - set_io 0 + cmp [tpc.mcfg], MCFG_METHOD_04 + jne .not_4 + set_io 0 ; WRITE_GMII_REG 0x1F, 0x0001 ; WRITE_GMII_REG 0x1b, 0x841e ; WRITE_GMII_REG 0x0e, 0x7bfb ; WRITE_GMII_REG 0x09, 0x273a - WRITE_GMII_REG 0x1F, 0x0002 - WRITE_GMII_REG 0x01, 0x90D0 - WRITE_GMII_REG 0x1F, 0x0000 - jmp .exit + WRITE_GMII_REG 0x1F, 0x0002 + WRITE_GMII_REG 0x01, 0x90D0 + WRITE_GMII_REG 0x1F, 0x0000 + jmp .exit .not_4: - cmp [tpc.mcfg], MCFG_METHOD_02 - je @f - cmp [tpc.mcfg], MCFG_METHOD_03 - jne .not_2_or_3 + cmp [tpc.mcfg], MCFG_METHOD_02 + je @f + cmp [tpc.mcfg], MCFG_METHOD_03 + jne .not_2_or_3 @@: - set_io 0 - WRITE_GMII_REG 0x1F, 0x0001 - WRITE_GMII_REG 0x15, 0x1000 - WRITE_GMII_REG 0x18, 0x65C7 - WRITE_GMII_REG 0x04, 0x0000 - WRITE_GMII_REG 0x03, 0x00A1 - WRITE_GMII_REG 0x02, 0x0008 - WRITE_GMII_REG 0x01, 0x1020 - WRITE_GMII_REG 0x00, 0x1000 - WRITE_GMII_REG 0x04, 0x0800 - WRITE_GMII_REG 0x04, 0x0000 - WRITE_GMII_REG 0x04, 0x7000 - WRITE_GMII_REG 0x03, 0xFF41 - WRITE_GMII_REG 0x02, 0xDE60 - WRITE_GMII_REG 0x01, 0x0140 - WRITE_GMII_REG 0x00, 0x0077 - WRITE_GMII_REG 0x04, 0x7800 - WRITE_GMII_REG 0x04, 0x7000 - WRITE_GMII_REG 0x04, 0xA000 - WRITE_GMII_REG 0x03, 0xDF01 - WRITE_GMII_REG 0x02, 0xDF20 - WRITE_GMII_REG 0x01, 0xFF95 - WRITE_GMII_REG 0x00, 0xFA00 - WRITE_GMII_REG 0x04, 0xA800 - WRITE_GMII_REG 0x04, 0xA000 - WRITE_GMII_REG 0x04, 0xB000 - WRITE_GMII_REG 0x03, 0xFF41 - WRITE_GMII_REG 0x02, 0xDE20 - WRITE_GMII_REG 0x01, 0x0140 - WRITE_GMII_REG 0x00, 0x00BB - WRITE_GMII_REG 0x04, 0xB800 - WRITE_GMII_REG 0x04, 0xB000 - WRITE_GMII_REG 0x04, 0xF000 - WRITE_GMII_REG 0x03, 0xDF01 - WRITE_GMII_REG 0x02, 0xDF20 - WRITE_GMII_REG 0x01, 0xFF95 - WRITE_GMII_REG 0x00, 0xBF00 - WRITE_GMII_REG 0x04, 0xF800 - WRITE_GMII_REG 0x04, 0xF000 - WRITE_GMII_REG 0x04, 0x0000 - WRITE_GMII_REG 0x1F, 0x0000 - WRITE_GMII_REG 0x0B, 0x0000 - jmp .exit + set_io 0 + WRITE_GMII_REG 0x1F, 0x0001 + WRITE_GMII_REG 0x15, 0x1000 + WRITE_GMII_REG 0x18, 0x65C7 + WRITE_GMII_REG 0x04, 0x0000 + WRITE_GMII_REG 0x03, 0x00A1 + WRITE_GMII_REG 0x02, 0x0008 + WRITE_GMII_REG 0x01, 0x1020 + WRITE_GMII_REG 0x00, 0x1000 + WRITE_GMII_REG 0x04, 0x0800 + WRITE_GMII_REG 0x04, 0x0000 + WRITE_GMII_REG 0x04, 0x7000 + WRITE_GMII_REG 0x03, 0xFF41 + WRITE_GMII_REG 0x02, 0xDE60 + WRITE_GMII_REG 0x01, 0x0140 + WRITE_GMII_REG 0x00, 0x0077 + WRITE_GMII_REG 0x04, 0x7800 + WRITE_GMII_REG 0x04, 0x7000 + WRITE_GMII_REG 0x04, 0xA000 + WRITE_GMII_REG 0x03, 0xDF01 + WRITE_GMII_REG 0x02, 0xDF20 + WRITE_GMII_REG 0x01, 0xFF95 + WRITE_GMII_REG 0x00, 0xFA00 + WRITE_GMII_REG 0x04, 0xA800 + WRITE_GMII_REG 0x04, 0xA000 + WRITE_GMII_REG 0x04, 0xB000 + WRITE_GMII_REG 0x03, 0xFF41 + WRITE_GMII_REG 0x02, 0xDE20 + WRITE_GMII_REG 0x01, 0x0140 + WRITE_GMII_REG 0x00, 0x00BB + WRITE_GMII_REG 0x04, 0xB800 + WRITE_GMII_REG 0x04, 0xB000 + WRITE_GMII_REG 0x04, 0xF000 + WRITE_GMII_REG 0x03, 0xDF01 + WRITE_GMII_REG 0x02, 0xDF20 + WRITE_GMII_REG 0x01, 0xFF95 + WRITE_GMII_REG 0x00, 0xBF00 + WRITE_GMII_REG 0x04, 0xF800 + WRITE_GMII_REG 0x04, 0xF000 + WRITE_GMII_REG 0x04, 0x0000 + WRITE_GMII_REG 0x1F, 0x0000 + WRITE_GMII_REG 0x0B, 0x0000 + jmp .exit .not_2_or_3: - DEBUGF 1,"tpc.mcfg=%d, discard hw PHY config\n", [tpc.mcfg] + DEBUGF 1,"tpc.mcfg=%d, discard hw PHY config\n", [tpc.mcfg] .exit: - ret + ret align 4 set_rx_mode: - DEBUGF 1,"set_rx_mode\n" + DEBUGF 1,"set_rx_mode\n" - ; IFF_ALLMULTI - ; Too many to filter perfectly -- accept all multicasts - set_io 0 - set_io REG_RxConfig - in eax, dx - mov ecx, [tpc.chipset] - and eax, [rtl_chip_info + ecx * 8 + 4] ; RxConfigMask - or eax, rx_config or (RXM_AcceptBroadcast or RXM_AcceptMulticast or RXM_AcceptMyPhys) - out dx, eax + ; IFF_ALLMULTI + ; Too many to filter perfectly -- accept all multicasts + set_io 0 + set_io REG_RxConfig + in eax, dx + mov ecx, [tpc.chipset] + and eax, [rtl_chip_info + ecx * 8 + 4] ; RxConfigMask + or eax, rx_config or (RXM_AcceptBroadcast or RXM_AcceptMulticast or RXM_AcceptMyPhys) + out dx, eax - ; Multicast hash filter - set_io REG_MAR0 + 0 - or eax, -1 - out dx, eax - set_io REG_MAR0 + 4 - out dx, eax + ; Multicast hash filter + set_io REG_MAR0 + 0 + or eax, -1 + out dx, eax + set_io REG_MAR0 + 4 + out dx, eax - ret + ret align 4 init_ring: - DEBUGF 1,"init_ring\n" + DEBUGF 1,"init_ring\n" - xor eax, eax - mov [tpc.cur_rx], eax - mov [tpc.cur_tx], eax + xor eax, eax + mov [tpc.cur_rx], eax + mov [tpc.cur_tx], eax - lea edi, [tx_ring] - mov ecx, (NUM_TX_DESC * tx_desc.size) / 4 - rep stosd + lea edi, [tx_ring] + mov ecx, (NUM_TX_DESC * tx_desc.size) / 4 + rep stosd - lea edi, [rx_ring] - mov ecx, (NUM_RX_DESC * rx_desc.size) / 4 - rep stosd + lea edi, [rx_ring] + mov ecx, (NUM_RX_DESC * rx_desc.size) / 4 + rep stosd - mov edi, [tpc.RxDescArray] - mov ecx, NUM_RX_DESC + mov edi, [tpc.RxDescArray] + mov ecx, NUM_RX_DESC .loop: - push ecx - stdcall KernelAlloc, RX_BUF_SIZE - mov [edi + rx_desc.buf_soft_addr], eax - call GetPgAddr - mov dword [edi + rx_desc.buf_addr], eax - mov [edi + rx_desc.status], DSB_OWNbit or RX_BUF_SIZE - add edi, rx_desc.size - pop ecx - loop .loop - or [edi - rx_desc.size + rx_desc.status], DSB_EORbit + push ecx + stdcall KernelAlloc, RX_BUF_SIZE + mov [edi + rx_desc.buf_soft_addr], eax + call GetPgAddr + mov dword [edi + rx_desc.buf_addr], eax + mov [edi + rx_desc.status], DSB_OWNbit or RX_BUF_SIZE + add edi, rx_desc.size + pop ecx + loop .loop + or [edi - rx_desc.size + rx_desc.status], DSB_EORbit - ret + ret align 4 hw_start: - DEBUGF 1,"hw_start\n" + DEBUGF 1,"hw_start\n" ; attach int handler - movzx eax, [device.irq_line] - DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 - stdcall AttachIntHandler, eax, int_handler, dword 0 + movzx eax, [device.irq_line] + DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 + stdcall AttachIntHandler, eax, int_handler, dword 0 - ; Soft reset the chip - set_io 0 - set_io REG_ChipCmd - mov al, CMD_Reset - out dx, al + ; Soft reset the chip + set_io 0 + set_io REG_ChipCmd + mov al, CMD_Reset + out dx, al - ; Check that the chip has finished the reset - mov ecx, 1000 - set_io REG_ChipCmd - @@: in al, dx - test al, CMD_Reset - jz @f - udelay 10 - loop @b + ; Check that the chip has finished the reset + mov ecx, 1000 + set_io REG_ChipCmd + @@: in al, dx + test al, CMD_Reset + jz @f + udelay 10 + loop @b @@: - set_io REG_Cfg9346 - mov al, CFG_9346_Unlock - out dx, al + set_io REG_Cfg9346 + mov al, CFG_9346_Unlock + out dx, al - set_io REG_ChipCmd - mov al, CMD_TxEnb or CMD_RxEnb - out dx, al + set_io REG_ChipCmd + mov al, CMD_TxEnb or CMD_RxEnb + out dx, al - set_io REG_ETThReg - mov al, ETTh - out dx, al + set_io REG_ETThReg + mov al, ETTh + out dx, al - ; For gigabit rtl8169 - set_io REG_RxMaxSize - mov ax, RxPacketMaxSize - out dx, ax + ; For gigabit rtl8169 + set_io REG_RxMaxSize + mov ax, RxPacketMaxSize + out dx, ax - ; Set Rx Config register - set_io REG_RxConfig - in ax, dx - mov ecx, [tpc.chipset] - and eax, [rtl_chip_info + ecx * 8 + 4] ; RxConfigMask - or eax, rx_config - out dx, eax + ; Set Rx Config register + set_io REG_RxConfig + in ax, dx + mov ecx, [tpc.chipset] + and eax, [rtl_chip_info + ecx * 8 + 4] ; RxConfigMask + or eax, rx_config + out dx, eax - ; Set DMA burst size and Interframe Gap Time - set_io REG_TxConfig - mov eax, (TX_DMA_BURST shl TXC_DMAShift) or (InterFrameGap shl TXC_InterFrameGapShift) - out dx, eax + ; Set DMA burst size and Interframe Gap Time + set_io REG_TxConfig + mov eax, (TX_DMA_BURST shl TXC_DMAShift) or (InterFrameGap shl TXC_InterFrameGapShift) + out dx, eax - set_io REG_CPlusCmd - in ax, dx - out dx, ax + set_io REG_CPlusCmd + in ax, dx + out dx, ax - in ax, dx - or ax, 1 shl 3 - cmp [tpc.mcfg], MCFG_METHOD_02 - jne @f - cmp [tpc.mcfg], MCFG_METHOD_03 - jne @f - or ax,1 shl 14 - DEBUGF 1,"Set MAC Reg C+CR Offset 0xE0: bit-3 and bit-14\n" - jmp .set + in ax, dx + or ax, 1 shl 3 + cmp [tpc.mcfg], MCFG_METHOD_02 + jne @f + cmp [tpc.mcfg], MCFG_METHOD_03 + jne @f + or ax,1 shl 14 + DEBUGF 1,"Set MAC Reg C+CR Offset 0xE0: bit-3 and bit-14\n" + jmp .set @@: - DEBUGF 1,"Set MAC Reg C+CR Offset 0xE0: bit-3\n" + DEBUGF 1,"Set MAC Reg C+CR Offset 0xE0: bit-3\n" .set: - set_io REG_CPlusCmd - out dx, ax + set_io REG_CPlusCmd + out dx, ax - set_io 0xE2 + set_io 0xE2 ; mov ax, 0x1517 ; out dx, ax ; mov ax, 0x152a ; out dx, ax ; mov ax, 0x282a ; out dx, ax - xor ax, ax - out dx, ax + xor ax, ax + out dx, ax - xor eax, eax - mov [tpc.cur_rx], eax - lea eax, [tx_ring] - GetRealAddr - set_io REG_TxDescStartAddr - out dx, eax + xor eax, eax + mov [tpc.cur_rx], eax + lea eax, [tx_ring] + GetRealAddr + set_io REG_TxDescStartAddr + out dx, eax - lea eax, [rx_ring] - GetRealAddr - set_io REG_RxDescStartAddr - out dx, eax + lea eax, [rx_ring] + GetRealAddr + set_io REG_RxDescStartAddr + out dx, eax - set_io REG_Cfg9346 - mov al, CFG_9346_Lock - out dx, al + set_io REG_Cfg9346 + mov al, CFG_9346_Lock + out dx, al - udelay 10 + udelay 10 - xor eax, eax - set_io REG_RxMissed - out dx, eax + xor eax, eax + set_io REG_RxMissed + out dx, eax - call set_rx_mode + call set_rx_mode - set_io 0 - ; no early-rx interrupts - set_io REG_MultiIntr - in ax, dx - and ax, 0xF000 - out dx, ax + set_io 0 + ; no early-rx interrupts + set_io REG_MultiIntr + in ax, dx + and ax, 0xF000 + out dx, ax - ; set interrupt mask - set_io REG_IntrMask - mov ax, intr_mask - out dx, ax + ; set interrupt mask + set_io REG_IntrMask + mov ax, intr_mask + out dx, ax - xor eax, eax - ret + xor eax, eax + ret align 4 read_mac: - set_io 0 - set_io REG_MAC0 - xor ecx, ecx - lea edi, [device.mac] - mov ecx, MAC_ADDR_LEN + set_io 0 + set_io REG_MAC0 + xor ecx, ecx + lea edi, [device.mac] + mov ecx, MAC_ADDR_LEN - ; Get MAC address. FIXME: read EEPROM - @@: in al, dx - stosb - inc edx - loop @r + ; Get MAC address. FIXME: read EEPROM + @@: in al, dx + stosb + inc edx + loop @r - DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",[device.mac+0]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 + DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",[device.mac+0]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 - ret + ret align 4 write_mac: - ret 6 + ret 6 @@ -1026,72 +1026,73 @@ write_mac: align 4 transmit: - DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8] - mov eax, [esp+4] - DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ - [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ - [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ - [eax+13]:2,[eax+12]:2 + DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8] + mov eax, [esp+4] + DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ + [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ + [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ + [eax+13]:2,[eax+12]:2 - cmp dword [esp+8], MAX_ETH_FRAME_SIZE - ja .fail + cmp dword [esp+8], MAX_ETH_FRAME_SIZE + ja .fail ;---------------------------------- ; Find currentTX descriptor address - mov eax, tx_desc.size - mul [tpc.cur_tx] - lea esi, [eax + tx_ring] + mov eax, tx_desc.size + mul [tpc.cur_tx] + lea esi, [eax + tx_ring] - DEBUGF 1,"Using TX desc: %x\n", esi + DEBUGF 1,"Using TX desc: %x\n", esi ;--------------------------- ; Program the packet pointer - mov eax, [esp + 4] - mov [esi + tx_desc.buf_soft_addr], eax - GetRealAddr - mov dword [esi + tx_desc.buf_addr], eax + mov eax, [esp + 4] + mov [esi + tx_desc.buf_soft_addr], eax + GetRealAddr + mov dword [esi + tx_desc.buf_addr], eax ;------------------------ ; Program the packet size - mov eax, [esp + 8] - @@: or eax, DSB_OWNbit or DSB_FSbit or DSB_LSbit - cmp [tpc.cur_tx], NUM_TX_DESC - 1 - jne @f - or eax, DSB_EORbit - @@: mov [esi + tx_desc.status], eax + mov eax, [esp + 8] + @@: or eax, DSB_OWNbit or DSB_FSbit or DSB_LSbit + cmp [tpc.cur_tx], NUM_TX_DESC - 1 + jne @f + or eax, DSB_EORbit + @@: mov [esi + tx_desc.status], eax ;----------------------------------------- ; Set the polling bit (start transmission) - set_io 0 - set_io REG_TxPoll - mov al, 0x40 ; set polling bit - out dx, al + set_io 0 + set_io REG_TxPoll + mov al, 0x40 ; set polling bit + out dx, al ;----------------------- ; Update TX descriptor - inc [tpc.cur_tx] - and [tpc.cur_tx], NUM_TX_DESC - 1 + inc [tpc.cur_tx] + and [tpc.cur_tx], NUM_TX_DESC - 1 ;------------- ; Update stats - inc [device.packets_tx] - mov eax, [esp+8] - add dword [device.bytes_tx], eax - adc dword [device.bytes_tx + 4], 0 + inc [device.packets_tx] + mov eax, [esp+8] + add dword [device.bytes_tx], eax + adc dword [device.bytes_tx + 4], 0 - ret 8 + xor eax, eax + ret 8 .fail: - DEBUGF 1,"transmit failed\n" - or eax, -1 - stdcall KernelFree, [esp+4] - ret 8 + DEBUGF 1,"transmit failed\n" + or eax, -1 + stdcall KernelFree, [esp+4] + ret 8 ;;;DSB_OWNbit @@ -1106,150 +1107,150 @@ transmit: align 4 int_handler: - DEBUGF 1,"IRQ %x ",eax:2 + DEBUGF 1,"IRQ %x ",eax:2 ; find pointer of device wich made IRQ occur - mov ecx, [devices] - test ecx, ecx - jz .fail - mov esi, device_list + mov ecx, [devices] + test ecx, ecx + jz .fail + mov esi, device_list .nextdevice: - mov ebx, dword [esi] + mov ebx, dword [esi] - set_io 0 - set_io REG_IntrStatus - in ax, dx + set_io 0 + set_io REG_IntrStatus + in ax, dx - test ax, ax - jnz .got_it + test ax, ax + jnz .got_it .continue: - add esi, 4 - dec ecx - jnz .nextdevice + add esi, 4 + dec ecx + jnz .nextdevice - ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) + ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) .got_it: - DEBUGF 1,"IntrStatus = 0x%x\n",ax + DEBUGF 1,"IntrStatus = 0x%x\n",ax - cmp ax, 0xFFFF ; if so, hardware is no longer present - je .fail + cmp ax, 0xFFFF ; if so, hardware is no longer present + je .fail ;-------- ; Receive - test ax, ISB_RxOK - jz .no_rx + test ax, ISB_RxOK + jz .no_rx - push ax - push ebx + push ax + push ebx .check_more: - pop ebx - DEBUGF 1,"ebx = 0x%x\n", ebx - mov eax, rx_desc.size - mul [tpc.cur_rx] - lea esi, [eax + rx_ring] + pop ebx + DEBUGF 1,"ebx = 0x%x\n", ebx + mov eax, rx_desc.size + mul [tpc.cur_rx] + lea esi, [eax + rx_ring] - DEBUGF 1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status] + DEBUGF 1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status] - mov eax, [esi + rx_desc.status] - test eax, DSB_OWNbit ;;; - jnz .rx_return + mov eax, [esi + rx_desc.status] + test eax, DSB_OWNbit ;;; + jnz .rx_return - DEBUGF 1,"tpc.cur_rx = %u\n", [tpc.cur_rx] + DEBUGF 1,"tpc.cur_rx = %u\n", [tpc.cur_rx] - test eax, SD_RxRES - jnz .rx_return ;;;;; RX error! + test eax, SD_RxRES + jnz .rx_return ;;;;; RX error! - push ebx - push .check_more - and eax, 0x00001FFF - add eax, -4 ; we dont need CRC - push eax - DEBUGF 1,"data length = %u\n", ax + push ebx + push .check_more + and eax, 0x00001FFF + add eax, -4 ; we dont need CRC + push eax + DEBUGF 1,"data length = %u\n", ax ;------------- ; Update stats - add dword [device.bytes_rx], eax - adc dword [device.bytes_rx + 4], 0 - inc dword [device.packets_rx] + add dword [device.bytes_rx], eax + adc dword [device.bytes_rx + 4], 0 + inc dword [device.packets_rx] - push [esi + rx_desc.buf_soft_addr] + push [esi + rx_desc.buf_soft_addr] ;---------------------- ; Allocate a new buffer - stdcall KernelAlloc, RX_BUF_SIZE - mov [esi + rx_desc.buf_soft_addr], eax - GetRealAddr - mov dword [esi + rx_desc.buf_addr], eax + stdcall KernelAlloc, RX_BUF_SIZE + mov [esi + rx_desc.buf_soft_addr], eax + GetRealAddr + mov dword [esi + rx_desc.buf_addr], eax ;--------------- ; re set OWN bit - mov eax, DSB_OWNbit or RX_BUF_SIZE - cmp [tpc.cur_rx], NUM_RX_DESC - 1 - jne @f - or eax, DSB_EORbit - @@: mov [esi + rx_desc.status], eax + mov eax, DSB_OWNbit or RX_BUF_SIZE + cmp [tpc.cur_rx], NUM_RX_DESC - 1 + jne @f + or eax, DSB_EORbit + @@: mov [esi + rx_desc.status], eax ;-------------- ; Update rx ptr - inc [tpc.cur_rx] - and [tpc.cur_rx], NUM_RX_DESC - 1 + inc [tpc.cur_rx] + and [tpc.cur_rx], NUM_RX_DESC - 1 - jmp EthReceiver + jmp EthReceiver .rx_return: - pop ax + pop ax .no_rx: ;--------- ; Transmit - test ax, ISB_TxOK - jz .no_tx - push ax + test ax, ISB_TxOK + jz .no_tx + push ax - DEBUGF 1,"TX ok!\n" + DEBUGF 1,"TX ok!\n" - mov ecx, NUM_TX_DESC - lea esi, [tx_ring] + mov ecx, NUM_TX_DESC + lea esi, [tx_ring] .txloop: - cmp [esi+tx_desc.buf_soft_addr], 0 - jz .maybenext + cmp [esi+tx_desc.buf_soft_addr], 0 + jz .maybenext - test [esi+tx_desc.status], DSB_OWNbit - jnz .maybenext + test [esi+tx_desc.status], DSB_OWNbit + jnz .maybenext - push ecx - DEBUGF 1,"Freeing up TX desc: %x\n", esi - stdcall KernelFree, [esi+tx_desc.buf_soft_addr] - pop ecx - and [esi+tx_desc.buf_soft_addr], 0 + push ecx + DEBUGF 1,"Freeing up TX desc: %x\n", esi + stdcall KernelFree, [esi+tx_desc.buf_soft_addr] + pop ecx + and [esi+tx_desc.buf_soft_addr], 0 .maybenext: - add esi, tx_desc.size - dec ecx - jnz .txloop + add esi, tx_desc.size + dec ecx + jnz .txloop - pop ax + pop ax .no_tx: ;------- ; Finish - set_io 0 - set_io REG_IntrStatus - out dx, ax ; ACK all interrupts + set_io 0 + set_io REG_IntrStatus + out dx, ax ; ACK all interrupts .fail: - ret + ret @@ -1260,13 +1261,13 @@ int_handler: ; End of code -align 4 ; Place all initialised data here +align 4 ; Place all initialised data here devices dd 0 version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) -my_service db 'RTL8169',0 ; max 16 chars include zero +my_service db 'RTL8169',0 ; max 16 chars include zero -include_debug_strings ; All data wich FDO uses will be included here +include_debug_strings ; All data wich FDO uses will be included here rtl_chip_info dd \ MCFG_METHOD_01, 0xff7e1880, \ ; RTL8169 @@ -1278,7 +1279,7 @@ rtl_chip_info dd \ MCFG_METHOD_12, 0xff7e1880, \ ; RTL8168b/8111b // PCI-E MCFG_METHOD_13, 0xff7e1880, \ ; RTL8101e // PCI-E 8139 MCFG_METHOD_14, 0xff7e1880, \ ; RTL8100e // PCI-E 8139 - MCFG_METHOD_15, 0xff7e1880 ; RTL8100e // PCI-E 8139 + MCFG_METHOD_15, 0xff7e1880 ; RTL8100e // PCI-E 8139 mac_info dd \ 0x38800000, MCFG_METHOD_15, \ @@ -1290,19 +1291,19 @@ mac_info dd \ 0x10000000, MCFG_METHOD_04, \ 0x04000000, MCFG_METHOD_03, \ 0x00800000, MCFG_METHOD_02, \ - 0x00000000, MCFG_METHOD_01 ; catch-all + 0x00000000, MCFG_METHOD_01 ; catch-all -name_01 db "RTL8169", 0 -name_02_03 db "RTL8169s/8110s", 0 -name_04 db "RTL8169sb/8110sb", 0 -name_05 db "RTL8169sc/8110sc", 0 -name_11_12 db "RTL8168b/8111b", 0 ; PCI-E -name_13 db "RTL8101e", 0 ; PCI-E 8139 -name_14_15 db "RTL8100e", 0 ; PCI-E 8139 +name_01 db "RTL8169", 0 +name_02_03 db "RTL8169s/8110s", 0 +name_04 db "RTL8169sb/8110sb", 0 +name_05 db "RTL8169sc/8110sc", 0 +name_11_12 db "RTL8168b/8111b", 0 ; PCI-E +name_13 db "RTL8101e", 0 ; PCI-E 8139 +name_14_15 db "RTL8100e", 0 ; PCI-E 8139 section '.data' data readable writable align 16 ; place all uninitialized data place here -device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling +device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling diff --git a/kernel/branches/net/drivers/i8255x.asm b/kernel/branches/net/drivers/i8255x.asm index 19e0351a3..0511ae81a 100644 --- a/kernel/branches/net/drivers/i8255x.asm +++ b/kernel/branches/net/drivers/i8255x.asm @@ -19,14 +19,14 @@ format MS COFF - API_VERSION equ 0x01000100 - DRIVER_VERSION equ 5 + API_VERSION equ 0x01000100 + DRIVER_VERSION equ 5 - MAX_DEVICES equ 16 + MAX_DEVICES equ 16 - DEBUG equ 1 - __DEBUG__ equ 1 - __DEBUG_LEVEL__ equ 1 + DEBUG equ 1 + __DEBUG__ equ 1 + __DEBUG_LEVEL__ equ 1 include 'proc32.inc' include 'imports.inc' @@ -39,131 +39,131 @@ public version virtual at ebx - device: + device: - ETH_DEVICE + ETH_DEVICE - .io_addr dd ? - .pci_bus db ? - .pci_dev db ? - .irq_line db ? + .io_addr dd ? + .pci_bus db ? + .pci_dev db ? + .irq_line db ? - .rx_buffer dd ? - .tx_buffer dd ? + .rx_buffer dd ? + .tx_buffer dd ? - .ee_bus_width dd ? + .ee_bus_width dd ? - rb 5+8 ;;;; align + rb 5+8 ;;;; align - rxfd: - .status dw ? - .command dw ? - .link dd ? - .rx_buf_addr dd ? - .count dw ? - .size dw ? - .packet dd ? + rxfd: + .status dw ? + .command dw ? + .link dd ? + .rx_buf_addr dd ? + .count dw ? + .size dw ? + .packet dd ? - rb 12 ;;;; + rb 12 ;;;; - txfd: - .status dw ? - .command dw ? - .link dd ? - .tx_desc_addr dd ? - .count dd ? - .tx_buf_addr0 dd ? - .tx_buf_size0 dd ? - .tx_buf_addr1 dd ? - .tx_buf_size1 dd ? + txfd: + .status dw ? + .command dw ? + .link dd ? + .tx_desc_addr dd ? + .count dd ? + .tx_buf_addr0 dd ? + .tx_buf_size0 dd ? + .tx_buf_addr1 dd ? + .tx_buf_size1 dd ? - confcmd: - .status: dw ? - .command: dw ? - .link: dd ? - .data rb 64 + confcmd: + .status: dw ? + .command: dw ? + .link: dd ? + .data rb 64 - lstats: - tx_good_frames dd ? - tx_coll16_errs dd ? - tx_late_colls dd ? - tx_underruns dd ? - tx_lost_carrier dd ? - tx_deferred dd ? - tx_one_colls dd ? - tx_multi_colls dd ? - tx_total_colls dd ? + lstats: + tx_good_frames dd ? + tx_coll16_errs dd ? + tx_late_colls dd ? + tx_underruns dd ? + tx_lost_carrier dd ? + tx_deferred dd ? + tx_one_colls dd ? + tx_multi_colls dd ? + tx_total_colls dd ? - rx_good_frames dd ? - rx_crc_errs dd ? - rx_align_errs dd ? - rx_resource_errs dd ? - rx_overrun_errs dd ? - rx_colls_errs dd ? - rx_runt_errs dd ? + rx_good_frames dd ? + rx_crc_errs dd ? + rx_align_errs dd ? + rx_resource_errs dd ? + rx_overrun_errs dd ? + rx_colls_errs dd ? + rx_runt_errs dd ? - device_size = $ - device + device_size = $ - device end virtual ; Serial EEPROM -EE_SK equ 1 shl 16 ; serial clock -EE_CS equ 1 shl 17 ; chip select -EE_DI equ 1 shl 18 ; data in -EE_DO equ 1 shl 19 ; data out +EE_SK equ 1 shl 16 ; serial clock +EE_CS equ 1 shl 17 ; chip select +EE_DI equ 1 shl 18 ; data in +EE_DO equ 1 shl 19 ; data out -EE_READ equ 110b -EE_WRITE equ 101b -EE_ERASE equ 111b +EE_READ equ 110b +EE_WRITE equ 101b +EE_ERASE equ 111b ; The SCB accepts the following controls for the Tx and Rx units: -CU_START equ 0x0010 -CU_RESUME equ 0x0020 -CU_STATSADDR equ 0x0040 -CU_SHOWSTATS equ 0x0050 ; Dump statistics counters. -CU_CMD_BASE equ 0x0060 ; Base address to add to add CU commands. -CU_DUMPSTATS equ 0x0070 ; Dump then reset stats counters. +CU_START equ 0x0010 +CU_RESUME equ 0x0020 +CU_STATSADDR equ 0x0040 +CU_SHOWSTATS equ 0x0050 ; Dump statistics counters. +CU_CMD_BASE equ 0x0060 ; Base address to add to add CU commands. +CU_DUMPSTATS equ 0x0070 ; Dump then reset stats counters. -RX_START equ 0x0001 -RX_RESUME equ 0x0002 -RX_ABORT equ 0x0004 -RX_ADDR_LOAD equ 0x0006 -RX_RESUMENR equ 0x0007 -INT_MASK equ 0x0100 -DRVR_INT equ 0x0200 ; Driver generated interrupt +RX_START equ 0x0001 +RX_RESUME equ 0x0002 +RX_ABORT equ 0x0004 +RX_ADDR_LOAD equ 0x0006 +RX_RESUMENR equ 0x0007 +INT_MASK equ 0x0100 +DRVR_INT equ 0x0200 ; Driver generated interrupt -CmdIASetup equ 0x0001 -CmdConfigure equ 0x0002 -CmdTx equ 0x0004 ;;;; -CmdTxFlex equ 0x0008 ;;; -Cmdsuspend equ 0x4000 +CmdIASetup equ 0x0001 +CmdConfigure equ 0x0002 +CmdTx equ 0x0004 ;;;; +CmdTxFlex equ 0x0008 ;;; +Cmdsuspend equ 0x4000 -reg_scb_status equ 0 -reg_scb_cmd equ 2 -reg_scb_ptr equ 4 -reg_port equ 8 +reg_scb_status equ 0 +reg_scb_cmd equ 2 +reg_scb_ptr equ 4 +reg_port equ 8 reg_eeprom_ctrl equ 12 -reg_eeprom equ 14 -reg_mdi_ctrl equ 16 +reg_eeprom equ 14 +reg_mdi_ctrl equ 16 macro delay { - push eax - in eax, dx - in eax, dx - in eax, dx - in eax, dx - in eax, dx - in eax, dx - in eax, dx - in eax, dx - in eax, dx - in eax, dx - pop eax + push eax + in eax, dx + in eax, dx + in eax, dx + in eax, dx + in eax, dx + in eax, dx + in eax, dx + in eax, dx + in eax, dx + in eax, dx + pop eax } section '.flat' code readable align 16 @@ -177,19 +177,19 @@ section '.flat' code readable align 16 proc START stdcall, state:dword - cmp [state], 1 - jne .exit + cmp [state], 1 + jne .exit .entry: - DEBUGF 1,"Loading i8255x driver\n" - stdcall RegService, my_service, service_proc - ret + DEBUGF 1,"Loading i8255x driver\n" + stdcall RegService, my_service, service_proc + ret .fail: .exit: - xor eax, eax - ret + xor eax, eax + ret endp @@ -204,133 +204,133 @@ endp align 4 proc service_proc stdcall, ioctl:dword - mov edx, [ioctl] - mov eax, [IOCTL.io_code] + mov edx, [ioctl] + mov eax, [IOCTL.io_code] ;------------------------------------------------------ - cmp eax, 0 ;SRV_GETVERSION - jne @F + cmp eax, 0 ;SRV_GETVERSION + jne @F - cmp [IOCTL.out_size], 4 - jl .fail - mov eax, [IOCTL.output] - mov [eax], dword API_VERSION + cmp [IOCTL.out_size], 4 + jl .fail + mov eax, [IOCTL.output] + mov [eax], dword API_VERSION - xor eax, eax - ret + xor eax, eax + ret ;------------------------------------------------------ @@: - cmp eax, 1 ;SRV_HOOK - jne .fail + cmp eax, 1 ;SRV_HOOK + jne .fail - cmp [IOCTL.inp_size], 3 ; Data input must be at least 3 bytes - jl .fail + cmp [IOCTL.inp_size], 3 ; Data input must be at least 3 bytes + jl .fail - mov eax, [IOCTL.input] - cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given - jne .fail ; other types arent supported for this card yet + mov eax, [IOCTL.input] + cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given + jne .fail ; other types arent supported for this card yet ; check if the device is already listed - mov esi, device_list - mov ecx, [devices] - test ecx, ecx - jz .firstdevice + mov esi, device_list + mov ecx, [devices] + test ecx, ecx + jz .firstdevice ; mov eax, [IOCTL.input] ; get the pci bus and device numbers - mov ax , [eax+1] ; + mov ax , [eax+1] ; .nextdevice: - mov ebx, [esi] - cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) - je .find_devicenum ; Device is already loaded, let's find it's device number - add esi, 4 - loop .nextdevice + mov ebx, [esi] + cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) + je .find_devicenum ; Device is already loaded, let's find it's device number + add esi, 4 + loop .nextdevice ; This device doesnt have its own eth_device structure yet, lets create one .firstdevice: - cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card - jge .fail + cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card + jge .fail - push edx - stdcall KernelAlloc, device_size - pop edx - test eax, eax - jz .fail - mov ebx, eax ; ebx is always used as a pointer to the structure (in driver, but also in kernel code) + push edx + stdcall KernelAlloc, device_size + pop edx + test eax, eax + jz .fail + mov ebx, eax ; ebx is always used as a pointer to the structure (in driver, but also in kernel code) ; Fill in the direct call addresses into the struct - mov [device.reset], reset - mov [device.transmit], transmit + mov [device.reset], reset + mov [device.transmit], transmit ; mov [device.get_MAC], read_mac - mov [device.set_MAC], MAC_write - mov [device.unload], unload - mov [device.name], my_service + mov [device.set_MAC], MAC_write + mov [device.unload], unload + mov [device.name], my_service ; save the pci bus and device numbers - mov eax, [IOCTL.input] - mov cl , [eax+1] - mov [device.pci_bus], cl - mov cl , [eax+2] - mov [device.pci_dev], cl + mov eax, [IOCTL.input] + mov cl , [eax+1] + mov [device.pci_bus], cl + mov cl , [eax+2] + mov [device.pci_dev], cl ; Now, it's time to find the base io addres of the PCI device - find_io [device.pci_bus], [device.pci_dev], [device.io_addr] + find_io [device.pci_bus], [device.pci_dev], [device.io_addr] ; We've found the io address, find IRQ now - find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] + find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] - DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ - [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 + DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ + [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 - allocate_and_clear [device.rx_buffer], (4096), .err - allocate_and_clear [device.tx_buffer], (4096), .err + allocate_and_clear [device.rx_buffer], (4096), .err + allocate_and_clear [device.tx_buffer], (4096), .err ; Ok, the eth_device structure is ready, let's probe the device - call probe ; this function will output in eax - test eax, eax - jnz .err ; If an error occured, exit + call probe ; this function will output in eax + test eax, eax + jnz .err ; If an error occured, exit - mov eax, [devices] ; Add the device structure to our device list - mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) - inc [devices] ; + mov eax, [devices] ; Add the device structure to our device list + mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) + inc [devices] ; - mov [device.type], NET_TYPE_ETH - call NetRegDev + mov [device.type], NET_TYPE_ETH + call NetRegDev - cmp eax, -1 - je .err + cmp eax, -1 + je .err - ret + ret ; If the device was already loaded, find the device number and return it in eax .find_devicenum: - DEBUGF 2,"Trying to find device number of already registered device\n" - call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx - ; into a device number in edi - mov eax, edi ; Application wants it in eax instead - DEBUGF 2,"Kernel says: %u\n", eax - ret + DEBUGF 2,"Trying to find device number of already registered device\n" + call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx + ; into a device number in edi + mov eax, edi ; Application wants it in eax instead + DEBUGF 2,"Kernel says: %u\n", eax + ret ; If an error occured, remove all allocated data and exit (returning -1 in eax) .err: - stdcall KernelFree, [device.rx_buffer] - stdcall KernelFree, [device.tx_buffer] - stdcall KernelFree, ebx + stdcall KernelFree, [device.rx_buffer] + stdcall KernelFree, [device.tx_buffer] + stdcall KernelFree, ebx .fail: - or eax, -1 - ret + or eax, -1 + ret ;------------------------------------------------------ endp @@ -347,15 +347,15 @@ endp unload: - ; TODO: (in this particular order) - ; - ; - Stop the device - ; - Detach int handler - ; - Remove device from local list (device_list) - ; - call unregister function in kernel - ; - Remove all allocated structures and buffers the card used + ; TODO: (in this particular order) + ; + ; - Stop the device + ; - Detach int handler + ; - Remove device from local list (device_list) + ; - call unregister function in kernel + ; - Remove all allocated structures and buffers the card used - or eax,-1 + or eax,-1 ret @@ -369,42 +369,42 @@ ret align 4 probe: - DEBUGF 1,"Probing i8255x\n" + DEBUGF 1,"Probing i8255x\n" - make_bus_master [device.pci_bus], [device.pci_dev] + make_bus_master [device.pci_bus], [device.pci_dev] ;--------------------------- ; First, identify the device - movzx ecx, [device.pci_bus] - movzx edx, [device.pci_dev] - stdcall PciRead32, ecx ,edx ,0 ; get device/vendor id + movzx ecx, [device.pci_bus] + movzx edx, [device.pci_dev] + stdcall PciRead32, ecx ,edx ,0 ; get device/vendor id - DEBUGF 1,"Vendor_id=0x%x\n", ax + DEBUGF 1,"Vendor_id=0x%x\n", ax - cmp ax, 0x8086 - jne .notfound - shr eax, 16 + cmp ax, 0x8086 + jne .notfound + shr eax, 16 - DEBUGF 1,"Device_id=0x%x\n", ax + DEBUGF 1,"Device_id=0x%x\n", ax - mov ecx, DEVICE_IDs - mov edi, device_id_list - repne scasw - jne .notfound - jmp .found + mov ecx, DEVICE_IDs + mov edi, device_id_list + repne scasw + jne .notfound + jmp .found .notfound: - DEBUGF 1,"ERROR: Unsupported device!\n" - or eax, -1 - ret + DEBUGF 1,"ERROR: Unsupported device!\n" + or eax, -1 + ret .found: - call ee_get_width - call MAC_read_eeprom + call ee_get_width + call MAC_read_eeprom - ;;; TODO: detect phy + ;;; TODO: detect phy @@ -420,139 +420,139 @@ reset: ;--------------- ; reset the card - set_io 0 - set_io reg_port - xor eax, eax ; Software Reset - out dx, eax + set_io 0 + set_io reg_port + xor eax, eax ; Software Reset + out dx, eax - mov esi, 10 - call Sleep ; Give the card time to warm up. + mov esi, 10 + call Sleep ; Give the card time to warm up. ;--------------------------------- ; Tell device where to store stats - lea eax, [lstats] - GetRealAddr - set_io reg_scb_ptr - out dx, eax + lea eax, [lstats] + GetRealAddr + set_io reg_scb_ptr + out dx, eax - mov ax, INT_MASK + CU_STATSADDR - set_io reg_scb_cmd - out dx, ax - call cmd_wait + mov ax, INT_MASK + CU_STATSADDR + set_io reg_scb_cmd + out dx, ax + call cmd_wait ;----------------- ; Set CU base to 0 - xor eax, eax - set_io reg_scb_ptr - out dx, eax + xor eax, eax + set_io reg_scb_ptr + out dx, eax - mov ax, INT_MASK + RX_ADDR_LOAD - set_io reg_scb_cmd - out dx, ax - call cmd_wait + mov ax, INT_MASK + RX_ADDR_LOAD + set_io reg_scb_cmd + out dx, ax + call cmd_wait ;--------------------- ; build rxfd structure - mov ax, 0x0001 - mov [rxfd.status], ax - mov ax, 0x0000 - mov [rxfd.command], ax + mov ax, 0x0001 + mov [rxfd.status], ax + mov ax, 0x0000 + mov [rxfd.command], ax - lea eax, [rxfd.status] - GetRealAddr - mov [rxfd.link], eax + lea eax, [rxfd.status] + GetRealAddr + mov [rxfd.link], eax - lea eax, [device.rx_buffer] - GetRealAddr - mov [rxfd.rx_buf_addr], eax + lea eax, [device.rx_buffer] + GetRealAddr + mov [rxfd.rx_buf_addr], eax - xor ax, ax - mov [rxfd.count], ax + xor ax, ax + mov [rxfd.count], ax - mov ax, 1528 - mov [rxfd.size], ax + mov ax, 1528 + mov [rxfd.size], ax ;------------------------------- ; Set ptr to first command block - set_io reg_scb_ptr - lea eax, [rxfd] - GetRealAddr - out dx, eax + set_io reg_scb_ptr + lea eax, [rxfd] + GetRealAddr + out dx, eax - set_io reg_scb_cmd - mov ax, INT_MASK + RX_START - out dx, ax - call cmd_wait + set_io reg_scb_cmd + mov ax, INT_MASK + RX_START + out dx, ax + call cmd_wait ;------------------- ; start the receiver - mov [rxfd.status], 0 - mov [rxfd.command], 0xc000 + mov [rxfd.status], 0 + mov [rxfd.command], 0xc000 - set_io reg_scb_ptr - lea eax, [rxfd] - GetRealAddr - out dx, eax + set_io reg_scb_ptr + lea eax, [rxfd] + GetRealAddr + out dx, eax - set_io reg_scb_cmd - mov ax, INT_MASK + RX_START - out dx, ax - call cmd_wait + set_io reg_scb_cmd + mov ax, INT_MASK + RX_START + out dx, ax + call cmd_wait ;----------------- ; set CU base to 0 - set_io reg_scb_ptr - xor eax, eax - out dx, eax + set_io reg_scb_ptr + xor eax, eax + out dx, eax - set_io reg_scb_cmd - mov ax, INT_MASK + CU_CMD_BASE - out dx, ax - call cmd_wait + set_io reg_scb_cmd + mov ax, INT_MASK + CU_CMD_BASE + out dx, ax + call cmd_wait ;-------------------- ; Set TX Base address ; First, set up confcmd values - mov [txfd.command], CmdIASetup - mov [txfd.status], 0 - lea eax, [confcmd] - GetRealAddr - mov [txfd.link], eax + mov [txfd.command], CmdIASetup + mov [txfd.status], 0 + lea eax, [confcmd] + GetRealAddr + mov [txfd.link], eax - mov word [confcmd.command], Cmdsuspend + CmdConfigure - mov word [confcmd.status], 0 - lea eax, [txfd] - GetRealAddr - mov [confcmd.link], eax + mov word [confcmd.command], Cmdsuspend + CmdConfigure + mov word [confcmd.status], 0 + lea eax, [txfd] + GetRealAddr + mov [confcmd.link], eax - mov byte [confcmd.data + 1], 0x88 ; fifo of 8 each - mov byte [confcmd.data + 4], 0 - mov byte [confcmd.data + 5], 0x80 - mov byte [confcmd.data + 15], 0x48 - mov byte [confcmd.data + 19], 0x80 - mov byte [confcmd.data + 21], 0x05 + mov byte [confcmd.data + 1], 0x88 ; fifo of 8 each + mov byte [confcmd.data + 4], 0 + mov byte [confcmd.data + 5], 0x80 + mov byte [confcmd.data + 15], 0x48 + mov byte [confcmd.data + 19], 0x80 + mov byte [confcmd.data + 21], 0x05 ; CU start ; lea eax, [txfd] ; GetRealAddr - set_io 0 - set_io reg_scb_ptr - out dx, eax + set_io 0 + set_io reg_scb_ptr + out dx, eax - mov ax, INT_MASK + CU_START - set_io reg_scb_cmd - out dx, ax - call cmd_wait + mov ax, INT_MASK + CU_START + set_io reg_scb_cmd + out dx, ax + call cmd_wait ; wait for thing to start @@ -566,9 +566,9 @@ reset: ;;; enable interrupts - xor eax, eax + xor eax, eax - ret + ret @@ -587,65 +587,69 @@ reset: align 4 transmit: - DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8] - mov eax, [esp+4] - DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ - [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ - [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ - [eax+13]:2,[eax+12]:2 + DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8] + mov eax, [esp+4] + DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ + [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ + [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ + [eax+13]:2,[eax+12]:2 - cmp dword [esp+8], 1500 - jg .finish ; packet is too long - cmp dword [esp+8], 60 - jl .finish ; packet is too short + cmp dword [esp+8], 1500 + jg .error ; packet is too long + cmp dword [esp+8], 60 + jl .error ; packet is too short - set_io 0 - in ax, dx - and ax, 0xfc00 - out dx, ax + set_io 0 + in ax, dx + and ax, 0xfc00 + out dx, ax - mov [txfd.status], 0 - mov [txfd.command], Cmdsuspend + CmdTx + CmdTxFlex - lea eax, [txfd] - GetRealAddr - mov [txfd.link], eax - mov [txfd.count], 0x02208000 - lea eax, [txfd.tx_buf_addr0] - GetRealAddr - mov [txfd.tx_desc_addr], eax + mov [txfd.status], 0 + mov [txfd.command], Cmdsuspend + CmdTx + CmdTxFlex + lea eax, [txfd] + GetRealAddr + mov [txfd.link], eax + mov [txfd.count], 0x02208000 + lea eax, [txfd.tx_buf_addr0] + GetRealAddr + mov [txfd.tx_desc_addr], eax - mov eax, [esp+4] - mov [txfd.tx_buf_addr0], eax - mov eax, [esp+8] - mov [txfd.tx_buf_size0], eax + mov eax, [esp+4] + mov [txfd.tx_buf_addr0], eax + mov eax, [esp+8] + mov [txfd.tx_buf_size0], eax - ; Copy the buffer address and size in - mov [txfd.tx_buf_addr1], 0 - mov [txfd.tx_buf_size1], 0 + ; Copy the buffer address and size in + mov [txfd.tx_buf_addr1], 0 + mov [txfd.tx_buf_size1], 0 - lea eax, [txfd] - GetRealAddr - set_io reg_scb_ptr - out dx, eax + lea eax, [txfd] + GetRealAddr + set_io reg_scb_ptr + out dx, eax - mov ax, INT_MASK + CU_START - set_io reg_scb_cmd - out dx, ax + mov ax, INT_MASK + CU_START + set_io reg_scb_cmd + out dx, ax - call cmd_wait + call cmd_wait - in ax, dx + in ax, dx .I8t_001: - cmp [txfd.status], 0 - je .I8t_001 + cmp [txfd.status], 0 + je .I8t_001 - in ax, dx + in ax, dx .finish: - ret 8 - + xor eax, eax + ret 8 + .error: + stdcall KernelFree, [esp+4] + or eax, -1 + ret 8 ;;;;;;;;;;;;;;;;;;;;;;; ;; ;; @@ -656,82 +660,82 @@ transmit: align 4 int_handler: - DEBUGF 1,"IRQ %x ",eax:2 ; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO + DEBUGF 1,"IRQ %x ",eax:2 ; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO ; find pointer of device wich made IRQ occur - mov esi, device_list - mov ecx, [devices] - test ecx, ecx - jz .fail + mov esi, device_list + mov ecx, [devices] + test ecx, ecx + jz .fail .nextdevice: - mov ebx, dword [esi] + mov ebx, dword [esi] - set_io 0 + set_io 0 ;; set_io REG_ISR ;; in ax , dx ;; out dx , ax ; send it back to ACK - add esi, 4 + add esi, 4 - test ax , ax - jnz .got_it + test ax , ax + jnz .got_it - dec ecx - jnz .nextdevice + dec ecx + jnz .nextdevice - ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) + ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) .got_it: ;;; receive - cmp [rxfd.status], 0 - je .nodata + cmp [rxfd.status], 0 + je .nodata - mov [rxfd.status], 0 - mov [rxfd.command], 0xc000 + mov [rxfd.status], 0 + mov [rxfd.command], 0xc000 - set_io reg_scb_ptr - lea eax, [rxfd.status] - GetRealAddr - out dx, eax + set_io reg_scb_ptr + lea eax, [rxfd.status] + GetRealAddr + out dx, eax - set_io reg_scb_cmd - mov ax, INT_MASK + RX_START - out dx, ax + set_io reg_scb_cmd + mov ax, INT_MASK + RX_START + out dx, ax - call cmd_wait + call cmd_wait - movzx ecx, [rxfd.count] - and ecx, 0x3fff + movzx ecx, [rxfd.count] + and ecx, 0x3fff - stdcall KernelAlloc, ecx ; Allocate a buffer to put packet into - push ecx - push eax + stdcall KernelAlloc, ecx ; Allocate a buffer to put packet into + push ecx + push eax - lea esi, [device.rx_buffer] + lea esi, [device.rx_buffer] .copy: - shr ecx, 1 - jnc .nb - movsb + shr ecx, 1 + jnc .nb + movsb .nb: - shr ecx, 1 - jnc .nw - movsw + shr ecx, 1 + jnc .nw + movsw .nw: - jz .nd - rep movsd + jz .nd + rep movsd .nd: - jmp EthReceiver ; Send it to kernel + jmp EthReceiver ; Send it to kernel .nodata: .fail: - ret + ret @@ -739,11 +743,11 @@ int_handler: align 4 cmd_wait: - in al, dx - test al, al - jnz cmd_wait + in al, dx + test al, al + jnz cmd_wait - ret + ret @@ -751,191 +755,191 @@ cmd_wait: align 4 -ee_read: ; esi = address to read +ee_read: ; esi = address to read - set_io 0 - set_io reg_eeprom + set_io 0 + set_io reg_eeprom ;----------------------------------------------------- ; Prepend start bit + read opcode to the address field ; and shift it to the very left bits of esi - mov ecx, 32 - sub ecx, [device.ee_bus_width] - shl esi, cl - or esi, EE_READ shl 28 + mov ecx, 32 + sub ecx, [device.ee_bus_width] + shl esi, cl + or esi, EE_READ shl 28 - mov ecx, [device.ee_bus_width] - add ecx, 3 + mov ecx, [device.ee_bus_width] + add ecx, 3 ;----------------------- ; Write this to the chip .loop: - mov eax, EE_CS - shl esi, 1 - jnc @f - or eax, EE_DI + mov eax, EE_CS + shl esi, 1 + jnc @f + or eax, EE_DI @@: - out dx , eax - delay + out dx , eax + delay - or eax, EE_SK - out dx , eax - delay + or eax, EE_SK + out dx , eax + delay - loop .loop + loop .loop ;------------------------------ ; Now read the data from eeprom - xor esi, esi - mov ecx, 16 + xor esi, esi + mov ecx, 16 .loop2: - mov eax, EE_CS + EE_SK - out dx , eax - delay + mov eax, EE_CS + EE_SK + out dx , eax + delay - in eax, dx - test eax, EE_DO - jz @f - inc esi + in eax, dx + test eax, EE_DO + jz @f + inc esi @@: - shl esi, 1 + shl esi, 1 - mov eax, EE_CS - out dx , eax - delay + mov eax, EE_CS + out dx , eax + delay - loop .loop2 + loop .loop2 ;----------------------- ; de-activate the eeprom - xor eax, eax - out dx, eax + xor eax, eax + out dx, eax - DEBUGF 1,"data=%x\n", esi - ret + DEBUGF 1,"data=%x\n", esi + ret align 4 -ee_write: ; esi = address to write to, di = data +ee_write: ; esi = address to write to, di = data - set_io 0 - set_io reg_eeprom + set_io 0 + set_io reg_eeprom ;----------------------------------------------------- ; Prepend start bit + write opcode to the address field ; and shift it to the very left bits of esi - mov ecx, 32 - sub ecx, [device.ee_bus_width] - shl esi, cl - or esi, EE_WRITE shl 28 + mov ecx, 32 + sub ecx, [device.ee_bus_width] + shl esi, cl + or esi, EE_WRITE shl 28 - mov ecx, [device.ee_bus_width] - add ecx, 3 + mov ecx, [device.ee_bus_width] + add ecx, 3 ;----------------------- ; Write this to the chip .loop: - mov eax, EE_CS - shl esi, 1 - jnc @f - or eax, EE_DI + mov eax, EE_CS + shl esi, 1 + jnc @f + or eax, EE_DI @@: - out dx , eax - delay + out dx , eax + delay - or eax, EE_SK - out dx , eax - delay + or eax, EE_SK + out dx , eax + delay - loop .loop + loop .loop ;----------------------------- ; Now write the data to eeprom - mov ecx, 16 + mov ecx, 16 .loop2: - mov eax, EE_CS - shl di , 1 - jnc @f - or eax, EE_DI + mov eax, EE_CS + shl di , 1 + jnc @f + or eax, EE_DI @@: - out dx , eax - delay + out dx , eax + delay - or eax, EE_SK - out dx , eax - delay + or eax, EE_SK + out dx , eax + delay - loop .loop2 + loop .loop2 ;----------------------- ; de-activate the eeprom - xor eax, eax - out dx, eax + xor eax, eax + out dx, eax - ret + ret align 4 ee_get_width: - set_io 0 - set_io reg_eeprom + set_io 0 + set_io reg_eeprom - mov esi, EE_READ shl 28 - xor ecx, ecx + mov esi, EE_READ shl 28 + xor ecx, ecx .loop: - mov eax, EE_CS - out dx , eax - delay + mov eax, EE_CS + out dx , eax + delay - or eax, EE_SK - out dx , eax - delay + or eax, EE_SK + out dx , eax + delay - inc ecx + inc ecx - in eax, dx - test eax, EE_DO - jnz .loop + in eax, dx + test eax, EE_DO + jnz .loop - mov [device.ee_bus_width], ecx + mov [device.ee_bus_width], ecx ;------------------------------ ; Now read the data from eeprom - mov ecx, 16 + mov ecx, 16 .loop2: - mov eax, EE_CS + EE_SK - out dx , eax - delay + mov eax, EE_CS + EE_SK + out dx , eax + delay - mov eax, EE_CS - out dx , eax - delay - loop .loop2 + mov eax, EE_CS + out dx , eax + delay + loop .loop2 ;----------------------- ; de-activate the eeprom - xor eax, eax - out dx, eax + xor eax, eax + out dx, eax - ret + ret @@ -947,24 +951,24 @@ ee_get_width: align 4 mdio_read: - shl ecx, 21 ; PHY addr - shl edx, 16 ; PHY reg addr + shl ecx, 21 ; PHY addr + shl edx, 16 ; PHY reg addr - mov eax, ecx - or eax, edx - or eax, 10b shl 26 ; read opcode + mov eax, ecx + or eax, edx + or eax, 10b shl 26 ; read opcode - set_io 0 - set_io reg_mdi_ctrl - out dx, eax + set_io 0 + set_io reg_mdi_ctrl + out dx, eax .wait: - delay - in eax, dx - test eax, 1 shl 28 ; ready bit - jz .wait + delay + in eax, dx + test eax, 1 shl 28 ; ready bit + jz .wait - ret + ret ; ax = data ; cx = phy addr @@ -975,26 +979,26 @@ mdio_read: align 4 mdio_write: - and eax, 0xffff + and eax, 0xffff - shl ecx, 21 ; PHY addr - shl edx, 16 ; PHY reg addr + shl ecx, 21 ; PHY addr + shl edx, 16 ; PHY reg addr - or eax, ecx - or eax, edx - or eax, 01b shl 26 ; write opcode + or eax, ecx + or eax, edx + or eax, 01b shl 26 ; write opcode - set_io 0 - set_io reg_mdi_ctrl - out dx, eax + set_io 0 + set_io reg_mdi_ctrl + out dx, eax .wait: - delay - in eax, dx - test eax, 1 shl 28 ; ready bit - jz .wait + delay + in eax, dx + test eax, 1 shl 28 ; ready bit + jz .wait - ret + ret @@ -1003,7 +1007,7 @@ MAC_read_eeprom: ;;;; - ret + ret align 4 @@ -1011,65 +1015,65 @@ MAC_write: ;;;; - ret + ret ; End of code -align 4 ; Place all initialised data here +align 4 ; Place all initialised data here -devices dd 0 ; number of currently running devices +devices dd 0 ; number of currently running devices version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) -my_service db 'i8255x',0 ; max 16 chars include zero +my_service db 'i8255x',0 ; max 16 chars include zero devicename db 'Intel Etherexpress pro/100',0 device_id_list: - dw 0x1029 - dw 0x1030 - dw 0x1031 - dw 0x1032 - dw 0x1033 - dw 0x1034 - dw 0x1038 - dw 0x1039 - dw 0x103A - dw 0x103B - dw 0x103C - dw 0x103D - dw 0x103E - dw 0x1050 - dw 0x1051 - dw 0x1052 - dw 0x1053 - dw 0x1054 - dw 0x1055 - dw 0x1056 - dw 0x1057 - dw 0x1059 - dw 0x1064 - dw 0x1065 - dw 0x1066 - dw 0x1067 - dw 0x1068 - dw 0x1069 - dw 0x106A - dw 0x106B - dw 0x1091 - dw 0x1092 - dw 0x1093 - dw 0x1094 - dw 0x1095 - dw 0x10fe - dw 0x1209 - dw 0x1229 - dw 0x2449 - dw 0x2459 - dw 0x245D - dw 0x27DC + dw 0x1029 + dw 0x1030 + dw 0x1031 + dw 0x1032 + dw 0x1033 + dw 0x1034 + dw 0x1038 + dw 0x1039 + dw 0x103A + dw 0x103B + dw 0x103C + dw 0x103D + dw 0x103E + dw 0x1050 + dw 0x1051 + dw 0x1052 + dw 0x1053 + dw 0x1054 + dw 0x1055 + dw 0x1056 + dw 0x1057 + dw 0x1059 + dw 0x1064 + dw 0x1065 + dw 0x1066 + dw 0x1067 + dw 0x1068 + dw 0x1069 + dw 0x106A + dw 0x106B + dw 0x1091 + dw 0x1092 + dw 0x1093 + dw 0x1094 + dw 0x1095 + dw 0x10fe + dw 0x1209 + dw 0x1229 + dw 0x2449 + dw 0x2459 + dw 0x245D + dw 0x27DC DEVICE_IDs = ($ - device_id_list) / 2 @@ -1080,12 +1084,12 @@ mac_82558_D101_A4 = 4 mac_82558_D101_B0 = 5 mac_82559_D101M = 8 mac_82559_D101S = 9 -mac_82550_D102 = 12 +mac_82550_D102 = 12 mac_82550_D102_C = 13 -mac_82551_E = 14 -mac_82551_F = 15 -mac_82551_10 = 16 -mac_unknown = 0xFF +mac_82551_E = 14 +mac_82551_F = 15 +mac_82551_10 = 16 +mac_unknown = 0xFF phy_100a = 0x000003E0 phy_100c = 0x035002A8 @@ -1099,9 +1103,9 @@ phy_82552_v = 0xd061004d phy_unknown = 0xFFFFFFFF -include_debug_strings ; All data wich FDO uses will be included here +include_debug_strings ; All data wich FDO uses will be included here section '.data' data readable writable align 16 ; place all uninitialized data place here -device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling +device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling diff --git a/kernel/branches/net/drivers/pcnet32.asm b/kernel/branches/net/drivers/pcnet32.asm index 82fb65aca..98e9b3d57 100644 --- a/kernel/branches/net/drivers/pcnet32.asm +++ b/kernel/branches/net/drivers/pcnet32.asm @@ -18,14 +18,14 @@ format MS COFF - API_VERSION equ 0x01000100 + API_VERSION equ 0x01000100 - DEBUG equ 1 - __DEBUG__ equ 1 - __DEBUG_LEVEL__ equ 1 + DEBUG equ 1 + __DEBUG__ equ 1 + __DEBUG_LEVEL__ equ 1 - MAX_DEVICES equ 4 - MAX_ETH_FRAME_SIZE equ 1514 + MAX_DEVICES equ 4 + MAX_ETH_FRAME_SIZE equ 1514 include 'proc32.inc' include 'imports.inc' @@ -40,311 +40,311 @@ public version virtual at ebx - device: + device: - ETH_DEVICE + ETH_DEVICE ; device specific .private: - .mode_ dw ? - .tlen_rlen dw ? - .phys_addr dp ? - .reserved dw ? - .filter dq ? - .rx_ring_phys dd ? - .tx_ring_phys dd ? + .mode_ dw ? + .tlen_rlen dw ? + .phys_addr dp ? + .reserved dw ? + .filter dq ? + .rx_ring_phys dd ? + .tx_ring_phys dd ? - .cur_rx db ? - .cur_tx db ? - .dirty_rx dd ? - .dirty_tx dd ? - .tx_full db ? - .options dd ? - .full_duplex db ? - .chip_version dd ? - .mii db ? - .ltint db ? - .dxsuflo db ? - .fset db ? - .fdx db ? + .cur_rx db ? + .cur_tx db ? + .dirty_rx dd ? + .dirty_tx dd ? + .tx_full db ? + .options dd ? + .full_duplex db ? + .chip_version dd ? + .mii db ? + .ltint db ? + .dxsuflo db ? + .fset db ? + .fdx db ? - .rx_buffer dd ? - .tx_buffer dd ? + .rx_buffer dd ? + .tx_buffer dd ? - .io_addr dd ? - .irq_line db ? - .pci_bus db ? - .pci_dev db ? + .io_addr dd ? + .irq_line db ? + .pci_bus db ? + .pci_dev db ? - .access_read_csr dd ? - .access_write_csr dd ? - .access_read_bcr dd ? - .access_write_bcr dd ? - .access_read_rap dd ? - .access_write_rap dd ? - .access_reset dd ? + .access_read_csr dd ? + .access_write_csr dd ? + .access_read_bcr dd ? + .access_write_bcr dd ? + .access_read_rap dd ? + .access_write_rap dd ? + .access_reset dd ? - device_size = $ - device + device_size = $ - device end virtual struc buf_head { - .base dd ? - .length dw ? - .status dw ? - .msg_length dw ? - .misc dw ? - .reserved dd ? + .base dd ? + .length dw ? + .status dw ? + .msg_length dw ? + .misc dw ? + .reserved dd ? - .size: + .size: } virtual at 0 buf_head buf_head end virtual - PCNET_PORT_AUI equ 0x00 - PCNET_PORT_10BT equ 0x01 - PCNET_PORT_GPSI equ 0x02 - PCNET_PORT_MII equ 0x03 - PCNET_PORT_PORTSEL equ 0x03 - PCNET_PORT_ASEL equ 0x04 - PCNET_PORT_100 equ 0x40 - PCNET_PORT_FD equ 0x80 + PCNET_PORT_AUI equ 0x00 + PCNET_PORT_10BT equ 0x01 + PCNET_PORT_GPSI equ 0x02 + PCNET_PORT_MII equ 0x03 + PCNET_PORT_PORTSEL equ 0x03 + PCNET_PORT_ASEL equ 0x04 + PCNET_PORT_100 equ 0x40 + PCNET_PORT_FD equ 0x80 - PCNET_DMA_MASK equ 0xffffffff + PCNET_DMA_MASK equ 0xffffffff - PCNET_LOG_TX_BUFFERS equ 2 - PCNET_LOG_RX_BUFFERS equ 2 + PCNET_LOG_TX_BUFFERS equ 2 + PCNET_LOG_RX_BUFFERS equ 2 - PCNET_TX_RING_SIZE equ 4 - PCNET_TX_RING_MOD_MASK equ (PCNET_TX_RING_SIZE-1) - PCNET_TX_RING_LEN_BITS equ (PCNET_LOG_TX_BUFFERS shl 12) + PCNET_TX_RING_SIZE equ 4 + PCNET_TX_RING_MOD_MASK equ (PCNET_TX_RING_SIZE-1) + PCNET_TX_RING_LEN_BITS equ (PCNET_LOG_TX_BUFFERS shl 12) - PCNET_RX_RING_SIZE equ 4 - PCNET_RX_RING_MOD_MASK equ (PCNET_RX_RING_SIZE-1) - PCNET_RX_RING_LEN_BITS equ (PCNET_LOG_RX_BUFFERS shl 4) + PCNET_RX_RING_SIZE equ 4 + PCNET_RX_RING_MOD_MASK equ (PCNET_RX_RING_SIZE-1) + PCNET_RX_RING_LEN_BITS equ (PCNET_LOG_RX_BUFFERS shl 4) - PCNET_PKT_BUF_SZ equ 1544 - PCNET_PKT_BUF_SZ_NEG equ 0xf9f8 + PCNET_PKT_BUF_SZ equ 1544 + PCNET_PKT_BUF_SZ_NEG equ 0xf9f8 - PCNET_WIO_RDP equ 0x10 - PCNET_WIO_RAP equ 0x12 - PCNET_WIO_RESET equ 0x14 - PCNET_WIO_BDP equ 0x16 - PCNET_DWIO_RDP equ 0x10 - PCNET_DWIO_RAP equ 0x14 - PCNET_DWIO_RESET equ 0x18 - PCNET_DWIO_BDP equ 0x1C - PCNET_TOTAL_SIZE equ 0x20 + PCNET_WIO_RDP equ 0x10 + PCNET_WIO_RAP equ 0x12 + PCNET_WIO_RESET equ 0x14 + PCNET_WIO_BDP equ 0x16 + PCNET_DWIO_RDP equ 0x10 + PCNET_DWIO_RAP equ 0x14 + PCNET_DWIO_RESET equ 0x18 + PCNET_DWIO_BDP equ 0x1C + PCNET_TOTAL_SIZE equ 0x20 ; CSR registers - PCNET_CSR_CSR equ 0x00 - PCNET_CSR_IAB0 equ 0x01 - PCNET_CSR_IAB1 equ 0x02 - PCNET_CSR_IMR equ 0x03 - PCNET_CSR_TFEAT equ 0x04 - PCNET_CSR_EXTCTL1 equ 0x05 - PCNET_CSR_DTBLLEN equ 0x06 - PCNET_CSR_EXTCTL2 equ 0x07 - PCNET_CSR_MAR0 equ 0x08 - PCNET_CSR_MAR1 equ 0x09 - PCNET_CSR_MAR2 equ 0x0A - PCNET_CSR_MAR3 equ 0x0B - PCNET_CSR_PAR0 equ 0x0C - PCNET_CSR_PAR1 equ 0x0D - PCNET_CSR_PAR2 equ 0x0E - PCNET_CSR_MODE equ 0x0F - PCNET_CSR_RXADDR0 equ 0x18 - PCNET_CSR_RXADDR1 equ 0x19 - PCNET_CSR_TXADDR0 equ 0x1E - PCNET_CSR_TXADDR1 equ 0x1F - PCNET_CSR_TXPOLL equ 0x2F - PCNET_CSR_RXPOLL equ 0x31 - PCNET_CSR_RXRINGLEN equ 0x4C - PCNET_CSR_TXRINGLEN equ 0x4E - PCNET_CSR_DMACTL equ 0x50 - PCNET_CSR_BUSTIMER equ 0x52 - PCNET_CSR_MEMERRTIMEO equ 0x64 - PCNET_CSR_ONNOWMISC equ 0x74 - PCNET_CSR_ADVFEAT equ 0x7A - PCNET_CSR_MACCFG equ 0x7D - PCNET_CSR_CHIPID0 equ 0x58 - PCNET_CSR_CHIPID1 equ 0x59 + PCNET_CSR_CSR equ 0x00 + PCNET_CSR_IAB0 equ 0x01 + PCNET_CSR_IAB1 equ 0x02 + PCNET_CSR_IMR equ 0x03 + PCNET_CSR_TFEAT equ 0x04 + PCNET_CSR_EXTCTL1 equ 0x05 + PCNET_CSR_DTBLLEN equ 0x06 + PCNET_CSR_EXTCTL2 equ 0x07 + PCNET_CSR_MAR0 equ 0x08 + PCNET_CSR_MAR1 equ 0x09 + PCNET_CSR_MAR2 equ 0x0A + PCNET_CSR_MAR3 equ 0x0B + PCNET_CSR_PAR0 equ 0x0C + PCNET_CSR_PAR1 equ 0x0D + PCNET_CSR_PAR2 equ 0x0E + PCNET_CSR_MODE equ 0x0F + PCNET_CSR_RXADDR0 equ 0x18 + PCNET_CSR_RXADDR1 equ 0x19 + PCNET_CSR_TXADDR0 equ 0x1E + PCNET_CSR_TXADDR1 equ 0x1F + PCNET_CSR_TXPOLL equ 0x2F + PCNET_CSR_RXPOLL equ 0x31 + PCNET_CSR_RXRINGLEN equ 0x4C + PCNET_CSR_TXRINGLEN equ 0x4E + PCNET_CSR_DMACTL equ 0x50 + PCNET_CSR_BUSTIMER equ 0x52 + PCNET_CSR_MEMERRTIMEO equ 0x64 + PCNET_CSR_ONNOWMISC equ 0x74 + PCNET_CSR_ADVFEAT equ 0x7A + PCNET_CSR_MACCFG equ 0x7D + PCNET_CSR_CHIPID0 equ 0x58 + PCNET_CSR_CHIPID1 equ 0x59 ; Control and Status Register (CSR0) - PCNET_CSR_INIT equ 1 shl 0 - PCNET_CSR_START equ 1 shl 1 - PCNET_CSR_STOP equ 1 shl 2 - PCNET_CSR_TX equ 1 shl 3 - PCNET_CSR_TXON equ 1 shl 4 - PCNET_CSR_RXON equ 1 shl 5 - PCNET_CSR_INTEN equ 1 shl 6 - PCNET_CSR_INTR equ 1 shl 7 - PCNET_CSR_IDONE equ 1 shl 8 - PCNET_CSR_TINT equ 1 shl 9 - PCNET_CSR_RINT equ 1 shl 10 - PCNET_CSR_MERR equ 1 shl 11 - PCNET_CSR_MISS equ 1 shl 12 - PCNET_CSR_CERR equ 1 shl 13 + PCNET_CSR_INIT equ 1 shl 0 + PCNET_CSR_START equ 1 shl 1 + PCNET_CSR_STOP equ 1 shl 2 + PCNET_CSR_TX equ 1 shl 3 + PCNET_CSR_TXON equ 1 shl 4 + PCNET_CSR_RXON equ 1 shl 5 + PCNET_CSR_INTEN equ 1 shl 6 + PCNET_CSR_INTR equ 1 shl 7 + PCNET_CSR_IDONE equ 1 shl 8 + PCNET_CSR_TINT equ 1 shl 9 + PCNET_CSR_RINT equ 1 shl 10 + PCNET_CSR_MERR equ 1 shl 11 + PCNET_CSR_MISS equ 1 shl 12 + PCNET_CSR_CERR equ 1 shl 13 ; Interrupt masks and deferral control (CSR3) - PCNET_IMR_BSWAP equ 0x0004 - PCNET_IMR_ENMBA equ 0x0008 ; enable modified backoff alg - PCNET_IMR_DXMT2PD equ 0x0010 - PCNET_IMR_LAPPEN equ 0x0020 ; lookahead packet processing enb - PCNET_IMR_DXSUFLO equ 0x0040 ; disable TX stop on underflow - PCNET_IMR_IDONE equ 0x0100 - PCNET_IMR_TINT equ 0x0200 - PCNET_IMR_RINT equ 0x0400 - PCNET_IMR_MERR equ 0x0800 - PCNET_IMR_MISS equ 0x1000 + PCNET_IMR_BSWAP equ 0x0004 + PCNET_IMR_ENMBA equ 0x0008 ; enable modified backoff alg + PCNET_IMR_DXMT2PD equ 0x0010 + PCNET_IMR_LAPPEN equ 0x0020 ; lookahead packet processing enb + PCNET_IMR_DXSUFLO equ 0x0040 ; disable TX stop on underflow + PCNET_IMR_IDONE equ 0x0100 + PCNET_IMR_TINT equ 0x0200 + PCNET_IMR_RINT equ 0x0400 + PCNET_IMR_MERR equ 0x0800 + PCNET_IMR_MISS equ 0x1000 - PCNET_IMR equ PCNET_IMR_TINT+PCNET_IMR_RINT+PCNET_IMR_IDONE+PCNET_IMR_MERR+PCNET_IMR_MISS + PCNET_IMR equ PCNET_IMR_TINT+PCNET_IMR_RINT+PCNET_IMR_IDONE+PCNET_IMR_MERR+PCNET_IMR_MISS ; Test and features control (CSR4) - PCNET_TFEAT_TXSTRTMASK equ 0x0004 - PCNET_TFEAT_TXSTRT equ 0x0008 - PCNET_TFEAT_RXCCOFLOWM equ 0x0010 ; Rx collision counter oflow - PCNET_TFEAT_RXCCOFLOW equ 0x0020 - PCNET_TFEAT_UINT equ 0x0040 - PCNET_TFEAT_UINTREQ equ 0x0080 - PCNET_TFEAT_MISSOFLOWM equ 0x0100 - PCNET_TFEAT_MISSOFLOW equ 0x0200 - PCNET_TFEAT_STRIP_FCS equ 0x0400 - PCNET_TFEAT_PAD_TX equ 0x0800 - PCNET_TFEAT_TXDPOLL equ 0x1000 - PCNET_TFEAT_DMAPLUS equ 0x4000 + PCNET_TFEAT_TXSTRTMASK equ 0x0004 + PCNET_TFEAT_TXSTRT equ 0x0008 + PCNET_TFEAT_RXCCOFLOWM equ 0x0010 ; Rx collision counter oflow + PCNET_TFEAT_RXCCOFLOW equ 0x0020 + PCNET_TFEAT_UINT equ 0x0040 + PCNET_TFEAT_UINTREQ equ 0x0080 + PCNET_TFEAT_MISSOFLOWM equ 0x0100 + PCNET_TFEAT_MISSOFLOW equ 0x0200 + PCNET_TFEAT_STRIP_FCS equ 0x0400 + PCNET_TFEAT_PAD_TX equ 0x0800 + PCNET_TFEAT_TXDPOLL equ 0x1000 + PCNET_TFEAT_DMAPLUS equ 0x4000 ; Extended control and interrupt 1 (CSR5) - PCNET_EXTCTL1_SPND equ 0x0001 ; suspend - PCNET_EXTCTL1_MPMODE equ 0x0002 ; magic packet mode - PCNET_EXTCTL1_MPENB equ 0x0004 ; magic packet enable - PCNET_EXTCTL1_MPINTEN equ 0x0008 ; magic packet interrupt enable - PCNET_EXTCTL1_MPINT equ 0x0010 ; magic packet interrupt - PCNET_EXTCTL1_MPPLBA equ 0x0020 ; magic packet phys. logical bcast - PCNET_EXTCTL1_EXDEFEN equ 0x0040 ; excessive deferral interrupt enb. - PCNET_EXTCTL1_EXDEF equ 0x0080 ; excessive deferral interrupt - PCNET_EXTCTL1_SINTEN equ 0x0400 ; system interrupt enable - PCNET_EXTCTL1_SINT equ 0x0800 ; system interrupt - PCNET_EXTCTL1_LTINTEN equ 0x4000 ; last TX interrupt enb - PCNET_EXTCTL1_TXOKINTD equ 0x8000 ; TX OK interrupt disable + PCNET_EXTCTL1_SPND equ 0x0001 ; suspend + PCNET_EXTCTL1_MPMODE equ 0x0002 ; magic packet mode + PCNET_EXTCTL1_MPENB equ 0x0004 ; magic packet enable + PCNET_EXTCTL1_MPINTEN equ 0x0008 ; magic packet interrupt enable + PCNET_EXTCTL1_MPINT equ 0x0010 ; magic packet interrupt + PCNET_EXTCTL1_MPPLBA equ 0x0020 ; magic packet phys. logical bcast + PCNET_EXTCTL1_EXDEFEN equ 0x0040 ; excessive deferral interrupt enb. + PCNET_EXTCTL1_EXDEF equ 0x0080 ; excessive deferral interrupt + PCNET_EXTCTL1_SINTEN equ 0x0400 ; system interrupt enable + PCNET_EXTCTL1_SINT equ 0x0800 ; system interrupt + PCNET_EXTCTL1_LTINTEN equ 0x4000 ; last TX interrupt enb + PCNET_EXTCTL1_TXOKINTD equ 0x8000 ; TX OK interrupt disable ; RX/TX descriptor len (CSR6) - PCNET_DTBLLEN_RLEN equ 0x0F00 - PCNET_DTBLLEN_TLEN equ 0xF000 + PCNET_DTBLLEN_RLEN equ 0x0F00 + PCNET_DTBLLEN_TLEN equ 0xF000 ; Extended control and interrupt 2 (CSR7) - PCNET_EXTCTL2_MIIPDTINTE equ 0x0001 - PCNET_EXTCTL2_MIIPDTINT equ 0x0002 - PCNET_EXTCTL2_MCCIINTE equ 0x0004 - PCNET_EXTCTL2_MCCIINT equ 0x0008 - PCNET_EXTCTL2_MCCINTE equ 0x0010 - PCNET_EXTCTL2_MCCINT equ 0x0020 - PCNET_EXTCTL2_MAPINTE equ 0x0040 - PCNET_EXTCTL2_MAPINT equ 0x0080 - PCNET_EXTCTL2_MREINTE equ 0x0100 - PCNET_EXTCTL2_MREINT equ 0x0200 - PCNET_EXTCTL2_STINTE equ 0x0400 - PCNET_EXTCTL2_STINT equ 0x0800 - PCNET_EXTCTL2_RXDPOLL equ 0x1000 - PCNET_EXTCTL2_RDMD equ 0x2000 - PCNET_EXTCTL2_RXFRTG equ 0x4000 - PCNET_EXTCTL2_FASTSPNDE equ 0x8000 + PCNET_EXTCTL2_MIIPDTINTE equ 0x0001 + PCNET_EXTCTL2_MIIPDTINT equ 0x0002 + PCNET_EXTCTL2_MCCIINTE equ 0x0004 + PCNET_EXTCTL2_MCCIINT equ 0x0008 + PCNET_EXTCTL2_MCCINTE equ 0x0010 + PCNET_EXTCTL2_MCCINT equ 0x0020 + PCNET_EXTCTL2_MAPINTE equ 0x0040 + PCNET_EXTCTL2_MAPINT equ 0x0080 + PCNET_EXTCTL2_MREINTE equ 0x0100 + PCNET_EXTCTL2_MREINT equ 0x0200 + PCNET_EXTCTL2_STINTE equ 0x0400 + PCNET_EXTCTL2_STINT equ 0x0800 + PCNET_EXTCTL2_RXDPOLL equ 0x1000 + PCNET_EXTCTL2_RDMD equ 0x2000 + PCNET_EXTCTL2_RXFRTG equ 0x4000 + PCNET_EXTCTL2_FASTSPNDE equ 0x8000 ; Mode (CSR15) - PCNET_MODE_RXD equ 0x0001 ; RX disable - PCNET_MODE_TXD equ 0x0002 ; TX disable - PCNET_MODE_LOOP equ 0x0004 ; loopback enable - PCNET_MODE_TXCRCD equ 0x0008 - PCNET_MODE_FORCECOLL equ 0x0010 - PCNET_MODE_RETRYD equ 0x0020 - PCNET_MODE_INTLOOP equ 0x0040 - PCNET_MODE_PORTSEL equ 0x0180 - PCNET_MODE_RXVPAD equ 0x2000 - PCNET_MODE_RXNOBROAD equ 0x4000 - PCNET_MODE_PROMISC equ 0x8000 + PCNET_MODE_RXD equ 0x0001 ; RX disable + PCNET_MODE_TXD equ 0x0002 ; TX disable + PCNET_MODE_LOOP equ 0x0004 ; loopback enable + PCNET_MODE_TXCRCD equ 0x0008 + PCNET_MODE_FORCECOLL equ 0x0010 + PCNET_MODE_RETRYD equ 0x0020 + PCNET_MODE_INTLOOP equ 0x0040 + PCNET_MODE_PORTSEL equ 0x0180 + PCNET_MODE_RXVPAD equ 0x2000 + PCNET_MODE_RXNOBROAD equ 0x4000 + PCNET_MODE_PROMISC equ 0x8000 ; BCR (Bus Control Registers) - PCNET_BCR_MMRA equ 0x00 ; Master Mode Read Active - PCNET_BCR_MMW equ 0x01 ; Master Mode Write Active - PCNET_BCR_MISCCFG equ 0x02 - PCNET_BCR_LED0 equ 0x04 - PCNET_BCR_LED1 equ 0x05 - PCNET_BCR_LED2 equ 0x06 - PCNET_BCR_LED3 equ 0x07 - PCNET_BCR_DUPLEX equ 0x09 - PCNET_BCR_BUSCTL equ 0x12 - PCNET_BCR_EECTL equ 0x13 - PCNET_BCR_SSTYLE equ 0x14 - PCNET_BCR_PCILAT equ 0x16 - PCNET_BCR_PCISUBVENID equ 0x17 - PCNET_BCR_PCISUBSYSID equ 0x18 - PCNET_BCR_SRAMSIZE equ 0x19 - PCNET_BCR_SRAMBOUND equ 0x1A - PCNET_BCR_SRAMCTL equ 0x1B - PCNET_BCR_MIICTL equ 0x20 - PCNET_BCR_MIIADDR equ 0x21 - PCNET_BCR_MIIDATA equ 0x22 - PCNET_BCR_PCIVENID equ 0x23 - PCNET_BCR_PCIPCAP equ 0x24 - PCNET_BCR_DATA0 equ 0x25 - PCNET_BCR_DATA1 equ 0x26 - PCNET_BCR_DATA2 equ 0x27 - PCNET_BCR_DATA3 equ 0x28 - PCNET_BCR_DATA4 equ 0x29 - PCNET_BCR_DATA5 equ 0x2A - PCNET_BCR_DATA6 equ 0x2B - PCNET_BCR_DATA7 equ 0x2C - PCNET_BCR_ONNOWPAT0 equ 0x2D - PCNET_BCR_ONNOWPAT1 equ 0x2E - PCNET_BCR_ONNOWPAT2 equ 0x2F - PCNET_BCR_PHYSEL equ 0x31 + PCNET_BCR_MMRA equ 0x00 ; Master Mode Read Active + PCNET_BCR_MMW equ 0x01 ; Master Mode Write Active + PCNET_BCR_MISCCFG equ 0x02 + PCNET_BCR_LED0 equ 0x04 + PCNET_BCR_LED1 equ 0x05 + PCNET_BCR_LED2 equ 0x06 + PCNET_BCR_LED3 equ 0x07 + PCNET_BCR_DUPLEX equ 0x09 + PCNET_BCR_BUSCTL equ 0x12 + PCNET_BCR_EECTL equ 0x13 + PCNET_BCR_SSTYLE equ 0x14 + PCNET_BCR_PCILAT equ 0x16 + PCNET_BCR_PCISUBVENID equ 0x17 + PCNET_BCR_PCISUBSYSID equ 0x18 + PCNET_BCR_SRAMSIZE equ 0x19 + PCNET_BCR_SRAMBOUND equ 0x1A + PCNET_BCR_SRAMCTL equ 0x1B + PCNET_BCR_MIICTL equ 0x20 + PCNET_BCR_MIIADDR equ 0x21 + PCNET_BCR_MIIDATA equ 0x22 + PCNET_BCR_PCIVENID equ 0x23 + PCNET_BCR_PCIPCAP equ 0x24 + PCNET_BCR_DATA0 equ 0x25 + PCNET_BCR_DATA1 equ 0x26 + PCNET_BCR_DATA2 equ 0x27 + PCNET_BCR_DATA3 equ 0x28 + PCNET_BCR_DATA4 equ 0x29 + PCNET_BCR_DATA5 equ 0x2A + PCNET_BCR_DATA6 equ 0x2B + PCNET_BCR_DATA7 equ 0x2C + PCNET_BCR_ONNOWPAT0 equ 0x2D + PCNET_BCR_ONNOWPAT1 equ 0x2E + PCNET_BCR_ONNOWPAT2 equ 0x2F + PCNET_BCR_PHYSEL equ 0x31 ; RX status register - PCNET_RXSTAT_BPE equ 0x0080 ; bus parity error - PCNET_RXSTAT_ENP equ 0x0100 ; end of packet - PCNET_RXSTAT_STP equ 0x0200 ; start of packet - PCNET_RXSTAT_BUFF equ 0x0400 ; buffer error - PCNET_RXSTAT_CRC equ 0x0800 ; CRC error - PCNET_RXSTAT_OFLOW equ 0x1000 ; rx overrun - PCNET_RXSTAT_FRAM equ 0x2000 ; framing error - PCNET_RXSTAT_ERR equ 0x4000 ; error summary - PCNET_RXSTAT_OWN equ 0x8000 + PCNET_RXSTAT_BPE equ 0x0080 ; bus parity error + PCNET_RXSTAT_ENP equ 0x0100 ; end of packet + PCNET_RXSTAT_STP equ 0x0200 ; start of packet + PCNET_RXSTAT_BUFF equ 0x0400 ; buffer error + PCNET_RXSTAT_CRC equ 0x0800 ; CRC error + PCNET_RXSTAT_OFLOW equ 0x1000 ; rx overrun + PCNET_RXSTAT_FRAM equ 0x2000 ; framing error + PCNET_RXSTAT_ERR equ 0x4000 ; error summary + PCNET_RXSTAT_OWN equ 0x8000 ; TX status register - PCNET_TXSTAT_TRC equ 0x0000000F ; transmit retries - PCNET_TXSTAT_RTRY equ 0x04000000 ; retry - PCNET_TXSTAT_LCAR equ 0x08000000 ; lost carrier - PCNET_TXSTAT_LCOL equ 0x10000000 ; late collision - PCNET_TXSTAT_EXDEF equ 0x20000000 ; excessive deferrals - PCNET_TXSTAT_UFLOW equ 0x40000000 ; transmit underrun - PCNET_TXSTAT_BUFF equ 0x80000000 ; buffer error + PCNET_TXSTAT_TRC equ 0x0000000F ; transmit retries + PCNET_TXSTAT_RTRY equ 0x04000000 ; retry + PCNET_TXSTAT_LCAR equ 0x08000000 ; lost carrier + PCNET_TXSTAT_LCOL equ 0x10000000 ; late collision + PCNET_TXSTAT_EXDEF equ 0x20000000 ; excessive deferrals + PCNET_TXSTAT_UFLOW equ 0x40000000 ; transmit underrun + PCNET_TXSTAT_BUFF equ 0x80000000 ; buffer error - PCNET_TXCTL_OWN equ 0x80000000 - PCNET_TXCTL_ERR equ 0x40000000 ; error summary - PCNET_TXCTL_ADD_FCS equ 0x20000000 ; add FCS to pkt - PCNET_TXCTL_MORE_LTINT equ 0x10000000 - PCNET_TXCTL_ONE equ 0x08000000 - PCNET_TXCTL_DEF equ 0x04000000 - PCNET_TXCTL_STP equ 0x02000000 - PCNET_TXCTL_ENP equ 0x01000000 - PCNET_TXCTL_BPE equ 0x00800000 - PCNET_TXCTL_MBO equ 0x0000F000 - PCNET_TXCTL_BUFSZ equ 0x00000FFF + PCNET_TXCTL_OWN equ 0x80000000 + PCNET_TXCTL_ERR equ 0x40000000 ; error summary + PCNET_TXCTL_ADD_FCS equ 0x20000000 ; add FCS to pkt + PCNET_TXCTL_MORE_LTINT equ 0x10000000 + PCNET_TXCTL_ONE equ 0x08000000 + PCNET_TXCTL_DEF equ 0x04000000 + PCNET_TXCTL_STP equ 0x02000000 + PCNET_TXCTL_ENP equ 0x01000000 + PCNET_TXCTL_BPE equ 0x00800000 + PCNET_TXCTL_MBO equ 0x0000F000 + PCNET_TXCTL_BUFSZ equ 0x00000FFF @@ -360,19 +360,19 @@ section '.flat' code readable align 16 proc START stdcall, state:dword - cmp [state], 1 - jne .exit + cmp [state], 1 + jne .exit .entry: - DEBUGF 1,"Loading PCnet driver\n" - stdcall RegService, my_service, service_proc - ret + DEBUGF 1,"Loading PCnet driver\n" + stdcall RegService, my_service, service_proc + ret .fail: .exit: - xor eax, eax - ret + xor eax, eax + ret endp @@ -387,132 +387,132 @@ endp align 4 proc service_proc stdcall, ioctl:dword - mov edx, [ioctl] - mov eax, [IOCTL.io_code] + mov edx, [ioctl] + mov eax, [IOCTL.io_code] ;------------------------------------------------------ - cmp eax, 0 ;SRV_GETVERSION - jne @F + cmp eax, 0 ;SRV_GETVERSION + jne @F - cmp [IOCTL.out_size], 4 - jl .fail - mov eax, [IOCTL.output] - mov [eax], dword API_VERSION + cmp [IOCTL.out_size], 4 + jl .fail + mov eax, [IOCTL.output] + mov [eax], dword API_VERSION - xor eax, eax - ret + xor eax, eax + ret ;------------------------------------------------------ @@: - cmp eax, 1 ;SRV_HOOK - jne .fail + cmp eax, 1 ;SRV_HOOK + jne .fail - cmp [IOCTL.inp_size], 3 ; Data input must be at least 3 bytes - jl .fail + cmp [IOCTL.inp_size], 3 ; Data input must be at least 3 bytes + jl .fail - mov eax, [IOCTL.input] - cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given - jne .fail ; other types arent supported for this card yet + mov eax, [IOCTL.input] + cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given + jne .fail ; other types arent supported for this card yet ; check if the device is already listed - mov ecx, [devices] - test ecx, ecx - jz .firstdevice + mov ecx, [devices] + test ecx, ecx + jz .firstdevice - mov esi, device_list + mov esi, device_list ; mov eax, [IOCTL.input] ; get the pci bus and device numbers - mov ax , [eax+1] ; + mov ax , [eax+1] ; .nextdevice: - mov ebx, [esi] - cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) - je .find_devicenum ; Device is already loaded, let's find it's device number - add esi, 4 - loop .nextdevice + mov ebx, [esi] + cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) + je .find_devicenum ; Device is already loaded, let's find it's device number + add esi, 4 + loop .nextdevice ; This device doesnt have its own eth_device structure yet, lets create one .firstdevice: - cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card - jge .fail + cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card + jge .fail - allocate_and_clear ebx, device_size, .fail + allocate_and_clear ebx, device_size, .fail ; Fill in the direct call addresses into the struct - mov [device.reset], reset - mov [device.transmit], transmit - mov [device.get_MAC], read_mac - mov [device.set_MAC], write_mac - mov [device.unload], unload - mov [device.name], my_service + mov [device.reset], reset + mov [device.transmit], transmit + mov [device.get_MAC], read_mac + mov [device.set_MAC], write_mac + mov [device.unload], unload + mov [device.name], my_service ; save the pci bus and device numbers - mov eax, [IOCTL.input] - mov cl , [eax+1] - mov [device.pci_bus], cl - mov cl , [eax+2] - mov [device.pci_dev], cl + mov eax, [IOCTL.input] + mov cl , [eax+1] + mov [device.pci_bus], cl + mov cl , [eax+2] + mov [device.pci_dev], cl ; Now, it's time to find the base io addres of the PCI device - find_io [device.pci_bus], [device.pci_dev], [device.io_addr] + find_io [device.pci_bus], [device.pci_dev], [device.io_addr] ; We've found the io address, find IRQ now - find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] + find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] - DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ - [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 + DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ + [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 - allocate_and_clear [device.tx_buffer], PCNET_RX_RING_SIZE * (PCNET_PKT_BUF_SZ + buf_head.size), .err - allocate_and_clear [device.rx_buffer], PCNET_TX_RING_SIZE * (PCNET_PKT_BUF_SZ + buf_head.size), .err + allocate_and_clear [device.tx_buffer], PCNET_RX_RING_SIZE * (PCNET_PKT_BUF_SZ + buf_head.size), .err + allocate_and_clear [device.rx_buffer], PCNET_TX_RING_SIZE * (PCNET_PKT_BUF_SZ + buf_head.size), .err ; Ok, the eth_device structure is ready, let's probe the device ; Because initialization fires IRQ, IRQ handler must be aware of this device - mov eax, [devices] ; Add the device structure to our device list - mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) - inc [devices] ; + mov eax, [devices] ; Add the device structure to our device list + mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) + inc [devices] ; - call probe ; this function will output in eax - test eax, eax - jnz .destroy ; If an error occured, exit + call probe ; this function will output in eax + test eax, eax + jnz .destroy ; If an error occured, exit - mov [device.type], NET_TYPE_ETH - call NetRegDev - cmp eax, -1 - je .destroy + mov [device.type], NET_TYPE_ETH + call NetRegDev + cmp eax, -1 + je .destroy - ret + ret ; If the device was already loaded, find the device number and return it in eax .find_devicenum: - DEBUGF 1,"Trying to find device number of already registered device\n" - mov ebx, eax - call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx - ; into a device number in edi - mov eax, edi ; Application wants it in eax instead - DEBUGF 1,"Kernel says: %u\n", eax - ret + DEBUGF 1,"Trying to find device number of already registered device\n" + mov ebx, eax + call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx + ; into a device number in edi + mov eax, edi ; Application wants it in eax instead + DEBUGF 1,"Kernel says: %u\n", eax + ret ; If an error occured, remove all allocated data and exit (returning -1 in eax) .destroy: - ; todo: reset device into virgin state + ; todo: reset device into virgin state - dec [devices] + dec [devices] .err: - DEBUGF 1,"Error, removing all data !\n" - stdcall KernelFree, [device.rx_buffer] - stdcall KernelFree, [device.tx_buffer] - stdcall KernelFree, ebx + DEBUGF 1,"Error, removing all data !\n" + stdcall KernelFree, [device.rx_buffer] + stdcall KernelFree, [device.tx_buffer] + stdcall KernelFree, ebx .fail: - or eax, -1 - ret + or eax, -1 + ret ;------------------------------------------------------ endp @@ -526,15 +526,15 @@ endp align 4 unload: - ; TODO: (in this particular order) - ; - ; - Stop the device - ; - Detach int handler - ; - Remove device from local list (RTL8139_LIST) - ; - call unregister function in kernel - ; - Remove all allocated structures and buffers the card used + ; TODO: (in this particular order) + ; + ; - Stop the device + ; - Detach int handler + ; - Remove device from local list (RTL8139_LIST) + ; - call unregister function in kernel + ; - Remove all allocated structures and buffers the card used - or eax,-1 + or eax,-1 ret @@ -547,391 +547,391 @@ ret align 4 probe: - mov edx, [device.io_addr] + mov edx, [device.io_addr] - call wio_reset + call wio_reset - xor ecx, ecx - call wio_read_csr - cmp eax, 4 - jne .try_dwio + xor ecx, ecx + call wio_read_csr + cmp eax, 4 + jne .try_dwio - ; Try Word I/O - mov ax , 88 - add edx, PCNET_WIO_RAP - out dx , ax - nop - nop - in ax , dx - sub edx, PCNET_WIO_RAP - cmp ax , 88 - jne .try_dwio + ; Try Word I/O + mov ax , 88 + add edx, PCNET_WIO_RAP + out dx , ax + nop + nop + in ax , dx + sub edx, PCNET_WIO_RAP + cmp ax , 88 + jne .try_dwio - call switch_to_wio + call switch_to_wio - jmp .L1 + jmp .L1 .try_dwio: - call dwio_reset + call dwio_reset - xor ecx, ecx - call dwio_read_csr - cmp eax, 4 - jne .no_dev + xor ecx, ecx + call dwio_read_csr + cmp eax, 4 + jne .no_dev - ; Try Dword I/O - add edx, PCNET_DWIO_RAP - mov eax, 88 - out dx , eax - nop - nop - in eax, dx - sub edx, PCNET_DWIO_RAP - and eax, 0xffff - cmp eax, 88 - jne .no_dev + ; Try Dword I/O + add edx, PCNET_DWIO_RAP + mov eax, 88 + out dx , eax + nop + nop + in eax, dx + sub edx, PCNET_DWIO_RAP + and eax, 0xffff + cmp eax, 88 + jne .no_dev - call switch_to_dwio + call switch_to_dwio - jmp .L1 + jmp .L1 .no_dev: - DEBUGF 1,"PCnet device not found!\n" - mov eax, 1 - ret + DEBUGF 1,"PCnet device not found!\n" + mov eax, 1 + ret .L1: - mov ecx, PCNET_CSR_CHIPID0 - call [device.access_read_csr] - mov esi, eax + mov ecx, PCNET_CSR_CHIPID0 + call [device.access_read_csr] + mov esi, eax - mov ecx, PCNET_CSR_CHIPID1 - call [device.access_read_csr] - shl eax, 16 - or eax, esi + mov ecx, PCNET_CSR_CHIPID1 + call [device.access_read_csr] + shl eax, 16 + or eax, esi - mov ecx, eax - and ecx, 0xfff - cmp ecx, 3 - jne .no_dev + mov ecx, eax + and ecx, 0xfff + cmp ecx, 3 + jne .no_dev - shr eax, 12 - and eax, 0xffff - mov [device.chip_version], eax + shr eax, 12 + and eax, 0xffff + mov [device.chip_version], eax - DEBUGF 1,"chip version ok\n" - mov [device.fdx], 0 - mov [device.mii], 0 - mov [device.fset], 0 - mov [device.dxsuflo], 0 - mov [device.ltint], 0 + DEBUGF 1,"chip version ok\n" + mov [device.fdx], 0 + mov [device.mii], 0 + mov [device.fset], 0 + mov [device.dxsuflo], 0 + mov [device.ltint], 0 - cmp eax, 0x2420 - je .L2 - cmp eax, 0x2430 - je .L2 + cmp eax, 0x2420 + je .L2 + cmp eax, 0x2430 + je .L2 - mov [device.fdx], 1 + mov [device.fdx], 1 - cmp eax, 0x2621 - je .L4 - cmp eax, 0x2623 - je .L5 - cmp eax, 0x2624 - je .L6 - cmp eax, 0x2625 - je .L7 - cmp eax, 0x2626 - je .L8 - cmp eax, 0x2627 - je .L9 + cmp eax, 0x2621 + je .L4 + cmp eax, 0x2623 + je .L5 + cmp eax, 0x2624 + je .L6 + cmp eax, 0x2625 + je .L7 + cmp eax, 0x2626 + je .L8 + cmp eax, 0x2627 + je .L9 - DEBUGF 1,"Invalid chip rev\n" - jmp .no_dev + DEBUGF 1,"Invalid chip rev\n" + jmp .no_dev .L2: - mov [device.name], device_l2 - jmp .L10 + mov [device.name], device_l2 + jmp .L10 .L4: - mov [device.name], device_l4 + mov [device.name], device_l4 ; mov [device.fdx], 1 - jmp .L10 + jmp .L10 .L5: - mov [device.name], device_l5 + mov [device.name], device_l5 ; mov [device.fdx], 1 - mov [device.mii], 1 - mov [device.fset], 1 - mov [device.ltint], 1 - jmp .L10 + mov [device.mii], 1 + mov [device.fset], 1 + mov [device.ltint], 1 + jmp .L10 .L6: - mov [device.name], device_l6 + mov [device.name], device_l6 ; mov [device.fdx], 1 - mov [device.mii], 1 - mov [device.fset], 1 - jmp .L10 + mov [device.mii], 1 + mov [device.fset], 1 + jmp .L10 .L7: - mov [device.name], device_l7 + mov [device.name], device_l7 ; mov [device.fdx], 1 - mov [device.mii], 1 - jmp .L10 + mov [device.mii], 1 + jmp .L10 .L8: - mov [device.name], device_l8 + mov [device.name], device_l8 ; mov [device.fdx], 1 - mov ecx, PCNET_CSR_RXPOLL - call dword [device.access_read_bcr] - call dword [device.access_write_bcr] - jmp .L10 + mov ecx, PCNET_CSR_RXPOLL + call dword [device.access_read_bcr] + call dword [device.access_write_bcr] + jmp .L10 .L9: - mov [device.name], device_l9 + mov [device.name], device_l9 ; mov [device.fdx], 1 - mov [device.mii], 1 + mov [device.mii], 1 .L10: - DEBUGF 1,"device name: %s\n",[device.name] + DEBUGF 1,"device name: %s\n",[device.name] - cmp [device.fset], 1 - jne .L11 - mov ecx, PCNET_BCR_BUSCTL - call [device.access_read_bcr] - or eax, 0x800 - call [device.access_write_bcr] + cmp [device.fset], 1 + jne .L11 + mov ecx, PCNET_BCR_BUSCTL + call [device.access_read_bcr] + or eax, 0x800 + call [device.access_write_bcr] - mov ecx, PCNET_CSR_DMACTL - call [device.access_read_csr] + mov ecx, PCNET_CSR_DMACTL + call [device.access_read_csr] ; and eax, 0xc00 ; or eax, 0xc00 - mov eax, 0xc00 - call [device.access_write_csr] + mov eax, 0xc00 + call [device.access_write_csr] - mov [device.dxsuflo],1 - mov [device.ltint],1 + mov [device.dxsuflo],1 + mov [device.ltint],1 .L11: - make_bus_master [device.pci_bus], [device.pci_dev] + make_bus_master [device.pci_bus], [device.pci_dev] - mov eax, PCNET_PORT_ASEL - mov [device.options], eax - mov [device.mode_], word 0x0003 - mov [device.tlen_rlen], word (PCNET_TX_RING_LEN_BITS or PCNET_RX_RING_LEN_BITS) + mov eax, PCNET_PORT_ASEL + mov [device.options], eax + mov [device.mode_], word 0x0003 + mov [device.tlen_rlen], word (PCNET_TX_RING_LEN_BITS or PCNET_RX_RING_LEN_BITS) - mov dword [device.filter], 0 - mov dword [device.filter+4], 0 + mov dword [device.filter], 0 + mov dword [device.filter+4], 0 - mov eax, PCNET_IMR - mov ecx, PCNET_CSR_IMR ; Write interrupt mask - call [device.access_write_csr] + mov eax, PCNET_IMR + mov ecx, PCNET_CSR_IMR ; Write interrupt mask + call [device.access_write_csr] align 4 reset: ; attach int handler - movzx eax, [device.irq_line] - DEBUGF 1,"Attaching int handler to irq %x\n",eax:1 - stdcall AttachIntHandler, eax, int_handler, dword 0 - test eax, eax - jnz @f - DEBUGF 1,"\nCould not attach int handler!\n" + movzx eax, [device.irq_line] + DEBUGF 1,"Attaching int handler to irq %x\n",eax:1 + stdcall AttachIntHandler, eax, int_handler, dword 0 + test eax, eax + jnz @f + DEBUGF 1,"\nCould not attach int handler!\n" ; or eax, -1 ; ret @@: - mov edx, [device.io_addr] - call [device.access_reset] + mov edx, [device.io_addr] + call [device.access_reset] - ; Switch pcnet32 to 32bit mode - mov ecx, PCNET_BCR_SSTYLE - mov eax, 2 - call [device.access_write_bcr] + ; Switch pcnet32 to 32bit mode + mov ecx, PCNET_BCR_SSTYLE + mov eax, 2 + call [device.access_write_bcr] - ; set/reset autoselect bit - mov ecx, PCNET_BCR_MISCCFG - call [device.access_read_bcr] - and eax,not 2 - test [device.options], PCNET_PORT_ASEL - jz .L1 - or eax, 2 + ; set/reset autoselect bit + mov ecx, PCNET_BCR_MISCCFG + call [device.access_read_bcr] + and eax,not 2 + test [device.options], PCNET_PORT_ASEL + jz .L1 + or eax, 2 .L1: - call [device.access_write_bcr] + call [device.access_write_bcr] - ; Handle full duplex setting - cmp byte [device.full_duplex], 0 - je .L2 - mov ecx, PCNET_BCR_DUPLEX - call [device.access_read_bcr] - and eax, not 3 - test [device.options], PCNET_PORT_FD - jz .L3 - or eax, 1 - cmp [device.options], PCNET_PORT_FD or PCNET_PORT_AUI - jne .L4 - or eax, 2 - jmp .L4 + ; Handle full duplex setting + cmp byte [device.full_duplex], 0 + je .L2 + mov ecx, PCNET_BCR_DUPLEX + call [device.access_read_bcr] + and eax, not 3 + test [device.options], PCNET_PORT_FD + jz .L3 + or eax, 1 + cmp [device.options], PCNET_PORT_FD or PCNET_PORT_AUI + jne .L4 + or eax, 2 + jmp .L4 .L3: - test [device.options], PCNET_PORT_ASEL - jz .L4 - cmp [device.chip_version], 0x2627 - jne .L4 - or eax, 3 + test [device.options], PCNET_PORT_ASEL + jz .L4 + cmp [device.chip_version], 0x2627 + jne .L4 + or eax, 3 .L4: - mov ecx, PCNET_BCR_DUPLEX - call [device.access_write_bcr] + mov ecx, PCNET_BCR_DUPLEX + call [device.access_write_bcr] .L2: - ; set/reset GPSI bit in test register - mov ecx, 124 - call [device.access_read_csr] - mov ecx, [device.options] - and ecx, PCNET_PORT_PORTSEL - cmp ecx, PCNET_PORT_GPSI - jne .L5 - or eax, 0x10 + ; set/reset GPSI bit in test register + mov ecx, 124 + call [device.access_read_csr] + mov ecx, [device.options] + and ecx, PCNET_PORT_PORTSEL + cmp ecx, PCNET_PORT_GPSI + jne .L5 + or eax, 0x10 .L5: - call [device.access_write_csr] - cmp [device.mii], 0 - je .L6 - test [device.options], PCNET_PORT_ASEL - jnz .L6 - mov ecx, PCNET_BCR_MIICTL - call [device.access_read_bcr] - and eax,not 0x38 - test [device.options], PCNET_PORT_FD - jz .L7 - or eax, 0x10 + call [device.access_write_csr] + cmp [device.mii], 0 + je .L6 + test [device.options], PCNET_PORT_ASEL + jnz .L6 + mov ecx, PCNET_BCR_MIICTL + call [device.access_read_bcr] + and eax,not 0x38 + test [device.options], PCNET_PORT_FD + jz .L7 + or eax, 0x10 .L7: - test [device.options], PCNET_PORT_100 - jz .L8 - or eax, 0x08 + test [device.options], PCNET_PORT_100 + jz .L8 + or eax, 0x08 .L8: - call [device.access_write_bcr] - jmp .L9 + call [device.access_write_bcr] + jmp .L9 .L6: - test [device.options], PCNET_PORT_ASEL - jz .L9 - mov ecx, PCNET_BCR_MIICTL - DEBUGF 1,"ASEL, enable auto-negotiation\n" - call [device.access_read_bcr] - and eax, not 0x98 - or eax, 0x20 - call [device.access_write_bcr] + test [device.options], PCNET_PORT_ASEL + jz .L9 + mov ecx, PCNET_BCR_MIICTL + DEBUGF 1,"ASEL, enable auto-negotiation\n" + call [device.access_read_bcr] + and eax, not 0x98 + or eax, 0x20 + call [device.access_write_bcr] .L9: - cmp [device.ltint],0 - je .L10 - mov ecx,5 - call [device.access_read_csr] - or eax,(1 shl 14) - call [device.access_write_csr] + cmp [device.ltint],0 + je .L10 + mov ecx,5 + call [device.access_read_csr] + or eax,(1 shl 14) + call [device.access_write_csr] .L10: - mov eax,[device.options] - and eax,PCNET_PORT_PORTSEL - shl eax,7 - mov [device.mode_],ax - mov dword [device.filter], -1 - mov dword [device.filter+4], -1 + mov eax,[device.options] + and eax,PCNET_PORT_PORTSEL + shl eax,7 + mov [device.mode_],ax + mov dword [device.filter], -1 + mov dword [device.filter+4], -1 - call read_mac + call read_mac - lea esi, [device.mac] - lea edi, [device.phys_addr] - movsd - movsw + lea esi, [device.mac] + lea edi, [device.phys_addr] + movsd + movsw - call init_ring + call init_ring - lea eax, [device.private] - GetRealAddr + lea eax, [device.private] + GetRealAddr - push eax - and eax, 0xffff - mov ecx, 1 - call [device.access_write_csr] - pop eax - shr eax,16 - mov ecx,2 - call [device.access_write_csr] + push eax + and eax, 0xffff + mov ecx, 1 + call [device.access_write_csr] + pop eax + shr eax,16 + mov ecx,2 + call [device.access_write_csr] - mov ecx,4 - mov eax,0x0915 - call [device.access_write_csr] + mov ecx,4 + mov eax,0x0915 + call [device.access_write_csr] - mov ecx,0 - mov eax,1 - call [device.access_write_csr] + mov ecx,0 + mov eax,1 + call [device.access_write_csr] - mov [device.tx_full],0 - mov [device.cur_rx],0 - mov [device.cur_tx],0 - mov [device.dirty_rx],0 - mov [device.dirty_tx],0 + mov [device.tx_full],0 + mov [device.cur_rx],0 + mov [device.cur_tx],0 + mov [device.dirty_rx],0 + mov [device.dirty_tx],0 - mov ecx,100 + mov ecx,100 .L11: - push ecx - xor ecx,ecx - call [device.access_read_csr] - pop ecx - test ax,0x100 - jnz .L12 - loop .L11 + push ecx + xor ecx,ecx + call [device.access_read_csr] + pop ecx + test ax,0x100 + jnz .L12 + loop .L11 .L12: - DEBUGF 1,"hardware reset\n" - xor ecx, ecx - mov eax, 0x0002 - call [device.access_write_csr] + DEBUGF 1,"hardware reset\n" + xor ecx, ecx + mov eax, 0x0002 + call [device.access_write_csr] - xor ecx, ecx - call [device.access_read_csr] + xor ecx, ecx + call [device.access_read_csr] - xor ecx, ecx - mov eax, PCNET_CSR_INTEN or PCNET_CSR_START - call [device.access_write_csr] + xor ecx, ecx + mov eax, PCNET_CSR_INTEN or PCNET_CSR_START + call [device.access_write_csr] ; Set the mtu, kernel will be able to send now - mov [device.mtu], 1514 + mov [device.mtu], 1514 - DEBUGF 1,"PCNET reset complete\n" - xor eax, eax - ret + DEBUGF 1,"PCNET reset complete\n" + xor eax, eax + ret align 4 init_ring: - mov ecx, PCNET_RX_RING_SIZE - mov edi, [device.rx_buffer] - mov eax, edi - GetRealAddr - mov [device.rx_ring_phys], eax - add eax, PCNET_RX_RING_SIZE * buf_head.size + mov ecx, PCNET_RX_RING_SIZE + mov edi, [device.rx_buffer] + mov eax, edi + GetRealAddr + mov [device.rx_ring_phys], eax + add eax, PCNET_RX_RING_SIZE * buf_head.size .rx_init: - mov [edi + buf_head.base], eax - mov [edi + buf_head.length], PCNET_PKT_BUF_SZ_NEG - mov [edi + buf_head.status], 0x8000 - and dword [edi + buf_head.msg_length], 0 - and dword [edi + buf_head.reserved], 0 - add eax, PCNET_PKT_BUF_SZ - add edi, buf_head.size - loop .rx_init + mov [edi + buf_head.base], eax + mov [edi + buf_head.length], PCNET_PKT_BUF_SZ_NEG + mov [edi + buf_head.status], 0x8000 + and dword [edi + buf_head.msg_length], 0 + and dword [edi + buf_head.reserved], 0 + add eax, PCNET_PKT_BUF_SZ + add edi, buf_head.size + loop .rx_init - mov ecx, PCNET_TX_RING_SIZE - mov edi, [device.tx_buffer] - mov eax, edi - GetRealAddr - mov [device.tx_ring_phys], eax - add eax, PCNET_TX_RING_SIZE * buf_head.size + mov ecx, PCNET_TX_RING_SIZE + mov edi, [device.tx_buffer] + mov eax, edi + GetRealAddr + mov [device.tx_ring_phys], eax + add eax, PCNET_TX_RING_SIZE * buf_head.size .tx_init: - mov [edi + buf_head.base], eax - and dword [edi + buf_head.length], 0 - and dword [edi + buf_head.msg_length], 0 - and dword [edi + buf_head.reserved], 0 - add eax, PCNET_PKT_BUF_SZ - add edi, buf_head.size - loop .tx_init + mov [edi + buf_head.base], eax + and dword [edi + buf_head.length], 0 + and dword [edi + buf_head.msg_length], 0 + and dword [edi + buf_head.reserved], 0 + add eax, PCNET_PKT_BUF_SZ + add edi, buf_head.size + loop .tx_init - mov [device.tlen_rlen], (PCNET_TX_RING_LEN_BITS or PCNET_RX_RING_LEN_BITS) + mov [device.tlen_rlen], (PCNET_TX_RING_LEN_BITS or PCNET_RX_RING_LEN_BITS) - ret + ret @@ -948,65 +948,66 @@ init_ring: align 4 transmit: - DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8] - mov eax, [esp+4] - DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ - [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ - [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ - [eax+13]:2,[eax+12]:2 + DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8] + mov eax, [esp+4] + DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ + [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ + [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ + [eax+13]:2,[eax+12]:2 - cmp dword [esp+8], 1514 - jg .finish ; packet is too long - cmp dword [esp+8], 60 - jl .finish ; packet is too short + cmp dword [esp+8], 1514 + jg .nospace ; packet is too long + cmp dword [esp+8], 60 + jl .nospace ; packet is too short ; check descriptor - movzx eax, [device.cur_tx] - imul edi, eax, PCNET_PKT_BUF_SZ - shl eax, 4 - add eax, [device.tx_buffer] - add edi, [device.tx_buffer] - add edi, PCNET_TX_RING_SIZE * buf_head.size + movzx eax, [device.cur_tx] + imul edi, eax, PCNET_PKT_BUF_SZ + shl eax, 4 + add eax, [device.tx_buffer] + add edi, [device.tx_buffer] + add edi, PCNET_TX_RING_SIZE * buf_head.size - test byte [eax + buf_head.status + 1], 80h - jnz .nospace + test byte [eax + buf_head.status + 1], 80h + jnz .nospace ; descriptor is free, copy data - mov esi, [esp+4] - mov ecx, [esp+8] - mov edx, ecx - shr ecx, 2 - and edx, 3 - rep movsd - mov ecx, edx - rep movsb + mov esi, [esp+4] + mov ecx, [esp+8] + mov edx, ecx + shr ecx, 2 + and edx, 3 + rep movsd + mov ecx, edx + rep movsb ; set length - mov ecx, [esp+8] - neg ecx - mov [eax + buf_head.length], cx + mov ecx, [esp+8] + neg ecx + mov [eax + buf_head.length], cx ; put to transfer queue - mov [eax + buf_head.status], 0x8300 + mov [eax + buf_head.status], 0x8300 ; trigger an immediate send - xor ecx, ecx ; CSR0 - call [device.access_read_csr] - or eax, PCNET_CSR_TX - call [device.access_write_csr] + xor ecx, ecx ; CSR0 + call [device.access_read_csr] + or eax, PCNET_CSR_TX + call [device.access_write_csr] ; get next descriptor 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, ... - inc [device.cur_tx] - and [device.cur_tx], 3 - DEBUGF 2," - Packet Sent! " + inc [device.cur_tx] + and [device.cur_tx], 3 + DEBUGF 2," - Packet Sent! " .finish: - DEBUGF 2," - Done!\n" - stdcall KernelFree, [esp+4] - ret 8 + DEBUGF 2," - Done!\n" + stdcall KernelFree, [esp+4] + xor eax, eax + ret 8 .nospace: - DEBUGF 1, 'ERROR: no free transmit descriptors\n' -; todo: maybe somehow notify the kernel about the error? - stdcall KernelFree, [esp+4] - ret 8 + DEBUGF 1, 'ERROR: no free transmit descriptors\n' + stdcall KernelFree, [esp+4] + or eax, -1 + ret 8 @@ -1023,26 +1024,26 @@ int_handler: ; find pointer of device wich made IRQ occur - mov esi, device_list - mov ecx, [devices] - test ecx, ecx - jz .abort + mov esi, device_list + mov ecx, [devices] + test ecx, ecx + jz .abort .nextdevice: - mov ebx, dword [esi] - mov edx, [device.io_addr] ; get IRQ reason + mov ebx, dword [esi] + mov edx, [device.io_addr] ; get IRQ reason - push ecx - xor ecx, ecx ; CSR0 - call [device.access_read_csr] - pop ecx + push ecx + xor ecx, ecx ; CSR0 + call [device.access_read_csr] + pop ecx - test al , al - js .got_it + test al , al + js .got_it - add esi, 4 - loop .nextdevice + add esi, 4 + loop .nextdevice - ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver + ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver .got_it: ;------------------------------------------------------- @@ -1053,71 +1054,71 @@ int_handler: ; Clear ALL IRQ reasons. ; N.B. One who wants to handle more than one reason must be ready ; to two or more reasons in one IRQ. - xor ecx, ecx - call [device.access_write_csr] + xor ecx, ecx + call [device.access_write_csr] ; Received packet ok? - test ax, PCNET_CSR_RINT - jz @f + test ax, PCNET_CSR_RINT + jz @f .receiver_test_loop: - movzx eax, [device.cur_rx] + movzx eax, [device.cur_rx] ; and eax, PCNET_RX_RING_MOD_MASK - mov edi, eax + mov edi, eax - imul esi, eax, PCNET_PKT_BUF_SZ ; - add esi, [device.rx_buffer] ; esi now points to rx buffer - add esi, PCNET_RX_RING_SIZE * buf_head.size + imul esi, eax, PCNET_PKT_BUF_SZ ; + add esi, [device.rx_buffer] ; esi now points to rx buffer + add esi, PCNET_RX_RING_SIZE * buf_head.size - shl edi, 4 ; desc * 16 (16 is size of one ring entry) - add edi, [device.rx_buffer] ; edi now points to current rx ring entry + shl edi, 4 ; desc * 16 (16 is size of one ring entry) + add edi, [device.rx_buffer] ; edi now points to current rx ring entry - mov cx , [edi + buf_head.status] + mov cx , [edi + buf_head.status] - test cx , PCNET_RXSTAT_OWN ; If this bit is set, the controller OWN's the packet, if not, we do - jnz .abort + test cx , PCNET_RXSTAT_OWN ; If this bit is set, the controller OWN's the packet, if not, we do + jnz .abort - test cx , PCNET_RXSTAT_ENP - jz .abort + test cx , PCNET_RXSTAT_ENP + jz .abort - test cx , PCNET_RXSTAT_STP - jz .abort + test cx , PCNET_RXSTAT_STP + jz .abort - movzx ecx, [edi + buf_head.msg_length] ; get packet length in ecx - sub ecx, 4 ; + movzx ecx, [edi + buf_head.msg_length] ; get packet length in ecx + sub ecx, 4 ; - push ecx - stdcall KernelAlloc, ecx ; Allocate a buffer to put packet into - pop ecx - test eax, eax ; Test if we allocated succesfully - jz .abort ; + push ecx + stdcall KernelAlloc, ecx ; Allocate a buffer to put packet into + pop ecx + test eax, eax ; Test if we allocated succesfully + jz .abort ; - push .receiver_test_loop ; - push ecx ; for eth_receiver - push eax ; + push .receiver_test_loop ; + push ecx ; for eth_receiver + push eax ; - xchg edi, eax - push ecx - shr ecx, 2 - cld - rep movsd - pop ecx - and ecx, 3 - rep movsb + xchg edi, eax + push ecx + shr ecx, 2 + cld + rep movsd + pop ecx + and ecx, 3 + rep movsb ; mov word [eax + buf_head.length], PCNET_PKT_BUF_SZ_NEG - mov word [eax + buf_head.status], PCNET_RXSTAT_OWN ; Set OWN bit back to 1 (controller may write to tx-buffer again now) + mov word [eax + buf_head.status], PCNET_RXSTAT_OWN ; Set OWN bit back to 1 (controller may write to tx-buffer again now) - inc [device.cur_rx] ; update descriptor - and [device.cur_rx], 3 ; + inc [device.cur_rx] ; update descriptor + and [device.cur_rx], 3 ; - jmp EthReceiver ; Send the copied packet to kernel + jmp EthReceiver ; Send the copied packet to kernel .abort: @@: - ret + ret @@ -1129,24 +1130,24 @@ int_handler: ;;;;;;;;;;;;;;;;;;;;;;; align 4 -write_mac: ; in: mac pushed onto stack (as 3 words) +write_mac: ; in: mac pushed onto stack (as 3 words) - DEBUGF 1,"Writing MAC: %x-%x-%x-%x-%x-%x",[esp+0]:2,[esp+1]:2,[esp+2]:2,[esp+3]:2,[esp+4]:2,[esp+5]:2 + DEBUGF 1,"Writing MAC: %x-%x-%x-%x-%x-%x",[esp+0]:2,[esp+1]:2,[esp+2]:2,[esp+3]:2,[esp+4]:2,[esp+5]:2 - mov edx, [device.io_addr] - add dx, 2 - xor eax, eax + mov edx, [device.io_addr] + add dx, 2 + xor eax, eax - mov ecx, PCNET_CSR_PAR0 + mov ecx, PCNET_CSR_PAR0 @@: - pop ax - call [device.access_write_csr] - DEBUGF 1,"." - inc ecx - cmp ecx, PCNET_CSR_PAR2 - jl @r + pop ax + call [device.access_write_csr] + DEBUGF 1,"." + inc ecx + cmp ecx, PCNET_CSR_PAR2 + jl @r - DEBUGF 1,"\n" + DEBUGF 1,"\n" ; Notice this procedure does not ret, but continues to read_mac instead. @@ -1157,60 +1158,60 @@ write_mac: ; in: mac pushed onto stack (as 3 words) ;;;;;;;;;;;;;;;;;;;;;; align 4 read_mac: - DEBUGF 1,"Reading MAC" + DEBUGF 1,"Reading MAC" - mov edx, [device.io_addr] - add dx, 6 + mov edx, [device.io_addr] + add dx, 6 @@: - dec dx - dec dx - in ax, dx - push ax - DEBUGF 1,"." - cmp edx, [device.io_addr] - jg @r + dec dx + dec dx + in ax, dx + push ax + DEBUGF 1,"." + cmp edx, [device.io_addr] + jg @r - DEBUGF 1," %x-%x-%x-%x-%x-%x\n",[esp+0]:2,[esp+1]:2,[esp+2]:2,[esp+3]:2,[esp+4]:2,[esp+5]:2 + DEBUGF 1," %x-%x-%x-%x-%x-%x\n",[esp+0]:2,[esp+1]:2,[esp+2]:2,[esp+3]:2,[esp+4]:2,[esp+5]:2 - lea edi, [device.mac] - pop ax - stosw - pop ax - stosw - pop ax - stosw + lea edi, [device.mac] + pop ax + stosw + pop ax + stosw + pop ax + stosw - ret + ret align 4 switch_to_wio: - DEBUGF 1,"Switching to 16-bit mode\n" + DEBUGF 1,"Switching to 16-bit mode\n" - mov [device.access_read_csr], wio_read_csr - mov [device.access_write_csr], wio_write_csr - mov [device.access_read_bcr], wio_read_bcr - mov [device.access_write_bcr], wio_write_bcr - mov [device.access_read_rap], wio_read_rap - mov [device.access_write_rap], wio_write_rap - mov [device.access_reset], wio_reset + mov [device.access_read_csr], wio_read_csr + mov [device.access_write_csr], wio_write_csr + mov [device.access_read_bcr], wio_read_bcr + mov [device.access_write_bcr], wio_write_bcr + mov [device.access_read_rap], wio_read_rap + mov [device.access_write_rap], wio_write_rap + mov [device.access_reset], wio_reset - ret + ret align 4 switch_to_dwio: - DEBUGF 1,"Switching to 32-bit mode\n" + DEBUGF 1,"Switching to 32-bit mode\n" - mov [device.access_read_csr], dwio_read_csr - mov [device.access_write_csr], dwio_write_csr - mov [device.access_read_bcr], dwio_read_bcr - mov [device.access_write_bcr], dwio_write_bcr - mov [device.access_read_rap], dwio_read_rap - mov [device.access_write_rap], dwio_write_rap - mov [device.access_reset], dwio_reset + mov [device.access_read_csr], dwio_read_csr + mov [device.access_write_csr], dwio_write_csr + mov [device.access_read_bcr], dwio_read_bcr + mov [device.access_write_bcr], dwio_write_bcr + mov [device.access_read_rap], dwio_read_rap + mov [device.access_write_rap], dwio_write_rap + mov [device.access_reset], dwio_reset - ret + ret ; ecx - index @@ -1219,15 +1220,15 @@ switch_to_dwio: align 4 wio_read_csr: - add edx, PCNET_WIO_RAP - mov ax , cx - out dx , ax - add edx, PCNET_WIO_RDP - PCNET_WIO_RAP - in ax , dx - and eax, 0xffff - sub edx, PCNET_WIO_RDP + add edx, PCNET_WIO_RAP + mov ax , cx + out dx , ax + add edx, PCNET_WIO_RDP - PCNET_WIO_RAP + in ax , dx + and eax, 0xffff + sub edx, PCNET_WIO_RDP - ret + ret ; eax - data @@ -1235,15 +1236,15 @@ wio_read_csr: align 4 wio_write_csr: - add edx, PCNET_WIO_RAP - xchg eax, ecx - out dx , ax - xchg eax, ecx - add edx, PCNET_WIO_RDP - PCNET_WIO_RAP - out dx , ax - sub edx, PCNET_WIO_RDP + add edx, PCNET_WIO_RAP + xchg eax, ecx + out dx , ax + xchg eax, ecx + add edx, PCNET_WIO_RDP - PCNET_WIO_RAP + out dx , ax + sub edx, PCNET_WIO_RDP - ret + ret ; ecx - index @@ -1252,15 +1253,15 @@ wio_write_csr: align 4 wio_read_bcr: - add edx, PCNET_WIO_RAP - mov ax , cx - out dx , ax - add edx, PCNET_WIO_BDP - PCNET_WIO_RAP - in ax , dx - and eax, 0xffff - sub edx, PCNET_WIO_BDP + add edx, PCNET_WIO_RAP + mov ax , cx + out dx , ax + add edx, PCNET_WIO_BDP - PCNET_WIO_RAP + in ax , dx + and eax, 0xffff + sub edx, PCNET_WIO_BDP - ret + ret ; eax - data @@ -1268,46 +1269,46 @@ wio_read_bcr: align 4 wio_write_bcr: - add edx, PCNET_WIO_RAP - xchg eax, ecx - out dx , ax - xchg eax, ecx - add edx, PCNET_WIO_BDP - PCNET_WIO_RAP - out dx , ax - sub edx, PCNET_WIO_BDP + add edx, PCNET_WIO_RAP + xchg eax, ecx + out dx , ax + xchg eax, ecx + add edx, PCNET_WIO_BDP - PCNET_WIO_RAP + out dx , ax + sub edx, PCNET_WIO_BDP - ret + ret align 4 wio_read_rap: - add edx, PCNET_WIO_RAP - in ax , dx - and eax, 0xffff - sub edx, PCNET_WIO_RAP + add edx, PCNET_WIO_RAP + in ax , dx + and eax, 0xffff + sub edx, PCNET_WIO_RAP - ret + ret ; eax - val align 4 wio_write_rap: - add edx, PCNET_WIO_RAP - out dx , ax - sub edx, PCNET_WIO_RAP + add edx, PCNET_WIO_RAP + out dx , ax + sub edx, PCNET_WIO_RAP - ret + ret align 4 wio_reset: - push eax - add edx, PCNET_WIO_RESET - in ax , dx - pop eax - sub edx, PCNET_WIO_RESET + push eax + add edx, PCNET_WIO_RESET + in ax , dx + pop eax + sub edx, PCNET_WIO_RESET - ret + ret @@ -1317,15 +1318,15 @@ wio_reset: align 4 dwio_read_csr: - add edx, PCNET_DWIO_RAP - mov eax, ecx - out dx , eax - add edx, PCNET_DWIO_RDP - PCNET_DWIO_RAP - in eax, dx - and eax, 0xffff - sub edx, PCNET_DWIO_RDP + add edx, PCNET_DWIO_RAP + mov eax, ecx + out dx , eax + add edx, PCNET_DWIO_RDP - PCNET_DWIO_RAP + in eax, dx + and eax, 0xffff + sub edx, PCNET_DWIO_RDP - ret + ret ; ecx - index @@ -1333,15 +1334,15 @@ dwio_read_csr: align 4 dwio_write_csr: - add edx, PCNET_DWIO_RAP - xchg eax, ecx - out dx , eax - add edx, PCNET_DWIO_RDP - PCNET_DWIO_RAP - xchg eax, ecx - out dx , eax - sub edx, PCNET_DWIO_RDP + add edx, PCNET_DWIO_RAP + xchg eax, ecx + out dx , eax + add edx, PCNET_DWIO_RDP - PCNET_DWIO_RAP + xchg eax, ecx + out dx , eax + sub edx, PCNET_DWIO_RDP - ret + ret ; ecx - index ; return: @@ -1349,15 +1350,15 @@ dwio_write_csr: align 4 dwio_read_bcr: - add edx, PCNET_DWIO_RAP - mov eax, ecx - out dx , eax - add edx, PCNET_DWIO_BDP - PCNET_DWIO_RAP - in eax, dx - and eax, 0xffff - sub edx, PCNET_DWIO_BDP + add edx, PCNET_DWIO_RAP + mov eax, ecx + out dx , eax + add edx, PCNET_DWIO_BDP - PCNET_DWIO_RAP + in eax, dx + and eax, 0xffff + sub edx, PCNET_DWIO_BDP - ret + ret ; ecx - index @@ -1365,57 +1366,57 @@ dwio_read_bcr: align 4 dwio_write_bcr: - add edx, PCNET_DWIO_RAP - xchg eax, ecx - out dx , eax - add edx, PCNET_DWIO_BDP - PCNET_DWIO_RAP - xchg eax, ecx - out dx , eax - sub edx, PCNET_DWIO_BDP + add edx, PCNET_DWIO_RAP + xchg eax, ecx + out dx , eax + add edx, PCNET_DWIO_BDP - PCNET_DWIO_RAP + xchg eax, ecx + out dx , eax + sub edx, PCNET_DWIO_BDP - ret + ret align 4 dwio_read_rap: - add edx, PCNET_DWIO_RAP - in eax, dx - and eax, 0xffff - sub edx, PCNET_DWIO_RAP + add edx, PCNET_DWIO_RAP + in eax, dx + and eax, 0xffff + sub edx, PCNET_DWIO_RAP - ret + ret ; eax - val align 4 dwio_write_rap: - add edx, PCNET_DWIO_RAP - out dx , eax - sub edx, PCNET_DWIO_RAP + add edx, PCNET_DWIO_RAP + out dx , eax + sub edx, PCNET_DWIO_RAP - ret + ret align 4 dwio_reset: - push eax - add edx, PCNET_DWIO_RESET - in eax, dx - pop eax - sub edx, PCNET_DWIO_RESET + push eax + add edx, PCNET_DWIO_RESET + in eax, dx + pop eax + sub edx, PCNET_DWIO_RESET - ret + ret ; End of code -align 4 ; Place all initialised data here +align 4 ; Place all initialised data here devices dd 0 version dd (5 shl 16) or (API_VERSION and 0xFFFF) -my_service db 'PCnet',0 ; max 16 chars include zero +my_service db 'PCnet',0 ; max 16 chars include zero device_l2 db "PCnet/PCI 79C970",0 device_l4 db "PCnet/PCI II 79C970A",0 @@ -1426,25 +1427,25 @@ device_l8 db "PCnet/Home 79C978",0 device_l9 db "PCnet/FAST III 79C975",0 options_mapping: -dd PCNET_PORT_ASEL ; 0 Auto-select -dd PCNET_PORT_AUI ; 1 BNC/AUI -dd PCNET_PORT_AUI ; 2 AUI/BNC -dd PCNET_PORT_ASEL ; 3 not supported -dd PCNET_PORT_10BT or PCNET_PORT_FD ; 4 10baseT-FD -dd PCNET_PORT_ASEL ; 5 not supported -dd PCNET_PORT_ASEL ; 6 not supported -dd PCNET_PORT_ASEL ; 7 not supported -dd PCNET_PORT_ASEL ; 8 not supported -dd PCNET_PORT_MII ; 9 MII 10baseT -dd PCNET_PORT_MII or PCNET_PORT_FD ; 10 MII 10baseT-FD -dd PCNET_PORT_MII ; 11 MII (autosel) -dd PCNET_PORT_10BT ; 12 10BaseT -dd PCNET_PORT_MII or PCNET_PORT_100 ; 13 MII 100BaseTx -dd PCNET_PORT_MII or PCNET_PORT_100 or PCNET_PORT_FD ; 14 MII 100BaseTx-FD -dd PCNET_PORT_ASEL ; 15 not supported +dd PCNET_PORT_ASEL ; 0 Auto-select +dd PCNET_PORT_AUI ; 1 BNC/AUI +dd PCNET_PORT_AUI ; 2 AUI/BNC +dd PCNET_PORT_ASEL ; 3 not supported +dd PCNET_PORT_10BT or PCNET_PORT_FD ; 4 10baseT-FD +dd PCNET_PORT_ASEL ; 5 not supported +dd PCNET_PORT_ASEL ; 6 not supported +dd PCNET_PORT_ASEL ; 7 not supported +dd PCNET_PORT_ASEL ; 8 not supported +dd PCNET_PORT_MII ; 9 MII 10baseT +dd PCNET_PORT_MII or PCNET_PORT_FD ; 10 MII 10baseT-FD +dd PCNET_PORT_MII ; 11 MII (autosel) +dd PCNET_PORT_10BT ; 12 10BaseT +dd PCNET_PORT_MII or PCNET_PORT_100 ; 13 MII 100BaseTx +dd PCNET_PORT_MII or PCNET_PORT_100 or PCNET_PORT_FD ; 14 MII 100BaseTx-FD +dd PCNET_PORT_ASEL ; 15 not supported -include_debug_strings ; All data wich FDO uses will be included here +include_debug_strings ; All data wich FDO uses will be included here -section '.data' data readable writable align 16 ; place all uninitialized data place here +section '.data' data readable writable align 16 ; place all uninitialized data place here -device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling +device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling diff --git a/kernel/branches/net/drivers/sis900.asm b/kernel/branches/net/drivers/sis900.asm index 044ae81e0..09f28c91c 100644 --- a/kernel/branches/net/drivers/sis900.asm +++ b/kernel/branches/net/drivers/sis900.asm @@ -25,14 +25,14 @@ format MS COFF - API_VERSION equ 0x01000100 - DRIVER_VERSION equ 5 + API_VERSION equ 0x01000100 + DRIVER_VERSION equ 5 - MAX_DEVICES equ 16 + MAX_DEVICES equ 16 - DEBUG equ 1 - __DEBUG__ equ 1 - __DEBUG_LEVEL__ equ 1 + DEBUG equ 1 + __DEBUG__ equ 1 + __DEBUG_LEVEL__ equ 1 include 'proc32.inc' include 'imports.inc' @@ -42,51 +42,51 @@ include 'netdrv.inc' public START public version -NUM_RX_DESC equ 4 ;* Number of RX descriptors * -NUM_TX_DESC equ 1 ;* Number of TX descriptors * -RX_BUFF_SZ equ 1520 ;* Buffer size for each Rx buffer * -TX_BUFF_SZ equ 1516 ;* Buffer size for each Tx buffer * -MAX_ETH_FRAME_SIZE equ 1516 +NUM_RX_DESC equ 4 ;* Number of RX descriptors * +NUM_TX_DESC equ 1 ;* Number of TX descriptors * +RX_BUFF_SZ equ 1520 ;* Buffer size for each Rx buffer * +TX_BUFF_SZ equ 1516 ;* Buffer size for each Tx buffer * +MAX_ETH_FRAME_SIZE equ 1516 virtual at ebx - device: + device: - ETH_DEVICE + ETH_DEVICE - .io_addr dd ? - .pci_bus db ? - .pci_dev db ? - .irq_line db ? - .cur_rx db ? - .cur_tx db ? - .last_tx db ? - .pci_revision db ? - .table_entries db ? + .io_addr dd ? + .pci_bus db ? + .pci_dev db ? + .irq_line db ? + .cur_rx db ? + .cur_tx db ? + .last_tx db ? + .pci_revision db ? + .table_entries db ? - dw ? ; align 4 + dw ? ; align 4 - .special_func dd ? + .special_func dd ? - .txd rd (4 * NUM_TX_DESC) - .rxd rd (4 * NUM_RX_DESC) + .txd rd (4 * NUM_TX_DESC) + .rxd rd (4 * NUM_RX_DESC) - .size = $ - device + .size = $ - device end virtual -macro ee_delay { - push eax - in eax, dx - in eax, dx - in eax, dx - in eax, dx - in eax, dx - in eax, dx - in eax, dx - in eax, dx - in eax, dx - in eax, dx - pop eax +macro ee_delay { + push eax + in eax, dx + in eax, dx + in eax, dx + in eax, dx + in eax, dx + in eax, dx + in eax, dx + in eax, dx + in eax, dx + in eax, dx + pop eax } @@ -95,144 +95,144 @@ section '.flat' code readable align 16 ; Driver entry point - register our service when the driver is loading. ; TODO: add needed operations when unloading START: - cmp dword [esp+4], 1 - jne .exit - stdcall RegService, my_service, service_proc - ret 4 + cmp dword [esp+4], 1 + jne .exit + stdcall RegService, my_service, service_proc + ret 4 .exit: - xor eax, eax - ret 4 + xor eax, eax + ret 4 ; Service procedure for the driver - handle all I/O requests for the driver. ; Currently handled requests are: SRV_GETVERSION = 0 and SRV_HOOK = 1. service_proc: ; 1. Get parameter from the stack: [esp+4] is the first parameter, ; pointer to IOCTL structure. - mov edx, [esp+4] ; edx -> IOCTL + mov edx, [esp+4] ; edx -> IOCTL ; 2. Get request code and select a handler for the code. - mov eax, [IOCTL.io_code] - test eax, eax ; check for SRV_GETVERSION - jnz @f + mov eax, [IOCTL.io_code] + test eax, eax ; check for SRV_GETVERSION + jnz @f ; 3. This is SRV_GETVERSION request, no input, 4 bytes output, API_VERSION. ; 3a. Output size must be at least 4 bytes. - cmp [IOCTL.out_size], 4 - jl .fail + cmp [IOCTL.out_size], 4 + jl .fail ; 3b. Write result to the output buffer. - mov eax, [IOCTL.output] - mov [eax], dword API_VERSION + mov eax, [IOCTL.output] + mov [eax], dword API_VERSION ; 3c. Return success. - xor eax, eax - ret 4 + xor eax, eax + ret 4 @@: - dec eax ; check for SRV_HOOK - jnz .fail + dec eax ; check for SRV_HOOK + jnz .fail ; 4. This is SRV_HOOK request, input defines the device to hook, no output. ; 4a. The driver works only with PCI devices, ; so input must be at least 3 bytes long. - cmp [IOCTL.inp_size], 3 - jl .fail + cmp [IOCTL.inp_size], 3 + jl .fail ; 4b. First byte of input is bus type, 1 stands for PCI. - mov eax, [IOCTL.input] - cmp byte [eax], 1 - jne .fail + mov eax, [IOCTL.input] + cmp byte [eax], 1 + jne .fail ; 4c. Second and third bytes of the input define the device: bus and dev. ; Word in bx holds both bytes. - mov bx, [eax+1] + mov bx, [eax+1] ; 4d. Check if the device was already hooked, ; scan through the list of known devices. ; check if the device is already listed - mov esi, device_list - mov ecx, [devices] - test ecx, ecx - jz .firstdevice + mov esi, device_list + mov ecx, [devices] + test ecx, ecx + jz .firstdevice ; mov eax, [IOCTL.input] ; get the pci bus and device numbers - mov ax , [eax+1] ; + mov ax , [eax+1] ; .nextdevice: - mov ebx, [esi] - cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) - je .find_devicenum ; Device is already loaded, let's find it's device number - add esi, 4 - loop .nextdevice + mov ebx, [esi] + cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) + je .find_devicenum ; Device is already loaded, let's find it's device number + add esi, 4 + loop .nextdevice ; 4e. This device doesn't have its own eth_device structure yet, let's create one .firstdevice: ; 4f. Check that we have place for new device. - cmp [devices], MAX_DEVICES - jge .fail + cmp [devices], MAX_DEVICES + jge .fail ; 4g. Allocate memory for device descriptor and receive+transmit buffers. - stdcall KernelAlloc, device.size - test eax, eax - jz .fail + stdcall KernelAlloc, device.size + test eax, eax + jz .fail ; 4h. Zero the structure. - mov edi, eax - mov ecx, (device.size + 3) shr 2 - xor eax, eax - rep stosd + mov edi, eax + mov ecx, (device.size + 3) shr 2 + xor eax, eax + rep stosd ; 4i. Save PCI coordinates - mov eax, [IOCTL.input] - mov cl , [eax+1] - mov [device.pci_bus], cl - mov cl , [eax+2] - mov [device.pci_dev], cl + mov eax, [IOCTL.input] + mov cl , [eax+1] + mov [device.pci_bus], cl + mov cl , [eax+2] + mov [device.pci_dev], cl ; 4j. Fill in the direct call addresses into the struct. ; Note that get_MAC pointer is filled in initialization by probe. - mov [device.reset], init - mov [device.transmit], transmit + mov [device.reset], init + mov [device.transmit], transmit ; mov [device.get_MAC], read_mac - mov [device.set_MAC], write_mac - mov [device.unload], unload - mov [device.name], my_service + mov [device.set_MAC], write_mac + mov [device.unload], unload + mov [device.name], my_service ; 4k. Now, it's time to find the base io addres of the PCI device ; TODO: implement check if bus and dev exist on this machine ; Now, it's time to find the base io addres of the PCI device - find_io [device.pci_bus], [device.pci_dev], [device.io_addr] + find_io [device.pci_bus], [device.pci_dev], [device.io_addr] ; We've found the io address, find IRQ now - find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] + find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] ; 4m. Add new device to the list (required for int_handler). - mov eax, [devices] - mov [device_list+4*eax], ebx - inc [devices] + mov eax, [devices] + mov [device_list+4*eax], ebx + inc [devices] ; 4m. Ok, the eth_device structure is ready, let's probe the device - call probe - test eax, eax - jnz .destroy + call probe + test eax, eax + jnz .destroy ; 4n. If device was successfully initialized, register it for the kernel. - mov [device.type], NET_TYPE_ETH - call NetRegDev + mov [device.type], NET_TYPE_ETH + call NetRegDev - cmp eax, -1 - je .destroy + cmp eax, -1 + je .destroy - ret 4 + ret 4 ; 5. If the device was already loaded, find the device number and return it in eax .find_devicenum: - mov ebx, eax - call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx - ; into a device number in edi - mov eax, edi ; Application wants it in eax instead - ret 4 + mov ebx, eax + call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx + ; into a device number in edi + mov eax, edi ; Application wants it in eax instead + ret 4 ; If an error occured, remove all allocated data and exit (returning -1 in eax) .destroy: - dec [devices] - ; todo: reset device into virgin state + dec [devices] + ; todo: reset device into virgin state .err: - stdcall KernelFree, ebx + stdcall KernelFree, ebx .fail: - xor eax, eax - ret 4 + xor eax, eax + ret 4 ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; @@ -242,15 +242,15 @@ service_proc: ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; unload: - ; TODO: (in this particular order) - ; - ; - Stop the device - ; - Detach int handler - ; - Remove device from local list - ; - call unregister function in kernel - ; - Remove all allocated structures and buffers the card used + ; TODO: (in this particular order) + ; + ; - Stop the device + ; - Detach int handler + ; - Remove device from local list + ; - call unregister function in kernel + ; - Remove all allocated structures and buffers the card used - or eax,-1 + or eax,-1 ret @@ -272,150 +272,150 @@ ret ; ;******************************************************************** - ETH_ALEN equ 6 ; Size of Ethernet address - ETH_HLEN equ 14 ; Size of ethernet header - ETH_ZLEN equ 60 ; Minimum packet length - DSIZE equ 0x00000fff - CRC_SIZE equ 4 - RFADDR_shift equ 16 + ETH_ALEN equ 6 ; Size of Ethernet address + ETH_HLEN equ 14 ; Size of ethernet header + ETH_ZLEN equ 60 ; Minimum packet length + DSIZE equ 0x00000fff + CRC_SIZE equ 4 + RFADDR_shift equ 16 ; Symbolic offsets to registers. - cr equ 0x0 ; Command Register - cfg equ 0x4 ; Configuration Register - mear equ 0x8 ; EEPROM Access Register - ptscr equ 0xc ; PCI Test Control Register - isr equ 0x10 ; Interrupt Status Register - imr equ 0x14 ; Interrupt Mask Register - ier equ 0x18 ; Interrupt Enable Register - epar equ 0x18 ; Enhanced PHY Access Register - txdp equ 0x20 ; Transmit Descriptor Pointer Register - txcfg equ 0x24 ; Transmit Configuration Register - rxdp equ 0x30 ; Receive Descriptor Pointer Register - rxcfg equ 0x34 ; Receive Configuration Register - flctrl equ 0x38 ; Flow Control Register - rxlen equ 0x3c ; Receive Packet Length Register - rfcr equ 0x48 ; Receive Filter Control Register - rfdr equ 0x4C ; Receive Filter Data Register - pmctrl equ 0xB0 ; Power Management Control Register - pmer equ 0xB4 ; Power Management Wake-up Event Register + cr equ 0x0 ; Command Register + cfg equ 0x4 ; Configuration Register + mear equ 0x8 ; EEPROM Access Register + ptscr equ 0xc ; PCI Test Control Register + isr equ 0x10 ; Interrupt Status Register + imr equ 0x14 ; Interrupt Mask Register + ier equ 0x18 ; Interrupt Enable Register + epar equ 0x18 ; Enhanced PHY Access Register + txdp equ 0x20 ; Transmit Descriptor Pointer Register + txcfg equ 0x24 ; Transmit Configuration Register + rxdp equ 0x30 ; Receive Descriptor Pointer Register + rxcfg equ 0x34 ; Receive Configuration Register + flctrl equ 0x38 ; Flow Control Register + rxlen equ 0x3c ; Receive Packet Length Register + rfcr equ 0x48 ; Receive Filter Control Register + rfdr equ 0x4C ; Receive Filter Data Register + pmctrl equ 0xB0 ; Power Management Control Register + pmer equ 0xB4 ; Power Management Wake-up Event Register ; Command Register Bits - RELOAD equ 0x00000400 - ACCESSMODE equ 0x00000200 - RESET equ 0x00000100 - SWI equ 0x00000080 - RxRESET equ 0x00000020 - TxRESET equ 0x00000010 - RxDIS equ 0x00000008 - RxENA equ 0x00000004 - TxDIS equ 0x00000002 - TxENA equ 0x00000001 + RELOAD equ 0x00000400 + ACCESSMODE equ 0x00000200 + RESET equ 0x00000100 + SWI equ 0x00000080 + RxRESET equ 0x00000020 + TxRESET equ 0x00000010 + RxDIS equ 0x00000008 + RxENA equ 0x00000004 + TxDIS equ 0x00000002 + TxENA equ 0x00000001 ; Configuration Register Bits - DESCRFMT equ 0x00000100 ; 7016 specific - REQALG equ 0x00000080 - SB equ 0x00000040 - POW equ 0x00000020 - EXD equ 0x00000010 - PESEL equ 0x00000008 - LPM equ 0x00000004 - BEM equ 0x00000001 - RND_CNT equ 0x00000400 - FAIR_BACKOFF equ 0x00000200 - EDB_MASTER_EN equ 0x00002000 + DESCRFMT equ 0x00000100 ; 7016 specific + REQALG equ 0x00000080 + SB equ 0x00000040 + POW equ 0x00000020 + EXD equ 0x00000010 + PESEL equ 0x00000008 + LPM equ 0x00000004 + BEM equ 0x00000001 + RND_CNT equ 0x00000400 + FAIR_BACKOFF equ 0x00000200 + EDB_MASTER_EN equ 0x00002000 ; Eeprom Access Reigster Bits - MDC equ 0x00000040 - MDDIR equ 0x00000020 - MDIO equ 0x00000010 ; 7016 specific - EECS equ 0x00000008 - EECLK equ 0x00000004 - EEDO equ 0x00000002 - EEDI equ 0x00000001 + MDC equ 0x00000040 + MDDIR equ 0x00000020 + MDIO equ 0x00000010 ; 7016 specific + EECS equ 0x00000008 + EECLK equ 0x00000004 + EEDO equ 0x00000002 + EEDI equ 0x00000001 ; TX Configuration Register Bits - ATP equ 0x10000000 ;Automatic Transmit Padding - MLB equ 0x20000000 ;Mac Loopback Enable - HBI equ 0x40000000 ;HeartBeat Ignore (Req for full-dup) - CSI equ 0x80000000 ;CarrierSenseIgnore (Req for full-du + ATP equ 0x10000000 ;Automatic Transmit Padding + MLB equ 0x20000000 ;Mac Loopback Enable + HBI equ 0x40000000 ;HeartBeat Ignore (Req for full-dup) + CSI equ 0x80000000 ;CarrierSenseIgnore (Req for full-du ; RX Configuration Register Bits - AJAB equ 0x08000000 ; - ATX equ 0x10000000 ;Accept Transmit Packets - ARP equ 0x40000000 ;accept runt packets (<64bytes) - AEP equ 0x80000000 ;accept error packets + AJAB equ 0x08000000 ; + ATX equ 0x10000000 ;Accept Transmit Packets + ARP equ 0x40000000 ;accept runt packets (<64bytes) + AEP equ 0x80000000 ;accept error packets ; Interrupt Reigster Bits - WKEVT equ 0x10000000 - TxPAUSEEND equ 0x08000000 - TxPAUSE equ 0x04000000 - TxRCMP equ 0x02000000 - RxRCMP equ 0x01000000 - DPERR equ 0x00800000 - SSERR equ 0x00400000 - RMABT equ 0x00200000 - RTABT equ 0x00100000 - RxSOVR equ 0x00010000 - HIBERR equ 0x00008000 - SWINT equ 0x00001000 - MIBINT equ 0x00000800 - TxURN equ 0x00000400 - TxIDLE equ 0x00000200 - TxERR equ 0x00000100 - TxDESC equ 0x00000080 - TxOK equ 0x00000040 - RxORN equ 0x00000020 - RxIDLE equ 0x00000010 - RxEARLY equ 0x00000008 - RxERR equ 0x00000004 - RxDESC equ 0x00000002 - RxOK equ 0x00000001 + WKEVT equ 0x10000000 + TxPAUSEEND equ 0x08000000 + TxPAUSE equ 0x04000000 + TxRCMP equ 0x02000000 + RxRCMP equ 0x01000000 + DPERR equ 0x00800000 + SSERR equ 0x00400000 + RMABT equ 0x00200000 + RTABT equ 0x00100000 + RxSOVR equ 0x00010000 + HIBERR equ 0x00008000 + SWINT equ 0x00001000 + MIBINT equ 0x00000800 + TxURN equ 0x00000400 + TxIDLE equ 0x00000200 + TxERR equ 0x00000100 + TxDESC equ 0x00000080 + TxOK equ 0x00000040 + RxORN equ 0x00000020 + RxIDLE equ 0x00000010 + RxEARLY equ 0x00000008 + RxERR equ 0x00000004 + RxDESC equ 0x00000002 + RxOK equ 0x00000001 ; Interrupt Enable Register Bits - IE equ RxOK + TxOK + IE equ RxOK + TxOK ; Revision ID - SIS900B_900_REV equ 0x03 - SIS630A_900_REV equ 0x80 - SIS630E_900_REV equ 0x81 - SIS630S_900_REV equ 0x82 - SIS630EA1_900_REV equ 0x83 - SIS630ET_900_REV equ 0x84 - SIS635A_900_REV equ 0x90 - SIS900_960_REV equ 0x91 + SIS900B_900_REV equ 0x03 + SIS630A_900_REV equ 0x80 + SIS630E_900_REV equ 0x81 + SIS630S_900_REV equ 0x82 + SIS630EA1_900_REV equ 0x83 + SIS630ET_900_REV equ 0x84 + SIS635A_900_REV equ 0x90 + SIS900_960_REV equ 0x91 ; Receive Filter Control Register Bits - RFEN equ 0x80000000 - RFAAB equ 0x40000000 - RFAAM equ 0x20000000 - RFAAP equ 0x10000000 - RFPromiscuous equ 0x70000000 + RFEN equ 0x80000000 + RFAAB equ 0x40000000 + RFAAM equ 0x20000000 + RFAAP equ 0x10000000 + RFPromiscuous equ 0x70000000 ; Reveive Filter Data Mask - RFDAT equ 0x0000FFFF + RFDAT equ 0x0000FFFF ; Eeprom Address - EEPROMSignature equ 0x00 - EEPROMVendorID equ 0x02 - EEPROMDeviceID equ 0x03 - EEPROMMACAddr equ 0x08 - EEPROMChecksum equ 0x0b + EEPROMSignature equ 0x00 + EEPROMVendorID equ 0x02 + EEPROMDeviceID equ 0x03 + EEPROMMACAddr equ 0x08 + EEPROMChecksum equ 0x0b ;The EEPROM commands include the alway-set leading bit. - EEread equ 0x0180 - EEwrite equ 0x0140 - EEerase equ 0x01C0 - EEwriteEnable equ 0x0130 - EEwriteDisable equ 0x0100 - EEeraseAll equ 0x0120 - EEwriteAll equ 0x0110 - EEaddrMask equ 0x013F - EEcmdShift equ 16 + EEread equ 0x0180 + EEwrite equ 0x0140 + EEerase equ 0x01C0 + EEwriteEnable equ 0x0130 + EEwriteDisable equ 0x0100 + EEeraseAll equ 0x0120 + EEwriteAll equ 0x0110 + EEaddrMask equ 0x013F + EEcmdShift equ 16 ;For SiS962 or SiS963, request the eeprom software access - EEREQ equ 0x00000400 - EEDONE equ 0x00000200 - EEGNT equ 0x00000100 + EEREQ equ 0x00000400 + EEDONE equ 0x00000200 + EEGNT equ 0x00000100 ;*************************************************************************** @@ -430,58 +430,58 @@ ret align 4 probe: - movzx eax, [device.pci_bus] - movzx edx, [device.pci_dev] - stdcall PciWrite8, eax, edx, 0x40, 0 ; Wake Up Chip + movzx eax, [device.pci_bus] + movzx edx, [device.pci_dev] + stdcall PciWrite8, eax, edx, 0x40, 0 ; Wake Up Chip - make_bus_master [device.pci_bus], [device.pci_dev] + make_bus_master [device.pci_bus], [device.pci_dev] ; Get Card Revision - movzx eax, [device.pci_bus] - movzx edx, [device.pci_dev] - stdcall PciRead8, eax, edx, 0x08 - mov [device.pci_revision], al ; save the revision for later use + movzx eax, [device.pci_bus] + movzx edx, [device.pci_dev] + stdcall PciRead8, eax, edx, 0x08 + mov [device.pci_revision], al ; save the revision for later use ; Look up through the specific_table - mov esi, specific_table + mov esi, specific_table .loop: - cmp dword [esi], 0 ; Check if we reached end of the list - je .error - cmp al, [esi] ; Check if revision is OK - je .ok - add esi, 12 ; Advance to next entry - jmp .loop + cmp dword [esi], 0 ; Check if we reached end of the list + je .error + cmp al, [esi] ; Check if revision is OK + je .ok + add esi, 12 ; Advance to next entry + jmp .loop .error: - DEBUGF 1, "Device not supported!\n" - or eax, -1 - ret + DEBUGF 1, "Device not supported!\n" + or eax, -1 + ret ; Find Get Mac Function .ok: - mov eax, [esi+4] ; Get pointer to "get MAC" function - mov [device.get_MAC], eax - mov eax, [esi+8] ; Get pointer to special initialization fn - mov [device.special_func], eax + mov eax, [esi+4] ; Get pointer to "get MAC" function + mov [device.get_MAC], eax + mov eax, [esi+8] ; Get pointer to special initialization fn + mov [device.special_func], eax ; Get MAC - call [device.get_MAC] + call [device.get_MAC] ; Call special initialization fn if requested - cmp [device.special_func],0 - je @f - call [device.special_func] + cmp [device.special_func],0 + je @f + call [device.special_func] @@: ; Set table entries - mov [device.table_entries], 16 - cmp [device.pci_revision], SIS635A_900_REV - jae @f - cmp [device.pci_revision], SIS900B_900_REV - je @f - mov [device.table_entries], 8 + mov [device.table_entries], 16 + cmp [device.pci_revision], SIS635A_900_REV + jae @f + cmp [device.pci_revision], SIS900B_900_REV + je @f + mov [device.table_entries], 8 @@: ; TODO: Probe for mii transceiver @@ -498,31 +498,31 @@ probe: align 4 init: - call reset - call init_rxfilter - call init_txd - call init_rxd - call set_rx_mode - call set_tx_mode - ;call check_mode + call reset + call init_rxfilter + call init_txd + call init_rxd + call set_rx_mode + call set_tx_mode + ;call check_mode ; enable interrupts on packet receive - xor eax, eax - inc eax ; eax = 1 = RxOK - set_io 0 - set_io imr - out dx, eax + xor eax, eax + inc eax ; eax = 1 = RxOK + set_io 0 + set_io imr + out dx, eax ; globally enable interrupts - set_io ier - out dx, eax ; eax is still 1 - xor eax, eax + set_io ier + out dx, eax ; eax is still 1 + xor eax, eax - mov [device.mtu], 1514 + mov [device.mtu], 1514 - ret + ret ;*************************************************************************** ; @@ -533,67 +533,67 @@ init: ;*************************************************************************** align 4 reset: - movzx eax, [device.irq_line] - stdcall AttachIntHandler, eax, int_handler, 0 + movzx eax, [device.irq_line] + stdcall AttachIntHandler, eax, int_handler, 0 ;-------------------------------------------- ; Disable Interrupts and reset Receive Filter - set_io 0 - set_io ier - xor eax, eax - out dx, eax + set_io 0 + set_io ier + xor eax, eax + out dx, eax - set_io imr - out dx, eax + set_io imr + out dx, eax - set_io rfcr - out dx, eax + set_io rfcr + out dx, eax ;----------- ; Reset Card - set_io cr - in eax, dx ; Get current Command Register - or eax, RESET + RxRESET + TxRESET ; set flags - out dx, eax ; Write new Command Register + set_io cr + in eax, dx ; Get current Command Register + or eax, RESET + RxRESET + TxRESET ; set flags + out dx, eax ; Write new Command Register ;---------- ; Wait loop - set_io isr - mov ecx, 1000 + set_io isr + mov ecx, 1000 .loop: - dec ecx - jz .error - in eax, dx ; move interrup status to eax - cmp eax, 0x03000000 - jne .loop + dec ecx + jz .error + in eax, dx ; move interrup status to eax + cmp eax, 0x03000000 + jne .loop ;------------------------------------------------------ ; Set Configuration Register depending on Card Revision - set_io cfg - mov eax, PESEL ; Configuration Register Bit - cmp [device.pci_revision], SIS635A_900_REV - je .match - cmp [device.pci_revision], SIS900B_900_REV ; Check card revision - je .match - out dx, eax ; no revision match - jmp .done + set_io cfg + mov eax, PESEL ; Configuration Register Bit + cmp [device.pci_revision], SIS635A_900_REV + je .match + cmp [device.pci_revision], SIS900B_900_REV ; Check card revision + je .match + out dx, eax ; no revision match + jmp .done - .match: ; Revision match - or eax, RND_CNT ; Configuration Register Bit - out dx, eax + .match: ; Revision match + or eax, RND_CNT ; Configuration Register Bit + out dx, eax .done: - xor eax, eax - ret + xor eax, eax + ret .error: - DEBUGF 1, "Reset failed!\n" - or eax, -1 - ret + DEBUGF 1, "Reset failed!\n" + or eax, -1 + ret ;*************************************************************************** @@ -609,43 +609,43 @@ init_rxfilter: ;------------------------------------ ; Get Receive Filter Control Register - set_io 0 - set_io rfcr - in eax, dx - push eax + set_io 0 + set_io rfcr + in eax, dx + push eax ;----------------------------------------------- ; disable packet filtering before setting filter - and eax, not RFEN - out dx, eax + and eax, not RFEN + out dx, eax ;-------------------------------------- ; load MAC addr to filter data register - xor ecx, ecx -RXINT_Mac_Write: ; high word of eax tells card which mac byte to write - mov eax, ecx - set_io 0 - set_io rfcr - shl eax, 16 ; - out dx, eax ; - set_io rfdr - mov ax, word [device.mac+ecx*2] ; Get Mac ID word - out dx, ax ; Send Mac ID - inc cl ; send next word - cmp cl, 3 ; more to send? - jne RXINT_Mac_Write + xor ecx, ecx +RXINT_Mac_Write: ; high word of eax tells card which mac byte to write + mov eax, ecx + set_io 0 + set_io rfcr + shl eax, 16 ; + out dx, eax ; + set_io rfdr + mov ax, word [device.mac+ecx*2] ; Get Mac ID word + out dx, ax ; Send Mac ID + inc cl ; send next word + cmp cl, 3 ; more to send? + jne RXINT_Mac_Write ;------------------------ ; enable packet filtering - pop eax ;old register value - set_io rfcr - or eax, RFEN ;enable filtering - out dx, eax ;set register + pop eax ;old register value + set_io rfcr + or eax, RFEN ;enable filtering + out dx, eax ;set register - ret + ret ;*************************************************************************** ; @@ -660,20 +660,20 @@ init_txd: ;------------------------- ; initialize TX descriptor - mov dword [device.txd], 0 ; put link to next descriptor in link field - mov dword [device.txd+4], 0 ; clear status field - mov dword [device.txd+8], 0 ; ptr to buffer + mov dword [device.txd], 0 ; put link to next descriptor in link field + mov dword [device.txd+4], 0 ; clear status field + mov dword [device.txd+8], 0 ; ptr to buffer ;---------------------------------- ; load Transmit Descriptor Register - set_io 0 - set_io txdp ; TX Descriptor Pointer - lea eax, [device.txd] - GetRealAddr - out dx, eax ; move the pointer + set_io 0 + set_io txdp ; TX Descriptor Pointer + lea eax, [device.txd] + GetRealAddr + out dx, eax ; move the pointer - ret + ret ;*************************************************************************** ; @@ -686,38 +686,38 @@ align 4 init_rxd: ; init RX descriptors - mov ecx, NUM_RX_DESC - lea esi, [device.rxd] + mov ecx, NUM_RX_DESC + lea esi, [device.rxd] .loop: - lea eax, [esi + 16] - GetRealAddr - mov dword [esi+0], eax - mov dword [esi+4], RX_BUFF_SZ + lea eax, [esi + 16] + GetRealAddr + mov dword [esi+0], eax + mov dword [esi+4], RX_BUFF_SZ - stdcall KernelAlloc, RX_BUFF_SZ - test eax, eax - jz .fail - mov dword [esi+12], eax - GetRealAddr - mov dword [esi+8], eax - add esi, 16 - loop .loop + stdcall KernelAlloc, RX_BUFF_SZ + test eax, eax + jz .fail + mov dword [esi+12], eax + GetRealAddr + mov dword [esi+8], eax + add esi, 16 + loop .loop - lea eax, [device.rxd] - GetRealAddr - mov dword [esi - 16], eax ; correct last descriptor link ptr + lea eax, [device.rxd] + GetRealAddr + mov dword [esi - 16], eax ; correct last descriptor link ptr ; And output ptr to first desc, to device - set_io 0 - set_io rxdp - out dx, eax + set_io 0 + set_io rxdp + out dx, eax - mov [device.cur_rx], 0 ; Set curent rx discriptor to 0 + mov [device.cur_rx], 0 ; Set curent rx discriptor to 0 - .fail: ;;; TODO: abort instead! - ret + .fail: ;;; TODO: abort instead! + ret ;*************************************************************************** @@ -742,23 +742,23 @@ init_rxd: align 4 set_tx_mode: - set_io 0 - set_io cr - in eax, dx ; Get current Command Register - or eax, TxENA ; Enable Receive - out dx, eax + set_io 0 + set_io cr + in eax, dx ; Get current Command Register + or eax, TxENA ; Enable Receive + out dx, eax - set_io txcfg ; Transmit config Register offset - mov eax, ATP + HBI + CSI +0x00600120 - ; allow automatic padding - ; allow heartbeat ignore - ; allow carrier sense ignore - ; Max DMA Burst (128 bytes) - ; TX Fill Threshold - ; TX Drain Threshold - out dx, eax + set_io txcfg ; Transmit config Register offset + mov eax, ATP + HBI + CSI +0x00600120 + ; allow automatic padding + ; allow heartbeat ignore + ; allow carrier sense ignore + ; Max DMA Burst (128 bytes) + ; TX Fill Threshold + ; TX Drain Threshold + out dx, eax - ret + ret ;*************************************************************************** ; @@ -787,53 +787,53 @@ set_rx_mode: ;---------------------------------------------- ; update Multicast Hash Table in Receive Filter - xor cl, cl + xor cl, cl .loop: - set_io 0 - set_io rfcr ; Receive Filter Control Reg offset - mov eax, 4 ; determine table entry - add al, cl - shl eax, 16 - out dx, eax ; tell card which entry to modify + set_io 0 + set_io rfcr ; Receive Filter Control Reg offset + mov eax, 4 ; determine table entry + add al, cl + shl eax, 16 + out dx, eax ; tell card which entry to modify - set_io rfdr ; Receive Filter Control Reg offset - mov eax, 0xffff ; entry value - out dx, ax ; write value to table in card + set_io rfdr ; Receive Filter Control Reg offset + mov eax, 0xffff ; entry value + out dx, ax ; write value to table in card - inc cl ; next entry - cmp cl, [device.table_entries] - jl .loop + inc cl ; next entry + cmp cl, [device.table_entries] + jl .loop ;------------------------------------ ; Set Receive Filter Control Register - set_io rfcr ; Receive Filter Control Register offset - mov eax, RFAAB + RFAAM + RFAAP + RFEN - ; accecpt all broadcast packets - ; accept all multicast packets - ; Accept all packets - ; enable receiver filter - out dx, eax + set_io rfcr ; Receive Filter Control Register offset + mov eax, RFAAB + RFAAM + RFAAP + RFEN + ; accecpt all broadcast packets + ; accept all multicast packets + ; Accept all packets + ; enable receiver filter + out dx, eax ;---------------- ; Enable Receiver - set_io cr - in eax, dx ; Get current Command Register - or eax, RxENA ; Enable Receive - out dx, eax + set_io cr + in eax, dx ; Get current Command Register + or eax, RxENA ; Enable Receive + out dx, eax ;------------------- ; Configure Receiver - set_io rxcfg ; Receive Config Register offset - mov eax, ATX + 0x00600002 - ; Accept Transmit Packets - ; (Req for full-duplex and PMD Loopback) - ; Max DMA Burst - ; RX Drain Threshold, 8X8 bytes or 64bytes - out dx, eax + set_io rxcfg ; Receive Config Register offset + mov eax, ATX + 0x00600002 + ; Accept Transmit Packets + ; (Req for full-duplex and PMD Loopback) + ; Max DMA Burst + ; RX Drain Threshold, 8X8 bytes or 64bytes + out dx, eax - ret + ret ;*************************************************************************** ; @@ -857,29 +857,29 @@ SIS960_get_mac_addr: ;------------------------------- ; Send Request for eeprom access - set_io 0 - set_io mear ; Eeprom access register - mov eax, EEREQ ; Request access to eeprom - out dx, eax ; Send request + set_io 0 + set_io mear ; Eeprom access register + mov eax, EEREQ ; Request access to eeprom + out dx, eax ; Send request ;----------------------------------------------------- ; Loop 4000 times and if access not granted, error out - mov ecx, 4000 + mov ecx, 4000 .loop: - in eax, dx ; get eeprom status - test eax, EEGNT ; see if eeprom access granted flag is set - jnz .got_access ; if it is, go access the eeprom - loop .loop ; else keep waiting + in eax, dx ; get eeprom status + test eax, EEGNT ; see if eeprom access granted flag is set + jnz .got_access ; if it is, go access the eeprom + loop .loop ; else keep waiting - DEBUGF 1, "Access to EEprom failed!\n", 0 + DEBUGF 1, "Access to EEprom failed!\n", 0 - set_io mear ; Eeprom access register - mov eax, EEDONE ; tell eeprom we are done - out dx, eax + set_io mear ; Eeprom access register + mov eax, EEDONE ; tell eeprom we are done + out dx, eax - or eax, -1 ; error - ret + or eax, -1 ; error + ret .got_access: @@ -888,31 +888,31 @@ SIS960_get_mac_addr: ; zero based so 3-16 bit reads will take place - mov ecx, 2 + mov ecx, 2 .read_loop: - mov eax, EEPROMMACAddr ; Base Mac Address - add eax, ecx ; Current Mac Byte Offset - push ecx - call read_eeprom ; try to read 16 bits - pop ecx - mov word [device.mac+ecx*2], ax ; save 16 bits to the MAC ID varible - dec ecx ; one less word to read - jns .read_loop ; if more read more - mov eax, 1 ; return non-zero indicating success + mov eax, EEPROMMACAddr ; Base Mac Address + add eax, ecx ; Current Mac Byte Offset + push ecx + call read_eeprom ; try to read 16 bits + pop ecx + mov word [device.mac+ecx*2], ax ; save 16 bits to the MAC ID varible + dec ecx ; one less word to read + jns .read_loop ; if more read more + mov eax, 1 ; return non-zero indicating success - DEBUGF 2,"%x-%x-%x-%x-%x-%x\n",[device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 + DEBUGF 2,"%x-%x-%x-%x-%x-%x\n",[device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 ;------------------------------------- ; Tell EEPROM We are Done Accessing It .done: - set_io 0 - set_io mear ; Eeprom access register - mov eax, EEDONE ; tell eeprom we are done - out dx, eax + set_io 0 + set_io mear ; Eeprom access register + mov eax, EEDONE ; tell eeprom we are done + out dx, eax - xor eax, eax ; ok - ret + xor eax, eax ; ok + ret @@ -930,40 +930,40 @@ SIS900_get_mac_addr: ;------------------------------------ ; check to see if we have sane EEPROM - mov eax, EEPROMSignature ; Base Eeprom Signature - call read_eeprom ; try to read 16 bits - cmp ax, 0xffff - je .err - test ax, ax - je .err + mov eax, EEPROMSignature ; Base Eeprom Signature + call read_eeprom ; try to read 16 bits + cmp ax, 0xffff + je .err + test ax, ax + je .err ;----------- ; Read MacID ; zero based so 3-16 bit reads will take place - mov ecx, 2 + mov ecx, 2 .loop: - mov eax, EEPROMMACAddr ; Base Mac Address - add eax, ecx ; Current Mac Byte Offset - push ecx - call read_eeprom ; try to read 16 bits - pop ecx - mov word [device.mac+ecx*2], ax ; save 16 bits to the MAC ID storage - dec ecx ; one less word to read - jns .loop ; if more read more + mov eax, EEPROMMACAddr ; Base Mac Address + add eax, ecx ; Current Mac Byte Offset + push ecx + call read_eeprom ; try to read 16 bits + pop ecx + mov word [device.mac+ecx*2], ax ; save 16 bits to the MAC ID storage + dec ecx ; one less word to read + jns .loop ; if more read more - DEBUGF 2,"%x-%x-%x-%x-%x-%x\n",[device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 + DEBUGF 2,"%x-%x-%x-%x-%x-%x\n",[device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 - xor eax, eax - ret + xor eax, eax + ret .err: - DEBUGF 1, "Access to EEprom failed!\n", 0 + DEBUGF 1, "Access to EEprom failed!\n", 0 - or eax, -1 - ret + or eax, -1 + ret ;*************************************************************************** @@ -974,42 +974,42 @@ SIS900_get_mac_addr: align 4 Get_Mac_SIS635_900_REV: - set_io 0 - set_io rfcr - in eax, dx - mov edi, eax ; EDI=rfcrSave + set_io 0 + set_io rfcr + in eax, dx + mov edi, eax ; EDI=rfcrSave - set_io cr - or eax, RELOAD - out dx, eax + set_io cr + or eax, RELOAD + out dx, eax - xor eax, eax - out dx, eax + xor eax, eax + out dx, eax ;----------------------------------------------- ; Disable packet filtering before setting filter - set_io rfcr - mov eax, edi - and edi, not RFEN - out dx, eax + set_io rfcr + mov eax, edi + and edi, not RFEN + out dx, eax ;--------------------------------- ; Load MAC to filter data register - mov ecx, 3 - lea edi, [device.mac] + mov ecx, 3 + lea edi, [device.mac] .loop: - set_io 0 - set_io rfcr - mov eax, ecx - shl eax, RFADDR_shift - out dx, eax + set_io 0 + set_io rfcr + mov eax, ecx + shl eax, RFADDR_shift + out dx, eax - set_io rfdr - in eax, dx - stosw - loop .loop + set_io rfdr + in eax, dx + stosw + loop .loop ;------------------------ ; Enable packet filtering @@ -1019,8 +1019,8 @@ Get_Mac_SIS635_900_REV: ; or eax, RFEN ; out dx, eax - xor eax, eax - ret + xor eax, eax + ret ;*************************************************************************** ; @@ -1035,87 +1035,87 @@ Get_Mac_SIS635_900_REV: align 4 read_eeprom: - set_io 0 - set_io mear + set_io 0 + set_io mear - xor eax, eax ; start send - out dx, eax - ee_delay + xor eax, eax ; start send + out dx, eax + ee_delay - or eax, EECLK - out dx, eax - ee_delay + or eax, EECLK + out dx, eax + ee_delay ;------------------------------------ ; Send the read command - or esi, EEread - mov ecx, 1 shl 9 + or esi, EEread + mov ecx, 1 shl 9 .loop: - mov eax, EECS - test esi, ecx - jz @f - or eax, EEDI + mov eax, EECS + test esi, ecx + jz @f + or eax, EEDI @@: - out dx, eax - ee_delay + out dx, eax + ee_delay - or eax, EECLK - out dx, eax - ee_delay + or eax, EECLK + out dx, eax + ee_delay - shr esi, 1 - jnc .loop + shr esi, 1 + jnc .loop - mov eax, EECS - out dx, eax - ee_delay + mov eax, EECS + out dx, eax + ee_delay ;------------------------ ; Read 16-bits of data in - xor esi, esi - mov cx, 16 + xor esi, esi + mov cx, 16 .loop2: - mov eax, EECS - out dx, eax - ee_delay + mov eax, EECS + out dx, eax + ee_delay - or eax, EECLK - out dx, eax - ee_delay + or eax, EECLK + out dx, eax + ee_delay - in eax, dx - shl esi, 1 - test eax, EEDO - jz @f - inc esi + in eax, dx + shl esi, 1 + test eax, EEDO + jz @f + inc esi @@: - loop .loop2 + loop .loop2 ;---------------------------- ; Terminate the EEPROM access - xor eax, eax - out dx, eax - ee_delay + xor eax, eax + out dx, eax + ee_delay - mov eax, EECLK - out dx, eax - ee_delay + mov eax, EECLK + out dx, eax + ee_delay - movzx eax, si + movzx eax, si - ret + ret align 4 write_mac: - DEBUGF 1,'Setting MAC is not supported for SIS900 card.\n' - add esp, 6 - ret + DEBUGF 1,'Setting MAC is not supported for SIS900 card.\n' + add esp, 6 + ret ;*************************************************************************** ; @@ -1130,116 +1130,116 @@ write_mac: align 4 int_handler: ; find pointer of device which made IRQ occur - mov esi, device_list - mov ecx, [devices] - test ecx, ecx - jz .nothing + mov esi, device_list + mov ecx, [devices] + test ecx, ecx + jz .nothing .nextdevice: - mov ebx, [esi] - set_io 0 - set_io isr - in eax, dx ; note that this clears all interrupts - test ax, IE - jnz .got_it - loop .nextdevice + mov ebx, [esi] + set_io 0 + set_io isr + in eax, dx ; note that this clears all interrupts + test ax, IE + jnz .got_it + loop .nextdevice .nothing: - ret + ret .got_it: - test ax, RxOK - jz .no_rx + test ax, RxOK + jz .no_rx - push ax + push ax ;----------- ; Get Status - movzx eax, [device.cur_rx] ; find current discriptor - shl eax, 4 ; * 16 - mov ecx, dword[device.rxd+eax+4] ; get receive status + movzx eax, [device.cur_rx] ; find current discriptor + shl eax, 4 ; * 16 + mov ecx, dword[device.rxd+eax+4] ; get receive status ;------------------------------------------- ; Check RX_Status to see if packet is waiting - test ecx, 0x80000000 - jnz .is_packet - ret + test ecx, 0x80000000 + jnz .is_packet + ret ;---------------------------------------------- ; There is a packet waiting check it for errors .is_packet: - test ecx, 0x67C0000 ; see if there are any errors - jnz .error_status + test ecx, 0x67C0000 ; see if there are any errors + jnz .error_status ;--------------------- ; Check size of packet - and ecx, DSIZE ; get packet size minus CRC - sub ecx, CRC_SIZE ; make sure packet contains data - jle .error_size + and ecx, DSIZE ; get packet size minus CRC + sub ecx, CRC_SIZE ; make sure packet contains data + jle .error_size ; update statistics - inc dword [device.packets_rx] - add dword [device.bytes_rx], ecx - adc dword [device.bytes_rx+4], 0 + inc dword [device.packets_rx] + add dword [device.bytes_rx], ecx + adc dword [device.bytes_rx+4], 0 - push ebx - push .return - push ecx ; packet size - push [device.rxd+eax+12] ; packet ptr - DEBUGF 1, "Packet received OK\n" - jmp EthReceiver + push ebx + push .return + push ecx ; packet size + push [device.rxd+eax+12] ; packet ptr + DEBUGF 1, "Packet received OK\n" + jmp EthReceiver .return: - pop ebx + pop ebx ; Reset status, allow ethernet card access to descriptor - movzx ecx, [device.cur_rx] - shl ecx, 4 ; *16 - mov ecx, [device.rxd+ecx] - stdcall KernelAlloc, RX_BUFF_SZ - test eax, eax - jz .fail - mov dword [ecx+12], eax - GetRealAddr - mov dword [ecx+8], eax - mov dword [ecx+4], RX_BUFF_SZ + movzx ecx, [device.cur_rx] + shl ecx, 4 ; *16 + mov ecx, [device.rxd+ecx] + stdcall KernelAlloc, RX_BUFF_SZ + test eax, eax + jz .fail + mov dword [ecx+12], eax + GetRealAddr + mov dword [ecx+8], eax + mov dword [ecx+4], RX_BUFF_SZ - inc [device.cur_rx] ; get next descriptor - and [device.cur_rx], NUM_RX_DESC-1 ; only 4 descriptors 0-3 + inc [device.cur_rx] ; get next descriptor + and [device.cur_rx], NUM_RX_DESC-1 ; only 4 descriptors 0-3 ; Enable Receiver - set_io 0 - set_io cr ; Command Register offset - in eax, dx ; Get current Command Register - or eax, RxENA ; Enable Receiver - out dx, eax + set_io 0 + set_io cr ; Command Register offset + in eax, dx ; Get current Command Register + or eax, RxENA ; Enable Receiver + out dx, eax - pop ax - jmp .no_rx + pop ax + jmp .no_rx .error_status: - DEBUGF 1, "Packet error: %x\n", ecx - jmp .fail + DEBUGF 1, "Packet error: %x\n", ecx + jmp .fail .error_size: - DEBUGF 1, "Packet too large/small\n" - jmp .fail + DEBUGF 1, "Packet too large/small\n" + jmp .fail .no_rx: ;; test ax, TxOk ;; jz .no_tx - ;;; TODO: free all unused buffers + ;;; TODO: free all unused buffers ;; stdcall KernelFree, eax .no_tx: - ret + ret .fail: - DEBUGF 1, "FAILED\n" - jmp $ - ret + DEBUGF 1, "FAILED\n" + jmp $ + ret ;*************************************************************************** @@ -1257,44 +1257,49 @@ int_handler: align 4 transmit: - cmp dword [esp+8], MAX_ETH_FRAME_SIZE - ja .finish + cmp dword [esp+8], MAX_ETH_FRAME_SIZE + ja .error - cmp dword [esp+8], 60 - jb .finish + cmp dword [esp+8], 60 + jb .error - movzx ecx, [device.cur_tx] - shl ecx, 4 - mov ecx, [device.txd+ecx] + movzx ecx, [device.cur_tx] + shl ecx, 4 + mov ecx, [device.txd+ecx] ;; TODO: check if desc is empty (for example: check for eax, 0x6200000 at [ecx+4] ;;; or: count number of available descriptors - mov eax, [esp+4] - mov dword [ecx + 12], eax - GetRealAddr - mov dword [ecx + 8], eax + mov eax, [esp+4] + mov dword [ecx + 12], eax + GetRealAddr + mov dword [ecx + 8], eax - mov eax, [esp+8] - and eax, DSIZE - or eax, 0x80000000 ; card owns descriptor - mov dword [ecx + 4], eax + mov eax, [esp+8] + and eax, DSIZE + or eax, 0x80000000 ; card owns descriptor + mov dword [ecx + 4], eax ; update stats - inc [device.packets_tx] - add dword [device.bytes_tx], ecx - adc dword [device.bytes_tx+4], 0 + inc [device.packets_tx] + add dword [device.bytes_tx], ecx + adc dword [device.bytes_tx+4], 0 .finish: + xor eax, eax + ret 8 - ret 8 + .error: + stdcall KernelFree, [esp+4] + or eax, -1 + ret 8 ; End of code -align 4 ; Place all initialised data here +align 4 ; Place all initialised data here -devices dd 0 +devices dd 0 specific_table: ; dd SIS630A_900_REV,Get_Mac_SIS630A_900_REV,0 @@ -1305,14 +1310,14 @@ specific_table: dd SIS635A_900_REV,Get_Mac_SIS635_900_REV,0 dd SIS900_960_REV,SIS960_get_mac_addr,0 dd SIS900B_900_REV,SIS900_get_mac_addr,0 - dd 0 ; end of list + dd 0 ; end of list -version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) -my_service db 'SIS900',0 ; max 16 chars include zero +version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) +my_service db 'SIS900',0 ; max 16 chars include zero -include_debug_strings ; All data wich FDO uses will be included here +include_debug_strings ; All data wich FDO uses will be included here section '.data' data readable writable align 16; place all uninitialized data place here -device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling +device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling