Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Dec 2000 13:27:28 -0800 (PST)
From:      wpaul@FreeBSD.ORG (Bill Paul)
To:        jhb@FreeBSD.org (John Baldwin)
Cc:        wkb@freebie.demon.nl, alpha@FreeBSD.org
Subject:   Re: cvs commit: src/sys/alpha/conf GENERIC
Message-ID:  <20001208212728.9D8D737B400@hub.freebsd.org>
In-Reply-To: <XFMail.001208131116.jhb@FreeBSD.org> from John Baldwin at "Dec 8, 2000 01:11:16 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
Ok. There's something about the way the descriptor memory is being
allocated that I don't like. I can't quite put my finger on what it
is. I usually resort to contigmalloc() when I allocate descriptor
space; it's not always necessary but it helps me sleep at night. Plus
you know you're getting memory that's aligned on the right boundary.

Wilko: please try me the following patch to if_tx.c. In addition to
tweaking the descriptor allocation, I added some code to force the
proper payload alignment on received packets. I'm not positive, but
I think you need this for this chip too.

-Bill


*** if_tx.c.orig	Thu Dec  7 15:56:26 2000
--- if_tx.c	Fri Dec  8 13:23:47 2000
***************
*** 567,573 ****
  {
  	struct ifnet *ifp;
  	epic_softc_t *sc;
! 	int s;
  
  	s = splimp();
  
--- 567,573 ----
  {
  	struct ifnet *ifp;
  	epic_softc_t *sc;
! 	int s, i;
  
  	s = splimp();
  
***************
*** 585,591 ****
  	bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
  	bus_release_resource(dev, EPIC_RES, EPIC_RID, sc->res);
  
! 	free(sc->pool, M_DEVBUF);
  
  	splx(s);
  
--- 585,595 ----
  	bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
  	bus_release_resource(dev, EPIC_RES, EPIC_RID, sc->res);
  
! 	i = sizeof(struct epic_frag_list)*TX_RING_SIZE +
! 	    sizeof(struct epic_rx_desc)*RX_RING_SIZE + 
! 	    sizeof(struct epic_tx_desc)*TX_RING_SIZE + PAGE_SIZE;
! 
! 	contigfree(sc->pool, i, M_DEVBUF);
  
  	splx(s);
  
***************
*** 746,753 ****
  
  	i = sizeof(struct epic_frag_list)*TX_RING_SIZE +
  	    sizeof(struct epic_rx_desc)*RX_RING_SIZE + 
! 	    sizeof(struct epic_tx_desc)*TX_RING_SIZE + PAGE_SIZE,
! 	sc->pool = (epic_softc_t *) malloc( i, M_DEVBUF, M_NOWAIT);
  
  	if (sc->pool == NULL) {
  		printf(": can't allocate memory for buffers\n");
--- 750,759 ----
  
  	i = sizeof(struct epic_frag_list)*TX_RING_SIZE +
  	    sizeof(struct epic_rx_desc)*RX_RING_SIZE + 
! 	    sizeof(struct epic_tx_desc)*TX_RING_SIZE;
! 
! 	sc->pool = (epic_softc_t *)contigmalloc(i, M_DEVBUF,
! 	    M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
  
  	if (sc->pool == NULL) {
  		printf(": can't allocate memory for buffers\n");
***************
*** 755,763 ****
  	}
  	bzero(sc->pool, i);
  
- 	/* Align pool on PAGE_SIZE */
  	pool = (caddr_t)sc->pool;
- 	pool = (caddr_t)((u_int32_t)(pool + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1));
  
  	/* Distribute memory */
  	sc->tx_flist = (void *)pool;
--- 761,767 ----
***************
*** 879,884 ****
--- 883,891 ----
  	struct epic_rx_desc *desc;
  	struct mbuf *m;
  	struct ether_header *eh;
+ 	struct ifnet *ifp;
+ 
+ 	ifp = &sc->sc_if;
  
  	while( !(sc->rx_desc[sc->cur_rx].status & 0x8000) ) { 
  		buf = sc->rx_buffer + sc->cur_rx;
***************
*** 914,924 ****
  		/* Point to new mbuf, and give descriptor to chip */
  		desc->bufaddr = vtophys( mtod( buf->mbuf, caddr_t ) );
  		desc->status = 0x8000;
! 		
! 		/* First mbuf in packet holds the ethernet and packet headers */
! 		eh = mtod( m, struct ether_header * );
! 		m->m_pkthdr.rcvif = &(sc->sc_if);
! 		m->m_pkthdr.len = m->m_len = len;
  
  #if !defined(__FreeBSD__)
  #if NBPFILTER > 0
--- 921,946 ----
  		/* Point to new mbuf, and give descriptor to chip */
  		desc->bufaddr = vtophys( mtod( buf->mbuf, caddr_t ) );
  		desc->status = 0x8000;
! 
! 		/* Force payload to be longword aligned. */
! 		{
! 			struct mbuf		*m0;
! 
! 			m0 = m_devget(mtod(m, char *) - ETHER_ALIGN,
! 			    len + ETHER_ALIGN, 0, ifp, NULL);
! 
! 			if (m0 == NULL) {
! 				ifp->if_ierrors++;
! 				m_freem(m);
! 				continue;
! 			}
! 
! 			m_adj(m0, ETHER_ALIGN);
! 			m_freem(m);
! 			m = m0;
! 		}
! 
! 		eh = mtod(m, struct ether_header *);
  
  #if !defined(__FreeBSD__)
  #if NBPFILTER > 0
***************
*** 928,936 ****
  #endif /* NBPFILTER > 0 */
  #endif /* !__FreeBSD__ */
  
! 		/* Second mbuf holds packet ifself */
! 		m->m_pkthdr.len = m->m_len = len - sizeof(struct ether_header);
! 		m->m_data += sizeof( struct ether_header );
  
  		/* Give mbuf to OS */
  		ether_input(&sc->sc_if, eh, m);
--- 950,956 ----
  #endif /* NBPFILTER > 0 */
  #endif /* !__FreeBSD__ */
  
! 		m_adj(m, sizeof(struct ether_header));
  
  		/* Give mbuf to OS */
  		ether_input(&sc->sc_if, eh, m);


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-alpha" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001208212728.9D8D737B400>