PERFORCE change 65684 for review
Sam Leffler
sam at FreeBSD.org
Tue Nov 23 03:48:46 GMT 2004
http://perforce.freebsd.org/chv.cgi?CH=65684
Change 65684 by sam at sam_ebb on 2004/11/23 03:48:38
pack allocated vap identifiers
Affected files ...
.. //depot/projects/wifi/sys/net80211/ieee80211.c#10 edit
Differences ...
==== //depot/projects/wifi/sys/net80211/ieee80211.c#10 (text+ko) ====
@@ -65,10 +65,44 @@
SLIST_HEAD(ieee80211_list, ieee80211com);
static struct ieee80211_list ieee80211_list =
SLIST_HEAD_INITIALIZER(ieee80211_list);
-static int ieee80211_vap = 0; /* next avail vap number */
+static u_int8_t ieee80211_vapmap[32]; /* enough for 256 */
static struct mtx ieee80211_vap_mtx;
MTX_SYSINIT(ieee80211, &ieee80211_vap_mtx, "net80211 instances", MTX_DEF);
+static void
+ieee80211_add_vap(struct ieee80211com *ic)
+{
+#define N(a) (sizeof(a)/sizeof(a[0]))
+ int i;
+ u_int8_t b;
+
+ mtx_lock(&ieee80211_vap_mtx);
+ ic->ic_vap = 0;
+ for (i = 0; i < N(ieee80211_vapmap) && ieee80211_vapmap[i] == 0xff; i++)
+ ic->ic_vap += NBBY;
+ if (i == N(ieee80211_vapmap))
+ panic("vap table full");
+ for (b = ieee80211_vapmap[i]; b & 1; b >>= 1)
+ ic->ic_vap++;
+ setbit(ieee80211_vapmap, ic->ic_vap);
+ SLIST_INSERT_HEAD(&ieee80211_list, ic, ic_next);
+ mtx_unlock(&ieee80211_vap_mtx);
+#undef N
+}
+
+static void
+ieee80211_remove_vap(struct ieee80211com *ic)
+{
+ mtx_lock(&ieee80211_vap_mtx);
+ SLIST_REMOVE(&ieee80211_list, ic, ieee80211com, ic_next);
+ KASSERT(ic->ic_vap < sizeof(ieee80211_vapmap)*NBBY,
+ ("invalid vap id %d", ic->ic_vap));
+ KASSERT(isset(ieee80211_vapmap, ic->ic_vap),
+ ("vap id %d not allocated", ic->ic_vap));
+ clrbit(ieee80211_vapmap, ic->ic_vap);
+ mtx_unlock(&ieee80211_vap_mtx);
+}
+
void
ieee80211_ifattach(struct ieee80211com *ic)
{
@@ -135,10 +169,7 @@
ieee80211_node_attach(ic);
ieee80211_proto_attach(ic);
- mtx_lock(&ieee80211_vap_mtx);
- ic->ic_vap = ieee80211_vap++; /* XXX use bitmap */
- SLIST_INSERT_HEAD(&ieee80211_list, ic, ic_next);
- mtx_unlock(&ieee80211_vap_mtx);
+ ieee80211_add_vap(ic);
ieee80211_sysctl_attach(ic); /* NB: requires ic_vap */
}
@@ -148,9 +179,7 @@
{
struct ifnet *ifp = ic->ic_ifp;
- mtx_lock(&ieee80211_vap_mtx);
- SLIST_REMOVE(&ieee80211_list, ic, ieee80211com, ic_next);
- mtx_unlock(&ieee80211_vap_mtx);
+ ieee80211_remove_vap(ic);
ieee80211_sysctl_detach(ic);
ieee80211_proto_detach(ic);
More information about the p4-projects
mailing list