Skip to contentSkip to conversation

atheros: implement common read/write ops

PATCH Superseded Luis R. Rodriguez 6 participants 17 messages Sep 11, 2009 – Sep 13, 2009

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover atheros: implement common read/write ops

This is my fourth series, as I had noted earlier another thing we needed to do was make read/write driver core specific so that ath9k_htc can define its own and yet share common hw code. As it turns out this means the work here allows us to also start sharing hw code between ath9k and ath5k. The last patch is an example of this.

Luis R. Rodriguez (4):
atheros/ath9k: add common read/write ops and port ath9k to use it
ath5k: allocate ath5k_hw prior to initializing hw
ath5k: define ath_common ops
atheros: define shared bssidmask setting

 drivers/net/wireless/ath/Makefile        |    5 +-
 drivers/net/wireless/ath/ath.h           |    9 ++
 drivers/net/wireless/ath/ath5k/ath5k.h   |   24 ++++---
 drivers/net/wireless/ath/ath5k/attach.c  |   25 +-----
 drivers/net/wireless/ath/ath5k/base.c    |   38 ++++++++-
 drivers/net/wireless/ath/ath5k/base.h    |   11 ---
 drivers/net/wireless/ath/ath5k/pcu.c     |  113 +--------------------------
 drivers/net/wireless/ath/ath9k/ath9k.h   |    3 -
 drivers/net/wireless/ath/ath9k/hw.c      |   42 +----------
 drivers/net/wireless/ath/ath9k/hw.h      |    4 +-
 drivers/net/wireless/ath/ath9k/main.c    |   43 ++++++++++
 drivers/net/wireless/ath/ath9k/recv.c    |    2 +-
 drivers/net/wireless/ath/ath9k/virtual.c |    2 +-
 drivers/net/wireless/ath/hw.c            |  126 ++++++++++++++++++++++++++++++
 drivers/net/wireless/ath/reg.h           |    2 +
 15 files changed, 245 insertions(+), 204 deletions(-)
 create mode 100644 drivers/net/wireless/ath/hw.c
 create mode 100644 drivers/net/wireless/ath/reg.h
#1 lore raw

PATCH 1/4 atheros/ath9k: add common read/write ops and port ath9k to use it

In an effort to make hw code driver core agnostic read and write operations are defined on the ath_common structure. This patch adds that and makes ath9k use it. This allows drivers like ath9k_htc to define its own read/write ops and still rely on the same hw code. This also paves the way for sharing code between ath9k/ath5k/ath9k_htc.

---
 drivers/net/wireless/ath/ath.h         |    6 ++++
 drivers/net/wireless/ath/ath9k/ath9k.h |    3 --
 drivers/net/wireless/ath/ath9k/hw.c    |   32 ------------------------
 drivers/net/wireless/ath/ath9k/hw.h    |    4 +-
 drivers/net/wireless/ath/ath9k/main.c  |   42 ++++++++++++++++++++++++++++++++
 5 files changed, 50 insertions(+), 37 deletions(-)
drivers/net/wireless/ath/ath.h +6 -0
index 7589b2a..91cb43c 100644
@@ -39,6 +39,11 @@ struct ath_regulatory {
 	struct reg_dmn_pair_mapping *regpair;
 };
 
+struct ath_ops {
+	unsigned int (*read)(void *, u32 reg_offset);
+        void (*write)(void *, u32 reg_offset, u32 val);
+};
+
 struct ath_common {
 	u16 cachelsz;
 	u16 curaid;
@@ -46,6 +51,7 @@ struct ath_common {
 	u8 curbssid[ETH_ALEN];
 	u8 bssidmask[ETH_ALEN];
 	struct ath_regulatory regulatory;
+	struct ath_ops *ops;
 };
 
 struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
drivers/net/wireless/ath/ath9k/ath9k.h +0 -3
index 0962505..affc3e5 100644
@@ -718,8 +718,5 @@ bool ath9k_wiphy_scanning(struct ath_softc *sc);
 void ath9k_wiphy_work(struct work_struct *work);
 bool ath9k_all_wiphys_idle(struct ath_softc *sc);
 
-void ath9k_iowrite32(struct ath_hw *ah, u32 reg_offset, u32 val);
-unsigned int ath9k_ioread32(struct ath_hw *ah, u32 reg_offset);
-
 int ath_tx_get_qnum(struct ath_softc *sc, int qtype, int haltype);
 #endif /* ATH9K_H */
drivers/net/wireless/ath/ath9k/hw.c +0 -32
index 5436244..dabff52 100644
@@ -81,38 +81,6 @@ static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
 		return ath9k_hw_mac_clks(ah, usecs);
 }
 
-/*
- * Read and write, they both share the same lock. We do this to serialize
- * reads and writes on Atheros 802.11n PCI devices only. This is required
- * as the FIFO on these devices can only accept sanely 2 requests. After
- * that the device goes bananas. Serializing the reads/writes prevents this
- * from happening.
- */
-
-void ath9k_iowrite32(struct ath_hw *ah, u32 reg_offset, u32 val)
-{
-	if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
-		unsigned long flags;
-		spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
-		iowrite32(val, ah->ah_sc->mem + reg_offset);
-		spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
-	} else
-		iowrite32(val, ah->ah_sc->mem + reg_offset);
-}
-
-unsigned int ath9k_ioread32(struct ath_hw *ah, u32 reg_offset)
-{
-	u32 val;
-	if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
-		unsigned long flags;
-		spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
-		val = ioread32(ah->ah_sc->mem + reg_offset);
-		spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
-	} else
-		val = ioread32(ah->ah_sc->mem + reg_offset);
-	return val;
-}
-
 bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
 {
 	int i;
drivers/net/wireless/ath/ath9k/hw.h +2 -2
index 84deae4..19b1da8 100644
@@ -51,8 +51,8 @@
 #define AT9285_COEX3WIRE_DA_SUBSYSID	0x30ab
 
 /* Register read/write primitives */
-#define REG_WRITE(_ah, _reg, _val) ath9k_iowrite32((_ah), (_reg), (_val))
-#define REG_READ(_ah, _reg) ath9k_ioread32((_ah), (_reg))
+#define REG_WRITE(_ah, _reg, _val) _ah->common.ops->write((_ah), (_reg), (_val))
+#define REG_READ(_ah, _reg) _ah->common.ops->read((_ah), (_reg))
 
 #define SM(_v, _f)  (((_v) << _f##_S) & _f)
 #define MS(_v, _f)  (((_v) & _f) >> _f##_S)
drivers/net/wireless/ath/ath9k/main.c +42 -0

54 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#2 lore raw

PATCH 2/4 ath5k: allocate ath5k_hw prior to initializing hw

In reply to Luis R. Rodriguez

We can propagate better errors upon failed hw initialization, and set up the ath_common structure for attach purposes. This will become important once we start using the ath_common for read/write ops.

---
 drivers/net/wireless/ath/ath5k/ath5k.h  |    2 +-
 drivers/net/wireless/ath/ath5k/attach.c |   23 ++++-------------------
 drivers/net/wireless/ath/ath5k/base.c   |   20 ++++++++++++++++----
 3 files changed, 21 insertions(+), 24 deletions(-)
drivers/net/wireless/ath/ath5k/ath5k.h +1 -1
index fee16fd..29ce868 100644
@@ -1147,7 +1147,7 @@ struct ath5k_hw {
  */
 
 /* Attach/Detach Functions */
-extern struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc);
+extern int ath5k_hw_attach(struct ath5k_softc *sc);
 extern void ath5k_hw_detach(struct ath5k_hw *ah);
 
 /* LED functions */
drivers/net/wireless/ath/ath5k/attach.c +4 -19
index 123612a..c0840ab 100644
@@ -101,28 +101,15 @@ static int ath5k_hw_post(struct ath5k_hw *ah)
  * -ENODEV if the device is not supported or prints an error msg if something
  * else went wrong.
  */
-struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc)
+int ath5k_hw_attach(struct ath5k_softc *sc)
 {
-	struct ath5k_hw *ah;
+	struct ath5k_hw *ah = sc->ah;
 	struct ath_common *common;
 	struct pci_dev *pdev = sc->pdev;
 	struct ath5k_eeprom_info *ee;
 	int ret;
 	u32 srev;
 
-	/*If we passed the test malloc a ath5k_hw struct*/
-	ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
-	if (ah == NULL) {
-		ret = -ENOMEM;
-		ATH5K_ERR(sc, "out of memory\n");
-		goto err;
-	}
-
-	ah->ah_sc = sc;
-	ah->ah_sc->ah = ah;
-	ah->ah_iobase = sc->iobase;
-	common = ath5k_hw_common(ah);
-
 	/*
 	 * HW information
 	 */
@@ -347,11 +334,10 @@ struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc)
 	/* turn on HW LEDs */
 	ath5k_hw_set_ledstate(ah, AR5K_LED_INIT);
 
-	return ah;
+	return 0;
 err_free:
 	kfree(ah);
-err:
-	return ERR_PTR(ret);
+	return ret;
 }
 
 /**
@@ -371,5 +357,4 @@ void ath5k_hw_detach(struct ath5k_hw *ah)
 	ath5k_eeprom_detach(ah);
 
 	/* assume interrupts are down */
-	kfree(ah);
 }
drivers/net/wireless/ath/ath5k/base.c +16 -4
index 06fc893..3cb0752 100644
@@ -565,16 +565,25 @@ ath5k_pci_probe(struct pci_dev *pdev,
 		goto err_free;
 	}
 
-	/* Initialize device */
-	sc->ah = ath5k_hw_attach(sc);
-	if (IS_ERR(sc->ah)) {
-		ret = PTR_ERR(sc->ah);
+	/*If we passed the test malloc a ath5k_hw struct*/
+	sc->ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
+	if (!sc->ah) {
+		ret = -ENOMEM;
+		ATH5K_ERR(sc, "out of memory\n");
 		goto err_irq;
 	}
 
+	sc->ah->ah_sc = sc;
+	sc->ah->ah_iobase = sc->iobase;
 	common = ath5k_hw_common(sc->ah);
 	common->cachelsz = csz << 2; /* convert to bytes */
 
+	/* Initialize device */
+	ret = ath5k_hw_attach(sc);
+	if (ret) {
+		goto err_free_ah;
+	}
+
 	/* set up multi-rate retry capabilities */
 	if (sc->ah->ah_version == AR5K_AR5212) {
 		hw->max_rates = 4;
@@ -643,6 +652,8 @@ err_ah:
 	ath5k_hw_detach(sc->ah);
 err_irq:
 	free_irq(pdev->irq, sc);
+err_free_ah:
+	kfree(sc->ah);
 err_free:
 	ieee80211_free_hw(hw);
 err_map:
@@ -664,6 +675,7 @@ ath5k_pci_remove(struct pci_dev *pdev)
 	ath5k_debug_finish_device(sc);
 	ath5k_detach(pdev, hw);
 	ath5k_hw_detach(sc->ah);
+	kfree(sc->ah);
 	free_irq(pdev->irq, sc);
 	pci_iounmap(pdev, sc->iobase);
 	pci_release_region(pdev, 0);
Signature · 1 line
1.6.3.3
#3 lore raw

PATCH 3/4 ath5k: define ath_common ops

In reply to Luis R. Rodriguez

All read/write ops now go through the common ops.

---
 drivers/net/wireless/ath/ath5k/ath5k.h |   20 ++++++++++++--------
 drivers/net/wireless/ath/ath5k/base.c  |   17 +++++++++++++++++
 drivers/net/wireless/ath/ath5k/base.h  |   11 -----------
 3 files changed, 29 insertions(+), 19 deletions(-)
drivers/net/wireless/ath/ath5k/ath5k.h +12 -8
index 29ce868..997101b 100644
@@ -1315,20 +1315,24 @@ static inline unsigned int ath5k_hw_clocktoh(unsigned int clock, bool turbo)
 	return turbo ? (clock / 80) : (clock / 40);
 }
 
-/*
- * Read from a register
- */
+static inline struct ath_common *ath5k_hw_common(struct ath5k_hw *ah)
+{
+        return &ah->common;
+}
+
+static inline struct ath_regulatory *ath5k_hw_regulatory(struct ath5k_hw *ah)
+{
+        return &(ath5k_hw_common(ah)->regulatory);
+}
+
 static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
 {
-	return ioread32(ah->ah_iobase + reg);
+	return ath5k_hw_common(ah)->ops->read(ah, reg);
 }
 
-/*
- * Write to a register
- */
 static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
 {
-	iowrite32(val, ah->ah_iobase + reg);
+	ath5k_hw_common(ah)->ops->write(ah, reg, val);
 }
 
 #if defined(_ATH5K_RESET) || defined(_ATH5K_PHY)
drivers/net/wireless/ath/ath5k/base.c +17 -0
index 3cb0752..535ea72 100644
@@ -437,6 +437,22 @@ ath5k_chip_name(enum ath5k_srev_type type, u_int16_t val)
 
 	return name;
 }
+static unsigned int ath5k_ioread32(void *hw_priv, u32 reg_offset)
+{
+	struct ath5k_hw *ah = (struct ath5k_hw *) hw_priv;
+	return ioread32(ah->ah_iobase + reg_offset);
+}
+
+static void ath5k_iowrite32(void *hw_priv, u32 reg_offset, u32 val)
+{
+	struct ath5k_hw *ah = (struct ath5k_hw *) hw_priv;
+	iowrite32(val, ah->ah_iobase + reg_offset);
+}
+
+static struct ath_ops ath5k_common_ops = {
+	.read = ath5k_ioread32,
+	.write = ath5k_iowrite32,
+};
 
 static int __devinit
 ath5k_pci_probe(struct pci_dev *pdev,
@@ -576,6 +592,7 @@ ath5k_pci_probe(struct pci_dev *pdev,
 	sc->ah->ah_sc = sc;
 	sc->ah->ah_iobase = sc->iobase;
 	common = ath5k_hw_common(sc->ah);
+	common->ops = &ath5k_common_ops;
 	common->cachelsz = csz << 2; /* convert to bytes */
 
 	/* Initialize device */
drivers/net/wireless/ath/ath5k/base.h +0 -11
index 005d25f..b14ba07 100644
@@ -201,15 +201,4 @@ struct ath5k_softc {
 #define ath5k_hw_hasveol(_ah) \
 	(ath5k_hw_get_capability(_ah, AR5K_CAP_VEOL, 0, NULL) == 0)
 
-static inline struct ath_common *ath5k_hw_common(struct ath5k_hw *ah)
-{
-	return &ah->common;
-}
-
-static inline struct ath_regulatory *ath5k_hw_regulatory(struct ath5k_hw *ah)
-{
-	return &(ath5k_hw_common(ah)->regulatory);
-
-}
-
 #endif
Signature · 1 line
1.6.3.3
#4 lore raw

PATCH 3/4 ath5k: define ath_common ops

Quoted 5 lines · Luis R. Rodriguez

 static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg) {
-       return ioread32(ah->ah_iobase + reg);
+       return ath5k_hw_common(ah)->ops->read(ah, reg); }

Is there any way we can do this without two pointer dereferences for every read and write? I have a feeling this is going to make certain operations (e.g. loading initvals during reset) really suck.

Signature · 1 line
Bob Copeland %% www.bobcopeland.com
#5 lore raw

PATCH 3/4 ath5k: define ath_common ops

Quoted 11 lines · Bob Copeland
Quoted 5 lines · Luis R. Rodriguez

?static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg) ?{
- ? ? ? return ioread32(ah->ah_iobase + reg);
+ ? ? ? return ath5k_hw_common(ah)->ops->read(ah, reg); ?}

Is there any way we can do this without two pointer dereferences for every read and write? ?I have a feeling this is going to make certain operations (e.g. loading initvals during reset) really suck.

It seems to work fine on my box, perhaps a single CPU (real single CPU) user can test to see if there are any differences noted. I don't think there should be really.

In any case if its deemed too nested for ath5k purposes you can just leave an ioread/iowrite on the ath5k_hw_reg_read() and later just move all read/write ops to use the common ops calls. If someone can think of better alternatives I'm all ears.

Luis

maintainer
#6 lore raw

PATCH 3/4 ath5k: define ath_common ops

In reply to Luis R. Rodriguez

2009/9/11 Luis R. Rodriguez <[email protected]>:

Quoted 91 lines

All read/write ops now go through the common ops.

---
 drivers/net/wireless/ath/ath5k/ath5k.h |   20 ++++++++++++-------- drivers/net/wireless/ath/ath5k/base.c  |   17 +++++++++++++++++ drivers/net/wireless/ath/ath5k/base.h  |   11 -----------

 3 files changed, 29 insertions(+), 19 deletions(-)
drivers/net/wireless/ath/ath5k/ath5k.h +12 -8
index 29ce868..997101b 100644
@@ -1315,20 +1315,24 @@ static inline unsigned int ath5k_hw_clocktoh(unsigned int clock, bool turbo)
        return turbo ? (clock / 80) : (clock / 40);
  }
 
-/*
- * Read from a register
- */
+static inline struct ath_common *ath5k_hw_common(struct ath5k_hw *ah)
+{
+        return &ah->common;
+}
+
+static inline struct ath_regulatory *ath5k_hw_regulatory(struct ath5k_hw *ah)
+{
+        return &(ath5k_hw_common(ah)->regulatory);
+}
+
  static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg)
  {
-       return ioread32(ah->ah_iobase + reg);
+       return ath5k_hw_common(ah)->ops->read(ah, reg);
  }
 
-/*
- * Write to a register
- */
  static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
  {
-       iowrite32(val, ah->ah_iobase + reg);
+       ath5k_hw_common(ah)->ops->write(ah, reg, val);
  }
 
  #if defined(_ATH5K_RESET) || defined(_ATH5K_PHY)
drivers/net/wireless/ath/ath5k/base.c +16 -0
index 3cb0752..535ea72 100644
@@ -437,6 +437,22 @@ ath5k_chip_name(enum ath5k_srev_type type, u_int16_t val)
 
        return name;
  }
+static unsigned int ath5k_ioread32(void *hw_priv, u32 reg_offset)
+{
+       struct ath5k_hw *ah = (struct ath5k_hw *) hw_priv;
+       return ioread32(ah->ah_iobase + reg_offset);
+}
+
+static void ath5k_iowrite32(void *hw_priv, u32 reg_offset, u32 val)
+{
+       struct ath5k_hw *ah = (struct ath5k_hw *) hw_priv;
+       iowrite32(val, ah->ah_iobase + reg_offset);
+}
+
+static struct ath_ops ath5k_common_ops = {
+       .read = ath5k_ioread32,
+       .write = ath5k_iowrite32,
+};
 

 static int __devinit
 ath5k_pci_probe(struct pci_dev *pdev,

drivers/net/wireless/ath/ath5k/base.c +1 -0
@@ -576,6 +592,7 @@ ath5k_pci_probe(struct pci_dev *pdev,
        sc->ah->ah_sc = sc;
        sc->ah->ah_iobase = sc->iobase;
        common = ath5k_hw_common(sc->ah);
+       common->ops = &ath5k_common_ops;

       common->cachelsz = csz << 2; /* convert to bytes */

       /* Initialize device */

drivers/net/wireless/ath/ath5k/base.h +0 -2
index 005d25f..b14ba07 100644
@@ -201,15 +201,4 @@ struct ath5k_softc {
  #define ath5k_hw_hasveol(_ah) \
        (ath5k_hw_get_capability(_ah, AR5K_CAP_VEOL, 0, NULL) == 0)
 
-static inline struct ath_common *ath5k_hw_common(struct ath5k_hw *ah)
-{

drivers/net/wireless/ath/ath5k/base.h struct ath5k_softc { · line 204

Quoted 10 lines
drivers/net/wireless/ath/ath5k/base.h +0 -9
-       return &ah->common;
-}
-
-static inline struct ath_regulatory *ath5k_hw_regulatory(struct ath5k_hw *ah)
-{
-       return &(ath5k_hw_common(ah)->regulatory);
-
-}
-
  #endif

Since each driver will use it's own reg read/write functions (ath5k hw code still uses ath5k_hw_reg_read/write), why do we need to have common reg read/write functions like that used in the driver code ? This makes the code more complex that it needs to be and i don't see a reason why we need it. I understand why we need a way to handle read/write functions from common ath code but i don't see a reason to use these functions on ath5k, we can just fill ath_ops struct so that common code can use them and leave ath5k_hw_read/write untouched.

Signature · 3 lines
GPG ID: 0xD21DB2DB
As you read this post global entropy rises. Have Fun ;-)
Nick
#7 lore raw

PATCH 3/4 ath5k: define ath_common ops

Quoted 13 lines · Nick Kossifidis
Quoted 13 lines

static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg) {

drivers/net/wireless/ath/ath5k/ath5k.h +2 -5
-       return ioread32(ah->ah_iobase + reg);
+       return ath5k_hw_common(ah)->ops->read(ah, reg);
 }
 
-/*
- * Write to a register
- */
 static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg)
 {
-       iowrite32(val, ah->ah_iobase + reg);
+       ath5k_hw_common(ah)->ops->write(ah, reg, val);

...

Quoted 8 lines

Since each driver will use it's own reg read/write functions (ath5k hw code still uses ath5k_hw_reg_read/write), why do we need to have common reg read/write functions like that used in the driver code ? This makes the code more complex that it needs to be and i don't see a reason why we need it. I understand why we need a way to handle read/write functions from common ath code but i don't see a reason to use these functions on ath5k, we can just fill ath_ops struct so that common code can use them and leave ath5k_hw_read/write untouched.

I definitely agree with Nick here. Althought whole ath_ops will be hot cache after the first operation, there is no need to prolong hot paths by computing the op address and a call. Ok, read/write on PCI is pretty slow, but still...

#8 lore raw

PATCH 3/4 ath5k: define ath_common ops

Quoted 24 lines · Jiri Slaby
Quoted 13 lines · Nick Kossifidis
Quoted 13 lines

?static inline u32 ath5k_hw_reg_read(struct ath5k_hw *ah, u16 reg) ?{
- ? ? ? return ioread32(ah->ah_iobase + reg);
+ ? ? ? return ath5k_hw_common(ah)->ops->read(ah, reg); ?}

-/*
- * Write to a register
- */
?static inline void ath5k_hw_reg_write(struct ath5k_hw *ah, u32 val, u16 reg) ?{
- ? ? ? iowrite32(val, ah->ah_iobase + reg);
+ ? ? ? ath5k_hw_common(ah)->ops->write(ah, reg, val);

...

Quoted 8 lines

Since each driver will use it's own reg read/write functions (ath5k hw code still uses ath5k_hw_reg_read/write), why do we need to have common reg read/write functions like that used in the driver code ? This makes the code more complex that it needs to be and i don't see a reason why we need it. I understand why we need a way to handle read/write functions from common ath code but i don't see a reason to use these functions on ath5k, we can just fill ath_ops struct so that common code can use them and leave ath5k_hw_read/write untouched.

Quoted 4 lines

I definitely agree with Nick here. Althought whole ath_ops will be hot cache after the first operation, there is no need to prolong hot paths by computing the op address and a call. Ok, read/write on PCI is pretty slow, but still...

That is the way I had it originally before submission, and I completely agree its reasonable to not incur additional cost at the expense of having two separate read/write paths, and perhaps we should only incur the extra cost on routines shared between ath9k/ath9k/ath9k_htc. But -- is there really is a measurable cost penalty?

This is why I asked if someone can test and give measurable differences over this. If there really isn't then that's not strong point against it.

For example, long ago I had argued over the cost incurred over the unnecessary branching on ioread()/iowrite() when you know you have MMIO devices [1] -- the defense then, and IMHO reasonable now, was that the benefits of allowing cleaner drivers through the new interfaces outweigh the theoretical penalties imposed by them.

Granted you can argue these new interfaces between ath5k/ath9k/ath9k_htc would make things a little more complex, but I would expect sharing the code will help in the end. And if these interfaces are not acceptable I'm completely open to better suggested alternatives.

[1] http://lkml.indiana.edu/hypermail/linux/kernel/0709.2/1068.html

Luis

#9 lore raw

PATCH 3/4 ath5k: define ath_common ops

Quoted 6 lines · Luis R. Rodriguez

ath9k/ath9k/ath9k_htc. But -- is there really is a measurable cost penalty?

This is why I asked if someone can test and give measurable differences over this. If there really isn't then that's not strong point against it.

Honestly, it probably won't matter in the grand scheme of things, but I think if you are proposing a patch that touches every hotpath in two drivers, then you need to do the work to say "by the way, this has benefit X which outweighs the very small (or absent) performance regression Y, and here are the numbers.

Signature · 1 line
Bob Copeland %% www.bobcopeland.com
#10 lore raw

PATCH 3/4 ath5k: define ath_common ops

Quoted 9 lines · Bob Copeland
Quoted 6 lines · Luis R. Rodriguez

ath9k/ath9k/ath9k_htc. But -- is there really is a measurable cost penalty?

This is why I asked if someone can test and give measurable differences over this. If there really isn't then that's not strong point against it.

Quoted 5 lines

Honestly, it probably won't matter in the grand scheme of things, but I think if you are proposing a patch that touches every hotpath in two drivers, then you need to do the work to say "by the way, this has benefit X which outweighs the very small (or absent) performance regression Y, and here are the numbers.

You're completely right, sorry about that. I thought the advantages would have been obvious but let me clarify them them:

So far I've tested this with:

time iw list dev wlan0 scan > /dev/null

Both with and without the patches and the time it takes to scan, when not associated, remains the same. Granted I do have an Intel Core Duo 1.8 GHz, so if some others could test this on some embedded platforms that would be appreciated.

The main added advantage to these changes is the possibility to now share hw access code between ath5k/ath9k. With the patches as-is you get one hot path on the driver, whether or not you use common hw code through ath.ko or through the driver's own hw code. It is unclear to me whether this has any measurable benefits so an alternative is to only use the common read/write ops on the common ath.ko.

Although I don't see any measurable differences at the moment I suspect most people are inclined to leave hw access directly on the driver and only use common hw read/write ops for the common code. I'll respin these patches to do just that.

Luis

#11 lore raw

PATCH 3/4 ath5k: define ath_common ops

In reply to Luis R. Rodriguez
Quoted 7 lines · Luis R. Rodriguez

That is the way I had it originally before submission, and I completely agree its reasonable to not incur additional cost at the expense of having two separate read/write paths, and perhaps we should only incur the extra cost on routines shared between ath9k/ath9k/ath9k_htc. But -- is there really is a measurable cost penalty?

There's a measurable size penalty, at least.

In fact, if you know what kind of IO op it is (ie "it's always MMIO"), you'd be even better using "writel()" directly, in which case it turns into just a single store on most architectures, and doesn't cause all the register save/restore of a function call.

Linus

#12 lore raw

PATCH 3/4 ath5k: define ath_common ops

Quoted 4 lines · Linus Torvalds
Quoted 1 line · Luis R. Rodriguez
Quoted 8 lines
Quoted 6 lines

That is the way I had it originally before submission, and I completely agree its reasonable to not incur additional cost at the expense of having two separate read/write paths, and perhaps we should only incur the extra cost on routines shared between ath9k/ath9k/ath9k_htc. But -- is there really is a measurable cost penalty?

There's a measurable size penalty, at least.

My tests so far yield no performance difference but I'm sure there is some, maybe as Jouni noted, more visible on embedded systems.

Quoted 2 lines

In fact, if you know what kind of IO op it is (ie "it's always MMIO"), you'd be even better using "writel()" directly,

Heh.. you realize I tried to document such a thing a while ago and it seems you opposed it [1]?

[1] http://lkml.indiana.edu/hypermail/linux/kernel/0709.2/0593.html

Luis

#13 lore raw

PATCH 3/4 ath5k: define ath_common ops

Quoted 6 lines · Luis R. Rodriguez
Quoted 3 lines

In fact, if you know what kind of IO op it is (ie "it's always MMIO"), you'd be even better using "writel()" directly,

Heh.. you realize I tried to document such a thing a while ago and it seems you opposed it [1]?

If it's mapped with "pci_iomap()" you should use ioread*/iowrite*.

But if you know it's always MMIO, and you use just ioremap() to map it, and then readl/writel.

It's the _mixing_ of the two that I object to:
- pci_iomap() - can do either MMIO of PIO
- readl/writel - always just MMIO
should preferably not be mixed.

(Sure it will _work_, but I wouldn't encourage it)

Linus

#14 lore raw

PATCH 3/4 ath5k: define ath_common ops

In reply to Luis R. Rodriguez
Quoted 6 lines · Luis R. Rodriguez
Quoted 4 lines · Jiri Slaby

I definitely agree with Nick here. Althought whole ath_ops will be hot cache after the first operation, there is no need to prolong hot paths by computing the op address and a call. Ok, read/write on PCI is pretty slow, but still...

Quoted 6 lines

That is the way I had it originally before submission, and I completely agree its reasonable to not incur additional cost at the expense of having two separate read/write paths, and perhaps we should only incur the extra cost on routines shared between ath9k/ath9k/ath9k_htc. But -- is there really is a measurable cost penalty?

Hardly there is a measurable one. As I wrote earlier one will wait ages for PCI in comparison to few load+call cycles.

Quoted 3 lines

This is why I asked if someone can test and give measurable differences over this. If there really isn't then that's not strong point against it.

Well, honestly I see no strong point for it. It rather looks like an obfuscation, not improvement.

Quoted 5 lines

For example, long ago I had argued over the cost incurred over the unnecessary branching on ioread()/iowrite() when you know you have MMIO devices [1] -- the defense then, and IMHO reasonable now, was that the benefits of allowing cleaner drivers through the new interfaces outweigh the theoretical penalties imposed by them.

Ok, that one has benefits. You just needn't care about what is behind that mapping. It will choose a PIO or MMIO op on its own.

When it's always MMIO I personally prefer simple ioremap though. (I didn't at the time of merging the driver.)

Quoted 5 lines

Granted you can argue these new interfaces between ath5k/ath9k/ath9k_htc would make things a little more complex, but I would expect sharing the code will help in the end. And if these interfaces are not acceptable I'm completely open to better suggested alternatives.

Ok, I think nothing more than this is needed:
+static u32 ath5k_ioread32(void *hw_priv, u32 reg_offset) +{
+ return ath5k_hw_reg_read(hw_priv, reg_offset)
+}
+
+static void ath5k_iowrite32(void *hw_priv, u32 reg_offset, u32 val) +{
+ ath5k_hw_reg_write(hw_priv, val, reg_offset);
+}
+
+static struct ath_ops ath5k_common_ops = {
+ .read = ath5k_ioread32,
+ .write = ath5k_iowrite32,
+};

What I wonder is why ath_ops has reg+val parameters in the opposite manner than the rest of kernel? It is error-prone.

#15 lore raw

PATCH 3/4 ath5k: define ath_common ops

Quoted 14 lines · Jiri Slaby
Quoted 6 lines · Luis R. Rodriguez
Quoted 4 lines · Jiri Slaby

I definitely agree with Nick here. Althought whole ath_ops will be hot cache after the first operation, there is no need to prolong hot paths by computing the op address and a call. Ok, read/write on PCI is pretty slow, but still...

Quoted 6 lines

That is the way I had it originally before submission, and I completely agree its reasonable to not incur additional cost at the expense of having two separate read/write paths, and perhaps we should only incur the extra cost on routines shared between ath9k/ath9k/ath9k_htc. But -- is there really is a measurable cost penalty?

Quoted 2 lines

Hardly there is a measurable one. As I wrote earlier one will wait ages for PCI in comparison to few load+call cycles.

Alright, this helps.

Quoted 6 lines
Quoted 3 lines

This is why I asked if someone can test and give measurable differences over this. If there really isn't then that's not strong point against it.

Well, honestly I see no strong point for it. It rather looks like an obfuscation, not improvement.

It may be and for ath5k this is not a requirement, for ath9k however we do need a way to share hw code and therefore we cannot keep read/write ops as part of hw.c but more importantly we need something to map READ_READ/REG_WRITE macros on hw.h which will work for both ath9k and ath9k_htc.

Quoted 11 lines
Quoted 5 lines

Granted you can argue these new interfaces between ath5k/ath9k/ath9k_htc would make things a little more complex, but I would expect sharing the code will help in the end. And if these interfaces are not acceptable I'm completely open to better suggested alternatives.

Ok, I think nothing more than this is needed:

drivers/net/wireless/ath/ath5k/base.c +4 -0
+static u32 ath5k_ioread32(void *hw_priv, u32 reg_offset)
+{
+ ? ? ? return ath5k_hw_reg_read(hw_priv, reg_offset)
+}

drivers/net/wireless/ath/ath5k/base.c ath5k_chip_name(enum ath5k_srev_type type, u_int16_t val) · line 455

Quoted 10 lines
drivers/net/wireless/ath/ath5k/base.c +10 -0
+
+static void ath5k_iowrite32(void *hw_priv, u32 reg_offset, u32 val)
+{
+ ? ? ? ath5k_hw_reg_write(hw_priv, val, reg_offset);
+}
+
+static struct ath_ops ath5k_common_ops = {
+ ? ? ? .read = ath5k_ioread32,
+ ? ? ? .write = ath5k_iowrite32,
+};

That's fine for ath5k.

Quoted 2 lines

What I wonder is why ath_ops has reg+val parameters in the opposite manner than the rest of kernel? It is error-prone.

Heh, yeah, that's just how the Atheros hw code was written, so I'll change the common ops to match standard practice but don't want to change the all the REG_READ/REG_WRITE macros, so ath9k stuff will just do the flip.

Luis

#16 lore raw

PATCH 4/4 atheros: define shared bssidmask setting

In reply to Luis R. Rodriguez
---
 drivers/net/wireless/ath/Makefile        |    5 +-
 drivers/net/wireless/ath/ath.h           |    3 +
 drivers/net/wireless/ath/ath5k/ath5k.h   |    2 +-
 drivers/net/wireless/ath/ath5k/attach.c  |    2 +-
 drivers/net/wireless/ath/ath5k/base.c    |    1 +
 drivers/net/wireless/ath/ath5k/pcu.c     |  113 +--------------------------
 drivers/net/wireless/ath/ath9k/hw.c      |   10 +--
 drivers/net/wireless/ath/ath9k/main.c    |    1 +
 drivers/net/wireless/ath/ath9k/recv.c    |    2 +-
 drivers/net/wireless/ath/ath9k/virtual.c |    2 +-
 drivers/net/wireless/ath/hw.c            |  126 ++++++++++++++++++++++++++++++
 drivers/net/wireless/ath/reg.h           |    2 +
 12 files changed, 145 insertions(+), 124 deletions(-)
 create mode 100644 drivers/net/wireless/ath/hw.c
 create mode 100644 drivers/net/wireless/ath/reg.h
drivers/net/wireless/ath/Makefile +4 -1
index 4bb0132..6ebf214 100644
@@ -3,4 +3,7 @@ obj-$(CONFIG_ATH9K)		+= ath9k/
 obj-$(CONFIG_AR9170_USB)        += ar9170/
 
 obj-$(CONFIG_ATH_COMMON)	+= ath.o
-ath-objs 		:= main.o regd.o
+
+ath-objs :=	main.o \
+		regd.o \
+		hw.o
drivers/net/wireless/ath/ath.h +3 -0
index 91cb43c..1d022a3 100644
@@ -45,6 +45,7 @@ struct ath_ops {
 };
 
 struct ath_common {
+	void *ah;
 	u16 cachelsz;
 	u16 curaid;
 	u8 macaddr[ETH_ALEN];
@@ -58,4 +59,6 @@ struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
 				u32 len,
 				gfp_t gfp_mask);
 
+void ath_hw_setbssidmask(struct ath_common *common);
+
 #endif /* ATH_H */
drivers/net/wireless/ath/ath5k/ath5k.h +1 -1
index 997101b..cc116c7 100644
@@ -1192,7 +1192,7 @@ extern int ath5k_hw_set_opmode(struct ath5k_hw *ah);
 /* BSSID Functions */
 extern int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac);
 extern void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id);
-extern int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask);
+extern void ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask);
 /* Receive start/stop functions */
 extern void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah);
 extern void ath5k_hw_stop_rx_pcu(struct ath5k_hw *ah);
drivers/net/wireless/ath/ath5k/attach.c +1 -1
index c0840ab..e230de8 100644
@@ -104,7 +104,7 @@ static int ath5k_hw_post(struct ath5k_hw *ah)
 int ath5k_hw_attach(struct ath5k_softc *sc)
 {
 	struct ath5k_hw *ah = sc->ah;
-	struct ath_common *common;
+	struct ath_common *common = ath5k_hw_common(ah);
 	struct pci_dev *pdev = sc->pdev;
 	struct ath5k_eeprom_info *ee;
 	int ret;
drivers/net/wireless/ath/ath5k/base.c +1 -0
index 535ea72..02e1ce6 100644
@@ -593,6 +593,7 @@ ath5k_pci_probe(struct pci_dev *pdev,
 	sc->ah->ah_iobase = sc->iobase;
 	common = ath5k_hw_common(sc->ah);
 	common->ops = &ath5k_common_ops;
+	common->ah = sc->ah;
 	common->cachelsz = csz << 2; /* convert to bytes */
 
 	/* Initialize device */
drivers/net/wireless/ath/ath5k/pcu.c +3 -110

128 lines not on this page · raw message

drivers/net/wireless/ath/ath9k/hw.c +1 -9
index dabff52..80bfa18 100644
@@ -2423,7 +2423,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
 		  | ah->sta_id1_defaults);
 	ath9k_hw_set_operating_mode(ah, ah->opmode);
 
-	ath9k_hw_setbssidmask(ah);
+	ath_hw_setbssidmask(common);
 
 	REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
 
@@ -3950,14 +3950,6 @@ void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
 	REG_WRITE(ah, AR_MCAST_FIL1, filter1);
 }
 
-void ath9k_hw_setbssidmask(struct ath_hw *ah)
-{
-	struct ath_common *common = ath9k_hw_common(ah);
-
-	REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(common->bssidmask));
-	REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(common->bssidmask + 4));
-}
-
 void ath9k_hw_write_associd(struct ath_hw *ah)
 {
 	struct ath_common *common = ath9k_hw_common(ah);
drivers/net/wireless/ath/ath9k/main.c +1 -0
index 5f8a18a..9a8c9ce 100644
@@ -1574,6 +1574,7 @@ static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid)
 
 	common = ath9k_hw_common(ah);
 	common->ops = &ath9k_common_ops;
+	common->ah = ah;
 
 	/*
 	 * Cache line size is used to size and align various
drivers/net/wireless/ath/ath9k/recv.c +1 -1
index 97a5efe..fb635a0 100644
@@ -282,7 +282,7 @@ static void ath_opmode_init(struct ath_softc *sc)
 
 	/* configure bssid mask */
 	if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
-		ath9k_hw_setbssidmask(ah);
+		ath_hw_setbssidmask(common);
 
 	/* configure operational mode */
 	ath9k_hw_setopmode(ah);
drivers/net/wireless/ath/ath9k/virtual.c +1 -1
index 7b763b6..bc7d173 100644
@@ -94,7 +94,7 @@ void ath9k_set_bssid_mask(struct ieee80211_hw *hw)
 	common->bssidmask[4] = ~mask[4];
 	common->bssidmask[5] = ~mask[5];
 
-	ath9k_hw_setbssidmask(sc->sc_ah);
+	ath_hw_setbssidmask(common);
 }
 
 int ath9k_wiphy_add(struct ath_softc *sc)
drivers/net/wireless/ath/hw.c new file +126 -0

126 lines not on this page · raw message

drivers/net/wireless/ath/reg.h new file +2 -0
new file mode 100644
index 0000000..70453f6
@@ -0,0 +1,2 @@
+#define AR_BSSMSKL		0x80e0
+#define AR_BSSMSKU		0x80e4
Signature · 1 line
1.6.3.3