lnc.c
pci/lnc.h
sys/io.h
ubixos/types.h
sys/idt.h
sys/gdt.h
lib/kmalloc.h
lib/kprintf.h
sys/video.h
isa/8259.h
src/sys/pci/lnc.c
pci/lnc.h
ubixos/types.h
sys/_types.h
sys/video.h
lib/kmalloc.h
sys/idt.h
lib/kprintf.h
sys/gdt.h
sys/io.h
isa/8259.h
asm
(".global _lncInt \n""_lncInt : \n"" pusha \n"" pushw %ds \n"" pushw %es \n"" pushw %ss \n"" pushw %ss \n"" popw %ds \n"" popw %es \n"" call lncInt \n"" popw %es \n"" popw %ds \n"" popa \n"" iret \n")
asm
".global _lncInt \n""_lncInt : \n"" pusha \n"" pushw %ds \n"" pushw %es \n"" pushw %ss \n"" pushw %ss \n"" popw %ds \n"" popw %es \n"" call lncInt \n"" popw %es \n"" popw %ds \n"" popa \n"" iret \n"
void void initLNC () initLNC _lncInt arpcom::ac_enaddr lncInfo::arpcom lncInfo::bdp CSR0 CSR3 dDpl3 dInt DMA_FIXED dPresent ETHER_ADDR_LEN nicInfo::ic nicInfo::ident IDON INEA INIT inportByte kmalloc kprintf lnc lncAttach nicInfo::memMode mVec NE2100 lncInfo::nic NRDRE lncInfo::nrdre NTDRE lncInfo::ntdre PCnet_32 PCNET_BDP PCNET_RAP PCNET_RDP probe lncInfo::rap lncInfo::rdp readCsr setVector STRT writeCsr x1000
int int lanceProbe (struct lncInfo *lnc) lanceProbe struct lncInfo * lnc C_LANCE CSR0 CSR3 INEA inportWord LANCE lnc lncInfo::rdp readCsr STOP UNKNOWN writeCsr probe
int int lncAttach (struct lncInfo *lnc, int unit) lncAttach struct lncInfo * lnc int unit arpcom::ac_enaddr lncInfo::arpcom C_LANCE DMA_FIXED nicInfo::ic icIdent nicInfo::ident kmalloc kprintf LANCE lnc MEM_SLEW nicInfo::memMode nicInfo::mode NDESC lncInfo::nic nicIdent NORMAL lncInfo::nrdre lncInfo::ntdre PCnet_32 RECVBUFSIZE lncInfo::recvRing SHMEM TRANSBUFSIZE initLNC
void void lncInt () lncInt ERR inportWord INTR kprintf lnc outportByte outportWord lncInfo::rdp RINT TINT x20
int int probe (struct lncInfo *lnc) probe struct lncInfo * lnc Am79C960 Am79C961 Am79C961A Am79C965 Am79C970 Am79C970A Am79C971 Am79C972 Am79C973 Am79C978 AMD_MASK CSR88 CSR89 lanceProbe lnc PART_MASK PCnet_32 PCnet_FAST PCnet_FASTplus PCnet_Home PCnet_ISA PCnet_ISA_II PCnet_ISAplus PCnet_PCI PCnet_PCI_II readCsr initLNC
uInt16 uInt16 readBcr (struct lncInfo *sc, uInt16 port) readBcr struct lncInfo * sc uInt16 port lncInfo::bdp inportWord outportWord lncInfo::rap
uInt16 uInt16 readCsr (struct lncInfo *lnc, uInt16 port) readCsr struct lncInfo * lnc uInt16 port inportWord lnc outportWord lncInfo::rap lncInfo::rdp initLNC lanceProbe probe
void void writeBcr (struct lncInfo *lnc, uInt16 port, uInt16 val) writeBcr struct lncInfo * lnc uInt16 port uInt16 val lncInfo::bdp lnc outportWord lncInfo::rap
void void writeCsr (struct lncInfo *lnc, uInt16 port, uInt16 val) writeCsr struct lncInfo * lnc uInt16 port uInt16 val lnc outportWord lncInfo::rap lncInfo::rdp initLNC lanceProbe
char const *const char const* const icIdent[] [] icIdent { "Unknown", "LANCE", "C-LANCE", "PCnet-ISA", "PCnet-ISA+", "PCnet-ISA II", "PCnet-32 VL-Bus", "PCnet-PCI", "PCnet-PCI II", "PCnet-FAST", "PCnet-FAST+", "PCnet-Home", } lncAttach
lncInfo * struct lncInfo* lnc lnc 0x0 initLNC lanceProbe lncAttach lncInt probe readCsr writeBcr writeCsr
char const *const char const* const nicIdent[] [] nicIdent { "Unknown", "BICC", "NE2100", "DEPCA", "CNET98S", } lncAttach

    /*****************************************************************************************
    Copyright(c)2002TheUbixOSProject
    Allrightsreserved.

    Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,are
    permittedprovidedthatthefollowingconditionsaremet:

    Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistof
    conditions,thefollowingdisclaimerandthelistofauthors.Redistributionsinbinary
    formmustreproducetheabovecopyrightnotice,thislistofconditions,thefollowing
    disclaimerandthelistofauthorsinthedocumentationand/orothermaterialsprovided
    withthedistribution.NeitherthenameoftheUbixOSProjectnorthenamesofits
    contributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftware
    withoutspecificpriorwrittenpermission.

    THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANY
    EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOF
    MERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALL
    THECOPYRIGHTOWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,
    SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENT
    OFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
    TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHIS
    SOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

    $Log: lnc_8c.xml,v $
    Revision 1.6  2006/12/19 14:12:52  reddawg
    rtld-elf almost workign

    Revision1.1.1.12006/06/0112:46:16reddawg
    ubix2

    Revision1.22005/10/1200:13:37reddawg
    Removed

    Revision1.1.1.12005/09/2617:24:35reddawg
    nomessage

    Revision1.1.1.12004/04/1512:07:15reddawg
    UbixOSv1.0

    Revision1.42004/04/1316:36:33reddawg
    Changedourcopyright,itisallnowunderaBSD-Stylelicense

    $Id: lnc_8c.xml 88 2016-01-12 00:11:29Z reddawg $

    *****************************************************************************************/

    #include<pci/lnc.h>
    #include<sys/io.h>
    #include<ubixos/types.h>
    #include<sys/idt.h>
    #include<sys/gdt.h>
    #include<lib/kmalloc.h>
    #include<lib/kprintf.h>
    #include<sys/video.h>
    #include<isa/8259.h>

    structlncInfo*lnc=0x0;

    staticcharconst*constnicIdent[]={
    "Unknown",
    "BICC",
    "NE2100",
    "DEPCA",
    "CNET98S",/*PC-98*/
    };

    staticcharconst*consticIdent[]={
    "Unknown",
    "LANCE",
    "C-LANCE",
    "PCnet-ISA",
    "PCnet-ISA+",
    "PCnet-ISAII",
    "PCnet-32VL-Bus",
    "PCnet-PCI",
    "PCnet-PCIII",
    "PCnet-FAST",
    "PCnet-FAST+",
    "PCnet-Home",
    };

    voidwriteCsr(structlncInfo*lnc,uInt16port,uInt16val){
    outportWord(lnc->rap,port);
    outportWord(lnc->rdp,val);
    }

    uInt16readCsr(structlncInfo*lnc,uInt16port){
    outportWord(lnc->rap,port);
    return(inportWord(lnc->rdp));
    }

    voidwriteBcr(structlncInfo*lnc,uInt16port,uInt16val){
    outportWord(lnc->rap,port);
    outportWord(lnc->bdp,val);
    }

    uInt16readBcr(structlncInfo*sc,uInt16port){
    outportWord(sc->rap,port);
    return(inportWord(sc->bdp));
    }

    voidinitLNC(){
    inti=0x0;
    lnc=kmalloc(sizeof(structlncInfo),-2);

    lnc->rap=0x1000+PCNET_RAP;
    lnc->rdp=0x1000+PCNET_RDP;
    lnc->bdp=0x1000+PCNET_BDP;

    lnc->nic.ic=probe(lnc);
    if((lnc->nic.ic>0)&&(lnc->nic.ic>=PCnet_32)){
    lnc->nic.ident=NE2100;
    lnc->nic.memMode=DMA_FIXED;

    lnc->nrdre=NRDRE;
    lnc->ntdre=NTDRE;

    /*ExtractMACaddressfromPROM*/
    for(i=0;i<ETHER_ADDR_LEN;i++){
    lnc->arpcom.ac_enaddr[i]=inportByte(0x1000+i);
    kprintf("[0x%X]",lnc->arpcom.ac_enaddr[i]);
    }
    }
    else{
    kprintf("LNCInitError\n");
    return;
    }
    lncAttach(lnc,0);
    writeCsr(lnc,CSR3,0);
    writeCsr(lnc,CSR0,INIT);
    for(i=0;i<1000;i++)
    if(readCsr(lnc,CSR0)&IDON)
    break;

    if(readCsr(lnc,CSR0)&IDON){
    writeCsr(lnc,CSR0,STRT|INEA);
    setVector(_lncInt,mVec+9,(dInt+dPresent+dDpl3));
    enableIrq(9);
    /*
    *sc->arpcom.ac_if.if_flags|=IFF_RUNNING;
    *sc->arpcom.ac_if.if_flags&=~IFF_OACTIVE;
    *lnc_start(&sc->arpcom.ac_if);
    */
    }
    else{
    kprintf("LNCinitError\n");
    return;
    }
    return;
    }

    intprobe(structlncInfo*lnc){
    uInt32chipId=0x0;
    inttype=0x0;

    if((type=lanceProbe(lnc))){
    chipId=readCsr(lnc,CSR89);
    chipId<<=16;
    chipId|=readCsr(lnc,CSR88);
    if(chipId&AMD_MASK){
    chipId>>=12;
    switch(chipId&PART_MASK){
    caseAm79C960:
    return(PCnet_ISA);
    caseAm79C961:
    return(PCnet_ISAplus);
    caseAm79C961A:
    return(PCnet_ISA_II);
    caseAm79C965:
    return(PCnet_32);
    caseAm79C970:
    return(PCnet_PCI);
    caseAm79C970A:
    return(PCnet_PCI_II);
    caseAm79C971:
    return(PCnet_FAST);
    caseAm79C972:
    caseAm79C973:
    return(PCnet_FASTplus);
    caseAm79C978:
    return(PCnet_Home);
    default:
    break;
    }
    }
    }
    return(type);
    }

    intlanceProbe(structlncInfo*lnc){
    writeCsr(lnc,CSR0,STOP);
    if((inportWord(lnc->rdp)&STOP)&&!(readCsr(lnc,CSR3))){
    writeCsr(lnc,CSR0,INEA);
    if(readCsr(lnc,CSR0)&INEA){
    return(C_LANCE);
    }
    else{
    return(LANCE);
    }
    }
    else{
    return(UNKNOWN);
    }
    }

    voidlncInt(){
    uInt16csr0=0x0;
    while((csr0=inportWord(lnc->rdp))&INTR){
    outportWord(lnc->rdp,csr0);
    kprintf("CSR0:[0x%X]\n",csr0);
    if(csr0&ERR){
    kprintf("Error:[0x%X]\n",csr0);
    }
    if(csr0&RINT){
    kprintf("RINT\n");
    }
    if(csr0&TINT){
    kprintf("TINT\n");
    }
    }
    kprintf("Finished!!!\n");
    outportByte(0x20,0x20);
    return;
    }

    asm(
    ".global_lncInt\n"
    "_lncInt:\n"

    "pusha\n"/*Saveallregisters*/
    "pushw%ds\n"/*Setupthedatasegment*/
    "pushw%es\n"
    "pushw%ss\n"/*Notethatssisalwaysvalid*/
    "pushw%ss\n"
    "popw%ds\n"
    "popw%es\n"
    "calllncInt\n"
    "popw%es\n"
    "popw%ds\n"/*Restoreregisters*/
    "popa\n"
    "iret\n"/*Exitinterrupt*/
    );

    intlncAttach(structlncInfo*lnc,intunit){
    intlncMemSize=0x0;

    lncMemSize=((NDESC(lnc->nrdre)+NDESC(lnc->ntdre))*sizeof(structhostRingEntry));

    if(lnc->nic.memMode!=SHMEM)
    lncMemSize+=sizeof(structinitBlock)+(sizeof(structmds)*(NDESC(lnc->nrdre)+NDESC(lnc->ntdre)))+MEM_SLEW;

    if(lnc->nic.memMode==DMA_FIXED)
    lncMemSize+=(NDESC(lnc->nrdre)*RECVBUFSIZE)+(NDESC(lnc->ntdre)*TRANSBUFSIZE);

    if(lnc->nic.memMode!=SHMEM){
    if(lnc->nic.ic<PCnet_32){
    /*ISAbasedcards*/
    kprintf("ISABoard\n");
    /*sc->recv_ring=contigmalloc(lnc_mem_size,M_DEVBUF,M_NOWAIT,0ul,0xfffffful,4ul,0x1000000);*/
    }
    else{
    /*
    *Fornowitstillneedstobebelow16MBbecausethe
    *descriptor'scanonlyhold16bitaddresses.
    */
    /*sc->recv_ring=contigmalloc(lnc_mem_size,M_DEVBUF,M_NOWAIT,0ul,0xfffffful,4ul,0x1000000);*/
    lnc->recvRing=kmalloc(lncMemSize,-2);
    kprintf("PCIBoard\n");
    }
    }

    if(!lnc->recvRing){
    kprintf("lnc%d:Couldn'tallocatememoryforNIC\n",unit);
    return(0);
    }

    lnc->nic.mode=NORMAL;

    /*Fillinarpcomstructureentries*/
    /*
    lnc->arpcom.ac_if.if_softc=sc;
    lnc->arpcom.ac_if.if_name=lncdriver.name;
    lnc->arpcom.ac_if.if_unit=unit;
    lnc->arpcom.ac_if.if_mtu=ETHERMTU;
    lnc->arpcom.ac_if.if_flags=IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
    lnc->arpcom.ac_if.if_timer=0;
    lnc->arpcom.ac_if.if_output=ether_output;
    lnc->arpcom.ac_if.if_start=lnc_start;
    lnc->arpcom.ac_if.if_ioctl=lnc_ioctl;
    lnc->arpcom.ac_if.if_watchdog=lnc_watchdog;
    lnc->arpcom.ac_if.if_init=lnc_init;
    lnc->arpcom.ac_if.if_type=IFT_ETHER;
    lnc->arpcom.ac_if.if_addrlen=ETHER_ADDR_LEN;
    lnc->arpcom.ac_if.if_hdrlen=ETHER_HDR_LEN;
    lnc->arpcom.ac_if.if_snd.ifq_maxlen=IFQ_MAXLEN;
    */
    /*ether_ifattach(&sc->arpcom.ac_if,ETHER_BPF_SUPPORTED);*/

    kprintf("lnc%d:",unit);
    if(lnc->nic.ic==LANCE||lnc->nic.ic==C_LANCE)
    kprintf("%s(%s)",nicIdent[lnc->nic.ident],icIdent[lnc->nic.ic]);
    else
    kprintf("%s",icIdent[lnc->nic.ic]);
    kprintf("address0x%X\n",lnc->arpcom.ac_enaddr);
    return(1);
    }

    /***
    END
    ***/