⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 am7990.c

📁 很好的一个嵌入式linux平台下的bootloader
💻 C
📖 第 1 页 / 共 3 页
字号:
#if defined(PROM) && defined(LEDEBUG)		ifp->if_flags |= IFF_DEBUG;		sc->sc_debug = 1;#endif		switch (ifa->ifa_addr->sa_family) {#ifdef INET		case AF_INET:			am7990_init(sc);			arp_ifinit(&sc->sc_arpcom, ifa);			break;#endif		default:			am7990_init(sc);			break;		}		break;	case SIOCSIFFLAGS:		if ((ifp->if_flags & IFF_UP) == 0 &&		    (ifp->if_flags & IFF_RUNNING) != 0) {		    /*		     * If interface is marked down and it is running, then		     * stop it.		     */		    am7990_stop(sc);		    ifp->if_flags &= ~IFF_RUNNING;		} else if ((ifp->if_flags & IFF_UP) != 0 &&		    	   (ifp->if_flags & IFF_RUNNING) == 0) {			/*			 * If interface is marked up and it is stopped, then			 * start it.			 */			am7990_init(sc);		} else {			/*			 * Reset the interface to pick up changes in any other			 * flags that affect hardware registers.			 */			/*am7990_stop(sc);*/			am7990_init(sc);		}#ifdef LEDEBUG		if (ifp->if_flags & IFF_DEBUG)			sc->sc_debug = 1;		else			sc->sc_debug = 0;#endif		break;#ifdef SIOCADDMULTI	case SIOCADDMULTI:	case SIOCDELMULTI:		error = (cmd == SIOCADDMULTI) ?		    ether_addmulti(ifr, &sc->sc_arpcom) :		    ether_delmulti(ifr, &sc->sc_arpcom);		if (error == ENETRESET) {			/*			 * Multicast list has changed; set the hardware filter			 * accordingly.			 */			am7990_reset(sc);			error = 0;		}		break;	case SIOCGIFMEDIA:	case SIOCSIFMEDIA:		if (sc->sc_hasifmedia)			error = ifmedia_ioctl(ifp, ifr, &sc->sc_ifmedia, cmd);		else			error = EINVAL;		break;#endif	default:		error = EINVAL;		break;	}	splx(s);	return (error);}hide voidam7990_shutdown(arg)	void *arg;{	am7990_stop((struct am7990_softc *)arg);}#ifdef LEDEBUGvoidam7990_recv_print(sc, no)	struct am7990_softc *sc;	int no;{	struct lermd rmd;	u_int16_t len;	struct ether_header eh;	(*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd));	len = mtohs(rmd.rmd3);	printf("%s: receive buffer %d, len = %d\n", sc->sc_dev.dv_xname, no,	    len);	printf("%s: status %04x\n", sc->sc_dev.dv_xname,	    (*sc->sc_rdcsr)(sc, LE_CSR0));	printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n",	    sc->sc_dev.dv_xname,	    rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits, rmd.rmd2, rmd.rmd3);	if (len >= sizeof(eh)) {		(*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh));		printf("%s: dst %s", sc->sc_dev.dv_xname,			ether_sprintf(eh.ether_dhost));		printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost),			ntohs(eh.ether_type));	}}voidam7990_xmit_print(sc, no)	struct am7990_softc *sc;	int no;{	struct letmd tmd;	u_int16_t len;	struct ether_header eh;	(*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd));	len = -mtohs(tmd.tmd2);	printf("%s: transmit buffer %d, len = %d\n", sc->sc_dev.dv_xname, no,	    len);	printf("%s: status %04x\n", sc->sc_dev.dv_xname,	    (*sc->sc_rdcsr)(sc, LE_CSR0));	printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n",	    sc->sc_dev.dv_xname,	    tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits, tmd.tmd2, tmd.tmd3);	if (len >= sizeof(eh)) {		(*sc->sc_copyfrombuf)(sc, &eh, LE_TBUFADDR(sc, no), sizeof(eh));		printf("%s: dst %s", sc->sc_dev.dv_xname,			ether_sprintf(eh.ether_dhost));		printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost),		    ntohs(eh.ether_type));	}}#endif /* LEDEBUG *//* * Set up the logical address filter. */voidam7990_setladrf(ac, af)	struct arpcom *ac;	u_int16_t *af;{	struct ifnet *ifp = &ac->ac_if;	struct ether_multi *enm;	register u_char *cp, c;	register u_int32_t crc;	register int i, len;#ifndef PROM	struct ether_multistep step;#endif	/*	 * Set up multicast address filter by passing all multicast addresses	 * through a crc generator, and then using the high order 6 bits as an	 * index into the 64 bit logical address filter.  The high order bit	 * selects the word, while the rest of the bits select the bit within	 * the word.	 */	if (ifp->if_flags & IFF_PROMISC)		goto allmulti;	af[0] = af[1] = af[2] = af[3] = 0x0000;#ifndef PROM	ETHER_FIRST_MULTI(step, ac, enm);	while (enm != NULL) {		if (ETHER_CMP(enm->enm_addrlo, enm->enm_addrhi)) {			/*			 * We must listen to a range of multicast addresses.			 * For now, just accept all multicasts, rather than			 * trying to set only those filter bits needed to match			 * the range.  (At this time, the only use of address			 * ranges is for IP multicast routing, for which the			 * range is big enough to require all bits set.)			 */			goto allmulti;		}		cp = enm->enm_addrlo;		crc = 0xffffffff;		for (len = sizeof(enm->enm_addrlo); --len >= 0;) {			c = *cp++;			for (i = 8; --i >= 0;) {				if ((crc & 0x01) ^ (c & 0x01)) {					crc >>= 1;					crc ^= 0xedb88320;				} else					crc >>= 1;				c >>= 1;			}		}		/* Just want the 6 most significant bits. */		crc >>= 26;		/* Set the corresponding bit in the filter. */		af[crc >> 4] |= 1 << (crc & 0xf);		ETHER_NEXT_MULTI(step, enm);	}	ifp->if_flags &= ~IFF_ALLMULTI;	return;#endifallmulti:	ifp->if_flags |= IFF_ALLMULTI;	af[0] = af[1] = af[2] = af[3] = 0xffff;}/* * Routines for accessing the transmit and receive buffers. * The various CPU and adapter configurations supported by this * driver require three different access methods for buffers * and descriptors: *	(1) contig (contiguous data; no padding), *	(2) gap2 (two bytes of data followed by two bytes of padding), *	(3) gap16 (16 bytes of data followed by 16 bytes of padding). *//* * * Buffers must have word alignmenb */voidam7990_copytodesc_contig(sc, from, boff, len)	struct am7990_softc *sc;	void *from;	int boff, len;{	volatile caddr_t buf = sc->sc_mem;	volatile unsigned int *f, *t;	/* special case descriptors to avoid setting owned bit before all descriptors are in place */	if (len == 8) {	    f = (volatile unsigned int *)from;	    t = (volatile unsigned int *)(buf+boff);	    t[1] = f[1];	    t[0] = f[0];	}	else	    bcopy (from, buf + boff, len);}voidam7990_copyfromdesc_contig(sc, to, boff, len)	struct am7990_softc *sc;	void *to;	int boff, len;{	volatile caddr_t buf = sc->sc_mem;	bcopy (buf + boff, to, len);}/* * contig: contiguous data with no padding. * * Buffers may have any alignment. */voidam7990_copytobuf_contig(sc, from, boff, len)	struct am7990_softc *sc;	void *from;	int boff, len;{	volatile caddr_t buf = sc->sc_mem;	/*	 * Just call bcopy() to do the work.	 */	bcopy(from, buf + boff, len);}voidam7990_copyfrombuf_contig(sc, to, boff, len)	struct am7990_softc *sc;	void *to;	int boff, len;{	volatile caddr_t buf = sc->sc_mem;	/*	 * Just call bcopy() to do the work.	 */	bcopy(buf + boff, to, len);}voidam7990_zerobuf_contig(sc, boff, len)	struct am7990_softc *sc;	int boff, len;{	volatile caddr_t buf = sc->sc_mem;	/*	 * Just let bzero() do the work	 */	bzero(buf + boff, len);}#if 0/* * Examples only; duplicate these and tweak (if necessary) in * machine-specific front-ends. *//* * gap2: two bytes of data followed by two bytes of pad. * * Buffers must be 4-byte aligned.  The code doesn't worry about * doing an extra byte. */voidam7990_copytobuf_gap2(sc, fromv, boff, len)	struct am7990_softc *sc;	void *fromv;	int boff;	register int len;{	volatile caddr_t buf = sc->sc_mem;	register caddr_t from = fromv;	register volatile u_int16_t *bptr;	if (boff & 0x1) {		/* handle unaligned first byte */		bptr = ((volatile u_int16_t *)buf) + (boff - 1);		*bptr = (*from++ << 8) | (*bptr & 0xff);		bptr += 2;		len--;	} else		bptr = ((volatile u_int16_t *)buf) + boff;	while (len > 1) {		*bptr = (from[1] << 8) | (from[0] & 0xff);		bptr += 2;		from += 2;		len -= 2;	}	if (len == 1)		*bptr = (u_int16_t)*from;}voidam7990_copyfrombuf_gap2(sc, tov, boff, len)	struct am7990_softc *sc;	void *tov;	int boff, len;{	volatile caddr_t buf = sc->sc_mem;	register caddr_t to = tov;	register volatile u_int16_t *bptr;	register u_int16_t tmp;	if (boff & 0x1) {		/* handle unaligned first byte */		bptr = ((volatile u_int16_t *)buf) + (boff - 1);		*to++ = (*bptr >> 8) & 0xff;		bptr += 2;		len--;	} else		bptr = ((volatile u_int16_t *)buf) + boff;	while (len > 1) {		tmp = *bptr;		*to++ = tmp & 0xff;		*to++ = (tmp >> 8) & 0xff;		bptr += 2;		len -= 2;	}	if (len == 1)		*to = *bptr & 0xff;}voidam7990_zerobuf_gap2(sc, boff, len)	struct am7990_softc *sc;	int boff, len;{	volatile caddr_t buf = sc->sc_mem;	register volatile u_int16_t *bptr;	if ((unsigned)boff & 0x1) {		bptr = ((volatile u_int16_t *)buf) + (boff - 1);		*bptr &= 0xff;		bptr += 2;		len--;	} else		bptr = ((volatile u_int16_t *)buf) + boff;	while (len > 0) {		*bptr = 0;		bptr += 2;		len -= 2;	}}/* * gap16: 16 bytes of data followed by 16 bytes of pad. * * Buffers must be 32-byte aligned. */voidam7990_copytobuf_gap16(sc, fromv, boff, len)	struct am7990_softc *sc;	void *fromv;	int boff;	register int len;{	volatile caddr_t buf = sc->sc_mem;	register caddr_t from = fromv;	register caddr_t bptr;	register int xfer;	bptr = buf + ((boff << 1) & ~0x1f);	boff &= 0xf;	xfer = min(len, 16 - boff);	while (len > 0) {		bcopy(from, bptr + boff, xfer);		from += xfer;		bptr += 32;		boff = 0;		len -= xfer;		xfer = min(len, 16);	}}voidam7990_copyfrombuf_gap16(sc, tov, boff, len)	struct am7990_softc *sc;	void *tov;	int boff, len;{	volatile caddr_t buf = sc->sc_mem;	register caddr_t to = tov;	register caddr_t bptr;	register int xfer;	bptr = buf + ((boff << 1) & ~0x1f);	boff &= 0xf;	xfer = min(len, 16 - boff);	while (len > 0) {		bcopy(bptr + boff, to, xfer);		to += xfer;		bptr += 32;		boff = 0;		len -= xfer;		xfer = min(len, 16);	}}voidam7990_zerobuf_gap16(sc, boff, len)	struct am7990_softc *sc;	int boff, len;{	volatile caddr_t buf = sc->sc_mem;	register caddr_t bptr;	register int xfer;	bptr = buf + ((boff << 1) & ~0x1f);	boff &= 0xf;	xfer = min(len, 16 - boff);	while (len > 0) {		bzero(bptr + boff, xfer);		bptr += 32;		boff = 0;		len -= xfer;		xfer = min(len, 16);	}}#endif /* Example only */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -