diff --git a/src/Makefile b/src/Makefile index 178e963..898354e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -93,8 +93,8 @@ clean: (cd sys;${MAKE} clean) - (cd bin;${MAKE} clean) - (cd lib;${MAKE} clean) + (cd bin;${WMAKE} clean) + (cd lib;${WMAKE} clean) # (cd src/lib/ubix;make clean) # (cd src/lib/objgfx40;make clean) # (cd src/lib/libcpp;make clean) diff --git a/src/sys/include/pci/lnc.h b/src/sys/include/pci/lnc.h index 31e7692..b08ef6b 100644 --- a/src/sys/include/pci/lnc.h +++ b/src/sys/include/pci/lnc.h @@ -39,15 +39,127 @@ #define BDP 0x16 // 16Bit #define BDP32 0x1C // 32Bit +// BCR18 +#define BCR18 18 +#define BCR18_DWIO 0x0080 + +// BCR20 +#define BCR20 0x0014 + // Modes #define MODE_16 0 #define MODE_32 1 #define MODE_INVALID 3 -// CSR0 Commands +// CSR0 +#define CSR0 0x0000 #define CSR0_STOP 0x0004 +// CSR15 +#define CSR15 15 +#define CSR15_DXMTFCS 0x0008 +#define CSR15_DRTY 0x0020 +#define CSR15_PROM 0x8000 + +// CSR58 +#define CSR58 0x003A + +/* Structs */ +struct mds { + uint16_t md0; + uint16_t md1; + short md2; + uint16_t md3; +}; + +struct hostRingEntry_old { + struct mds *md; + union { + //struct mbuf *mbuf; + char *data; + } buff; +}; + +struct hostRingEntry { + uint32_t addr; + uint16_t bcnt; + uint8_t md[6]; + uint32_t reserved; +}; + +struct arpcom { + //struct ifnet ac_if; /* network-visible interface */ + uint8_t ac_enaddr[6]; /* ethernet hardware address */ + int ac_multicnt; /* length of ac_multiaddrs list */ + void *ac_netgraph; /* ng_ether(4) netgraph node info */ +}; + +struct nicInfo { + int ident; /* Type of card */ + int ic; /* Type of ic, Am7990, Am79C960 etc. */ + int memMode; + int iobase; + int mode; /* Mode setting at initialization */ +}; + +struct initBlock16 { + uint16_t mode; // Mode register + uint8_t padr[6]; // Ethernet address + uint8_t ladrf[8]; // Logical address filter (multicast) + uint16_t rdra; // Low order pointer to receive ring + uint16_t rlen; // High order pointer and no. rings + uint16_t tdra; // Low order pointer to transmit ring + uint16_t tlen; // High order pointer and no rings +}; + +struct initBlock32 { + uint16_t mode; + uint8_t rlen; + uint8_t tlen; + uint8_t padr[6]; + uint16_t res; + uint8_t ladrf[8]; + uint32_t rdra; + uint32_t tdra; +}; + + +struct lncInfo { + struct arpcom arpcom; + struct nicInfo nic; + struct hostRingEntry *rxRing; + struct hostRingEntry *txRing; + struct initBlock32 init; + unsigned int ioAddr; + int nrdre; + int ntdre; +}; + +/* Functions */ +void lnc_writeCSR(struct lncInfo *, uint16_t, uint16_t); +void lnc_writeCSR32(struct lncInfo *, uint32_t, uint32_t); + +uint16_t lnc_readCSR(struct lncInfo *, uint16_t); +uint32_t lnc_readCSR32(struct lncInfo *, uint32_t); + +void lnc_writeBCR(struct lncInfo *, uint16_t, uint16_t); +void lnc_writeBCR32(struct lncInfo *, uint32_t, uint32_t); + +uint16_t lnc_readBCR(struct lncInfo *, uint16_t); +uint32_t lnc_readBCR32(struct lncInfo *, uint32_t); + +void lnc_reset(struct lncInfo *); +void lnc_reset32(struct lncInfo *); + +int lnc_probe(struct lncInfo *); + +int lnc_switchDWord(struct lncInfo *); + +int lnc_getMode(struct lncInfo *); + +void lnc_isr(); + // OLD #define NDESC(len2) (1 << len2) @@ -83,7 +195,6 @@ #define PCnet_Home 11 /* Am79C978 */ /******** AM7990 Specifics **************/ -#define CSR0 0x0000 #define CSR1 1 #define CSR2 2 #define CSR3 3 @@ -121,64 +232,9 @@ #define Am79C973 0x2625 #define Am79C978 0x2626 -struct initBlock { - uint16_t mode; // Mode register - uint8_t padr[6]; // Ethernet address - uint8_t ladrf[8]; // Logical address filter (multicast) - uint16_t rdra; // Low order pointer to receive ring - uint16_t rlen; // High order pointer and no. rings - uint16_t tdra; // Low order pointer to transmit ring - uint16_t tlen; // High order pointer and no rings -}; - -struct mds { - uint16_t md0; - uint16_t md1; - short md2; - uint16_t md3; -}; - -struct hostRingEntry { - struct mds *md; - union { - //struct mbuf *mbuf; - char *data; - } buff; -}; - -struct arpcom { - //struct ifnet ac_if; /* network-visible interface */ - uint8_t ac_enaddr[6]; /* ethernet hardware address */ - int ac_multicnt; /* length of ac_multiaddrs list */ - void *ac_netgraph; /* ng_ether(4) netgraph node info */ -}; - -struct nicInfo { - int ident; /* Type of card */ - int ic; /* Type of ic, Am7990, Am79C960 etc. */ - int memMode; - int iobase; - int mode; /* Mode setting at initialization */ -}; - -struct lncInfo { - struct arpcom arpcom; - struct nicInfo nic; - struct hostRingEntry *rxRing; - struct hostRingEntry *txRing; - struct initBlock *initBlock; - unsigned int ioAddr; - int nrdre; - int ntdre; -}; extern struct lncInfo *lnc; -void writeCsr(struct lncInfo *lnc, uInt16 port, uInt16 val); -uInt16 readCsr(struct lncInfo *lnc, uInt16 port); -void writeBcr(struct lncInfo *lnc, uInt16 port, uInt16 val); -uInt16 readBcr(struct lncInfo *lnc, uInt16 port); -uInt32 readBCR32(struct lncInfo *lnc, uInt32 port); int initLNC(); int probe(struct lncInfo *lnc); diff --git a/src/sys/include/ubixos/init.h b/src/sys/include/ubixos/init.h index a2259e4..3cc2562 100644 --- a/src/sys/include/ubixos/init.h +++ b/src/sys/include/ubixos/init.h @@ -57,13 +57,13 @@ intFunctionPTR init_tasks[] = { vmm_init, static_constructors, i8259_init, idt_init, vitals_init, sysctl_init, vfs_init, sched_init, pit_init, atkbd_init, time_init, net_init, -//ne2k_init, devfs_init, pci_init, - //ubixfs_init, - //fdc_init, initLNC, tty_init, ufs_init, initHardDisk, }; +//ne2k_init, +//ubixfs_init, +//fdc_init, int init_tasksTotal = sizeof(init_tasks) / sizeof(intFunctionPTR); diff --git a/src/sys/pci/lnc.c b/src/sys/pci/lnc.c index 461c4b1..4006469 100644 --- a/src/sys/pci/lnc.c +++ b/src/sys/pci/lnc.c @@ -56,8 +56,8 @@ } uint32_t lnc_readCSR32(struct lncInfo *lnc, uint32_t port) { - outportWord(lnc->ioAddr + RAP32, port); - return (inportWord(lnc->ioAddr + RDP32)); + outportDWord(lnc->ioAddr + RAP32, port); + return (inportDWord(lnc->ioAddr + RDP32)); } void lnc_writeBCR(struct lncInfo *lnc, uint16_t port, uint16_t val) { @@ -65,9 +65,9 @@ outportWord(lnc->ioAddr + BDP, val); } -void lnc_writeBCR32(struct lncInfo *lnc, uint16_t port, uint16_t val) { - outportWord(lnc->ioAddr + RAP, port); - outportWord(lnc->ioAddr + BDP, val); +void lnc_writeBCR32(struct lncInfo *lnc, uint32_t port, uint32_t val) { + outportDWord(lnc->ioAddr + RAP32, port); + outportDWord(lnc->ioAddr + BDP32, val); } uint16_t lnc_readBCR(struct lncInfo *lnc, uint16_t port) { @@ -111,33 +111,54 @@ lncAttach(lnc, 0); - /* - init->init_mode = 0x8000; - init->init_padr[0] = (lnc->arpcom.ac_enaddr[1] << 8) | lnc->arpcom.ac_enaddr[0]; - init->init_padr[1] = (lnc->arpcom.ac_enaddr[3] << 8) | lnc->arpcom.ac_enaddr[2]; - init->init_padr[2] = (lnc->arpcom.ac_enaddr[5] << 8) | lnc->arpcom.ac_enaddr[4]; + i = lnc_getMode(lnc); + if (i == MODE_16) + kprintf("16 Bit"); + else if (i == MODE_32) + kprintf("32 Bit"); + else + kprintf("Invalid Mode: [%i]", i); - init->init_rdra = lnc->recvRing; - init->init_rlen = 3; + lnc_switchDWord(lnc); - init->init_tdra = lnc->recvRing; - init->init_tlen = 3; + uint32_t iW = 0; - writeCsr(lnc, CSR1, (int) init & 0xFFFF); - writeCsr(lnc, CSR2, (int) init >> 16); - */ + iW = lnc_readBCR32(lnc, 0x2); + iW |= 0x2; + lnc_writeBCR32(lnc, 2, iW); - writeCsr(lnc, CSR3, 0); - writeCsr(lnc, CSR0, INIT); + lnc->init.mode = 0x8000; + //lnc->init.padr[0] = (lnc->arpcom.ac_enaddr[1] << 8) | lnc->arpcom.ac_enaddr[0]; + //lnc->init.padr[1] = (lnc->arpcom.ac_enaddr[3] << 8) | lnc->arpcom.ac_enaddr[2]; + //lnc->init.padr[2] = (lnc->arpcom.ac_enaddr[5] << 8) | lnc->arpcom.ac_enaddr[4]; + +lnc->init.padr[0] = lnc->arpcom.ac_enaddr[0]; +lnc->init.padr[1] = lnc->arpcom.ac_enaddr[1]; +lnc->init.padr[2] = lnc->arpcom.ac_enaddr[2]; +lnc->init.padr[3] = lnc->arpcom.ac_enaddr[3]; +lnc->init.padr[4] = lnc->arpcom.ac_enaddr[4]; +lnc->init.padr[5] = lnc->arpcom.ac_enaddr[5]; + lnc->init.rdra = (uint32_t)lnc->rxRing; + lnc->init.rlen = 3 << 4; + + lnc->init.tdra = (uint32_t)lnc->txRing; + lnc->init.tlen = 3 << 4; + + lnc_writeCSR32(lnc, CSR1, (uint32_t) &lnc->init & 0xFFFF); + lnc_writeCSR32(lnc, CSR2, ((uint32_t) &lnc->init >> 16) &0xFFFF); + + lnc_writeCSR32(lnc, CSR3, 0); + + lnc_writeCSR32(lnc, CSR0, INIT); for (i = 0; i < 1000; i++) - if (readCsr(lnc, CSR0) & IDON) + if (lnc_readCSR32(lnc, CSR0) & IDON) break; - if (readCsr(lnc, CSR0) & IDON) { - setVector(_lncInt, mVec + 9, (dInt + dPresent + dDpl3)); - irqEnable(9); - writeCsr(lnc, CSR0, STRT | INEA); + if (lnc_readCSR32(lnc, CSR0) & IDON) { + setVector(&lnc_isr, mVec + 0x9, (dInt + dPresent + dDpl0)); + irqEnable(0x9); + lnc_writeCSR32(lnc, CSR0, STRT | INEA); /* * sc->arpcom.ac_if.if_flags |= IFF_RUNNING; * sc->arpcom.ac_if.if_flags &= ~IFF_OACTIVE; @@ -149,15 +170,8 @@ return (-1); } - uInt16 iW = 0; - - iW = readBcr(lnc, 0x2); - kprintf("BCR2.0: [0x%X]", iW); - - iW = readBcr(lnc, 0x4); - kprintf("BCR2.1: [0x%X]", iW); - - while (1) + kprintf("SENDING PACKET"); + while(1) lnc_sendPacket(lnc, 0x0, 32, 0x0); return (0); @@ -169,10 +183,10 @@ int type = 0x0; if ((type = lanceProbe(lnc))) { - kprint("Type: [0x%X]", type); - chipId = readCsr(lnc, CSR89); + kprintf("Type: [0x%X]", type); + chipId = lnc_readCSR(lnc, CSR89); chipId <<= 16; - chipId |= readCsr(lnc, CSR88); + chipId |= lnc_readCSR(lnc, CSR88); if (chipId & AMD_MASK) { chipId >>= 12; switch (chipId & PART_MASK) { @@ -206,15 +220,15 @@ int lanceProbe(struct lncInfo *lnc) { uInt16 inW = 0; - writeCsr(lnc, CSR0, CSR0_STOP); + lnc_writeCSR(lnc, CSR0, CSR0_STOP); inW = inportWord(lnc->ioAddr + RDP); - if ((inW & CSR0_STOP) && !(readCsr(lnc, CSR3))) { + if ((inW & CSR0_STOP) && !(lnc_readCSR(lnc, CSR3))) { - writeCsr(lnc, CSR0, INEA); + lnc_writeCSR(lnc, CSR0, INEA); - if (readCsr(lnc, CSR0) & INEA) { + if (lnc_readCSR(lnc, CSR0) & INEA) { return (C_LANCE); } else { @@ -227,12 +241,12 @@ } void lncInt() { + kprintf("Finished!!!\n"); + outportByte(0x20, 0x20); + return; uInt16 csr0 = 0x0; - kprintf("TEST"); - while (1) - ; while ((csr0 = inportWord(lnc->ioAddr + RDP)) & INTR) { - outportWord(lnc->rdp, csr0); + outportWord(lnc->ioAddr + RDP, csr0); kprintf("CSR0: [0x%X]\n", csr0); if (csr0 & ERR) { kprintf("Error: [0x%X]\n", csr0); @@ -245,7 +259,6 @@ } } kprintf("Finished!!!\n"); - outportByte(0x20, 0x20); return; } @@ -267,17 +280,43 @@ " iret \n" /* Exit interrupt */ ); +asm( + ".globl lnc_isr \n" + "lnc_isr: \n" + " pusha \n" /* Save all registers */ + " push %ss \n" + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " call lncInt \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " pop %ss \n" + " popa \n" + " iret \n" /* Exit interrupt */ +); + + + int lncAttach(struct lncInfo *lnc, int unit) { + int i = 0; int lncMemSize = 0x0; + char *tmpBuffer = 0x0; + uint16_t bcnt = 0x0; + const int buffer_size = 1548; //lncMemSize = ((NDESC(lnc->nrdre) + NDESC(lnc->ntdre)) * sizeof(struct hostRingEntry)); - lncMemSize = (NDESC(lnc->nrdre) * sizeof(struct hostRingEntry)); + /* MrOlsen 2017-12-16 if (lnc->nic.memMode != SHMEM) lncMemSize += sizeof(struct initBlock) + (sizeof(struct mds) * (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) { @@ -291,20 +330,43 @@ * descriptor's can only hold 16 bit addresses. */ /* sc->recv_ring = contigmalloc(lnc_mem_size, M_DEVBUF, M_NOWAIT,0ul, 0xfffffful, 4ul, 0x1000000); */ - lnc->recvRing = kmalloc(lncMemSize); + //lncMemSize = (sizeof(struct hostRingEntry) * lnc->nrdre); + lncMemSize = (NDESC(lnc->nrdre) * sizeof(struct hostRingEntry)); + kprintf("lncMemSize: [%i]", lncMemSize); + lnc->rxRing = kmalloc(lncMemSize); + memset(lnc->rxRing,0x0,lncMemSize); + for (i = 0;i < NDESC(lnc->nrdre);i++) { + tmpBuffer = kmalloc(buffer_size); + lnc->rxRing->addr = (uint32_t)tmpBuffer; + bcnt = (uint16_t)(-buffer_size); + bcnt &= 0x0FFF; + bcnt |= 0xF000; + lnc->rxRing->bcnt = bcnt; +} kprintf("PCI Board\n"); } } - if (!lnc->recvRing) { + if (!lnc->rxRing) { kprintf("lnc%d: Couldn't allocate memory for NIC\n", unit); return (-1); } lncMemSize = (NDESC(lnc->ntdre) * sizeof(struct hostRingEntry)); - lnc->transRing = kmalloc(lncMemSize); + lnc->txRing = kmalloc(lncMemSize); + memset(lnc->txRing,0x0,lncMemSize); + for (i = 0;i < NDESC(lnc->ntdre);i++) { + tmpBuffer = kmalloc(buffer_size); + lnc->txRing->addr = (uint32_t)tmpBuffer; + bcnt = (uint16_t)(-buffer_size); + bcnt &= 0x0FFF; + bcnt |= 0xF000; + lnc->txRing->bcnt = bcnt; + lnc->txRing->md[0] = 0x80; + } - if (!lnc->recvRing) { + + if (!lnc->txRing) { kprintf("lnc%d: Couldn't allocate memory for NIC\n", unit); return (-1); } @@ -346,7 +408,9 @@ int tx_ptr = 0; char data[1548] = "SDFSDF"; - char *tdes = lnc->transRing; + char *tdes = (char *)lnc->txRing; + + //memcpy((void *)(tx_buffers + (tx_ptr * buffer_size), packet, len); tdes[(tx_ptr * 16) + 7] |= 0x2; tdes[(tx_ptr * 16) + 7] |= 0x1; @@ -356,18 +420,18 @@ bcnt |= 0xF000; *(uInt16 *) &tdes[tx_ptr * 16 + 4] = bcnt; tdes[tx_ptr * 16 + 7] |= 0x80; - + return(len); } int lnc_getMode(struct lncInfo *lnc) { + lnc_reset32(lnc); + if (lnc_readCSR32(lnc, CSR0) == CSR0_STOP) + return MODE_32; lnc_reset(lnc); if (lnc_readCSR(lnc, CSR0) == CSR0_STOP) return MODE_16; - lnc_reset32(lnc); - if (lnc_readCSR32(lnc, CSR0) == CSR0_STOP) - return MODE_32; return (MODE_INVALID); } @@ -379,3 +443,22 @@ void lnc_reset32(struct lncInfo *lnc) { inportDWord(lnc->ioAddr + RESET32); } + +int lnc_switchDWord(struct lncInfo *lnc) { + inportDWord(lnc->ioAddr + RESET32); + inportWord(lnc->ioAddr + RESET); + outportDWord(lnc->ioAddr + RDP, 0); + + /* a dword write to RDP sets controller into 32-bit I/O mode */ + //kprintf("BCR20.1: [0x%X][0x%X]", lnc_readBCR32(lnc, BCR20), lnc_readBCR32(lnc, BCR18) & BCR18_DWIO); + if (!(lnc_readBCR32(lnc, BCR18) & BCR18_DWIO)) { + kprintf("Cannot Swithc To 32 Bit"); + } + uint32_t _csr58 = lnc_readCSR32(lnc, CSR58); + _csr58 &= 0xFFF0; + _csr58 |= 2; + lnc_writeCSR32(lnc, CSR58, _csr58); + + return(0); + +} diff --git a/src/sys/pci/pci.c b/src/sys/pci/pci.c index f6f5621..16861d9 100644 --- a/src/sys/pci/pci.c +++ b/src/sys/pci/pci.c @@ -254,11 +254,11 @@ cfg->func = func; cfg->subsysVendor = pciRead(bus, dev, func, 0x2c, 2); cfg->subsys = pciRead(bus, dev, func, 0x2e, 2); -//if (cfg->vendorId == 0x1022) { +if (cfg->vendorId == 0x1022) { kprintf("Device Info: /bus/pci/%d/%d/%d\n",bus,dev,func); kprintf(" * Vendor: %X Device: %X Class/SubClass/Interface %X/%X/%X\n",cfg->vendorId,cfg->deviceId,cfg->baseClass,cfg->subClass,cfg->interface); kprintf(" * Status: %X Command: %X BIST/Type/Lat/CLS: %X/%X/%X/%X\n",cfg->status, cfg->command, cfg->bist, cfg->headerType,cfg->latencyTimer, cfg->cacheLineSize); -//} +} switch(cfg->headerType & 0x7F){ case 0: /* normal device */ for(i=0;i<6;i++) { @@ -308,9 +308,9 @@ /* kprintf(" * Vendor: %X Device: %X Class/SubClass/Interface %X/%X/%X\n",pcfg.vendorId,pcfg.deviceId,pcfg.baseClass,pcfg.subClass,pcfg.interface); */ for (i=0x0;i