Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb - change to use rcvfilt_locked() name to clarify...
details: https://anonhg.NetBSD.org/src/rev/7b291f99dd6a
branches: trunk
changeset: 1008590:7b291f99dd6a
user: nisimura <nisimura%NetBSD.org@localhost>
date: Fri Mar 27 18:04:45 2020 +0000
description:
- change to use rcvfilt_locked() name to clarify the intent.
- stylise receive filter manipulation logic.
- use ETHER_F_ALLMULTI flag.
diffstat:
sys/dev/usb/if_axe.c | 56 +++++++++++++---------------
sys/dev/usb/if_ure.c | 99 +++++++++++++++++++++++----------------------------
2 files changed, 70 insertions(+), 85 deletions(-)
diffs (281 lines):
diff -r 41dcba56b253 -r 7b291f99dd6a sys/dev/usb/if_axe.c
--- a/sys/dev/usb/if_axe.c Fri Mar 27 17:42:36 2020 +0000
+++ b/sys/dev/usb/if_axe.c Fri Mar 27 18:04:45 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_axe.c,v 1.130 2020/03/15 23:04:50 thorpej Exp $ */
+/* $NetBSD: if_axe.c,v 1.131 2020/03/27 18:04:45 nisimura Exp $ */
/* $OpenBSD: if_axe.c,v 1.137 2016/04/13 11:03:37 mpi Exp $ */
/*
@@ -87,7 +87,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.130 2020/03/15 23:04:50 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_axe.c,v 1.131 2020/03/27 18:04:45 nisimura Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -426,7 +426,7 @@
}
static void
-axe_setiff_locked(struct usbnet *un)
+axe_rcvfilt_locked(struct usbnet *un)
{
AXEHIST_FUNC(); AXEHIST_CALLED();
struct axe_softc * const sc = usbnet_softc(un);
@@ -434,9 +434,9 @@
struct ethercom *ec = usbnet_ec(un);
struct ether_multi *enm;
struct ether_multistep step;
+ uint16_t rxmode;
uint32_t h = 0;
- uint16_t rxmode;
- uint8_t hashtbl[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ uint8_t mchash[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
if (usbnet_isdying(un))
return;
@@ -450,38 +450,34 @@
rxmode &=
~(AXE_RXCMD_ALLMULTI | AXE_RXCMD_PROMISC | AXE_RXCMD_MULTICAST);
+ ETHER_LOCK(ec);
if (ifp->if_flags & IFF_PROMISC) {
- ifp->if_flags |= IFF_ALLMULTI;
- goto allmulti;
+ ec->ec_flags |= ETHER_F_ALLMULTI;
+ ETHER_UNLOCK(ec);
+ /* run promisc. mode */
+ rxmode |= AXE_RXCMD_ALLMULTI; /* ??? */
+ rxmode |= AXE_RXCMD_PROMISC;
+ goto update;
}
- ifp->if_flags &= ~IFF_ALLMULTI;
-
- /* Now program new ones */
- ETHER_LOCK(ec);
+ ec->ec_flags &= ~ETHER_F_ALLMULTI;
ETHER_FIRST_MULTI(step, ec, enm);
while (enm != NULL) {
- if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
- ETHER_ADDR_LEN) != 0) {
+ if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
+ ec->ec_flags |= ETHER_F_ALLMULTI;
ETHER_UNLOCK(ec);
- ifp->if_flags |= IFF_ALLMULTI;
- goto allmulti;
+ /* accept all mcast frames */
+ rxmode |= AXE_RXCMD_ALLMULTI;
+ goto update;
}
-
- h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26;
- hashtbl[h >> 3] |= 1U << (h & 7);
+ h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN);
+ mchash[h >> 29] |= 1U << ((h >> 26) & 7);
ETHER_NEXT_MULTI(step, enm);
}
ETHER_UNLOCK(ec);
-
- rxmode |= AXE_RXCMD_MULTICAST; /* activate mcast hash filter */
- axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, hashtbl);
- axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
- return;
-
- allmulti:
- if (ifp->if_flags & IFF_PROMISC)
- rxmode |= AXE_RXCMD_PROMISC; /* run promisc. mode */
- rxmode |= AXE_RXCMD_ALLMULTI; /* accept all mcast frames */
+ if (h != 0)
+ rxmode |= AXE_RXCMD_MULTICAST; /* activate mcast hash filter */
+ axe_cmd(sc, AXE_CMD_WRITE_MCAST, 0, 0, mchash);
+ update:
axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
}
@@ -1311,7 +1307,7 @@
axe_cmd(sc, AXE_CMD_RXCTL_WRITE, 0, rxmode, NULL);
/* Accept multicast frame or run promisc. mode */
- axe_setiff_locked(un);
+ axe_rcvfilt_locked(un);
return usbnet_init_rx_tx(un);
}
@@ -1341,7 +1337,7 @@
switch (cmd) {
case SIOCADDMULTI:
case SIOCDELMULTI:
- axe_setiff_locked(un);
+ axe_rcvfilt_locked(un);
break;
default:
break;
diff -r 41dcba56b253 -r 7b291f99dd6a sys/dev/usb/if_ure.c
--- a/sys/dev/usb/if_ure.c Fri Mar 27 17:42:36 2020 +0000
+++ b/sys/dev/usb/if_ure.c Fri Mar 27 18:04:45 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_ure.c,v 1.39 2020/03/21 06:54:43 skrll Exp $ */
+/* $NetBSD: if_ure.c,v 1.40 2020/03/27 18:04:45 nisimura Exp $ */
/* $OpenBSD: if_ure.c,v 1.10 2018/11/02 21:32:30 jcs Exp $ */
/*-
@@ -30,7 +30,7 @@
/* RealTek RTL8152/RTL8153 10/100/Gigabit USB Ethernet device */
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.39 2020/03/21 06:54:43 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ure.c,v 1.40 2020/03/27 18:04:45 nisimura Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -331,15 +331,14 @@
}
static void
-ure_setiff_locked(struct usbnet *un)
+ure_rcvfilt_locked(struct usbnet *un)
{
struct ethercom *ec = usbnet_ec(un);
struct ifnet *ifp = usbnet_ifp(un);
struct ether_multi *enm;
struct ether_multistep step;
- uint32_t hashes[2] = { 0, 0 };
- uint32_t hash;
- uint32_t rxmode;
+ uint32_t mchash[2] = { 0, 0 };
+ uint32_t h = 0, rxmode;
usbnet_isowned_core(un);
@@ -347,54 +346,43 @@
return;
rxmode = ure_read_4(un, URE_PLA_RCR, URE_MCU_TYPE_PLA);
- rxmode &= ~URE_RCR_ACPT_ALL;
+ rxmode &= ~(URE_RCR_AAP | URE_RCR_AM);
+ /* continue to accept my own DA and bcast frames */
- /*
- * Always accept frames destined to our station address.
- * Always accept broadcast frames.
- */
- rxmode |= URE_RCR_APM | URE_RCR_AB;
-
+ ETHER_LOCK(ec);
if (ifp->if_flags & IFF_PROMISC) {
- rxmode |= URE_RCR_AAP;
-allmulti:
- ETHER_LOCK(ec);
ec->ec_flags |= ETHER_F_ALLMULTI;
ETHER_UNLOCK(ec);
- rxmode |= URE_RCR_AM;
- hashes[0] = hashes[1] = 0xffffffff;
- } else {
- rxmode |= URE_RCR_AM;
-
- ETHER_LOCK(ec);
- ec->ec_flags &= ~ETHER_F_ALLMULTI;
-
- ETHER_FIRST_MULTI(step, ec, enm);
- while (enm != NULL) {
- if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
- ETHER_ADDR_LEN)) {
- ETHER_UNLOCK(ec);
- goto allmulti;
- }
-
- hash = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN)
- >> 26;
- if (hash < 32)
- hashes[0] |= (1 << hash);
- else
- hashes[1] |= (1 << (hash - 32));
-
- ETHER_NEXT_MULTI(step, enm);
+ /* run promisc. mode */
+ rxmode |= URE_RCR_AM; /* ??? */
+ rxmode |= URE_RCR_AAP;
+ goto update;
+ }
+ ec->ec_flags &= ~ETHER_F_ALLMULTI;
+ ETHER_FIRST_MULTI(step, ec, enm);
+ while (enm != NULL) {
+ if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
+ ec->ec_flags |= ETHER_F_ALLMULTI;
+ ETHER_UNLOCK(ec);
+ /* accept all mcast frames */
+ rxmode |= URE_RCR_AM;
+ mchash[0] = mchash[1] = ~0U; /* necessary ?? */
+ goto update;
}
- ETHER_UNLOCK(ec);
-
- hash = bswap32(hashes[0]);
- hashes[0] = bswap32(hashes[1]);
- hashes[1] = hash;
+ h = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN);
+ mchash[h >> 31] |= 1 << ((h >> 26) & 0x1f);
+ ETHER_NEXT_MULTI(step, enm);
}
-
- ure_write_4(un, URE_PLA_MAR0, URE_MCU_TYPE_PLA, hashes[0]);
- ure_write_4(un, URE_PLA_MAR4, URE_MCU_TYPE_PLA, hashes[1]);
+ ETHER_UNLOCK(ec);
+ if (h != 0) {
+ rxmode |= URE_RCR_AM; /* activate mcast hash filter */
+ h = bswap32(mchash[0]);
+ mchash[0] = bswap32(mchash[1]);
+ mchash[1] = h;
+ }
+ update:
+ ure_write_4(un, URE_PLA_MAR0, URE_MCU_TYPE_PLA, mchash[0]);
+ ure_write_4(un, URE_PLA_MAR4, URE_MCU_TYPE_PLA, mchash[1]);
ure_write_4(un, URE_PLA_RCR, URE_MCU_TYPE_PLA, rxmode);
}
@@ -457,8 +445,8 @@
ure_read_2(un, URE_PLA_MISC_1, URE_MCU_TYPE_PLA) &
~URE_RXDY_GATED_EN);
- /* Load the multicast filter. */
- ure_setiff_locked(un);
+ /* Accept multicast frame or run promisc. mode. */
+ ure_rcvfilt_locked(un);
return usbnet_init_rx_tx(un);
}
@@ -701,7 +689,7 @@
static void
ure_init_fifo(struct usbnet *un)
{
- uint32_t rx_fifo1, rx_fifo2;
+ uint32_t rxmode, rx_fifo1, rx_fifo2;
int i;
ure_write_2(un, URE_PLA_MISC_1, URE_MCU_TYPE_PLA,
@@ -710,9 +698,10 @@
ure_disable_teredo(un);
- ure_write_4(un, URE_PLA_RCR, URE_MCU_TYPE_PLA,
- ure_read_4(un, URE_PLA_RCR, URE_MCU_TYPE_PLA) &
- ~URE_RCR_ACPT_ALL);
+ rxmode = ure_read_4(un, URE_PLA_RCR, URE_MCU_TYPE_PLA);
+ rxmode &= ~URE_RCR_ACPT_ALL;
+ rxmode |= URE_RCR_APM | URE_RCR_AB; /* accept my own DA and bcast */
+ ure_write_4(un, URE_PLA_RCR, URE_MCU_TYPE_PLA, rxmode);
if (!(un->un_flags & URE_FLAG_8152)) {
if (un->un_flags & (URE_FLAG_VER_5C00 | URE_FLAG_VER_5C10 |
@@ -816,7 +805,7 @@
switch (cmd) {
case SIOCADDMULTI:
case SIOCDELMULTI:
- ure_setiff_locked(un);
+ ure_rcvfilt_locked(un);
break;
default:
break;
Home |
Main Index |
Thread Index |
Old Index