Skip to contentSkip to conversation

orinoco: initiate cfg80211 conversion

RFC Superseded David Kilroy 2 participants 9 messages May 16, 2009

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover orinoco: initiate cfg80211 conversion

The interesting bit of this series is in patch 3, which shamelessly cribs from Johns rndis_wlan conversion.

I'm interested in hearing if there's a better way to organise the wiphy/wdev/net_device/orinoco_private structures for orinoco. Also whether I'm registering with netdev and cfg80211 in the right places.

The driver appears to runs fine. iw list shows the card on phy0. iwconfig still gets 'IEEE802.11b' for GIWNAME. However the device is still eth1 - is that expected?

The first two patches are only there because I started marking things const, and found a couple cfg80211 interfaces wouldn't let me. I couldn't see anything in the code that needs to modify ops and privid, so I've marked them const. A build coverring (almost?) all drivers still works, and I couldn't see any extra sparse complaints. Anyway, I've no particular attachment to these two patches, so dropping them is fine by me.

Regards,

Dave.
---

David Kilroy (3):
cfg80211: mark ops as pointer to const
cfg80211: mark wiphy->privid as pointer to const
orinoco: initiate cfg80211 conversion

 drivers/net/wireless/orinoco/Kconfig   |    1 +
 drivers/net/wireless/orinoco/Makefile  |    2 +-
 drivers/net/wireless/orinoco/cfg.c     |   82 ++++++++++++++++++++++++++++++++
 drivers/net/wireless/orinoco/cfg.h     |   18 +++++++
 drivers/net/wireless/orinoco/main.c    |   28 ++++++++++-
 drivers/net/wireless/orinoco/orinoco.h |    7 +++
 drivers/net/wireless/orinoco/wext.c    |   22 +--------
 include/net/cfg80211.h                 |    4 +-
 net/wireless/core.c                    |    2 +-
 net/wireless/core.h                    |    2 +-
 10 files changed, 142 insertions(+), 26 deletions(-)
 create mode 100644 drivers/net/wireless/orinoco/cfg.c
 create mode 100644 drivers/net/wireless/orinoco/cfg.h
#1 lore raw

RFC 1/3 cfg80211: mark ops as pointer to const

This allows drivers to mark their cfg80211_ops tables const.

Signed-off by: David Kilroy <[email protected]>

---
 include/net/cfg80211.h |    2 +-
 net/wireless/core.c    |    2 +-
 net/wireless/core.h    |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
include/net/cfg80211.h +1 -1
index 9e17a83..7702715 100644
@@ -1070,7 +1070,7 @@ static inline const char *wiphy_name(struct wiphy *wiphy)
  * The returned pointer must be assigned to each netdev's
  * ieee80211_ptr for proper operation.
  */
-struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
+struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv);
 
 /**
  * wiphy_register - register a wiphy with cfg80211
net/wireless/core.c +1 -1
index 47c20eb..98bfd4d 100644
@@ -228,7 +228,7 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
 
 /* exported functions */
 
-struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
+struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
 {
 	static int wiphy_counter;
 
net/wireless/core.h +1 -1
index f14b6c5..725c22e 100644
@@ -15,7 +15,7 @@
 #include "reg.h"
 
 struct cfg80211_registered_device {
-	struct cfg80211_ops *ops;
+	const struct cfg80211_ops *ops;
 	struct list_head list;
 	/* we hold this mutex during any call so that
 	 * we cannot do multiple calls at once, and also
Signature · 1 line
1.6.0.6
#3 lore raw

RFC 2/3 cfg80211: mark wiphy->privid as pointer to const

In reply to David Kilroy

This allows drivers to use a const pointer as the privid without a cast.

Signed-off by: David Kilroy <[email protected]>

---
 include/net/cfg80211.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/net/cfg80211.h +1 -1
index 7702715..0639962 100644
@@ -994,7 +994,7 @@ struct wiphy {
 	 * know whether it points to a wiphy your driver has registered
 	 * or not. Assign this to something global to your driver to
 	 * help determine whether you own this wiphy or not. */
-	void *privid;
+	const void *privid;
 
 	struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
 
Signature · 1 line
1.6.0.6
#5 lore raw

RFC 3/3 orinoco: initiate cfg80211 conversion

In reply to David Kilroy

Initialise and register a wiphy. We can immediately rely on cfg80211 to handle SIOCGIWNAME.

Signed-off by: David Kilroy <[email protected]>

---
 drivers/net/wireless/orinoco/Kconfig   |    1 +
 drivers/net/wireless/orinoco/Makefile  |    2 +-
 drivers/net/wireless/orinoco/cfg.c     |   82 ++++++++++++++++++++++++++++++++
 drivers/net/wireless/orinoco/cfg.h     |   18 +++++++
 drivers/net/wireless/orinoco/main.c    |   28 ++++++++++-
 drivers/net/wireless/orinoco/orinoco.h |    7 +++
 drivers/net/wireless/orinoco/wext.c    |   22 +--------
 7 files changed, 138 insertions(+), 22 deletions(-)
 create mode 100644 drivers/net/wireless/orinoco/cfg.c
 create mode 100644 drivers/net/wireless/orinoco/cfg.h
drivers/net/wireless/orinoco/Kconfig +1 -0
index 44411eb..9f8e96e 100644
@@ -5,6 +5,7 @@ config HERMES
 	select FW_LOADER
 	select CRYPTO
 	select CRYPTO_MICHAEL_MIC
+	select CFG80211
 	---help---
 	  A driver for 802.11b wireless cards based on the "Hermes" or
 	  Intersil HFA384x (Prism 2) MAC controller.  This includes the vast
drivers/net/wireless/orinoco/Makefile +1 -1
index 1fc7409..9abd632 100644
@@ -1,7 +1,7 @@
 #
 # Makefile for the orinoco wireless device drivers.
 #
-orinoco-objs := main.o fw.o hw.o mic.o scan.o wext.o hermes_dld.o hermes.o
+orinoco-objs := main.o fw.o hw.o mic.o scan.o wext.o hermes_dld.o hermes.o cfg.o
 
 obj-$(CONFIG_HERMES)		+= orinoco.o
 obj-$(CONFIG_PCMCIA_HERMES)	+= orinoco_cs.o
drivers/net/wireless/orinoco/cfg.c new file +82 -0

82 lines not on this page · raw message

drivers/net/wireless/orinoco/cfg.h new file +18 -0
new file mode 100644
index 0000000..6bd3071
@@ -0,0 +1,18 @@
+/* cfg80211 support.
+ *
+ * See copyright notice in main.c
+ */
+#ifndef ORINOCO_CFG_H
+#define ORINOCO_CFG_H
+
+#include <net/cfg80211.h>
+
+/* Forward declaration */
+struct orinoco_private;
+
+extern const struct cfg80211_ops orinoco_cfg_ops;
+
+void orinoco_wiphy_init(struct wiphy *wiphy, struct orinoco_private *priv);
+int orinoco_wiphy_register(struct wiphy *wiphy);
+
+#endif /* ORINOCO_CFG_H */
drivers/net/wireless/orinoco/main.c +27 -1
index 345593c..d062307 100644
@@ -88,6 +88,7 @@
 #include <linux/wireless.h>
 #include <linux/ieee80211.h>
 #include <net/iw_handler.h>
+#include <net/cfg80211.h>
 
 #include "hermes_rid.h"
 #include "hermes_dld.h"
@@ -96,6 +97,7 @@
 #include "mic.h"
 #include "fw.h"
 #include "wext.h"
+#include "cfg.h"
 #include "main.h"
 
 #include "orinoco.h"
@@ -2502,6 +2504,11 @@ static int orinoco_init(struct net_device *dev)
 	priv->wpa_ie_len = 0;
 	priv->wpa_ie = NULL;
 
+	if (orinoco_wiphy_register(priv->wdev.wiphy)) {
+		err = -ENODEV;
+		goto out;
+	}
+
 	/* Make the hardware available, as long as it hasn't been
 	 * removed elsewhere (e.g. by PCMCIA hot unplug) */
 	spin_lock_irq(&priv->lock);
@@ -2533,12 +2540,26 @@ struct net_device
 {
 	struct net_device *dev;
 	struct orinoco_private *priv;
+	struct wiphy *wiphy;
+
+	/* allocate wiphy
+	 * NOTE: We only support a single virtual interface, so wiphy
+	 * and wireless_dev are somewhat synonymous for this device.
+	 */
+	wiphy = wiphy_new(&orinoco_cfg_ops,
+			  sizeof(struct orinoco_private *));
+	if (!wiphy)
+		return NULL;
 
 	dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
-	if (!dev)
+	if (!dev) {
+		wiphy_free(wiphy);
 		return NULL;
+	}
+
 	priv = netdev_priv(dev);
 	priv->ndev = dev;
+
 	if (sizeof_card)
 		priv->card = (void *)((unsigned long)priv
 				      + sizeof(struct orinoco_private));
@@ -2547,6 +2568,7 @@ struct net_device
 	priv->dev = device;
 
 	/* Setup / override net_device fields */
+	dev->ieee80211_ptr = &priv->wdev;
 	dev->netdev_ops = &orinoco_netdev_ops;
 	dev->watchdog_timeo = HZ; /* 1 second timeout */
 	dev->ethtool_ops = &orinoco_ethtool_ops;
@@ -2588,6 +2610,8 @@ struct net_device
 	/* Register PM notifiers */
 	orinoco_register_pm_notifier(priv);
 
+	orinoco_wiphy_init(wiphy, priv);
+
 	return dev;
 }
 EXPORT_SYMBOL(alloc_orinocodev);
@@ -2618,7 +2642,9 @@ void free_orinocodev(struct net_device *dev)
 	kfree(priv->wpa_ie);
 	orinoco_mic_free(priv);
 	orinoco_bss_data_free(priv);
+	wiphy_unregister(priv->wdev.wiphy);
 	free_netdev(dev);
+	wiphy_free(priv->wdev.wiphy);
 }
 EXPORT_SYMBOL(free_orinocodev);
 
drivers/net/wireless/orinoco/orinoco.h +7 -0
index 8e5a72c..afc0f6b 100644
@@ -14,6 +14,7 @@
 #include <linux/netdevice.h>
 #include <linux/wireless.h>
 #include <net/iw_handler.h>
+#include <net/cfg80211.h>
 
 #include "hermes.h"
 
@@ -64,9 +65,15 @@ struct firmware;
 struct orinoco_private {
 	void *card;	/* Pointer to card dependent structure */
 	struct device *dev;
+	struct wireless_dev wdev;
 	int (*hard_reset)(struct orinoco_private *);
 	int (*stop_fw)(struct orinoco_private *, int);
 
+	/* cfg80211 */
+	struct ieee80211_supported_band band;
+	struct ieee80211_channel channels[14];
+	struct ieee80211_rate rates[4];
+
 	/* Synchronisation stuff */
 	spinlock_t lock;
 	int hw_unavailable;
drivers/net/wireless/orinoco/wext.c +2 -20
index 3f08142..7ce471a 100644
@@ -7,6 +7,7 @@
 #include <linux/wireless.h>
 #include <linux/ieee80211.h>
 #include <net/iw_handler.h>
+#include <net/cfg80211.h>
 
 #include "hermes.h"
 #include "hermes_rid.h"
@@ -87,25 +88,6 @@ static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
 /* Wireless extensions                                              */
 /********************************************************************/
 
-static int orinoco_ioctl_getname(struct net_device *dev,
-				 struct iw_request_info *info,
-				 char *name,
-				 char *extra)
-{
-	struct orinoco_private *priv = netdev_priv(dev);
-	int numrates;
-	int err;
-
-	err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
-
-	if (!err && (numrates > 2))
-		strcpy(name, "IEEE 802.11b");
-	else
-		strcpy(name, "IEEE 802.11-DS");
-
-	return 0;
-}
-
 static int orinoco_ioctl_setwap(struct net_device *dev,
 				struct iw_request_info *info,
 				struct sockaddr *ap_addr,
@@ -2258,7 +2240,7 @@ static const struct iw_priv_args orinoco_privtab[] = {
 	[IW_IOCTL_IDX(id)] = (iw_handler) func
 static const iw_handler	orinoco_handler[] = {
 	STD_IW_HANDLER(SIOCSIWCOMMIT,	orinoco_ioctl_commit),
-	STD_IW_HANDLER(SIOCGIWNAME,	orinoco_ioctl_getname),
+	STD_IW_HANDLER(SIOCGIWNAME,	cfg80211_wext_giwname),
 	STD_IW_HANDLER(SIOCSIWFREQ,	orinoco_ioctl_setfreq),
 	STD_IW_HANDLER(SIOCGIWFREQ,	orinoco_ioctl_getfreq),
 	STD_IW_HANDLER(SIOCSIWMODE,	orinoco_ioctl_setmode),
Signature · 1 line
1.6.0.6
maintainer Acked-by on v1 1/3
#2 lore raw

Re: [RFC 1/3] cfg80211: mark ops as pointer to const

In reply to David Kilroy
Quoted 1 line · David Kilroy

This allows drivers to mark their cfg80211_ops tables const.

Seems fine to me. Somehow I forgot to mark lots of things const in cfg80211...

Quoted 1 line

Signed-off by: David Kilroy <[email protected]>

Quoted 45 lines
---
 include/net/cfg80211.h |    2 +-
 net/wireless/core.c    |    2 +-
 net/wireless/core.h    |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
include/net/cfg80211.h +1 -1
index 9e17a83..7702715 100644
@@ -1070,7 +1070,7 @@ static inline const char *wiphy_name(struct wiphy *wiphy)
  * The returned pointer must be assigned to each netdev's
  * ieee80211_ptr for proper operation.
  */
-struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
+struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv);
 
 /**
  * wiphy_register - register a wiphy with cfg80211
net/wireless/core.c +1 -1
index 47c20eb..98bfd4d 100644
@@ -228,7 +228,7 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
 
 /* exported functions */
 
-struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
+struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
 {
 	static int wiphy_counter;
 
net/wireless/core.h +1 -1
index f14b6c5..725c22e 100644
@@ -15,7 +15,7 @@
 #include "reg.h"
 
 struct cfg80211_registered_device {
-	struct cfg80211_ops *ops;
+	const struct cfg80211_ops *ops;
 	struct list_head list;
 	/* we hold this mutex during any call so that
 	 * we cannot do multiple calls at once, and also
maintainer Acked-by on v1 2/3
#4 lore raw

Re: [RFC 2/3] cfg80211: mark wiphy->privid as pointer to const

In reply to David Kilroy
Quoted 1 line · David Kilroy

This allows drivers to use a const pointer as the privid without a cast.

Same here.

Quoted 1 line

Signed-off by: David Kilroy <[email protected]>

Quoted 17 lines
---
 include/net/cfg80211.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
include/net/cfg80211.h +1 -1
index 7702715..0639962 100644
@@ -994,7 +994,7 @@ struct wiphy {
 	 * know whether it points to a wiphy your driver has registered
 	 * or not. Assign this to something global to your driver to
 	 * help determine whether you own this wiphy or not. */
-	void *privid;
+	const void *privid;
 
 	struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
 
maintainer
#6 lore raw
In reply to David Kilroy

drivers/net/wireless/orinoco/cfg.c line 21

Quoted 8 lines · David Kilroy
drivers/net/wireless/orinoco/cfg.c new file +8 -0
+/* Supported bitrates. Must agree with hw.c
+ * TODO: are the flags correct? */
+static const struct ieee80211_rate orinoco_rates[] = {
+	{ .bitrate = 10 },
+	{ .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+	{ .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+	{ .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+};

Flags look fine from a protocol POV, I don't know whether your hw supports short preamble. On the other hand, this is only reported to userspace, we don't do anything with it in cfg80211.

Quoted 3 lines

+/* Called after orinoco_private is allocated.
+ * Which must we do now? Which do we put off until we have firmware?
+ */

Generally, try to do things as early as possible.

Quoted 24 lines
drivers/net/wireless/orinoco/cfg.c new file +24 -0
+void orinoco_wiphy_init(struct wiphy *wiphy, struct orinoco_private *priv)
+{
+	/* Setup so that we can recover orinoco_private from wiphy */
+	ophy_priv(wiphy) = priv;
+
+	wiphy->privid = orinoco_wiphy_privid;
+
+	priv->wdev.wiphy = wiphy;
+	priv->wdev.iftype = NL80211_IFTYPE_STATION;
+
+	set_wiphy_dev(wiphy, priv->dev);
+}
+
+/* Called after firmware is initialised */
+int orinoco_wiphy_register(struct wiphy *wiphy)
+{
+	struct orinoco_private *priv = ophy_priv(wiphy);
+	int i, channels = 0;
+
+	memcpy(wiphy->perm_addr, priv->ndev->dev_addr, ETH_ALEN);
+
+	wiphy->max_scan_ssids = 1;
+
+	wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);

drivers/net/wireless/orinoco/cfg.c line 61

Quoted 10 lines
drivers/net/wireless/orinoco/cfg.c new file +10 -0
+
+	/* TODO: should we set if we only have demo ad-hoc?
+	 *       (priv->has_port3)
+	 */
+	if (priv->has_ibss)
+		wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
+
+	memcpy(priv->rates, orinoco_rates, sizeof(orinoco_rates));
+	priv->band.bitrates = priv->rates;
+	priv->band.n_bitrates = ARRAY_SIZE(orinoco_rates);

Is there a need to copy the rates? Normally you should be able to just do

	priv->band.bitrates = orinoco_rates;
Quoted 6 lines
drivers/net/wireless/orinoco/cfg.c new file +6 -0
+	/* Only support channels allowed by the card EEPROM */
+	for (i = 0; i < 14; i++) {
+		if (priv->channel_mask & (1 << i)) {
+			priv->channels[i].center_freq =
+				ieee80211_dsss_chan_to_freq(i+1);
+			channels++;

drivers/net/wireless/orinoco/cfg.c line 78

Quoted 10 lines
drivers/net/wireless/orinoco/cfg.c new file +10 -0
+		}
+	}
+	priv->band.channels = priv->channels;
+	priv->band.n_channels = channels;
+
+	wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
+	wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
+
+	return wiphy_register(wiphy);
+}

When do you load firmware? We try to only load it when the first interface is brought up, but that's sometimes problematic because then we don't have enough information.

drivers/net/wireless/orinoco/cfg.c line 82

Quoted 3 lines
drivers/net/wireless/orinoco/cfg.c new file +3 -0
+const struct cfg80211_ops orinoco_cfg_ops = {
+
+};

Heh.

Quoted 17 lines

#include "orinoco.h"

drivers/net/wireless/orinoco/main.c +5 -0
@@ -2502,6 +2504,11 @@ static int orinoco_init(struct net_device *dev)
 	priv->wpa_ie_len = 0;
 	priv->wpa_ie = NULL;
 
+	if (orinoco_wiphy_register(priv->wdev.wiphy)) {
+		err = -ENODEV;
+		goto out;
+	}
+
 	/* Make the hardware available, as long as it hasn't been
 	 * removed elsewhere (e.g. by PCMCIA hot unplug) */
 	spin_lock_irq(&priv->lock);
@@ -2533,12 +2540,26 @@ struct net_device
 {
 	struct net_device *dev;
 	struct orinoco_private *priv;

drivers/net/wireless/orinoco/main.c struct net_device · line 2552

Quoted 10 lines
drivers/net/wireless/orinoco/main.c +10 -0
+	struct wiphy *wiphy;
+
+	/* allocate wiphy
+	 * NOTE: We only support a single virtual interface, so wiphy
+	 * and wireless_dev are somewhat synonymous for this device.
+	 */
+	wiphy = wiphy_new(&orinoco_cfg_ops,
+			  sizeof(struct orinoco_private *));
+	if (!wiphy)
+		return NULL;

You could with little effort, support virtual monitor interfaces by just passing all frames the firmware gives you to those. Probably not worth bothering with though.

Other notes:
* you could easily migrate over orinoco_ioctl_setmode/getmode
* if we improve the cfg80211 iwrange implementation a little and you register which ciphers you support, you can migrate over orinoco_ioctl_getiwrange
* iwencode(ext) should be fairly easy too
* just get rid of iwnick
* rts/frag/retry should be easy to migrate
* what are ibss ports?
* scan should be easy to port too
* iwpriv isn't supported by cfg80211

Anyway looks good for a start, though I would maybe build the structures a little different and not put the wdev into priv since priv is per hardware.

Generally the layout I recommend would be like this:

+-------------+
|  wiphy      |
+-------------+
|  priv       |  == wiphy_priv()
+-------------+

and

+-------------+
|  netdev     |
+-------------+
|  wdev       |  == netdev_priv()
+-------------+

For you it doesn't really matter since you can only have one virtual interface (well in monitor mode you could have multiple but that seems pointless) -- it's still more in line with what other drivers are doing though.

johannes

author
#7 lore raw
Quoted 13 lines · Johannes Berg

drivers/net/wireless/orinoco/cfg.c line 21

Quoted 8 lines · David Kilroy
drivers/net/wireless/orinoco/cfg.c new file +8 -0
+/* Supported bitrates. Must agree with hw.c
+ * TODO: are the flags correct? */
+static const struct ieee80211_rate orinoco_rates[] = {
+	{ .bitrate = 10 },
+	{ .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+	{ .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+	{ .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+};

Flags look fine from a protocol POV, I don't know whether your hw supports short preamble. On the other hand, this is only reported to userspace, we don't do anything with it in cfg80211.

I thought that might be the case. I think I'll remove the flags, as there's some code that indicates only some of the cards support short preamble.

Quoted 7 lines

drivers/net/wireless/orinoco/cfg.c line 61

Quoted 3 lines
drivers/net/wireless/orinoco/cfg.c new file +3 -0
+	memcpy(priv->rates, orinoco_rates, sizeof(orinoco_rates));
+	priv->band.bitrates = priv->rates;
+	priv->band.n_bitrates = ARRAY_SIZE(orinoco_rates);

Is there a need to copy the rates? Normally you should be able to just do

	priv->band.bitrates = orinoco_rates;

I just copied what rndis was doing. I'll do as you recommend.

Quoted 3 lines

When do you load firmware? We try to only load it when the first interface is brought up, but that's sometimes problematic because then we don't have enough information.

Firmware is loaded when netdev calls ndo_init. I think netdev is registerred by the hardware modules (airport, _cs etc) shortly after allocating orinoco_priv.

Quoted 4 lines
Quoted 4 lines
drivers/net/wireless/orinoco/main.c +4 -0
+	/* allocate wiphy
+	 * NOTE: We only support a single virtual interface, so wiphy
+	 * and wireless_dev are somewhat synonymous for this device.
+	 */
Quoted 8 lines

drivers/net/wireless/orinoco/main.c struct net_device · line 2552

Quoted 4 lines
drivers/net/wireless/orinoco/main.c +4 -0
+	wiphy = wiphy_new(&orinoco_cfg_ops,
+			  sizeof(struct orinoco_private *));
+	if (!wiphy)
+		return NULL;

You could with little effort, support virtual monitor interfaces by just passing all frames the firmware gives you to those. Probably not worth bothering with though.

Yep. I'll look at supporting monitor interfaces later on.

Quoted 11 lines

Other notes:
* you could easily migrate over orinoco_ioctl_setmode/getmode
* if we improve the cfg80211 iwrange implementation a little and you register which ciphers you support, you can migrate over orinoco_ioctl_getiwrange
* iwencode(ext) should be fairly easy too
* just get rid of iwnick
* rts/frag/retry should be easy to migrate
* what are ibss ports?
* scan should be easy to port too
* iwpriv isn't supported by cfg80211

Yep. I wanted to get the structure layout right before tackling those.

Hermes has different types of 'ports'. We configure the port as either type 1 or type 3. In addition the port can have what seems to be an ibss attribute, which allows us to do IEEE ad-hoc. Apparently type 3 allows us to do a demo ad-hoc mode. Different firmwares need to use different port settings for different modes of operation (see determine_firmware).

Quoted 20 lines

Anyway looks good for a start, though I would maybe build the structures a little different and not put the wdev into priv since priv is per hardware.

Generally the layout I recommend would be like this:

+-------------+
|  wiphy      |
+-------------+
|  priv       |  == wiphy_priv()
+-------------+

and

+-------------+
|  netdev     |
+-------------+
|  wdev       |  == netdev_priv()
+-------------+
Quoted 4 lines

For you it doesn't really matter since you can only have one virtual interface (well in monitor mode you could have multiple but that seems pointless) -- it's still more in line with what other drivers are doing though.

That makes a bit more sense. I'll try restructure things this way to be consistent.

Thanks for the feedback!

Dave.

#8 lore raw

RFC 3/3 orinoco: initiate cfg80211 conversion

In reply to Johannes Berg

Initialise and register a wiphy.

Move the driver private structure from net_device to the new wiphy, and store a wireless_dev structure in the net_device private area. This results in a change to the way we navigate from a net_device to the driver private orinoco_private, which we encapsulate in the inline function ndev_priv. Almost all calls to netdev_priv are thus replaced by ndev_priv.

We can immediately rely on cfg80211 to handle SIOCGIWNAME, so orinoco_ioctl_getname is removed.

---
The big change from the last post is the move of orinoco_private to the wiphy, and placing wdev in net_device. Many more files are touched, but they're all s/netdev_priv/ndev_priv/. Things still seem to work.

Also:
* removed the short preamble flags on the bitrates. These are only
supported on Symbol and Intersil firmwares, and the flag only affects display.
* point band bitrates at the static local array, rather than memcpy.
* unregister the wiphy slightly earlier

---
 drivers/net/wireless/orinoco/Kconfig          |    1 +
 drivers/net/wireless/orinoco/Makefile         |    2 +-
 drivers/net/wireless/orinoco/airport.c        |    8 +-
 drivers/net/wireless/orinoco/cfg.c            |   71 +++++++++++++++
 drivers/net/wireless/orinoco/cfg.h            |   15 +++
 drivers/net/wireless/orinoco/main.c           |  121 +++++++++++++++++++------
 drivers/net/wireless/orinoco/orinoco.h        |   10 ++
 drivers/net/wireless/orinoco/orinoco_cs.c     |   10 +-
 drivers/net/wireless/orinoco/orinoco_nortel.c |    4 +-
 drivers/net/wireless/orinoco/orinoco_pci.c    |    4 +-
 drivers/net/wireless/orinoco/orinoco_pci.h    |    4 +-
 drivers/net/wireless/orinoco/orinoco_plx.c    |    4 +-
 drivers/net/wireless/orinoco/orinoco_tmd.c    |    4 +-
 drivers/net/wireless/orinoco/spectrum_cs.c    |   10 +-
 drivers/net/wireless/orinoco/wext.c           |  110 ++++++++++-------------
 15 files changed, 259 insertions(+), 119 deletions(-)
 create mode 100644 drivers/net/wireless/orinoco/cfg.c
 create mode 100644 drivers/net/wireless/orinoco/cfg.h
drivers/net/wireless/orinoco/Kconfig +1 -0
index 44411eb..9f8e96e 100644
@@ -5,6 +5,7 @@ config HERMES
 	select FW_LOADER
 	select CRYPTO
 	select CRYPTO_MICHAEL_MIC
+	select CFG80211
 	---help---
 	  A driver for 802.11b wireless cards based on the "Hermes" or
 	  Intersil HFA384x (Prism 2) MAC controller.  This includes the vast
drivers/net/wireless/orinoco/Makefile +1 -1
index 1fc7409..9abd632 100644
@@ -1,7 +1,7 @@
 #
 # Makefile for the orinoco wireless device drivers.
 #
-orinoco-objs := main.o fw.o hw.o mic.o scan.o wext.o hermes_dld.o hermes.o
+orinoco-objs := main.o fw.o hw.o mic.o scan.o wext.o hermes_dld.o hermes.o cfg.o
 
 obj-$(CONFIG_HERMES)		+= orinoco.o
 obj-$(CONFIG_PCMCIA_HERMES)	+= orinoco_cs.o
drivers/net/wireless/orinoco/airport.c +4 -4
index 8c4065f..66f816e 100644
@@ -35,7 +35,7 @@ static int
 airport_suspend(struct macio_dev *mdev, pm_message_t state)
 {
 	struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev);
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	unsigned long flags;
 	int err;
 
@@ -70,7 +70,7 @@ static int
 airport_resume(struct macio_dev *mdev)
 {
 	struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev);
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	unsigned long flags;
 	int err;
 
@@ -112,7 +112,7 @@ static int
 airport_detach(struct macio_dev *mdev)
 {
 	struct net_device *dev = dev_get_drvdata(&mdev->ofdev.dev);
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	struct airport *card = priv->card;
 
 	if (card->ndev_registered)
@@ -191,7 +191,7 @@ airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
 		printk(KERN_ERR PFX "Cannot allocate network device\n");
 		return -ENODEV;
 	}
-	priv = netdev_priv(dev);
+	priv = ndev_priv(dev);
 	card = priv->card;
 
 	hw = &priv->hw;
drivers/net/wireless/orinoco/cfg.c new file +71 -0

71 lines not on this page · raw message

drivers/net/wireless/orinoco/cfg.h new file +15 -0
new file mode 100644
index 0000000..3ddc96a
@@ -0,0 +1,15 @@
+/* cfg80211 support.
+ *
+ * See copyright notice in main.c
+ */
+#ifndef ORINOCO_CFG_H
+#define ORINOCO_CFG_H
+
+#include <net/cfg80211.h>
+
+extern const struct cfg80211_ops orinoco_cfg_ops;
+
+void orinoco_wiphy_init(struct wiphy *wiphy);
+int orinoco_wiphy_register(struct wiphy *wiphy);
+
+#endif /* ORINOCO_CFG_H */
drivers/net/wireless/orinoco/main.c +91 -30

331 lines not on this page · raw message

drivers/net/wireless/orinoco/orinoco.h +10 -0
index 8e5a72c..34f956a 100644
@@ -14,6 +14,7 @@
 #include <linux/netdevice.h>
 #include <linux/wireless.h>
 #include <net/iw_handler.h>
+#include <net/cfg80211.h>
 
 #include "hermes.h"
 
@@ -67,6 +68,9 @@ struct orinoco_private {
 	int (*hard_reset)(struct orinoco_private *);
 	int (*stop_fw)(struct orinoco_private *, int);
 
+	struct ieee80211_supported_band band;
+	struct ieee80211_channel channels[14];
+
 	/* Synchronisation stuff */
 	spinlock_t lock;
 	int hw_unavailable;
@@ -215,4 +219,10 @@ static inline void orinoco_unlock(struct orinoco_private *priv,
 	spin_unlock_irqrestore(&priv->lock, *flags);
 }
 
+/*** Navigate from net_device to orinoco_private ***/
+static inline struct orinoco_private *ndev_priv(struct net_device *dev)
+{
+	struct wireless_dev *wdev = netdev_priv(dev);
+	return wdev_priv(wdev);
+}
 #endif /* _ORINOCO_H */
drivers/net/wireless/orinoco/orinoco_cs.c +5 -5
index b381aed..4edec8f 100644
@@ -114,7 +114,7 @@ orinoco_cs_probe(struct pcmcia_device *link)
 			       orinoco_cs_hard_reset, NULL);
 	if (!dev)
 		return -ENOMEM;
-	priv = netdev_priv(dev);
+	priv = ndev_priv(dev);
 	card = priv->card;
 
 	/* Link both structures together */
@@ -240,7 +240,7 @@ static int
 orinoco_cs_config(struct pcmcia_device *link)
 {
 	struct net_device *dev = link->priv;
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	struct orinoco_pccard *card = priv->card;
 	hermes_t *hw = &priv->hw;
 	int last_fn, last_ret;
@@ -337,7 +337,7 @@ static void
 orinoco_cs_release(struct pcmcia_device *link)
 {
 	struct net_device *dev = link->priv;
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	unsigned long flags;
 
 	/* We're committed to taking the device away now, so mark the
@@ -354,7 +354,7 @@ orinoco_cs_release(struct pcmcia_device *link)
 static int orinoco_cs_suspend(struct pcmcia_device *link)
 {
 	struct net_device *dev = link->priv;
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	struct orinoco_pccard *card = priv->card;
 	int err = 0;
 	unsigned long flags;
@@ -382,7 +382,7 @@ static int orinoco_cs_suspend(struct pcmcia_device *link)
 static int orinoco_cs_resume(struct pcmcia_device *link)
 {
 	struct net_device *dev = link->priv;
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	struct orinoco_pccard *card = priv->card;
 	int err = 0;
 	unsigned long flags;
drivers/net/wireless/orinoco/orinoco_nortel.c +2 -2
index b017262..75ed160 100644
@@ -189,7 +189,7 @@ static int orinoco_nortel_init_one(struct pci_dev *pdev,
 		goto fail_alloc;
 	}
 
-	priv = netdev_priv(dev);
+	priv = ndev_priv(dev);
 	card = priv->card;
 	card->bridge_io = bridge_io;
 	card->attr_io = attr_io;
@@ -257,7 +257,7 @@ static int orinoco_nortel_init_one(struct pci_dev *pdev,
 static void __devexit orinoco_nortel_remove_one(struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	struct orinoco_pci_card *card = priv->card;
 
 	/* Clear LEDs */
drivers/net/wireless/orinoco/orinoco_pci.c +2 -2
index 78cafff..43094ed 100644
@@ -147,7 +147,7 @@ static int orinoco_pci_init_one(struct pci_dev *pdev,
 		goto fail_alloc;
 	}
 
-	priv = netdev_priv(dev);
+	priv = ndev_priv(dev);
 	card = priv->card;
 	SET_NETDEV_DEV(dev, &pdev->dev);
 
@@ -201,7 +201,7 @@ static int orinoco_pci_init_one(struct pci_dev *pdev,
 static void __devexit orinoco_pci_remove_one(struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 
 	unregister_netdev(dev);
 	free_irq(pdev->irq, dev);
drivers/net/wireless/orinoco/orinoco_pci.h +2 -2
index c655b4a..382dc4b 100644
@@ -22,7 +22,7 @@ struct orinoco_pci_card {
 static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	unsigned long flags;
 	int err;
 
@@ -55,7 +55,7 @@ static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
 static int orinoco_pci_resume(struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	unsigned long flags;
 	int err;
 
drivers/net/wireless/orinoco/orinoco_plx.c +2 -2
index a2a4471..2b9074a 100644
@@ -228,7 +228,7 @@ static int orinoco_plx_init_one(struct pci_dev *pdev,
 		goto fail_alloc;
 	}
 
-	priv = netdev_priv(dev);
+	priv = ndev_priv(dev);
 	card = priv->card;
 	card->bridge_io = bridge_io;
 	card->attr_io = attr_io;
@@ -296,7 +296,7 @@ static int orinoco_plx_init_one(struct pci_dev *pdev,
 static void __devexit orinoco_plx_remove_one(struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	struct orinoco_pci_card *card = priv->card;
 
 	unregister_netdev(dev);
drivers/net/wireless/orinoco/orinoco_tmd.c +2 -2
index cda0e6e..477fe1e 100644
@@ -132,7 +132,7 @@ static int orinoco_tmd_init_one(struct pci_dev *pdev,
 		goto fail_alloc;
 	}
 
-	priv = netdev_priv(dev);
+	priv = ndev_priv(dev);
 	card = priv->card;
 	card->bridge_io = bridge_io;
 	SET_NETDEV_DEV(dev, &pdev->dev);
@@ -190,7 +190,7 @@ static int orinoco_tmd_init_one(struct pci_dev *pdev,
 static void __devexit orinoco_tmd_remove_one(struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	struct orinoco_pci_card *card = priv->card;
 
 	unregister_netdev(dev);
drivers/net/wireless/orinoco/spectrum_cs.c +5 -5
index 38e5198..c3702d4 100644
@@ -187,7 +187,7 @@ spectrum_cs_probe(struct pcmcia_device *link)
 			       spectrum_cs_stop_firmware);
 	if (!dev)
 		return -ENOMEM;
-	priv = netdev_priv(dev);
+	priv = ndev_priv(dev);
 	card = priv->card;
 
 	/* Link both structures together */
@@ -307,7 +307,7 @@ static int
 spectrum_cs_config(struct pcmcia_device *link)
 {
 	struct net_device *dev = link->priv;
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	struct orinoco_pccard *card = priv->card;
 	hermes_t *hw = &priv->hw;
 	int last_fn, last_ret;
@@ -409,7 +409,7 @@ static void
 spectrum_cs_release(struct pcmcia_device *link)
 {
 	struct net_device *dev = link->priv;
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	unsigned long flags;
 
 	/* We're committed to taking the device away now, so mark the
@@ -428,7 +428,7 @@ static int
 spectrum_cs_suspend(struct pcmcia_device *link)
 {
 	struct net_device *dev = link->priv;
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	unsigned long flags;
 	int err = 0;
 
@@ -452,7 +452,7 @@ static int
 spectrum_cs_resume(struct pcmcia_device *link)
 {
 	struct net_device *dev = link->priv;
-	struct orinoco_private *priv = netdev_priv(dev);
+	struct orinoco_private *priv = ndev_priv(dev);
 	unsigned long flags;
 	int err;
 
drivers/net/wireless/orinoco/wext.c +46 -64

391 lines not on this page · raw message

Signature · 1 line
1.6.0.6