home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / packetdrivers.tar.gz / pd.tar / src / hppclanp.asm < prev    next >
Assembly Source File  |  1995-06-25  |  13KB  |  644 lines

  1. PAGE ,132
  2. version    equ    2
  3. ;History:83,1
  4.  
  5. ;  Russell Nelson, Clarkson University.
  6. ;  Copyright, 1988-1991, Russell Nelson
  7. ;  The following people have contributed to this code: David Horne, Eric
  8. ;  Henderson, and Bob Clements.
  9.  
  10. ;   This program is free software; you can redistribute it and/or modify
  11. ;   it under the terms of the GNU General Public License as published by
  12. ;   the Free Software Foundation, version 1.
  13. ;
  14. ;   This program is distributed in the hope that it will be useful,
  15. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ;   GNU General Public License for more details.
  18. ;
  19. ;   You should have received a copy of the GNU General Public License
  20. ;   along with this program; if not, write to the Free Software
  21. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23.     include    defs.asm
  24.  
  25.     .286
  26.  
  27. code    segment    word public
  28.     assume    cs:code, ds:code
  29.  
  30. ;*****************************************************************************
  31. ;
  32. ;    hppclan controller board offsets
  33. ;    IO port definition (BASE in io_addr)
  34. ;*****************************************************************************
  35. HP_ID    equ    00h
  36. PAGING    equ    02h
  37. OPTION    equ    04h
  38. PAGE_0    equ    08h
  39. PAGE_2    equ    0ah
  40. PAGE_4    equ    0ch
  41. PAGE_6    equ    0eh
  42. ;the following is needed for 8390.
  43. EN_OFF        equ    10h
  44.  
  45. ;OPTION bit definitions from the ERS:
  46. MMap_Dis    equ    1000h
  47. Zero_Wait_En    equ    0080h
  48. Mem_En        equ    0040h
  49. IO_En        equ    0020h
  50. Boot_Rom_En    equ    0010h
  51. Fake_Int    equ    0008h
  52. En_Int        equ    0004h
  53. HW_Rst        equ    0002h
  54. NIC_Rst        equ    0001h
  55.  
  56. ;PAGING definitions from the ERS:
  57. Perf_page    equ    0
  58. MAC_Page    equ    1
  59. HW_page        equ    2
  60. Lan_Page    equ    4
  61. ID_Page        equ    6
  62.  
  63.     include    8390.inc
  64.  
  65. ; Shared memory management parameters
  66.  
  67. SM_TSTART_PG    EQU    0h        ; First page of TX buffer
  68. SM_RSTART_PG    EQU    6h        ; start at page 6
  69.   ifndef debugxx
  70. SM_RSTOP_PG    EQU    080h
  71.   else
  72. ;Make problems occur sooner and faster by having a smaller ring
  73. ;- gft - 910618
  74. SM_RSTOP_PG    EQU    1fh
  75.   endif
  76.  
  77. pause_    macro
  78. ; The reason for the pause_ macro is to establish a minimum time between
  79. ; accesses to the card hardware.  However, the Starfighter hardware inserts
  80. ; its own delays, which is much more reliable than any software hack.
  81.     endm
  82.  
  83. reset_8390    macro
  84.     loadport
  85.     setport    OPTION            ;hard reset 8390.
  86.     in    ax,dx
  87.     and    ax,not (NIC_Rst or HW_Rst)    ;reset the 8390
  88.     out    dx,ax
  89.     longpause
  90.     or    al,En_Int or NIC_Rst or HW_Rst    ;unreset it.
  91.     out    dx,al
  92.     endm
  93.  
  94. terminate_board    macro
  95.     loadport
  96.     setport    OPTION
  97.     in    ax,dx
  98.     or    ax,MMap_Dis or NIC_Rst or HW_Rst
  99.     and    ax,not En_Int
  100.     out    dx,ax
  101.     endm
  102.  
  103.     extrn    set_recv_isr: near
  104.  
  105. ;enter with si -> argument string, di -> word to store.
  106. ;if there is no number, don't change the number.
  107.     extrn    get_number: near
  108.  
  109. ;enter with dx -> name of word, di -> dword to print.
  110.     extrn    print_number: near
  111.  
  112. ;enter with al = single character
  113.     extrn    chrout: near
  114.  
  115.     extrn    is_386: byte        ;=0 if 80[12]8[68], =1 if 80[34]86.
  116.  
  117.     public    int_no, io_addr
  118. int_no        db    ?,0,0,0        ;must be four bytes long for print_number.
  119. io_addr        dw    -1,-1        ; I/O address for card (jumpers)
  120. mem_addr    dw    ?,0
  121. memory_mapped    db    0
  122.  
  123.     public    driver_class, driver_type, driver_name, driver_function, parameter_list
  124. driver_class    db    BLUEBOOK, IEEE8023, 0        ;from the packet spec
  125. driver_type    db    60        ;Wild card matches any type
  126. driver_name    db    "HPPCLANP",0    ;name of the driver.
  127. driver_function    db    2
  128. parameter_list    label    byte
  129.     db    1    ;major rev of packet driver
  130.     db    9    ;minor rev of packet driver
  131.     db    14    ;length of parameter list
  132.     db    EADDR_LEN    ;length of MAC-layer address
  133.     dw    GIANT    ;MTU, including MAC headers
  134.     dw    MAX_MULTICAST * EADDR_LEN    ;buffer size of multicast addrs
  135.     dw    0    ;(# of back-to-back MTU rcvs) - 1
  136.     dw    0    ;(# of successive xmits) - 1
  137. int_num    dw    0    ;Interrupt # to hook for post-EOI
  138.             ;processing, 0 == none,
  139.  
  140. block_input_ptr        dw    ?
  141. block_output_ptr    dw    ?
  142.  
  143. ;    Block input routine
  144. ;    CX = byte count, es:si = buffer location, ax = buffer address
  145.  
  146.     public    block_input
  147. block_input:
  148.     loadport
  149.     setport    PAGE_2        ;set the read address.
  150.     out    dx,ax
  151.  
  152.     setport    PAGE_4
  153.     jmp    block_input_ptr
  154.  
  155. io_input_286:
  156.     shr    cx,1
  157.     rep    insw
  158.     jnc    read_done
  159.     insb
  160. read_done:
  161.     ret
  162.  
  163. io_input_386:
  164.     .386
  165.     push    eax
  166.     push    cx            ;first, get all the full words.
  167.     shr    cx,2
  168.     rep    insd
  169.     pop    cx
  170.     in    eax,dx            ;then, get the partial word.
  171.     test    cx,2
  172.     je    block_input_386_one_word
  173.     stosw
  174.     shr    eax,16
  175. block_input_386_one_word:
  176.  
  177.     test    cx,1
  178.     je    block_input_386_one_byte
  179.     stosb
  180. block_input_386_one_byte:
  181.     pop    eax
  182.     ret
  183.     .286
  184.  
  185. mem_input_286:
  186.     loadport
  187.     setport    OPTION
  188.     in    ax,dx
  189.     push    ax            ;save original contents.
  190.     and    ax,not (MMap_Dis or Boot_Rom_En)    ;turn off boot rom, memory on.
  191.     out    dx,ax
  192.  
  193.     push    ds
  194.     mov    ds,mem_addr
  195.     mov    si,0
  196.     shr    cx,1
  197.     rep    movsw
  198.     jnc    mem_input_286_1
  199.     movsb
  200. mem_input_286_1:
  201.     pop    ds
  202.     pop    ax            ;restore OPTION register.
  203.     out    dx,ax
  204.     ret
  205.  
  206. mem_input_386:
  207. ;transfer all complete dwords.
  208.     .386
  209.     loadport
  210.     setport    OPTION
  211.     in    ax,dx
  212.     push    eax            ;save original contents.
  213.     and    ax,not (MMap_Dis or Boot_Rom_En)    ;turn off boot rom, memory on.
  214.     out    dx,ax
  215.  
  216.     push    ds
  217.     mov    ds,mem_addr
  218.     mov    si,0
  219.     push    cx
  220.     shr    cx,2            ; convert byte count to dword count
  221.     rep    movsd
  222.     pop    cx
  223.  
  224. ;now take take of any trailing words and/or bytes.
  225.     lodsd
  226.  
  227.     test    cx,2
  228.     je    movemem_386_one_word
  229.     stosw
  230.     shr    eax,16
  231. movemem_386_one_word:
  232.  
  233.     test    cx,1
  234.     je    movemem_386_one_byte
  235.     stosb
  236. movemem_386_one_byte:
  237.     pop    ds
  238.     pop    eax            ;restore OPTION register.
  239.     out    dx,ax
  240.     ret
  241.     .286
  242.  
  243.  
  244. ;
  245. ;    Block output routine
  246. ;    CX = byte count, ds:si = buffer location, ax = buffer address
  247.  
  248.  
  249. block_output:
  250.     assume    ds:nothing
  251.     loadport
  252.     setport    PAGE_0        ;set the write address.
  253.     out    dx,ax
  254.  
  255.     setport    PAGE_4
  256.     jmp    block_output_ptr
  257.  
  258. io_output_286:
  259.     inc    cx            ;round up.
  260.     shr    cx,1
  261.     rep    outsw
  262.     clc
  263.     ret
  264.  
  265. io_output_386:
  266.     .386
  267.     add    cx,3            ;round up
  268.     shr    cx,2
  269.     rep    outsd
  270.     clc
  271.     ret
  272.     .286
  273.  
  274. mem_output_286:
  275.     loadport
  276.     setport    OPTION
  277.     in    ax,dx
  278.     push    ax            ;save original contents.
  279.     and    ax,not (MMap_Dis or Boot_Rom_En)    ;turn off boot rom, memory on.
  280.     out    dx,ax
  281.  
  282.     mov    es,mem_addr
  283.     mov    di,0
  284.     inc    cx
  285.     shr    cx,1
  286.     rep    movsw
  287.     pop    ax            ;restore OPTION register.
  288.     out    dx,ax
  289.     clc
  290.     ret
  291.  
  292. mem_output_386:
  293.     .386
  294.     loadport
  295.     setport    OPTION
  296.     in    ax,dx
  297.     push    ax            ;save original contents.
  298.     and    ax,not (MMap_Dis or Boot_Rom_En)    ;turn off boot rom, memory on.
  299.     out    dx,ax
  300.  
  301.     mov    es,mem_addr
  302.     mov    di,0
  303.     add    cx,3
  304.     shr    cx,2            ; convert byte count to dword count
  305.     rep    movsd
  306.     pop    ax            ;restore OPTION register.
  307.     out    dx,ax
  308.     clc
  309.     ret
  310.     .286
  311.  
  312.     include    8390.asm
  313.  
  314.     public    usage_msg
  315. usage_msg    db    "usage: hppclanp [options] <packet_int_no> <io_addr>",CR,LF,'$'
  316.  
  317.     public    copyright_msg
  318. copyright_msg    db    "Packet driver for HP 27247B/27252A cards, version "
  319.         db    '0'+(majver / 10),'0'+(majver mod 10),".",'0'+version,".",'0'+dp8390_version,CR,LF,'$'
  320.  
  321. no_board_msg    db    "No HP PC LAN detected.",CR,LF,'$'
  322. io_addr_funny_msg    label    byte
  323.         db    "No HP PC LAN detected, continuing anyway.",CR,LF,'$'
  324. no_network_msg    db    "Check network connector - no network connection detected.",CR,LF,'$'
  325. int_no_name    db    "Interrupt number ",'$'
  326. io_addr_name    db    "I/O port ",'$'
  327. mem_addr_name    db    "Memory address ",'$'
  328.  
  329. config_flags    db    ?
  330. config_aui_bit    db    ?        ;=01h if TP, =40h if TL
  331.  
  332.     public    parse_args
  333. parse_args:
  334. ;exit with nc if all went well, cy otherwise.
  335.  
  336.     mov    di,offset io_addr
  337.     call    get_number
  338.  
  339.     push    si
  340.  
  341.     cmp    io_addr,-1        ;Did they ask for auto-detect?
  342.     je    find_board
  343.  
  344.     call    detect_board        ;no, just verify its existance.
  345.     je    find_board_found
  346.  
  347.     mov    dx,offset io_addr_funny_msg
  348.     mov    ah,9
  349.     int    21h
  350.  
  351.     jmp    find_board_found
  352.  
  353. find_board:
  354.     mov    io_addr,100h        ;Search for the Ethernet address.
  355.     mov    io_addr+2,0
  356. find_board_0:
  357.     call    detect_board
  358.     je    find_board_found
  359. find_board_again:
  360.     add    io_addr,20h        ;not at this port, try another.
  361.     cmp    io_addr,3ffh
  362.     jb    find_board_0
  363.  
  364.     mov    dx,offset no_board_msg    ;Tell them that we can't find it.
  365.     stc
  366.     ret
  367. find_board_found:
  368.     mov    config_flags,al        ;remember the config flags for later.
  369.     and    al,40h            ;Twisted Pair or Thin Lan?
  370.     jne    find_board_tl
  371.     mov    al,1
  372. find_board_tl:
  373.     mov    config_aui_bit,al
  374.  
  375.     loadport
  376.     setport    PAGING            ;select swap page 2 (hardware)
  377.     mov    al,HW_page
  378.     out    dx,al
  379.  
  380.     setport    0dh            ;get the IRQ Channel
  381.     in    al,dx
  382.     and    al,0fh
  383.     mov    int_no,al
  384.  
  385.     setport    09h            ;get the low memory map location
  386.     in    ax,dx
  387.     shl    ax,4            ;make into a segment address
  388.     mov    mem_addr,ax
  389.  
  390.     mov    ax,SM_RSTART_PG + (SM_RSTOP_PG-1) * 256
  391.     setport    0eh
  392.     out    dx,ax
  393.  
  394.   if 0
  395.     setport    PAGING
  396.     mov    al,Lan_Page        ;select Lan_Page page.
  397.     out    dx,al
  398.  
  399.     setport    PAGE_0
  400.     in    ax,dx
  401.     or    al,config_aui_bit    ;start with AUI on.
  402.     out    dx,ax
  403.   endif
  404.  
  405.     setport    PAGING
  406.     mov    al,Perf_page        ;select Performance page again.
  407.     out    dx,al
  408.  
  409.     setport    OPTION            ;see if we're memory or I/O mapped.
  410.     in    ax,dx
  411.     mov    bx,offset io_input_286
  412.     mov    cx,offset io_input_386
  413.     mov    si,offset io_output_286
  414.     mov    di,offset io_output_386
  415.  
  416.     test    ax,Mem_En        ;is memory enabled?
  417.     je    io_mapped
  418. ;    and    ax,not MMap_Dis        ;turn off the memory map disable.
  419. ;    out    dx,ax
  420.     inc    memory_mapped
  421.     mov    bx,offset mem_input_286
  422.     mov    cx,offset mem_input_386
  423.     mov    si,offset mem_output_286
  424.     mov    di,offset mem_output_386
  425. io_mapped:
  426.     mov    block_input_ptr,bx    ;by default, use 286 transfers.
  427.     mov    block_output_ptr,si
  428.     cmp    is_386,0        ;do we have a 386?
  429.     je    use_286_code        ;no, use 286 transfers
  430.     test    config_flags,10h    ;should we use 16-bit transfers anyway?
  431.     jne    use_286_code        ;yes, their motherboard has a problem.
  432.     mov    block_input_ptr,cx
  433.     mov    block_output_ptr,di
  434. use_286_code:
  435.  
  436.     mov    sm_rstop_ptr,SM_RSTOP_PG
  437.  
  438.     pop    si
  439.     clc
  440.     ret
  441.  
  442.     extrn    etopen_diagn: byte
  443.  
  444. init_card:
  445. ;we have nothing left to do here.
  446.     clc
  447.     ret
  448.  
  449.  
  450. test_packet    label    byte
  451.     db    EADDR_LEN dup(?)
  452.     db    EADDR_LEN dup(?)
  453.     db    00h,2eh            ;A 46 in network order
  454.     db    0,0            ;DSAP=0 & SSAP=0 fields
  455.     db    0f3h,0            ;Control (Test Req + P bit set)
  456.  
  457.     public    print_parameters
  458. print_parameters:
  459. ;echo our command-line parameters
  460.     assume    ds:code
  461.  
  462.     test    config_flags,80h    ;should we auto-sense?
  463.     jne    do_auto_sense
  464.     jmp    send_test_exit        ;no.
  465. do_auto_sense:
  466.  
  467. ;but on *this* adapter, try sending a test packet.
  468.  
  469.     mov    si,offset rom_address    ;set the destination address.
  470.     movseg    es,cs
  471.     mov    di,offset test_packet
  472.     repmov    EADDR_LEN
  473.     mov    si,offset rom_address    ;set the source address.
  474.     repmov    EADDR_LEN
  475.  
  476.     loadport
  477.     setport    PAGING
  478.     mov    ax,Lan_Page
  479.     out    dx,ax            ;Point at LAN Control page
  480.  
  481.     setport    PAGE_0
  482.     in    ax,dx            ;Get current state of LAN register
  483.     or    al,config_aui_bit    ;Turn on AUI select bit
  484. send_test:
  485.     out    dx,ax
  486.  
  487.     call    delay_150ms
  488.  
  489.     setport    PAGING            ;set back to the expected page
  490.     mov    ax,Perf_page
  491.     out    dx,ax
  492.  
  493.     mov    cx,6            ;try six times
  494. send_test_again:
  495.     push    bx
  496.     push    cx
  497.     mov    cx,60
  498.     mov    si,offset test_packet
  499.     call    send_pkt
  500.     pop    cx
  501.     pop    bx
  502.  
  503.     mov    ax,18
  504.     call    set_timeout
  505.  
  506.     loadport
  507.     setport    EN0_ISR
  508. send_test_wait:
  509.     in    al,dx
  510.     test    al,ENISR_TX or ENISR_TX_ERR    ;did it finish?
  511.     jne    send_test_done
  512.  
  513.     call    do_timeout
  514.     jnz    send_test_wait
  515.     jmp    short send_test_loop
  516.  
  517. send_test_done:
  518.     mov    al,0ffh            ;clear all interrupts.
  519.     out    dx,al
  520.  
  521.     setport    EN0_TSR
  522.     in    al,dx            ;get the transmit status
  523.     test    al,ENTSR_COLL16 or ENTSR_CRS or ENTSR_FU    ;any problems?
  524.     je    send_test_exit        ;no, it worked.
  525.  
  526. send_test_loop:
  527.     loop    send_test_again
  528.  
  529. ;it failed all six times.  Try again on a different interface.
  530.     setport    PAGING
  531.     mov    ax,Lan_Page
  532.     out    dx,ax            ;Point at LAN Control page
  533.  
  534.     setport    PAGE_0
  535.     in    ax,dx            ;Get current state of LAN register
  536.     test    al,config_aui_bit    ;did we already try internal xcvr?
  537.     je    send_test_fail        ;yes, we can't send any packets!
  538.  
  539.     not    al            ;Turn off AUI select bit
  540.     or    al,config_aui_bit
  541.     not    al
  542.     jmp    send_test
  543.  
  544. send_test_fail:
  545.     mov    dx,offset no_network_msg
  546.     mov    ah,9
  547.     int    21h
  548.  
  549. send_test_exit:
  550.     loadport
  551.     setport    PAGING            ;set back to the expected page
  552.     mov    ax,Perf_page
  553.     out    dx,ax
  554.  
  555.     mov    di,offset int_no
  556.     mov    dx,offset int_no_name
  557.     call    print_number
  558.     mov    di,offset io_addr
  559.     mov    dx,offset io_addr_name
  560.     call    print_number
  561.     cmp    memory_mapped,0
  562.     je    print_parameters_1
  563.     mov    di,offset mem_addr
  564.     mov    dx,offset mem_addr_name
  565.     call    print_number
  566. print_parameters_1:
  567.     ret
  568.  
  569.  
  570. delay_150ms:
  571.     mov    ax,(3000+275)/275    ;delay 300 ms (27.5 ms per increment).
  572.     call    set_timeout
  573. delay_150ms_1:
  574.     call    do_timeout
  575.     jnz    delay_150ms_1
  576.     ret
  577.  
  578.  
  579. detect_board:
  580. ;see if this adapter is the HP Adapter/16+.
  581. ;exit with zr if adapter is at io_addr,
  582. ;  AL = Driver Configuration Flags    (YOYO page 6 offset 0Ch)
  583. ;  AH = Soft model byte            (YOYO page 6 offset 0Dh)
  584. ;
  585. ;    Check Hardware Family ID bytes
  586. ;
  587.     loadport
  588.     setport    HP_ID
  589.     in    al,dx
  590.     cmp    al,50h
  591.     jne    detect_board_1
  592.  
  593.     setport    HP_ID+1
  594.     in    al,dx
  595.     cmp    al,48h
  596.     jne    detect_board_1
  597.     setport    HP_ID+2
  598.     in    al,dx
  599.     and    al,0f0h            ;AND off page select bits
  600.     cmp    al,0
  601.     jne    detect_board_1
  602.     setport    HP_ID+3
  603.     in    al,dx
  604.     cmp    al,53h
  605.     jne    detect_board_1
  606. ;
  607. ;    Checksum the Station Address to verify this really is an Adapter/16+
  608. ;
  609.     setport    PAGING            ;Point back at PAGING register
  610.     mov    ax,MAC_Page
  611.     out    dx,ax            ;Goto adapter ISA ID page
  612.     xor    bl,bl
  613.     movseg    es,cs
  614.     mov    di,offset rom_address
  615.     mov    cx,7            ;6 bytes of address + 1 checksum byte
  616.     setport    PAGE_0            ;Point at 1st Station Address byte
  617. detect_board_2:
  618.     in    al,dx
  619.     add    bl,al
  620.     stosb
  621.     inc    dx
  622.     loop    detect_board_2
  623.     cmp    bl,0ffh            ;Is checksum good??
  624.     jnz    detect_board_1        ;NO, exit
  625. ;
  626. ;    Check the Software Model number to verify this Adapter/16+ is NIC based.
  627. ;
  628.     loadport
  629.     setport    PAGING            ;Point back at PAGING register
  630.     mov    ax,ID_Page
  631.     out    dx,ax            ;Point at Board ID and SW info page
  632.     setport    PAGE_4            ;Point at Software Configuration Flags
  633.     in    ax,dx
  634.     mov    bh,ah
  635.     and    bh,(NOT 3h)        ;Mask off revision bits
  636.     cmp    bh,0            ;Compare soft model number (0)?
  637. detect_board_1:
  638.     ret
  639.  
  640.  
  641. code    ends
  642.  
  643.     end
  644.