-/* $OpenBSD: re.c,v 1.85 2008/08/05 01:58:47 brad Exp $ */
+/* $OpenBSD: re.c,v 1.86 2008/08/11 22:42:19 brad Exp $ */
/* $FreeBSD: if_re.c,v 1.31 2004/09/04 07:54:05 ru Exp $ */
/*
* Copyright (c) 1997, 1998-2003
IFQ_SET_MAXLEN(&ifp->if_snd, RL_TX_QLEN);
IFQ_SET_READY(&ifp->if_snd);
-
- ifp->if_capabilities = IFCAP_VLAN_MTU;
- if ((sc->rl_flags & RL_FLAG_DESCV2) == 0)
- ifp->if_capabilities |= IFCAP_CSUM_IPv4 |
- IFCAP_CSUM_TCPv4 | IFCAP_CSUM_UDPv4;
+ ifp->if_capabilities = IFCAP_VLAN_MTU | IFCAP_CSUM_IPv4 |
+ IFCAP_CSUM_TCPv4 | IFCAP_CSUM_UDPv4;
#if NVLAN > 0
ifp->if_capabilities |= IFCAP_VLAN_HWTAGGING;
int i, total_len;
struct rl_desc *cur_rx;
struct rl_rxsoft *rxs;
- u_int32_t rxstat;
+ u_int32_t rxstat, rxvlan;
ifp = &sc->sc_arpcom.ac_if;
RL_RXDESCSYNC(sc, i,
BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
rxstat = letoh32(cur_rx->rl_cmdstat);
+ rxvlan = letoh32(cur_rx->rl_vlanctl);
RL_RXDESCSYNC(sc, i, BUS_DMASYNC_PREREAD);
if ((rxstat & RL_RDESC_STAT_OWN) != 0)
break;
/* Do RX checksumming */
if (sc->rl_flags & RL_FLAG_DESCV2) {
- /* XXX V2 CSUM */
+ /* Check IP header checksum */
+ if ((rxstat & RL_RDESC_STAT_PROTOID) &&
+ !(rxstat & RL_RDESC_STAT_IPSUMBAD) &&
+ (rxvlan & RL_RDESC_IPV4))
+ m->m_pkthdr.csum_flags |= M_IPV4_CSUM_IN_OK;
+
+ /* Check TCP/UDP checksum */
+ if (((rxstat & RL_RDESC_STAT_TCP) &&
+ !(rxstat & RL_RDESC_STAT_TCPSUMBAD)) ||
+ ((rxstat & RL_RDESC_STAT_UDP) &&
+ !(rxstat & RL_RDESC_STAT_UDPSUMBAD)))
+ m->m_pkthdr.csum_flags |= M_TCP_CSUM_IN_OK |
+ M_UDP_CSUM_IN_OK;
} else {
/* Check IP header checksum */
if ((rxstat & RL_RDESC_STAT_PROTOID) &&
bus_dmamap_t map;
int error, seg, nsegs, uidx, startidx, curidx, lastidx, pad;
struct rl_desc *d;
- u_int32_t cmdstat, vlanctl, rl_flags = 0;
+ u_int32_t cmdstat, vlanctl = 0, csum_flags = 0;
struct rl_txq *txq;
#if NVLAN > 0
struct ifvlan *ifv = NULL;
if ((m->m_pkthdr.csum_flags &
(M_IPV4_CSUM_OUT|M_TCPV4_CSUM_OUT|M_UDPV4_CSUM_OUT)) != 0) {
- rl_flags |= RL_TDESC_CMD_IPCSUM;
- if (m->m_pkthdr.csum_flags & M_TCPV4_CSUM_OUT)
- rl_flags |= RL_TDESC_CMD_TCPCSUM;
- if (m->m_pkthdr.csum_flags & M_UDPV4_CSUM_OUT)
- rl_flags |= RL_TDESC_CMD_UDPCSUM;
+ if (sc->rl_flags & RL_FLAG_DESCV2) {
+ vlanctl |= RL_TDESC_CMD_IPCSUMV2;
+ if (m->m_pkthdr.csum_flags & M_TCPV4_CSUM_OUT)
+ vlanctl |= RL_TDESC_CMD_TCPCSUMV2;
+ if (m->m_pkthdr.csum_flags & M_UDPV4_CSUM_OUT)
+ vlanctl |= RL_TDESC_CMD_UDPCSUMV2;
+ } else {
+ csum_flags |= RL_TDESC_CMD_IPCSUM;
+ if (m->m_pkthdr.csum_flags & M_TCPV4_CSUM_OUT)
+ csum_flags |= RL_TDESC_CMD_TCPCSUM;
+ if (m->m_pkthdr.csum_flags & M_UDPV4_CSUM_OUT)
+ csum_flags |= RL_TDESC_CMD_UDPCSUM;
+ }
}
txq = &sc->rl_ldata.rl_txq[*idx];
nsegs = map->dm_nsegs;
pad = 0;
- if (m->m_pkthdr.len <= RL_IP4CSUMTX_PADLEN &&
- (rl_flags & RL_TDESC_CMD_IPCSUM) != 0) {
+ if ((sc->rl_flags & RL_FLAG_DESCV2) == 0 &&
+ m->m_pkthdr.len <= RL_IP4CSUMTX_PADLEN &&
+ (csum_flags & RL_TDESC_CMD_IPCSUM) != 0) {
pad = 1;
nsegs++;
}
* appear in all descriptors of a multi-descriptor
* transmission attempt.
*/
- vlanctl = 0;
#if NVLAN > 0
if (ifv != NULL)
- vlanctl = swap16(ifv->ifv_tag) | RL_TDESC_VLANCTL_TAG;
+ vlanctl |= swap16(ifv->ifv_tag) | RL_TDESC_VLANCTL_TAG;
#endif
/*
d->rl_vlanctl = htole32(vlanctl);
re_set_bufaddr(d, map->dm_segs[seg].ds_addr);
- cmdstat = rl_flags | map->dm_segs[seg].ds_len;
+ cmdstat = csum_flags | map->dm_segs[seg].ds_len;
if (seg == 0)
cmdstat |= RL_TDESC_CMD_SOF;
else
d->rl_vlanctl = htole32(vlanctl);
paddaddr = RL_TXPADDADDR(sc);
re_set_bufaddr(d, paddaddr);
- cmdstat = rl_flags |
+ cmdstat = csum_flags |
RL_TDESC_CMD_OWN | RL_TDESC_CMD_EOF |
(RL_IP4CSUMTX_PADLEN + 1 - m->m_pkthdr.len);
if (curidx == (RL_TX_DESC_CNT(sc) - 1))
-/* $OpenBSD: rtl81x9reg.h,v 1.49 2008/07/15 13:21:17 jsg Exp $ */
+/* $OpenBSD: rtl81x9reg.h,v 1.50 2008/08/11 22:42:19 brad Exp $ */
/*
* Copyright (c) 1997, 1998
#define RL_TDESC_VLANCTL_TAG 0x00020000 /* Insert VLAN tag */
#define RL_TDESC_VLANCTL_DATA 0x0000FFFF /* TAG data */
+/* RTL8168C/RTL8168CP/RTL8111C/RTL8111CP */
+#define RL_TDESC_CMD_IPCSUMV2 0x20000000
+#define RL_TDESC_CMD_TCPCSUMV2 0x40000000
+#define RL_TDESC_CMD_UDPCSUMV2 0x80000000
/*
* Error bits are valid only on the last descriptor of a frame
#define RL_RDESC_STAT_RUNT 0x00080000 /* runt packet received */
#define RL_RDESC_STAT_CRCERR 0x00040000 /* CRC error */
#define RL_RDESC_STAT_PROTOID 0x00030000 /* Protocol type */
+#define RL_RDESC_STAT_UDP 0x00020000 /* UDP, 8168C/CP, 8111C/CP */
+#define RL_RDESC_STAT_TCP 0x00010000 /* TCP, 8168C/CP, 8111C/CP */
#define RL_RDESC_STAT_IPSUMBAD 0x00008000 /* IP header checksum bad */
#define RL_RDESC_STAT_UDPSUMBAD 0x00004000 /* UDP checksum bad */
#define RL_RDESC_STAT_TCPSUMBAD 0x00002000 /* TCP checksum bad */
#define RL_RDESC_VLANCTL_TAG 0x00010000 /* VLAN tag available
(rl_vlandata valid)*/
#define RL_RDESC_VLANCTL_DATA 0x0000FFFF /* TAG data */
+/* RTL8168C/RTL8168CP/RTL8111C/RTL8111CP */
+#define RL_RDESC_IPV6 0x80000000
+#define RL_RDESC_IPV4 0x40000000
#define RL_PROTOID_NONIP 0x00000000
#define RL_PROTOID_TCPIP 0x00010000