so, what are we doing with this now?
I still want to hide in_cksum_phdr() and kill in_cksum_addword() so that
nobody ever uses that sh*t again.
yes, sk loses is half-baked cksum offload support with this, as
discussed before.
as naddy pointed out there are (at least) two private copies of
in_cksum_phdr in other drivers, that is a seperate issue in my book if
it is an issue at all, that's not an exposed API (well, for some value
of "exposed", we're talking in-kernel only).
oks?
Index: dev/pci/if_sk.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_sk.c,v
retrieving revision 1.167
diff -u -p -r1.167 if_sk.c
--- dev/pci/if_sk.c 28 Dec 2013 03:36:25 -0000 1.167
+++ dev/pci/if_sk.c 24 Jan 2014 09:16:46 -0000
@@ -180,7 +180,6 @@ void sk_iff_yukon(struct sk_if_softc *);
void sk_tick(void *);
void sk_yukon_tick(void *);
-void sk_rxcsum(struct ifnet *, struct mbuf *, const u_int16_t, const
u_int16_t);
#ifdef SK_DEBUG
#define DPRINTF(x) if (skdebug) printf x
@@ -550,9 +549,6 @@ sk_init_rx_ring(struct sk_if_softc *sc_i
nexti = i + 1;
cd->sk_rx_chain[i].sk_next = &cd->sk_rx_chain[nexti];
rd->sk_rx_ring[i].sk_next = htole32(SK_RX_RING_ADDR(sc_if,
nexti));
- rd->sk_rx_ring[i].sk_csum1_start = htole16(ETHER_HDR_LEN);
- rd->sk_rx_ring[i].sk_csum2_start = htole16(ETHER_HDR_LEN +
- sizeof(struct ip));
}
for (i = 0; i < SK_RX_RING_CNT; i++) {
@@ -1732,7 +1728,6 @@ sk_rxeof(struct sk_if_softc *sc_if)
int i, cur, total_len = 0;
u_int32_t rxstat, sk_ctl;
bus_dmamap_t dmamap;
- u_int16_t csum1, csum2;
DPRINTFN(2, ("sk_rxeof\n"));
@@ -1765,9 +1760,6 @@ sk_rxeof(struct sk_if_softc *sc_if)
cur_rx->sk_mbuf = NULL;
total_len = SK_RXBYTES(letoh32(cur_desc->sk_ctl));
- csum1 = letoh16(sc_if->sk_rdata->sk_rx_ring[i].sk_csum1);
- csum2 = letoh16(sc_if->sk_rdata->sk_rx_ring[i].sk_csum2);
-
SK_INC(i, SK_RX_RING_CNT);
if ((sk_ctl & (SK_RXCTL_STATUS_VALID | SK_RXCTL_FIRSTFRAG |
@@ -1805,8 +1797,6 @@ sk_rxeof(struct sk_if_softc *sc_if)
ifp->if_ipackets++;
- sk_rxcsum(ifp, m, csum1, csum2);
-
#if NBPFILTER > 0
if (ifp->if_bpf)
bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_IN);
@@ -1818,94 +1808,6 @@ sk_rxeof(struct sk_if_softc *sc_if)
}
void
-sk_rxcsum(struct ifnet *ifp, struct mbuf *m, const u_int16_t csum1, const
u_int16_t csum2)
-{
- struct ether_header *eh;
- struct ip *ip;
- u_int8_t *pp;
- int hlen, len, plen;
- u_int16_t iph_csum, ipo_csum, ipd_csum, csum;
-
- pp = mtod(m, u_int8_t *);
- plen = m->m_pkthdr.len;
- if (plen < sizeof(*eh))
- return;
- eh = (struct ether_header *)pp;
- iph_csum = in_cksum_addword(csum1, (~csum2 & 0xffff));
-
- if (eh->ether_type == htons(ETHERTYPE_VLAN)) {
- u_int16_t *xp = (u_int16_t *)pp;
-
- xp = (u_int16_t *)pp;
- if (xp[1] != htons(ETHERTYPE_IP))
- return;
- iph_csum = in_cksum_addword(iph_csum, (~xp[0] & 0xffff));
- iph_csum = in_cksum_addword(iph_csum, (~xp[1] & 0xffff));
- xp = (u_int16_t *)(pp + sizeof(struct ip));
- iph_csum = in_cksum_addword(iph_csum, xp[0]);
- iph_csum = in_cksum_addword(iph_csum, xp[1]);
- pp += EVL_ENCAPLEN;
- } else if (eh->ether_type != htons(ETHERTYPE_IP))
- return;
-
- pp += sizeof(*eh);
- plen -= sizeof(*eh);
-
- ip = (struct ip *)pp;
-
- if (ip->ip_v != IPVERSION)
- return;
-
- hlen = ip->ip_hl << 2;
- if (hlen < sizeof(struct ip))
- return;
- if (hlen > ntohs(ip->ip_len))
- return;
-
- /* Don't deal with truncated or padded packets. */
- if (plen != ntohs(ip->ip_len))
- return;
-
- len = hlen - sizeof(struct ip);
- if (len > 0) {
- u_int16_t *p;
-
- p = (u_int16_t *)(ip + 1);
- ipo_csum = 0;
- for (ipo_csum = 0; len > 0; len -= sizeof(*p), p++)
- ipo_csum = in_cksum_addword(ipo_csum, *p);
- iph_csum = in_cksum_addword(iph_csum, ipo_csum);
- ipd_csum = in_cksum_addword(csum2, (~ipo_csum & 0xffff));
- } else
- ipd_csum = csum2;
-
- if (iph_csum != 0xffff)
- return;
- m->m_pkthdr.csum_flags |= M_IPV4_CSUM_IN_OK;
-
- if (ip->ip_off & htons(IP_MF | IP_OFFMASK))
- return; /* ip frag, we're done for now */
-
- pp += hlen;
-
- /* Only know checksum protocol for udp/tcp */
- if (ip->ip_p == IPPROTO_UDP) {
- struct udphdr *uh = (struct udphdr *)pp;
-
- if (uh->uh_sum == 0) /* udp with no checksum */
- return;
- } else if (ip->ip_p != IPPROTO_TCP)
- return;
-
- csum = in_cksum_phdr(ip->ip_src.s_addr, ip->ip_dst.s_addr,
- htonl(ntohs(ip->ip_len) - hlen + ip->ip_p) + ipd_csum);
- if (csum == 0xffff) {
- m->m_pkthdr.csum_flags |= (ip->ip_p == IPPROTO_TCP) ?
- M_TCP_CSUM_IN_OK : M_UDP_CSUM_IN_OK;
- }
-}
-
-void
sk_txeof(struct sk_if_softc *sc_if)
{
struct sk_softc *sc = sc_if->sk_softc;
@@ -2817,9 +2719,6 @@ sk_dump_txdesc(struct sk_tx_desc *desc,
DESC_PRINT(letoh32(desc->sk_data_hi));
DESC_PRINT(letoh32(desc->sk_xmac_txstat));
DESC_PRINT(letoh16(desc->sk_rsvd0));
- DESC_PRINT(letoh16(desc->sk_csum_startval));
- DESC_PRINT(letoh16(desc->sk_csum_startpos));
- DESC_PRINT(letoh16(desc->sk_csum_writepos));
DESC_PRINT(letoh16(desc->sk_rsvd1));
#undef PRINT
}
Index: netinet/in.h
===================================================================
RCS file: /cvs/src/sys/netinet/in.h,v
retrieving revision 1.102
diff -u -p -r1.102 in.h
--- netinet/in.h 23 Jan 2014 01:10:42 -0000 1.102
+++ netinet/in.h 24 Jan 2014 04:40:44 -0000
@@ -777,53 +777,6 @@ __END_DECLS
#endif
#else
-/*
- * in_cksum_phdr:
- *
- * Compute significant parts of the IPv4 checksum pseudo-header
- * for use in a delayed TCP/UDP checksum calculation.
- *
- * Args:
- *
- * src Source IP address
- * dst Destination IP address
- * lenproto htons(proto-hdr-len + proto-number)
- */
-static __inline u_int16_t __attribute__((__unused__))
-in_cksum_phdr(u_int32_t src, u_int32_t dst, u_int32_t lenproto)
-{
- u_int32_t sum;
-
- sum = lenproto +
- (u_int16_t)(src >> 16) +
- (u_int16_t)(src /*& 0xffff*/) +
- (u_int16_t)(dst >> 16) +
- (u_int16_t)(dst /*& 0xffff*/);
-
- sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/);
-
- if (sum > 0xffff)
- sum -= 0xffff;
-
- return (sum);
-}
-
-/*
- * in_cksum_addword:
- *
- * Add the two 16-bit network-order values, carry, and return.
- */
-static __inline u_int16_t __attribute__((__unused__))
-in_cksum_addword(u_int16_t a, u_int16_t b)
-{
- u_int32_t sum = a + b;
-
- if (sum > 0xffff)
- sum -= 0xffff;
-
- return (sum);
-}
-
extern int inetctlerrmap[];
extern struct ifqueue ipintrq; /* ip packet input queue */
extern struct in_addr zeroin_addr;
Index: netinet/ip_output.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_output.c,v
retrieving revision 1.261
diff -u -p -r1.261 ip_output.c
--- netinet/ip_output.c 14 Apr 2014 09:06:42 -0000 1.261
+++ netinet/ip_output.c 17 Apr 2014 21:28:55 -0000
@@ -74,6 +74,8 @@
struct mbuf *ip_insertoptions(struct mbuf *, struct mbuf *, int *);
void ip_mloopback(struct ifnet *, struct mbuf *, struct sockaddr_in *);
+static __inline u_int16_t __attribute__((__unused__))
+ in_cksum_phdr(u_int32_t, u_int32_t, u_int32_t);
void in_delayed_cksum(struct mbuf *);
/*
@@ -2013,6 +2015,29 @@ ip_mloopback(struct ifnet *ifp, struct m
ip->ip_sum = in_cksum(copym, ip->ip_hl << 2);
(void) looutput(ifp, copym, sintosa(dst), NULL);
}
+}
+
+/*
+ * Compute significant parts of the IPv4 checksum pseudo-header
+ * for use in a delayed TCP/UDP checksum calculation.
+ */
+static __inline u_int16_t __attribute__((__unused__))
+in_cksum_phdr(u_int32_t src, u_int32_t dst, u_int32_t lenproto)
+{
+ u_int32_t sum;
+
+ sum = lenproto +
+ (u_int16_t)(src >> 16) +
+ (u_int16_t)(src /*& 0xffff*/) +
+ (u_int16_t)(dst >> 16) +
+ (u_int16_t)(dst /*& 0xffff*/);
+
+ sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/);
+
+ if (sum > 0xffff)
+ sum -= 0xffff;
+
+ return (sum);
}
/*