📄 dec21140.c
字号:
/* * Stop the device */static voiddec21140_stop (struct dec21140_softc *sc){ volatile unsigned int *tbase; struct ifnet *ifp = &sc->arpcom.ac_if; ifp->if_flags &= ~IFF_RUNNING; /* * Stop the transmitter */ tbase = sc->base; st_le32( (tbase+memCSR7), NO_IT); st_le32( (tbase+memCSR6), CSR6_INIT); /* free((void*)sc->bufferBase); */}/* * Show interface statistics */static voiddec21140_stats (struct dec21140_softc *sc){ printf (" Rx Interrupts:%-8lu", sc->rxInterrupts); printf (" Not First:%-8lu", sc->rxNotFirst); printf (" Not Last:%-8lu\n", sc->rxNotLast); printf (" Giant:%-8lu", sc->rxGiant); printf (" Runt:%-8lu", sc->rxRunt); printf (" Non-octet:%-8lu\n", sc->rxNonOctet); printf (" Bad CRC:%-8lu", sc->rxBadCRC); printf (" Overrun:%-8lu", sc->rxOverrun); printf (" Collision:%-8lu\n", sc->rxCollision); printf (" Tx Interrupts:%-8lu", sc->txInterrupts); printf (" Deferred:%-8lu", sc->txDeferred); printf (" Missed Hearbeat:%-8lu\n", sc->txHeartbeat); printf (" No Carrier:%-8lu", sc->txLostCarrier); printf ("Retransmit Limit:%-8lu", sc->txRetryLimit); printf (" Late Collision:%-8lu\n", sc->txLateCollision); printf (" Underrun:%-8lu", sc->txUnderrun); printf (" Raw output wait:%-8lu\n", sc->txRawWait);}/* * Driver ioctl handler */static intdec21140_ioctl (struct ifnet *ifp, int command, caddr_t data){ struct dec21140_softc *sc = ifp->if_softc; int error = 0; switch (command) { case SIOCGIFADDR: case SIOCSIFADDR: ether_ioctl (ifp, command, data); break; case SIOCSIFFLAGS: switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) { case IFF_RUNNING: dec21140_stop (sc); break; case IFF_UP: dec21140_init (sc); break; case IFF_UP | IFF_RUNNING: dec21140_stop (sc); dec21140_init (sc); break; default: break; } break; case SIO_RTEMS_SHOW_STATS: dec21140_stats (sc); break; /* * FIXME: All sorts of multicast commands need to be added here! */ default: error = EINVAL; break; } return error;}/*int iftap(struct ifnet *ifp, struct ether_header *eh, struct mbuf *m ){ int i; if( ifp->if_unit == 1 ) return 0; printf("unit %i, src ", ifp->if_unit ); for(i=0; i< ETHER_ADDR_LEN; i++) printf("%02x", (char) eh->ether_shost[i] ); printf(" dest "); for(i=0; i< ETHER_ADDR_LEN; i++) printf("%02x", (char) eh->ether_dhost[i] ); printf("\n"); return -1;}*//* * Attach an DEC21140 driver to the system */intrtems_dec21140_driver_attach (struct rtems_bsdnet_ifconfig *config, int attach){ struct dec21140_softc *sc; struct ifnet *ifp; char *unitName; int unitNumber; int mtu; unsigned char cvalue;#if defined(__i386__) int signature; int value; char interrupt; int diag; unsigned int deviceId;#endif#if defined(__PPC) int pbus, pdev, pfun; int tmp; unsigned int lvalue;#endif /* * Get the instance number for the board we're going to configure * from the user. */ if( (unitNumber = rtems_bsdnet_parse_driver_name(config, &unitName)) == -1 ) { return 0; } if( strcmp(unitName, DRIVER_PREFIX) ) { printk("dec2114x : unit name '%s' not %s\n", unitName, DRIVER_PREFIX ); return 0; }#if defined(__i386__) /* * First, find a DEC board */ if (pcib_init() == PCIB_ERR_NOTPRESENT) rtems_panic("PCI BIOS not found !!"); /* * Try to find the network card on the PCI bus. Probe for a DEC 21140 * card first. If not found probe the bus for a DEC/Intel 21143 card. */ deviceId = PCI_DEVICE_ID_DEC_21140; diag = pcib_find_by_devid( PCI_VENDOR_ID_DEC, deviceId, unitNumber-1, &signature); if ( diag == PCIB_ERR_SUCCESS) printk( "DEC 21140 PCI network card found\n" ); else { deviceId = PCI_DEVICE_ID_DEC_21143; diag = pcib_find_by_devid( PCI_VENDOR_ID_DEC, deviceId, unitNumber-1, &signature); if ( diag == PCIB_ERR_SUCCESS) printk( "DEC/Intel 21143 PCI network card found\n" ); else { printk("No DEC/Intel 21140/3 PCI network card found !!\n"); return 0; } }#endif #if defined(__PPC) /* * Find the board */ if( BSP_pciFindDevice( PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21140, unitNumber-1, &pbus, &pdev, &pfun) == -1 ) { if( BSP_pciFindDevice( PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21143, unitNumber-1, &pbus, &pdev, &pfun) != -1 ) { pci_write_config_dword(pbus, pdev, pfun, 0x40, PCI_DEVICE_ID_DEC_21143 ); } else { printk("dec2114x : device '%s' not found on PCI bus\n", config->name ); return 0; } }#ifdef DEC_DEBUG else { printk("dec21140 : found device '%s', bus 0x%02x, dev 0x%02x, func 0x%02x\n", config->name, pbus, pdev, pfun); }#endif#endif if ((unitNumber < 1) || (unitNumber > NDECDRIVER)) { printk("dec2114x : unit %i is invalid, must be (1 <= n <= %d)\n", unitNumber); return 0; } sc = &dec21140_softc[unitNumber - 1]; ifp = &sc->arpcom.ac_if; if (ifp->if_softc != NULL) { printk("dec2114x : unit %i already in use.\n", unitNumber ); return 0; } /* ** Get this unit's rx/tx event */ sc->ioevent = unit_signals[unitNumber-1]; /* ** Save the buffer counts */ sc->numRxbuffers = (config->rbuf_count) ? config->rbuf_count : NRXBUFS; sc->numTxbuffers = (config->xbuf_count) ? config->xbuf_count : NTXBUFS; /* * Get card address spaces & retrieve its isr vector */#if defined(__i386__) /* the 21143 chip must be enabled before it can be accessed */ if ( deviceId == PCI_DEVICE_ID_DEC_21143 ) pcib_conf_write32( signature, 0x40, 0 ); pcib_conf_read32(signature, 16, &value); sc->port = value & ~IO_MASK; pcib_conf_read32(signature, 20, &value); if (_CPU_is_paging_enabled()) _CPU_map_phys_address((void **) &(sc->base), (void *)(value & ~MEM_MASK), DEC_REGISTER_SIZE , PTE_CACHE_DISABLE | PTE_WRITABLE); else sc->base = (unsigned int *)(value & ~MEM_MASK); pcib_conf_read8(signature, 60, &interrupt); cvalue = interrupt;#endif#if defined(__PPC) (void)pci_read_config_dword(pbus, pdev, pfun, PCI_BASE_ADDRESS_0, &lvalue); sc->port = lvalue & (unsigned int)(~IO_MASK); (void)pci_read_config_dword(pbus, pdev, pfun, PCI_BASE_ADDRESS_1, &lvalue); tmp = (unsigned int)(lvalue & (unsigned int)(~MEM_MASK)) + (unsigned int)PCI_MEM_BASE_ADJUSTMENT; sc->base = (unsigned int *)(tmp); pci_read_config_byte(pbus, pdev, pfun, PCI_INTERRUPT_LINE, &cvalue);#endif /* ** Prep the board */#if defined(__PPC) pci_write_config_word(pbus, pdev, pfun, PCI_COMMAND, (unsigned16) ( PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER ) );#endif#if defined(__i386__) pcib_conf_write16(signature, 0x04, ( 0x2 | 0x4 | 0x10 | 0x80 | 0x200) );#endif /* ** Store the interrupt name, we'll use it later when we initialize ** the board. */ memset(&sc->irqInfo,0,sizeof(rtems_irq_connect_data)); sc->irqInfo.name = cvalue;#ifdef DEC_DEBUG printk("dec2114x : unit %d base address %08x.\n", unitNumber, sc->base );#endif /* ** Setup ethernet address */ if (config->hardware_address) { memcpy (sc->arpcom.ac_enaddr, config->hardware_address, ETHER_ADDR_LEN); } else { union {char c[64]; unsigned short s[32];} rombuf; int i; for (i=0; i<32; i++){ rombuf.s[i] = eeget16( sc->base + memCSR9, i); }#if defined(__i386__) for (i=0 ; i<(ETHER_ADDR_LEN/2); i++){ sc->arpcom.ac_enaddr[2*i] = rombuf.c[20+2*i+1]; sc->arpcom.ac_enaddr[2*i+1] = rombuf.c[20+2*i]; } #endif#if defined(__PPC) memcpy (sc->arpcom.ac_enaddr, rombuf.c+20, ETHER_ADDR_LEN);#endif } if (config->mtu) mtu = config->mtu; else mtu = ETHERMTU; sc->acceptBroadcast = !config->ignore_broadcast; /* * Set up network interface values *//* ifp->if_tap = iftap; */ ifp->if_softc = sc; ifp->if_unit = unitNumber; ifp->if_name = unitName; ifp->if_mtu = mtu; ifp->if_init = dec21140_init; ifp->if_ioctl = dec21140_ioctl; ifp->if_start = dec21140_start; ifp->if_output = ether_output; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; if (ifp->if_snd.ifq_maxlen == 0) ifp->if_snd.ifq_maxlen = ifqmaxlen; /* * Attach the interface */ if_attach (ifp); ether_ifattach (ifp);#ifdef DEC_DEBUG printk( "dec2114x : driver attached\n" );#endif /* * Start driver tasks if this is the first dec unit initialized */ if (txDaemonTid == 0) { rxDaemonTid = rtems_bsdnet_newproc( "DCrx", 4096, dec21140_rxDaemon, NULL); txDaemonTid = rtems_bsdnet_newproc( "DCtx", 4096, dec21140_txDaemon, NULL);#ifdef DEC_DEBUG printk( "dec2114x : driver tasks created\n" );#endif } return 1;};#endif /* DEC21140_SUPPORTED *//* eof */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -