Subject: Re: 802.1q hardware support
To: Jun-ichiro itojun Hagino <itojun@iijlab.net>
From: Manuel Bouyer <bouyer@antioche.lip6.fr>
List: tech-net
Date: 11/16/2000 13:38:50
--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
On Thu, Nov 16, 2000 at 05:45:22AM +0900, Jun-ichiro itojun Hagino wrote:
>
> > > - vlan_input_tag(eh, m, vlan_tag);
> > > + struct mbuf *n;
> > > + n = m_aux_add(m, AF_LINK, ETHERTYPE_VLAN);
> > > + if (n) {
> > > + *mtod(n, int *) = vlan_tag;
> > > + n->m_len = sizeof(int);
> > > + } else
> > > + printf("%s: no mbuf for tag\n", ifp->if_xname);
> > > + m->m_flags |= M_VLAN1Q;
>
> I believe you no longer need M_VLAN1Q. you just need to check
> if m_aux_find(m, AF_LINK, ETHERTYPE_VLAN) returns NULL or not.
Yes, once I change the driver to not drop the mbuf when m_aux_add fails.
There is a small, but measurable performance benefit in not using
M_VLAN1Q (27200 vs 27800 KB/s with ttcp -u).
I had 29000 KB/s with M_VLAN1Q + mph_info, but I think the cleaner design
of m_aux is worth the performance penality (and this is on a P200,
with a modern hardware it may not be measurable :).
New diff attached. Note that in the input path, there are 2 calls to
m_aux_find(): one in ether_input and one in vlan_input. This could be
avoided by adding a third arg to vlan_input to pass n. I tried, this gains
us another 50KB/s in ttcp, but I think it is better to keep all the *_input
with the same prototype, if we ever want to modularize this.
Anything else that could be improved in this area ? If not I commit this and
start looking at IP checksum support.
--
Manuel Bouyer, LIP6, Universite Paris VI. Manuel.Bouyer@lip6.fr
--
--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="vlan.diff"
Index: net/if_ether.h
===================================================================
RCS file: /cvsroot/syssrc/sys/net/if_ether.h,v
retrieving revision 1.20
diff -u -r1.20 if_ether.h
--- net/if_ether.h 2000/10/11 16:53:41 1.20
+++ net/if_ether.h 2000/11/16 12:37:21
@@ -154,7 +154,7 @@
};
#define ETHERCAP_VLAN_MTU 0x00000001 /* VLAN-compatible MTU */
-#define ETHERCAP_VLAN_TAGGING 0x00000002 /* VLAN tag support */
+#define ETHERCAP_VLAN_HWTAGGING 0x00000002 /* hardware VLAN tag support */
#ifdef _KERNEL
extern u_int8_t etherbroadcastaddr[ETHER_ADDR_LEN];
Index: net/if_ethersubr.c
===================================================================
RCS file: /cvsroot/syssrc/sys/net/if_ethersubr.c,v
retrieving revision 1.68
diff -u -r1.68 if_ethersubr.c
--- net/if_ethersubr.c 2000/10/15 19:49:55 1.68
+++ net/if_ethersubr.c 2000/11/16 12:37:22
@@ -500,6 +500,7 @@
u_int16_t etype;
int s;
struct ether_header *eh;
+ struct mbuf *n;
#if defined (ISO) || defined (LLC) || defined(NETATALK)
struct llc *l;
#endif
@@ -535,6 +536,22 @@
memcmp(LLADDR(ifp->if_sadl), eh->ether_dhost,
ETHER_ADDR_LEN) != 0) {
m_freem(m);
+ return;
+ }
+
+ /* Check if the mbuf has a VLAN tag */
+ n = m_aux_find(m, AF_LINK, ETHERTYPE_VLAN);
+ if (n) {
+#if NVLAN > 0
+ /*
+ * vlan_input() will either recursively call ether_input()
+ * or drop the packet.
+ */
+ if (((struct ethercom *)ifp)->ec_nvlans != 0)
+ vlan_input(ifp, m);
+ else
+#endif
+ m_freem(m);
return;
}
Index: net/if_vlan.c
===================================================================
RCS file: /cvsroot/syssrc/sys/net/if_vlan.c,v
retrieving revision 1.22
diff -u -r1.22 if_vlan.c
--- net/if_vlan.c 2000/11/15 01:02:15 1.22
+++ net/if_vlan.c 2000/11/16 12:37:24
@@ -313,7 +313,7 @@
ifv->ifv_p = p;
ifv->ifv_if.if_mtu = p->if_mtu - ifv->ifv_mtufudge;
ifv->ifv_if.if_flags = p->if_flags &
- (IFF_UP | IFF_BROADCAST | IFF_RUNNING | IFF_ALLMULTI | IFF_SIMPLEX);
+ (IFF_UP | IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
/*
* Inherit the if_type from the parent. This allows us
@@ -665,6 +665,7 @@
{
struct ifvlan *ifv = ifp->if_softc;
struct ifnet *p = ifv->ifv_p;
+ struct ethercom *ec = (void *) ifv->ifv_p;
struct mbuf *m;
ifp->if_flags |= IFF_OACTIVE;
@@ -678,51 +679,66 @@
if (ifp->if_bpf)
bpf_mtap(ifp->if_bpf, m);
#endif
-
/*
- * XXX Should handle the case where the underlying hardware
- * interface can do VLAN tag insertion itself.
+ * If the parent can insert the tag itself, just mark
+ * the tag in the mbuf header.
*/
- M_PREPEND(m, ifv->ifv_encaplen, M_DONTWAIT);
- if (m == NULL) {
- printf("%s: unable to prepend encap header",
- ifv->ifv_p->if_xname);
- ifp->if_oerrors++;
- continue;
- }
-
- switch (p->if_type) {
- case IFT_ETHER:
- {
- struct ether_vlan_header *evl;
-
- if (m->m_len < sizeof(struct ether_vlan_header) &&
- (m = m_pullup(m,
- sizeof(struct ether_vlan_header))) == NULL) {
- printf("%s: unable to pullup encap header",
- ifv->ifv_p->if_xname);
+ if (ec->ec_capabilities & ETHERCAP_VLAN_HWTAGGING) {
+ struct mbuf *n;
+ n = m_aux_add(m, AF_LINK, ETHERTYPE_VLAN);
+ if (n == NULL) {
ifp->if_oerrors++;
+ m_freem(m);
continue;
}
-
+ *mtod(n, int *) = ifv->ifv_tag;
+ n->m_len = sizeof(int);
+ } else {
/*
- * Transform the Ethernet header into an Ethernet
- * header with 802.1Q encapsulation.
+ * insert the tag ourselve
*/
- memmove(mtod(m, caddr_t),
- mtod(m, caddr_t) + ifv->ifv_encaplen,
- sizeof(struct ether_header));
- evl = mtod(m, struct ether_vlan_header *);
- evl->evl_proto = evl->evl_encap_proto;
- evl->evl_encap_proto = htons(ETHERTYPE_VLAN);
- evl->evl_tag = htons(ifv->ifv_tag);
- break;
- }
+ M_PREPEND(m, ifv->ifv_encaplen, M_DONTWAIT);
+ if (m == NULL) {
+ printf("%s: unable to prepend encap header",
+ ifv->ifv_p->if_xname);
+ ifp->if_oerrors++;
+ continue;
+ }
+
+ switch (p->if_type) {
+ case IFT_ETHER:
+ {
+ struct ether_vlan_header *evl;
+
+ if (m->m_len < sizeof(struct ether_vlan_header))
+ m = m_pullup(m,
+ sizeof(struct ether_vlan_header));
+ if (m == NULL) {
+ printf("%s: unable to pullup encap "
+ "header", ifv->ifv_p->if_xname);
+ ifp->if_oerrors++;
+ continue;
+ }
+
+ /*
+ * Transform the Ethernet header into an
+ * Ethernet header with 802.1Q encapsulation.
+ */
+ memmove(mtod(m, caddr_t),
+ mtod(m, caddr_t) + ifv->ifv_encaplen,
+ sizeof(struct ether_header));
+ evl = mtod(m, struct ether_vlan_header *);
+ evl->evl_proto = evl->evl_encap_proto;
+ evl->evl_encap_proto = htons(ETHERTYPE_VLAN);
+ evl->evl_tag = htons(ifv->ifv_tag);
+ break;
+ }
#ifdef DIAGNOSTIC
- default:
- panic("vlan_start: impossible");
+ default:
+ panic("vlan_start: impossible");
#endif
+ }
}
/*
@@ -738,9 +754,9 @@
}
IF_ENQUEUE(&p->if_snd, m);
+ ifp->if_opackets++;
if ((p->if_flags & IFF_OACTIVE) == 0) {
(*p->if_start)(p);
- ifp->if_opackets++;
}
}
@@ -757,44 +773,67 @@
{
struct ifvlan *ifv;
u_int tag;
+ struct mbuf *n;
- switch (ifp->if_type) {
- case IFT_ETHER:
- {
- struct ether_vlan_header *evl;
+ n = m_aux_find(m, AF_LINK, ETHERTYPE_VLAN);
+ if (n) {
+ /* m contains a normal ethernet frame, the tag is in m_aux */
+ tag = *mtod(n, int *);
+ m_aux_delete(m, n);
+ for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
+ ifv = LIST_NEXT(ifv, ifv_list))
+ if (ifp == ifv->ifv_p && tag == ifv->ifv_tag)
+ break;
+ } else {
+ switch (ifp->if_type) {
+ case IFT_ETHER:
+ {
+ struct ether_vlan_header *evl;
- if (m->m_len < sizeof(struct ether_vlan_header) &&
- (m = m_pullup(m,
- sizeof(struct ether_vlan_header))) == NULL) {
- printf("%s: no memory for VLAN header, "
- "dropping packet.\n", ifp->if_xname);
- return;
- }
- evl = mtod(m, struct ether_vlan_header *);
- KASSERT(ntohs(evl->evl_encap_proto) == ETHERTYPE_VLAN);
+ if (m->m_len < sizeof(struct ether_vlan_header) &&
+ (m = m_pullup(m,
+ sizeof(struct ether_vlan_header))) == NULL) {
+ printf("%s: no memory for VLAN header, "
+ "dropping packet.\n", ifp->if_xname);
+ return;
+ }
+ evl = mtod(m, struct ether_vlan_header *);
+ KASSERT(ntohs(evl->evl_encap_proto) == ETHERTYPE_VLAN);
- tag = EVL_VLANOFTAG(ntohs(evl->evl_tag));
+ tag = EVL_VLANOFTAG(ntohs(evl->evl_tag));
- /*
- * Restore the original ethertype. We'll remove
- * the encapsulation after we've found the vlan
- * interface corresponding to the tag.
- */
- evl->evl_encap_proto = evl->evl_proto;
- break;
- }
+ /*
+ * Restore the original ethertype. We'll remove
+ * the encapsulation after we've found the vlan
+ * interface corresponding to the tag.
+ */
+ evl->evl_encap_proto = evl->evl_proto;
+ break;
+ }
- default:
- tag = (u_int) -1; /* XXX GCC */
+ default:
+ tag = (u_int) -1; /* XXX GCC */
#ifdef DIAGNOSTIC
- panic("vlan_input: impossible");
+ panic("vlan_input: impossible");
#endif
- }
+ }
- for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
- ifv = LIST_NEXT(ifv, ifv_list))
- if (ifp == ifv->ifv_p && tag == ifv->ifv_tag)
- break;
+ for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;
+ ifv = LIST_NEXT(ifv, ifv_list))
+ if (ifp == ifv->ifv_p && tag == ifv->ifv_tag)
+ break;
+
+
+ /*
+ * Now, remove the encapsulation header. The original
+ * header has already been fixed up above.
+ */
+ if (ifv) {
+ memmove(mtod(m, caddr_t) + ifv->ifv_encaplen,
+ mtod(m, caddr_t), ifv->ifv_encaplen);
+ m_adj(m, ifv->ifv_encaplen);
+ }
+ }
if (ifv == NULL ||
(ifv->ifv_if.if_flags & (IFF_UP|IFF_RUNNING)) !=
@@ -803,15 +842,6 @@
ifp->if_noproto++;
return;
}
-
- /*
- * Now, remove the encapsulation header. The original
- * header has already been fixed up above.
- */
- memmove(mtod(m, caddr_t) + ifv->ifv_encaplen, mtod(m, caddr_t),
- ifv->ifv_encaplen);
- m_adj(m, ifv->ifv_encaplen);
-
m->m_pkthdr.rcvif = &ifv->ifv_if;
ifv->ifv_if.if_ipackets++;
Index: dev/pci/if_ti.c
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/pci/if_ti.c,v
retrieving revision 1.12
diff -u -r1.12 if_ti.c
--- dev/pci/if_ti.c 2000/11/12 18:32:43 1.12
+++ dev/pci/if_ti.c 2000/11/16 12:37:26
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ti.c,v 1.12 2000/11/12 18:32:43 bouyer Exp $ */
+/* $NetBSD: if_ti.c,v 1.8.4.1 2000/09/26 20:18:16 martin Exp $ */
/*
* Copyright (c) 1997, 1998, 1999
@@ -135,11 +135,15 @@
static struct ti_type ti_devs[] = {
{ PCI_VENDOR_ALTEON, PCI_PRODUCT_ALTEON_ACENIC,
- "Alteon AceNIC Gigabit Ethernet" },
+ "Alteon AceNIC 1000baseSX Gigabit Ethernet" },
+ { PCI_VENDOR_ALTEON, PCI_PRODUCT_ALTEON_ACENIC_COPPER,
+ "Alteon AceNIC 1000baseT Gigabit Ethernet" },
{ PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C985,
"3Com 3c985-SX Gigabit Ethernet" },
{ PCI_VENDOR_NETGEAR, PCI_PRODUCT_NETGEAR_GA620,
- "Netgear GA620 Gigabit Ethernet" },
+ "Netgear GA620 1000baseSX Gigabit Ethernet" },
+ { PCI_VENDOR_NETGEAR, PCI_PRODUCT_NETGEAR_GA620T,
+ "Netgear GA620 1000baseT Gigabit Ethernet" },
{ PCI_VENDOR_SGI, PCI_PRODUCT_SGI_TIGON,
"Silicon Graphics Gigabit Ethernet" },
{ 0, 0, NULL }
@@ -625,21 +629,12 @@
/*
* Now divide it up into 9K pieces and save the addresses
- * in an array. Note that we play an evil trick here by using
- * the first few bytes in the buffer to hold the address
- * of the softc structure for this interface. This is because
- * ti_jfree() needs it, but it is called by the mbuf management
- * code which will not pass it to us explicitly.
+ * in an array.
*/
ptr = sc->ti_cdata.ti_jumbo_buf;
for (i = 0; i < TI_JSLOTS; i++) {
- u_int64_t **aptr;
- aptr = (u_int64_t **)ptr;
- aptr[0] = (u_int64_t *)sc;
- ptr += sizeof(u_int64_t);
- sc->ti_cdata.ti_jslots[i].ti_buf = ptr;
- sc->ti_cdata.ti_jslots[i].ti_inuse = 0;
- ptr += (TI_JLEN - sizeof(u_int64_t));
+ sc->ti_cdata.ti_jslots[i] = ptr;
+ ptr += TI_JLEN;
entry = malloc(sizeof(struct ti_jpool_entry),
M_DEVBUF, M_NOWAIT);
if (entry == NULL) {
@@ -674,8 +669,7 @@
SIMPLEQ_REMOVE_HEAD(&sc->ti_jfree_listhead, entry, jpool_entries);
SIMPLEQ_INSERT_HEAD(&sc->ti_jinuse_listhead, entry, jpool_entries);
- sc->ti_cdata.ti_jslots[entry->slot].ti_inuse = 1;
- return(sc->ti_cdata.ti_jslots[entry->slot].ti_buf);
+ return(sc->ti_cdata.ti_jslots[entry->slot]);
}
/*
@@ -684,45 +678,33 @@
static void ti_jfree(buf, size, arg)
caddr_t buf;
u_int size;
- void *arg; /* XXX NetBSD: we should really use it */
+ void *arg;
{
struct ti_softc *sc;
- u_int64_t **aptr;
int i;
struct ti_jpool_entry *entry;
/* Extract the softc struct pointer. */
- aptr = (u_int64_t **)(buf - sizeof(u_int64_t));
- sc = (struct ti_softc *)(aptr[0]);
+ sc = (struct ti_softc *)arg;
if (sc == NULL)
- panic("ti_jfree: can't find softc pointer!");
+ panic("ti_jfree: didn't get softc pointer!");
- if (size != TI_JUMBO_FRAMELEN)
- panic("ti_jfree: freeing buffer of wrong size!");
-
/* calculate the slot this buffer belongs to */
- i = ((caddr_t)aptr
+ i = ((caddr_t)buf
- (caddr_t)sc->ti_cdata.ti_jumbo_buf) / TI_JLEN;
if ((i < 0) || (i >= TI_JSLOTS))
panic("ti_jfree: asked to free buffer that we don't manage!");
- else if (sc->ti_cdata.ti_jslots[i].ti_inuse == 0)
- panic("ti_jfree: buffer already free!");
- else {
- sc->ti_cdata.ti_jslots[i].ti_inuse--;
- if(sc->ti_cdata.ti_jslots[i].ti_inuse == 0) {
- entry = SIMPLEQ_FIRST(&sc->ti_jinuse_listhead);
- if (entry == NULL)
- panic("ti_jfree: buffer not in use!");
- entry->slot = i;
- SIMPLEQ_REMOVE_HEAD(&sc->ti_jinuse_listhead,
- entry, jpool_entries);
- SIMPLEQ_INSERT_HEAD(&sc->ti_jfree_listhead,
- entry, jpool_entries);
- }
- }
+ entry = SIMPLEQ_FIRST(&sc->ti_jinuse_listhead);
+ if (entry == NULL)
+ panic("ti_jfree: buffer not in use!");
+ entry->slot = i;
+ SIMPLEQ_REMOVE_HEAD(&sc->ti_jinuse_listhead,
+ entry, jpool_entries);
+ SIMPLEQ_INSERT_HEAD(&sc->ti_jfree_listhead,
+ entry, jpool_entries);
return;
}
@@ -1484,9 +1466,7 @@
#ifdef TI_CSUM_OFFLOAD
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM|TI_RCB_FLAG_IP_CKSUM;
#endif
-#if NVLAN > 0
rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
-#endif
/* Set up the jumbo receive ring. */
rcb = &sc->ti_rdata->ti_info.ti_jumbo_rx_rcb;
@@ -1497,9 +1477,7 @@
#ifdef TI_CSUM_OFFLOAD
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM|TI_RCB_FLAG_IP_CKSUM;
#endif
-#if NVLAN > 0
rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
-#endif
/*
* Set up the mini ring. Only activated on the
@@ -1517,9 +1495,7 @@
#ifdef TI_CSUM_OFFLOAD
rcb->ti_flags |= TI_RCB_FLAG_TCP_UDP_CKSUM|TI_RCB_FLAG_IP_CKSUM;
#endif
-#if NVLAN > 0
rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
-#endif
/*
* Set up the receive return ring.
@@ -1554,9 +1530,7 @@
rcb->ti_flags = 0;
else
rcb->ti_flags = TI_RCB_FLAG_HOST_RING;
-#if NVLAN > 0
rcb->ti_flags |= TI_RCB_FLAG_VLAN_ASSIST;
-#endif
rcb->ti_max_len = TI_TX_RING_CNT;
if (sc->ti_hwrev == TI_HWREV_TIGON)
TI_HOSTADDR(rcb->ti_hostaddr) = TI_TX_RING_BASE;
@@ -1785,6 +1759,21 @@
goto fail2;
}
+ /*
+ * We really need a better way to tell a 1000baseTX card
+ * from a 1000baseSX one, since in theory there could be
+ * OEMed 1000baseTX cards from lame vendors who aren't
+ * clever enough to change the PCI ID. For the moment
+ * though, the AceNIC is the only copper card available.
+ */
+ if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALTEON &&
+ PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ALTEON_ACENIC_COPPER) ||
+ (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NETGEAR &&
+ PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NETGEAR_GA620T))
+ sc->ti_copper = 1;
+ else
+ sc->ti_copper = 0;
+
/* Set default tuneable values. */
sc->ti_stat_ticks = 2 * TI_TICKS_PER_SEC;
sc->ti_rx_coal_ticks = TI_TICKS_PER_SEC / 5000;
@@ -1806,16 +1795,34 @@
/*
* We can support 802.1Q VLAN-sized frames.
*/
- sc->ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
+ sc->ethercom.ec_capabilities |=
+ ETHERCAP_VLAN_MTU | ETHERCAP_VLAN_HWTAGGING;
/* Set up ifmedia support. */
ifmedia_init(&sc->ifmedia, IFM_IMASK, ti_ifmedia_upd, ti_ifmedia_sts);
- ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_FL, 0, NULL);
- ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_FL|IFM_FDX, 0, NULL);
- ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_FX, 0, NULL);
- ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_FX|IFM_FDX, 0, NULL);
- ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_SX, 0, NULL);
- ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_SX|IFM_FDX, 0, NULL);
+ if (sc->ti_copper) {
+ /*
+ * Copper cards allow manual 10/100 mode selection,
+ * but not manual 1000baseTX mode selection. Why?
+ * Becuase currently there's no way to specify the
+ * master/slave setting through the firmware interface,
+ * so Alteon decided to just bag it and handle it
+ * via autonegotiation.
+ */
+ ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL);
+ ifmedia_add(&sc->ifmedia,
+ IFM_ETHER|IFM_10_T|IFM_FDX, 0, NULL);
+ ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_100_TX, 0, NULL);
+ ifmedia_add(&sc->ifmedia,
+ IFM_ETHER|IFM_100_TX|IFM_FDX, 0, NULL);
+ ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_TX, 0, NULL);
+ ifmedia_add(&sc->ifmedia,
+ IFM_ETHER|IFM_1000_TX|IFM_FDX, 0, NULL);
+ } else {
+ /* Fiber cards don't support 10/100 modes. */
+ ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_SX, 0, NULL);
+ ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_1000_SX|IFM_FDX, 0, NULL);
+ }
ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL);
ifmedia_set(&sc->ifmedia, IFM_ETHER|IFM_AUTO);
@@ -1859,10 +1866,8 @@
struct ti_rx_desc *cur_rx;
u_int32_t rxidx;
struct mbuf *m = NULL;
-#if NVLAN > 0
u_int16_t vlan_tag = 0;
int have_tag = 0;
-#endif
#ifdef TI_CSUM_OFFLOAD
struct ip *ip;
#endif
@@ -1873,12 +1878,10 @@
rxidx = cur_rx->ti_idx;
TI_INC(sc->ti_rx_saved_considx, TI_RETURN_RING_CNT);
-#if NVLAN > 0
if (cur_rx->ti_flags & TI_BDFLAG_VLAN_TAG) {
have_tag = 1;
vlan_tag = cur_rx->ti_vlan_tag;
}
-#endif
if (cur_rx->ti_flags & TI_BDFLAG_JUMBO_RING) {
TI_INC(sc->ti_jumbo, TI_JUMBO_RX_RING_CNT);
@@ -1953,17 +1956,19 @@
m->m_flags |= M_HWCKSUM;
#endif
-#if NVLAN > 0 /* XXX NetBSD: broken because m points to ether pkt */
- /*
- * If we received a packet with a vlan tag, pass it
- * to vlan_input() instead of ether_input().
- */
if (have_tag) {
- vlan_input_tag(eh, m, vlan_tag);
+ struct mbuf *n;
+ n = m_aux_add(m, AF_LINK, ETHERTYPE_VLAN);
+ if (n) {
+ *mtod(n, int *) = vlan_tag;
+ n->m_len = sizeof(int);
+ } else {
+ printf("%s: no mbuf for tag\n", ifp->if_xname);
+ m_freem(m);
+ continue;
+ }
have_tag = vlan_tag = 0;
- continue;
}
-#endif
(*ifp->if_input)(ifp, m);
}
@@ -2102,15 +2107,8 @@
struct txdmamap_pool_entry *dma;
bus_dmamap_t dmamap;
int error, i;
-#if NVLAN > 0
- struct ifvlan *ifv = NULL;
+ struct mbuf *n;
- if ((m_head->m_flags & (M_PROTO1|M_PKTHDR)) == (M_PROTO1|M_PKTHDR) &&
- m_head->m_pkthdr.rcvif != NULL &&
- m_head->m_pkthdr.rcvif->if_type == IFT_8021_VLAN)
- ifv = m_head->m_pkthdr.rcvif->if_softc;
-#endif
-
dma = SIMPLEQ_FIRST(&sc->txdma_list);
if (dma == NULL) {
return ENOMEM;
@@ -2157,14 +2155,13 @@
TI_HOSTADDR(f->ti_addr) = dmamap->dm_segs[i].ds_addr;
f->ti_len = dmamap->dm_segs[i].ds_len;
f->ti_flags = 0;
-#if NVLAN > 0
- if (ifv != NULL) {
+ n = m_aux_find(m_head, AF_LINK, ETHERTYPE_VLAN);
+ if (n) {
f->ti_flags |= TI_BDFLAG_VLAN_TAG;
- f->ti_vlan_tag = ifv->ifv_tag;
+ f->ti_vlan_tag = *mtod(n, int *);
} else {
f->ti_vlan_tag = 0;
}
-#endif
/*
* Sanity check: avoid coming within 16 descriptors
* of the end of the ring.
@@ -2391,17 +2388,28 @@
TI_CMD_CODE_NEGOTIATE_BOTH, 0);
break;
case IFM_1000_SX:
- CSR_WRITE_4(sc, TI_GCR_GLINK, TI_GLNK_PREF|TI_GLNK_1000MB|
- TI_GLNK_FULL_DUPLEX|TI_GLNK_RX_FLOWCTL_Y|TI_GLNK_ENB);
+ case IFM_1000_TX:
+ if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX) {
+ CSR_WRITE_4(sc, TI_GCR_GLINK,
+ TI_GLNK_PREF|TI_GLNK_1000MB|TI_GLNK_FULL_DUPLEX|
+ TI_GLNK_RX_FLOWCTL_Y|TI_GLNK_ENB);
+ } else {
+ CSR_WRITE_4(sc, TI_GCR_GLINK,
+ TI_GLNK_PREF|TI_GLNK_1000MB|
+ TI_GLNK_RX_FLOWCTL_Y|TI_GLNK_ENB);
+ }
CSR_WRITE_4(sc, TI_GCR_LINK, 0);
TI_DO_CMD(TI_CMD_LINK_NEGOTIATION,
TI_CMD_CODE_NEGOTIATE_GIGABIT, 0);
break;
case IFM_100_FX:
case IFM_10_FL:
+ case IFM_100_TX:
+ case IFM_10_T:
CSR_WRITE_4(sc, TI_GCR_GLINK, 0);
CSR_WRITE_4(sc, TI_GCR_LINK, TI_LNK_ENB|TI_LNK_PREF);
- if (IFM_SUBTYPE(ifm->ifm_media) == IFM_100_FX) {
+ if (IFM_SUBTYPE(ifm->ifm_media) == IFM_100_FX ||
+ IFM_SUBTYPE(ifm->ifm_media) == IFM_100_TX) {
TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_100MB);
} else {
TI_SETBIT(sc, TI_GCR_LINK, TI_LNK_10MB);
@@ -2430,6 +2438,7 @@
struct ifmediareq *ifmr;
{
struct ti_softc *sc;
+ u_int32_t media = 0;
sc = ifp->if_softc;
@@ -2441,15 +2450,29 @@
ifmr->ifm_status |= IFM_ACTIVE;
- if (sc->ti_linkstat == TI_EV_CODE_GIG_LINK_UP)
- ifmr->ifm_active |= IFM_1000_SX|IFM_FDX;
- else if (sc->ti_linkstat == TI_EV_CODE_LINK_UP) {
- u_int32_t media;
+ if (sc->ti_linkstat == TI_EV_CODE_GIG_LINK_UP) {
+ media = CSR_READ_4(sc, TI_GCR_GLINK_STAT);
+ if (sc->ti_copper)
+ ifmr->ifm_active |= IFM_1000_TX;
+ else
+ ifmr->ifm_active |= IFM_1000_SX;
+ if (media & TI_GLNK_FULL_DUPLEX)
+ ifmr->ifm_active |= IFM_FDX;
+ else
+ ifmr->ifm_active |= IFM_HDX;
+ } else if (sc->ti_linkstat == TI_EV_CODE_LINK_UP) {
media = CSR_READ_4(sc, TI_GCR_LINK_STAT);
- if (media & TI_LNK_100MB)
- ifmr->ifm_active |= IFM_100_FX;
- if (media & TI_LNK_10MB)
- ifmr->ifm_active |= IFM_10_FL;
+ if (sc->ti_copper) {
+ if (media & TI_LNK_100MB)
+ ifmr->ifm_active |= IFM_100_TX;
+ if (media & TI_LNK_10MB)
+ ifmr->ifm_active |= IFM_10_T;
+ } else {
+ if (media & TI_LNK_100MB)
+ ifmr->ifm_active |= IFM_100_FX;
+ if (media & TI_LNK_10MB)
+ ifmr->ifm_active |= IFM_10_FL;
+ }
if (media & TI_LNK_FULL_DUPLEX)
ifmr->ifm_active |= IFM_FDX;
if (media & TI_LNK_HALF_DUPLEX)
--fUYQa+Pmc3FrFX/N--