Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178017626
D62076.1795767438.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
D62076.1795767438.diff
View Options
diff --git a/sys/dev/rge/if_rge.c b/sys/dev/rge/if_rge.c
--- a/sys/dev/rge/if_rge.c
+++ b/sys/dev/rge/if_rge.c
@@ -38,7 +38,11 @@
#include <sys/kernel.h>
#include <netinet/in.h>
+#include <netinet/ip.h>
+#include <netinet/ip6.h>
+#include <netinet/ip_var.h>
#include <netinet/if_ether.h>
+#include <netinet/udp.h>
#include <net/bpf.h>
#include <net/ethernet.h>
@@ -53,6 +57,7 @@
#include <machine/bus.h>
#include <machine/resource.h>
+#include <machine/in_cksum.h>
#include <dev/mii/mii.h>
@@ -101,6 +106,7 @@
static void rge_iff_locked(struct rge_softc *);
static void rge_add_media_types(struct rge_softc *);
static void rge_tx_task(void *, int);
+static int rge_tx_pad(struct rge_softc *, struct mbuf **);
static void rge_txq_flush_mbufs(struct rge_softc *sc);
static void rge_tick(void *);
static void rge_link_state(struct rge_softc *);
@@ -796,6 +802,11 @@
RGE_ASSERT_LOCKED(sc);
+ if (rge_tx_pad(sc, mp)) {
+ /* XXX: Should we incr a stat here??*/
+ return (-1);
+ }
+
m = *mp;
txq = &q->q_tx.rge_txq[idx];
txmap = txq->txq_dmamap;
@@ -2592,6 +2603,134 @@
callout_reset(&sc->sc_timeout, hz, rge_tick, sc);
}
+static int
+rge_tx_pad(struct rge_softc *sc, struct mbuf **mp)
+{
+ struct mbuf *m = *mp, *n;
+ struct ether_vlan_header evh;
+ struct ip ip;
+ struct ip6_hdr ip6;
+ uint16_t etype = 0, port;
+ uint8_t proto = 0;
+ int ehlen = ETHER_HDR_LEN, hdrlen = 0;
+ int udplen, totlen, padlen = 0;
+ bool is_ipv4 = false;
+
+ totlen = m->m_pkthdr.len;
+
+ /*
+ * Copy the headers out, if anything is too short to parse,
+ * proto stays 0 and only the 60-byte pad below can apply
+ */
+ if (totlen >= ETHER_HDR_LEN) {
+ m_copydata(m, 0, MIN(totlen, (int)sizeof(evh)), &evh);
+ etype = ntohs(evh.evl_encap_proto);
+
+ /* We can't forget about VLAN's extra 4 Bytes */
+ if (etype == ETHERTYPE_VLAN) {
+ if (totlen >= (int)sizeof(evh)) {
+ etype = ntohs(evh.evl_proto);
+ ehlen += ETHER_VLAN_ENCAP_LEN;
+ } else
+ etype = 0;
+ }
+
+ switch (etype) {
+ case ETHERTYPE_IP:
+ if (totlen < ehlen + (int)sizeof(ip))
+ break;
+ m_copydata(m, ehlen, sizeof(ip), &ip);
+ hdrlen = ehlen + (ip.ip_hl << 2);
+ proto = ip.ip_p;
+ is_ipv4 = true;
+ break;
+ case ETHERTYPE_IPV6:
+ if (totlen < ehlen + (int)sizeof(ip6))
+ break;
+ m_copydata(m, ehlen, sizeof(ip6), &ip6);
+ hdrlen = ehlen + sizeof(ip6);
+ proto = ip6.ip6_nxt;
+ break;
+ }
+ }
+
+ /*
+ * Workaround for a bug in RTL8125/RTL8125B.
+ * The chip hangs when a short UDP frame reads port 319 or 320
+ * with fewer than 47 bytes of data.
+ */
+ if ((sc->rge_type == MAC_R25 || sc->rge_type == MAC_R25B) &&
+ totlen < 128 + RGE_MIN_PATCHLEN && proto == IPPROTO_UDP) {
+ udplen = totlen - hdrlen;
+ if (udplen > 3 && udplen < RGE_MIN_PATCHLEN) {
+ m_copydata(m,
+ hdrlen + offsetof(struct udphdr, uh_dport),
+ sizeof(port), &port);
+ port = ntohs(port);
+ if (port == 319 || port == 320)
+ padlen = RGE_MIN_PATCHLEN - udplen;
+ }
+ if (udplen < (int)sizeof(struct udphdr))
+ padlen = MAX(padlen,
+ (int)sizeof(struct udphdr) - udplen);
+ }
+
+ /*
+ * MAC does not checksum transmit packets that are fewer than
+ * 60 bytes correctly.
+ */
+ if (totlen + padlen < RGE_MIN_FRAMELEN)
+ padlen = RGE_MIN_FRAMELEN - totlen;
+
+ if (padlen > 0) {
+ if (m->m_pkthdr.csum_flags & RGE_CSUM_FEATURES) {
+ /*
+ * Unshare as we are going to write into the packet's cksum
+ */
+ m = m_unshare(m, M_NOWAIT);
+ if (m == NULL) {
+ *mp = NULL;
+ return (ENOBUFS);
+ }
+ if (is_ipv4) {
+ m = m_pullup(m, hdrlen);
+ if (m == NULL) {
+ *mp = NULL;
+ return (ENOBUFS);
+ }
+ }
+ *mp = m;
+
+ if (is_ipv4) {
+ struct ip *ipp = (struct ip *)mtodo(m, ehlen);
+
+ if (m->m_pkthdr.csum_flags & CSUM_IP) {
+ ipp->ip_sum = 0;
+ ipp->ip_sum = in_cksum_skip(m,
+ hdrlen, ehlen);
+ }
+ if (m->m_pkthdr.csum_flags &
+ (CSUM_TCP | CSUM_UDP))
+ in_delayed_cksum_o(m, ehlen);
+ }
+ /* No ipv6 logic as we only support offloading ipv4 */
+
+ m->m_pkthdr.csum_flags &= ~RGE_CSUM_FEATURES;
+ }
+
+ MGET(n, M_NOWAIT, MT_DATA);
+ if (n == NULL)
+ return (ENOBUFS);
+
+ memset(mtod(n, caddr_t), 0, padlen);
+ n->m_len = padlen;
+ m_cat(m, n);
+ m->m_pkthdr.len += padlen;
+ }
+
+ return (0);
+}
+
/**
* @brief process a link state change.
*
diff --git a/sys/dev/rge/if_rgereg.h b/sys/dev/rge/if_rgereg.h
--- a/sys/dev/rge/if_rgereg.h
+++ b/sys/dev/rge/if_rgereg.h
@@ -385,6 +385,8 @@
#define RGE_JUMBO_MTU \
(RGE_JUMBO_FRAMELEN - ETHER_HDR_LEN - ETHER_CRC_LEN - \
ETHER_VLAN_ENCAP_LEN)
+#define RGE_MIN_FRAMELEN (ETHER_MIN_LEN - ETHER_CRC_LEN)
+#define RGE_MIN_PATCHLEN 47 /* "Vendor Magic" - OpenBSD */
#define RGE_TXCFG_CONFIG 0x03000700
#define RGE_RXCFG_CONFIG 0x41000700
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 27, 8:17 AM (21 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42040397
Default Alt Text
D62076.1795767438.diff (4 KB)
Attached To
Mode
D62076: rge(4): Implement RTL8125 UDP hardware workaround
Attached
Detach File
Event Timeline