Skip to contentSkip to conversation

ath9k: Virtual interfaces and radios

PATCH In review Jouni Malinen 2 participants 18 messages Mar 3, 2009 – Mar 12, 2009 Networking drivers (wireless)

lore
Share & tools
lore
#0 lore raw

cover ath9k: Virtual interfaces and radios

This set of patches brings in an initial step in adding support for multiple virtual interfaces into ath9k both at the multi-vif (for single channel only) and multi-wiphy (virtual radios that can be used with multiple channels). The patches are on top of the current wireless-testing tree, the beacon changes from Sujith and a setkey patch from earlier today.

The first two patches clean up the multi-vif code and prepare the driver for use of multiple MAC addresses. The third patch starts the work on the concept of a virtual wiphy/radio (i.e., ath9k will be able to register multiple "radios" with mac80211, but without mac80211 having to know about multi-channel operations). The fourth patch adds support for multiple secondary wiphys. The patches 5-13 are completing and improving the virtual interface operations.

The 14th patch file brings in a simple channel scheduler that is enough for initial tests, but will be optimized in the future to take into account various corner cases and different states of each virtual radio to time the channel changes better.

The final patch in this series adds a debugfs interface that makes it possible to control the virtual radios (e.g., add a new "radio"). For now, this is enough to allow initial testing and experiments with the new virtual wiphy concept. In the future, more official interface (e.g., an nl80211 command passed through mac80211) is likely to remove need for a debugfs interface.

Lot of the code here is still quite experimental, but taken into account how many areas this touches, it would be helpful to get at least parts of this merged in. I'm not aware of any regressions for single-interface operations.

There are still some known limitations for the multi-interface operations and one should be aware of these when running experiments with the code. These will be worked on in the future to avoid the extra complexity or compromises needed in the initial version.

Key cache configuration does not yet handle all combinations of security policies in virtual interfaces. Consequently, the recommended starting point is to use software crypto when using multiple wiphys/vifs, i.e., use nohwcrypt=1 module parameter.

There is currently support for only a single beaconing interface, i.e., not more than one AP wiphy can be added at a time. There is no such limitation for station interfaces, i.e., arbitrary number of virtual station wiphys can be added and used on arbitrary channels. Though, the simple channel scheduler will start showing up its simplicity with increased latency if there the wiphys end up on large number of different channels.

Quick steps to start experiments:

modprobe ath9k nohwcrypt=1

# make sure debugfs is mounted somewhere (replace '/debug' in the
# command below with wherever the root directory is)
# wlan0 can now be used, e.g., with wpa_supplicant

echo add > /debug/ath9k/phy0/wiphy

# wlan1 can now be used, e.g., with wpa_supplicant

echo add > /debug/ath9k/phy0/wiphy

# wlan2 can now be used, e.g., with wpa_supplicant

and so on.. In theory, all the virtual wiphy interfaces could be used as if they are real radios (run wpa_supplicant, hostapd, use iwconfig, etc.).

When using virtual wiphys, the APs that the virtual interfaces are associated with do not need to be on the same channel. One of the wiphys could also be used with hostapd to bring up an AP. However, it should be noted that most client implementation do not exactly like the AP disappearing all the time, so using a virtual station interface on another channel at the same time may not be that good of an idea for most use cases now. This will hopefully improve somewhat with future optimizations.

It would be useful to hear what others think about this sort of functionality and how this should be integrated with Linux, including the user space interface, applications managing the virtual interface functionality, and user interface that the end users would see. This is still quite an early step in the progress, but the goal here is to get this functionality into mature state and provide something that makes it easier to use wireless LAN in general for connecting devices in various scenarios. All feedback would be welcome!

Signature · 1 line
Jouni Malinen                                            PGP id EFC895FA
#1 lore raw

PATCH 1/15 ath9k: Cleanup multiple VIF processing

Replace the internal sc_vaps array and index values by using vif pointer from mac80211. Allow multiple VIPs to be registered. Though, number of beaconing VIFs is still limited by ATH_BCBUF (currently 1). Multiple virtual STAs support is not yet complete, but at least the data structures should now be able to handle this.

---
 drivers/net/wireless/ath9k/ath9k.h  |    8 ++---
 drivers/net/wireless/ath9k/beacon.c |   54 ++++++++++++++++--------------------
 drivers/net/wireless/ath9k/main.c   |   54 +++++++++++++++++++++---------------
 3 files changed, 59 insertions(+), 57 deletions(-)
drivers/net/wireless/ath9k/beacon.c +24 -30
@@ -113,17 +113,16 @@ static void ath_beacon_setup(struct ath_
 				     series, 4, 0);
 }
 
-static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id)
+static struct ath_buf *ath_beacon_generate(struct ath_softc *sc,
+					   struct ieee80211_vif *vif)
 {
 	struct ath_buf *bf;
 	struct ath_vif *avp;
 	struct sk_buff *skb;
 	struct ath_txq *cabq;
-	struct ieee80211_vif *vif;
 	struct ieee80211_tx_info *info;
 	int cabq_depth;
 
-	vif = sc->vifs[if_id];
 	avp = (void *)vif->drv_priv;
 	cabq = sc->beacon.cabq;
 
@@ -208,15 +207,14 @@ static struct ath_buf *ath_beacon_genera
  * Startup beacon transmission for adhoc mode when they are sent entirely
  * by the hardware using the self-linked descriptor + veol trick.
 */
-static void ath_beacon_start_adhoc(struct ath_softc *sc, int if_id)
+static void ath_beacon_start_adhoc(struct ath_softc *sc,
+				   struct ieee80211_vif *vif)
 {
-	struct ieee80211_vif *vif;
 	struct ath_hw *ah = sc->sc_ah;
 	struct ath_buf *bf;
 	struct ath_vif *avp;
 	struct sk_buff *skb;
 
-	vif = sc->vifs[if_id];
 	avp = (void *)vif->drv_priv;
 
 	if (avp->av_bcbuf == NULL)
@@ -246,16 +244,14 @@ int ath_beaconq_setup(struct ath_hw *ah)
 	return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi);
 }
 
-int ath_beacon_alloc(struct ath_softc *sc, int if_id)
+int ath_beacon_alloc(struct ath_softc *sc, struct ieee80211_vif *vif)
 {
-	struct ieee80211_vif *vif;
 	struct ath_vif *avp;
 	struct ieee80211_hdr *hdr;
 	struct ath_buf *bf;
 	struct sk_buff *skb;
 	__le64 tstamp;
 
-	vif = sc->vifs[if_id];
 	avp = (void *)vif->drv_priv;
 
 	/* Allocate a beacon descriptor if we haven't done so. */
@@ -275,22 +271,21 @@ int ath_beacon_alloc(struct ath_softc *s
 			 */
 			avp->av_bslot = 0;
 			for (slot = 0; slot < ATH_BCBUF; slot++)
-				if (sc->beacon.bslot[slot] == ATH_IF_ID_ANY) {
+				if (sc->beacon.bslot[slot] == NULL) {
 					/*
 					 * XXX hack, space out slots to better
 					 * deal with misses
 					 */
 					if (slot+1 < ATH_BCBUF &&
-					    sc->beacon.bslot[slot+1] ==
-						ATH_IF_ID_ANY) {
+					    sc->beacon.bslot[slot+1] == NULL) {
 						avp->av_bslot = slot+1;
 						break;
 					}
 					avp->av_bslot = slot;
 					/* NB: keep looking for a double slot */
 				}
-			BUG_ON(sc->beacon.bslot[avp->av_bslot] != ATH_IF_ID_ANY);
-			sc->beacon.bslot[avp->av_bslot] = if_id;
+			BUG_ON(sc->beacon.bslot[avp->av_bslot] != NULL);
+			sc->beacon.bslot[avp->av_bslot] = vif;
 			sc->nbcnvifs++;
 		}
 	}
@@ -372,7 +367,7 @@ void ath_beacon_return(struct ath_softc 
 		struct ath_buf *bf;
 
 		if (avp->av_bslot != -1) {
-			sc->beacon.bslot[avp->av_bslot] = ATH_IF_ID_ANY;
+			sc->beacon.bslot[avp->av_bslot] = NULL;
 			sc->nbcnvifs--;
 		}
 
@@ -395,7 +390,8 @@ void ath_beacon_tasklet(unsigned long da
 	struct ath_softc *sc = (struct ath_softc *)data;
 	struct ath_hw *ah = sc->sc_ah;
 	struct ath_buf *bf = NULL;
-	int slot, if_id;
+	struct ieee80211_vif *vif;
+	int slot;
 	u32 bfaddr, bc = 0, tsftu;
 	u64 tsf;
 	u16 intval;
@@ -442,15 +438,15 @@ void ath_beacon_tasklet(unsigned long da
 	tsf = ath9k_hw_gettsf64(ah);
 	tsftu = TSF_TO_TU(tsf>>32, tsf);
 	slot = ((tsftu % intval) * ATH_BCBUF) / intval;
-	if_id = sc->beacon.bslot[(slot + 1) % ATH_BCBUF];
+	vif = sc->beacon.bslot[(slot + 1) % ATH_BCBUF];
 
 	DPRINTF(sc, ATH_DBG_BEACON,
-		"slot %d [tsf %llu tsftu %u intval %u] if_id %d\n",
-		slot, tsf, tsftu, intval, if_id);
+		"slot %d [tsf %llu tsftu %u intval %u] vif %p\n",
+		slot, tsf, tsftu, intval, vif);
 
 	bfaddr = 0;
-	if (if_id != ATH_IF_ID_ANY) {
-		bf = ath_beacon_generate(sc, if_id);
+	if (vif) {
+		bf = ath_beacon_generate(sc, vif);
 		if (bf != NULL) {
 			bfaddr = bf->bf_daddr;
 			bc = 1;
@@ -652,7 +648,8 @@ static void ath_beacon_config_sta(struct
 
 static void ath_beacon_config_adhoc(struct ath_softc *sc,
 				    struct ath_beacon_config *conf,
-				    struct ath_vif *avp)
+				    struct ath_vif *avp,
+				    struct ieee80211_vif *vif)
 {
 	u64 tsf;
 	u32 tsftu, intval, nexttbtt;
@@ -696,14 +693,12 @@ static void ath_beacon_config_adhoc(stru
 	ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
 
 	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_VEOL)
-		ath_beacon_start_adhoc(sc, 0);
+		ath_beacon_start_adhoc(sc, vif);
 }
 
-void ath_beacon_config(struct ath_softc *sc, int if_id)
+void ath_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif)
 {
 	struct ath_beacon_config conf;
-	struct ath_vif *avp;
-	struct ieee80211_vif *vif;
 
 	/* Setup the beacon configuration parameters */
 
@@ -715,16 +710,15 @@ void ath_beacon_config(struct ath_softc 
 	conf.dtim_count = 1;
 	conf.bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf.beacon_interval;
 
-	if (if_id != ATH_IF_ID_ANY) {
-		vif = sc->vifs[if_id];
-		avp = (struct ath_vif *)vif->drv_priv;
+	if (vif) {
+		struct ath_vif *avp = (struct ath_vif *)vif->drv_priv;
 
 		switch(avp->av_opmode) {
 		case NL80211_IFTYPE_AP:
 			ath_beacon_config_ap(sc, &conf, avp);
 			break;
 		case NL80211_IFTYPE_ADHOC:
-			ath_beacon_config_adhoc(sc, &conf, avp);
+			ath_beacon_config_adhoc(sc, &conf, avp, vif);
 			break;
 		case NL80211_IFTYPE_STATION:
 			ath_beacon_config_sta(sc, &conf, avp);
drivers/net/wireless/ath9k/main.c +32 -22

149 lines not on this page · raw message

drivers/net/wireless/ath9k/ath9k.h +3 -5
@@ -439,7 +439,7 @@ struct ath_beacon {
 	u32 bmisscnt;
 	u32 ast_be_xmit;
 	u64 bc_tstamp;
-	int bslot[ATH_BCBUF];
+	struct ieee80211_vif *bslot[ATH_BCBUF];
 	int slottime;
 	int slotupdate;
 	struct ath9k_tx_queue_info beacon_qi;
@@ -449,9 +449,9 @@ struct ath_beacon {
 };
 
 void ath_beacon_tasklet(unsigned long data);
-void ath_beacon_config(struct ath_softc *sc, int if_id);
+void ath_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif);
 int ath_beaconq_setup(struct ath_hw *ah);
-int ath_beacon_alloc(struct ath_softc *sc, int if_id);
+int ath_beacon_alloc(struct ath_softc *sc, struct ieee80211_vif *vif);
 void ath_beacon_return(struct ath_softc *sc, struct ath_vif *avp);
 
 /*******/
@@ -532,7 +532,6 @@ struct ath_rfkill {
  */
 #define	ATH_KEYMAX	        128     /* max key cache size we handle */
 
-#define ATH_IF_ID_ANY   	0xff
 #define ATH_TXPOWER_MAX         100     /* .5 dBm units */
 #define ATH_RSSI_DUMMY_MARKER   0x127
 #define ATH_RATE_DUMMY_MARKER   0
@@ -595,7 +594,6 @@ struct ath_softc {
 	struct ath_rx rx;
 	struct ath_tx tx;
 	struct ath_beacon beacon;
-	struct ieee80211_vif *vifs[ATH_BCBUF];
 	struct ieee80211_rate rates[IEEE80211_NUM_BANDS][ATH_RATE_MAX];
 	struct ath_rate_table *hw_rate_table[ATH9K_MODE_MAX];
 	struct ath_rate_table *cur_rate_table;
Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#2 lore raw

PATCH 2/15 ath9k: Set BSSID mask based on configured interfaces

In reply to Jouni Malinen

Instead of using a hardcoded BSSID mask (mask for own addresses), iterate through all active interfaces and determine the minimal mask that covers all local addresses.

---
 drivers/net/wireless/ath9k/Makefile  |    1 
 drivers/net/wireless/ath9k/ath9k.h   |   14 +----
 drivers/net/wireless/ath9k/main.c    |   15 ++++-
 drivers/net/wireless/ath9k/virtual.c |   88 +++++++++++++++++++++++++++++++++++
 4 files changed, 103 insertions(+), 15 deletions(-)
drivers/net/wireless/ath9k/main.c +11 -4
@@ -1512,11 +1512,8 @@ static int ath_init(u16 devid, struct at
 	ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
 	sc->rx.defant = ath9k_hw_getdefantenna(ah);
 
-	if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) {
+	if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
 		memcpy(sc->bssidmask, ath_bcast_mac, ETH_ALEN);
-		ATH_SET_VIF_BSSID_MASK(sc->bssidmask);
-		ath9k_hw_setbssidmask(sc);
-	}
 
 	sc->beacon.slottime = ATH9K_SLOT_TIME_9;	/* default to short slot time */
 
@@ -2126,6 +2123,12 @@ static int ath9k_add_interface(struct ie
 
 	mutex_lock(&sc->mutex);
 
+	if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
+	    sc->nvifs > 0) {
+		ret = -ENOBUFS;
+		goto out;
+	}
+
 	switch (conf->type) {
 	case NL80211_IFTYPE_STATION:
 		ic_opmode = NL80211_IFTYPE_STATION;
@@ -2158,6 +2161,10 @@ static int ath9k_add_interface(struct ie
 	avp->av_bslot = -1;
 
 	sc->nvifs++;
+
+	if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
+		ath9k_set_bssid_mask(hw);
+
 	if (sc->nvifs > 1)
 		goto out; /* skip global settings for secondary vif */
 
drivers/net/wireless/ath9k/ath9k.h +3 -11
@@ -387,17 +387,6 @@ void ath_tx_aggr_resume(struct ath_softc
 /* VIFs */
 /********/
 
-/*
- * Define the scheme that we select MAC address for multiple
- * BSS on the same radio. The very first VIF will just use the MAC
- * address from the EEPROM. For the next 3 VIFs, we set the
- * U/L bit (bit 1) in MAC address, and use the next two bits as the
- * index of the VIF.
- */
-
-#define ATH_SET_VIF_BSSID_MASK(bssid_mask) \
-	((bssid_mask)[0] &= ~(((ATH_BCBUF-1)<<2)|0x02))
-
 struct ath_vif {
 	int av_bslot;
 	enum nl80211_iftype av_opmode;
@@ -675,4 +664,7 @@ static inline void ath9k_ps_restore(stru
 					  sc->sc_ah->restore_mode);
 }
 
+
+void ath9k_set_bssid_mask(struct ieee80211_hw *hw);
+
 #endif /* ATH9K_H */
drivers/net/wireless/ath9k/Makefile +1 -0
@@ -9,6 +9,7 @@ ath9k-y +=	hw.o \
 		main.o \
 		recv.o \
 		xmit.o \
+		virtual.o \
 		rc.o
 
 ath9k-$(CONFIG_PCI) += pci.o
drivers/net/wireless/ath9k/virtual.c new file +88 -0

88 lines not on this page · raw message

Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#3 lore raw

PATCH 3/15 ath9k: Add data structure for supporting virtual radio/wiphy operation

In reply to Jouni Malinen

This is the initial step in allowing ath9k to register multiple virtual radios (wiphys). The goal of virtual radios is to allow the same radio to be shared for multiple virtual interfaces that may operate on different channels. The mac80211 virtual interface support is designed only for single channel operation and as such, it is not suitable for this type of use. Anyway, it can be used on top of the virtual radio concept, if desired (e.g., use two virtual radios to handle two channels and then add multiple mac80211 virtual interfaces on top of each virtual radio).

The new struct ath_wiphy is now registered as the driver data structure for wiphy. This structure has a pointer to the shared (among virtual wiphys of the same physical radio) struct ath_softc data. The primary wiphy maintains the allocated memory for ath_softc. Secondary (virtual) wiphys will only allocate the new ath_wiphy structure.

Registration of secondary wiphys is added in a separate patch.

---
 drivers/net/wireless/ath9k/ahb.c     |   12 +++++--
 drivers/net/wireless/ath9k/ath9k.h   |    8 ++++
 drivers/net/wireless/ath9k/main.c    |   58 ++++++++++++++++++++++-------------
 drivers/net/wireless/ath9k/pci.c     |   19 ++++++++---
 drivers/net/wireless/ath9k/rc.c      |    3 +
 drivers/net/wireless/ath9k/recv.c    |   15 ++++++---
 drivers/net/wireless/ath9k/regd.c    |    6 ++-
 drivers/net/wireless/ath9k/virtual.c |    3 +
 8 files changed, 88 insertions(+), 36 deletions(-)
drivers/net/wireless/ath9k/ath9k.h +8 -0
@@ -549,9 +549,12 @@ struct ath_bus_ops {
 	bool		(*eeprom_read)(struct ath_hw *ah, u32 off, u16 *data);
 };
 
+struct ath_wiphy;
+
 struct ath_softc {
 	struct ieee80211_hw *hw;
 	struct device *dev;
+	struct ath_wiphy *pri_wiphy;
 	struct tasklet_struct intr_tq;
 	struct tasklet_struct bcon_tasklet;
 	struct ath_hw *sc_ah;
@@ -607,6 +610,11 @@ struct ath_softc {
 	struct ath_bus_ops *bus_ops;
 };
 
+struct ath_wiphy {
+	struct ath_softc *sc; /* shared for all virtual wiphys */
+	struct ieee80211_hw *hw;
+};
+
 int ath_reset(struct ath_softc *sc, bool retry_tx);
 int ath_get_hal_qnum(u16 queue, struct ath_softc *sc);
 int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc);
drivers/net/wireless/ath9k/pci.c +14 -5
@@ -83,6 +83,7 @@ static struct ath_bus_ops ath_pci_bus_op
 static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	void __iomem *mem;
+	struct ath_wiphy *aphy;
 	struct ath_softc *sc;
 	struct ieee80211_hw *hw;
 	u8 csz;
@@ -155,7 +156,8 @@ static int ath_pci_probe(struct pci_dev 
 		goto bad1;
 	}
 
-	hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
+	hw = ieee80211_alloc_hw(sizeof(struct ath_wiphy) +
+				sizeof(struct ath_softc), &ath9k_ops);
 	if (hw == NULL) {
 		printk(KERN_ERR "ath_pci: no memory for ieee80211_hw\n");
 		goto bad2;
@@ -164,7 +166,11 @@ static int ath_pci_probe(struct pci_dev 
 	SET_IEEE80211_DEV(hw, &pdev->dev);
 	pci_set_drvdata(pdev, hw);
 
-	sc = hw->priv;
+	aphy = hw->priv;
+	sc = (struct ath_softc *) (aphy + 1);
+	aphy->sc = sc;
+	aphy->hw = hw;
+	sc->pri_wiphy = aphy;
 	sc->hw = hw;
 	sc->dev = &pdev->dev;
 	sc->mem = mem;
@@ -214,7 +220,8 @@ bad:
 static void ath_pci_remove(struct pci_dev *pdev)
 {
 	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
-	struct ath_softc *sc = hw->priv;
+	struct ath_wiphy *aphy = hw->priv;
+	struct ath_softc *sc = aphy->sc;
 
 	ath_cleanup(sc);
 }
@@ -224,7 +231,8 @@ static void ath_pci_remove(struct pci_de
 static int ath_pci_suspend(struct pci_dev *pdev, pm_message_t state)
 {
 	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
-	struct ath_softc *sc = hw->priv;
+	struct ath_wiphy *aphy = hw->priv;
+	struct ath_softc *sc = aphy->sc;
 
 	ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
 
@@ -243,7 +251,8 @@ static int ath_pci_suspend(struct pci_de
 static int ath_pci_resume(struct pci_dev *pdev)
 {
 	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
-	struct ath_softc *sc = hw->priv;
+	struct ath_wiphy *aphy = hw->priv;
+	struct ath_softc *sc = aphy->sc;
 	u32 val;
 	int err;
 
drivers/net/wireless/ath9k/main.c +38 -20

178 lines not on this page · raw message

drivers/net/wireless/ath9k/ahb.c +9 -3
@@ -96,7 +96,8 @@ static int ath_ahb_probe(struct platform
 
 	irq = res->start;
 
-	hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
+	hw = ieee80211_alloc_hw(sizeof(struct ath_wiphy) +
+				sizeof(struct ath_softc), &ath9k_ops);
 	if (hw == NULL) {
 		dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
 		ret = -ENOMEM;
@@ -106,7 +107,11 @@ static int ath_ahb_probe(struct platform
 	SET_IEEE80211_DEV(hw, &pdev->dev);
 	platform_set_drvdata(pdev, hw);
 
-	sc = hw->priv;
+	aphy = hw->priv;
+	sc = (struct ath_softc *) (aphy + 1);
+	aphy->sc = sc;
+	aphy->hw = hw;
+	sc->pri_wiphy = aphy;
 	sc->hw = hw;
 	sc->dev = &pdev->dev;
 	sc->mem = mem;
@@ -156,7 +161,8 @@ static int ath_ahb_remove(struct platfor
 	struct ieee80211_hw *hw = platform_get_drvdata(pdev);
 
 	if (hw) {
-		struct ath_softc *sc = hw->priv;
+		struct ath_wiphy *aphy = hw->priv;
+		struct ath_softc *sc = aphy->sc;
 
 		ath_cleanup(sc);
 		platform_set_drvdata(pdev, NULL);
drivers/net/wireless/ath9k/rc.c +2 -1
@@ -1611,7 +1611,8 @@ static void ath_rate_init(void *priv, st
 
 static void *ath_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
 {
-	return hw->priv;
+	struct ath_wiphy *aphy = hw->priv;
+	return aphy->sc;
 }
 
 static void ath_rate_free(void *priv)
drivers/net/wireless/ath9k/regd.c +4 -2
@@ -311,7 +311,8 @@ void ath9k_reg_apply_radar_flags(struct 
 void ath9k_reg_apply_world_flags(struct wiphy *wiphy, enum reg_set_by setby)
 {
 	struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
-	struct ath_softc *sc = hw->priv;
+	struct ath_wiphy *aphy = hw->priv;
+	struct ath_softc *sc = aphy->sc;
 	struct ath_hw *ah = sc->sc_ah;
 
 	switch (ah->regulatory.regpair->regDmnEnum) {
@@ -332,7 +333,8 @@ void ath9k_reg_apply_world_flags(struct 
 int ath9k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request)
 {
 	struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
-	struct ath_softc *sc = hw->priv;
+	struct ath_wiphy *aphy = hw->priv;
+	struct ath_softc *sc = aphy->sc;
 
 	/* We always apply this */
 	ath9k_reg_apply_radar_flags(wiphy);
drivers/net/wireless/ath9k/recv.c +11 -4
@@ -16,6 +16,12 @@
 
 #include "ath9k.h"
 
+static struct ieee80211_hw * ath_get_virt_hw(struct ath_softc *sc,
+					     struct ieee80211_hdr *hdr)
+{
+	return sc->pri_wiphy->hw;
+}
+
 /*
  * Setup and link descriptors.
  *
@@ -123,10 +129,12 @@ static int ath_rx_prepare(struct sk_buff
 	struct ieee80211_hdr *hdr;
 	u8 ratecode;
 	__le16 fc;
+	struct ieee80211_hw *hw;
 
 	hdr = (struct ieee80211_hdr *)skb->data;
 	fc = hdr->frame_control;
 	memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
+	hw = ath_get_virt_hw(sc, hdr);
 
 	if (ds->ds_rxstat.rs_more) {
 		/*
@@ -186,7 +194,6 @@ static int ath_rx_prepare(struct sk_buff
 		rx_status->rate_idx = ratecode & 0x7f;
 	} else {
 		int i = 0, cur_band, n_rates;
-		struct ieee80211_hw *hw = sc->hw;
 
 		cur_band = hw->conf.channel->band;
 		n_rates = sc->sbands[cur_band].n_bitrates;
@@ -208,8 +215,8 @@ static int ath_rx_prepare(struct sk_buff
 	}
 
 	rx_status->mactime = ath_extend_tsf(sc, ds->ds_rxstat.rs_tstamp);
-	rx_status->band = sc->hw->conf.channel->band;
-	rx_status->freq =  sc->hw->conf.channel->center_freq;
+	rx_status->band = hw->conf.channel->band;
+	rx_status->freq = hw->conf.channel->center_freq;
 	rx_status->noise = sc->ani.noise_floor;
 	rx_status->signal = rx_status->noise + ds->ds_rxstat.rs_rssi;
 	rx_status->antenna = ds->ds_rxstat.rs_antenna;
@@ -604,7 +611,7 @@ int ath_rx_tasklet(struct ath_softc *sc,
 		}
 
 		/* Send the frame to mac80211 */
-		__ieee80211_rx(sc->hw, skb, &rx_status);
+		__ieee80211_rx(ath_get_virt_hw(sc, hdr), skb, &rx_status);
 
 		/* We will now give hardware our shiny new allocated skb */
 		bf->bf_mpdu = requeue_skb;
drivers/net/wireless/ath9k/virtual.c +2 -1
@@ -38,7 +38,8 @@ static void ath9k_vif_iter(void *data, u
 
 void ath9k_set_bssid_mask(struct ieee80211_hw *hw)
 {
-	struct ath_softc *sc = hw->priv;
+	struct ath_wiphy *aphy = hw->priv;
+	struct ath_softc *sc = aphy->sc;
 	struct ath9k_vif_iter_data iter_data;
 	int i, j;
 	u8 mask[ETH_ALEN];
Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#4 lore raw

PATCH 4/15 ath9k: Add support for multiple secondary virtual wiphys

In reply to Jouni Malinen

The new struct ath_softc::sec_wiphy array is used to store information about virtual wiphys and select which wiphy is used in calls to mac80211. Each virtual wiphy will be assigned a different MAC address based on the virtual wiphy index.

---
 drivers/net/wireless/ath9k/ath9k.h   |   15 ++++-
 drivers/net/wireless/ath9k/beacon.c  |   21 +++++---
 drivers/net/wireless/ath9k/main.c    |   65 ++++++++++++++++---------
 drivers/net/wireless/ath9k/rc.h      |    1 
 drivers/net/wireless/ath9k/recv.c    |   41 +++++++++++++++
 drivers/net/wireless/ath9k/virtual.c |   90 ++++++++++++++++++++++++++++++++++-
 drivers/net/wireless/ath9k/xmit.c    |   20 +++++--
 7 files changed, 212 insertions(+), 41 deletions(-)
drivers/net/wireless/ath9k/ath9k.h +12 -3
@@ -373,10 +373,10 @@ int ath_tx_cleanup(struct ath_softc *sc)
 struct ath_txq *ath_test_get_txq(struct ath_softc *sc, struct sk_buff *skb);
 int ath_txq_update(struct ath_softc *sc, int qnum,
 		   struct ath9k_tx_queue_info *q);
-int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb,
+int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
 		 struct ath_tx_control *txctl);
 void ath_tx_tasklet(struct ath_softc *sc);
-void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb);
+void ath_tx_cabq(struct ieee80211_hw *hw, struct sk_buff *skb);
 bool ath_tx_aggr_check(struct ath_softc *sc, struct ath_node *an, u8 tidno);
 int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
 		      u16 tid, u16 *ssn);
@@ -429,6 +429,7 @@ struct ath_beacon {
 	u32 ast_be_xmit;
 	u64 bc_tstamp;
 	struct ieee80211_vif *bslot[ATH_BCBUF];
+	struct ath_wiphy *bslot_aphy[ATH_BCBUF];
 	int slottime;
 	int slotupdate;
 	struct ath9k_tx_queue_info beacon_qi;
@@ -440,7 +441,7 @@ struct ath_beacon {
 void ath_beacon_tasklet(unsigned long data);
 void ath_beacon_config(struct ath_softc *sc, struct ieee80211_vif *vif);
 int ath_beaconq_setup(struct ath_hw *ah);
-int ath_beacon_alloc(struct ath_softc *sc, struct ieee80211_vif *vif);
+int ath_beacon_alloc(struct ath_wiphy *aphy, struct ieee80211_vif *vif);
 void ath_beacon_return(struct ath_softc *sc, struct ath_vif *avp);
 
 /*******/
@@ -554,7 +555,12 @@ struct ath_wiphy;
 struct ath_softc {
 	struct ieee80211_hw *hw;
 	struct device *dev;
+
+	spinlock_t wiphy_lock; /* spinlock to protect ath_wiphy data */
 	struct ath_wiphy *pri_wiphy;
+	struct ath_wiphy **sec_wiphy; /* secondary wiphys (virtual radios); may
+				       * have NULL entries */
+	int num_sec_wiphy; /* number of sec_wiphy pointers in the array */
 	struct tasklet_struct intr_tq;
 	struct tasklet_struct bcon_tasklet;
 	struct ath_hw *sc_ah;
@@ -638,6 +644,7 @@ int ath_attach(u16 devid, struct ath_sof
 void ath_detach(struct ath_softc *sc);
 const char *ath_mac_bb_name(u32 mac_bb_version);
 const char *ath_rf_name(u16 rf_version);
+void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw);
 
 #ifdef CONFIG_PCI
 int ath_pci_init(void);
@@ -674,5 +681,7 @@ static inline void ath9k_ps_restore(stru
 
 
 void ath9k_set_bssid_mask(struct ieee80211_hw *hw);
+int ath9k_wiphy_add(struct ath_softc *sc);
+int ath9k_wiphy_del(struct ath_wiphy *aphy);
 
 #endif /* ATH9K_H */
drivers/net/wireless/ath9k/main.c +42 -23

127 lines not on this page · raw message

drivers/net/wireless/ath9k/recv.c +39 -2

53 lines not on this page · raw message

drivers/net/wireless/ath9k/beacon.c +14 -7
@@ -113,9 +113,11 @@ static void ath_beacon_setup(struct ath_
 				     series, 4, 0);
 }
 
-static struct ath_buf *ath_beacon_generate(struct ath_softc *sc,
+static struct ath_buf *ath_beacon_generate(struct ieee80211_hw *hw,
 					   struct ieee80211_vif *vif)
 {
+	struct ath_wiphy *aphy = hw->priv;
+	struct ath_softc *sc = aphy->sc;
 	struct ath_buf *bf;
 	struct ath_vif *avp;
 	struct sk_buff *skb;
@@ -144,7 +146,7 @@ static struct ath_buf *ath_beacon_genera
 
 	/* Get a new beacon from mac80211 */
 
-	skb = ieee80211_beacon_get(sc->hw, vif);
+	skb = ieee80211_beacon_get(hw, vif);
 	bf->bf_mpdu = skb;
 	if (skb == NULL)
 		return NULL;
@@ -171,7 +173,7 @@ static struct ath_buf *ath_beacon_genera
 		return NULL;
 	}
 
-	skb = ieee80211_get_buffered_bc(sc->hw, vif);
+	skb = ieee80211_get_buffered_bc(hw, vif);
 
 	/*
 	 * if the CABQ traffic from previous DTIM is pending and the current
@@ -196,8 +198,8 @@ static struct ath_buf *ath_beacon_genera
 	ath_beacon_setup(sc, avp, bf);
 
 	while (skb) {
-		ath_tx_cabq(sc, skb);
-		skb = ieee80211_get_buffered_bc(sc->hw, vif);
+		ath_tx_cabq(hw, skb);
+		skb = ieee80211_get_buffered_bc(hw, vif);
 	}
 
 	return bf;
@@ -244,8 +246,9 @@ int ath_beaconq_setup(struct ath_hw *ah)
 	return ath9k_hw_setuptxqueue(ah, ATH9K_TX_QUEUE_BEACON, &qi);
 }
 
-int ath_beacon_alloc(struct ath_softc *sc, struct ieee80211_vif *vif)
+int ath_beacon_alloc(struct ath_wiphy *aphy, struct ieee80211_vif *vif)
 {
+	struct ath_softc *sc = aphy->sc;
 	struct ath_vif *avp;
 	struct ieee80211_hdr *hdr;
 	struct ath_buf *bf;
@@ -286,6 +289,7 @@ int ath_beacon_alloc(struct ath_softc *s
 				}
 			BUG_ON(sc->beacon.bslot[avp->av_bslot] != NULL);
 			sc->beacon.bslot[avp->av_bslot] = vif;
+			sc->beacon.bslot_aphy[avp->av_bslot] = aphy;
 			sc->nbcnvifs++;
 		}
 	}
@@ -368,6 +372,7 @@ void ath_beacon_return(struct ath_softc 
 
 		if (avp->av_bslot != -1) {
 			sc->beacon.bslot[avp->av_bslot] = NULL;
+			sc->beacon.bslot_aphy[avp->av_bslot] = NULL;
 			sc->nbcnvifs--;
 		}
 
@@ -391,6 +396,7 @@ void ath_beacon_tasklet(unsigned long da
 	struct ath_hw *ah = sc->sc_ah;
 	struct ath_buf *bf = NULL;
 	struct ieee80211_vif *vif;
+	struct ath_wiphy *aphy;
 	int slot;
 	u32 bfaddr, bc = 0, tsftu;
 	u64 tsf;
@@ -439,6 +445,7 @@ void ath_beacon_tasklet(unsigned long da
 	tsftu = TSF_TO_TU(tsf>>32, tsf);
 	slot = ((tsftu % intval) * ATH_BCBUF) / intval;
 	vif = sc->beacon.bslot[(slot + 1) % ATH_BCBUF];
+	aphy = sc->beacon.bslot_aphy[(slot + 1) % ATH_BCBUF];
 
 	DPRINTF(sc, ATH_DBG_BEACON,
 		"slot %d [tsf %llu tsftu %u intval %u] vif %p\n",
@@ -446,7 +453,7 @@ void ath_beacon_tasklet(unsigned long da
 
 	bfaddr = 0;
 	if (vif) {
-		bf = ath_beacon_generate(sc, vif);
+		bf = ath_beacon_generate(aphy->hw, vif);
 		if (bf != NULL) {
 			bfaddr = bf->bf_daddr;
 			bc = 1;
drivers/net/wireless/ath9k/rc.h +1 -0
@@ -195,6 +195,7 @@ struct ath_rate_priv {
 };
 
 struct ath_tx_info_priv {
+	struct ath_wiphy *aphy;
 	struct ath_tx_status tx;
 	int n_frames;
 	int n_bad_frames;
drivers/net/wireless/ath9k/xmit.c +15 -5
@@ -1497,10 +1497,12 @@ static void ath_buf_set_rate(struct ath_
 		ath9k_hw_set11n_burstduration(sc->sc_ah, bf->bf_desc, 8192);
 }
 
-static int ath_tx_setup_buffer(struct ath_softc *sc, struct ath_buf *bf,
+static int ath_tx_setup_buffer(struct ieee80211_hw *hw, struct ath_buf *bf,
 				struct sk_buff *skb,
 				struct ath_tx_control *txctl)
 {
+	struct ath_wiphy *aphy = hw->priv;
+	struct ath_softc *sc = aphy->sc;
 	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
 	struct ath_tx_info_priv *tx_info_priv;
@@ -1511,6 +1513,7 @@ static int ath_tx_setup_buffer(struct at
 	if (unlikely(!tx_info_priv))
 		return -ENOMEM;
 	tx_info->rate_driver_data[0] = tx_info_priv;
+	tx_info_priv->aphy = aphy;
 	hdrlen = ieee80211_get_hdrlen_from_skb(skb);
 	fc = hdr->frame_control;
 
@@ -1614,9 +1617,11 @@ static void ath_tx_start_dma(struct ath_
 }
 
 /* Upon failure caller should free skb */
-int ath_tx_start(struct ath_softc *sc, struct sk_buff *skb,
+int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
 		 struct ath_tx_control *txctl)
 {
+	struct ath_wiphy *aphy = hw->priv;
+	struct ath_softc *sc = aphy->sc;
 	struct ath_buf *bf;
 	int r;
 
@@ -1626,7 +1631,7 @@ int ath_tx_start(struct ath_softc *sc, s
 		return -1;
 	}
 
-	r = ath_tx_setup_buffer(sc, bf, skb, txctl);
+	r = ath_tx_setup_buffer(hw, bf, skb, txctl);
 	if (unlikely(r)) {
 		struct ath_txq *txq = txctl->txq;
 
@@ -1656,8 +1661,10 @@ int ath_tx_start(struct ath_softc *sc, s
 	return 0;
 }
 
-void ath_tx_cabq(struct ath_softc *sc, struct sk_buff *skb)
+void ath_tx_cabq(struct ieee80211_hw *hw, struct sk_buff *skb)
 {
+	struct ath_wiphy *aphy = hw->priv;
+	struct ath_softc *sc = aphy->sc;
 	int hdrlen, padsize;
 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
 	struct ath_tx_control txctl;
@@ -1694,7 +1701,7 @@ void ath_tx_cabq(struct ath_softc *sc, s
 
 	DPRINTF(sc, ATH_DBG_XMIT, "transmitting CABQ packet, skb: %p\n", skb);
 
-	if (ath_tx_start(sc, skb, &txctl) != 0) {
+	if (ath_tx_start(hw, skb, &txctl) != 0) {
 		DPRINTF(sc, ATH_DBG_XMIT, "CABQ TX failed\n");
 		goto exit;
 	}
@@ -1718,6 +1725,9 @@ static void ath_tx_complete(struct ath_s
 
 	DPRINTF(sc, ATH_DBG_XMIT, "TX complete: skb: %p\n", skb);
 
+	if (tx_info_priv)
+		hw = tx_info_priv->aphy->hw;
+
 	if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK ||
 	    tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
 		kfree(tx_info_priv);
drivers/net/wireless/ath9k/virtual.c +89 -1

100 lines not on this page · raw message

Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#5 lore raw

PATCH 5/15 ath9k: Configure RX filter for multi-BSSID broadcast

In reply to Jouni Malinen

Allow RX filter to pass through all broadcast/multicast frames (i.e., no BSSID filtering) if virtual interfaces are used. Software filtering will be used in this case to drop broadcast/multicast frames for foreign BSSIDs.

---
 drivers/net/wireless/ath9k/mac.h  |    1 +
 drivers/net/wireless/ath9k/recv.c |    8 ++++++++
 2 files changed, 9 insertions(+)
drivers/net/wireless/ath9k/recv.c +8 -0
@@ -407,6 +407,14 @@ u32 ath_calcrxfilter(struct ath_softc *s
 	if (sc->sc_ah->opmode == NL80211_IFTYPE_AP)
 		rfilt |= ATH9K_RX_FILTER_PSPOLL;
 
+	if (sc->sec_wiphy) {
+		/* TODO: only needed if more than one BSSID is in use in
+		 * station/adhoc mode */
+		/* TODO: for older chips, may need to add ATH9K_RX_FILTER_PROM
+		 */
+		rfilt |= ATH9K_RX_FILTER_MCAST_BCAST_ALL;
+	}
+
 	return rfilt;
 
 #undef RX_FILTER_PRESERVE
drivers/net/wireless/ath9k/mac.h +1 -0
@@ -570,6 +570,7 @@ enum ath9k_rx_filter {
 	ATH9K_RX_FILTER_MYBEACON = 0x00000200,
 	ATH9K_RX_FILTER_PSPOLL = 0x00004000,
 	ATH9K_RX_FILTER_PHYRADAR = 0x00002000,
+	ATH9K_RX_FILTER_MCAST_BCAST_ALL = 0x00008000,
 };
 
 #define ATH9K_RATESERIES_RTS_CTS  0x0001
Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#6 lore raw

PATCH 6/15 ath9k: Virtual wiphy pause/unpause functionality

In reply to Jouni Malinen

Allow virtual wiphys to be paused/unpaused to allow off-channel operations. Pause will stop all TX queues for the wiphy and move the STA into power save mode if in managed mode. Unpause wakes up the TX queues and notifies the AP that the STA woke up if in managed mode.

---
 drivers/net/wireless/ath9k/ath9k.h   |   10 ++
 drivers/net/wireless/ath9k/beacon.c  |    3 
 drivers/net/wireless/ath9k/main.c    |    1 
 drivers/net/wireless/ath9k/rc.h      |    7 +
 drivers/net/wireless/ath9k/virtual.c |  161 +++++++++++++++++++++++++++++++++++
 drivers/net/wireless/ath9k/xmit.c    |   11 +-
 6 files changed, 191 insertions(+), 2 deletions(-)
drivers/net/wireless/ath9k/ath9k.h +10 -0
@@ -292,6 +292,7 @@ struct ath_atx_ac {
 struct ath_tx_control {
 	struct ath_txq *txq;
 	int if_id;
+	enum ath9k_internal_frame_type frame_type;
 };
 
 struct ath_xmit_status {
@@ -392,6 +393,7 @@ struct ath_vif {
 	enum nl80211_iftype av_opmode;
 	struct ath_buf *av_bcbuf;
 	struct ath_tx_control av_btxctl;
+	u8 bssid[ETH_ALEN]; /* current BSSID from config_interface */
 };
 
 /*******************/
@@ -619,6 +621,11 @@ struct ath_softc {
 struct ath_wiphy {
 	struct ath_softc *sc; /* shared for all virtual wiphys */
 	struct ieee80211_hw *hw;
+	enum ath_wiphy_state {
+		ATH_WIPHY_ACTIVE,
+		ATH_WIPHY_PAUSING,
+		ATH_WIPHY_PAUSED,
+	} state;
 };
 
 int ath_reset(struct ath_softc *sc, bool retry_tx);
@@ -683,5 +690,8 @@ static inline void ath9k_ps_restore(stru
 void ath9k_set_bssid_mask(struct ieee80211_hw *hw);
 int ath9k_wiphy_add(struct ath_softc *sc);
 int ath9k_wiphy_del(struct ath_wiphy *aphy);
+void ath9k_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb);
+int ath9k_wiphy_pause(struct ath_wiphy *aphy);
+int ath9k_wiphy_unpause(struct ath_wiphy *aphy);
 
 #endif /* ATH9K_H */
drivers/net/wireless/ath9k/main.c +1 -0
@@ -2371,6 +2371,7 @@ static int ath9k_config_interface(struct
 		case NL80211_IFTYPE_ADHOC:
 			/* Set BSSID */
 			memcpy(sc->curbssid, conf->bssid, ETH_ALEN);
+			memcpy(avp->bssid, conf->bssid, ETH_ALEN);
 			sc->curaid = 0;
 			ath9k_hw_write_associd(sc);
 
drivers/net/wireless/ath9k/xmit.c +9 -2
@@ -1514,6 +1514,7 @@ static int ath_tx_setup_buffer(struct ie
 		return -ENOMEM;
 	tx_info->rate_driver_data[0] = tx_info_priv;
 	tx_info_priv->aphy = aphy;
+	tx_info_priv->frame_type = txctl->frame_type;
 	hdrlen = ieee80211_get_hdrlen_from_skb(skb);
 	fc = hdr->frame_control;
 
@@ -1722,11 +1723,14 @@ static void ath_tx_complete(struct ath_s
 	struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
 	struct ath_tx_info_priv *tx_info_priv = ATH_TX_INFO_PRIV(tx_info);
 	int hdrlen, padsize;
+	int frame_type = ATH9K_NOT_INTERNAL;
 
 	DPRINTF(sc, ATH_DBG_XMIT, "TX complete: skb: %p\n", skb);
 
-	if (tx_info_priv)
+	if (tx_info_priv) {
 		hw = tx_info_priv->aphy->hw;
+		frame_type = tx_info_priv->frame_type;
+	}
 
 	if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK ||
 	    tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
@@ -1757,7 +1761,10 @@ static void ath_tx_complete(struct ath_s
 		skb_pull(skb, padsize);
 	}
 
-	ieee80211_tx_status(hw, skb);
+	if (frame_type == ATH9K_NOT_INTERNAL)
+		ieee80211_tx_status(hw, skb);
+	else
+		ath9k_tx_status(hw, skb);
 }
 
 static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
drivers/net/wireless/ath9k/rc.h +7 -0
@@ -194,12 +194,19 @@ struct ath_rate_priv {
 	struct ath_rate_softc *asc;
 };
 
+enum ath9k_internal_frame_type {
+	ATH9K_NOT_INTERNAL,
+	ATH9K_INT_PAUSE,
+	ATH9K_INT_UNPAUSE
+};
+
 struct ath_tx_info_priv {
 	struct ath_wiphy *aphy;
 	struct ath_tx_status tx;
 	int n_frames;
 	int n_bad_frames;
 	bool update_rc;
+	enum ath9k_internal_frame_type frame_type;
 };
 
 #define ATH_TX_INFO_PRIV(tx_info) \
drivers/net/wireless/ath9k/virtual.c +161 -0

164 lines not on this page · raw message

drivers/net/wireless/ath9k/beacon.c +3 -0
@@ -125,6 +125,9 @@ static struct ath_buf *ath_beacon_genera
 	struct ieee80211_tx_info *info;
 	int cabq_depth;
 
+	if (aphy->state != ATH_WIPHY_ACTIVE)
+		return NULL;
+
 	avp = (void *)vif->drv_priv;
 	cabq = sc->beacon.cabq;
 
Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#7 lore raw

PATCH 7/15 ath9k: Add routines for switching between active virtual wiphys

In reply to Jouni Malinen

ath9k_wiphy_select() can be used to select a virtual wiphy to be activated. Other virtual wiphys will be paused and once that is done, the operational channel is changed and the wiphys that are on the selected channel will be unpaused.

---
 drivers/net/wireless/ath9k/ath9k.h   |   14 +++
 drivers/net/wireless/ath9k/main.c    |   27 ++++--
 drivers/net/wireless/ath9k/virtual.c |  147 ++++++++++++++++++++++++++++++++++-
 3 files changed, 176 insertions(+), 12 deletions(-)
drivers/net/wireless/ath9k/ath9k.h +14 -0
@@ -563,6 +563,11 @@ struct ath_softc {
 	struct ath_wiphy **sec_wiphy; /* secondary wiphys (virtual radios); may
 				       * have NULL entries */
 	int num_sec_wiphy; /* number of sec_wiphy pointers in the array */
+	int chan_idx;
+	int chan_is_ht;
+	struct ath_wiphy *next_wiphy;
+	struct work_struct chan_work;
+
 	struct tasklet_struct intr_tq;
 	struct tasklet_struct bcon_tasklet;
 	struct ath_hw *sc_ah;
@@ -626,6 +631,8 @@ struct ath_wiphy {
 		ATH_WIPHY_PAUSING,
 		ATH_WIPHY_PAUSED,
 	} state;
+	int chan_idx;
+	int chan_is_ht;
 };
 
 int ath_reset(struct ath_softc *sc, bool retry_tx);
@@ -652,6 +659,11 @@ void ath_detach(struct ath_softc *sc);
 const char *ath_mac_bb_name(u32 mac_bb_version);
 const char *ath_rf_name(u16 rf_version);
 void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw);
+void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
+			   struct ath9k_channel *ichan);
+void ath_update_chainmask(struct ath_softc *sc, int is_ht);
+int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
+		    struct ath9k_channel *hchan);
 
 #ifdef CONFIG_PCI
 int ath_pci_init(void);
@@ -693,5 +705,7 @@ int ath9k_wiphy_del(struct ath_wiphy *ap
 void ath9k_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb);
 int ath9k_wiphy_pause(struct ath_wiphy *aphy);
 int ath9k_wiphy_unpause(struct ath_wiphy *aphy);
+int ath9k_wiphy_select(struct ath_wiphy *aphy);
+void ath9k_wiphy_chan_work(struct work_struct *work);
 
 #endif /* ATH9K_H */
drivers/net/wireless/ath9k/main.c +18 -9
@@ -236,11 +236,11 @@ static void ath_setup_rates(struct ath_s
  * by reseting the chip.  To accomplish this we must first cleanup any pending
  * DMA, then restart stuff.
 */
-static int ath_set_channel(struct ath_softc *sc, struct ath9k_channel *hchan)
+int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
+		    struct ath9k_channel *hchan)
 {
 	struct ath_hw *ah = sc->sc_ah;
 	bool fastcc = true, stopped;
-	struct ieee80211_hw *hw = sc->hw;
 	struct ieee80211_channel *channel = hw->conf.channel;
 	int r;
 
@@ -414,7 +414,7 @@ set_timer:
  * the chainmask configuration, for bt coexistence, use
  * the chainmask configuration even in legacy mode.
  */
-static void ath_update_chainmask(struct ath_softc *sc, int is_ht)
+void ath_update_chainmask(struct ath_softc *sc, int is_ht)
 {
 	sc->sc_flags |= SC_OP_CHAINMASK_UPDATE;
 	if (is_ht ||
@@ -1322,6 +1322,7 @@ void ath_detach(struct ath_softc *sc)
 	ath_deinit_rfkill(sc);
 #endif
 	ath_deinit_leds(sc);
+	cancel_work_sync(&sc->chan_work);
 
 	for (i = 0; i < sc->num_sec_wiphy; i++) {
 		struct ath_wiphy *aphy = sc->sec_wiphy[i];
@@ -1667,6 +1668,8 @@ int ath_attach(u16 devid, struct ath_sof
 	ath9k_reg_apply_radar_flags(hw->wiphy);
 	ath9k_reg_apply_world_flags(hw->wiphy, REGDOM_SET_BY_INIT);
 
+	INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
+
 	error = ieee80211_register_hw(hw);
 
 	if (!ath9k_is_world_regd(sc->sc_ah)) {
@@ -1915,10 +1918,9 @@ int ath_get_mac80211_qnum(u32 queue, str
 
 /* XXX: Remove me once we don't depend on ath9k_channel for all
  * this redundant data */
-static void ath9k_update_ichannel(struct ath_softc *sc,
-			  struct ath9k_channel *ichan)
+void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
+			   struct ath9k_channel *ichan)
 {
-	struct ieee80211_hw *hw = sc->hw;
 	struct ieee80211_channel *chan = hw->conf.channel;
 	struct ieee80211_conf *conf = &hw->conf;
 
@@ -1965,8 +1967,9 @@ static int ath9k_start(struct ieee80211_
 
 	pos = curchan->hw_value;
 
+	sc->chan_idx = pos;
 	init_channel = &sc->sc_ah->channels[pos];
-	ath9k_update_ichannel(sc, init_channel);
+	ath9k_update_ichannel(sc, hw, init_channel);
 
 	/* Reset SERDES registers */
 	ath9k_hw_configpcipowersave(sc->sc_ah, 0);
@@ -2305,15 +2308,21 @@ static int ath9k_config(struct ieee80211
 		struct ieee80211_channel *curchan = hw->conf.channel;
 		int pos = curchan->hw_value;
 
+		aphy->chan_idx = pos;
+		aphy->chan_is_ht = conf_is_ht(conf);
+
+		/* TODO: do not change operation channel immediately if there
+		 * are other virtual wiphys that use another channel */
+
 		DPRINTF(sc, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
 			curchan->center_freq);
 
 		/* XXX: remove me eventualy */
-		ath9k_update_ichannel(sc, &sc->sc_ah->channels[pos]);
+		ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
 
 		ath_update_chainmask(sc, conf_is_ht(conf));
 
-		if (ath_set_channel(sc, &sc->sc_ah->channels[pos]) < 0) {
+		if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
 			DPRINTF(sc, ATH_DBG_FATAL, "Unable to set channel\n");
 			mutex_unlock(&sc->mutex);
 			return -EINVAL;
drivers/net/wireless/ath9k/virtual.c +144 -3

180 lines not on this page · raw message

Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#8 lore raw

PATCH 8/15 ath9k: Make start/stop operations aware of virtual wiphys

In reply to Jouni Malinen

Instead of always going through initialization/deinitialization steps, do this only for the first/last wiphy to not break the other wiphys.

---
 drivers/net/wireless/ath9k/ath9k.h   |    2 ++
 drivers/net/wireless/ath9k/main.c    |   28 ++++++++++++++++++++++++++++
 drivers/net/wireless/ath9k/virtual.c |   19 +++++++++++++++++++
 3 files changed, 49 insertions(+)
drivers/net/wireless/ath9k/ath9k.h +2 -0
@@ -627,6 +627,7 @@ struct ath_wiphy {
 	struct ath_softc *sc; /* shared for all virtual wiphys */
 	struct ieee80211_hw *hw;
 	enum ath_wiphy_state {
+		ATH_WIPHY_INACTIVE,
 		ATH_WIPHY_ACTIVE,
 		ATH_WIPHY_PAUSING,
 		ATH_WIPHY_PAUSED,
@@ -707,5 +708,6 @@ int ath9k_wiphy_pause(struct ath_wiphy *
 int ath9k_wiphy_unpause(struct ath_wiphy *aphy);
 int ath9k_wiphy_select(struct ath_wiphy *aphy);
 void ath9k_wiphy_chan_work(struct work_struct *work);
+bool ath9k_wiphy_started(struct ath_softc *sc);
 
 #endif /* ATH9K_H */
drivers/net/wireless/ath9k/main.c +28 -0
@@ -1963,6 +1963,27 @@ static int ath9k_start(struct ieee80211_
 
 	mutex_lock(&sc->mutex);
 
+	if (ath9k_wiphy_started(sc)) {
+		if (sc->chan_idx == curchan->hw_value) {
+			/*
+			 * Already on the operational channel, the new wiphy
+			 * can be marked active.
+			 */
+			aphy->state = ATH_WIPHY_ACTIVE;
+			ieee80211_wake_queues(hw);
+		} else {
+			/*
+			 * Another wiphy is on another channel, start the new
+			 * wiphy in paused state.
+			 */
+			aphy->state = ATH_WIPHY_PAUSED;
+			ieee80211_stop_queues(hw);
+		}
+		mutex_unlock(&sc->mutex);
+		return 0;
+	}
+	aphy->state = ATH_WIPHY_ACTIVE;
+
 	/* setup initial channel */
 
 	pos = curchan->hw_value;
@@ -2102,6 +2123,8 @@ static void ath9k_stop(struct ieee80211_
 	struct ath_wiphy *aphy = hw->priv;
 	struct ath_softc *sc = aphy->sc;
 
+	aphy->state = ATH_WIPHY_INACTIVE;
+
 	if (sc->sc_flags & SC_OP_INVALID) {
 		DPRINTF(sc, ATH_DBG_ANY, "Device not present\n");
 		return;
@@ -2111,6 +2134,11 @@ static void ath9k_stop(struct ieee80211_
 
 	ieee80211_stop_queues(hw);
 
+	if (ath9k_wiphy_started(sc)) {
+		mutex_unlock(&sc->mutex);
+		return; /* another wiphy still in use */
+	}
+
 	/* make sure h/w will not generate any interrupt
 	 * before setting the invalid flag. */
 	ath9k_hw_set_interrupts(sc->sc_ah, 0);
drivers/net/wireless/ath9k/virtual.c +19 -0
@@ -477,3 +477,22 @@ int ath9k_wiphy_select(struct ath_wiphy 
 
 	return 0;
 }
+
+bool ath9k_wiphy_started(struct ath_softc *sc)
+{
+	int i;
+	spin_lock_bh(&sc->wiphy_lock);
+	if (sc->pri_wiphy->state != ATH_WIPHY_INACTIVE) {
+		spin_unlock_bh(&sc->wiphy_lock);
+		return true;
+	}
+	for (i = 0; i < sc->num_sec_wiphy; i++) {
+		if (sc->sec_wiphy[i] &&
+		    sc->sec_wiphy[i]->state != ATH_WIPHY_INACTIVE) {
+			spin_unlock_bh(&sc->wiphy_lock);
+			return true;
+		}
+	}
+	spin_unlock_bh(&sc->wiphy_lock);
+	return false;
+}
Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#9 lore raw

PATCH 9/15 ath9k: Register larger listen interval

In reply to Jouni Malinen

Notify the AP that we may be sleeping longer to allow the AP power save code to buffer larger number of frames for us when using virtual wiphys.

---
 drivers/net/wireless/ath9k/main.c |    1 +
 1 file changed, 1 insertion(+)
drivers/net/wireless/ath9k/main.c +1 -0
@@ -1595,6 +1595,7 @@ void ath_set_hw_capab(struct ath_softc *
 	hw->queues = 4;
 	hw->max_rates = 4;
 	hw->channel_change_time = 5000;
+	hw->max_listen_interval = 10;
 	hw->max_rate_tries = ATH_11N_TXMAXTRY;
 	hw->sta_data_size = sizeof(struct ath_node);
 	hw->vif_data_size = sizeof(struct ath_vif);
Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#10 lore raw

PATCH 10/15 ath9k: Pause other virtual wiphys on channel change

In reply to Jouni Malinen

For now, allow channel changes immediately and just force the other virtual wiphys to paused state. This is needed to allow mac80211-controlled scan to control channel changes.

---
 drivers/net/wireless/ath9k/ath9k.h   |    2 ++
 drivers/net/wireless/ath9k/main.c    |    8 +++++++-
 drivers/net/wireless/ath9k/virtual.c |   24 ++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)
drivers/net/wireless/ath9k/main.c +7 -1
@@ -2341,7 +2341,13 @@ static int ath9k_config(struct ieee80211
 		aphy->chan_is_ht = conf_is_ht(conf);
 
 		/* TODO: do not change operation channel immediately if there
-		 * are other virtual wiphys that use another channel */
+		 * are other virtual wiphys that use another channel. For now,
+		 * we do the change immediately to allow mac80211-operated scan
+		 * to work. Once the scan operation is moved into ath9k, we can
+		 * just move the current aphy in PAUSED state if the channel is
+		 * changed into something different from the current operation
+		 * channel. */
+		ath9k_wiphy_pause_all_forced(sc, aphy);
 
 		DPRINTF(sc, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
 			curchan->center_freq);
drivers/net/wireless/ath9k/ath9k.h +2 -0
@@ -709,5 +709,7 @@ int ath9k_wiphy_unpause(struct ath_wiphy
 int ath9k_wiphy_select(struct ath_wiphy *aphy);
 void ath9k_wiphy_chan_work(struct work_struct *work);
 bool ath9k_wiphy_started(struct ath_softc *sc);
+void ath9k_wiphy_pause_all_forced(struct ath_softc *sc,
+				  struct ath_wiphy *selected);
 
 #endif /* ATH9K_H */
drivers/net/wireless/ath9k/virtual.c +24 -0
@@ -496,3 +496,27 @@ bool ath9k_wiphy_started(struct ath_soft
 	spin_unlock_bh(&sc->wiphy_lock);
 	return false;
 }
+
+static void ath9k_wiphy_pause_chan(struct ath_wiphy *aphy,
+				   struct ath_wiphy *selected)
+{
+	if (aphy->chan_idx == selected->chan_idx)
+		return;
+	aphy->state = ATH_WIPHY_PAUSED;
+	ieee80211_stop_queues(aphy->hw);
+}
+
+void ath9k_wiphy_pause_all_forced(struct ath_softc *sc,
+				  struct ath_wiphy *selected)
+{
+	int i;
+	spin_lock_bh(&sc->wiphy_lock);
+	if (sc->pri_wiphy->state == ATH_WIPHY_ACTIVE)
+		ath9k_wiphy_pause_chan(sc->pri_wiphy, selected);
+	for (i = 0; i < sc->num_sec_wiphy; i++) {
+		if (sc->sec_wiphy[i] &&
+		    sc->sec_wiphy[i]->state == ATH_WIPHY_ACTIVE)
+			ath9k_wiphy_pause_chan(sc->sec_wiphy[i], selected);
+	}
+	spin_unlock_bh(&sc->wiphy_lock);
+}
Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#11 lore raw

PATCH 11/15 ath9k: Check virtual wiphy state on tx()

In reply to Jouni Malinen

mac80211 should not be requesting us to transmit frames on paused wiphys since we stop the TX queues. Just in case, add debug code to make sure we catch if this were to happen.

---
 drivers/net/wireless/ath9k/main.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/wireless/ath9k/main.c +6 -0
@@ -2075,6 +2075,12 @@ static int ath9k_tx(struct ieee80211_hw 
 	struct ath_tx_control txctl;
 	int hdrlen, padsize;
 
+	if (aphy->state != ATH_WIPHY_ACTIVE) {
+		printk(KERN_DEBUG "ath9k: %s: TX in unexpected wiphy state "
+		       "%d\n", wiphy_name(hw->wiphy), aphy->state);
+		goto exit;
+	}
+
 	memset(&txctl, 0, sizeof(struct ath_tx_control));
 
 	/*
Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#12 lore raw

PATCH 12/15 ath9k: Add workaround to recover from failed channel changes

In reply to Jouni Malinen

It looks like channel change may fail in some cases and end up leaving the hardware in state where it cannot transmit any frames. Add a workaround to recover from this state if we detect that wiphy selection is failing due to wiphys not leaving PAUSING state.

---
 drivers/net/wireless/ath9k/ath9k.h   |    4 +++
 drivers/net/wireless/ath9k/main.c    |    4 +--
 drivers/net/wireless/ath9k/virtual.c |   37 +++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
drivers/net/wireless/ath9k/ath9k.h +4 -0
@@ -567,6 +567,8 @@ struct ath_softc {
 	int chan_is_ht;
 	struct ath_wiphy *next_wiphy;
 	struct work_struct chan_work;
+	int wiphy_select_failures;
+	unsigned long wiphy_select_first_fail;
 
 	struct tasklet_struct intr_tq;
 	struct tasklet_struct bcon_tasklet;
@@ -665,6 +667,8 @@ void ath9k_update_ichannel(struct ath_so
 void ath_update_chainmask(struct ath_softc *sc, int is_ht);
 int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
 		    struct ath9k_channel *hchan);
+void ath_radio_enable(struct ath_softc *sc);
+void ath_radio_disable(struct ath_softc *sc);
 
 #ifdef CONFIG_PCI
 int ath_pci_init(void);
drivers/net/wireless/ath9k/virtual.c +37 -0
@@ -432,6 +432,18 @@ int ath9k_wiphy_unpause(struct ath_wiphy
 	return ret;
 }
 
+static void __ath9k_wiphy_mark_all_paused(struct ath_softc *sc)
+{
+	int i;
+	if (sc->pri_wiphy->state != ATH_WIPHY_INACTIVE)
+		sc->pri_wiphy->state = ATH_WIPHY_PAUSED;
+	for (i = 0; i < sc->num_sec_wiphy; i++) {
+		if (sc->sec_wiphy[i] &&
+		    sc->sec_wiphy[i]->state != ATH_WIPHY_INACTIVE)
+			sc->sec_wiphy[i]->state = ATH_WIPHY_PAUSED;
+	}
+}
+
 /* caller must hold wiphy_lock */
 static void __ath9k_wiphy_pause_all(struct ath_softc *sc)
 {
@@ -452,9 +464,34 @@ int ath9k_wiphy_select(struct ath_wiphy 
 
 	spin_lock_bh(&sc->wiphy_lock);
 	if (__ath9k_wiphy_pausing(sc)) {
+		if (sc->wiphy_select_failures == 0)
+			sc->wiphy_select_first_fail = jiffies;
+		sc->wiphy_select_failures++;
+		if (time_after(jiffies, sc->wiphy_select_first_fail + HZ / 2))
+		{
+			printk(KERN_DEBUG "ath9k: Previous wiphy select timed "
+			       "out; disable/enable hw to recover\n");
+			__ath9k_wiphy_mark_all_paused(sc);
+			/*
+			 * TODO: this workaround to fix hardware is unlikely to
+			 * be specific to virtual wiphy changes. It can happen
+			 * on normal channel change, too, and as such, this
+			 * should really be made more generic. For example,
+			 * tricker radio disable/enable on GTT interrupt burst
+			 * (say, 10 GTT interrupts received without any TX
+			 * frame being completed)
+			 */
+			spin_unlock_bh(&sc->wiphy_lock);
+			ath_radio_disable(sc);
+			ath_radio_enable(sc);
+			queue_work(aphy->sc->hw->workqueue,
+				   &aphy->sc->chan_work);
+			return -EBUSY; /* previous select still in progress */
+		}
 		spin_unlock_bh(&sc->wiphy_lock);
 		return -EBUSY; /* previous select still in progress */
 	}
+	sc->wiphy_select_failures = 0;
 
 	/* Store the new channel */
 	sc->chan_idx = aphy->chan_idx;
drivers/net/wireless/ath9k/main.c +2 -2
@@ -1088,7 +1088,7 @@ fail:
 /*	Rfkill	   */
 /*******************/
 
-static void ath_radio_enable(struct ath_softc *sc)
+void ath_radio_enable(struct ath_softc *sc)
 {
 	struct ath_hw *ah = sc->sc_ah;
 	struct ieee80211_channel *channel = sc->hw->conf.channel;
@@ -1129,7 +1129,7 @@ static void ath_radio_enable(struct ath_
 	ath9k_ps_restore(sc);
 }
 
-static void ath_radio_disable(struct ath_softc *sc)
+void ath_radio_disable(struct ath_softc *sc)
 {
 	struct ath_hw *ah = sc->sc_ah;
 	struct ieee80211_channel *channel = sc->hw->conf.channel;
Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#13 lore raw

PATCH 13/15 ath9k: Special processing for channel changes during scan

In reply to Jouni Malinen

Allow mac80211-controlled channel changes on an active wiphy and especially during a scan. We need this as long as the scan is controlled by mac80211. Moving this control into the driver could allow some optimizations on scanning while using multiple virtual interfaces, but for now, try to work as well as possible with the current scan mechanism.

---
 drivers/net/wireless/ath9k/ath9k.h   |    2 +
 drivers/net/wireless/ath9k/main.c    |   35 ++++++++++++++++++++++-------
 drivers/net/wireless/ath9k/virtual.c |   41 ++++++++++++++++++++++++++++++++++-
 3 files changed, 68 insertions(+), 10 deletions(-)
drivers/net/wireless/ath9k/ath9k.h +2 -0
@@ -633,6 +633,7 @@ struct ath_wiphy {
 		ATH_WIPHY_ACTIVE,
 		ATH_WIPHY_PAUSING,
 		ATH_WIPHY_PAUSED,
+		ATH_WIPHY_SCAN,
 	} state;
 	int chan_idx;
 	int chan_is_ht;
@@ -715,5 +716,6 @@ void ath9k_wiphy_chan_work(struct work_s
 bool ath9k_wiphy_started(struct ath_softc *sc);
 void ath9k_wiphy_pause_all_forced(struct ath_softc *sc,
 				  struct ath_wiphy *selected);
+bool ath9k_wiphy_scanning(struct ath_softc *sc);
 
 #endif /* ATH9K_H */
drivers/net/wireless/ath9k/main.c +26 -9
@@ -2075,7 +2075,7 @@ static int ath9k_tx(struct ieee80211_hw 
 	struct ath_tx_control txctl;
 	int hdrlen, padsize;
 
-	if (aphy->state != ATH_WIPHY_ACTIVE) {
+	if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
 		printk(KERN_DEBUG "ath9k: %s: TX in unexpected wiphy state "
 		       "%d\n", wiphy_name(hw->wiphy), aphy->state);
 		goto exit;
@@ -2346,14 +2346,16 @@ static int ath9k_config(struct ieee80211
 		aphy->chan_idx = pos;
 		aphy->chan_is_ht = conf_is_ht(conf);
 
-		/* TODO: do not change operation channel immediately if there
-		 * are other virtual wiphys that use another channel. For now,
-		 * we do the change immediately to allow mac80211-operated scan
-		 * to work. Once the scan operation is moved into ath9k, we can
-		 * just move the current aphy in PAUSED state if the channel is
-		 * changed into something different from the current operation
-		 * channel. */
-		ath9k_wiphy_pause_all_forced(sc, aphy);
+		if (aphy->state == ATH_WIPHY_SCAN ||
+		    aphy->state == ATH_WIPHY_ACTIVE)
+			ath9k_wiphy_pause_all_forced(sc, aphy);
+		else {
+			/*
+			 * Do not change operational channel based on a paused
+			 * wiphy changes.
+			 */
+			goto skip_chan_change;
+		}
 
 		DPRINTF(sc, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
 			curchan->center_freq);
@@ -2370,6 +2372,7 @@ static int ath9k_config(struct ieee80211
 		}
 	}
 
+skip_chan_change:
 	if (changed & IEEE80211_CONF_CHANGE_POWER)
 		sc->config.txpowlimit = 2 * conf->power_level;
 
@@ -2737,6 +2740,19 @@ static void ath9k_sw_scan_start(struct i
 	struct ath_wiphy *aphy = hw->priv;
 	struct ath_softc *sc = aphy->sc;
 
+	if (ath9k_wiphy_scanning(sc)) {
+		printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the "
+		       "same time\n");
+		/*
+		 * Do not allow the concurrent scanning state for now. This
+		 * could be improved with scanning control moved into ath9k.
+		 */
+		return;
+	}
+
+	aphy->state = ATH_WIPHY_SCAN;
+	ath9k_wiphy_pause_all_forced(sc, aphy);
+
 	mutex_lock(&sc->mutex);
 	sc->sc_flags |= SC_OP_SCANNING;
 	mutex_unlock(&sc->mutex);
@@ -2748,6 +2764,7 @@ static void ath9k_sw_scan_complete(struc
 	struct ath_softc *sc = aphy->sc;
 
 	mutex_lock(&sc->mutex);
+	aphy->state = ATH_WIPHY_ACTIVE;
 	sc->sc_flags &= ~SC_OP_SCANNING;
 	mutex_unlock(&sc->mutex);
 }
drivers/net/wireless/ath9k/virtual.c +40 -1

59 lines not on this page · raw message

Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#14 lore raw

PATCH 14/15 ath9k: Add a simple virtual wiphy scheduler

In reply to Jouni Malinen

This is a very simple scheduler that goes through the wiphys and schedules one at a time every N milliseconds (current default value:
500 ms). This is enough for initial testing, but there are number of areas where a more complex scheduler can improve operations greatly.

---
 drivers/net/wireless/ath9k/ath9k.h   |    5 ++
 drivers/net/wireless/ath9k/main.c    |    3 +
 drivers/net/wireless/ath9k/virtual.c |   64 +++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
drivers/net/wireless/ath9k/ath9k.h +5 -0
@@ -569,6 +569,9 @@ struct ath_softc {
 	struct work_struct chan_work;
 	int wiphy_select_failures;
 	unsigned long wiphy_select_first_fail;
+	struct delayed_work wiphy_work;
+	unsigned long wiphy_scheduler_int;
+	int wiphy_scheduler_index;
 
 	struct tasklet_struct intr_tq;
 	struct tasklet_struct bcon_tasklet;
@@ -712,10 +715,12 @@ void ath9k_tx_status(struct ieee80211_hw
 int ath9k_wiphy_pause(struct ath_wiphy *aphy);
 int ath9k_wiphy_unpause(struct ath_wiphy *aphy);
 int ath9k_wiphy_select(struct ath_wiphy *aphy);
+void ath9k_wiphy_set_scheduler(struct ath_softc *sc, unsigned int msec_int);
 void ath9k_wiphy_chan_work(struct work_struct *work);
 bool ath9k_wiphy_started(struct ath_softc *sc);
 void ath9k_wiphy_pause_all_forced(struct ath_softc *sc,
 				  struct ath_wiphy *selected);
 bool ath9k_wiphy_scanning(struct ath_softc *sc);
+void ath9k_wiphy_work(struct work_struct *work);
 
 #endif /* ATH9K_H */
drivers/net/wireless/ath9k/main.c +3 -0
@@ -1323,6 +1323,7 @@ void ath_detach(struct ath_softc *sc)
 #endif
 	ath_deinit_leds(sc);
 	cancel_work_sync(&sc->chan_work);
+	cancel_delayed_work_sync(&sc->wiphy_work);
 
 	for (i = 0; i < sc->num_sec_wiphy; i++) {
 		struct ath_wiphy *aphy = sc->sec_wiphy[i];
@@ -1670,6 +1671,8 @@ int ath_attach(u16 devid, struct ath_sof
 	ath9k_reg_apply_world_flags(hw->wiphy, REGDOM_SET_BY_INIT);
 
 	INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
+	INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
+	sc->wiphy_scheduler_int = msecs_to_jiffies(500);
 
 	error = ieee80211_register_hw(hw);
 
drivers/net/wireless/ath9k/virtual.c +64 -0

73 lines not on this page · raw message

Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#15 lore raw

PATCH 15/15 ath9k: Add a debugfs interface for controlling virtual wiphys

In reply to Jouni Malinen

debugfs ath9k/phy#/wiphy can be used to show the current list of virtual wiphys and to add/remove virtual wiphys. Eventually, this interface could be replaced with a cfg80211/nl80211 command that is passed through mac80211.

For example:

# cat /debug/ath9k/phy0/wiphy 
primary: phy0
# echo add > /debug/ath9k/phy0/wiphy 
# cat /debug/ath9k/phy0/wiphy 
primary: phy0
secondary: phy1
# echo del=phy1 > /debug/ath9k/phy0/wiphy 
# cat /debug/ath9k/phy0/wiphy 
primary: phy0

In addition, following commands can be used to test pausing and unpausing of the virtual wiphys:
pause=phy1
unpause=phy1
select=phy1
(select pauses and unpauses wiphys automatically based on channel) schedule=500
(set wiphy scheduling interval in msec; 0 = disable; default value: 500)

---
 drivers/net/wireless/ath9k/debug.c |  164 +++++++++++++++++++++++++++++++++++++
 drivers/net/wireless/ath9k/debug.h |    1 
 2 files changed, 165 insertions(+)
drivers/net/wireless/ath9k/debug.c +164 -0
@@ -330,6 +330,163 @@ static const struct file_operations fops
 	.owner = THIS_MODULE
 };
 
+static const char * ath_wiphy_state_str(enum ath_wiphy_state state)
+{
+	switch (state) {
+	case ATH_WIPHY_INACTIVE:
+		return "INACTIVE";
+	case ATH_WIPHY_ACTIVE:
+		return "ACTIVE";
+	case ATH_WIPHY_PAUSING:
+		return "PAUSING";
+	case ATH_WIPHY_PAUSED:
+		return "PAUSED";
+	case ATH_WIPHY_SCAN:
+		return "SCAN";
+	}
+	return "?";
+}
+
+static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
+			       size_t count, loff_t *ppos)
+{
+	struct ath_softc *sc = file->private_data;
+	char buf[512];
+	unsigned int len = 0;
+	int i;
+	u8 addr[ETH_ALEN];
+
+	len += snprintf(buf + len, sizeof(buf) - len,
+			"primary: %s (%s chan=%d ht=%d)\n",
+			wiphy_name(sc->pri_wiphy->hw->wiphy),
+			ath_wiphy_state_str(sc->pri_wiphy->state),
+			sc->pri_wiphy->chan_idx, sc->pri_wiphy->chan_is_ht);
+	for (i = 0; i < sc->num_sec_wiphy; i++) {
+		struct ath_wiphy *aphy = sc->sec_wiphy[i];
+		if (aphy == NULL)
+			continue;
+		len += snprintf(buf + len, sizeof(buf) - len,
+				"secondary: %s (%s chan=%d ht=%d)\n",
+				wiphy_name(aphy->hw->wiphy),
+				ath_wiphy_state_str(aphy->state),
+				aphy->chan_idx, aphy->chan_is_ht);
+	}
+
+	put_unaligned_le32(REG_READ(sc->sc_ah, AR_STA_ID0), addr);
+	put_unaligned_le16(REG_READ(sc->sc_ah, AR_STA_ID1) & 0xffff, addr + 4);
+	len += snprintf(buf + len, sizeof(buf) - len,
+			"addr: %pM\n", addr);
+	put_unaligned_le32(REG_READ(sc->sc_ah, AR_BSSMSKL), addr);
+	put_unaligned_le16(REG_READ(sc->sc_ah, AR_BSSMSKU) & 0xffff, addr + 4);
+	len += snprintf(buf + len, sizeof(buf) - len,
+			"addrmask: %pM\n", addr);
+
+	return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
+static struct ath_wiphy * get_wiphy(struct ath_softc *sc, const char *name)
+{
+	int i;
+	if (strcmp(name, wiphy_name(sc->pri_wiphy->hw->wiphy)) == 0)
+		return sc->pri_wiphy;
+	for (i = 0; i < sc->num_sec_wiphy; i++) {
+		struct ath_wiphy *aphy = sc->sec_wiphy[i];
+		if (aphy && strcmp(name, wiphy_name(aphy->hw->wiphy)) == 0)
+			return aphy;
+	}
+	return NULL;
+}
+
+static int del_wiphy(struct ath_softc *sc, const char *name)
+{
+	struct ath_wiphy *aphy = get_wiphy(sc, name);
+	if (!aphy)
+		return -ENOENT;
+	return ath9k_wiphy_del(aphy);
+}
+
+static int pause_wiphy(struct ath_softc *sc, const char *name)
+{
+	struct ath_wiphy *aphy = get_wiphy(sc, name);
+	if (!aphy)
+		return -ENOENT;
+	return ath9k_wiphy_pause(aphy);
+}
+
+static int unpause_wiphy(struct ath_softc *sc, const char *name)
+{
+	struct ath_wiphy *aphy = get_wiphy(sc, name);
+	if (!aphy)
+		return -ENOENT;
+	return ath9k_wiphy_unpause(aphy);
+}
+
+static int select_wiphy(struct ath_softc *sc, const char *name)
+{
+	struct ath_wiphy *aphy = get_wiphy(sc, name);
+	if (!aphy)
+		return -ENOENT;
+	return ath9k_wiphy_select(aphy);
+}
+
+static int schedule_wiphy(struct ath_softc *sc, const char *msec)
+{
+	ath9k_wiphy_set_scheduler(sc, simple_strtoul(msec, NULL, 0));
+	return 0;
+}
+
+static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
+				size_t count, loff_t *ppos)
+{
+	struct ath_softc *sc = file->private_data;
+	char buf[50];
+	size_t len;
+
+	len = min(count, sizeof(buf) - 1);
+	if (copy_from_user(buf, user_buf, len))
+		return -EFAULT;
+	buf[len] = '\0';
+	if (len > 0 && buf[len - 1] == '\n')
+		buf[len - 1] = '\0';
+
+	if (strncmp(buf, "add", 3) == 0) {
+		int res = ath9k_wiphy_add(sc);
+		if (res < 0)
+			return res;
+	} else if (strncmp(buf, "del=", 4) == 0) {
+		int res = del_wiphy(sc, buf + 4);
+		if (res < 0)
+			return res;
+	} else if (strncmp(buf, "pause=", 6) == 0) {
+		int res = pause_wiphy(sc, buf + 6);
+		if (res < 0)
+			return res;
+	} else if (strncmp(buf, "unpause=", 8) == 0) {
+		int res = unpause_wiphy(sc, buf + 8);
+		if (res < 0)
+			return res;
+	} else if (strncmp(buf, "select=", 7) == 0) {
+		int res = select_wiphy(sc, buf + 7);
+		if (res < 0)
+			return res;
+	} else if (strncmp(buf, "schedule=", 9) == 0) {
+		int res = schedule_wiphy(sc, buf + 9);
+		if (res < 0)
+			return res;
+	} else
+		return -EOPNOTSUPP;
+
+	return count;
+}
+
+static const struct file_operations fops_wiphy = {
+	.read = read_file_wiphy,
+	.write = write_file_wiphy,
+	.open = ath9k_debugfs_open,
+	.owner = THIS_MODULE
+};
+
+
 int ath9k_init_debug(struct ath_softc *sc)
 {
 	sc->debug.debug_mask = ath9k_debug;
@@ -362,6 +519,12 @@ int ath9k_init_debug(struct ath_softc *s
 	if (!sc->debug.debugfs_rcstat)
 		goto err;
 
+	sc->debug.debugfs_wiphy = debugfs_create_file(
+		"wiphy", S_IRUGO | S_IWUSR, sc->debug.debugfs_phy, sc,
+		&fops_wiphy);
+	if (!sc->debug.debugfs_wiphy)
+		goto err;
+
 	return 0;
 err:
 	ath9k_exit_debug(sc);
@@ -370,6 +533,7 @@ err:
 
 void ath9k_exit_debug(struct ath_softc *sc)
 {
+	debugfs_remove(sc->debug.debugfs_wiphy);
 	debugfs_remove(sc->debug.debugfs_rcstat);
 	debugfs_remove(sc->debug.debugfs_interrupt);
 	debugfs_remove(sc->debug.debugfs_dma);
drivers/net/wireless/ath9k/debug.h +1 -0
@@ -107,6 +107,7 @@ struct ath9k_debug {
 	struct dentry *debugfs_dma;
 	struct dentry *debugfs_interrupt;
 	struct dentry *debugfs_rcstat;
+	struct dentry *debugfs_wiphy;
 	struct ath_stats stats;
 };
 
Signature · 2 lines
-- 
Jouni Malinen                                            PGP id EFC895FA
#16 lore raw
In reply to Jouni Malinen

Hello Jouni,

Le Tuesday 03 March 2009 18:23:25 Jouni Malinen, vous avez =C3=A9crit=C2= =A0:

Quoted 5 lines

When using virtual wiphys, the APs that the virtual interfaces are associated with do not need to be on the same channel. One of the wiphys could also be used with hostapd to bring up an AP. However, it should be noted that most client implementation do not exactly like the AP disappearing all the time, so using a virtual station interfac=

e

Quoted 5 lines

on another channel at the same time may not be that good of an idea for most use cases now. This will hopefully improve somewhat with future optimizations.

Quoted 8 lines

It would be useful to hear what others think about this sort of functionality and how this should be integrated with Linux, including the user space interface, applications managing the virtual interface functionality, and user interface that the end users would see. This is still quite an early step in the progress, but the goal here is to get this functionality into mature state and provide something that makes it easier to use wireless LAN in general for connecting devices in various scenarios. All feedback would be welcome!

I am only commenting from a user point of view this feature. This defin= itively=20
is very useful since quite a lot of people stick to madwifi instead of = using=20
ath5k or ath9k since there was not real support before this patch for v= irtual=20
interfaces.

One thing that I did not like with wlanconfig and I would like not to f= ind=20
with mac80211/cfg80211 is the incompatibility of some setups (i.e: AP s= hould=20
be created first, STA interface later with nosbeacon), not sure this is= =20
possible, but if it is, one should be able to add a virtual interface w= ithout=20
knowing the state of the other interfaces before.

I really like the way we can create mesh point interfaces with iw, so t= his=20
could be the user interface to configure virtual interfaces, say like t= his :

iw dev wlan0 interface add sta0 type sta
iw dev wlan0 interface add ap0 type master

On a broader perspective, I really hope other drivers will become capab= le of=20
supporting virtual interfaces as well.

Thank you for your work.
--=20
Best regards, Florian Fainelli
Email : [email protected]
http://openwrt.org
-------------------------------
--
To unsubscribe from this list: send the line "unsubscribe linux-wireles= s" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#17 lore raw
Quoted 4 lines · Florian Fainelli

I am only commenting from a user point of view this feature. This definitively is very useful since quite a lot of people stick to madwifi instead of using ath5k or ath9k since there was not real support before this patch for virtual interfaces.

The set of patches that went in should take care of the virtual station side. The patch I just sent out will add multi-BSSID support for AP mode (it will require an update to hostapd, too), so this should provide support for quite complete set of virtual interface configurations.

Quoted 5 lines

One thing that I did not like with wlanconfig and I would like not to find with mac80211/cfg80211 is the incompatibility of some setups (i.e: AP should be created first, STA interface later with nosbeacon), not sure this is possible, but if it is, one should be able to add a virtual interface without knowing the state of the other interfaces before.

The goal is certainly to be able to add and remove virtual interfaces in any order and at any time. There may be some limitations in the current version, i.e., something might end up not working, but the configuration part itself is not prevented. If someone finds a sequence that does not work, I would hope it can be resolved.

Quoted 5 lines

I really like the way we can create mesh point interfaces with iw, so this could be the user interface to configure virtual interfaces, say like this :

iw dev wlan0 interface add sta0 type sta
iw dev wlan0 interface add ap0 type master

The multi-channel operation with virtual radio (wiphy) is at somewhat different layer than the mesh interface (vif). Anyway, if nl80211 is extended with a command that can be used to add a new virtual wiphy, similar iw command could be added for this use, too. Here standard commands (iwconfig/wpa_supplicant/hostapd) can change the interface mode, so it does not need to be specified at wiphy creation time.

As far as multi-BSSID configuration of AP mode on the same channel is concerned, those virtual interfaces are vifs and hostapd generates them dynamically using the same mechanism as the iw commands above.

- Jouni