Clean up the buffer allocation code a bit. Make sure to initialize certain

critical mbuf fields to sane values. Simplify the use of ETHER_ALIGN to
enforce payload alignment, and turn it on on the x86 as well as alpha
since it helps with NFS which wants the payload to be longword aligned
even though the hardware doesn't require it.

This fixes a problem with the ti driver causing an unaligned access trap
on the Alpha due to m_adj() sometimes not setting the alignment correctly
because of incomplete mbuf initialization.
This commit is contained in:
wpaul 1999-07-23 18:46:24 +00:00
parent b934da313f
commit e4620300d6
4 changed files with 64 additions and 58 deletions

View File

@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: if_ti.c,v 1.10 1999/07/23 02:10:11 wpaul Exp $
* $Id: if_ti.c,v 1.11 1999/07/23 16:21:43 wpaul Exp $
*/
/*
@ -131,7 +131,7 @@
#if !defined(lint)
static const char rcsid[] =
"$Id: if_ti.c,v 1.10 1999/07/23 02:10:11 wpaul Exp $";
"$Id: if_ti.c,v 1.11 1999/07/23 16:21:43 wpaul Exp $";
#endif
/*
@ -692,7 +692,7 @@ static void ti_jref(buf, size)
if (sc == NULL)
panic("ti_jref: can't find softc pointer!");
if (size != TI_JUMBO_FRAMELEN - ETHER_ALIGN)
if (size != TI_JUMBO_FRAMELEN)
panic("ti_jref: adjusting refcount of buf of wrong size!");
/* calculate the slot this buffer belongs to */
@ -730,7 +730,7 @@ static void ti_jfree(buf, size)
if (sc == NULL)
panic("ti_jfree: can't find softc pointer!");
if (size != TI_JUMBO_FRAMELEN - ETHER_ALIGN)
if (size != TI_JUMBO_FRAMELEN)
panic("ti_jfree: freeing buffer of wrong size!");
/* calculate the slot this buffer belongs to */
@ -771,9 +771,7 @@ static int ti_newbuf_std(sc, i, m)
struct mbuf *m_new = NULL;
struct ti_rx_desc *r;
if (m != NULL) {
m_new = m;
} else {
if (m == NULL) {
MGETHDR(m_new, M_DONTWAIT, MT_DATA);
if (m_new == NULL) {
printf("ti%d: mbuf allocation failed "
@ -788,6 +786,11 @@ static int ti_newbuf_std(sc, i, m)
m_freem(m_new);
return(ENOBUFS);
}
m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
} else {
m_new = m;
m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
m_new->m_data = m_new->m_ext.ext_buf;
}
m_adj(m_new, ETHER_ALIGN);
@ -800,7 +803,7 @@ static int ti_newbuf_std(sc, i, m)
#else
r->ti_flags = 0;
#endif
r->ti_len = MCLBYTES - ETHER_ALIGN;
r->ti_len = m_new->m_len;
r->ti_idx = i;
return(0);
@ -818,16 +821,20 @@ static int ti_newbuf_mini(sc, i, m)
struct mbuf *m_new = NULL;
struct ti_rx_desc *r;
if (m != NULL) {
m_new = m;
} else {
if (m == NULL) {
MGETHDR(m_new, M_DONTWAIT, MT_DATA);
if (m_new == NULL) {
printf("ti%d: mbuf allocation failed "
"-- packet dropped!\n", sc->ti_unit);
return(ENOBUFS);
}
m_new->m_len = m_new->m_pkthdr.len = MHLEN;
} else {
m_new = m;
m_new->m_data = m_new->m_pktdat;
m_new->m_len = m_new->m_pkthdr.len = MHLEN;
}
m_adj(m_new, ETHER_ALIGN);
r = &sc->ti_rdata->ti_rx_mini_ring[i];
sc->ti_cdata.ti_rx_mini_chain[i] = m_new;
@ -837,7 +844,7 @@ static int ti_newbuf_mini(sc, i, m)
#ifdef TI_CSUM_OFFLOAD
r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM|TI_BDFLAG_IP_CKSUM;
#endif
r->ti_len = MHLEN - ETHER_ALIGN;
r->ti_len = m_new->m_len;
r->ti_idx = i;
return(0);
@ -855,9 +862,7 @@ static int ti_newbuf_jumbo(sc, i, m)
struct mbuf *m_new = NULL;
struct ti_rx_desc *r;
if (m != NULL) {
m_new = m;
} else {
if (m == NULL) {
caddr_t *buf = NULL;
/* Allocate the mbuf. */
@ -879,13 +884,18 @@ static int ti_newbuf_jumbo(sc, i, m)
/* Attach the buffer to the mbuf. */
m_new->m_data = m_new->m_ext.ext_buf = (void *)buf;
m_new->m_data += ETHER_ALIGN;
m_new->m_flags |= M_EXT;
m_new->m_ext.ext_size = TI_JUMBO_FRAMELEN - ETHER_ALIGN;
m_new->m_len = m_new->m_pkthdr.len =
m_new->m_ext.ext_size = TI_JUMBO_FRAMELEN;
m_new->m_ext.ext_free = ti_jfree;
m_new->m_ext.ext_ref = ti_jref;
} else {
m_new = m;
m_new->m_data = m_new->m_ext.ext_buf;
m_new->m_ext.ext_size = TI_JUMBO_FRAMELEN;
}
m_adj(m, ETHER_ALIGN);
/* Set up the descriptor. */
r = &sc->ti_rdata->ti_rx_jumbo_ring[i];
sc->ti_cdata.ti_rx_jumbo_chain[i] = m_new;
@ -895,7 +905,7 @@ static int ti_newbuf_jumbo(sc, i, m)
#ifdef TI_CSUM_OFFLOAD
r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM|TI_BDFLAG_IP_CKSUM;
#endif
r->ti_len = TI_JUMBO_FRAMELEN - ETHER_ALIGN;
r->ti_len = m_new->m_len;
r->ti_idx = i;
return(0);
@ -1412,7 +1422,7 @@ static int ti_gibinit(sc)
rcb = &sc->ti_rdata->ti_info.ti_jumbo_rx_rcb;
TI_HOSTADDR(rcb->ti_hostaddr) =
vtophys(&sc->ti_rdata->ti_rx_jumbo_ring);
rcb->ti_max_len = TI_JUMBO_FRAMELEN - ETHER_ALIGN;
rcb->ti_max_len = TI_JUMBO_FRAMELEN;
rcb->ti_flags = 0;
#ifdef TI_CSUM_OFFLOAD
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM|TI_RCB_FLAG_IP_CKSUM;

View File

@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: if_tireg.h,v 1.6 1999/07/23 02:10:11 wpaul Exp $
* $Id: if_tireg.h,v 1.7 1999/07/23 02:17:59 wpaul Exp $
*/
/*
@ -801,17 +801,10 @@ struct ti_tx_desc {
* boundary.
*/
#ifdef __alpha__
#define ETHER_ALIGN 2
#endif
#ifdef __i386__
#define ETHER_ALIGN 0
#endif
#define TI_FRAMELEN 1518
#define TI_JUMBO_FRAMELEN 9018 + ETHER_ALIGN
#define TI_JUMBO_FRAMELEN 9018
#define TI_JUMBO_MTU (TI_JUMBO_FRAMELEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
#define TI_PAGE_SIZE PAGE_SIZE
#define TI_MIN_FRAMELEN 60
@ -1035,7 +1028,7 @@ struct ti_event_desc {
#define TI_MSLOTS 256
#define TI_JSLOTS 256
#define TI_JRAWLEN (TI_JUMBO_FRAMELEN + sizeof(u_int64_t))
#define TI_JRAWLEN (TI_JUMBO_FRAMELEN + ETHER_ALIGN + sizeof(u_int64_t))
#define TI_JLEN (TI_JRAWLEN + (sizeof(u_int64_t) - \
(TI_JRAWLEN % sizeof(u_int64_t))))
#define TI_JPAGESZ PAGE_SIZE

View File

@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: if_ti.c,v 1.10 1999/07/23 02:10:11 wpaul Exp $
* $Id: if_ti.c,v 1.11 1999/07/23 16:21:43 wpaul Exp $
*/
/*
@ -131,7 +131,7 @@
#if !defined(lint)
static const char rcsid[] =
"$Id: if_ti.c,v 1.10 1999/07/23 02:10:11 wpaul Exp $";
"$Id: if_ti.c,v 1.11 1999/07/23 16:21:43 wpaul Exp $";
#endif
/*
@ -692,7 +692,7 @@ static void ti_jref(buf, size)
if (sc == NULL)
panic("ti_jref: can't find softc pointer!");
if (size != TI_JUMBO_FRAMELEN - ETHER_ALIGN)
if (size != TI_JUMBO_FRAMELEN)
panic("ti_jref: adjusting refcount of buf of wrong size!");
/* calculate the slot this buffer belongs to */
@ -730,7 +730,7 @@ static void ti_jfree(buf, size)
if (sc == NULL)
panic("ti_jfree: can't find softc pointer!");
if (size != TI_JUMBO_FRAMELEN - ETHER_ALIGN)
if (size != TI_JUMBO_FRAMELEN)
panic("ti_jfree: freeing buffer of wrong size!");
/* calculate the slot this buffer belongs to */
@ -771,9 +771,7 @@ static int ti_newbuf_std(sc, i, m)
struct mbuf *m_new = NULL;
struct ti_rx_desc *r;
if (m != NULL) {
m_new = m;
} else {
if (m == NULL) {
MGETHDR(m_new, M_DONTWAIT, MT_DATA);
if (m_new == NULL) {
printf("ti%d: mbuf allocation failed "
@ -788,6 +786,11 @@ static int ti_newbuf_std(sc, i, m)
m_freem(m_new);
return(ENOBUFS);
}
m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
} else {
m_new = m;
m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
m_new->m_data = m_new->m_ext.ext_buf;
}
m_adj(m_new, ETHER_ALIGN);
@ -800,7 +803,7 @@ static int ti_newbuf_std(sc, i, m)
#else
r->ti_flags = 0;
#endif
r->ti_len = MCLBYTES - ETHER_ALIGN;
r->ti_len = m_new->m_len;
r->ti_idx = i;
return(0);
@ -818,16 +821,20 @@ static int ti_newbuf_mini(sc, i, m)
struct mbuf *m_new = NULL;
struct ti_rx_desc *r;
if (m != NULL) {
m_new = m;
} else {
if (m == NULL) {
MGETHDR(m_new, M_DONTWAIT, MT_DATA);
if (m_new == NULL) {
printf("ti%d: mbuf allocation failed "
"-- packet dropped!\n", sc->ti_unit);
return(ENOBUFS);
}
m_new->m_len = m_new->m_pkthdr.len = MHLEN;
} else {
m_new = m;
m_new->m_data = m_new->m_pktdat;
m_new->m_len = m_new->m_pkthdr.len = MHLEN;
}
m_adj(m_new, ETHER_ALIGN);
r = &sc->ti_rdata->ti_rx_mini_ring[i];
sc->ti_cdata.ti_rx_mini_chain[i] = m_new;
@ -837,7 +844,7 @@ static int ti_newbuf_mini(sc, i, m)
#ifdef TI_CSUM_OFFLOAD
r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM|TI_BDFLAG_IP_CKSUM;
#endif
r->ti_len = MHLEN - ETHER_ALIGN;
r->ti_len = m_new->m_len;
r->ti_idx = i;
return(0);
@ -855,9 +862,7 @@ static int ti_newbuf_jumbo(sc, i, m)
struct mbuf *m_new = NULL;
struct ti_rx_desc *r;
if (m != NULL) {
m_new = m;
} else {
if (m == NULL) {
caddr_t *buf = NULL;
/* Allocate the mbuf. */
@ -879,13 +884,18 @@ static int ti_newbuf_jumbo(sc, i, m)
/* Attach the buffer to the mbuf. */
m_new->m_data = m_new->m_ext.ext_buf = (void *)buf;
m_new->m_data += ETHER_ALIGN;
m_new->m_flags |= M_EXT;
m_new->m_ext.ext_size = TI_JUMBO_FRAMELEN - ETHER_ALIGN;
m_new->m_len = m_new->m_pkthdr.len =
m_new->m_ext.ext_size = TI_JUMBO_FRAMELEN;
m_new->m_ext.ext_free = ti_jfree;
m_new->m_ext.ext_ref = ti_jref;
} else {
m_new = m;
m_new->m_data = m_new->m_ext.ext_buf;
m_new->m_ext.ext_size = TI_JUMBO_FRAMELEN;
}
m_adj(m, ETHER_ALIGN);
/* Set up the descriptor. */
r = &sc->ti_rdata->ti_rx_jumbo_ring[i];
sc->ti_cdata.ti_rx_jumbo_chain[i] = m_new;
@ -895,7 +905,7 @@ static int ti_newbuf_jumbo(sc, i, m)
#ifdef TI_CSUM_OFFLOAD
r->ti_flags |= TI_BDFLAG_TCP_UDP_CKSUM|TI_BDFLAG_IP_CKSUM;
#endif
r->ti_len = TI_JUMBO_FRAMELEN - ETHER_ALIGN;
r->ti_len = m_new->m_len;
r->ti_idx = i;
return(0);
@ -1412,7 +1422,7 @@ static int ti_gibinit(sc)
rcb = &sc->ti_rdata->ti_info.ti_jumbo_rx_rcb;
TI_HOSTADDR(rcb->ti_hostaddr) =
vtophys(&sc->ti_rdata->ti_rx_jumbo_ring);
rcb->ti_max_len = TI_JUMBO_FRAMELEN - ETHER_ALIGN;
rcb->ti_max_len = TI_JUMBO_FRAMELEN;
rcb->ti_flags = 0;
#ifdef TI_CSUM_OFFLOAD
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM|TI_RCB_FLAG_IP_CKSUM;

View File

@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: if_tireg.h,v 1.6 1999/07/23 02:10:11 wpaul Exp $
* $Id: if_tireg.h,v 1.7 1999/07/23 02:17:59 wpaul Exp $
*/
/*
@ -801,17 +801,10 @@ struct ti_tx_desc {
* boundary.
*/
#ifdef __alpha__
#define ETHER_ALIGN 2
#endif
#ifdef __i386__
#define ETHER_ALIGN 0
#endif
#define TI_FRAMELEN 1518
#define TI_JUMBO_FRAMELEN 9018 + ETHER_ALIGN
#define TI_JUMBO_FRAMELEN 9018
#define TI_JUMBO_MTU (TI_JUMBO_FRAMELEN-ETHER_HDR_LEN-ETHER_CRC_LEN)
#define TI_PAGE_SIZE PAGE_SIZE
#define TI_MIN_FRAMELEN 60
@ -1035,7 +1028,7 @@ struct ti_event_desc {
#define TI_MSLOTS 256
#define TI_JSLOTS 256
#define TI_JRAWLEN (TI_JUMBO_FRAMELEN + sizeof(u_int64_t))
#define TI_JRAWLEN (TI_JUMBO_FRAMELEN + ETHER_ALIGN + sizeof(u_int64_t))
#define TI_JLEN (TI_JRAWLEN + (sizeof(u_int64_t) - \
(TI_JRAWLEN % sizeof(u_int64_t))))
#define TI_JPAGESZ PAGE_SIZE