From owner-svn-src-all@freebsd.org Mon May 16 19:11:01 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 42E65B3DA08; Mon, 16 May 2016 19:11:01 +0000 (UTC) (envelope-from avos@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 04AD41807; Mon, 16 May 2016 19:11:00 +0000 (UTC) (envelope-from avos@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4GJB0CD001428; Mon, 16 May 2016 19:11:00 GMT (envelope-from avos@FreeBSD.org) Received: (from avos@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4GJB0oL001427; Mon, 16 May 2016 19:11:00 GMT (envelope-from avos@FreeBSD.org) Message-Id: <201605161911.u4GJB0oL001427@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avos set sender to avos@FreeBSD.org using -f From: Andriy Voskoboinyk Date: Mon, 16 May 2016 19:11:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299965 - head/sys/dev/urtwn X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 May 2016 19:11:01 -0000 Author: avos Date: Mon May 16 19:10:59 2016 New Revision: 299965 URL: https://svnweb.freebsd.org/changeset/base/299965 Log: urtwn: add support for hardware multicast filter setup. Tested with RTL8188EU and RTL8188CUS. Modified: head/sys/dev/urtwn/if_urtwn.c Modified: head/sys/dev/urtwn/if_urtwn.c ============================================================================== --- head/sys/dev/urtwn/if_urtwn.c Mon May 16 19:10:35 2016 (r299964) +++ head/sys/dev/urtwn/if_urtwn.c Mon May 16 19:10:59 2016 (r299965) @@ -356,6 +356,8 @@ static void urtwn_update_slot(struct ie static void urtwn_update_slot_cb(struct urtwn_softc *, union sec_param *); static void urtwn_update_aifs(struct urtwn_softc *, uint8_t); +static uint8_t urtwn_get_multi_pos(const uint8_t[]); +static void urtwn_set_multi(struct urtwn_softc *); static void urtwn_set_promisc(struct urtwn_softc *); static void urtwn_update_promisc(struct ieee80211com *); static void urtwn_update_mcast(struct ieee80211com *); @@ -4359,9 +4361,8 @@ urtwn_rxfilter_init(struct urtwn_softc * URTWN_ASSERT_LOCKED(sc); - /* Accept all multicast frames. */ - urtwn_write_4(sc, R92C_MAR + 0, 0xffffffff); - urtwn_write_4(sc, R92C_MAR + 4, 0xffffffff); + /* Setup multicast filter. */ + urtwn_set_multi(sc); /* Filter for management frames. */ filter = 0x7f3f; @@ -4822,6 +4823,67 @@ urtwn_update_aifs(struct urtwn_softc *sc } } +static uint8_t +urtwn_get_multi_pos(const uint8_t maddr[]) +{ + uint64_t mask = 0x00004d101df481b4; + uint8_t pos = 0x27; /* initial value */ + int i, j; + + for (i = 0; i < IEEE80211_ADDR_LEN; i++) + for (j = (i == 0) ? 1 : 0; j < 8; j++) + if ((maddr[i] >> j) & 1) + pos ^= (mask >> (i * 8 + j - 1)); + + pos &= 0x3f; + + return (pos); +} + +static void +urtwn_set_multi(struct urtwn_softc *sc) +{ + struct ieee80211com *ic = &sc->sc_ic; + uint32_t mfilt[2]; + + URTWN_ASSERT_LOCKED(sc); + + /* general structure was copied from ath(4). */ + if (ic->ic_allmulti == 0) { + struct ieee80211vap *vap; + struct ifnet *ifp; + struct ifmultiaddr *ifma; + + /* + * Merge multicast addresses to form the hardware filter. + */ + mfilt[0] = mfilt[1] = 0; + TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) { + ifp = vap->iv_ifp; + if_maddr_rlock(ifp); + TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { + caddr_t dl; + uint8_t pos; + + dl = LLADDR((struct sockaddr_dl *) + ifma->ifma_addr); + pos = urtwn_get_multi_pos(dl); + + mfilt[pos / 32] |= (1 << (pos % 32)); + } + if_maddr_runlock(ifp); + } + } else + mfilt[0] = mfilt[1] = ~0; + + + urtwn_write_4(sc, R92C_MAR + 0, mfilt[0]); + urtwn_write_4(sc, R92C_MAR + 4, mfilt[1]); + + URTWN_DPRINTF(sc, URTWN_DEBUG_STATE, "%s: MC filter %08x:%08x\n", + __func__, mfilt[0], mfilt[1]); +} + static void urtwn_set_promisc(struct urtwn_softc *sc) { @@ -4877,7 +4939,12 @@ urtwn_update_promisc(struct ieee80211com static void urtwn_update_mcast(struct ieee80211com *ic) { - /* XXX do nothing? */ + struct urtwn_softc *sc = ic->ic_softc; + + URTWN_LOCK(sc); + if (sc->sc_flags & URTWN_RUNNING) + urtwn_set_multi(sc); + URTWN_UNLOCK(sc); } static struct ieee80211_node *