use VLAN_* macros for VLAN tag extraction/addition

This commit is contained in:
jdolecek 2005-02-20 15:56:03 +00:00
parent 2bba43d247
commit 2a0d290c56
4 changed files with 30 additions and 72 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtl8169.c,v 1.8 2005/02/13 16:04:18 jdolecek Exp $ */
/* $NetBSD: rtl8169.c,v 1.9 2005/02/20 15:56:03 jdolecek Exp $ */
/*
* Copyright (c) 1997, 1998-2003
@ -1124,7 +1124,6 @@ re_rxeof(struct rtk_softc *sc)
struct ifnet *ifp;
int i, total_len;
struct rtk_desc *cur_rx;
struct m_tag *mtag;
u_int32_t rxstat, rxvlan;
ifp = &sc->ethercom.ec_if;
@ -1273,16 +1272,9 @@ re_rxeof(struct rtk_softc *sc)
}
if (rxvlan & RTK_RDESC_VLANCTL_TAG) {
mtag = m_tag_get(PACKET_TAG_VLAN, sizeof(u_int),
M_NOWAIT);
if (mtag == NULL) {
ifp->if_ierrors++;
m_freem(m);
continue;
}
*(u_int *)(mtag + 1) =
be16toh(rxvlan & RTK_RDESC_VLANCTL_DATA);
m_tag_prepend(m, mtag);
VLAN_INPUT_TAG(ifp, m,
be16toh(rxvlan & RTK_RDESC_VLANCTL_DATA),
continue);
}
#if NBPFILTER > 0
if (ifp->if_bpf)
@ -1609,11 +1601,11 @@ re_encap(struct rtk_softc *sc, struct mbuf *m_head, int *idx)
* transmission attempt.
*/
if (sc->ethercom.ec_nvlans &&
(mtag = m_tag_find(m_head, PACKET_TAG_VLAN, NULL)) != NULL)
if ((mtag = VLAN_OUTPUT_TAG(&sc->ethercom, m_head)) != NULL) {
sc->rtk_ldata.rtk_tx_list[*idx].rtk_vlanctl =
htole32(htons(*(u_int *)(mtag + 1)) |
htole32(htons(VLAN_TAG_VALUE(mtag)) |
RTK_TDESC_VLANCTL_TAG);
}
/* Transfer ownership of packet to the chip. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_sip.c,v 1.99 2005/02/06 08:52:08 cube Exp $ */
/* $NetBSD: if_sip.c,v 1.100 2005/02/20 15:56:03 jdolecek Exp $ */
/*-
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_sip.c,v 1.99 2005/02/06 08:52:08 cube Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_sip.c,v 1.100 2005/02/20 15:56:03 jdolecek Exp $");
#include "bpfilter.h"
#include "rnd.h"
@ -1354,11 +1354,10 @@ SIP_DECL(start)(struct ifnet *ifp)
* This apparently has to be on the last descriptor of
* the packet.
*/
if (sc->sc_ethercom.ec_nvlans != 0 &&
(mtag = m_tag_find(m0, PACKET_TAG_VLAN, NULL)) != NULL) {
if ((mtag = VLAN_OUTPUT_TAG(&sc->sc_ethercom, m0)) != NULL) {
sc->sc_txdescs[lasttx].sipd_extsts |=
htole32(EXTSTS_VPKT |
(*(u_int *)(mtag + 1) & EXTSTS_VTCI));
(VLAN_TAG_VALUE(mtag) & EXTSTS_VTCI));
}
/*
@ -1970,21 +1969,9 @@ SIP_DECL(rxintr)(struct sip_softc *sc)
* If VLANs are enabled, VLAN packets have been unwrapped
* for us. Associate the tag with the packet.
*/
if (sc->sc_ethercom.ec_nvlans != 0 &&
(extsts & EXTSTS_VPKT) != 0) {
struct m_tag *vtag;
vtag = m_tag_get(PACKET_TAG_VLAN, sizeof(u_int),
M_NOWAIT);
if (vtag == NULL) {
ifp->if_ierrors++;
printf("%s: unable to allocate VLAN tag\n",
sc->sc_dev.dv_xname);
m_freem(m);
continue;
}
*(u_int *)(vtag + 1) = ntohs(extsts & EXTSTS_VTCI);
if ((extsts & EXTSTS_VPKT) != 0) {
VLAN_INPUT_TAG(ifp, m, ntohs(extsts & EXTSTS_VTCI),
continue);
}
/*
@ -2475,7 +2462,7 @@ SIP_DECL(init)(struct ifnet *ifp)
if (ifp->if_capenable &
(IFCAP_CSUM_IPv4|IFCAP_CSUM_TCPv4|IFCAP_CSUM_UDPv4))
reg |= VRCR_IPEN;
if (sc->sc_ethercom.ec_nvlans != 0)
if (VLAN_ATTACHED(&sc->sc_ethercom))
reg |= VRCR_VTDEN|VRCR_VTREN;
bus_space_write_4(st, sh, SIP_VRCR, reg);
@ -2488,7 +2475,7 @@ SIP_DECL(init)(struct ifnet *ifp)
if (ifp->if_capenable &
(IFCAP_CSUM_IPv4|IFCAP_CSUM_TCPv4|IFCAP_CSUM_UDPv4))
reg |= VTCR_PPCHK;
if (sc->sc_ethercom.ec_nvlans != 0)
if (VLAN_ATTACHED(&sc->sc_ethercom))
reg |= VTCR_VPPTI;
bus_space_write_4(st, sh, SIP_VTCR, reg);
@ -2497,7 +2484,7 @@ SIP_DECL(init)(struct ifnet *ifp)
* To understand why we bswap the VLAN Ethertype, see section
* 4.2.36 of the DP83820 manual.
*/
if (sc->sc_ethercom.ec_nvlans != 0)
if (VLAN_ATTACHED(&sc->sc_ethercom))
bus_space_write_4(st, sh, SIP_VDR, bswap16(ETHERTYPE_VLAN));
#endif /* DP83820 */

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_stge.c,v 1.22 2004/10/30 18:09:22 thorpej Exp $ */
/* $NetBSD: if_stge.c,v 1.23 2005/02/20 15:56:03 jdolecek Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_stge.c,v 1.22 2004/10/30 18:09:22 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_stge.c,v 1.23 2005/02/20 15:56:03 jdolecek Exp $");
#include "bpfilter.h"
@ -817,8 +817,7 @@ stge_start(struct ifnet *ifp)
/*
* See if we have any VLAN stuff.
*/
mtag = sc->sc_ethercom.ec_nvlans ?
m_tag_find(m0, PACKET_TAG_VLAN, NULL) : NULL;
mtag = VLAN_OUTPUT_TAG(&sc->sc_ethercom, m0);
/*
* Get the last and next available transmit descriptor.
@ -934,7 +933,7 @@ stge_start(struct ifnet *ifp)
#ifdef STGE_VLAN_CFI
TFD_CFI |
#endif
TFD_VID((*(u_int *)(mtag + 1)));
TFD_VID(VLAN_TAG_VALUE(mtag));
}
tfd->tfd_control = htole64(tfc);
@ -1361,18 +1360,9 @@ stge_rxintr(struct stge_softc *sc)
/*
* Check for VLAN tagged packets
*/
if (status & RFD_VLANDetected) {
struct m_tag *mtag =
m_tag_get(PACKET_TAG_VLAN, sizeof(u_int), M_NOWAIT);
if (mtag == NULL) {
printf("%s: no mbuf for VLAN tag\n",
ifp->if_xname);
m_freem(m);
continue;
}
*(u_int *)(mtag + 1) = RFD_TCI(status);
m_tag_prepend(m, mtag);
}
if (status & RFD_VLANDetected)
VLAN_INPUT_TAG(ifp, m, RFD_TCI(status), continue);
#endif
#if 0
if (status & RFD_VLANDetected) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_txp.c,v 1.8 2004/10/30 18:09:22 thorpej Exp $ */
/* $NetBSD: if_txp.c,v 1.9 2005/02/20 15:56:03 jdolecek Exp $ */
/*
* Copyright (c) 2001
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_txp.c,v 1.8 2004/10/30 18:09:22 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_txp.c,v 1.9 2005/02/20 15:56:03 jdolecek Exp $");
#include "bpfilter.h"
#include "opt_inet.h"
@ -764,18 +764,8 @@ txp_rx_reclaim(sc, r, dma)
m->m_pkthdr.csum_flags = sumflags;
if (rxd->rx_stat & htole32(RX_STAT_VLAN)) {
struct m_tag *mtag;
mtag = m_tag_get(PACKET_TAG_VLAN, sizeof(u_int),
M_NOWAIT);
if (!m) {
printf("%s: no mbuf for tag\n",
sc->sc_dev.dv_xname);
m_freem(m);
goto next;
}
*(u_int *)(mtag + 1) = htons(rxd->rx_vlan >> 16);
m_tag_prepend(m, mtag);
VLAN_INPUT_TAG(ifp, m, htons(rxd->rx_vlan >> 16),
continue);
}
(*ifp->if_input)(ifp, m);
@ -1477,10 +1467,9 @@ txp_start(ifp)
if (++cnt >= (TX_ENTRIES - 4))
goto oactive;
mtag = m_tag_find(m, PACKET_TAG_VLAN, NULL);
if (mtag)
if ((mtag = VLAN_OUTPUT_TAG(sc->sc_ethercom, m)))
txd->tx_pflags = TX_PFLAGS_VLAN |
(htons(*(u_int *)(mtag + 1)) << TX_PFLAGS_VLANTAG_S);
(htons(VLAN_TAG_VALUE(mtag)) << TX_PFLAGS_VLANTAG_S);
if (m->m_pkthdr.csum_flags & M_CSUM_IPv4)
txd->tx_pflags |= TX_PFLAGS_IPCKSUM;