summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2015-08-26 09:17:21 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2015-08-26 09:17:21 +0000
commit0f98ea08ea77b115aa15ff2b7b3d133afdfce396 (patch)
treef4a822afcd70c484ec59513612354a6344d5040f
parente1de1d5a903c4a656a14fe8aac2ab5c30825db2f (diff)
Get rid if em_align. This approach used to make sense, but now that the
hardware rx mtu always gets set to the maximum supported value we will hit it for every received packet. Instead, use a larger mbuf cluster size on strict alignment architectures such that we can always m_adj to make sure the packets are properly aligned. This wastes some memory but simplifies things considerably. Hopefully we can reduce the spillage in the near future by taking advantage of recent improvements in the pool code. ok mpi@, mikeb@, dlg@
-rw-r--r--sys/dev/pci/if_em.c71
-rw-r--r--sys/dev/pci/if_em.h14
2 files changed, 16 insertions, 69 deletions
diff --git a/sys/dev/pci/if_em.c b/sys/dev/pci/if_em.c
index 0e530f24d70..dace553b0dd 100644
--- a/sys/dev/pci/if_em.c
+++ b/sys/dev/pci/if_em.c
@@ -31,7 +31,7 @@ POSSIBILITY OF SUCH DAMAGE.
***************************************************************************/
-/* $OpenBSD: if_em.c,v 1.300 2015/08/21 09:16:06 kettenis Exp $ */
+/* $OpenBSD: if_em.c,v 1.301 2015/08/26 09:17:20 kettenis Exp $ */
/* $FreeBSD: if_em.c,v 1.46 2004/09/29 18:28:28 mlaier Exp $ */
#include <dev/pci/if_em.h>
@@ -229,11 +229,6 @@ void em_disable_aspm(struct em_softc *);
void em_txeof(struct em_softc *);
int em_allocate_receive_structures(struct em_softc *);
int em_allocate_transmit_structures(struct em_softc *);
-#ifdef __STRICT_ALIGNMENT
-void em_realign(struct em_softc *, struct mbuf *, u_int16_t *);
-#else
-#define em_realign(a, b, c) /* a, b, c */
-#endif
int em_rxfill(struct em_softc *);
void em_rxeof(struct em_softc *);
void em_receive_checksum(struct em_softc *, struct em_rx_desc *,
@@ -708,7 +703,7 @@ em_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
case SIOCGIFRXR:
error = if_rxr_ioctl((struct if_rxrinfo *)ifr->ifr_data,
- NULL, MCLBYTES, &sc->rx_ring);
+ NULL, EM_MCLBYTES, &sc->rx_ring);
break;
default:
@@ -2528,14 +2523,15 @@ em_get_buf(struct em_softc *sc, int i)
return (ENOBUFS);
}
- m = MCLGETI(NULL, M_DONTWAIT, NULL, MCLBYTES);
+ m = MCLGETI(NULL, M_DONTWAIT, NULL, EM_MCLBYTES);
if (!m) {
sc->mbuf_cluster_failed++;
return (ENOBUFS);
}
- m->m_len = m->m_pkthdr.len = MCLBYTES;
- if (sc->hw.max_frame_size <= (MCLBYTES - ETHER_ALIGN))
- m_adj(m, ETHER_ALIGN);
+ m->m_len = m->m_pkthdr.len = EM_MCLBYTES;
+#ifdef __STRICT_ALIGNMENT
+ m_adj(m, ETHER_ALIGN);
+#endif
error = bus_dmamap_load_mbuf(sc->rxtag, pkt->map, m, BUS_DMA_NOWAIT);
if (error) {
@@ -2584,8 +2580,8 @@ em_allocate_receive_structures(struct em_softc *sc)
rx_buffer = sc->rx_buffer_area;
for (i = 0; i < sc->num_rx_desc; i++, rx_buffer++) {
- error = bus_dmamap_create(sc->rxtag, MCLBYTES, 1,
- MCLBYTES, 0, BUS_DMA_NOWAIT, &rx_buffer->map);
+ error = bus_dmamap_create(sc->rxtag, EM_MCLBYTES, 1,
+ EM_MCLBYTES, 0, BUS_DMA_NOWAIT, &rx_buffer->map);
if (error != 0) {
printf("%s: em_allocate_receive_structures: "
"bus_dmamap_create failed; error %u\n",
@@ -2785,53 +2781,6 @@ em_free_receive_structures(struct em_softc *sc)
}
}
-#ifdef __STRICT_ALIGNMENT
-void
-em_realign(struct em_softc *sc, struct mbuf *m, u_int16_t *prev_len_adj)
-{
- unsigned char tmp_align_buf[ETHER_ALIGN];
- int tmp_align_buf_len = 0;
-
- /*
- * The Ethernet payload is not 32-bit aligned when
- * Jumbo packets are enabled, so on architectures with
- * strict alignment we need to shift the entire packet
- * ETHER_ALIGN bytes. Ugh.
- */
- if (sc->hw.max_frame_size <= (MCLBYTES - ETHER_ALIGN))
- return;
-
- if (*prev_len_adj > sc->align_buf_len)
- *prev_len_adj -= sc->align_buf_len;
- else
- *prev_len_adj = 0;
-
- if (m->m_len > (MCLBYTES - ETHER_ALIGN)) {
- bcopy(m->m_data + (MCLBYTES - ETHER_ALIGN),
- &tmp_align_buf, ETHER_ALIGN);
- tmp_align_buf_len = m->m_len -
- (MCLBYTES - ETHER_ALIGN);
- m->m_len -= ETHER_ALIGN;
- }
-
- if (m->m_len) {
- bcopy(m->m_data, m->m_data + ETHER_ALIGN, m->m_len);
- if (!sc->align_buf_len)
- m->m_data += ETHER_ALIGN;
- }
-
- if (sc->align_buf_len) {
- m->m_len += sc->align_buf_len;
- bcopy(&sc->align_buf, m->m_data, sc->align_buf_len);
- }
-
- if (tmp_align_buf_len)
- bcopy(&tmp_align_buf, &sc->align_buf, tmp_align_buf_len);
-
- sc->align_buf_len = tmp_align_buf_len;
-}
-#endif /* __STRICT_ALIGNMENT */
-
int
em_rxfill(struct em_softc *sc)
{
@@ -2967,8 +2916,6 @@ em_rxeof(struct em_softc *sc)
/* Assign correct length to the current fragment */
m->m_len = len;
- em_realign(sc, m, &prev_len_adj); /* STRICT_ALIGN */
-
if (sc->fmp == NULL) {
m->m_pkthdr.len = m->m_len;
sc->fmp = m; /* Store the first mbuf */
diff --git a/sys/dev/pci/if_em.h b/sys/dev/pci/if_em.h
index da4144784fc..f58051644b7 100644
--- a/sys/dev/pci/if_em.h
+++ b/sys/dev/pci/if_em.h
@@ -32,7 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
***************************************************************************/
/* $FreeBSD: if_em.h,v 1.26 2004/09/01 23:22:41 pdeuskar Exp $ */
-/* $OpenBSD: if_em.h,v 1.55 2015/08/21 09:16:06 kettenis Exp $ */
+/* $OpenBSD: if_em.h,v 1.56 2015/08/26 09:17:20 kettenis Exp $ */
#ifndef _EM_H_DEFINED_
#define _EM_H_DEFINED_
@@ -266,6 +266,12 @@ typedef int boolean_t;
#define EM_RXBUFFER_8192 8192
#define EM_RXBUFFER_16384 16384
+#ifdef __STRICT_ALIGNMENT
+#define EM_MCLBYTES (EM_RXBUFFER_2048 + ETHER_ALIGN)
+#else
+#define EM_MCLBYTES EM_RXBUFFER_2048
+#endif
+
#define EM_MAX_SCATTER 64
#define EM_TSO_SIZE 65535
@@ -324,12 +330,6 @@ struct em_softc {
struct timeout timer_handle;
struct timeout tx_fifo_timer_handle;
-#ifdef __STRICT_ALIGNMENT
- /* Used for carrying forward alignment adjustments */
- unsigned char align_buf[ETHER_ALIGN]; /* tail of unaligned packet */
- u_int8_t align_buf_len; /* bytes in tail */
-#endif /* __STRICT_ALIGNMENT */
-
/* Info about the board itself */
u_int32_t part_num;
u_int8_t link_active;