svn commit: r309214 - head/sys/dev/usb/wlan

Andriy Voskoboinyk avos at FreeBSD.org
Sun Nov 27 18:06:04 UTC 2016


Author: avos
Date: Sun Nov 27 18:06:03 2016
New Revision: 309214
URL: https://svnweb.freebsd.org/changeset/base/309214

Log:
  rsu: add support for hardware multicast filter setup.
  
  The algorithm is the same as in rtwn(4).
  
  Tested with Asus USB-N10 (STA) + RTL8188CUS (AP).

Modified:
  head/sys/dev/usb/wlan/if_rsu.c
  head/sys/dev/usb/wlan/if_rsureg.h

Modified: head/sys/dev/usb/wlan/if_rsu.c
==============================================================================
--- head/sys/dev/usb/wlan/if_rsu.c	Sun Nov 27 14:27:51 2016	(r309213)
+++ head/sys/dev/usb/wlan/if_rsu.c	Sun Nov 27 18:06:03 2016	(r309214)
@@ -175,6 +175,8 @@ static void	rsu_getradiocaps(struct ieee
 static void	rsu_set_channel(struct ieee80211com *);
 static void	rsu_scan_curchan(struct ieee80211_scan_state *, unsigned long);
 static void	rsu_scan_mindwell(struct ieee80211_scan_state *);
+static uint8_t	rsu_get_multi_pos(const uint8_t[]);
+static void	rsu_set_multi(struct rsu_softc *);
 static void	rsu_update_mcast(struct ieee80211com *);
 static int	rsu_alloc_rx_list(struct rsu_softc *);
 static void	rsu_free_rx_list(struct rsu_softc *);
@@ -750,10 +752,78 @@ rsu_scan_mindwell(struct ieee80211_scan_
 	/* NB: don't try to abort scan; wait for firmware to finish */
 }
 
+/*
+ * The same as rtwn_get_multi_pos() / rtwn_set_multi().
+ */
+static uint8_t
+rsu_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
+rsu_set_multi(struct rsu_softc *sc)
+{
+	struct ieee80211com *ic = &sc->sc_ic;
+	uint32_t mfilt[2];
+
+	RSU_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 = rsu_get_multi_pos(dl);
+
+				mfilt[pos / 32] |= (1 << (pos % 32));
+			}
+			if_maddr_runlock(ifp);
+		}
+	} else
+		mfilt[0] = mfilt[1] = ~0;
+
+	rsu_write_4(sc, R92S_MAR + 0, mfilt[0]);
+	rsu_write_4(sc, R92S_MAR + 4, mfilt[1]);
+
+	RSU_DPRINTF(sc, RSU_DEBUG_STATE, "%s: MC filter %08x:%08x\n",
+	    __func__, mfilt[0], mfilt[1]);
+}
+
 static void
 rsu_update_mcast(struct ieee80211com *ic)
 {
-        /* XXX do nothing?  */
+	struct rsu_softc *sc = ic->ic_softc;
+
+	RSU_LOCK(sc);
+	if (sc->sc_running)
+		rsu_set_multi(sc);
+	RSU_UNLOCK(sc);
 }
 
 static int
@@ -2925,6 +2995,9 @@ rsu_init(struct rsu_softc *sc)
 		goto fail;
 	}
 
+	/* Setup multicast filter (must be done after firmware loading). */
+	rsu_set_multi(sc);
+
 	/* Set PS mode fully active */
 	error = rsu_set_fw_power_state(sc, RSU_PWR_ACTIVE);
 

Modified: head/sys/dev/usb/wlan/if_rsureg.h
==============================================================================
--- head/sys/dev/usb/wlan/if_rsureg.h	Sun Nov 27 14:27:51 2016	(r309213)
+++ head/sys/dev/usb/wlan/if_rsureg.h	Sun Nov 27 18:06:03 2016	(r309214)
@@ -48,6 +48,7 @@
 
 #define R92S_MACIDSETTING	0x0050
 #define R92S_MACID		(R92S_MACIDSETTING + 0x000)
+#define R92S_MAR		(R92S_MACIDSETTING + 0x010)
 
 #define R92S_GP			0x01e0
 #define R92S_GPIO_CTRL		(R92S_GP + 0x00c)


More information about the svn-src-all mailing list