2010-07-05 19:52:32

by greearb

[permalink] [raw]
Subject: [ath9k] ath9k: Expose virtual wiphy indexes to debugfs.

From: Ben Greear <[email protected]>

It is very difficult to map phyX devices to real/virtual
entities because the phyX devices change on module
reload. This patch makes it slightly easier to
associate virtual phy devices with phyX entities.

# echo add=5 > /debug/ath9k/phy0/wiphy
# cat /debug/ath9k/phy0/wiphy
primary: phy0 (ACTIVE chan=0 ht=0)
secondary[5]: phy1 (ACTIVE chan=0 ht=0)
addr: ef:be:ad:de:ef:be
addrmask: ef:be:ad:de:ef:be

Signed-off-by: Ben Greear <[email protected]>
---
:100644 100644 6e486a5... a58ff60... M drivers/net/wireless/ath/ath9k/ath9k.h
:100644 100644 54aae93... f63423c... M drivers/net/wireless/ath/ath9k/debug.c
:100644 100644 89423ca... 03fd64d... M drivers/net/wireless/ath/ath9k/virtual.c
drivers/net/wireless/ath/ath9k/ath9k.h | 2 +-
drivers/net/wireless/ath/ath9k/debug.c | 12 ++++++++----
drivers/net/wireless/ath/ath9k/virtual.c | 26 ++++++++++++++++++++------
3 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index 6e486a5..a58ff60 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -670,7 +670,7 @@ void ath9k_ps_wakeup(struct ath_softc *sc);
void ath9k_ps_restore(struct ath_softc *sc);

void ath9k_set_bssid_mask(struct ieee80211_hw *hw);
-int ath9k_wiphy_add(struct ath_softc *sc);
+int ath9k_wiphy_add(struct ath_softc *sc, const char* id);
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);
diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
index 54aae93..f63423c 100644
--- a/drivers/net/wireless/ath/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -503,8 +503,8 @@ static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
if (aphy == NULL)
continue;
len += snprintf(buf + len, sizeof(buf) - len,
- "secondary: %s (%s chan=%d ht=%d)\n",
- wiphy_name(aphy->hw->wiphy),
+ "secondary[%i]: %s (%s chan=%d ht=%d)\n",
+ i, wiphy_name(aphy->hw->wiphy),
ath_wiphy_state_str(aphy->state),
aphy->chan_idx, aphy->chan_is_ht);
}
@@ -589,8 +589,12 @@ static ssize_t write_file_wiphy(struct file *file, const char __user *user_buf,
if (len > 0 && buf[len - 1] == '\n')
buf[len - 1] = '\0';

- if (strncmp(buf, "add", 3) == 0) {
- int res = ath9k_wiphy_add(sc);
+ if (strncmp(buf, "add=", 4) == 0) {
+ int res = ath9k_wiphy_add(sc, buf + 4);
+ if (res < 0)
+ return res;
+ } else if (strncmp(buf, "add", 3) == 0) {
+ int res = ath9k_wiphy_add(sc, NULL);
if (res < 0)
return res;
} else if (strncmp(buf, "del=", 4) == 0) {
diff --git a/drivers/net/wireless/ath/ath9k/virtual.c b/drivers/net/wireless/ath/ath9k/virtual.c
index 89423ca..03fd64d 100644
--- a/drivers/net/wireless/ath/ath9k/virtual.c
+++ b/drivers/net/wireless/ath/ath9k/virtual.c
@@ -99,9 +99,10 @@ void ath9k_set_bssid_mask(struct ieee80211_hw *hw)
ath_hw_setbssidmask(common);
}

-int ath9k_wiphy_add(struct ath_softc *sc)
+int ath9k_wiphy_add(struct ath_softc *sc, const char* id)
{
int i, error;
+ int nid = 0;
struct ath_wiphy *aphy;
struct ath_common *common = ath9k_hw_common(sc->sc_ah);
struct ieee80211_hw *hw;
@@ -112,16 +113,26 @@ int ath9k_wiphy_add(struct ath_softc *sc)
return -ENOMEM;

spin_lock_bh(&sc->wiphy_lock);
- for (i = 0; i < sc->num_sec_wiphy; i++) {
+ if (id && id[0]) {
+ nid = simple_strtoul(id, NULL, 0);
+ if (nid < 0 || nid > 10000) { /* 10,000 should be plenty! */
+ printk("ath9k: id out of range in wiphy_add:"
+ " %i, ignoring.", nid);
+ nid = 0;
+ }
+ }
+
+ for (i = nid; i < sc->num_sec_wiphy; i++) {
if (sc->sec_wiphy[i] == NULL)
break;
}

- if (i == sc->num_sec_wiphy) {
+ if (i >= sc->num_sec_wiphy) {
/* No empty slot available; increase array length */
struct ath_wiphy **n;
+ int q;
n = krealloc(sc->sec_wiphy,
- (sc->num_sec_wiphy + 1) *
+ (i + 1) *
sizeof(struct ath_wiphy *),
GFP_ATOMIC);
if (n == NULL) {
@@ -129,9 +140,12 @@ int ath9k_wiphy_add(struct ath_softc *sc)
ieee80211_free_hw(hw);
return -ENOMEM;
}
- n[i] = NULL;
+ // Null out any new memory allocated.
+ for (q = sc->num_sec_wiphy; q <= i; q++) {
+ n[q] = NULL;
+ }
sc->sec_wiphy = n;
- sc->num_sec_wiphy++;
+ sc->num_sec_wiphy = i+1;
}

SET_IEEE80211_DEV(hw, sc->dev);
--
1.7.0.1



2010-07-06 05:15:37

by Ben Greear

[permalink] [raw]
Subject: Re: [ath9k] ath9k: Expose virtual wiphy indexes to debugfs.

On 07/05/2010 09:59 PM, Vasanthakumar Thiagarajan wrote:
> On Tue, Jul 06, 2010 at 01:22:25AM +0530, [email protected] wrote:
>> From: Ben Greear<[email protected]>
>>
>> It is very difficult to map phyX devices to real/virtual
>> entities because the phyX devices change on module
>> reload. This patch makes it slightly easier to
>> associate virtual phy devices with phyX entities.
>>
>
> It does not make much sense to give an index while creating a new
> virtual wiphy interface. This is unncessary, only wiphy name
> matters.

Will the underlying code allow you to specify a phy name though? It
seems to me that once a phyX is used, you cannot have a new phy
with that name again, even if the old one has been unloaded:

modprobe ath9k
rmmod ath9k
modprobe ath9k, and the now it's using phy1 instead of phy0,
and you cannot even rename the phy1 to phy0 with 'iw'.

It would be great if phy names were reusable like network
device names, but I'm guessing that must be difficult or
it would already be like that.

For virtual PHYs at least, the parent phy and index is a unique
identifier, so it sort of helps work around the phy naming
issues.

Thanks,
Ben

--
Ben Greear <[email protected]>
Candela Technologies Inc http://www.candelatech.com

Subject: Re: [ath9k] ath9k: Expose virtual wiphy indexes to debugfs.

On Tue, Jul 06, 2010 at 10:45:32AM +0530, Ben Greear wrote:
> On 07/05/2010 09:59 PM, Vasanthakumar Thiagarajan wrote:
> > On Tue, Jul 06, 2010 at 01:22:25AM +0530, [email protected] wrote:
> >> From: Ben Greear<[email protected]>
> >>
> >> It is very difficult to map phyX devices to real/virtual
> >> entities because the phyX devices change on module
> >> reload. This patch makes it slightly easier to
> >> associate virtual phy devices with phyX entities.
> >>
> >
> > It does not make much sense to give an index while creating a new
> > virtual wiphy interface. This is unncessary, only wiphy name
> > matters.
>
> Will the underlying code allow you to specify a phy name though? It
> seems to me that once a phyX is used, you cannot have a new phy
> with that name again, even if the old one has been unloaded

Driver has nothing to do with assigning phy names. This is done in
cfg80211.


Vasanth

Subject: Re: [ath9k] ath9k: Expose virtual wiphy indexes to debugfs.

On Tue, Jul 06, 2010 at 01:22:25AM +0530, [email protected] wrote:
> From: Ben Greear <[email protected]>
>
> It is very difficult to map phyX devices to real/virtual
> entities because the phyX devices change on module
> reload. This patch makes it slightly easier to
> associate virtual phy devices with phyX entities.
>

It does not make much sense to give an index while creating a new
virtual wiphy interface. This is unncessary, only wiphy name
matters.

Vasanth