From f10b7bd3bcd43ddd8f866bac9493da5cad4dad46 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Mon, 2 Apr 2012 18:49:13 +0000 Subject: [PATCH] Fixed bug in some network drivers. (net branch) git-svn-id: svn://kolibrios.org@2544 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/net/drivers/RTL8029.asm | 11 +- kernel/branches/net/drivers/RTL8139.asm | 3 +- kernel/branches/net/drivers/RTL8169.asm | 1 - kernel/branches/net/drivers/dec21x4x.asm | 1851 +++++++++++----------- kernel/branches/net/drivers/mtd80x.asm | 1141 +++++++------ kernel/branches/net/drivers/pcnet32.asm | 1 - kernel/branches/net/drivers/sis900.asm | 1 - 7 files changed, 1501 insertions(+), 1508 deletions(-) diff --git a/kernel/branches/net/drivers/RTL8029.asm b/kernel/branches/net/drivers/RTL8029.asm index 1b8a1745fe..6473f47a4f 100644 --- a/kernel/branches/net/drivers/RTL8029.asm +++ b/kernel/branches/net/drivers/RTL8029.asm @@ -199,7 +199,7 @@ proc service_proc stdcall, ioctl:dword mov [eax], dword API_VERSION xor eax, eax - ret 4 + ret ;------------------------------------------------------ @@: ;--------- @@ -231,8 +231,7 @@ proc service_proc stdcall, ioctl:dword 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] ; get the pci bus and device numbers .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) @@ -306,14 +305,13 @@ proc service_proc stdcall, ioctl:dword cmp eax, -1 jz .err - ret 4 + 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 @@ -330,7 +328,7 @@ proc service_proc stdcall, ioctl:dword @@: .fail: or eax, -1 - ret 4 + ret ;------------------------------------------------------ endp @@ -661,6 +659,7 @@ nsr_002: mov [device.mtu], 1514 ; Indicate that we have successfully reset the card + xor eax, eax DEBUGF 2,"Done!\n" ret diff --git a/kernel/branches/net/drivers/RTL8139.asm b/kernel/branches/net/drivers/RTL8139.asm index fc09cfb7c8..29be9915f2 100644 --- a/kernel/branches/net/drivers/RTL8139.asm +++ b/kernel/branches/net/drivers/RTL8139.asm @@ -294,8 +294,7 @@ proc service_proc stdcall, ioctl:dword test ecx, ecx jz .firstdevice -; mov eax, [IOCTL.input] ; get the pci bus and device numbers - mov ax , [eax+1] ; + mov ax , [eax+1] ; get the pci bus and device numbers .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) diff --git a/kernel/branches/net/drivers/RTL8169.asm b/kernel/branches/net/drivers/RTL8169.asm index 4c76f50c58..5dbb1c8105 100644 --- a/kernel/branches/net/drivers/RTL8169.asm +++ b/kernel/branches/net/drivers/RTL8169.asm @@ -501,7 +501,6 @@ proc service_proc stdcall, ioctl:dword .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 diff --git a/kernel/branches/net/drivers/dec21x4x.asm b/kernel/branches/net/drivers/dec21x4x.asm index 2136b1466d..f653090d3f 100644 --- a/kernel/branches/net/drivers/dec21x4x.asm +++ b/kernel/branches/net/drivers/dec21x4x.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' @@ -38,268 +38,268 @@ public version virtual at ebx - device: + device: - ETH_DEVICE + ETH_DEVICE - .rx_p_des dd ? ; descriptors ring with received packets - .tx_p_des dd ? ; descriptors ring with 'to transmit' packets - .tx_free_des dd ? ; Tx descriptors available - .tx_wr_des dd ? ; Tx current descriptor to write data to - .tx_rd_des dd ? ; Tx current descriptor to read TX completion - .rx_crt_des dd ? ; Rx current descriptor + .rx_p_des dd ? ; descriptors ring with received packets + .tx_p_des dd ? ; descriptors ring with 'to transmit' packets + .tx_free_des dd ? ; Tx descriptors available + .tx_wr_des dd ? ; Tx current descriptor to write data to + .tx_rd_des dd ? ; Tx current descriptor to read TX completion + .rx_crt_des dd ? ; Rx current descriptor - .io_addr dd ? - .pci_bus db ? - .pci_dev db ? - .irq_line db ? + .io_addr dd ? + .pci_bus db ? + .pci_dev db ? + .irq_line db ? - .size = $ - device + .size = $ - device end virtual ;------------------------------------------- ; configuration registers ;------------------------------------------- -CFCS equ 4 ; configuration and status register +CFCS equ 4 ; configuration and status register -CSR0 equ 0x00 ; Bus mode -CSR1 equ 0x08 ; Transmit Poll Command -CSR2 equ 0x10 ; Receive Poll Command -CSR3 equ 0x18 ; Receive list base address -CSR4 equ 0x20 ; Transmit list base address -CSR5 equ 0x28 ; Status -CSR6 equ 0x30 ; Operation mode -CSR7 equ 0x38 ; Interrupt enable -CSR8 equ 0x40 ; Missed frames and overflow counter -CSR9 equ 0x48 ; Boot ROM, serial ROM, and MII management -CSR10 equ 0x50 ; Boot ROM programming address -CSR11 equ 0x58 ; General-purpose timer -CSR12 equ 0x60 ; General-purpose port -CSR13 equ 0x68 -CSR14 equ 0x70 -CSR15 equ 0x78 ; Watchdog timer +CSR0 equ 0x00 ; Bus mode +CSR1 equ 0x08 ; Transmit Poll Command +CSR2 equ 0x10 ; Receive Poll Command +CSR3 equ 0x18 ; Receive list base address +CSR4 equ 0x20 ; Transmit list base address +CSR5 equ 0x28 ; Status +CSR6 equ 0x30 ; Operation mode +CSR7 equ 0x38 ; Interrupt enable +CSR8 equ 0x40 ; Missed frames and overflow counter +CSR9 equ 0x48 ; Boot ROM, serial ROM, and MII management +CSR10 equ 0x50 ; Boot ROM programming address +CSR11 equ 0x58 ; General-purpose timer +CSR12 equ 0x60 ; General-purpose port +CSR13 equ 0x68 +CSR14 equ 0x70 +CSR15 equ 0x78 ; Watchdog timer ;--------bits/commands of CSR0------------------- -CSR0_RESET equ 1b +CSR0_RESET equ 1b -CSR0_WIE equ 1 SHL 24 ; Write and Invalidate Enable -CSR0_RLE equ 1 SHL 23 ; PCI Read Line Enable -CSR0_RML equ 1 SHL 21 ; PCI Read Multiple +CSR0_WIE equ 1 SHL 24 ; Write and Invalidate Enable +CSR0_RLE equ 1 SHL 23 ; PCI Read Line Enable +CSR0_RML equ 1 SHL 21 ; PCI Read Multiple -CSR0_CACHEALIGN_NONE equ 00b SHL 14 -CSR0_CACHEALIGN_32 equ 01b SHL 14 -CSR0_CACHEALIGN_64 equ 10b SHL 14 -CSR0_CACHEALIGN_128 equ 11b SHL 14 +CSR0_CACHEALIGN_NONE equ 00b SHL 14 +CSR0_CACHEALIGN_32 equ 01b SHL 14 +CSR0_CACHEALIGN_64 equ 10b SHL 14 +CSR0_CACHEALIGN_128 equ 11b SHL 14 ; using values from linux driver.. :P -CSR0_DEFAULT equ CSR0_WIE+CSR0_RLE+CSR0_RML+CSR0_CACHEALIGN_NONE ;32 +CSR0_DEFAULT equ CSR0_WIE+CSR0_RLE+CSR0_RML+CSR0_CACHEALIGN_NONE ;32 ;------- CSR5 -STATUS- bits -------------------------------- -CSR5_TI equ 1 SHL 0 ; Transmit interupt - frame transmition completed -CSR5_TPS equ 1 SHL 1 ; Transmit process stopped -CSR5_TU equ 1 SHL 2 ; Transmit Buffer unavailable -CSR5_TJT equ 1 SHL 3 ; Transmit Jabber Timeout (transmitter had been excessively active) -CSR5_UNF equ 1 SHL 5 ; Transmit underflow - FIFO underflow -CSR5_RI equ 1 SHL 6 ; Receive Interrupt -CSR5_RU equ 1 SHL 7 ; Receive Buffer unavailable -CSR5_RPS equ 1 SHL 8 ; Receive Process stopped -CSR5_RWT equ 1 SHL 9 ; Receive Watchdow Timeout -CSR5_ETI equ 1 SHL 10 ; Early transmit Interrupt -CSR5_GTE equ 1 SHL 11 ; General Purpose Timer Expired -CSR5_FBE equ 1 SHL 13 ; Fatal bus error -CSR5_ERI equ 1 SHL 14 ; Early receive Interrupt -CSR5_AIS equ 1 SHL 15 ; Abnormal interrupt summary -CSR5_NIS equ 1 SHL 16 ; normal interrupt summary -CSR5_RS_SH equ 1 SHL 17 ; Receive process state -shift -CSR5_RS_MASK equ 111b ; -mask -CSR5_TS_SH equ 1 SHL 20 ; Transmit process state -shift -CSR5_TS_MASK equ 111b ; -mask -CSR5_EB_SH equ 1 SHL 23 ; Error bits -shift -CSR5_EB_MASK equ 111b ; Error bits -mask +CSR5_TI equ 1 SHL 0 ; Transmit interupt - frame transmition completed +CSR5_TPS equ 1 SHL 1 ; Transmit process stopped +CSR5_TU equ 1 SHL 2 ; Transmit Buffer unavailable +CSR5_TJT equ 1 SHL 3 ; Transmit Jabber Timeout (transmitter had been excessively active) +CSR5_UNF equ 1 SHL 5 ; Transmit underflow - FIFO underflow +CSR5_RI equ 1 SHL 6 ; Receive Interrupt +CSR5_RU equ 1 SHL 7 ; Receive Buffer unavailable +CSR5_RPS equ 1 SHL 8 ; Receive Process stopped +CSR5_RWT equ 1 SHL 9 ; Receive Watchdow Timeout +CSR5_ETI equ 1 SHL 10 ; Early transmit Interrupt +CSR5_GTE equ 1 SHL 11 ; General Purpose Timer Expired +CSR5_FBE equ 1 SHL 13 ; Fatal bus error +CSR5_ERI equ 1 SHL 14 ; Early receive Interrupt +CSR5_AIS equ 1 SHL 15 ; Abnormal interrupt summary +CSR5_NIS equ 1 SHL 16 ; normal interrupt summary +CSR5_RS_SH equ 1 SHL 17 ; Receive process state -shift +CSR5_RS_MASK equ 111b ; -mask +CSR5_TS_SH equ 1 SHL 20 ; Transmit process state -shift +CSR5_TS_MASK equ 111b ; -mask +CSR5_EB_SH equ 1 SHL 23 ; Error bits -shift +CSR5_EB_MASK equ 111b ; Error bits -mask ;CSR5 TS values -CSR5_TS_STOPPED equ 000b +CSR5_TS_STOPPED equ 000b CSR5_TS_RUNNING_FETCHING_DESC equ 001b CSR5_TS_RUNNING_WAITING_TX equ 010b CSR5_TS_RUNNING_READING_BUFF equ 011b CSR5_TS_RUNNING_SETUP_PCKT equ 101b -CSR5_TS_SUSPENDED equ 110b +CSR5_TS_SUSPENDED equ 110b CSR5_TS_RUNNING_CLOSING_DESC equ 111b ;------- CSR6 -OPERATION MODE- bits -------------------------------- -CSR6_HP equ 1 SHL 0 ; Hash/Perfect Receive Filtering mode -CSR6_SR equ 1 SHL 1 ; Start/Stop receive -CSR6_HO equ 1 SHL 2 ; Hash only Filtering mode -CSR6_PB equ 1 SHL 3 ; Pass bad frames -CSR6_IF equ 1 SHL 4 ; Inverse filtering -CSR6_SB equ 1 SHL 5 ; Start/Stop backoff counter -CSR6_PR equ 1 SHL 6 ; Promiscuos mode -default after reset -CSR6_PM equ 1 SHL 7 ; Pass all multicast -CSR6_F equ 1 SHL 9 ; Full Duplex mode -CSR6_OM_SH equ 1 SHL 10 ; Operating Mode -shift -CSR6_OM_MASK equ 11b ; -mask -CSR6_FC equ 1 SHL 12 ; Force Collision Mode -CSR6_ST equ 1 SHL 13 ; Start/Stop Transmission Command -CSR6_TR_SH equ 1 SHL 14 ; Threshold Control -shift -CSR6_TR_MASK equ 11b ; -mask -CSR6_CA equ 1 SHL 17 ; Capture Effect Enable -CSR6_PS equ 1 SHL 18 ; Port select SRL / MII/SYM -CSR6_HBD equ 1 SHL 19 ; Heartbeat Disable -CSR6_SF equ 1 SHL 21 ; Store and Forward -transmit full packet only -CSR6_TTM equ 1 SHL 22 ; Transmit Threshold Mode - -CSR6_PCS equ 1 SHL 23 ; PCS active and MII/SYM port operates in symbol mode -CSR6_SCR equ 1 SHL 24 ; Scrambler Mode -CSR6_MBO equ 1 SHL 25 ; Must Be One -CSR6_RA equ 1 SHL 30 ; Receive All -CSR6_SC equ 1 SHL 31 ; Special Capture Effect Enable +CSR6_HP equ 1 SHL 0 ; Hash/Perfect Receive Filtering mode +CSR6_SR equ 1 SHL 1 ; Start/Stop receive +CSR6_HO equ 1 SHL 2 ; Hash only Filtering mode +CSR6_PB equ 1 SHL 3 ; Pass bad frames +CSR6_IF equ 1 SHL 4 ; Inverse filtering +CSR6_SB equ 1 SHL 5 ; Start/Stop backoff counter +CSR6_PR equ 1 SHL 6 ; Promiscuos mode -default after reset +CSR6_PM equ 1 SHL 7 ; Pass all multicast +CSR6_F equ 1 SHL 9 ; Full Duplex mode +CSR6_OM_SH equ 1 SHL 10 ; Operating Mode -shift +CSR6_OM_MASK equ 11b ; -mask +CSR6_FC equ 1 SHL 12 ; Force Collision Mode +CSR6_ST equ 1 SHL 13 ; Start/Stop Transmission Command +CSR6_TR_SH equ 1 SHL 14 ; Threshold Control -shift +CSR6_TR_MASK equ 11b ; -mask +CSR6_CA equ 1 SHL 17 ; Capture Effect Enable +CSR6_PS equ 1 SHL 18 ; Port select SRL / MII/SYM +CSR6_HBD equ 1 SHL 19 ; Heartbeat Disable +CSR6_SF equ 1 SHL 21 ; Store and Forward -transmit full packet only +CSR6_TTM equ 1 SHL 22 ; Transmit Threshold Mode - +CSR6_PCS equ 1 SHL 23 ; PCS active and MII/SYM port operates in symbol mode +CSR6_SCR equ 1 SHL 24 ; Scrambler Mode +CSR6_MBO equ 1 SHL 25 ; Must Be One +CSR6_RA equ 1 SHL 30 ; Receive All +CSR6_SC equ 1 SHL 31 ; Special Capture Effect Enable ;------- CSR7 -INTERRUPT ENABLE- bits -------------------------------- -CSR7_TI equ 1 SHL 0 ; transmit Interrupt Enable (set with CSR7<16> & CSR5<0> ) -CSR7_TS equ 1 SHL 1 ; transmit Stopped Enable (set with CSR7<15> & CSR5<1> ) -CSR7_TU equ 1 SHL 2 ; transmit buffer underrun Enable (set with CSR7<16> & CSR5<2> ) -CSR7_TJ equ 1 SHL 3 ; transmit jabber timeout enable (set with CSR7<15> & CSR5<3> ) -CSR7_UN equ 1 SHL 5 ; underflow Interrupt enable (set with CSR7<15> & CSR5<5> ) -CSR7_RI equ 1 SHL 6 ; receive Interrupt enable (set with CSR7<16> & CSR5<5> ) -CSR7_RU equ 1 SHL 7 ; receive buffer unavailable enable (set with CSR7<15> & CSR5<7> ) -CSR7_RS equ 1 SHL 8 ; Receive stopped enable (set with CSR7<15> & CSR5<8> ) -CSR7_RW equ 1 SHL 9 ; receive watchdog timeout enable (set with CSR7<15> & CSR5<9> ) -CSR7_ETE equ 1 SHL 10 ; Early transmit Interrupt enable (set with CSR7<15> & CSR5<10> ) -CSR7_GPT equ 1 SHL 11 ; general purpose timer enable (set with CSR7<15> & CSR5<11> ) -CSR7_FBE equ 1 SHL 13 ; Fatal bus error enable (set with CSR7<15> & CSR5<13> ) -CSR7_ERE equ 1 SHL 14 ; Early receive enable (set with CSR7<16> & CSR5<14> ) -CSR7_AI equ 1 SHL 15 ; Abnormal Interrupt Summary Enable (enables CSR5<0,3,7,8,9,10,13>) -CSR7_NI equ 1 SHL 16 ; Normal Interrup Enable (enables CSR5<0,2,6,11,14>) -CSR7_DEFAULT equ CSR7_TI+CSR7_TS+CSR7_RI+CSR7_RS+CSR7_TU+CSR7_TJ+CSR7_UN+\ - CSR7_RU+CSR7_RW+CSR7_FBE+CSR7_AI+CSR7_NI +CSR7_TI equ 1 SHL 0 ; transmit Interrupt Enable (set with CSR7<16> & CSR5<0> ) +CSR7_TS equ 1 SHL 1 ; transmit Stopped Enable (set with CSR7<15> & CSR5<1> ) +CSR7_TU equ 1 SHL 2 ; transmit buffer underrun Enable (set with CSR7<16> & CSR5<2> ) +CSR7_TJ equ 1 SHL 3 ; transmit jabber timeout enable (set with CSR7<15> & CSR5<3> ) +CSR7_UN equ 1 SHL 5 ; underflow Interrupt enable (set with CSR7<15> & CSR5<5> ) +CSR7_RI equ 1 SHL 6 ; receive Interrupt enable (set with CSR7<16> & CSR5<5> ) +CSR7_RU equ 1 SHL 7 ; receive buffer unavailable enable (set with CSR7<15> & CSR5<7> ) +CSR7_RS equ 1 SHL 8 ; Receive stopped enable (set with CSR7<15> & CSR5<8> ) +CSR7_RW equ 1 SHL 9 ; receive watchdog timeout enable (set with CSR7<15> & CSR5<9> ) +CSR7_ETE equ 1 SHL 10 ; Early transmit Interrupt enable (set with CSR7<15> & CSR5<10> ) +CSR7_GPT equ 1 SHL 11 ; general purpose timer enable (set with CSR7<15> & CSR5<11> ) +CSR7_FBE equ 1 SHL 13 ; Fatal bus error enable (set with CSR7<15> & CSR5<13> ) +CSR7_ERE equ 1 SHL 14 ; Early receive enable (set with CSR7<16> & CSR5<14> ) +CSR7_AI equ 1 SHL 15 ; Abnormal Interrupt Summary Enable (enables CSR5<0,3,7,8,9,10,13>) +CSR7_NI equ 1 SHL 16 ; Normal Interrup Enable (enables CSR5<0,2,6,11,14>) +CSR7_DEFAULT equ CSR7_TI+CSR7_TS+CSR7_RI+CSR7_RS+CSR7_TU+CSR7_TJ+CSR7_UN+\ + CSR7_RU+CSR7_RW+CSR7_FBE+CSR7_AI+CSR7_NI ;----------- descriptor structure --------------------- struc DES { - .DES0 DD ? ; bit 31 is 'own' and rest is 'status' - .DES1 DD ? ; control bits + bytes-count buffer 1 + bytes-count buffer 2 - .DES2 DD ? ; pointer to buffer1 - .DES3 DD ? ; pointer to buffer2 or in this case to next descriptor, as we use a chained structure - .realaddr dd ? - .size = 64 + .DES0 DD ? ; bit 31 is 'own' and rest is 'status' + .DES1 DD ? ; control bits + bytes-count buffer 1 + bytes-count buffer 2 + .DES2 DD ? ; pointer to buffer1 + .DES3 DD ? ; pointer to buffer2 or in this case to next descriptor, as we use a chained structure + .realaddr dd ? + .size = 64 } virtual at 0 - DES DES + DES DES end virtual ;common to Rx and Tx -DES0_OWN equ 1 SHL 31 ; if set, the NIC controls the descriptor, otherwise driver 'owns' the descriptors +DES0_OWN equ 1 SHL 31 ; if set, the NIC controls the descriptor, otherwise driver 'owns' the descriptors ;receive -RDES0_ZER equ 1 SHL 0 ; must be 0 if legal length :D -RDES0_CE equ 1 SHL 1 ; CRC error, valid only on last desc (RDES0<8>=1) -RDES0_DB equ 1 SHL 2 ; dribbling bit - not multiple of 8 bits, valid only on last desc (RDES0<8>=1) -RDES0_RE equ 1 SHL 3 ; Report on MII error.. i dont realy know what this means :P -RDES0_RW equ 1 SHL 4 ; received watchdog timer expiration - must set CSR5<9>, valid only on last desc (RDES0<8>=1) -RDES0_FT equ 1 SHL 5 ; frame type: 0->IEEE802.0 (len<1500) 1-> ETHERNET frame (len>1500), valid only on last desc (RDES0<8>=1) -RDES0_CS equ 1 SHL 6 ; Collision seen, valid only on last desc (RDES0<8>=1) -RDES0_TL equ 1 SHL 7 ; Too long(>1518)-NOT AN ERROR, valid only on last desc (RDES0<8>=1) -RDES0_LS equ 1 SHL 8 ; Last descriptor of current frame -RDES0_FS equ 1 SHL 9 ; First descriptor of current frame -RDES0_MF equ 1 SHL 10 ; Multicast frame, valid only on last desc (RDES0<8>=1) -RDES0_RF equ 1 SHL 11 ; Runt frame, valid only on last desc (RDES0<8>=1) and id overflow -RDES0_DT_SERIAL equ 00b SHL 12 ; Data type-Serial recv frame, valid only on last desc (RDES0<8>=1) -RDES0_DT_INTERNAL equ 01b SHL 12 ; Data type-Internal loopback recv frame, valid only on last desc (RDES0<8>=1) -RDES0_DT_EXTERNAL equ 11b SHL 12 ; Data type-External loopback recv frame, valid only on last desc (RDES0<8>=1) -RDES0_DE equ 1 SHL 14 ; Descriptor error - cant own a new desc and frame doesnt fit, valid only on last desc (RDES0<8>=1) -RDES0_ES equ 1 SHL 15 ; Error Summmary - bits 1+6+11+14, valid only on last desc (RDES0<8>=1) -RDES0_FL_SH equ 16 ; Field length shift, valid only on last desc (RDES0<8>=1) -RDES0_FL_MASK equ 11111111111111b ; Field length mask (+CRC), valid only on last desc (RDES0<8>=1) -RDES0_FF equ 1 SHL 30 ; Filtering fail-frame failed address recognition test(must CSR6<30>=1), valid only on last desc (RDES0<8>=1) +RDES0_ZER equ 1 SHL 0 ; must be 0 if legal length :D +RDES0_CE equ 1 SHL 1 ; CRC error, valid only on last desc (RDES0<8>=1) +RDES0_DB equ 1 SHL 2 ; dribbling bit - not multiple of 8 bits, valid only on last desc (RDES0<8>=1) +RDES0_RE equ 1 SHL 3 ; Report on MII error.. i dont realy know what this means :P +RDES0_RW equ 1 SHL 4 ; received watchdog timer expiration - must set CSR5<9>, valid only on last desc (RDES0<8>=1) +RDES0_FT equ 1 SHL 5 ; frame type: 0->IEEE802.0 (len<1500) 1-> ETHERNET frame (len>1500), valid only on last desc (RDES0<8>=1) +RDES0_CS equ 1 SHL 6 ; Collision seen, valid only on last desc (RDES0<8>=1) +RDES0_TL equ 1 SHL 7 ; Too long(>1518)-NOT AN ERROR, valid only on last desc (RDES0<8>=1) +RDES0_LS equ 1 SHL 8 ; Last descriptor of current frame +RDES0_FS equ 1 SHL 9 ; First descriptor of current frame +RDES0_MF equ 1 SHL 10 ; Multicast frame, valid only on last desc (RDES0<8>=1) +RDES0_RF equ 1 SHL 11 ; Runt frame, valid only on last desc (RDES0<8>=1) and id overflow +RDES0_DT_SERIAL equ 00b SHL 12 ; Data type-Serial recv frame, valid only on last desc (RDES0<8>=1) +RDES0_DT_INTERNAL equ 01b SHL 12 ; Data type-Internal loopback recv frame, valid only on last desc (RDES0<8>=1) +RDES0_DT_EXTERNAL equ 11b SHL 12 ; Data type-External loopback recv frame, valid only on last desc (RDES0<8>=1) +RDES0_DE equ 1 SHL 14 ; Descriptor error - cant own a new desc and frame doesnt fit, valid only on last desc (RDES0<8>=1) +RDES0_ES equ 1 SHL 15 ; Error Summmary - bits 1+6+11+14, valid only on last desc (RDES0<8>=1) +RDES0_FL_SH equ 16 ; Field length shift, valid only on last desc (RDES0<8>=1) +RDES0_FL_MASK equ 11111111111111b ; Field length mask (+CRC), valid only on last desc (RDES0<8>=1) +RDES0_FF equ 1 SHL 30 ; Filtering fail-frame failed address recognition test(must CSR6<30>=1), valid only on last desc (RDES0<8>=1) -RDES1_RBS1_MASK equ 11111111111b ; firsd buffer size MASK -RDES1_RBS2_SH equ 1 SHL 11 ; second buffer size SHIFT -RDES1_RBS2_MASK equ 11111111111b ; second buffer size MASK -RDES1_RCH equ 1 SHL 24 ; Second address chained - second address (buffer) is next desc address -RDES1_RER equ 1 SHL 25 ; Receive End of Ring - final descriptor, NIC must return to first desc +RDES1_RBS1_MASK equ 11111111111b ; firsd buffer size MASK +RDES1_RBS2_SH equ 1 SHL 11 ; second buffer size SHIFT +RDES1_RBS2_MASK equ 11111111111b ; second buffer size MASK +RDES1_RCH equ 1 SHL 24 ; Second address chained - second address (buffer) is next desc address +RDES1_RER equ 1 SHL 25 ; Receive End of Ring - final descriptor, NIC must return to first desc ;transmition -TDES0_DE equ 1 SHL 0 ; Deffered -TDES0_UF equ 1 SHL 1 ; Underflow error -TDES0_LF equ 1 SHL 2 ; Link fail report (only if CSR6<23>=1) -TDES0_CC_SH equ 3 ; Collision Count shift - no of collision before transmition -TDES0_CC_MASK equ 1111b ; Collision Count mask -TDES0_HF equ 1 SHL 7 ; Heartbeat fail -TDES0_EC equ 1 SHL 8 ; Excessive Collisions - >16 collisions -TDES0_LC equ 1 SHL 9 ; Late collision -TDES0_NC equ 1 SHL 10 ; No carrier -TDES0_LO equ 1 SHL 11 ; Loss of carrier -TDES0_TO equ 1 SHL 14 ; Transmit Jabber Timeout -TDES0_ES equ 1 SHL 15 ; Error summary TDES0<1+8+9+10+11+14>=1 +TDES0_DE equ 1 SHL 0 ; Deffered +TDES0_UF equ 1 SHL 1 ; Underflow error +TDES0_LF equ 1 SHL 2 ; Link fail report (only if CSR6<23>=1) +TDES0_CC_SH equ 3 ; Collision Count shift - no of collision before transmition +TDES0_CC_MASK equ 1111b ; Collision Count mask +TDES0_HF equ 1 SHL 7 ; Heartbeat fail +TDES0_EC equ 1 SHL 8 ; Excessive Collisions - >16 collisions +TDES0_LC equ 1 SHL 9 ; Late collision +TDES0_NC equ 1 SHL 10 ; No carrier +TDES0_LO equ 1 SHL 11 ; Loss of carrier +TDES0_TO equ 1 SHL 14 ; Transmit Jabber Timeout +TDES0_ES equ 1 SHL 15 ; Error summary TDES0<1+8+9+10+11+14>=1 -TDES1_TBS1_MASK equ 11111111111b ; Buffer 1 size mask -TDES1_TBS2_SH equ 11 ; Buffer 2 size shift -TDES1_TBS2_MASK equ 11111111111b ; Buffer 2 size mask -TDES1_FT0 equ 1 SHL 22 ; Filtering type 0 -TDES1_DPD equ 1 SHL 23 ; Disabled padding for packets <64bytes, no padding -TDES1_TCH equ 1 SHL 24 ; Second address chained - second buffer pointer is to next desc -TDES1_TER equ 1 SHL 25 ; Transmit end of ring - final descriptor -TDES1_AC equ 1 SHL 26 ; Add CRC disable -pretty obvious -TDES1_SET equ 1 SHL 27 ; Setup packet -TDES1_FT1 equ 1 SHL 28 ; Filtering type 1 -TDES1_FS equ 1 SHL 29 ; First segment - buffer is first segment of frame -TDES1_LS equ 1 SHL 30 ; Last segment -TDES1_IC equ 1 SHL 31 ; Interupt on completion (CSR5<0>=1) valid when TDES1<30>=1 +TDES1_TBS1_MASK equ 11111111111b ; Buffer 1 size mask +TDES1_TBS2_SH equ 11 ; Buffer 2 size shift +TDES1_TBS2_MASK equ 11111111111b ; Buffer 2 size mask +TDES1_FT0 equ 1 SHL 22 ; Filtering type 0 +TDES1_DPD equ 1 SHL 23 ; Disabled padding for packets <64bytes, no padding +TDES1_TCH equ 1 SHL 24 ; Second address chained - second buffer pointer is to next desc +TDES1_TER equ 1 SHL 25 ; Transmit end of ring - final descriptor +TDES1_AC equ 1 SHL 26 ; Add CRC disable -pretty obvious +TDES1_SET equ 1 SHL 27 ; Setup packet +TDES1_FT1 equ 1 SHL 28 ; Filtering type 1 +TDES1_FS equ 1 SHL 29 ; First segment - buffer is first segment of frame +TDES1_LS equ 1 SHL 30 ; Last segment +TDES1_IC equ 1 SHL 31 ; Interupt on completion (CSR5<0>=1) valid when TDES1<30>=1 -MAX_ETH_FRAME_SIZE equ 1514 +MAX_ETH_FRAME_SIZE equ 1514 -RX_DES_COUNT equ 4 ; no of RX descriptors, must be power of 2 -RX_BUFF_SIZE equ 2048 ; size of buffer for each descriptor, must be multiple of 4 and <= 2048 TDES1_TBS1_MASK -TX_DES_COUNT equ 4 ; no of TX descriptors, must be power of 2 -TX_BUFF_SIZE equ 2048 ; size of buffer for each descriptor, used for memory allocation only +RX_DES_COUNT equ 4 ; no of RX descriptors, must be power of 2 +RX_BUFF_SIZE equ 2048 ; size of buffer for each descriptor, must be multiple of 4 and <= 2048 TDES1_TBS1_MASK +TX_DES_COUNT equ 4 ; no of TX descriptors, must be power of 2 +TX_BUFF_SIZE equ 2048 ; size of buffer for each descriptor, used for memory allocation only -RX_MEM_TOTAL_SIZE equ RX_DES_COUNT*(DES.size+RX_BUFF_SIZE) -TX_MEM_TOTAL_SIZE equ TX_DES_COUNT*(DES.size+TX_BUFF_SIZE) +RX_MEM_TOTAL_SIZE equ RX_DES_COUNT*(DES.size+RX_BUFF_SIZE) +TX_MEM_TOTAL_SIZE equ TX_DES_COUNT*(DES.size+TX_BUFF_SIZE) ;============================================================================= ; serial ROM operations ;============================================================================= -CSR9_SR equ 1 SHL 11 ; SROM Select -CSR9_RD equ 1 SHL 14 ; ROM Read Operation -CSR9_SROM_DO equ 1 SHL 3 ; Data Out for SROM -CSR9_SROM_DI equ 1 SHL 2 ; Data In to SROM -CSR9_SROM_CK equ 1 SHL 1 ; clock for SROM -CSR9_SROM_CS equ 1 SHL 0 ; chip select.. always needed +CSR9_SR equ 1 SHL 11 ; SROM Select +CSR9_RD equ 1 SHL 14 ; ROM Read Operation +CSR9_SROM_DO equ 1 SHL 3 ; Data Out for SROM +CSR9_SROM_DI equ 1 SHL 2 ; Data In to SROM +CSR9_SROM_CK equ 1 SHL 1 ; clock for SROM +CSR9_SROM_CS equ 1 SHL 0 ; chip select.. always needed ; assume dx is CSR9 macro SROM_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 } ; assume dx is CSR9 macro MDIO_Delay { - push eax - in eax, dx - pop eax + push eax + in eax, dx + pop eax } macro Bit_Set a_bit { - in eax, dx - or eax, a_bit - out dx , eax + in eax, dx + or eax, a_bit + out dx , eax } macro Bit_Clear a_bit { - in eax, dx - and eax, NOT (a_bit) - out dx , eax + in eax, dx + and eax, NOT (a_bit) + out dx , eax } @@ -315,19 +315,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 dec21x4x driver\n" - stdcall RegService, my_service, service_proc - ret + DEBUGF 2,"Loading dec21x4x driver\n" + stdcall RegService, my_service, service_proc + ret .fail: .exit: - xor eax, eax - ret + xor eax, eax + ret endp @@ -342,141 +342,140 @@ 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, dword device.size ; Allocate the buffer for eth_device structure - 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, dword device.size ; Allocate the buffer for eth_device structure + 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.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]: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 - allocate_and_clear [device.rx_p_des], RX_DES_COUNT*(DES.size+RX_BUFF_SIZE), .err - allocate_and_clear [device.tx_p_des], TX_DES_COUNT*(DES.size+TX_BUFF_SIZE), .err + allocate_and_clear [device.rx_p_des], RX_DES_COUNT*(DES.size+RX_BUFF_SIZE), .err + allocate_and_clear [device.tx_p_des], TX_DES_COUNT*(DES.size+TX_BUFF_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 .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" + 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, [device.rx_p_des] - stdcall KernelFree, [device.tx_p_des] - stdcall KernelFree, ebx + DEBUGF 2,"removing device structure\n" + stdcall KernelFree, [device.rx_p_des] + stdcall KernelFree, [device.tx_p_des] + stdcall KernelFree, ebx .fail: - or eax, -1 - ret + or eax, -1 + ret ;------------------------------------------------------ endp @@ -492,23 +491,23 @@ 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 macro status { - set_io CSR5 - in eax, dx - DEBUGF 1,"CSR5: %x\n", eax + set_io CSR5 + in eax, dx + DEBUGF 1,"CSR5: %x\n", eax } @@ -521,46 +520,46 @@ macro status { align 4 probe: - DEBUGF 2,"Probing dec21x4x device: " + DEBUGF 2,"Probing dec21x4x device: " - make_bus_master [device.pci_bus], [device.pci_dev] + make_bus_master [device.pci_bus], [device.pci_dev] - movzx eax, [device.pci_bus] - movzx ecx, [device.pci_dev] - stdcall PciRead32, eax ,ecx ,0 ; get device/vendor id + movzx eax, [device.pci_bus] + movzx ecx, [device.pci_dev] + stdcall PciRead32, eax ,ecx ,0 ; get device/vendor id - DEBUGF 1,"Vendor id: 0x%x\n", ax + DEBUGF 1,"Vendor id: 0x%x\n", ax - cmp ax , 0x1011 - jne .notfound - shr eax, 16 + cmp ax , 0x1011 + jne .notfound + shr eax, 16 - DEBUGF 1,"Vendor ok!, device id: 0x%x\n", ax ; TODO: use another method to detect chip! + DEBUGF 1,"Vendor ok!, device id: 0x%x\n", ax ; TODO: use another method to detect chip! - cmp ax , 0x0009 - je .supported_device + cmp ax , 0x0009 + je .supported_device - cmp ax , 0x0019 - je .supported_device2 + cmp ax , 0x0019 + je .supported_device2 .notfound: - DEBUGF 1,"Device not supported!\n" - or eax, -1 - ret + DEBUGF 1,"Device not supported!\n" + or eax, -1 + ret .supported_device2: - ; wake up the 21143 + ; wake up the 21143 - movzx ecx, [device.pci_bus] - movzx edx, [device.pci_dev] - xor eax, eax - stdcall PciWrite32, ecx, edx, 0x40, eax + movzx ecx, [device.pci_bus] + movzx edx, [device.pci_dev] + xor eax, eax + stdcall PciWrite32, ecx, edx, 0x40, eax .supported_device: - call SROM_GetWidth ; TODO: use this value returned in ecx - ; in the read_word routine! + call SROM_GetWidth ; TODO: use this value returned in ecx + ; in the read_word routine! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; @@ -571,211 +570,211 @@ probe: align 4 reset: - DEBUGF 2,"Resetting dec21x4x\n" + DEBUGF 2,"Resetting dec21x4x\n" ;----------------------------------------------------------- ; board software reset - if fails, dont do nothing else - set_io 0 - status - set_io CSR0 - mov eax, CSR0_RESET - out dx , eax + set_io 0 + status + set_io CSR0 + mov eax, CSR0_RESET + out dx , eax ; wait at least 50 PCI cycles - mov esi, 1000 - call Sleep + mov esi, 1000 + call Sleep ;----------- ; setup CSR0 - set_io 0 - status - set_io CSR0 - mov eax, CSR0_DEFAULT - out dx , eax + set_io 0 + status + set_io CSR0 + mov eax, CSR0_DEFAULT + out dx , eax ; wait at least 50 PCI cycles - mov esi, 1000 - call Sleep + mov esi, 1000 + call Sleep ;----------------------------------- ; Read mac from eeprom to driver ram - call read_mac_eeprom + call read_mac_eeprom ;-------------------------------- ; insert irq handler on given irq - 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 @@: - set_io 0 - status + set_io 0 + status ;------------------------------------------ ; Setup RX descriptors (use chained method) - mov eax, [device.rx_p_des] - call GetPgAddr - mov edx, eax - lea esi, [eax + RX_DES_COUNT*(DES.size)] ; jump over RX descriptors + mov eax, [device.rx_p_des] + call GetPgAddr + mov edx, eax + lea esi, [eax + RX_DES_COUNT*(DES.size)] ; jump over RX descriptors - mov eax, [device.rx_p_des] - add eax, RX_DES_COUNT*(DES.size) ; jump over RX descriptors + mov eax, [device.rx_p_des] + add eax, RX_DES_COUNT*(DES.size) ; jump over RX descriptors - mov edi, [device.rx_p_des] - mov ecx, RX_DES_COUNT + mov edi, [device.rx_p_des] + mov ecx, RX_DES_COUNT - push edx ;; + push edx ;; .loop_rx_des: - add edx, DES.size - mov [edi+DES.DES0], DES0_OWN ; hardware owns buffer - mov [edi+DES.DES1], 1984+RDES1_RCH ; only size of first buffer, chained buffers - mov [edi+DES.DES2], esi ; hw buffer address - mov [edi+DES.DES3], edx ; pointer to next descriptor - mov [edi+DES.realaddr], eax ; virtual buffer address + add edx, DES.size + mov [edi+DES.DES0], DES0_OWN ; hardware owns buffer + mov [edi+DES.DES1], 1984+RDES1_RCH ; only size of first buffer, chained buffers + mov [edi+DES.DES2], esi ; hw buffer address + mov [edi+DES.DES3], edx ; pointer to next descriptor + mov [edi+DES.realaddr], eax ; virtual buffer address - DEBUGF 1,"RX desc %u, buff addr: %x, next desc: %x, real buff addr: %x, real descr addr: %x \n", ecx, esi, edx, eax, edi + DEBUGF 1,"RX desc %u, buff addr: %x, next desc: %x, real buff addr: %x, real descr addr: %x \n", ecx, esi, edx, eax, edi - add esi, RX_BUFF_SIZE - add eax, RX_BUFF_SIZE - add edi, DES.size - dec ecx - jnz .loop_rx_des + add esi, RX_BUFF_SIZE + add eax, RX_BUFF_SIZE + add edi, DES.size + dec ecx + jnz .loop_rx_des ; set last descriptor as LAST - sub edi, DES.size - or [edi+DES.DES1], RDES1_RER ; EndOfRing - pop edx ;; - mov [edi+DES.DES3], edx ;; + sub edi, DES.size + or [edi+DES.DES1], RDES1_RER ; EndOfRing + pop edx ;; + mov [edi+DES.DES3], edx ;; ;--------------------- ; Setup TX descriptors - mov eax, [device.tx_p_des] - call GetPgAddr - mov edx, eax - lea esi, [eax + TX_DES_COUNT*(DES.size)] ; jump over TX descriptors + mov eax, [device.tx_p_des] + call GetPgAddr + mov edx, eax + lea esi, [eax + TX_DES_COUNT*(DES.size)] ; jump over TX descriptors - mov eax, [device.tx_p_des] - add eax, TX_DES_COUNT*(DES.size) ; jump over TX descriptors + mov eax, [device.tx_p_des] + add eax, TX_DES_COUNT*(DES.size) ; jump over TX descriptors - mov edi, [device.tx_p_des] - mov ecx, TX_DES_COUNT + mov edi, [device.tx_p_des] + mov ecx, TX_DES_COUNT - push edx ;; + push edx ;; .loop_tx_des: - add edx, DES.size - mov [edi+DES.DES0], 0 ; owned by driver - mov [edi+DES.DES1], TDES1_TCH ; chained method - mov [edi+DES.DES2], esi ; pointer to buffer - mov [edi+DES.DES3], edx ; pointer to next descr - mov [edi+DES.realaddr], eax + add edx, DES.size + mov [edi+DES.DES0], 0 ; owned by driver + mov [edi+DES.DES1], TDES1_TCH ; chained method + mov [edi+DES.DES2], esi ; pointer to buffer + mov [edi+DES.DES3], edx ; pointer to next descr + mov [edi+DES.realaddr], eax - DEBUGF 1,"TX desc %u, buff addr: %x, next desc: %x, real buff addr: %x, real descr addr: %x \n", ecx, esi, edx, eax, edi + DEBUGF 1,"TX desc %u, buff addr: %x, next desc: %x, real buff addr: %x, real descr addr: %x \n", ecx, esi, edx, eax, edi - add esi, TX_BUFF_SIZE - add eax, TX_BUFF_SIZE - add edi, DES.size - dec ecx - jnz .loop_tx_des - + add esi, TX_BUFF_SIZE + add eax, TX_BUFF_SIZE + add edi, DES.size + dec ecx + jnz .loop_tx_des + ; set last descriptor as LAST - sub edi, DES.size - or [edi+DES.DES1], TDES1_TER ; EndOfRing - pop edx ;;; - mov [edi+DES.DES3], edx ;;; + sub edi, DES.size + or [edi+DES.DES1], TDES1_TER ; EndOfRing + pop edx ;;; + mov [edi+DES.DES3], edx ;;; ;------------------ ; Reset descriptors - mov [device.tx_wr_des], 0 - mov [device.tx_rd_des], 0 - mov [device.rx_crt_des], 0 - mov [device.tx_free_des], TX_DES_COUNT + mov [device.tx_wr_des], 0 + mov [device.tx_rd_des], 0 + mov [device.rx_crt_des], 0 + mov [device.tx_free_des], TX_DES_COUNT ;-------------------------------------------- ; setup CSR3 & CSR4 (pointers to descriptors) - set_io 0 - status - set_io CSR3 - mov eax, [device.rx_p_des] - call GetPgAddr - DEBUGF 1,"RX descriptor base address: %x\n", eax - out dx , eax + set_io 0 + status + set_io CSR3 + mov eax, [device.rx_p_des] + call GetPgAddr + DEBUGF 1,"RX descriptor base address: %x\n", eax + out dx , eax - set_io CSR4 - mov eax, [device.tx_p_des] - call GetPgAddr - DEBUGF 1,"TX descriptor base address: %x\n", eax - out dx , eax + set_io CSR4 + mov eax, [device.tx_p_des] + call GetPgAddr + DEBUGF 1,"TX descriptor base address: %x\n", eax + out dx , eax ;------------------------------------------------------- ; setup interrupt mask register -expect IRQs from now on - status - DEBUGF 1,"Enabling interrupts\n" - set_io CSR7 - mov eax, CSR7_DEFAULT - out dx , eax - status + status + DEBUGF 1,"Enabling interrupts\n" + set_io CSR7 + mov eax, CSR7_DEFAULT + out dx , eax + status ;---------- ; enable RX - set_io 0 - status - DEBUGF 1,"Enable RX\n" + set_io 0 + status + DEBUGF 1,"Enable RX\n" - set_io CSR6 - Bit_Set CSR6_SR; or CSR6_PR or CSR6_ST - DEBUGF 1,"CSR6: %x\n", eax + set_io CSR6 + Bit_Set CSR6_SR; or CSR6_PR or CSR6_ST + DEBUGF 1,"CSR6: %x\n", eax - status + status - call start_link + call start_link ; wait a bit - mov esi, 3000 - call Sleep + mov esi, 3000 + call Sleep ;---------------------------------------------------- ; send setup packet to notify the board about the MAC - call Send_Setup_Packet + call Send_Setup_Packet - 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 - DEBUGF 1,"Reset done\n" + DEBUGF 1,"Reset done\n" - ret + ret align 4 start_link: - ; TODO: write working code here + ; TODO: write working code here - ret + ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; @@ -786,29 +785,29 @@ start_link: align 4 Send_Setup_Packet: - DEBUGF 1,"Sending setup packet\n" + DEBUGF 1,"Sending setup packet\n" ; if no descriptors available, out - mov ecx, 1000 + mov ecx, 1000 @@loop_wait_desc: - cmp [device.tx_free_des], 0 - jne @f + cmp [device.tx_free_des], 0 + jne @f - dec ecx - jnz @@loop_wait_desc + dec ecx + jnz @@loop_wait_desc - mov eax, -1 - ret + mov eax, -1 + ret @@: ; go to current send descriptor - mov edi, [device.tx_p_des] - mov eax, [device.tx_wr_des] - DEBUGF 1,"Got free descriptor: %u (%x)", eax, edi - mov edx, DES.size - mul edx - add edi, eax - DEBUGF 1,"=>%x\n", edi + mov edi, [device.tx_p_des] + mov eax, [device.tx_wr_des] + DEBUGF 1,"Got free descriptor: %u (%x)", eax, edi + mov edx, DES.size + mul edx + add edi, eax + DEBUGF 1,"=>%x\n", edi ; if NOT sending FIRST setup packet, must set current descriptor to 0 size for both buffers, ; and go to next descriptor for real setup packet... ;; TODO: check if 2 descriptors are available @@ -838,73 +837,73 @@ Send_Setup_Packet: .not_first: - push edi + push edi ; copy setup packet to current descriptor - mov edi, [edi+DES.realaddr] + mov edi, [edi+DES.realaddr] ; copy once the address - lea esi, [device.mac] - DEBUGF 1,"copying packet to %x from %x\n", edi, esi - mov ecx, 3 ; mac is 6 bytes thus 3 words + lea esi, [device.mac] + DEBUGF 1,"copying packet to %x from %x\n", edi, esi + mov ecx, 3 ; mac is 6 bytes thus 3 words .loop: - DEBUGF 1,"%x ", [esi]:4 - movsw - dec esi - dec esi - movsw - dec ecx - jnz .loop + DEBUGF 1,"%x ", [esi]:4 + movsw + dec esi + dec esi + movsw + dec ecx + jnz .loop - DEBUGF 1,"\n" + DEBUGF 1,"\n" ; copy 15 times the broadcast address - mov ecx, 3*15 - mov eax, 0xffffffff - rep stosd + mov ecx, 3*15 + mov eax, 0xffffffff + rep stosd - pop edi + pop edi ; setup descriptor - DEBUGF 1,"setting up descriptor\n" - mov [edi+DES.DES1], TDES1_IC+TDES1_SET+TDES1_TCH+192 ; size must be EXACTLY 192 bytes - mov [edi+DES.DES0], DES0_OWN + DEBUGF 1,"setting up descriptor\n" + mov [edi+DES.DES1], TDES1_IC+TDES1_SET+TDES1_TCH+192 ; size must be EXACTLY 192 bytes + mov [edi+DES.DES0], DES0_OWN - DEBUGF 1,"TDES0: %x\n", [edi+DES.DES0]:8 - DEBUGF 1,"TDES1: %x\n", [edi+DES.DES1]:8 - DEBUGF 1,"TDES2: %x\n", [edi+DES.DES2]:8 - DEBUGF 1,"TDES3: %x\n", [edi+DES.DES3]:8 + DEBUGF 1,"TDES0: %x\n", [edi+DES.DES0]:8 + DEBUGF 1,"TDES1: %x\n", [edi+DES.DES1]:8 + DEBUGF 1,"TDES2: %x\n", [edi+DES.DES2]:8 + DEBUGF 1,"TDES3: %x\n", [edi+DES.DES3]:8 ; go to next descriptor - inc [device.tx_wr_des] - and [device.tx_wr_des], TX_DES_COUNT-1 + inc [device.tx_wr_des] + and [device.tx_wr_des], TX_DES_COUNT-1 ; dec free descriptors count - cmp [device.tx_free_des], 0 - jz @f - dec [device.tx_free_des] + cmp [device.tx_free_des], 0 + jz @f + dec [device.tx_free_des] @@: ; start tx - set_io 0 - status - set_io CSR6 - in eax, dx - test eax, CSR6_ST ; if NOT started, start now - jnz .already_started - or eax, CSR6_ST - DEBUGF 1,"Starting TX\n" - jmp .do_it + set_io 0 + status + set_io CSR6 + in eax, dx + test eax, CSR6_ST ; if NOT started, start now + jnz .already_started + or eax, CSR6_ST + DEBUGF 1,"Starting TX\n" + jmp .do_it .already_started: - ; if already started, issue a Transmit Poll command - set_io CSR1 - mov eax, 0 - DEBUGF 1,"Issuing transmit poll command\n" + ; if already started, issue a Transmit Poll command + set_io CSR1 + mov eax, 0 + DEBUGF 1,"Issuing transmit poll command\n" .do_it: - out dx , eax - status + out dx , eax + status - DEBUGF 1,"Sending setup packet, completed!\n" + DEBUGF 1,"Sending setup packet, completed!\n" - ret + ret @@ -921,87 +920,87 @@ Send_Setup_Packet: 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 - cmp [device.tx_free_des], 0 - je .fail + cmp [device.tx_free_des], 0 + je .fail ;-------------------------- ; copy packet to crt buffer - - mov eax, [device.tx_wr_des] - mov edx, DES.size - mul edx - add eax, [device.tx_p_des] - mov edi, [eax+DES.realaddr] ; pointer to buffer - mov esi, [esp+4] - mov ecx, [esp+8] - DEBUGF 1,"copying %u bytes from %x to %x\n", ecx, esi, edi - rep movsb + + mov eax, [device.tx_wr_des] + mov edx, DES.size + mul edx + add eax, [device.tx_p_des] + mov edi, [eax+DES.realaddr] ; pointer to buffer + mov esi, [esp+4] + mov ecx, [esp+8] + DEBUGF 1,"copying %u bytes from %x to %x\n", ecx, esi, edi + rep movsb ; set packet size - mov ecx, [eax+DES.DES1] - and ecx, TDES1_TER ; preserve 'End of Ring' bit - or ecx, [esp+8] ; set size - or ecx, TDES1_FS or TDES1_LS or TDES1_IC or TDES1_TCH ; first descr, last descr, interrupt on complete, chained modus - mov [eax+DES.DES1], ecx + mov ecx, [eax+DES.DES1] + and ecx, TDES1_TER ; preserve 'End of Ring' bit + or ecx, [esp+8] ; set size + or ecx, TDES1_FS or TDES1_LS or TDES1_IC or TDES1_TCH ; first descr, last descr, interrupt on complete, chained modus + mov [eax+DES.DES1], ecx ; set descriptor info - mov [eax+DES.DES0], DES0_OWN ; say it is now owned by the 21x4x + mov [eax+DES.DES0], DES0_OWN ; say it is now owned by the 21x4x ; start tx - set_io 0 - status - set_io CSR6 - in eax, dx - test eax, CSR6_ST ; if NOT started, start now - jnz .already_started - or eax, CSR6_ST - DEBUGF 1,"Starting TX\n" - jmp .do_it + set_io 0 + status + set_io CSR6 + in eax, dx + test eax, CSR6_ST ; if NOT started, start now + jnz .already_started + or eax, CSR6_ST + DEBUGF 1,"Starting TX\n" + jmp .do_it .already_started: - ; if already started, issues a Transmit Poll command - set_io CSR1 - mov eax, -1 + ; if already started, issues a Transmit Poll command + set_io CSR1 + mov eax, -1 .do_it: - out dx , eax + out dx , eax ; 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 ; go to next descriptor - inc [device.tx_wr_des] - and [device.tx_wr_des], TX_DES_COUNT-1 + inc [device.tx_wr_des] + and [device.tx_wr_des], TX_DES_COUNT-1 ; dec free descriptors count - test [device.tx_free_des], -1 - jz .end - dec [device.tx_free_des] + test [device.tx_free_des], -1 + jz .end + dec [device.tx_free_des] .end: - status + status - DEBUGF 1,"transmit ok\n" - xor eax, eax - stdcall KernelFree, [esp+4] - ret 8 + DEBUGF 1,"transmit ok\n" + xor eax, eax + stdcall KernelFree, [esp+4] + 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 ;;;;;;;;;;;;;;;;;;;;;;; @@ -1013,36 +1012,36 @@ 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 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 CSR5 - in eax, dx - out dx , eax ; send it back to ACK + set_io 0 + set_io CSR5 + in eax, dx + out dx , eax ; send it back to ACK - and eax, CSR7_DEFAULT ; int mask - test eax, eax - jnz .got_it + and eax, CSR7_DEFAULT ; int mask + test eax, eax + 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,"CSR7: %x ", eax + DEBUGF 1,"CSR7: %x ", eax ; looks like we've found it! @@ -1051,341 +1050,341 @@ int_handler: ;---------------------------------- ; TX ok? - test eax, CSR5_TI - jz .not_tx - push ax esi ecx + test eax, CSR5_TI + jz .not_tx + push ax esi ecx - DEBUGF 1,"TX ok!\n" - - ; go to current descriptor - mov edi, [device.tx_p_des] + DEBUGF 1,"TX ok!\n" + + ; go to current descriptor + mov edi, [device.tx_p_des] - mov eax, [device.tx_rd_des] - mov edx, DES.size - mul edx - add edi, eax - + mov eax, [device.tx_rd_des] + mov edx, DES.size + mul edx + add edi, eax + .loop_tx: - - ; done if all desc are free - cmp [device.tx_free_des], TX_DES_COUNT - jz .end_tx + + ; done if all desc are free + cmp [device.tx_free_des], TX_DES_COUNT + jz .end_tx - mov eax, [edi+DES.DES0] + mov eax, [edi+DES.DES0] - ; we stop at first desc that is owned be NIC - test eax, DES0_OWN - jnz .end_tx + ; we stop at first desc that is owned be NIC + test eax, DES0_OWN + jnz .end_tx - ; detect is setup packet - cmp eax, (0ffffffffh - DES0_OWN) ; all other bits are 1 - jne .not_setup_packet - DEBUGF 1,"Setup Packet detected\n" + ; detect is setup packet + cmp eax, (0ffffffffh - DES0_OWN) ; all other bits are 1 + jne .not_setup_packet + DEBUGF 1,"Setup Packet detected\n" .not_setup_packet: - DEBUGF 1,"packet status: %x\n", eax + DEBUGF 1,"packet status: %x\n", eax - ; next descriptor - add edi, DES.size - inc [device.tx_rd_des] - and [device.tx_rd_des], TX_DES_COUNT-1 + ; next descriptor + add edi, DES.size + inc [device.tx_rd_des] + and [device.tx_rd_des], TX_DES_COUNT-1 - ; inc free desc - inc [device.tx_free_des] - cmp [device.tx_free_des], TX_DES_COUNT - jle @f - mov [device.tx_free_des], TX_DES_COUNT + ; inc free desc + inc [device.tx_free_des] + cmp [device.tx_free_des], TX_DES_COUNT + jle @f + mov [device.tx_free_des], TX_DES_COUNT @@: - jmp .loop_tx + jmp .loop_tx .end_tx: - - ;------------------------------------------------------ - ; here must be called standard Ethernet Tx Irq Handler - ;------------------------------------------------------ + + ;------------------------------------------------------ + ; here must be called standard Ethernet Tx Irq Handler + ;------------------------------------------------------ - pop ecx esi ax + pop ecx esi ax ;---------------------------------- ; RX irq .not_tx: - test eax, CSR5_RI - jz .not_rx - push ax esi ecx + test eax, CSR5_RI + jz .not_rx + push ax esi ecx - DEBUGF 1,"RX ok!\n" - - ;go to current descriptor - mov edi, [device.rx_p_des] + DEBUGF 1,"RX ok!\n" + + ;go to current descriptor + mov edi, [device.rx_p_des] - mov eax, [device.rx_crt_des] - mov edx, DES.size - mul edx - add edi, eax - + mov eax, [device.rx_crt_des] + mov edx, DES.size + mul edx + add edi, eax + .loop_rx_start_of_packet: - mov eax, [edi+DES.DES0] + mov eax, [edi+DES.DES0] - test eax, DES0_OWN - jnz .end_rx ; current desc is busy, nothing to do + test eax, DES0_OWN + jnz .end_rx ; current desc is busy, nothing to do - test eax, RDES0_FS - jz .end_rx ; current desc is NOT first packet, ERROR! + test eax, RDES0_FS + jz .end_rx ; current desc is NOT first packet, ERROR! - test eax, RDES0_LS ; if not last desc of packet, error for now - jz .end_rx + test eax, RDES0_LS ; if not last desc of packet, error for now + jz .end_rx ; .IF ZERO? ; ODS2 <"Net_Interrupt: packet > 1 descriptor, not supported yet :P"> ; jmp @@end_rx ; .ENDIF - test eax, RDES0_ES - jnz .end_rx + test eax, RDES0_ES + jnz .end_rx ; .IF !ZERO? ; ODS2 <"Net_Interrupt: RX error"> ; jmp @@end_rx ; .ENDIF - mov esi, [edi+DES.realaddr] - mov ecx, [edi+DES.DES0] - shr ecx, RDES0_FL_SH - and ecx, RDES0_FL_MASK - sub ecx, 4 ; crc + mov esi, [edi+DES.realaddr] + mov ecx, [edi+DES.DES0] + shr ecx, RDES0_FL_SH + and ecx, RDES0_FL_MASK + sub ecx, 4 ; crc - DEBUGF 1,"Received packet!, size=%u, addr:%x\n", ecx, esi + DEBUGF 1,"Received packet!, size=%u, addr:%x\n", ecx, esi - push esi edi ecx - stdcall KernelAlloc, ecx ; Allocate a buffer to put packet into - pop ecx edi esi - test eax, eax - jz .fail + push esi edi ecx + stdcall KernelAlloc, ecx ; Allocate a buffer to put packet into + pop ecx edi esi + test eax, eax + jz .fail - push edi - push dword .continue_rx - push ecx eax - mov edi, eax + push edi + push dword .continue_rx + push ecx eax + mov edi, eax ; update statistics - inc [device.packets_rx] + inc [device.packets_rx] - add dword [device.bytes_rx], ecx - adc dword [device.bytes_rx + 4], 0 + add dword [device.bytes_rx], ecx + adc dword [device.bytes_rx + 4], 0 ; copy packet data - shr cx , 1 - jnc .nb - movsb + shr cx , 1 + jnc .nb + movsb .nb: - shr cx , 1 - jnc .nw - movsw + shr cx , 1 + jnc .nw + movsw .nw: - rep movsd + rep movsd - jmp EthReceiver + jmp EthReceiver .continue_rx: - pop edi + pop edi - ; free descriptor - mov [edi+DES.DES0], DES0_OWN - - ; next descriptor - add edi, DES.size + ; free descriptor + mov [edi+DES.DES0], DES0_OWN + + ; next descriptor + add edi, DES.size - inc [device.rx_crt_des] - and [device.rx_crt_des], RX_DES_COUNT-1 + inc [device.rx_crt_des] + and [device.rx_crt_des], RX_DES_COUNT-1 - jmp .loop_rx_start_of_packet + jmp .loop_rx_start_of_packet .end_rx: .fail: - pop ecx esi ax + pop ecx esi ax .not_rx: - jmp .continue + jmp .continue 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: " ; write data into driver cache - mov esi, esp - lea edi, [device.mac] - movsd - movsw - add esp, 6 - + mov esi, esp + lea edi, [device.mac] + movsd + movsw + add esp, 6 + ; send setup packet (only if driver is started) - call Send_Setup_Packet + call Send_Setup_Packet align 4 read_mac: - DEBUGF 1,"Read_mac\n" + DEBUGF 1,"Read_mac\n" - ret + ret align 4 read_mac_eeprom: - DEBUGF 1,"Read_mac_eeprom\n" + DEBUGF 1,"Read_mac_eeprom\n" - lea edi, [device.mac] - mov esi, 20/2 ; read words, start address is 20 + lea edi, [device.mac] + mov esi, 20/2 ; read words, start address is 20 .loop: - push esi edi - call SROM_Read_Word - pop edi esi - stosw - inc esi - cmp esi, 26/2 - jl .loop + push esi edi + call SROM_Read_Word + pop edi esi + stosw + inc esi + cmp esi, 26/2 + jl .loop - 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 align 4 write_mac_eeprom: - DEBUGF 1,"Write_mac_eeprom\n" + DEBUGF 1,"Write_mac_eeprom\n" - ret + ret align 4 -SROM_GetWidth: ; should be 6 or 8 according to some manuals (returns in ecx) +SROM_GetWidth: ; should be 6 or 8 according to some manuals (returns in ecx) - DEBUGF 1,"SROM_GetWidth\n" + DEBUGF 1,"SROM_GetWidth\n" - call SROM_Idle - call SROM_EnterAccessMode + call SROM_Idle + call SROM_EnterAccessMode ; set_io 0 ; set_io CSR9 - ; send 110b + ; send 110b - in eax, dx - or eax, CSR9_SROM_DI - call SROM_out + in eax, dx + or eax, CSR9_SROM_DI + call SROM_out - in eax, dx - or eax, CSR9_SROM_DI - call SROM_out + in eax, dx + or eax, CSR9_SROM_DI + call SROM_out - in eax, dx - and eax, not (CSR9_SROM_DI) - call SROM_out - - mov ecx,1 + in eax, dx + and eax, not (CSR9_SROM_DI) + call SROM_out + + mov ecx,1 .loop2: - Bit_Set CSR9_SROM_CK - SROM_Delay - - in eax, dx - and eax, CSR9_SROM_DO - jnz .not_zero + Bit_Set CSR9_SROM_CK + SROM_Delay + + in eax, dx + and eax, CSR9_SROM_DO + jnz .not_zero - Bit_Clear CSR9_SROM_CK - SROM_Delay - jmp .end_loop2 + Bit_Clear CSR9_SROM_CK + SROM_Delay + jmp .end_loop2 .not_zero: - - Bit_Clear CSR9_SROM_CK - SROM_Delay - - inc ecx - cmp ecx, 12 - jle .loop2 + + Bit_Clear CSR9_SROM_CK + SROM_Delay + + inc ecx + cmp ecx, 12 + jle .loop2 .end_loop2: - - DEBUGF 1,"Srom width=%u\n", ecx - - call SROM_Idle - call SROM_EnterAccessMode - call SROM_Idle - - ret + + DEBUGF 1,"Srom width=%u\n", ecx + + call SROM_Idle + call SROM_EnterAccessMode + call SROM_Idle + + ret align 4 SROM_out: - out dx, eax - SROM_Delay - Bit_Set CSR9_SROM_CK - SROM_Delay - Bit_Clear CSR9_SROM_CK - SROM_Delay + out dx, eax + SROM_Delay + Bit_Set CSR9_SROM_CK + SROM_Delay + Bit_Clear CSR9_SROM_CK + SROM_Delay - ret + ret align 4 SROM_EnterAccessMode: - DEBUGF 1,"SROM_EnterAccessMode\n" + DEBUGF 1,"SROM_EnterAccessMode\n" - set_io 0 - set_io CSR9 - mov eax, CSR9_SR - out dx, eax - SROM_Delay + set_io 0 + set_io CSR9 + mov eax, CSR9_SR + out dx, eax + SROM_Delay - Bit_Set CSR9_RD - SROM_Delay + Bit_Set CSR9_RD + SROM_Delay - Bit_Clear CSR9_SROM_CK - SROM_Delay + Bit_Clear CSR9_SROM_CK + SROM_Delay - Bit_Set CSR9_SROM_CS - SROM_Delay - - ret + Bit_Set CSR9_SROM_CS + SROM_Delay + + ret align 4 SROM_Idle: - DEBUGF 1,"SROM_Idle\n" + DEBUGF 1,"SROM_Idle\n" - call SROM_EnterAccessMode - + call SROM_EnterAccessMode + ; set_io 0 ; set_io CSR9 - - mov ecx, 25 + + mov ecx, 25 .loop_clk: - Bit_Clear CSR9_SROM_CK - SROM_Delay - Bit_Set CSR9_SROM_CK - SROM_Delay - - dec ecx - jnz .loop_clk + Bit_Clear CSR9_SROM_CK + SROM_Delay + Bit_Set CSR9_SROM_CK + SROM_Delay + + dec ecx + jnz .loop_clk - - Bit_Clear CSR9_SROM_CK - SROM_Delay - Bit_Clear CSR9_SROM_CS - SROM_Delay - - xor eax, eax - out dx, eax - - ret + + Bit_Clear CSR9_SROM_CK + SROM_Delay + Bit_Clear CSR9_SROM_CS + SROM_Delay + + xor eax, eax + out dx, eax + + ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1399,67 +1398,67 @@ SROM_Idle: align 4 SROM_Read_Word: - DEBUGF 1,"SROM_Read_word at: %x result: ", esi + DEBUGF 1,"SROM_Read_word at: %x result: ", esi - set_io 0 - set_io CSR9 + set_io 0 + set_io CSR9 ; enter access mode - mov eax, CSR9_SR + CSR9_RD - out dx , eax - or eax, CSR9_SROM_CS - out dx , eax + mov eax, CSR9_SR + CSR9_RD + out dx , eax + or eax, CSR9_SROM_CS + out dx , eax - ; TODO: change this hard-coded 6-bit stuff to use value from srom_getwidth - + ; TODO: change this hard-coded 6-bit stuff to use value from srom_getwidth + ; send read command "110b" + address to read from - and esi, 111111b - or esi, 110b shl 6 - - mov ecx, 1 shl 9 + and esi, 111111b + or esi, 110b shl 6 + + mov ecx, 1 shl 9 .loop_cmd: - mov eax, CSR9_SR + CSR9_RD + CSR9_SROM_CS - test esi, ecx - jz @f - or eax, CSR9_SROM_DI + mov eax, CSR9_SR + CSR9_RD + CSR9_SROM_CS + test esi, ecx + jz @f + or eax, CSR9_SROM_DI @@: - out dx , eax - SROM_Delay - or eax, CSR9_SROM_CK - out dx , eax - SROM_Delay - - shr ecx, 1 - jnz .loop_cmd + out dx , eax + SROM_Delay + or eax, CSR9_SROM_CK + out dx , eax + SROM_Delay + + shr ecx, 1 + jnz .loop_cmd ; read data from SROM - xor esi, esi - mov ecx, 17 ;;; TODO: figure out why 17, not 16 + xor esi, esi + mov ecx, 17 ;;; TODO: figure out why 17, not 16 .loop_read: - - mov eax, CSR9_SR + CSR9_RD + CSR9_SROM_CS + CSR9_SROM_CK - out dx , eax - SROM_Delay - - in eax, dx - and eax, CSR9_SROM_DO - shr eax, 3 - shl esi, 1 - or esi, eax - - mov eax, CSR9_SR + CSR9_RD + CSR9_SROM_CS - out dx , eax - SROM_Delay - - dec ecx - jnz .loop_read - - mov eax, esi + + mov eax, CSR9_SR + CSR9_RD + CSR9_SROM_CS + CSR9_SROM_CK + out dx , eax + SROM_Delay + + in eax, dx + and eax, CSR9_SROM_DO + shr eax, 3 + shl esi, 1 + or esi, eax + + mov eax, CSR9_SR + CSR9_RD + CSR9_SROM_CS + out dx , eax + SROM_Delay + + dec ecx + jnz .loop_read + + mov eax, esi - DEBUGF 1,"%x\n", ax + DEBUGF 1,"%x\n", ax - ret + ret @@ -1488,12 +1487,12 @@ SROM_Read_Word: ; MDIO protocol. It is just different enough from the EEPROM protocol ; to not share code. The maxium data clock rate is 2.5 Mhz. -MDIO_SHIFT_CLK equ 0x10000 -MDIO_DATA_WRITE0 equ 0x00000 -MDIO_DATA_WRITE1 equ 0x20000 -MDIO_ENB equ 0x00000 ; Ignore the 0x02000 databook setting. -MDIO_ENB_IN equ 0x40000 -MDIO_DATA_READ equ 0x80000 +MDIO_SHIFT_CLK equ 0x10000 +MDIO_DATA_WRITE0 equ 0x00000 +MDIO_DATA_WRITE1 equ 0x20000 +MDIO_ENB equ 0x00000 ; Ignore the 0x02000 databook setting. +MDIO_ENB_IN equ 0x40000 +MDIO_DATA_READ equ 0x80000 ; MII transceiver control section. ; Read and write the MII registers using software-generated serial @@ -1501,16 +1500,16 @@ MDIO_DATA_READ equ 0x80000 ; for details. align 4 -mdio_read: ; phy_id:edx, location:esi +mdio_read: ; phy_id:edx, location:esi - DEBUGF 1,"mdio read, phy=%x, location=%x", edx, esi + DEBUGF 1,"mdio read, phy=%x, location=%x", edx, esi - shl edx, 5 - or esi, edx - or esi, 0xf6 shl 10 + shl edx, 5 + or esi, edx + or esi, 0xf6 shl 10 - set_io 0 - set_io CSR9 + set_io 0 + set_io CSR9 ; if (tp->chip_id == LC82C168) { ; int i = 1000; @@ -1537,86 +1536,86 @@ mdio_read: ; phy_id:edx, location:esi ; Establish sync by sending at least 32 logic ones. - mov ecx, 32 + mov ecx, 32 .loop: - mov eax, MDIO_ENB or MDIO_DATA_WRITE1 - out dx, eax - MDIO_Delay + mov eax, MDIO_ENB or MDIO_DATA_WRITE1 + out dx, eax + MDIO_Delay - or eax, MDIO_SHIFT_CLK - out dx, eax - MDIO_Delay + or eax, MDIO_SHIFT_CLK + out dx, eax + MDIO_Delay - dec ecx - jnz .loop + dec ecx + jnz .loop ; Shift the read command bits out. - mov ecx, 1 shl 15 + mov ecx, 1 shl 15 .loop2: - mov eax, MDIO_ENB - test esi, ecx - jz @f - or eax, MDIO_DATA_WRITE1 + mov eax, MDIO_ENB + test esi, ecx + jz @f + or eax, MDIO_DATA_WRITE1 @@: - out dx, eax - MDIO_Delay + out dx, eax + MDIO_Delay - or eax, MDIO_SHIFT_CLK - out dx, eax - MDIO_Delay + or eax, MDIO_SHIFT_CLK + out dx, eax + MDIO_Delay - shr ecx, 1 - jnz .loop2 + shr ecx, 1 + jnz .loop2 ; Read the two transition, 16 data, and wire-idle bits. - xor esi, esi - mov ecx, 19 + xor esi, esi + mov ecx, 19 .loop3: - mov eax, MDIO_ENB_IN - out dx, eax - MDIO_Delay + mov eax, MDIO_ENB_IN + out dx, eax + MDIO_Delay - shl esi, 1 - in eax, dx - test eax, MDIO_DATA_READ - jz @f - inc esi + shl esi, 1 + in eax, dx + test eax, MDIO_DATA_READ + jz @f + inc esi @@: - mov eax, MDIO_ENB_IN or MDIO_SHIFT_CLK - out dx, eax - MDIO_Delay + mov eax, MDIO_ENB_IN or MDIO_SHIFT_CLK + out dx, eax + MDIO_Delay - dec ecx - jnz .loop3 + dec ecx + jnz .loop3 - shr esi, 1 - movzx eax, si + shr esi, 1 + movzx eax, si - DEBUGF 1,", data=%x\n", ax + DEBUGF 1,", data=%x\n", ax - ret + ret align 4 -mdio_write: ;int phy_id: edx, int location: edi, int value: ax) +mdio_write: ;int phy_id: edx, int location: edi, int value: ax) - DEBUGF 1,"mdio write, phy=%x, location=%x, data=%x\n", edx, edi, ax + DEBUGF 1,"mdio write, phy=%x, location=%x, data=%x\n", edx, edi, ax - shl edi, 18 - or edi, 0x5002 shl 16 - shl edx, 23 - or edi, edx - mov di, ax + shl edi, 18 + or edi, 0x5002 shl 16 + shl edx, 23 + or edi, edx + mov di, ax - set_io 0 - set_io CSR9 + set_io 0 + set_io CSR9 ; if (tp->chip_id == LC82C168) { ; int i = 1000; @@ -1643,69 +1642,69 @@ mdio_write: ;int phy_id: edx, int location: edi, int value: ax) ; Establish sync by sending at least 32 logic ones. - mov ecx, 32 + mov ecx, 32 .loop: - mov eax, MDIO_ENB or MDIO_DATA_WRITE1 - out dx, eax - MDIO_Delay + mov eax, MDIO_ENB or MDIO_DATA_WRITE1 + out dx, eax + MDIO_Delay - or eax, MDIO_SHIFT_CLK - out dx, eax - MDIO_Delay + or eax, MDIO_SHIFT_CLK + out dx, eax + MDIO_Delay - dec ecx - jnz .loop + dec ecx + jnz .loop ; Shift the command bits out. - mov ecx, 1 shl 31 + mov ecx, 1 shl 31 .loop2: - mov eax, MDIO_ENB - test edi, ecx - jz @f - or eax, MDIO_DATA_WRITE1 + mov eax, MDIO_ENB + test edi, ecx + jz @f + or eax, MDIO_DATA_WRITE1 @@: - out dx, eax - MDIO_Delay + out dx, eax + MDIO_Delay - or eax, MDIO_SHIFT_CLK - out dx, eax - MDIO_Delay + or eax, MDIO_SHIFT_CLK + out dx, eax + MDIO_Delay - shr ecx, 1 - jnz .loop2 + shr ecx, 1 + jnz .loop2 ; Clear out extra bits. - mov ecx, 2 + mov ecx, 2 .loop3: - mov eax, MDIO_ENB - out dx, eax - MDIO_Delay + mov eax, MDIO_ENB + out dx, eax + MDIO_Delay - or eax, MDIO_SHIFT_CLK - out dx, eax - MDIO_Delay + or eax, MDIO_SHIFT_CLK + out dx, eax + MDIO_Delay - dec ecx - jnz .loop3 + dec ecx + jnz .loop3 - ret + ret ; 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 'DEC21X4X',0 ; max 16 chars include zero +my_service db 'DEC21X4X',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 diff --git a/kernel/branches/net/drivers/mtd80x.asm b/kernel/branches/net/drivers/mtd80x.asm index 3ed653ea46..9eb24ec0c3 100644 --- a/kernel/branches/net/drivers/mtd80x.asm +++ b/kernel/branches/net/drivers/mtd80x.asm @@ -16,17 +16,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' @@ -40,198 +40,198 @@ public version ; for different PHY - MysonPHY equ 1 - AhdocPHY equ 2 - SeeqPHY equ 3 - MarvellPHY equ 4 - Myson981 equ 5 - LevelOnePHY equ 6 - OtherPHY equ 10 + MysonPHY equ 1 + AhdocPHY equ 2 + SeeqPHY equ 3 + MarvellPHY equ 4 + Myson981 equ 5 + LevelOnePHY equ 6 + OtherPHY equ 10 ; Offsets to the Command and Status Registers. - PAR0 equ 0x0 ; physical address 0-3 - PAR1 equ 0x04 ; physical address 4-5 - MAR0 equ 0x08 ; multicast address 0-3 - MAR1 equ 0x0C ; multicast address 4-7 - FAR0 equ 0x10 ; flow-control address 0-3 - FAR1 equ 0x14 ; flow-control address 4-5 - TCRRCR equ 0x18 ; receive & transmit configuration - BCR equ 0x1C ; bus command - TXPDR equ 0x20 ; transmit polling demand - RXPDR equ 0x24 ; receive polling demand - RXCWP equ 0x28 ; receive current word pointer - TXLBA equ 0x2C ; transmit list base address - RXLBA equ 0x30 ; receive list base address - ISR equ 0x34 ; interrupt status - IMR equ 0x38 ; interrupt mask - FTH equ 0x3C ; flow control high/low threshold - MANAGEMENT equ 0x40 ; bootrom/eeprom and mii management - TALLY equ 0x44 ; tally counters for crc and mpa - TSR equ 0x48 ; tally counter for transmit status - BMCRSR equ 0x4c ; basic mode control and status - PHYIDENTIFIER equ 0x50 ; phy identifier - ANARANLPAR equ 0x54 ; auto-negotiation advertisement and link partner ability - ANEROCR equ 0x58 ; auto-negotiation expansion and pci conf. - BPREMRPSR equ 0x5c ; bypass & receive error mask and phy status + PAR0 equ 0x0 ; physical address 0-3 + PAR1 equ 0x04 ; physical address 4-5 + MAR0 equ 0x08 ; multicast address 0-3 + MAR1 equ 0x0C ; multicast address 4-7 + FAR0 equ 0x10 ; flow-control address 0-3 + FAR1 equ 0x14 ; flow-control address 4-5 + TCRRCR equ 0x18 ; receive & transmit configuration + BCR equ 0x1C ; bus command + TXPDR equ 0x20 ; transmit polling demand + RXPDR equ 0x24 ; receive polling demand + RXCWP equ 0x28 ; receive current word pointer + TXLBA equ 0x2C ; transmit list base address + RXLBA equ 0x30 ; receive list base address + ISR equ 0x34 ; interrupt status + IMR equ 0x38 ; interrupt mask + FTH equ 0x3C ; flow control high/low threshold + MANAGEMENT equ 0x40 ; bootrom/eeprom and mii management + TALLY equ 0x44 ; tally counters for crc and mpa + TSR equ 0x48 ; tally counter for transmit status + BMCRSR equ 0x4c ; basic mode control and status + PHYIDENTIFIER equ 0x50 ; phy identifier + ANARANLPAR equ 0x54 ; auto-negotiation advertisement and link partner ability + ANEROCR equ 0x58 ; auto-negotiation expansion and pci conf. + BPREMRPSR equ 0x5c ; bypass & receive error mask and phy status ; Bits in the interrupt status/enable registers. - RFCON equ 0x00020000 ; receive flow control xon packet - RFCOFF equ 0x00010000 ; receive flow control xoff packet - LSCStatus equ 0x00008000 ; link status change - ANCStatus equ 0x00004000 ; autonegotiation completed - FBE equ 0x00002000 ; fatal bus error - FBEMask equ 0x00001800 ; mask bit12-11 - ParityErr equ 0x00000000 ; parity error - TargetErr equ 0x00001000 ; target abort - MasterErr equ 0x00000800 ; master error - TUNF equ 0x00000400 ; transmit underflow - ROVF equ 0x00000200 ; receive overflow - ETI equ 0x00000100 ; transmit early int - ERI equ 0x00000080 ; receive early int - CNTOVF equ 0x00000040 ; counter overflow - RBU equ 0x00000020 ; receive buffer unavailable - TBU equ 0x00000010 ; transmit buffer unavilable - TI equ 0x00000008 ; transmit interrupt - RI equ 0x00000004 ; receive interrupt - RxErr equ 0x00000002 ; receive error + RFCON equ 0x00020000 ; receive flow control xon packet + RFCOFF equ 0x00010000 ; receive flow control xoff packet + LSCStatus equ 0x00008000 ; link status change + ANCStatus equ 0x00004000 ; autonegotiation completed + FBE equ 0x00002000 ; fatal bus error + FBEMask equ 0x00001800 ; mask bit12-11 + ParityErr equ 0x00000000 ; parity error + TargetErr equ 0x00001000 ; target abort + MasterErr equ 0x00000800 ; master error + TUNF equ 0x00000400 ; transmit underflow + ROVF equ 0x00000200 ; receive overflow + ETI equ 0x00000100 ; transmit early int + ERI equ 0x00000080 ; receive early int + CNTOVF equ 0x00000040 ; counter overflow + RBU equ 0x00000020 ; receive buffer unavailable + TBU equ 0x00000010 ; transmit buffer unavilable + TI equ 0x00000008 ; transmit interrupt + RI equ 0x00000004 ; receive interrupt + RxErr equ 0x00000002 ; receive error ; Bits in the NetworkConfig register. - RxModeMask equ 0xe0 - AcceptAllPhys equ 0x80 ; promiscuous mode - AcceptBroadcast equ 0x40 ; accept broadcast - AcceptMulticast equ 0x20 ; accept mutlicast - AcceptRunt equ 0x08 ; receive runt pkt - ALP equ 0x04 ; receive long pkt - AcceptErr equ 0x02 ; receive error pkt + RxModeMask equ 0xe0 + AcceptAllPhys equ 0x80 ; promiscuous mode + AcceptBroadcast equ 0x40 ; accept broadcast + AcceptMulticast equ 0x20 ; accept mutlicast + AcceptRunt equ 0x08 ; receive runt pkt + ALP equ 0x04 ; receive long pkt + AcceptErr equ 0x02 ; receive error pkt - AcceptMyPhys equ 0x00000000 - RxEnable equ 0x00000001 - RxFlowCtrl equ 0x00002000 - TxEnable equ 0x00040000 - TxModeFDX equ 0x00100000 - TxThreshold equ 0x00e00000 + AcceptMyPhys equ 0x00000000 + RxEnable equ 0x00000001 + RxFlowCtrl equ 0x00002000 + TxEnable equ 0x00040000 + TxModeFDX equ 0x00100000 + TxThreshold equ 0x00e00000 - PS1000 equ 0x00010000 - PS10 equ 0x00080000 - FD equ 0x00100000 + PS1000 equ 0x00010000 + PS10 equ 0x00080000 + FD equ 0x00100000 ; Bits in network_desc.status - RXOWN equ 0x80000000 ; own bit - FLNGMASK equ 0x0fff0000 ; frame length - FLNGShift equ 16 - MARSTATUS equ 0x00004000 ; multicast address received - BARSTATUS equ 0x00002000 ; broadcast address received - PHYSTATUS equ 0x00001000 ; physical address received - RXFSD equ 0x00000800 ; first descriptor - RXLSD equ 0x00000400 ; last descriptor - ErrorSummary equ 0x80 ; error summary - RUNT equ 0x40 ; runt packet received - LONG equ 0x20 ; long packet received - FAE equ 0x10 ; frame align error - CRC equ 0x08 ; crc error - RXER equ 0x04 ; receive error + RXOWN equ 0x80000000 ; own bit + FLNGMASK equ 0x0fff0000 ; frame length + FLNGShift equ 16 + MARSTATUS equ 0x00004000 ; multicast address received + BARSTATUS equ 0x00002000 ; broadcast address received + PHYSTATUS equ 0x00001000 ; physical address received + RXFSD equ 0x00000800 ; first descriptor + RXLSD equ 0x00000400 ; last descriptor + ErrorSummary equ 0x80 ; error summary + RUNT equ 0x40 ; runt packet received + LONG equ 0x20 ; long packet received + FAE equ 0x10 ; frame align error + CRC equ 0x08 ; crc error + RXER equ 0x04 ; receive error ; rx_desc_control_bits - RXIC equ 0x00800000 ; interrupt control - RBSShift equ 0 + RXIC equ 0x00800000 ; interrupt control + RBSShift equ 0 ; tx_desc_status_bits - TXOWN equ 0x80000000 ; own bit - JABTO equ 0x00004000 ; jabber timeout - CSL equ 0x00002000 ; carrier sense lost - LC equ 0x00001000 ; late collision - EC equ 0x00000800 ; excessive collision - UDF equ 0x00000400 ; fifo underflow - DFR equ 0x00000200 ; deferred - HF equ 0x00000100 ; heartbeat fail - NCRMask equ 0x000000ff ; collision retry count - NCRShift equ 0 + TXOWN equ 0x80000000 ; own bit + JABTO equ 0x00004000 ; jabber timeout + CSL equ 0x00002000 ; carrier sense lost + LC equ 0x00001000 ; late collision + EC equ 0x00000800 ; excessive collision + UDF equ 0x00000400 ; fifo underflow + DFR equ 0x00000200 ; deferred + HF equ 0x00000100 ; heartbeat fail + NCRMask equ 0x000000ff ; collision retry count + NCRShift equ 0 ; tx_desc_control_bits - TXIC equ 0x80000000 ; interrupt control - ETIControl equ 0x40000000 ; early transmit interrupt - TXLD equ 0x20000000 ; last descriptor - TXFD equ 0x10000000 ; first descriptor - CRCEnable equ 0x08000000 ; crc control - PADEnable equ 0x04000000 ; padding control - RetryTxLC equ 0x02000000 ; retry late collision - PKTSMask equ 0x3ff800 ; packet size bit21-11 - PKTSShift equ 11 - TBSMask equ 0x000007ff ; transmit buffer bit 10-0 - TBSShift equ 0 + TXIC equ 0x80000000 ; interrupt control + ETIControl equ 0x40000000 ; early transmit interrupt + TXLD equ 0x20000000 ; last descriptor + TXFD equ 0x10000000 ; first descriptor + CRCEnable equ 0x08000000 ; crc control + PADEnable equ 0x04000000 ; padding control + RetryTxLC equ 0x02000000 ; retry late collision + PKTSMask equ 0x3ff800 ; packet size bit21-11 + PKTSShift equ 11 + TBSMask equ 0x000007ff ; transmit buffer bit 10-0 + TBSShift equ 0 ; BootROM/EEPROM/MII Management Register - MASK_MIIR_MII_READ equ 0x00000000 + MASK_MIIR_MII_READ equ 0x00000000 MASK_MIIR_MII_WRITE equ 0x00000008 - MASK_MIIR_MII_MDO equ 0x00000004 - MASK_MIIR_MII_MDI equ 0x00000002 - MASK_MIIR_MII_MDC equ 0x00000001 + MASK_MIIR_MII_MDO equ 0x00000004 + MASK_MIIR_MII_MDI equ 0x00000002 + MASK_MIIR_MII_MDC equ 0x00000001 ; ST+OP+PHYAD+REGAD+TA - OP_READ equ 0x6000 ; ST:01+OP:10+PHYAD+REGAD+TA:Z0 - OP_WRITE equ 0x5002 ; ST:01+OP:01+PHYAD+REGAD+TA:10 + OP_READ equ 0x6000 ; ST:01+OP:10+PHYAD+REGAD+TA:Z0 + OP_WRITE equ 0x5002 ; ST:01+OP:01+PHYAD+REGAD+TA:10 ; ------------------------------------------------------------------------- ; Constants for Myson PHY ; ------------------------------------------------------------------------- - MysonPHYID equ 0xd0000302 - MysonPHYID0 equ 0x0302 - StatusRegister equ 18 - SPEED100 equ 0x0400 ; bit10 - FULLMODE equ 0x0800 ; bit11 + MysonPHYID equ 0xd0000302 + MysonPHYID0 equ 0x0302 + StatusRegister equ 18 + SPEED100 equ 0x0400 ; bit10 + FULLMODE equ 0x0800 ; bit11 ; ------------------------------------------------------------------------- ; Constants for Seeq 80225 PHY ; ------------------------------------------------------------------------- - SeeqPHYID0 equ 0x0016 - MIIRegister18 equ 18 - SPD_DET_100 equ 0x80 - DPLX_DET_FULL equ 0x40 + SeeqPHYID0 equ 0x0016 + MIIRegister18 equ 18 + SPD_DET_100 equ 0x80 + DPLX_DET_FULL equ 0x40 ; ------------------------------------------------------------------------- ; Constants for Ahdoc 101 PHY ; ------------------------------------------------------------------------- - AhdocPHYID0 equ 0x0022 - DiagnosticReg equ 18 - DPLX_FULL equ 0x0800 - Speed_100 equ 0x0400 + AhdocPHYID0 equ 0x0022 + DiagnosticReg equ 18 + DPLX_FULL equ 0x0800 + Speed_100 equ 0x0400 ; -------------------------------------------------------------------------- ; Constants ; -------------------------------------------------------------------------- - MarvellPHYID0 equ 0x0141 - LevelOnePHYID0 equ 0x0013 + MarvellPHYID0 equ 0x0141 + LevelOnePHYID0 equ 0x0013 - MII1000BaseTControlReg equ 9 - MII1000BaseTStatusReg equ 10 - SpecificReg equ 17 + MII1000BaseTControlReg equ 9 + MII1000BaseTStatusReg equ 10 + SpecificReg equ 17 ; for 1000BaseT Control Register PHYAbletoPerform1000FullDuplex equ 0x0200 PHYAbletoPerform1000HalfDuplex equ 0x0100 - PHY1000AbilityMask equ 0x300 + PHY1000AbilityMask equ 0x300 ; for phy specific status register, marvell phy. - SpeedMask equ 0x0c000 + SpeedMask equ 0x0c000 Speed_1000M equ 0x08000 - Speed_100M equ 0x4000 - Speed_10M equ 0 + Speed_100M equ 0x4000 + Speed_10M equ 0 Full_Duplex equ 0x2000 ; for phy specific status register, levelone phy @@ -242,67 +242,67 @@ public version ; for PHY - LinkIsUp equ 0x0004 - LinkIsUp2 equ 0x00040000 + LinkIsUp equ 0x0004 + LinkIsUp2 equ 0x00040000 virtual at 0 - mtd_desc: - .status dd ? - .control dd ? - .buffer dd ? - .next_desc dd ? + mtd_desc: + .status dd ? + .control dd ? + .buffer dd ? + .next_desc dd ? - .next_desc_logical dd ? - .skbuff dd ? + .next_desc_logical dd ? + .skbuff dd ? - .reserved1 dd ? - .reserved2 dd ? + .reserved1 dd ? + .reserved2 dd ? - .size = $ + .size = $ end virtual virtual at ebx - device: + device: - ETH_DEVICE + ETH_DEVICE - .tx_desc rb NUM_TX_DESC*mtd_desc.size - .rx_desc rb NUM_RX_DESC*mtd_desc.size + .tx_desc rb NUM_TX_DESC*mtd_desc.size + .rx_desc rb NUM_RX_DESC*mtd_desc.size - .io_addr dd ? - .pci_bus db ? - .pci_dev db ? - .irq_line db ? - .dev_id dw ? + .io_addr dd ? + .pci_bus db ? + .pci_dev db ? + .irq_line db ? + .dev_id dw ? - .flags dd ? + .flags dd ? - .crvalue dd ? - .bcrvalue dd ? + .crvalue dd ? + .bcrvalue dd ? - .cur_rx dd ? - .cur_tx dd ? + .cur_rx dd ? + .cur_tx dd ? ; These values are keep track of the transceiver/media in use. - .linkok dd ? - .line_speed dd ? - .duplexmode dd ? - .default_port dd ? - .PHYType dd ? + .linkok dd ? + .line_speed dd ? + .duplexmode dd ? + .default_port dd ? + .PHYType dd ? ; MII transceiver section. - .mii_cnt dd ? ; MII device addresses. - .phys db ? ; MII device addresses. + .mii_cnt dd ? ; MII device addresses. + .phys db ? ; MII device addresses. - device_size = $ - device + device_size = $ - device end virtual @@ -320,19 +320,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 mtd80x driver\n" - stdcall RegService, my_service, service_proc - ret + DEBUGF 2,"Loading mtd80x driver\n" + stdcall RegService, my_service, service_proc + ret .fail: .exit: - xor eax, eax - ret + xor eax, eax + ret endp @@ -347,128 +347,127 @@ 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_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 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" + 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 @@ -484,9 +483,9 @@ endp align 4 unload: - ; TODO: (in this particular order) - ; - ; - Stop the device + ; TODO: (in this particular order) + ; + ; - Stop the device ; /* Disable Tx Rx*/ ; outl( mtdx.crvalue & (~TxEnable) & (~RxEnable), mtdx.ioaddr + TCRRCR ); @@ -494,12 +493,12 @@ unload: ; /* Reset the chip to erase previous misconfiguration. */ ; mtd_reset(nic); - ; - Detach int handler - ; - Remove device from local list (device_list) - ; - call unregister function in kernel - ; - Remove all allocated structures and buffers the card used + ; - 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 @@ -512,58 +511,58 @@ ret align 4 probe: - DEBUGF 2,"Probing mtd80x device\n" + DEBUGF 2,"Probing mtd80x device\n" - make_bus_master [device.pci_bus], [device.pci_dev] + make_bus_master [device.pci_bus], [device.pci_dev] - movzx eax, [device.pci_bus] - movzx ecx, [device.pci_dev] - stdcall PciRead32, eax ,ecx ,0 + movzx eax, [device.pci_bus] + movzx ecx, [device.pci_dev] + stdcall PciRead32, eax ,ecx ,0 - cmp ax , 0x1516 - jne .notfound - shr eax, 16 - mov [device.dev_id], ax + cmp ax , 0x1516 + jne .notfound + shr eax, 16 + mov [device.dev_id], ax - cmp ax, 0x0800 - je .has_mii_xcvr + cmp ax, 0x0800 + je .has_mii_xcvr - cmp ax, 0x0803 - je .has_chip_xcvr + cmp ax, 0x0803 + je .has_chip_xcvr - cmp ax, 0x0891 - je .has_mii_xcvr + cmp ax, 0x0891 + je .has_mii_xcvr .notfound: - DEBUGF 1,"Device not supported!\n" - xor eax, eax - dec eax - ret + DEBUGF 1,"Device not supported!\n" + xor eax, eax + dec eax + ret .has_chip_xcvr: - DEBUGF 1,"Device has chip xcvr\n" + DEBUGF 1,"Device has chip xcvr\n" - jmp .xcvr_set + jmp .xcvr_set .has_mii_xcvr: - DEBUGF 1,"Device has mii xcvr\n" + DEBUGF 1,"Device has mii xcvr\n" .xcvr_set: - call read_mac + call read_mac ; Reset the chip to erase previous misconfiguration. - set_io 0 - set_io BCR - xor eax, eax - inc eax - out dx, eax + set_io 0 + set_io BCR + xor eax, eax + inc eax + out dx, eax ; find the connected MII xcvrs - cmp [device.dev_id], 0x0803 - je .is_803 + cmp [device.dev_id], 0x0803 + je .is_803 ; int phy, phy_idx equ 0; ; @@ -603,27 +602,27 @@ probe: ; "not operate correctly.\n", mtdx.nic_name); ; } - jmp .no_803 + jmp .no_803 .is_803: - mov [device.phys], 32 + mov [device.phys], 32 ; get phy type - set_io 0 - set_io PHYIDENTIFIER - in eax, dx + set_io 0 + set_io PHYIDENTIFIER + in eax, dx - cmp eax, MysonPHYID - jne @f + cmp eax, MysonPHYID + jne @f - mov [device.PHYType], MysonPHY - DEBUGF 1,"MysonPHY\n" - jmp .no_803 + mov [device.PHYType], MysonPHY + DEBUGF 1,"MysonPHY\n" + jmp .no_803 @@: - mov [device.PHYType], OtherPHY - DEBUGF 1,"OtherPHY\n" + mov [device.PHYType], OtherPHY + DEBUGF 1,"OtherPHY\n" .no_803: @@ -635,88 +634,88 @@ probe: align 4 reset: - DEBUGF 1,"Resetting mtd80x\n" + DEBUGF 1,"Resetting mtd80x\n" ;-------------------------------- ; insert irq handler on given irq - 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 @@: ; Reset the chip to erase previous misconfiguration. - set_io 0 - set_io BCR - xor eax, eax - inc eax - out dx, eax + set_io 0 + set_io BCR + xor eax, eax + inc eax + out dx, eax - call init_ring + call init_ring ; Initialize other registers. ; Configure the PCI bus bursts and FIFO thresholds. - mov [device.bcrvalue], 0x10 ; little-endian, 8 burst length - mov [device.crvalue], 0xa00 ; 128 burst length + mov [device.bcrvalue], 0x10 ; little-endian, 8 burst length + mov [device.crvalue], 0xa00 ; 128 burst length - cmp [device.dev_id], 0x891 - jne @f - or [device.bcrvalue], 0x200 ; set PROG bit - or [device.crvalue], 0x02000000 ; set enhanced bit + cmp [device.dev_id], 0x891 + jne @f + or [device.bcrvalue], 0x200 ; set PROG bit + or [device.crvalue], 0x02000000 ; set enhanced bit @@: - or [device.crvalue], RxEnable + TxThreshold + TxEnable + or [device.crvalue], RxEnable + TxThreshold + TxEnable - call set_rx_mode + call set_rx_mode - set_io 0 - set_io BCR - mov eax, [device.bcrvalue] - out dx, eax + set_io 0 + set_io BCR + mov eax, [device.bcrvalue] + out dx, eax - set_io TCRRCR - mov eax, [device.crvalue] - out dx, eax + set_io TCRRCR + mov eax, [device.crvalue] + out dx, eax - call getlinkstatus - call getlinktype + call getlinkstatus + call getlinktype ; Restart Rx engine if stopped. - set_io 0 - set_io RXPDR - xor eax, eax - out dx, eax + set_io 0 + set_io RXPDR + xor eax, eax + out dx, eax ; Enable interrupts - set_io 0 - set_io ISR - mov eax, (FBE or TUNF or CNTOVF or RBU or TI or RI) - out dx, eax + set_io 0 + set_io ISR + mov eax, (FBE or TUNF or CNTOVF or RBU or TI or RI) + out dx, eax - set_io IMR + set_io IMR ; mov eax, (FBE or TUNF or CNTOVF or RBU or TI or RI) - out dx, eax + out dx, eax ; 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], 1514 - xor eax, eax + mov [device.mtu], 1514 + xor eax, eax - ret + ret @@ -724,127 +723,127 @@ reset: align 4 init_ring: - DEBUGF 1,"initializing rx and tx ring\n" + DEBUGF 1,"initializing rx and tx ring\n" ; Initialize all Rx descriptors - lea esi, [device.rx_desc] - mov [device.cur_rx], esi - mov ecx, NUM_RX_DESC + lea esi, [device.rx_desc] + mov [device.cur_rx], esi + mov ecx, NUM_RX_DESC .rx_desc_loop: - mov [esi + mtd_desc.status], RXOWN - mov [esi + mtd_desc.control], 1536 shl RBSShift + mov [esi + mtd_desc.status], RXOWN + mov [esi + mtd_desc.control], 1536 shl RBSShift - lea eax, [esi + mtd_desc.size] - mov [esi + mtd_desc.next_desc_logical], eax - push ecx esi - GetRealAddr - mov [esi + mtd_desc.next_desc], eax + lea eax, [esi + mtd_desc.size] + mov [esi + mtd_desc.next_desc_logical], eax + push ecx esi + GetRealAddr + mov [esi + mtd_desc.next_desc], eax - stdcall KernelAlloc, 1536 - pop esi - push esi - mov [esi + mtd_desc.skbuff], eax - call GetPgAddr - pop esi ecx - mov [esi + mtd_desc.buffer], eax + stdcall KernelAlloc, 1536 + pop esi + push esi + mov [esi + mtd_desc.skbuff], eax + call GetPgAddr + pop esi ecx + mov [esi + mtd_desc.buffer], eax - add esi, mtd_desc.size - loop .rx_desc_loop + add esi, mtd_desc.size + loop .rx_desc_loop ; Mark the last entry as wrapping the ring. - lea eax, [device.rx_desc] - mov [esi - mtd_desc.size + mtd_desc.next_desc_logical], eax - push esi - GetRealAddr - pop esi - mov [esi - mtd_desc.size + mtd_desc.next_desc], eax + lea eax, [device.rx_desc] + mov [esi - mtd_desc.size + mtd_desc.next_desc_logical], eax + push esi + GetRealAddr + pop esi + mov [esi - mtd_desc.size + mtd_desc.next_desc], eax - set_io 0 - set_io RXLBA - out dx, eax + set_io 0 + set_io RXLBA + out dx, eax ; Initialize all Tx descriptors - lea esi, [device.tx_desc] - mov [device.cur_tx], esi - mov ecx, NUM_TX_DESC + lea esi, [device.tx_desc] + mov [device.cur_tx], esi + mov ecx, NUM_TX_DESC .tx_desc_loop: - mov [esi + mtd_desc.status], 0 + mov [esi + mtd_desc.status], 0 - lea eax, [esi + mtd_desc.size] - mov [esi + mtd_desc.next_desc_logical], eax - push ecx esi - GetRealAddr - pop esi ecx - mov [esi + mtd_desc.next_desc], eax + lea eax, [esi + mtd_desc.size] + mov [esi + mtd_desc.next_desc_logical], eax + push ecx esi + GetRealAddr + pop esi ecx + mov [esi + mtd_desc.next_desc], eax - add esi, mtd_desc.size - loop .tx_desc_loop + add esi, mtd_desc.size + loop .tx_desc_loop ; Mark the last entry as wrapping the ring. - lea eax, [device.tx_desc] - mov [esi - mtd_desc.size + mtd_desc.next_desc_logical], eax - push esi - GetRealAddr - pop esi - mov [esi - mtd_desc.size + mtd_desc.next_desc], eax + lea eax, [device.tx_desc] + mov [esi - mtd_desc.size + mtd_desc.next_desc_logical], eax + push esi + GetRealAddr + pop esi + mov [esi - mtd_desc.size + mtd_desc.next_desc], eax - set_io 0 - set_io TXLBA - out dx, eax + set_io 0 + set_io TXLBA + out dx, eax - ret + ret align 4 set_rx_mode: - DEBUGF 1,"Setting RX mode\n" + DEBUGF 1,"Setting RX mode\n" ; Too many to match, or accept all multicasts. - set_io 0 - set_io MAR0 - xor eax, eax - not eax - out dx, eax - set_io MAR1 - out dx, eax + set_io 0 + set_io MAR0 + xor eax, eax + not eax + out dx, eax + set_io MAR1 + out dx, eax - and [device.crvalue], not (RxModeMask) - or [device.crvalue], AcceptBroadcast + AcceptMulticast + AcceptMyPhys + and [device.crvalue], not (RxModeMask) + or [device.crvalue], AcceptBroadcast + AcceptMulticast + AcceptMyPhys - ret + ret align 4 getlinkstatus: - DEBUGF 1,"Getting link status\n" + DEBUGF 1,"Getting link status\n" - mov [device.linkok], 0 + mov [device.linkok], 0 - cmp [device.PHYType], MysonPHY - jne .no_myson_phy + cmp [device.PHYType], MysonPHY + jne .no_myson_phy - set_io 0 - set_io BMCRSR - mov ecx, 1000 + set_io 0 + set_io BMCRSR + mov ecx, 1000 .loop1: - in eax, dx - test eax, LinkIsUp2 - jnz .link_ok + in eax, dx + test eax, LinkIsUp2 + jnz .link_ok - push ecx edx ebx - mov esi, 10 - call Sleep - pop ebx edx ecx - loop .loop1 + push ecx edx ebx + mov esi, 10 + call Sleep + pop ebx edx ecx + loop .loop1 - ret + ret .no_myson_phy: @@ -855,12 +854,12 @@ getlinkstatus: ; } ; m80x_delay(100); - ret + ret .link_ok: - DEBUGF 1,"Link is up\n" - inc [device.linkok] - ret + DEBUGF 1,"Link is up\n" + inc [device.linkok] + ret @@ -868,36 +867,36 @@ getlinkstatus: align 4 getlinktype: - DEBUGF 1,"Getting link type\n" + DEBUGF 1,"Getting link type\n" - cmp [device.PHYType], MysonPHY - jne .no_myson_phy + cmp [device.PHYType], MysonPHY + jne .no_myson_phy - DEBUGF 1,"myson PHY\n" + DEBUGF 1,"myson PHY\n" - set_io 0 - set_io TCRRCR - in eax, dx + set_io 0 + set_io TCRRCR + in eax, dx - mov [device.duplexmode], 1 ; 1 equ half duplex - test eax, FD - jne @f - DEBUGF 1,"full duplex\n" - inc [device.duplexmode] ; 2 equ full duplex + mov [device.duplexmode], 1 ; 1 equ half duplex + test eax, FD + jne @f + DEBUGF 1,"full duplex\n" + inc [device.duplexmode] ; 2 equ full duplex @@: - mov [device.line_speed], 1 ; 1 equ 10M - test eax, PS10 - jne @f - DEBUGF 1,"100mbit\n" - inc [device.line_speed] ; 2 equ 100M + mov [device.line_speed], 1 ; 1 equ 10M + test eax, PS10 + jne @f + DEBUGF 1,"100mbit\n" + inc [device.line_speed] ; 2 equ 100M @@: - ret + ret .no_myson_phy: - DEBUGF 1,"no myson phy\n" + DEBUGF 1,"no myson phy\n" ; if (mtdx.PHYType equequ SeeqPHY) { /* this PHY is SEEQ 80225 */ ; unsigned int data; @@ -983,7 +982,7 @@ getlinktype: ; mtdx.crvalue |equ FD; ; - ret + ret @@ -1001,49 +1000,49 @@ getlinktype: 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 - ja .fail + cmp dword [esp+8], 1514 + ja .fail - mov esi, [device.cur_tx] - push [esi + mtd_desc.next_desc_logical] - pop [device.cur_tx] + mov esi, [device.cur_tx] + push [esi + mtd_desc.next_desc_logical] + pop [device.cur_tx] - ; todo: check if descriptor is not owned by the device! + ; todo: check if descriptor is not owned by the device! - mov eax, [esp + 4] - mov [esi + mtd_desc.skbuff], eax - GetRealAddr - mov [esi + mtd_desc.buffer], eax + mov eax, [esp + 4] + mov [esi + mtd_desc.skbuff], eax + GetRealAddr + mov [esi + mtd_desc.buffer], eax - mov eax, [esp + 8] - shl eax, PKTSShift ; packet size - or eax, TXLD + TXFD + CRCEnable + PADEnable + TXIC + 1536 shl TBSShift ; buffer size - mov [esi + mtd_desc.control], eax + mov eax, [esp + 8] + shl eax, PKTSShift ; packet size + or eax, TXLD + TXFD + CRCEnable + PADEnable + TXIC + 1536 shl TBSShift ; buffer size + mov [esi + mtd_desc.control], eax - mov [esi + mtd_desc.status], TXOWN + mov [esi + mtd_desc.status], TXOWN ;------------- ; 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 ; Point to transmit descriptor - set_io 0 - set_io TXLBA - mov eax, esi - GetRealAddr - out dx, eax + set_io 0 + set_io TXLBA + mov eax, esi + GetRealAddr + out dx, eax ; set_io TCRRCR ; mov eax, [device.crvalue] @@ -1051,43 +1050,43 @@ transmit: ; Wake the potentially-idle transmit channel. - set_io TXPDR ; TX Poll - xor eax, eax - out dx, eax + set_io TXPDR ; TX Poll + xor eax, eax + out dx, eax - DEBUGF 1,"transmit ok\n" - xor eax, eax - ret 8 + DEBUGF 1,"transmit ok\n" + 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 align 4 read_mac: - set_io 0 - set_io PAR0 - lea edi, [device.mac] - insd - stosd - set_io PAR1 - insw - stosw + set_io 0 + set_io PAR0 + lea edi, [device.mac] + insd + stosd + set_io PAR1 + insw + stosw - 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 + ret @@ -1100,84 +1099,84 @@ write_mac: 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 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 ISR - in eax, dx - out dx , eax ; send it back to ACK + set_io 0 + set_io ISR + in eax, dx + out dx , eax ; send it back to ACK ; and eax, ; int mask - test eax, eax - jnz .got_it + test eax, eax + 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,"Status=%x\n", eax + DEBUGF 1,"Status=%x\n", eax - test ax, RI ; receive interrupt - jz .no_rx + test ax, RI ; receive interrupt + jz .no_rx - DEBUGF 1,"Receive interrupt\n" + DEBUGF 1,"Receive interrupt\n" .rx: - push ax + push ax .rx_loop: - mov esi, [device.cur_rx] + mov esi, [device.cur_rx] - test [esi + mtd_desc.status], RXOWN - jnz .fail_rx + test [esi + mtd_desc.status], RXOWN + jnz .fail_rx - push .rx_complete + push .rx_complete - mov ecx, [esi + mtd_desc.status] - shr ecx, FLNGShift - sub ecx, 4 ; we dont need CRC - push ecx + mov ecx, [esi + mtd_desc.status] + shr ecx, FLNGShift + sub ecx, 4 ; we dont need CRC + push ecx ;------------- ; 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] - push [esi + mtd_desc.skbuff] + push [esi + mtd_desc.skbuff] - jmp EthReceiver + jmp EthReceiver .rx_complete: - mov esi, [device.cur_rx] + mov esi, [device.cur_rx] - mov [esi + mtd_desc.control], 1536 shl RBSShift + mov [esi + mtd_desc.control], 1536 shl RBSShift - stdcall KernelAlloc, 1536 - mov [esi + mtd_desc.skbuff], eax - call GetPgAddr - mov [esi + mtd_desc.buffer], eax + stdcall KernelAlloc, 1536 + mov [esi + mtd_desc.skbuff], eax + call GetPgAddr + mov [esi + mtd_desc.buffer], eax - mov [esi + mtd_desc.status], RXOWN + mov [esi + mtd_desc.status], RXOWN - mov eax, [esi + mtd_desc.next_desc_logical] - mov [device.cur_rx], eax + mov eax, [esi + mtd_desc.next_desc_logical] + mov [device.cur_rx], eax - jmp .rx_loop + jmp .rx_loop ; ; while( ( mtdx.cur_rx->status & RXOWN ) == 0 ) ; { @@ -1189,60 +1188,60 @@ int_handler: ; outl(0, mtdx.ioaddr + RXPDR); .fail_rx: - DEBUGF 1,"RX failed\n" + DEBUGF 1,"RX failed\n" - pop ax + pop ax .no_rx: - test ax, TI ; transmit interrupt - jz .no_tx + test ax, TI ; transmit interrupt + jz .no_tx - DEBUGF 1,"Transmit interrupt\n" - push ax + DEBUGF 1,"Transmit interrupt\n" + push ax - lea esi, [device.tx_desc] - mov ecx, NUM_TX_DESC + lea esi, [device.tx_desc] + mov ecx, NUM_TX_DESC .tx_loop: - test [esi + mtd_desc.status], TXOWN - jnz .skip_this_one + test [esi + mtd_desc.status], TXOWN + jnz .skip_this_one - mov eax, [esi + mtd_desc.skbuff] - test eax, eax - je .skip_this_one + mov eax, [esi + mtd_desc.skbuff] + test eax, eax + je .skip_this_one - mov [esi + mtd_desc.skbuff], 0 + mov [esi + mtd_desc.skbuff], 0 - DEBUGF 1,"freeing buffer:%x\n", eax - stdcall KernelFree, eax + DEBUGF 1,"freeing buffer:%x\n", eax + stdcall KernelFree, eax .skip_this_one: - mov esi, [esi + mtd_desc.next_desc_logical] - loop .tx_loop + mov esi, [esi + mtd_desc.next_desc_logical] + loop .tx_loop - pop ax + pop ax .no_tx: - test ax, TBU - jz .no_tbu + test ax, TBU + jz .no_tbu - DEBUGF 1,"Transmit buffer unavailable!\n" + DEBUGF 1,"Transmit buffer unavailable!\n" .no_tbu: .fail: - ret + ret ; 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 'mtd80x',0 ; max 16 chars include zero +my_service db 'mtd80x',0 ; max 16 chars include zero ; 0x1516, 0x0800, "MTD800", "Myson MTD800" @@ -1250,10 +1249,10 @@ my_service db 'mtd80x',0 ; max 16 chars include zero ; 0x1516, 0x0891, "MTD891", "Myson MTD891" -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 302eb1080a..7afdd35625 100644 --- a/kernel/branches/net/drivers/pcnet32.asm +++ b/kernel/branches/net/drivers/pcnet32.asm @@ -491,7 +491,6 @@ proc service_proc stdcall, ioctl:dword .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 diff --git a/kernel/branches/net/drivers/sis900.asm b/kernel/branches/net/drivers/sis900.asm index 09f28c91cb..02cc3a95f8 100644 --- a/kernel/branches/net/drivers/sis900.asm +++ b/kernel/branches/net/drivers/sis900.asm @@ -214,7 +214,6 @@ service_proc: ; 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