Module Name: src Committed By: snj Date: Fri May 1 02:03:44 UTC 2009
Modified Files: src/sys/dev/ic [netbsd-5]: rtl8169.c rtl81x9reg.h rtl81x9var.h Log Message: Pull up following revision(s) (requested by tsutsui in ticket #597): sys/dev/ic/rtl8169.c: revision 1.109 sys/dev/ic/rtl81x9reg.h: revision 1.34 sys/dev/ic/rtl81x9var.h: revision 1.43 Add hardware checksum support for newer PCIe 8168/8111/8102 chips, per device info taken from FreeBSD driver. Tested by snj@ on 8111C. Should closes PR kern/40955. Note on old 8169 chips IP hw csum must be enabled to use TCP/UDP hw csums, but I'm not sure if these newer chips still have the same restriction. To generate a diff of this commit: cvs rdiff -u -r1.105.4.2 -r1.105.4.3 src/sys/dev/ic/rtl8169.c cvs rdiff -u -r1.32.4.1 -r1.32.4.2 src/sys/dev/ic/rtl81x9reg.h cvs rdiff -u -r1.41.12.1 -r1.41.12.2 src/sys/dev/ic/rtl81x9var.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ic/rtl8169.c diff -u src/sys/dev/ic/rtl8169.c:1.105.4.2 src/sys/dev/ic/rtl8169.c:1.105.4.3 --- src/sys/dev/ic/rtl8169.c:1.105.4.2 Thu Mar 26 17:36:03 2009 +++ src/sys/dev/ic/rtl8169.c Fri May 1 02:03:44 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rtl8169.c,v 1.105.4.2 2009/03/26 17:36:03 snj Exp $ */ +/* $NetBSD: rtl8169.c,v 1.105.4.3 2009/05/01 02:03:44 snj Exp $ */ /* * Copyright (c) 1997, 1998-2003 @@ -33,7 +33,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rtl8169.c,v 1.105.4.2 2009/03/26 17:36:03 snj Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rtl8169.c,v 1.105.4.3 2009/05/01 02:03:44 snj Exp $"); /* $FreeBSD: /repoman/r/ncvs/src/sys/dev/re/if_re.c,v 1.20 2004/04/11 20:34:08 ru Exp $ */ /* @@ -592,20 +592,25 @@ break; case RTK_HWREV_8168_SPIN1: sc->sc_rev = 21; + sc->sc_quirk |= RTKQ_DESCV2; break; case RTK_HWREV_8168_SPIN2: sc->sc_rev = 22; + sc->sc_quirk |= RTKQ_DESCV2; break; case RTK_HWREV_8168_SPIN3: sc->sc_rev = 23; + sc->sc_quirk |= RTKQ_DESCV2; break; case RTK_HWREV_8168C: case RTK_HWREV_8168C_SPIN2: sc->sc_rev = 24; + sc->sc_quirk |= RTKQ_DESCV2; break; case RTK_HWREV_8102E: case RTK_HWREV_8102EL: sc->sc_rev = 25; + sc->sc_quirk |= RTKQ_DESCV2; break; case RTK_HWREV_8100E: case RTK_HWREV_8100E_SPIN2: @@ -792,6 +797,15 @@ IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx | IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx | IFCAP_TSOv4; + + /* + * XXX + * Still have no idea how to make TSO work on 8168C, 8168CP, + * 8102E, 8111C and 8111CP. + */ + if ((sc->sc_quirk & RTKQ_DESCV2) != 0) + ifp->if_capabilities &= ~IFCAP_TSOv4; + ifp->if_watchdog = re_watchdog; ifp->if_init = re_init; ifp->if_snd.ifq_maxlen = RE_IFQ_MAXLEN; @@ -1238,7 +1252,9 @@ /* Do RX checksumming */ /* Check IP header checksum */ - if (rxstat & RE_RDESC_STAT_PROTOID) { + if ((rxstat & RE_RDESC_STAT_PROTOID) != 0 && + ((sc->sc_quirk & RTKQ_DESCV2) == 0 || + (rxvlan & RE_PROTOID_IP) != 0)) { m->m_pkthdr.csum_flags |= M_CSUM_IPv4; if (rxstat & RE_RDESC_STAT_IPSUMBAD) m->m_pkthdr.csum_flags |= M_CSUM_IPv4_BAD; @@ -1453,6 +1469,7 @@ * chip. I'm not sure if this is a requirement or a bug.) */ + vlanctl = 0; if ((m->m_pkthdr.csum_flags & M_CSUM_TSOv4) != 0) { uint32_t segsz = m->m_pkthdr.segsz; @@ -1468,12 +1485,28 @@ if ((m->m_pkthdr.csum_flags & (M_CSUM_IPv4 | M_CSUM_TCPv4 | M_CSUM_UDPv4)) != 0) { - re_flags |= RE_TDESC_CMD_IPCSUM; - if (m->m_pkthdr.csum_flags & M_CSUM_TCPv4) { - re_flags |= RE_TDESC_CMD_TCPCSUM; - } else if (m->m_pkthdr.csum_flags & - M_CSUM_UDPv4) { - re_flags |= RE_TDESC_CMD_UDPCSUM; + if ((sc->sc_quirk & RTKQ_DESCV2) == 0) { + re_flags |= RE_TDESC_CMD_IPCSUM; + if (m->m_pkthdr.csum_flags & + M_CSUM_TCPv4) { + re_flags |= + RE_TDESC_CMD_TCPCSUM; + } else if (m->m_pkthdr.csum_flags & + M_CSUM_UDPv4) { + re_flags |= + RE_TDESC_CMD_UDPCSUM; + } + } else { + vlanctl |= RE_TDESC_VLANCTL_IPCSUM; + if (m->m_pkthdr.csum_flags & + M_CSUM_TCPv4) { + vlanctl |= + RE_TDESC_VLANCTL_TCPCSUM; + } else if (m->m_pkthdr.csum_flags & + M_CSUM_UDPv4) { + vlanctl |= + RE_TDESC_VLANCTL_UDPCSUM; + } } } } @@ -1497,7 +1530,8 @@ nsegs = map->dm_nsegs; pad = false; if (__predict_false(m->m_pkthdr.len <= RE_IP4CSUMTX_PADLEN && - (re_flags & RE_TDESC_CMD_IPCSUM) != 0)) { + (re_flags & RE_TDESC_CMD_IPCSUM) != 0 && + (sc->sc_quirk & RTKQ_DESCV2) == 0)) { pad = true; nsegs++; } @@ -1525,9 +1559,8 @@ * appear in all descriptors of a multi-descriptor * transmission attempt. */ - vlanctl = 0; if ((mtag = VLAN_OUTPUT_TAG(&sc->ethercom, m)) != NULL) - vlanctl = bswap16(VLAN_TAG_VALUE(mtag)) | + vlanctl |= bswap16(VLAN_TAG_VALUE(mtag)) | RE_TDESC_VLANCTL_TAG; /* @@ -1861,8 +1894,7 @@ /* * According to FreeBSD, 8102E/8102EL use a different DMA * descriptor format. 8168C/8111C requires touching additional - * magic registers. Depending on MAC revisions some controllers - * need to disable checksum offload. + * magic registers. * * Disable jumbo frames for those parts. */ Index: src/sys/dev/ic/rtl81x9reg.h diff -u src/sys/dev/ic/rtl81x9reg.h:1.32.4.1 src/sys/dev/ic/rtl81x9reg.h:1.32.4.2 --- src/sys/dev/ic/rtl81x9reg.h:1.32.4.1 Thu Mar 26 17:36:03 2009 +++ src/sys/dev/ic/rtl81x9reg.h Fri May 1 02:03:44 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rtl81x9reg.h,v 1.32.4.1 2009/03/26 17:36:03 snj Exp $ */ +/* $NetBSD: rtl81x9reg.h,v 1.32.4.2 2009/05/01 02:03:44 snj Exp $ */ /* * Copyright (c) 1997, 1998 @@ -475,6 +475,9 @@ #define RE_TDESC_VLANCTL_TAG 0x00020000 /* Insert VLAN tag */ #define RE_TDESC_VLANCTL_DATA 0x0000FFFF /* TAG data */ +#define RE_TDESC_VLANCTL_UDPCSUM 0x80000000 /* DESCV2 UDP cksum enable */ +#define RE_TDESC_VLANCTL_TCPCSUM 0x40000000 /* DESCV2 TCP cksum enable */ +#define RE_TDESC_VLANCTL_IPCSUM 0x20000000 /* DESCV2 IP hdr cksum enable */ /* * Error bits are valid only on the last descriptor of a frame Index: src/sys/dev/ic/rtl81x9var.h diff -u src/sys/dev/ic/rtl81x9var.h:1.41.12.1 src/sys/dev/ic/rtl81x9var.h:1.41.12.2 --- src/sys/dev/ic/rtl81x9var.h:1.41.12.1 Tue Mar 24 20:38:38 2009 +++ src/sys/dev/ic/rtl81x9var.h Fri May 1 02:03:44 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rtl81x9var.h,v 1.41.12.1 2009/03/24 20:38:38 snj Exp $ */ +/* $NetBSD: rtl81x9var.h,v 1.41.12.2 2009/05/01 02:03:44 snj Exp $ */ /* * Copyright (c) 1997, 1998 @@ -189,6 +189,7 @@ #define RTKQ_8169NONS 0x00000004 /* old non-single 8169 */ #define RTKQ_PCIE 0x00000008 /* PCIe variants */ #define RTKQ_MACLDPS 0x00000010 /* has LDPS register */ +#define RTKQ_DESCV2 0x00000020 /* has V2 TX/RX descriptor */ bus_dma_tag_t sc_dmat;