linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs
@ 2009-01-07 10:09 Gabor Juhos
  2009-01-07 10:09 ` [PATCH 01/11] ath9k: convert to struct device Gabor Juhos
                   ` (10 more replies)
  0 siblings, 11 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 10:09 UTC (permalink / raw)
  To: John W. Linville
  Cc: Luis R. Rodriguez, Jouni Malinen, ath9k-devel@lists.ath9k.org,
	linux-wireless@vger.kernel.org, Felix Fietkau, Christoph Hellwig,
	Sujith Manoharan, Gabor Juhos

This patch set introduces preliminary support for the Atheros' AR9130/AR9132
SoCs built-in WMAC device. Tested with compat-wireless-2009-01-07 and 2.6.27.10 
kernel on the following devices:
  * Atheros AP83-050 reference board (AR9132 SoC, AR9103 RF)
  * TRENDnet TEW-632BRP router (AR9130 SoC, AR9102 RF)
  * Mikrotik RB433 board (AR7161 SoC) + AR5416 based miniPCI card

Changes since RFC:
  * bus specific DMA routines removed
  * bus specific register access routines removed
  * irq value is stored in softc
  * rebased against master-2009-01-06 of wireless-testing
  
11 patches will follow as replies:

Gabor Juhos (11):
      ath9k: convert to struct device
      ath9k: convert to use bus-agnostic DMA routines
      ath9k: introduce bus specific cache size routine
      ath9k: introduce bus specific cleanup routine
      ath9k: move PCI code into separate file
      ath9k: introduce platform driver for AHB bus support
      ath9k: get EEPROM contents from platform data on AHB bus
      ath9k: enable support for AR9100
      ath9k: remove (u16) casts from rtc register access
      ath9k: fix ar5416Addac_9100 values
      ath9k: fix null pointer dereference in ani monitor code

 drivers/net/wireless/ath9k/Makefile   |    2 
 drivers/net/wireless/ath9k/ahb.c      |  206 +++++++++++++++++++++
 drivers/net/wireless/ath9k/ani.c      |    6 -
 drivers/net/wireless/ath9k/beacon.c   |   28 +--
 drivers/net/wireless/ath9k/core.h     |   46 +++++
 drivers/net/wireless/ath9k/eeprom.c   |   51 -----
 drivers/net/wireless/ath9k/hw.c       |   17 +-
 drivers/net/wireless/ath9k/initvals.h |    2 
 drivers/net/wireless/ath9k/main.c     |  318 ++++-----------------------------
 drivers/net/wireless/ath9k/pci.c      |  307 ++++++++++++++++++++++++++++++++
 drivers/net/wireless/ath9k/recv.c     |   24 +-
 drivers/net/wireless/ath9k/xmit.c     |   14 +
 include/linux/ath9k_platform.h        |   28 +++
 13 files changed, 675 insertions(+), 374 deletions(-)
 create mode 100644 drivers/net/wireless/ath9k/ahb.c
 create mode 100644 drivers/net/wireless/ath9k/pci.c
 create mode 100644 include/linux/ath9k_platform.h

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 01/11] ath9k: convert to struct device
  2009-01-07 10:09 [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs Gabor Juhos
@ 2009-01-07 10:09 ` Gabor Juhos
  2009-01-07 10:09 ` [PATCH 02/11] ath9k: convert to use bus-agnostic DMA routines Gabor Juhos
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 10:09 UTC (permalink / raw)
  To: John W. Linville
  Cc: Luis R. Rodriguez, Jouni Malinen, ath9k-devel@lists.ath9k.org,
	linux-wireless@vger.kernel.org, Felix Fietkau, Christoph Hellwig,
	Sujith Manoharan, Gabor Juhos, Imre Kaloz

Convert 'struct pci_dev' to 'struct device' to make it usable on the AHB
bus as well.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
 drivers/net/wireless/ath9k/beacon.c |   17 ++++++++++-------
 drivers/net/wireless/ath9k/core.h   |    2 +-
 drivers/net/wireless/ath9k/main.c   |   21 +++++++++++----------
 drivers/net/wireless/ath9k/recv.c   |   15 +++++++++------
 drivers/net/wireless/ath9k/xmit.c   |    7 ++++---
 5 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/drivers/net/wireless/ath9k/beacon.c b/drivers/net/wireless/ath9k/beacon.c
index 3ab0b43..f02b099 100644
--- a/drivers/net/wireless/ath9k/beacon.c
+++ b/drivers/net/wireless/ath9k/beacon.c
@@ -164,7 +164,7 @@ static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id)
 	bf = avp->av_bcbuf;
 	skb = (struct sk_buff *)bf->bf_mpdu;
 	if (skb) {
-		pci_unmap_single(sc->pdev, bf->bf_dmacontext,
+		pci_unmap_single(to_pci_dev(sc->dev), bf->bf_dmacontext,
 				 skb->len,
 				 PCI_DMA_TODEVICE);
 		dev_kfree_skb_any(skb);
@@ -188,10 +188,11 @@ static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id)
 	}
 
 	bf->bf_buf_addr = bf->bf_dmacontext =
-		pci_map_single(sc->pdev, skb->data,
+		pci_map_single(to_pci_dev(sc->dev), skb->data,
 			       skb->len,
 			       PCI_DMA_TODEVICE);
-	if (unlikely(pci_dma_mapping_error(sc->pdev, bf->bf_buf_addr))) {
+	if (unlikely(pci_dma_mapping_error(to_pci_dev(sc->dev),
+					   bf->bf_buf_addr))) {
 		dev_kfree_skb_any(skb);
 		bf->bf_mpdu = NULL;
 		DPRINTF(sc, ATH_DBG_CONFIG,
@@ -343,7 +344,7 @@ int ath_beacon_alloc(struct ath_softc *sc, int if_id)
 	bf = avp->av_bcbuf;
 	if (bf->bf_mpdu != NULL) {
 		skb = (struct sk_buff *)bf->bf_mpdu;
-		pci_unmap_single(sc->pdev, bf->bf_dmacontext,
+		pci_unmap_single(to_pci_dev(sc->dev), bf->bf_dmacontext,
 				 skb->len,
 				 PCI_DMA_TODEVICE);
 		dev_kfree_skb_any(skb);
@@ -402,10 +403,11 @@ int ath_beacon_alloc(struct ath_softc *sc, int if_id)
 
 	bf->bf_mpdu = skb;
 	bf->bf_buf_addr = bf->bf_dmacontext =
-		pci_map_single(sc->pdev, skb->data,
+		pci_map_single(to_pci_dev(sc->dev), skb->data,
 			       skb->len,
 			       PCI_DMA_TODEVICE);
-	if (unlikely(pci_dma_mapping_error(sc->pdev, bf->bf_buf_addr))) {
+	if (unlikely(pci_dma_mapping_error(to_pci_dev(sc->dev),
+					   bf->bf_buf_addr))) {
 		dev_kfree_skb_any(skb);
 		bf->bf_mpdu = NULL;
 		DPRINTF(sc, ATH_DBG_CONFIG,
@@ -429,7 +431,8 @@ void ath_beacon_return(struct ath_softc *sc, struct ath_vap *avp)
 		bf = avp->av_bcbuf;
 		if (bf->bf_mpdu != NULL) {
 			struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
-			pci_unmap_single(sc->pdev, bf->bf_dmacontext,
+			pci_unmap_single(to_pci_dev(sc->dev),
+					 bf->bf_dmacontext,
 					 skb->len,
 					 PCI_DMA_TODEVICE);
 			dev_kfree_skb_any(skb);
diff --git a/drivers/net/wireless/ath9k/core.h b/drivers/net/wireless/ath9k/core.h
index 2bb35dd..2256ba4 100644
--- a/drivers/net/wireless/ath9k/core.h
+++ b/drivers/net/wireless/ath9k/core.h
@@ -695,7 +695,7 @@ enum PROT_MODE {
 
 struct ath_softc {
 	struct ieee80211_hw *hw;
-	struct pci_dev *pdev;
+	struct device *dev;
 	struct tasklet_struct intr_tq;
 	struct tasklet_struct bcon_tasklet;
 	struct ath_hal *sc_ah;
diff --git a/drivers/net/wireless/ath9k/main.c b/drivers/net/wireless/ath9k/main.c
index f590fce..3313459 100644
--- a/drivers/net/wireless/ath9k/main.c
+++ b/drivers/net/wireless/ath9k/main.c
@@ -46,7 +46,8 @@ static void bus_read_cachesize(struct ath_softc *sc, int *csz)
 {
 	u8 u8tmp;
 
-	pci_read_config_byte(sc->pdev, PCI_CACHE_LINE_SIZE, (u8 *)&u8tmp);
+	pci_read_config_byte(to_pci_dev(sc->dev), PCI_CACHE_LINE_SIZE,
+			     (u8 *)&u8tmp);
 	*csz = (int)u8tmp;
 
 	/*
@@ -1267,11 +1268,11 @@ static int ath_start_rfkill_poll(struct ath_softc *sc)
 
 			/* Deinitialize the device */
 			ath_detach(sc);
-			if (sc->pdev->irq)
-				free_irq(sc->pdev->irq, sc);
-			pci_iounmap(sc->pdev, sc->mem);
-			pci_release_region(sc->pdev, 0);
-			pci_disable_device(sc->pdev);
+			if (to_pci_dev(sc->dev)->irq)
+				free_irq(to_pci_dev(sc->dev)->irq, sc);
+			pci_iounmap(to_pci_dev(sc->dev), sc->mem);
+			pci_release_region(to_pci_dev(sc->dev), 0);
+			pci_disable_device(to_pci_dev(sc->dev));
 			ieee80211_free_hw(sc->hw);
 			return -EIO;
 		} else {
@@ -1708,7 +1709,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
 	}
 
 	/* allocate descriptors */
-	dd->dd_desc = pci_alloc_consistent(sc->pdev,
+	dd->dd_desc = pci_alloc_consistent(to_pci_dev(sc->dev),
 			      dd->dd_desc_len,
 			      &dd->dd_desc_paddr);
 	if (dd->dd_desc == NULL) {
@@ -1756,7 +1757,7 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
 	}
 	return 0;
 fail2:
-	pci_free_consistent(sc->pdev,
+	pci_free_consistent(to_pci_dev(sc->dev),
 		dd->dd_desc_len, dd->dd_desc, dd->dd_desc_paddr);
 fail:
 	memset(dd, 0, sizeof(*dd));
@@ -1770,7 +1771,7 @@ void ath_descdma_cleanup(struct ath_softc *sc,
 			 struct ath_descdma *dd,
 			 struct list_head *head)
 {
-	pci_free_consistent(sc->pdev,
+	pci_free_consistent(to_pci_dev(sc->dev),
 		dd->dd_desc_len, dd->dd_desc, dd->dd_desc_paddr);
 
 	INIT_LIST_HEAD(head);
@@ -2615,7 +2616,7 @@ static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	sc = hw->priv;
 	sc->hw = hw;
-	sc->pdev = pdev;
+	sc->dev = &pdev->dev;
 	sc->mem = mem;
 
 	if (ath_attach(id->device, sc) != 0) {
diff --git a/drivers/net/wireless/ath9k/recv.c b/drivers/net/wireless/ath9k/recv.c
index 462e08c..d7774d1 100644
--- a/drivers/net/wireless/ath9k/recv.c
+++ b/drivers/net/wireless/ath9k/recv.c
@@ -291,10 +291,11 @@ int ath_rx_init(struct ath_softc *sc, int nbufs)
 			}
 
 			bf->bf_mpdu = skb;
-			bf->bf_buf_addr = pci_map_single(sc->pdev, skb->data,
+			bf->bf_buf_addr = pci_map_single(to_pci_dev(sc->dev),
+							 skb->data,
 							 sc->rx.bufsize,
 							 PCI_DMA_FROMDEVICE);
-			if (unlikely(pci_dma_mapping_error(sc->pdev,
+			if (unlikely(pci_dma_mapping_error(to_pci_dev(sc->dev),
 				  bf->bf_buf_addr))) {
 				dev_kfree_skb_any(skb);
 				bf->bf_mpdu = NULL;
@@ -524,7 +525,8 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush)
 		 * 1. accessing the frame
 		 * 2. requeueing the same buffer to h/w
 		 */
-		pci_dma_sync_single_for_cpu(sc->pdev, bf->bf_buf_addr,
+		pci_dma_sync_single_for_cpu(to_pci_dev(sc->dev),
+				bf->bf_buf_addr,
 				sc->rx.bufsize,
 				PCI_DMA_FROMDEVICE);
 
@@ -557,7 +559,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush)
 			goto requeue;
 
 		/* Unmap the frame */
-		pci_unmap_single(sc->pdev, bf->bf_buf_addr,
+		pci_unmap_single(to_pci_dev(sc->dev), bf->bf_buf_addr,
 				 sc->rx.bufsize,
 				 PCI_DMA_FROMDEVICE);
 
@@ -599,10 +601,11 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush)
 
 		/* We will now give hardware our shiny new allocated skb */
 		bf->bf_mpdu = requeue_skb;
-		bf->bf_buf_addr = pci_map_single(sc->pdev, requeue_skb->data,
+		bf->bf_buf_addr = pci_map_single(to_pci_dev(sc->dev),
+					 requeue_skb->data,
 					 sc->rx.bufsize,
 					 PCI_DMA_FROMDEVICE);
-		if (unlikely(pci_dma_mapping_error(sc->pdev,
+		if (unlikely(pci_dma_mapping_error(to_pci_dev(sc->dev),
 			  bf->bf_buf_addr))) {
 			dev_kfree_skb_any(requeue_skb);
 			bf->bf_mpdu = NULL;
diff --git a/drivers/net/wireless/ath9k/xmit.c b/drivers/net/wireless/ath9k/xmit.c
index 9e910f7..27cb9d5 100644
--- a/drivers/net/wireless/ath9k/xmit.c
+++ b/drivers/net/wireless/ath9k/xmit.c
@@ -340,7 +340,7 @@ static void ath_tx_complete_buf(struct ath_softc *sc,
 	}
 
 	/* Unmap this frame */
-	pci_unmap_single(sc->pdev,
+	pci_unmap_single(to_pci_dev(sc->dev),
 			 bf->bf_dmacontext,
 			 skb->len,
 			 PCI_DMA_TODEVICE);
@@ -1716,9 +1716,10 @@ static int ath_tx_setup_buffer(struct ath_softc *sc, struct ath_buf *bf,
 	/* DMA setup */
 	bf->bf_mpdu = skb;
 
-	bf->bf_dmacontext = pci_map_single(sc->pdev, skb->data,
+	bf->bf_dmacontext = pci_map_single(to_pci_dev(sc->dev), skb->data,
 					   skb->len, PCI_DMA_TODEVICE);
-	if (unlikely(pci_dma_mapping_error(sc->pdev, bf->bf_dmacontext))) {
+	if (unlikely(pci_dma_mapping_error(to_pci_dev(sc->dev),
+					   bf->bf_dmacontext))) {
 		bf->bf_mpdu = NULL;
 		DPRINTF(sc, ATH_DBG_CONFIG,
 			"pci_dma_mapping_error() on TX\n");
-- 
1.5.3.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 02/11] ath9k: convert to use bus-agnostic DMA routines
  2009-01-07 10:09 [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs Gabor Juhos
  2009-01-07 10:09 ` [PATCH 01/11] ath9k: convert to struct device Gabor Juhos
@ 2009-01-07 10:09 ` Gabor Juhos
  2009-01-07 10:09 ` [PATCH 03/11] ath9k: introduce bus specific cache size routine Gabor Juhos
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 10:09 UTC (permalink / raw)
  To: John W. Linville
  Cc: Luis R. Rodriguez, Jouni Malinen, ath9k-devel@lists.ath9k.org,
	linux-wireless@vger.kernel.org, Felix Fietkau, Christoph Hellwig,
	Sujith Manoharan, Gabor Juhos, Imre Kaloz

Convert to use bus-agnostic DMA routines to make it usable on AHB bus as well.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
 drivers/net/wireless/ath9k/beacon.c |   31 ++++++++++++++-----------------
 drivers/net/wireless/ath9k/main.c   |   13 ++++++-------
 drivers/net/wireless/ath9k/recv.c   |   27 ++++++++++++---------------
 drivers/net/wireless/ath9k/xmit.c   |   15 ++++++---------
 4 files changed, 38 insertions(+), 48 deletions(-)

diff --git a/drivers/net/wireless/ath9k/beacon.c b/drivers/net/wireless/ath9k/beacon.c
index f02b099..be1d84a 100644
--- a/drivers/net/wireless/ath9k/beacon.c
+++ b/drivers/net/wireless/ath9k/beacon.c
@@ -164,9 +164,9 @@ static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id)
 	bf = avp->av_bcbuf;
 	skb = (struct sk_buff *)bf->bf_mpdu;
 	if (skb) {
-		pci_unmap_single(to_pci_dev(sc->dev), bf->bf_dmacontext,
+		dma_unmap_single(sc->dev, bf->bf_dmacontext,
 				 skb->len,
-				 PCI_DMA_TODEVICE);
+				 DMA_TO_DEVICE);
 		dev_kfree_skb_any(skb);
 	}
 
@@ -188,15 +188,14 @@ static struct ath_buf *ath_beacon_generate(struct ath_softc *sc, int if_id)
 	}
 
 	bf->bf_buf_addr = bf->bf_dmacontext =
-		pci_map_single(to_pci_dev(sc->dev), skb->data,
+		dma_map_single(sc->dev, skb->data,
 			       skb->len,
-			       PCI_DMA_TODEVICE);
-	if (unlikely(pci_dma_mapping_error(to_pci_dev(sc->dev),
-					   bf->bf_buf_addr))) {
+			       DMA_TO_DEVICE);
+	if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) {
 		dev_kfree_skb_any(skb);
 		bf->bf_mpdu = NULL;
 		DPRINTF(sc, ATH_DBG_CONFIG,
-			"pci_dma_mapping_error() on beaconing\n");
+			"dma_mapping_error() on beaconing\n");
 		return NULL;
 	}
 
@@ -344,9 +343,9 @@ int ath_beacon_alloc(struct ath_softc *sc, int if_id)
 	bf = avp->av_bcbuf;
 	if (bf->bf_mpdu != NULL) {
 		skb = (struct sk_buff *)bf->bf_mpdu;
-		pci_unmap_single(to_pci_dev(sc->dev), bf->bf_dmacontext,
+		dma_unmap_single(sc->dev, bf->bf_dmacontext,
 				 skb->len,
-				 PCI_DMA_TODEVICE);
+				 DMA_TO_DEVICE);
 		dev_kfree_skb_any(skb);
 		bf->bf_mpdu = NULL;
 	}
@@ -403,15 +402,14 @@ int ath_beacon_alloc(struct ath_softc *sc, int if_id)
 
 	bf->bf_mpdu = skb;
 	bf->bf_buf_addr = bf->bf_dmacontext =
-		pci_map_single(to_pci_dev(sc->dev), skb->data,
+		dma_map_single(sc->dev, skb->data,
 			       skb->len,
-			       PCI_DMA_TODEVICE);
-	if (unlikely(pci_dma_mapping_error(to_pci_dev(sc->dev),
-					   bf->bf_buf_addr))) {
+			       DMA_TO_DEVICE);
+	if (unlikely(dma_mapping_error(sc->dev, bf->bf_buf_addr))) {
 		dev_kfree_skb_any(skb);
 		bf->bf_mpdu = NULL;
 		DPRINTF(sc, ATH_DBG_CONFIG,
-			"pci_dma_mapping_error() on beacon alloc\n");
+			"dma_mapping_error() on beacon alloc\n");
 		return -ENOMEM;
 	}
 
@@ -431,10 +429,9 @@ void ath_beacon_return(struct ath_softc *sc, struct ath_vap *avp)
 		bf = avp->av_bcbuf;
 		if (bf->bf_mpdu != NULL) {
 			struct sk_buff *skb = (struct sk_buff *)bf->bf_mpdu;
-			pci_unmap_single(to_pci_dev(sc->dev),
-					 bf->bf_dmacontext,
+			dma_unmap_single(sc->dev, bf->bf_dmacontext,
 					 skb->len,
-					 PCI_DMA_TODEVICE);
+					 DMA_TO_DEVICE);
 			dev_kfree_skb_any(skb);
 			bf->bf_mpdu = NULL;
 		}
diff --git a/drivers/net/wireless/ath9k/main.c b/drivers/net/wireless/ath9k/main.c
index 3313459..9acd968 100644
--- a/drivers/net/wireless/ath9k/main.c
+++ b/drivers/net/wireless/ath9k/main.c
@@ -1709,9 +1709,8 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
 	}
 
 	/* allocate descriptors */
-	dd->dd_desc = pci_alloc_consistent(to_pci_dev(sc->dev),
-			      dd->dd_desc_len,
-			      &dd->dd_desc_paddr);
+	dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
+					 &dd->dd_desc_paddr, GFP_ATOMIC);
 	if (dd->dd_desc == NULL) {
 		error = -ENOMEM;
 		goto fail;
@@ -1757,8 +1756,8 @@ int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
 	}
 	return 0;
 fail2:
-	pci_free_consistent(to_pci_dev(sc->dev),
-		dd->dd_desc_len, dd->dd_desc, dd->dd_desc_paddr);
+	dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
+			  dd->dd_desc_paddr);
 fail:
 	memset(dd, 0, sizeof(*dd));
 	return error;
@@ -1771,8 +1770,8 @@ void ath_descdma_cleanup(struct ath_softc *sc,
 			 struct ath_descdma *dd,
 			 struct list_head *head)
 {
-	pci_free_consistent(to_pci_dev(sc->dev),
-		dd->dd_desc_len, dd->dd_desc, dd->dd_desc_paddr);
+	dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
+			  dd->dd_desc_paddr);
 
 	INIT_LIST_HEAD(head);
 	kfree(dd->dd_bufptr);
diff --git a/drivers/net/wireless/ath9k/recv.c b/drivers/net/wireless/ath9k/recv.c
index d7774d1..1fc4dd9 100644
--- a/drivers/net/wireless/ath9k/recv.c
+++ b/drivers/net/wireless/ath9k/recv.c
@@ -291,16 +291,15 @@ int ath_rx_init(struct ath_softc *sc, int nbufs)
 			}
 
 			bf->bf_mpdu = skb;
-			bf->bf_buf_addr = pci_map_single(to_pci_dev(sc->dev),
-							 skb->data,
+			bf->bf_buf_addr = dma_map_single(sc->dev, skb->data,
 							 sc->rx.bufsize,
-							 PCI_DMA_FROMDEVICE);
-			if (unlikely(pci_dma_mapping_error(to_pci_dev(sc->dev),
+							 DMA_FROM_DEVICE);
+			if (unlikely(dma_mapping_error(sc->dev,
 				  bf->bf_buf_addr))) {
 				dev_kfree_skb_any(skb);
 				bf->bf_mpdu = NULL;
 				DPRINTF(sc, ATH_DBG_CONFIG,
-					"pci_dma_mapping_error() on RX init\n");
+					"dma_mapping_error() on RX init\n");
 				error = -ENOMEM;
 				break;
 			}
@@ -525,10 +524,9 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush)
 		 * 1. accessing the frame
 		 * 2. requeueing the same buffer to h/w
 		 */
-		pci_dma_sync_single_for_cpu(to_pci_dev(sc->dev),
-				bf->bf_buf_addr,
+		dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
 				sc->rx.bufsize,
-				PCI_DMA_FROMDEVICE);
+				DMA_FROM_DEVICE);
 
 		/*
 		 * If we're asked to flush receive queue, directly
@@ -559,9 +557,9 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush)
 			goto requeue;
 
 		/* Unmap the frame */
-		pci_unmap_single(to_pci_dev(sc->dev), bf->bf_buf_addr,
+		dma_unmap_single(sc->dev, bf->bf_buf_addr,
 				 sc->rx.bufsize,
-				 PCI_DMA_FROMDEVICE);
+				 DMA_FROM_DEVICE);
 
 		skb_put(skb, ds->ds_rxstat.rs_datalen);
 		skb->protocol = cpu_to_be16(ETH_P_CONTROL);
@@ -601,16 +599,15 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush)
 
 		/* We will now give hardware our shiny new allocated skb */
 		bf->bf_mpdu = requeue_skb;
-		bf->bf_buf_addr = pci_map_single(to_pci_dev(sc->dev),
-					 requeue_skb->data,
+		bf->bf_buf_addr = dma_map_single(sc->dev, requeue_skb->data,
 					 sc->rx.bufsize,
-					 PCI_DMA_FROMDEVICE);
-		if (unlikely(pci_dma_mapping_error(to_pci_dev(sc->dev),
+					 DMA_FROM_DEVICE);
+		if (unlikely(dma_mapping_error(sc->dev,
 			  bf->bf_buf_addr))) {
 			dev_kfree_skb_any(requeue_skb);
 			bf->bf_mpdu = NULL;
 			DPRINTF(sc, ATH_DBG_CONFIG,
-				"pci_dma_mapping_error() on RX\n");
+				"dma_mapping_error() on RX\n");
 			break;
 		}
 		bf->bf_dmacontext = bf->bf_buf_addr;
diff --git a/drivers/net/wireless/ath9k/xmit.c b/drivers/net/wireless/ath9k/xmit.c
index 27cb9d5..522078d 100644
--- a/drivers/net/wireless/ath9k/xmit.c
+++ b/drivers/net/wireless/ath9k/xmit.c
@@ -340,10 +340,8 @@ static void ath_tx_complete_buf(struct ath_softc *sc,
 	}
 
 	/* Unmap this frame */
-	pci_unmap_single(to_pci_dev(sc->dev),
-			 bf->bf_dmacontext,
-			 skb->len,
-			 PCI_DMA_TODEVICE);
+	dma_unmap_single(sc->dev, bf->bf_dmacontext, skb->len, DMA_TO_DEVICE);
+
 	/* complete this frame */
 	ath_tx_complete(sc, skb, &tx_status);
 
@@ -1716,13 +1714,12 @@ static int ath_tx_setup_buffer(struct ath_softc *sc, struct ath_buf *bf,
 	/* DMA setup */
 	bf->bf_mpdu = skb;
 
-	bf->bf_dmacontext = pci_map_single(to_pci_dev(sc->dev), skb->data,
-					   skb->len, PCI_DMA_TODEVICE);
-	if (unlikely(pci_dma_mapping_error(to_pci_dev(sc->dev),
-					   bf->bf_dmacontext))) {
+	bf->bf_dmacontext = dma_map_single(sc->dev, skb->data,
+					   skb->len, DMA_TO_DEVICE);
+	if (unlikely(dma_mapping_error(sc->dev, bf->bf_dmacontext))) {
 		bf->bf_mpdu = NULL;
 		DPRINTF(sc, ATH_DBG_CONFIG,
-			"pci_dma_mapping_error() on TX\n");
+			"dma_mapping_error() on TX\n");
 		return -ENOMEM;
 	}
 
-- 
1.5.3.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 03/11] ath9k: introduce bus specific cache size routine
  2009-01-07 10:09 [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs Gabor Juhos
  2009-01-07 10:09 ` [PATCH 01/11] ath9k: convert to struct device Gabor Juhos
  2009-01-07 10:09 ` [PATCH 02/11] ath9k: convert to use bus-agnostic DMA routines Gabor Juhos
@ 2009-01-07 10:09 ` Gabor Juhos
  2009-01-07 10:09 ` [PATCH 04/11] ath9k: introduce bus specific cleanup routine Gabor Juhos
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 10:09 UTC (permalink / raw)
  To: John W. Linville
  Cc: Luis R. Rodriguez, Jouni Malinen, ath9k-devel@lists.ath9k.org,
	linux-wireless@vger.kernel.org, Felix Fietkau, Christoph Hellwig,
	Sujith Manoharan, Gabor Juhos, Imre Kaloz

The PCI specific bus_read_cachesize routine won't work on the AHB bus,
we have to replace it with a suitable one later.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
 drivers/net/wireless/ath9k/core.h |   10 ++++++++++
 drivers/net/wireless/ath9k/main.c |    9 +++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ath9k/core.h b/drivers/net/wireless/ath9k/core.h
index 2256ba4..8e93d11 100644
--- a/drivers/net/wireless/ath9k/core.h
+++ b/drivers/net/wireless/ath9k/core.h
@@ -693,6 +693,10 @@ enum PROT_MODE {
 #define SC_OP_RFKILL_SW_BLOCKED	BIT(12)
 #define SC_OP_RFKILL_HW_BLOCKED	BIT(13)
 
+struct ath_bus_ops {
+	void		(*read_cachesize)(struct ath_softc *sc, int *csz);
+};
+
 struct ath_softc {
 	struct ieee80211_hw *hw;
 	struct device *dev;
@@ -743,6 +747,7 @@ struct ath_softc {
 #ifdef CONFIG_ATH9K_DEBUG
 	struct ath9k_debug sc_debug;
 #endif
+	struct ath_bus_ops *bus_ops;
 };
 
 int ath_reset(struct ath_softc *sc, bool retry_tx);
@@ -750,4 +755,9 @@ int ath_get_hal_qnum(u16 queue, struct ath_softc *sc);
 int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc);
 int ath_cabq_update(struct ath_softc *);
 
+static inline void ath_read_cachesize(struct ath_softc *sc, int *csz)
+{
+	sc->bus_ops->read_cachesize(sc, csz);
+}
+
 #endif /* CORE_H */
diff --git a/drivers/net/wireless/ath9k/main.c b/drivers/net/wireless/ath9k/main.c
index 9acd968..15824c1 100644
--- a/drivers/net/wireless/ath9k/main.c
+++ b/drivers/net/wireless/ath9k/main.c
@@ -42,7 +42,7 @@ static void ath_detach(struct ath_softc *sc);
 
 /* return bus cachesize in 4B word units */
 
-static void bus_read_cachesize(struct ath_softc *sc, int *csz)
+static void ath_pci_read_cachesize(struct ath_softc *sc, int *csz)
 {
 	u8 u8tmp;
 
@@ -1338,7 +1338,7 @@ static int ath_init(u16 devid, struct ath_softc *sc)
 	 * Cache line size is used to size and align various
 	 * structures used to communicate with the hardware.
 	 */
-	bus_read_cachesize(sc, &csz);
+	ath_read_cachesize(sc, &csz);
 	/* XXX assert csz is non-zero */
 	sc->sc_cachelsz = csz << 2;	/* convert to bytes */
 
@@ -2529,6 +2529,10 @@ ath_rf_name(u16 rf_version)
 	return "????";
 }
 
+static struct ath_bus_ops ath_pci_bus_ops = {
+	.read_cachesize = ath_pci_read_cachesize,
+};
+
 static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	void __iomem *mem;
@@ -2617,6 +2621,7 @@ static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	sc->hw = hw;
 	sc->dev = &pdev->dev;
 	sc->mem = mem;
+	sc->bus_ops = &ath_pci_bus_ops;
 
 	if (ath_attach(id->device, sc) != 0) {
 		ret = -ENODEV;
-- 
1.5.3.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 04/11] ath9k: introduce bus specific cleanup routine
  2009-01-07 10:09 [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs Gabor Juhos
                   ` (2 preceding siblings ...)
  2009-01-07 10:09 ` [PATCH 03/11] ath9k: introduce bus specific cache size routine Gabor Juhos
@ 2009-01-07 10:09 ` Gabor Juhos
  2009-01-07 10:24   ` Johannes Berg
  2009-01-07 10:27   ` Johannes Berg
  2009-01-07 10:09 ` [PATCH 05/11] ath9k: move PCI code into separate file Gabor Juhos
                   ` (6 subsequent siblings)
  10 siblings, 2 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 10:09 UTC (permalink / raw)
  To: John W. Linville
  Cc: Luis R. Rodriguez, Jouni Malinen, ath9k-devel@lists.ath9k.org,
	linux-wireless@vger.kernel.org, Felix Fietkau, Christoph Hellwig,
	Sujith Manoharan, Gabor Juhos, Imre Kaloz

We have left only some PCI specific cleanup code. We have to convert
them as well.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
 drivers/net/wireless/ath9k/core.h |    6 ++++++
 drivers/net/wireless/ath9k/main.c |   30 ++++++++++++++++--------------
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/drivers/net/wireless/ath9k/core.h b/drivers/net/wireless/ath9k/core.h
index 8e93d11..175f026 100644
--- a/drivers/net/wireless/ath9k/core.h
+++ b/drivers/net/wireless/ath9k/core.h
@@ -695,6 +695,7 @@ enum PROT_MODE {
 
 struct ath_bus_ops {
 	void		(*read_cachesize)(struct ath_softc *sc, int *csz);
+	void		(*cleanup)(struct ath_softc *sc);
 };
 
 struct ath_softc {
@@ -760,4 +761,9 @@ static inline void ath_read_cachesize(struct ath_softc *sc, int *csz)
 	sc->bus_ops->read_cachesize(sc, csz);
 }
 
+static inline void ath_bus_cleanup(struct ath_softc *sc)
+{
+	sc->bus_ops->cleanup(sc);
+}
+
 #endif /* CORE_H */
diff --git a/drivers/net/wireless/ath9k/main.c b/drivers/net/wireless/ath9k/main.c
index 15824c1..7917441 100644
--- a/drivers/net/wireless/ath9k/main.c
+++ b/drivers/net/wireless/ath9k/main.c
@@ -1267,13 +1267,7 @@ static int ath_start_rfkill_poll(struct ath_softc *sc)
 			rfkill_free(sc->rf_kill.rfkill);
 
 			/* Deinitialize the device */
-			ath_detach(sc);
-			if (to_pci_dev(sc->dev)->irq)
-				free_irq(to_pci_dev(sc->dev)->irq, sc);
-			pci_iounmap(to_pci_dev(sc->dev), sc->mem);
-			pci_release_region(to_pci_dev(sc->dev), 0);
-			pci_disable_device(to_pci_dev(sc->dev));
-			ieee80211_free_hw(sc->hw);
+			ath_bus_cleanup(sc);
 			return -EIO;
 		} else {
 			sc->sc_flags |= SC_OP_RFKILL_REGISTERED;
@@ -2529,8 +2523,22 @@ ath_rf_name(u16 rf_version)
 	return "????";
 }
 
+static void ath_pci_cleanup(struct ath_softc *sc)
+{
+	struct pci_dev *pdev = to_pci_dev(sc->dev);
+
+	ath_detach(sc);
+	if (pdev->irq)
+		free_irq(pdev->irq, sc);
+	pci_iounmap(pdev, sc->mem);
+	pci_release_region(pdev, 0);
+	pci_disable_device(pdev);
+	ieee80211_free_hw(sc->hw);
+}
+
 static struct ath_bus_ops ath_pci_bus_ops = {
 	.read_cachesize = ath_pci_read_cachesize,
+	.cleanup = ath_pci_cleanup,
 };
 
 static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
@@ -2667,13 +2675,7 @@ static void ath_pci_remove(struct pci_dev *pdev)
 	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
 	struct ath_softc *sc = hw->priv;
 
-	ath_detach(sc);
-	if (pdev->irq)
-		free_irq(pdev->irq, sc);
-	pci_iounmap(pdev, sc->mem);
-	pci_release_region(pdev, 0);
-	pci_disable_device(pdev);
-	ieee80211_free_hw(hw);
+	ath_pci_cleanup(sc);
 }
 
 #ifdef CONFIG_PM
-- 
1.5.3.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 05/11] ath9k: move PCI code into separate file
  2009-01-07 10:09 [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs Gabor Juhos
                   ` (3 preceding siblings ...)
  2009-01-07 10:09 ` [PATCH 04/11] ath9k: introduce bus specific cleanup routine Gabor Juhos
@ 2009-01-07 10:09 ` Gabor Juhos
  2009-01-07 10:09 ` [PATCH 06/11] ath9k: introduce platform driver for AHB bus support Gabor Juhos
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 10:09 UTC (permalink / raw)
  To: John W. Linville
  Cc: Luis R. Rodriguez, Jouni Malinen, ath9k-devel@lists.ath9k.org,
	linux-wireless@vger.kernel.org, Felix Fietkau, Christoph Hellwig,
	Sujith Manoharan, Gabor Juhos, Imre Kaloz

Now that we have converted all bus specific routines to replaceable, we
can move the PCI specific codes into a separate file.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
 drivers/net/wireless/ath9k/Makefile |    1 +
 drivers/net/wireless/ath9k/core.h   |   18 ++-
 drivers/net/wireless/ath9k/main.c   |  299 +++--------------------------------
 drivers/net/wireless/ath9k/pci.c    |  289 +++++++++++++++++++++++++++++++++
 4 files changed, 328 insertions(+), 279 deletions(-)

diff --git a/drivers/net/wireless/ath9k/Makefile b/drivers/net/wireless/ath9k/Makefile
index 1209d14..af3f39b 100644
--- a/drivers/net/wireless/ath9k/Makefile
+++ b/drivers/net/wireless/ath9k/Makefile
@@ -11,6 +11,7 @@ ath9k-y +=	hw.o \
 		xmit.o \
 		rc.o
 
+ath9k-$(CONFIG_PCI) += pci.o
 ath9k-$(CONFIG_ATH9K_DEBUG) += debug.o
 
 obj-$(CONFIG_ATH9K) += ath9k.o
diff --git a/drivers/net/wireless/ath9k/core.h b/drivers/net/wireless/ath9k/core.h
index 175f026..a7cdbed 100644
--- a/drivers/net/wireless/ath9k/core.h
+++ b/drivers/net/wireless/ath9k/core.h
@@ -18,7 +18,7 @@
 #define CORE_H
 
 #include <linux/etherdevice.h>
-#include <linux/pci.h>
+#include <linux/device.h>
 #include <net/mac80211.h>
 #include <linux/leds.h>
 #include <linux/rfkill.h>
@@ -766,4 +766,20 @@ static inline void ath_bus_cleanup(struct ath_softc *sc)
 	sc->bus_ops->cleanup(sc);
 }
 
+extern struct ieee80211_ops ath9k_ops;
+
+irqreturn_t ath_isr(int irq, void *dev);
+int ath_attach(u16 devid, struct ath_softc *sc);
+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);
+
+#ifdef CONFIG_PCI
+int ath_pci_init(void);
+void ath_pci_exit(void);
+#else
+static inline int ath_pci_init(void) { return 0; };
+static inline void ath_pci_exit(void) {};
+#endif
+
 #endif /* CORE_H */
diff --git a/drivers/net/wireless/ath9k/main.c b/drivers/net/wireless/ath9k/main.c
index 7917441..a1b3f82 100644
--- a/drivers/net/wireless/ath9k/main.c
+++ b/drivers/net/wireless/ath9k/main.c
@@ -28,38 +28,6 @@ MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
 MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
 MODULE_LICENSE("Dual BSD/GPL");
 
-static struct pci_device_id ath_pci_id_table[] __devinitdata = {
-	{ PCI_VDEVICE(ATHEROS, 0x0023) }, /* PCI   */
-	{ PCI_VDEVICE(ATHEROS, 0x0024) }, /* PCI-E */
-	{ PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI   */
-	{ PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI   */
-	{ PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
-	{ PCI_VDEVICE(ATHEROS, 0x002B) }, /* PCI-E */
-	{ 0 }
-};
-
-static void ath_detach(struct ath_softc *sc);
-
-/* return bus cachesize in 4B word units */
-
-static void ath_pci_read_cachesize(struct ath_softc *sc, int *csz)
-{
-	u8 u8tmp;
-
-	pci_read_config_byte(to_pci_dev(sc->dev), PCI_CACHE_LINE_SIZE,
-			     (u8 *)&u8tmp);
-	*csz = (int)u8tmp;
-
-	/*
-	 * This check was put in to avoid "unplesant" consequences if
-	 * the bootrom has not fully initialized all PCI devices.
-	 * Sometimes the cache line size register is not set
-	 */
-
-	if (*csz == 0)
-		*csz = DEFAULT_CACHELINE >> 2;   /* Use the default size */
-}
-
 static void ath_cache_conf_rate(struct ath_softc *sc,
 				struct ieee80211_conf *conf)
 {
@@ -497,7 +465,7 @@ static void ath9k_tasklet(unsigned long data)
 	ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask);
 }
 
-static irqreturn_t ath_isr(int irq, void *dev)
+irqreturn_t ath_isr(int irq, void *dev)
 {
 	struct ath_softc *sc = dev;
 	struct ath_hal *ah = sc->sc_ah;
@@ -1278,7 +1246,7 @@ static int ath_start_rfkill_poll(struct ath_softc *sc)
 }
 #endif /* CONFIG_RFKILL */
 
-static void ath_detach(struct ath_softc *sc)
+void ath_detach(struct ath_softc *sc)
 {
 	struct ieee80211_hw *hw = sc->hw;
 	int i = 0;
@@ -1529,7 +1497,7 @@ bad:
 	return error;
 }
 
-static int ath_attach(u16 devid, struct ath_softc *sc)
+int ath_attach(u16 devid, struct ath_softc *sc)
 {
 	struct ieee80211_hw *hw = sc->hw;
 	int error = 0;
@@ -2448,7 +2416,7 @@ static int ath9k_ampdu_action(struct ieee80211_hw *hw,
 	return ret;
 }
 
-static struct ieee80211_ops ath9k_ops = {
+struct ieee80211_ops ath9k_ops = {
 	.tx 		    = ath9k_tx,
 	.start 		    = ath9k_start,
 	.stop 		    = ath9k_stop,
@@ -2492,7 +2460,7 @@ static struct {
 /*
  * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
  */
-static const char *
+const char *
 ath_mac_bb_name(u32 mac_bb_version)
 {
 	int i;
@@ -2509,7 +2477,7 @@ ath_mac_bb_name(u32 mac_bb_version)
 /*
  * Return the RF name. "????" is returned if the RF is unknown.
  */
-static const char *
+const char *
 ath_rf_name(u16 rf_version)
 {
 	int i;
@@ -2523,236 +2491,7 @@ ath_rf_name(u16 rf_version)
 	return "????";
 }
 
-static void ath_pci_cleanup(struct ath_softc *sc)
-{
-	struct pci_dev *pdev = to_pci_dev(sc->dev);
-
-	ath_detach(sc);
-	if (pdev->irq)
-		free_irq(pdev->irq, sc);
-	pci_iounmap(pdev, sc->mem);
-	pci_release_region(pdev, 0);
-	pci_disable_device(pdev);
-	ieee80211_free_hw(sc->hw);
-}
-
-static struct ath_bus_ops ath_pci_bus_ops = {
-	.read_cachesize = ath_pci_read_cachesize,
-	.cleanup = ath_pci_cleanup,
-};
-
-static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
-{
-	void __iomem *mem;
-	struct ath_softc *sc;
-	struct ieee80211_hw *hw;
-	u8 csz;
-	u32 val;
-	int ret = 0;
-	struct ath_hal *ah;
-
-	if (pci_enable_device(pdev))
-		return -EIO;
-
-	ret =  pci_set_dma_mask(pdev, DMA_32BIT_MASK);
-
-	if (ret) {
-		printk(KERN_ERR "ath9k: 32-bit DMA not available\n");
-		goto bad;
-	}
-
-	ret = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
-
-	if (ret) {
-		printk(KERN_ERR "ath9k: 32-bit DMA consistent "
-			"DMA enable failed\n");
-		goto bad;
-	}
-
-	/*
-	 * Cache line size is used to size and align various
-	 * structures used to communicate with the hardware.
-	 */
-	pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
-	if (csz == 0) {
-		/*
-		 * Linux 2.4.18 (at least) writes the cache line size
-		 * register as a 16-bit wide register which is wrong.
-		 * We must have this setup properly for rx buffer
-		 * DMA to work so force a reasonable value here if it
-		 * comes up zero.
-		 */
-		csz = L1_CACHE_BYTES / sizeof(u32);
-		pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
-	}
-	/*
-	 * The default setting of latency timer yields poor results,
-	 * set it to the value used by other systems. It may be worth
-	 * tweaking this setting more.
-	 */
-	pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
-
-	pci_set_master(pdev);
-
-	/*
-	 * Disable the RETRY_TIMEOUT register (0x41) to keep
-	 * PCI Tx retries from interfering with C3 CPU state.
-	 */
-	pci_read_config_dword(pdev, 0x40, &val);
-	if ((val & 0x0000ff00) != 0)
-		pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
-
-	ret = pci_request_region(pdev, 0, "ath9k");
-	if (ret) {
-		dev_err(&pdev->dev, "PCI memory region reserve error\n");
-		ret = -ENODEV;
-		goto bad;
-	}
-
-	mem = pci_iomap(pdev, 0, 0);
-	if (!mem) {
-		printk(KERN_ERR "PCI memory map error\n") ;
-		ret = -EIO;
-		goto bad1;
-	}
-
-	hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
-	if (hw == NULL) {
-		printk(KERN_ERR "ath_pci: no memory for ieee80211_hw\n");
-		goto bad2;
-	}
-
-	SET_IEEE80211_DEV(hw, &pdev->dev);
-	pci_set_drvdata(pdev, hw);
-
-	sc = hw->priv;
-	sc->hw = hw;
-	sc->dev = &pdev->dev;
-	sc->mem = mem;
-	sc->bus_ops = &ath_pci_bus_ops;
-
-	if (ath_attach(id->device, sc) != 0) {
-		ret = -ENODEV;
-		goto bad3;
-	}
-
-	/* setup interrupt service routine */
-
-	if (request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath", sc)) {
-		printk(KERN_ERR "%s: request_irq failed\n",
-			wiphy_name(hw->wiphy));
-		ret = -EIO;
-		goto bad4;
-	}
-
-	ah = sc->sc_ah;
-	printk(KERN_INFO
-	       "%s: Atheros AR%s MAC/BB Rev:%x "
-	       "AR%s RF Rev:%x: mem=0x%lx, irq=%d\n",
-	       wiphy_name(hw->wiphy),
-	       ath_mac_bb_name(ah->ah_macVersion),
-	       ah->ah_macRev,
-	       ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
-	       ah->ah_phyRev,
-	       (unsigned long)mem, pdev->irq);
-
-	return 0;
-bad4:
-	ath_detach(sc);
-bad3:
-	ieee80211_free_hw(hw);
-bad2:
-	pci_iounmap(pdev, mem);
-bad1:
-	pci_release_region(pdev, 0);
-bad:
-	pci_disable_device(pdev);
-	return ret;
-}
-
-static void ath_pci_remove(struct pci_dev *pdev)
-{
-	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
-	struct ath_softc *sc = hw->priv;
-
-	ath_pci_cleanup(sc);
-}
-
-#ifdef CONFIG_PM
-
-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;
-
-	ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
-
-#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
-	if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
-		cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
-#endif
-
-	pci_save_state(pdev);
-	pci_disable_device(pdev);
-	pci_set_power_state(pdev, 3);
-
-	return 0;
-}
-
-static int ath_pci_resume(struct pci_dev *pdev)
-{
-	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
-	struct ath_softc *sc = hw->priv;
-	u32 val;
-	int err;
-
-	err = pci_enable_device(pdev);
-	if (err)
-		return err;
-	pci_restore_state(pdev);
-	/*
-	 * Suspend/Resume resets the PCI configuration space, so we have to
-	 * re-disable the RETRY_TIMEOUT register (0x41) to keep
-	 * PCI Tx retries from interfering with C3 CPU state
-	 */
-	pci_read_config_dword(pdev, 0x40, &val);
-	if ((val & 0x0000ff00) != 0)
-		pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
-
-	/* Enable LED */
-	ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
-			    AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
-	ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
-
-#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
-	/*
-	 * check the h/w rfkill state on resume
-	 * and start the rfkill poll timer
-	 */
-	if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
-		queue_delayed_work(sc->hw->workqueue,
-				   &sc->rf_kill.rfkill_poll, 0);
-#endif
-
-	return 0;
-}
-
-#endif /* CONFIG_PM */
-
-MODULE_DEVICE_TABLE(pci, ath_pci_id_table);
-
-static struct pci_driver ath_pci_driver = {
-	.name       = "ath9k",
-	.id_table   = ath_pci_id_table,
-	.probe      = ath_pci_probe,
-	.remove     = ath_pci_remove,
-#ifdef CONFIG_PM
-	.suspend    = ath_pci_suspend,
-	.resume     = ath_pci_resume,
-#endif /* CONFIG_PM */
-};
-
-static int __init init_ath_pci(void)
+static int __init ath9k_init(void)
 {
 	int error;
 
@@ -2764,26 +2503,30 @@ static int __init init_ath_pci(void)
 		printk(KERN_ERR
 			"Unable to register rate control algorithm: %d\n",
 			error);
-		ath_rate_control_unregister();
-		return error;
+		goto err_out;
 	}
 
-	if (pci_register_driver(&ath_pci_driver) < 0) {
+	error = ath_pci_init();
+	if (error < 0) {
 		printk(KERN_ERR
 			"ath_pci: No devices found, driver not installed.\n");
-		ath_rate_control_unregister();
-		pci_unregister_driver(&ath_pci_driver);
-		return -ENODEV;
+		error = -ENODEV;
+		goto err_rate_unregister;
 	}
 
 	return 0;
+
+ err_rate_unregister:
+	ath_rate_control_unregister();
+ err_out:
+	return error;
 }
-module_init(init_ath_pci);
+module_init(ath9k_init);
 
-static void __exit exit_ath_pci(void)
+static void __exit ath9k_exit(void)
 {
+	ath_pci_exit();
 	ath_rate_control_unregister();
-	pci_unregister_driver(&ath_pci_driver);
 	printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
 }
-module_exit(exit_ath_pci);
+module_exit(ath9k_exit);
diff --git a/drivers/net/wireless/ath9k/pci.c b/drivers/net/wireless/ath9k/pci.c
new file mode 100644
index 0000000..02c946e
--- /dev/null
+++ b/drivers/net/wireless/ath9k/pci.c
@@ -0,0 +1,289 @@
+/*
+ * Copyright (c) 2008 Atheros Communications Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <linux/nl80211.h>
+#include <linux/pci.h>
+#include "core.h"
+#include "reg.h"
+#include "hw.h"
+
+static struct pci_device_id ath_pci_id_table[] __devinitdata = {
+	{ PCI_VDEVICE(ATHEROS, 0x0023) }, /* PCI   */
+	{ PCI_VDEVICE(ATHEROS, 0x0024) }, /* PCI-E */
+	{ PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI   */
+	{ PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI   */
+	{ PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
+	{ PCI_VDEVICE(ATHEROS, 0x002B) }, /* PCI-E */
+	{ 0 }
+};
+
+/* return bus cachesize in 4B word units */
+static void ath_pci_read_cachesize(struct ath_softc *sc, int *csz)
+{
+	u8 u8tmp;
+
+	pci_read_config_byte(to_pci_dev(sc->dev), PCI_CACHE_LINE_SIZE,
+			     (u8 *)&u8tmp);
+	*csz = (int)u8tmp;
+
+	/*
+	 * This check was put in to avoid "unplesant" consequences if
+	 * the bootrom has not fully initialized all PCI devices.
+	 * Sometimes the cache line size register is not set
+	 */
+
+	if (*csz == 0)
+		*csz = DEFAULT_CACHELINE >> 2;   /* Use the default size */
+}
+
+static void ath_pci_cleanup(struct ath_softc *sc)
+{
+	struct pci_dev *pdev = to_pci_dev(sc->dev);
+
+	ath_detach(sc);
+	if (pdev->irq)
+		free_irq(pdev->irq, sc);
+	pci_iounmap(pdev, sc->mem);
+	pci_release_region(pdev, 0);
+	pci_disable_device(pdev);
+	ieee80211_free_hw(sc->hw);
+}
+
+static struct ath_bus_ops ath_pci_bus_ops = {
+	.read_cachesize = ath_pci_read_cachesize,
+	.cleanup = ath_pci_cleanup,
+};
+
+static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+	void __iomem *mem;
+	struct ath_softc *sc;
+	struct ieee80211_hw *hw;
+	u8 csz;
+	u32 val;
+	int ret = 0;
+	struct ath_hal *ah;
+
+	if (pci_enable_device(pdev))
+		return -EIO;
+
+	ret =  pci_set_dma_mask(pdev, DMA_32BIT_MASK);
+
+	if (ret) {
+		printk(KERN_ERR "ath9k: 32-bit DMA not available\n");
+		goto bad;
+	}
+
+	ret = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
+
+	if (ret) {
+		printk(KERN_ERR "ath9k: 32-bit DMA consistent "
+			"DMA enable failed\n");
+		goto bad;
+	}
+
+	/*
+	 * Cache line size is used to size and align various
+	 * structures used to communicate with the hardware.
+	 */
+	pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
+	if (csz == 0) {
+		/*
+		 * Linux 2.4.18 (at least) writes the cache line size
+		 * register as a 16-bit wide register which is wrong.
+		 * We must have this setup properly for rx buffer
+		 * DMA to work so force a reasonable value here if it
+		 * comes up zero.
+		 */
+		csz = L1_CACHE_BYTES / sizeof(u32);
+		pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
+	}
+	/*
+	 * The default setting of latency timer yields poor results,
+	 * set it to the value used by other systems. It may be worth
+	 * tweaking this setting more.
+	 */
+	pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
+
+	pci_set_master(pdev);
+
+	/*
+	 * Disable the RETRY_TIMEOUT register (0x41) to keep
+	 * PCI Tx retries from interfering with C3 CPU state.
+	 */
+	pci_read_config_dword(pdev, 0x40, &val);
+	if ((val & 0x0000ff00) != 0)
+		pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
+
+	ret = pci_request_region(pdev, 0, "ath9k");
+	if (ret) {
+		dev_err(&pdev->dev, "PCI memory region reserve error\n");
+		ret = -ENODEV;
+		goto bad;
+	}
+
+	mem = pci_iomap(pdev, 0, 0);
+	if (!mem) {
+		printk(KERN_ERR "PCI memory map error\n") ;
+		ret = -EIO;
+		goto bad1;
+	}
+
+	hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
+	if (hw == NULL) {
+		printk(KERN_ERR "ath_pci: no memory for ieee80211_hw\n");
+		goto bad2;
+	}
+
+	SET_IEEE80211_DEV(hw, &pdev->dev);
+	pci_set_drvdata(pdev, hw);
+
+	sc = hw->priv;
+	sc->hw = hw;
+	sc->dev = &pdev->dev;
+	sc->mem = mem;
+	sc->bus_ops = &ath_pci_bus_ops;
+
+	if (ath_attach(id->device, sc) != 0) {
+		ret = -ENODEV;
+		goto bad3;
+	}
+
+	/* setup interrupt service routine */
+
+	if (request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath", sc)) {
+		printk(KERN_ERR "%s: request_irq failed\n",
+			wiphy_name(hw->wiphy));
+		ret = -EIO;
+		goto bad4;
+	}
+
+	ah = sc->sc_ah;
+	printk(KERN_INFO
+	       "%s: Atheros AR%s MAC/BB Rev:%x "
+	       "AR%s RF Rev:%x: mem=0x%lx, irq=%d\n",
+	       wiphy_name(hw->wiphy),
+	       ath_mac_bb_name(ah->ah_macVersion),
+	       ah->ah_macRev,
+	       ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
+	       ah->ah_phyRev,
+	       (unsigned long)mem, pdev->irq);
+
+	return 0;
+bad4:
+	ath_detach(sc);
+bad3:
+	ieee80211_free_hw(hw);
+bad2:
+	pci_iounmap(pdev, mem);
+bad1:
+	pci_release_region(pdev, 0);
+bad:
+	pci_disable_device(pdev);
+	return ret;
+}
+
+static void ath_pci_remove(struct pci_dev *pdev)
+{
+	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
+	struct ath_softc *sc = hw->priv;
+
+	ath_pci_cleanup(sc);
+}
+
+#ifdef CONFIG_PM
+
+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;
+
+	ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
+
+#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
+	if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
+		cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
+#endif
+
+	pci_save_state(pdev);
+	pci_disable_device(pdev);
+	pci_set_power_state(pdev, 3);
+
+	return 0;
+}
+
+static int ath_pci_resume(struct pci_dev *pdev)
+{
+	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
+	struct ath_softc *sc = hw->priv;
+	u32 val;
+	int err;
+
+	err = pci_enable_device(pdev);
+	if (err)
+		return err;
+	pci_restore_state(pdev);
+	/*
+	 * Suspend/Resume resets the PCI configuration space, so we have to
+	 * re-disable the RETRY_TIMEOUT register (0x41) to keep
+	 * PCI Tx retries from interfering with C3 CPU state
+	 */
+	pci_read_config_dword(pdev, 0x40, &val);
+	if ((val & 0x0000ff00) != 0)
+		pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
+
+	/* Enable LED */
+	ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
+			    AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
+	ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
+
+#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
+	/*
+	 * check the h/w rfkill state on resume
+	 * and start the rfkill poll timer
+	 */
+	if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
+		queue_delayed_work(sc->hw->workqueue,
+				   &sc->rf_kill.rfkill_poll, 0);
+#endif
+
+	return 0;
+}
+
+#endif /* CONFIG_PM */
+
+MODULE_DEVICE_TABLE(pci, ath_pci_id_table);
+
+static struct pci_driver ath_pci_driver = {
+	.name       = "ath9k",
+	.id_table   = ath_pci_id_table,
+	.probe      = ath_pci_probe,
+	.remove     = ath_pci_remove,
+#ifdef CONFIG_PM
+	.suspend    = ath_pci_suspend,
+	.resume     = ath_pci_resume,
+#endif /* CONFIG_PM */
+};
+
+int __init ath_pci_init(void)
+{
+	return pci_register_driver(&ath_pci_driver);
+}
+
+void ath_pci_exit(void)
+{
+	pci_unregister_driver(&ath_pci_driver);
+}
-- 
1.5.3.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 06/11] ath9k: introduce platform driver for AHB bus support
  2009-01-07 10:09 [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs Gabor Juhos
                   ` (4 preceding siblings ...)
  2009-01-07 10:09 ` [PATCH 05/11] ath9k: move PCI code into separate file Gabor Juhos
@ 2009-01-07 10:09 ` Gabor Juhos
  2009-01-07 10:09 ` [PATCH 07/11] ath9k: get EEPROM contents from platform data on AHB bus Gabor Juhos
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 10:09 UTC (permalink / raw)
  To: John W. Linville
  Cc: Luis R. Rodriguez, Jouni Malinen, ath9k-devel@lists.ath9k.org,
	linux-wireless@vger.kernel.org, Felix Fietkau, Christoph Hellwig,
	Sujith Manoharan, Gabor Juhos, Imre Kaloz

This patch adds the platform_driver itself, and modifies the main driver
to register it.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
 drivers/net/wireless/ath9k/Makefile |    1 +
 drivers/net/wireless/ath9k/ahb.c    |  179 +++++++++++++++++++++++++++++++++++
 drivers/net/wireless/ath9k/core.h   |    9 ++
 drivers/net/wireless/ath9k/main.c   |   10 ++
 4 files changed, 199 insertions(+), 0 deletions(-)

diff --git a/drivers/net/wireless/ath9k/Makefile b/drivers/net/wireless/ath9k/Makefile
index af3f39b..0062958 100644
--- a/drivers/net/wireless/ath9k/Makefile
+++ b/drivers/net/wireless/ath9k/Makefile
@@ -12,6 +12,7 @@ ath9k-y +=	hw.o \
 		rc.o
 
 ath9k-$(CONFIG_PCI) += pci.o
+ath9k-$(CONFIG_ATHEROS_AR71XX) += ahb.o
 ath9k-$(CONFIG_ATH9K_DEBUG) += debug.o
 
 obj-$(CONFIG_ATH9K) += ath9k.o
diff --git a/drivers/net/wireless/ath9k/ahb.c b/drivers/net/wireless/ath9k/ahb.c
new file mode 100644
index 0000000..0a6fa0e
--- /dev/null
+++ b/drivers/net/wireless/ath9k/ahb.c
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2008 Atheros Communications Inc.
+ * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
+ * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <linux/nl80211.h>
+#include <linux/platform_device.h>
+#include "core.h"
+#include "reg.h"
+#include "hw.h"
+
+/* return bus cachesize in 4B word units */
+static void ath_ahb_read_cachesize(struct ath_softc *sc, int *csz)
+{
+	*csz = L1_CACHE_BYTES >> 2;
+}
+
+static void ath_ahb_cleanup(struct ath_softc *sc)
+{
+	struct ieee80211_hw *hw = sc->hw;
+
+	free_irq(sc->irq, sc);
+
+	ath_detach(sc);
+	iounmap(sc->mem);
+	ieee80211_free_hw(hw);
+}
+
+static struct ath_bus_ops ath_ahb_bus_ops  = {
+	.read_cachesize = ath_ahb_read_cachesize,
+	.cleanup = ath_ahb_cleanup,
+};
+
+static int ath_ahb_probe(struct platform_device *pdev)
+{
+	void __iomem *mem;
+	struct ath_softc *sc;
+	struct ieee80211_hw *hw;
+	struct resource *res;
+	int irq;
+	int ret = 0;
+	struct ath_hal *ah;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (res == NULL) {
+		dev_err(&pdev->dev, "no memory resource found\n");
+		ret = -ENXIO;
+		goto err_out;
+	}
+
+	mem = ioremap_nocache(res->start, res->end - res->start + 1);
+	if (mem == NULL) {
+		dev_err(&pdev->dev, "ioremap failed\n");
+		ret = -ENOMEM;
+		goto err_out;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	if (res == NULL) {
+		dev_err(&pdev->dev, "no IRQ resource found\n");
+		ret = -ENXIO;
+		goto err_iounmap;
+	}
+
+	irq = res->start;
+
+	hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
+	if (hw == NULL) {
+		dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
+		ret = -ENOMEM;
+		goto err_iounmap;
+	}
+
+	hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
+		IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
+		IEEE80211_HW_SIGNAL_DBM |
+		IEEE80211_HW_NOISE_DBM;
+
+	hw->wiphy->interface_modes =
+		BIT(NL80211_IFTYPE_AP) |
+		BIT(NL80211_IFTYPE_STATION) |
+		BIT(NL80211_IFTYPE_ADHOC);
+
+	SET_IEEE80211_DEV(hw, &pdev->dev);
+	platform_set_drvdata(pdev, hw);
+
+	sc = hw->priv;
+	sc->hw = hw;
+	sc->dev = &pdev->dev;
+	sc->mem = mem;
+	sc->bus_ops = &ath_ahb_bus_ops;
+	sc->irq = irq;
+
+	ret = ath_attach(AR5416_AR9100_DEVID, sc);
+	if (ret != 0) {
+		dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
+		ret = -ENODEV;
+		goto err_free_hw;
+	}
+
+	ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
+	if (ret) {
+		dev_err(&pdev->dev, "request_irq failed, err=%d\n", ret);
+		ret = -EIO;
+		goto err_detach;
+	}
+
+	ah = sc->sc_ah;
+	printk(KERN_INFO
+	       "%s: Atheros AR%s MAC/BB Rev:%x, "
+	       "AR%s RF Rev:%x, mem=0x%lx, irq=%d\n",
+	       wiphy_name(hw->wiphy),
+	       ath_mac_bb_name(ah->ah_macVersion),
+	       ah->ah_macRev,
+	       ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
+	       ah->ah_phyRev,
+	       (unsigned long)mem, irq);
+
+	return 0;
+
+ err_detach:
+	ath_detach(sc);
+ err_free_hw:
+	ieee80211_free_hw(hw);
+	platform_set_drvdata(pdev, NULL);
+ err_iounmap:
+	iounmap(mem);
+ err_out:
+	return ret;
+}
+
+static int ath_ahb_remove(struct platform_device *pdev)
+{
+	struct ieee80211_hw *hw = platform_get_drvdata(pdev);
+
+	if (hw) {
+		struct ath_softc *sc = hw->priv;
+
+		free_irq(sc->irq, sc);
+		ath_detach(sc);
+		iounmap(sc->mem);
+		ieee80211_free_hw(hw);
+		platform_set_drvdata(pdev, NULL);
+	}
+
+	return 0;
+}
+
+static struct platform_driver ath_ahb_driver = {
+	.probe      = ath_ahb_probe,
+	.remove     = ath_ahb_remove,
+	.driver		= {
+		.name	= "ath9k",
+		.owner	= THIS_MODULE,
+	},
+};
+
+int ath_ahb_init(void)
+{
+	return platform_driver_register(&ath_ahb_driver);
+}
+
+void ath_ahb_exit(void)
+{
+	platform_driver_register(&ath_ahb_driver);
+}
diff --git a/drivers/net/wireless/ath9k/core.h b/drivers/net/wireless/ath9k/core.h
index a7cdbed..e162ab1 100644
--- a/drivers/net/wireless/ath9k/core.h
+++ b/drivers/net/wireless/ath9k/core.h
@@ -705,6 +705,7 @@ struct ath_softc {
 	struct tasklet_struct bcon_tasklet;
 	struct ath_hal *sc_ah;
 	void __iomem *mem;
+	int irq;
 	spinlock_t sc_resetlock;
 	struct mutex mutex;
 
@@ -782,4 +783,12 @@ static inline int ath_pci_init(void) { return 0; };
 static inline void ath_pci_exit(void) {};
 #endif
 
+#ifdef CONFIG_ATHEROS_AR71XX
+int ath_ahb_init(void);
+void ath_ahb_exit(void);
+#else
+static inline int ath_ahb_init(void) { return 0; };
+static inline void ath_ahb_exit(void) {};
+#endif
+
 #endif /* CORE_H */
diff --git a/drivers/net/wireless/ath9k/main.c b/drivers/net/wireless/ath9k/main.c
index a1b3f82..f2dc538 100644
--- a/drivers/net/wireless/ath9k/main.c
+++ b/drivers/net/wireless/ath9k/main.c
@@ -2514,8 +2514,17 @@ static int __init ath9k_init(void)
 		goto err_rate_unregister;
 	}
 
+	error = ath_ahb_init();
+	if (error < 0) {
+		error = -ENODEV;
+		goto err_pci_exit;
+	}
+
 	return 0;
 
+ err_pci_exit:
+	ath_pci_exit();
+
  err_rate_unregister:
 	ath_rate_control_unregister();
  err_out:
@@ -2525,6 +2534,7 @@ module_init(ath9k_init);
 
 static void __exit ath9k_exit(void)
 {
+	ath_ahb_exit();
 	ath_pci_exit();
 	ath_rate_control_unregister();
 	printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
-- 
1.5.3.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 07/11] ath9k: get EEPROM contents from platform data on AHB bus
  2009-01-07 10:09 [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs Gabor Juhos
                   ` (5 preceding siblings ...)
  2009-01-07 10:09 ` [PATCH 06/11] ath9k: introduce platform driver for AHB bus support Gabor Juhos
@ 2009-01-07 10:09 ` Gabor Juhos
  2009-01-07 10:09 ` [PATCH 08/11] ath9k: enable support for AR9100 Gabor Juhos
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 10:09 UTC (permalink / raw)
  To: John W. Linville
  Cc: Luis R. Rodriguez, Jouni Malinen, ath9k-devel@lists.ath9k.org,
	linux-wireless@vger.kernel.org, Felix Fietkau, Christoph Hellwig,
	Sujith Manoharan, Gabor Juhos, Imre Kaloz

On the AR913x SOCs we have to provide EEPROM contents via platform_data,
because accessing the flash via MMIO is not safe. Additionally different
boards may store the radio calibration data at different locations.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
 drivers/net/wireless/ath9k/ahb.c    |   27 ++++++++++++++++++
 drivers/net/wireless/ath9k/core.h   |    1 +
 drivers/net/wireless/ath9k/eeprom.c |   51 ++--------------------------------
 drivers/net/wireless/ath9k/pci.c    |   18 ++++++++++++
 include/linux/ath9k_platform.h      |   28 +++++++++++++++++++
 5 files changed, 77 insertions(+), 48 deletions(-)

diff --git a/drivers/net/wireless/ath9k/ahb.c b/drivers/net/wireless/ath9k/ahb.c
index 0a6fa0e..602c20a 100644
--- a/drivers/net/wireless/ath9k/ahb.c
+++ b/drivers/net/wireless/ath9k/ahb.c
@@ -18,6 +18,7 @@
 
 #include <linux/nl80211.h>
 #include <linux/platform_device.h>
+#include <linux/ath9k_platform.h>
 #include "core.h"
 #include "reg.h"
 #include "hw.h"
@@ -39,9 +40,29 @@ static void ath_ahb_cleanup(struct ath_softc *sc)
 	ieee80211_free_hw(hw);
 }
 
+static bool ath_ahb_eeprom_read(struct ath_hal *ah, u32 off, u16 *data)
+{
+	struct ath_softc *sc = ah->ah_sc;
+	struct platform_device *pdev = to_platform_device(sc->dev);
+	struct ath9k_platform_data *pdata;
+
+	pdata = (struct ath9k_platform_data *) pdev->dev.platform_data;
+	if (off >= (ARRAY_SIZE(pdata->eeprom_data))) {
+		DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
+			"%s: flash read failed, offset %08x is out of range\n",
+				__func__, off);
+		return false;
+	}
+
+	*data = pdata->eeprom_data[off];
+	return true;
+}
+
 static struct ath_bus_ops ath_ahb_bus_ops  = {
 	.read_cachesize = ath_ahb_read_cachesize,
 	.cleanup = ath_ahb_cleanup,
+
+	.eeprom_read = ath_ahb_eeprom_read,
 };
 
 static int ath_ahb_probe(struct platform_device *pdev)
@@ -54,6 +75,12 @@ static int ath_ahb_probe(struct platform_device *pdev)
 	int ret = 0;
 	struct ath_hal *ah;
 
+	if (!pdev->dev.platform_data) {
+		dev_err(&pdev->dev, "no platform data specified\n");
+		ret = -EINVAL;
+		goto err_out;
+	}
+
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (res == NULL) {
 		dev_err(&pdev->dev, "no memory resource found\n");
diff --git a/drivers/net/wireless/ath9k/core.h b/drivers/net/wireless/ath9k/core.h
index e162ab1..e0d665f 100644
--- a/drivers/net/wireless/ath9k/core.h
+++ b/drivers/net/wireless/ath9k/core.h
@@ -696,6 +696,7 @@ enum PROT_MODE {
 struct ath_bus_ops {
 	void		(*read_cachesize)(struct ath_softc *sc, int *csz);
 	void		(*cleanup)(struct ath_softc *sc);
+	bool		(*eeprom_read)(struct ath_hal *ah, u32 off, u16 *data);
 };
 
 struct ath_softc {
diff --git a/drivers/net/wireless/ath9k/eeprom.c b/drivers/net/wireless/ath9k/eeprom.c
index 0f29d31..cf1a5ff 100644
--- a/drivers/net/wireless/ath9k/eeprom.c
+++ b/drivers/net/wireless/ath9k/eeprom.c
@@ -91,53 +91,11 @@ static inline bool ath9k_hw_get_lower_upper_index(u8 target, u8 *pList,
 	return false;
 }
 
-static bool ath9k_hw_eeprom_read(struct ath_hal *ah, u32 off, u16 *data)
-{
-	(void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
-
-	if (!ath9k_hw_wait(ah,
-			   AR_EEPROM_STATUS_DATA,
-			   AR_EEPROM_STATUS_DATA_BUSY |
-			   AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0)) {
-		return false;
-	}
-
-	*data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
-		   AR_EEPROM_STATUS_DATA_VAL);
-
-	return true;
-}
-
-static int ath9k_hw_flash_map(struct ath_hal *ah)
-{
-	struct ath_hal_5416 *ahp = AH5416(ah);
-
-	ahp->ah_cal_mem = ioremap(AR5416_EEPROM_START_ADDR, AR5416_EEPROM_MAX);
-
-	if (!ahp->ah_cal_mem) {
-		DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
-			"cannot remap eeprom region \n");
-		return -EIO;
-	}
-
-	return 0;
-}
-
-static bool ath9k_hw_flash_read(struct ath_hal *ah, u32 off, u16 *data)
-{
-	struct ath_hal_5416 *ahp = AH5416(ah);
-
-	*data = ioread16(ahp->ah_cal_mem + off);
-
-	return true;
-}
-
 static inline bool ath9k_hw_nvram_read(struct ath_hal *ah, u32 off, u16 *data)
 {
-	if (ath9k_hw_use_flash(ah))
-		return ath9k_hw_flash_read(ah, off, data);
-	else
-		return ath9k_hw_eeprom_read(ah, off, data);
+	struct ath_softc *sc = ah->ah_sc;
+
+	return sc->bus_ops->eeprom_read(ah, off, data);
 }
 
 static bool ath9k_hw_fill_4k_eeprom(struct ath_hal *ah)
@@ -2825,9 +2783,6 @@ int ath9k_hw_eeprom_attach(struct ath_hal *ah)
 	int status;
 	struct ath_hal_5416 *ahp = AH5416(ah);
 
-	if (ath9k_hw_use_flash(ah))
-		ath9k_hw_flash_map(ah);
-
 	if (AR_SREV_9285(ah))
 		ahp->ah_eep_map = EEP_MAP_4KBITS;
 	else
diff --git a/drivers/net/wireless/ath9k/pci.c b/drivers/net/wireless/ath9k/pci.c
index 02c946e..fa2301d 100644
--- a/drivers/net/wireless/ath9k/pci.c
+++ b/drivers/net/wireless/ath9k/pci.c
@@ -62,9 +62,27 @@ static void ath_pci_cleanup(struct ath_softc *sc)
 	ieee80211_free_hw(sc->hw);
 }
 
+static bool ath_pci_eeprom_read(struct ath_hal *ah, u32 off, u16 *data)
+{
+	(void)REG_READ(ah, AR5416_EEPROM_OFFSET + (off << AR5416_EEPROM_S));
+
+	if (!ath9k_hw_wait(ah,
+			   AR_EEPROM_STATUS_DATA,
+			   AR_EEPROM_STATUS_DATA_BUSY |
+			   AR_EEPROM_STATUS_DATA_PROT_ACCESS, 0)) {
+		return false;
+	}
+
+	*data = MS(REG_READ(ah, AR_EEPROM_STATUS_DATA),
+		   AR_EEPROM_STATUS_DATA_VAL);
+
+	return true;
+}
+
 static struct ath_bus_ops ath_pci_bus_ops = {
 	.read_cachesize = ath_pci_read_cachesize,
 	.cleanup = ath_pci_cleanup,
+	.eeprom_read = ath_pci_eeprom_read,
 };
 
 static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
diff --git a/include/linux/ath9k_platform.h b/include/linux/ath9k_platform.h
new file mode 100644
index 0000000..b847fc7
--- /dev/null
+++ b/include/linux/ath9k_platform.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2008 Atheros Communications Inc.
+ * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
+ * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _LINUX_ATH9K_PLATFORM_H
+#define _LINUX_ATH9K_PLATFORM_H
+
+#define ATH9K_PLAT_EEP_MAX_WORDS	2048
+
+struct ath9k_platform_data {
+	u16 eeprom_data[ATH9K_PLAT_EEP_MAX_WORDS];
+};
+
+#endif /* _LINUX_ATH9K_PLATFORM_H */
-- 
1.5.3.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 08/11] ath9k: enable support for AR9100
  2009-01-07 10:09 [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs Gabor Juhos
                   ` (6 preceding siblings ...)
  2009-01-07 10:09 ` [PATCH 07/11] ath9k: get EEPROM contents from platform data on AHB bus Gabor Juhos
@ 2009-01-07 10:09 ` Gabor Juhos
  2009-01-07 10:29   ` Johannes Berg
  2009-01-07 10:09 ` [PATCH 09/11] ath9k: remove (u16) casts from rtc register access Gabor Juhos
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 10:09 UTC (permalink / raw)
  To: John W. Linville
  Cc: Luis R. Rodriguez, Jouni Malinen, ath9k-devel@lists.ath9k.org,
	linux-wireless@vger.kernel.org, Felix Fietkau, Christoph Hellwig,
	Sujith Manoharan, Gabor Juhos, Imre Kaloz

Because we have support for the AR9100 devices now, we can enable them.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
 drivers/net/wireless/ath9k/hw.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/net/wireless/ath9k/hw.c b/drivers/net/wireless/ath9k/hw.c
index 088d968..e4aa39e 100644
--- a/drivers/net/wireless/ath9k/hw.c
+++ b/drivers/net/wireless/ath9k/hw.c
@@ -373,6 +373,8 @@ static const char *ath9k_hw_devname(u16 devid)
 		return "Atheros 5418";
 	case AR9160_DEVID_PCI:
 		return "Atheros 9160";
+	case AR5416_AR9100_DEVID:
+		return "Atheros 9100";
 	case AR9280_DEVID_PCI:
 	case AR9280_DEVID_PCIE:
 		return "Atheros 9280";
@@ -1176,6 +1178,7 @@ struct ath_hal *ath9k_hw_attach(u16 devid, struct ath_softc *sc,
 	switch (devid) {
 	case AR5416_DEVID_PCI:
 	case AR5416_DEVID_PCIE:
+	case AR5416_AR9100_DEVID:
 	case AR9160_DEVID_PCI:
 	case AR9280_DEVID_PCI:
 	case AR9280_DEVID_PCIE:
-- 
1.5.3.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 09/11] ath9k: remove (u16) casts from rtc register access
  2009-01-07 10:09 [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs Gabor Juhos
                   ` (7 preceding siblings ...)
  2009-01-07 10:09 ` [PATCH 08/11] ath9k: enable support for AR9100 Gabor Juhos
@ 2009-01-07 10:09 ` Gabor Juhos
  2009-01-07 10:09 ` [PATCH 10/11] ath9k: fix ar5416Addac_9100 values Gabor Juhos
  2009-01-07 10:09 ` [PATCH 11/11] ath9k: fix null pointer dereference in ani monitor code Gabor Juhos
  10 siblings, 0 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 10:09 UTC (permalink / raw)
  To: John W. Linville
  Cc: Luis R. Rodriguez, Jouni Malinen, ath9k-devel@lists.ath9k.org,
	linux-wireless@vger.kernel.org, Felix Fietkau, Christoph Hellwig,
	Sujith Manoharan, Gabor Juhos, Imre Kaloz

The RTC register offsets don't fit into 'u16' on the AR913x, so we have
to remove the existing casts.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
 drivers/net/wireless/ath9k/hw.c |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/ath9k/hw.c b/drivers/net/wireless/ath9k/hw.c
index e4aa39e..8bfa216 100644
--- a/drivers/net/wireless/ath9k/hw.c
+++ b/drivers/net/wireless/ath9k/hw.c
@@ -1010,7 +1010,7 @@ static void ath9k_hw_init_pll(struct ath_hal *ah,
 				pll |= SM(0xb, AR_RTC_PLL_DIV);
 		}
 	}
-	REG_WRITE(ah, (u16) (AR_RTC_PLL_CONTROL), pll);
+	REG_WRITE(ah, (AR_RTC_PLL_CONTROL), pll);
 
 	udelay(RTC_PLL_SETTLE_DELAY);
 
@@ -1550,11 +1550,11 @@ static bool ath9k_hw_set_reset(struct ath_hal *ah, int type)
 			rst_flags |= AR_RTC_RC_MAC_COLD;
 	}
 
-	REG_WRITE(ah, (u16) (AR_RTC_RC), rst_flags);
+	REG_WRITE(ah, (AR_RTC_RC), rst_flags);
 	udelay(50);
 
-	REG_WRITE(ah, (u16) (AR_RTC_RC), 0);
-	if (!ath9k_hw_wait(ah, (u16) (AR_RTC_RC), AR_RTC_RC_M, 0)) {
+	REG_WRITE(ah, (AR_RTC_RC), 0);
+	if (!ath9k_hw_wait(ah, (AR_RTC_RC), AR_RTC_RC_M, 0)) {
 		DPRINTF(ah->ah_sc, ATH_DBG_RESET,
 			"RTC stuck in MAC reset\n");
 		return false;
@@ -1576,8 +1576,8 @@ static bool ath9k_hw_set_reset_power_on(struct ath_hal *ah)
 	REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
 		  AR_RTC_FORCE_WAKE_ON_INT);
 
-	REG_WRITE(ah, (u16) (AR_RTC_RESET), 0);
-	REG_WRITE(ah, (u16) (AR_RTC_RESET), 1);
+	REG_WRITE(ah, (AR_RTC_RESET), 0);
+	REG_WRITE(ah, (AR_RTC_RESET), 1);
 
 	if (!ath9k_hw_wait(ah,
 			   AR_RTC_STATUS,
@@ -2602,7 +2602,7 @@ static void ath9k_set_power_sleep(struct ath_hal *ah, int setChip)
 		if (!AR_SREV_9100(ah))
 			REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
 
-		REG_CLR_BIT(ah, (u16) (AR_RTC_RESET),
+		REG_CLR_BIT(ah, (AR_RTC_RESET),
 			    AR_RTC_RESET_EN);
 	}
 }
-- 
1.5.3.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 10/11] ath9k: fix ar5416Addac_9100 values
  2009-01-07 10:09 [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs Gabor Juhos
                   ` (8 preceding siblings ...)
  2009-01-07 10:09 ` [PATCH 09/11] ath9k: remove (u16) casts from rtc register access Gabor Juhos
@ 2009-01-07 10:09 ` Gabor Juhos
  2009-01-07 10:09 ` [PATCH 11/11] ath9k: fix null pointer dereference in ani monitor code Gabor Juhos
  10 siblings, 0 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 10:09 UTC (permalink / raw)
  To: John W. Linville
  Cc: Luis R. Rodriguez, Jouni Malinen, ath9k-devel@lists.ath9k.org,
	linux-wireless@vger.kernel.org, Felix Fietkau, Christoph Hellwig,
	Sujith Manoharan, Gabor Juhos, Imre Kaloz

Writing the register at offset 0x98c4 causes a deadlock on the AR913x
SoCs. Although i don't have detailed knowledge about these registers,
but if i change the register offset according to the 'ar5416Addac' table,
it works. Additionally there is no reference to the 0x98c4 elsewhere.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
 drivers/net/wireless/ath9k/initvals.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/wireless/ath9k/initvals.h b/drivers/net/wireless/ath9k/initvals.h
index a1bc631..d492363 100644
--- a/drivers/net/wireless/ath9k/initvals.h
+++ b/drivers/net/wireless/ath9k/initvals.h
@@ -658,7 +658,7 @@ static const u32 ar5416Addac_9100[][2] = {
     {0x0000989c,  0x00000000 },
     {0x0000989c,  0x00000000 },
     {0x0000989c,  0x00000000 },
-    {0x000098c4,  0x00000000 },
+    {0x000098cc,  0x00000000 },
 };
 
 static const u32 ar5416Modes[][6] = {
-- 
1.5.3.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 11/11] ath9k: fix null pointer dereference in ani monitor code
  2009-01-07 10:09 [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs Gabor Juhos
                   ` (9 preceding siblings ...)
  2009-01-07 10:09 ` [PATCH 10/11] ath9k: fix ar5416Addac_9100 values Gabor Juhos
@ 2009-01-07 10:09 ` Gabor Juhos
  10 siblings, 0 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 10:09 UTC (permalink / raw)
  To: John W. Linville
  Cc: Luis R. Rodriguez, Jouni Malinen, ath9k-devel@lists.ath9k.org,
	linux-wireless@vger.kernel.org, Felix Fietkau, Christoph Hellwig,
	Sujith Manoharan, Gabor Juhos, Imre Kaloz

In 'ath9k_ani_reset' the 'ahp->ah_curani' will be initialized only
if 'DO_ANI(ah)' true. In 'ath9k_hw_ani_monitor' we are using
'ahp->ah_curani' unconditionally, and it will cause a NULL pointer
dereference on AR9100.

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Imre Kaloz <kaloz@openwrt.org>
---
 drivers/net/wireless/ath9k/ani.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/ath9k/ani.c b/drivers/net/wireless/ath9k/ani.c
index 4dd0860..42197ff 100644
--- a/drivers/net/wireless/ath9k/ani.c
+++ b/drivers/net/wireless/ath9k/ani.c
@@ -551,6 +551,9 @@ void ath9k_hw_ani_monitor(struct ath_hal *ah,
 	struct ar5416AniState *aniState;
 	int32_t listenTime;
 
+	if (!DO_ANI(ah))
+		return;
+
 	aniState = ahp->ah_curani;
 	ahp->ah_stats.ast_nodestats = *stats;
 
@@ -610,9 +613,6 @@ void ath9k_hw_ani_monitor(struct ath_hal *ah,
 		aniState->cckPhyErrCount = cckPhyErrCnt;
 	}
 
-	if (!DO_ANI(ah))
-		return;
-
 	if (aniState->listenTime > 5 * ahp->ah_aniPeriod) {
 		if (aniState->ofdmPhyErrCount <= aniState->listenTime *
 		    aniState->ofdmTrigLow / 1000 &&
-- 
1.5.3.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 04/11] ath9k: introduce bus specific cleanup routine
  2009-01-07 10:09 ` [PATCH 04/11] ath9k: introduce bus specific cleanup routine Gabor Juhos
@ 2009-01-07 10:24   ` Johannes Berg
  2009-01-07 17:34     ` Gabor Juhos
  2009-01-07 10:27   ` Johannes Berg
  1 sibling, 1 reply; 17+ messages in thread
From: Johannes Berg @ 2009-01-07 10:24 UTC (permalink / raw)
  To: Gabor Juhos
  Cc: John W. Linville, Luis R. Rodriguez, Jouni Malinen,
	ath9k-devel@lists.ath9k.org, linux-wireless@vger.kernel.org,
	Felix Fietkau, Christoph Hellwig, Sujith Manoharan, Imre Kaloz

[-- Attachment #1: Type: text/plain, Size: 539 bytes --]

On Wed, 2009-01-07 at 11:09 +0100, Gabor Juhos wrote:

>  			/* Deinitialize the device */
> -			ath_detach(sc);
> -			if (to_pci_dev(sc->dev)->irq)
> -				free_irq(to_pci_dev(sc->dev)->irq, sc);
> -			pci_iounmap(to_pci_dev(sc->dev), sc->mem);
> -			pci_release_region(to_pci_dev(sc->dev), 0);
> -			pci_disable_device(to_pci_dev(sc->dev));
> -			ieee80211_free_hw(sc->hw);
> +			ath_bus_cleanup(sc);

And how is ath_detach() or ieee80211_free_hw() bus specific? That should
not be in the bus specific function.

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 04/11] ath9k: introduce bus specific cleanup routine
  2009-01-07 10:09 ` [PATCH 04/11] ath9k: introduce bus specific cleanup routine Gabor Juhos
  2009-01-07 10:24   ` Johannes Berg
@ 2009-01-07 10:27   ` Johannes Berg
  1 sibling, 0 replies; 17+ messages in thread
From: Johannes Berg @ 2009-01-07 10:27 UTC (permalink / raw)
  To: Gabor Juhos
  Cc: John W. Linville, Luis R. Rodriguez, Jouni Malinen,
	ath9k-devel@lists.ath9k.org, linux-wireless@vger.kernel.org,
	Felix Fietkau, Christoph Hellwig, Sujith Manoharan, Imre Kaloz

[-- Attachment #1: Type: text/plain, Size: 255 bytes --]

On Wed, 2009-01-07 at 11:09 +0100, Gabor Juhos wrote:

> +	ath_detach(sc);
> +	if (pdev->irq)
> +		free_irq(pdev->irq, sc);

the irq stuff also need not be bus specific, if the bus specific code
tells the generic code which irq to use

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 08/11] ath9k: enable support for AR9100
  2009-01-07 10:09 ` [PATCH 08/11] ath9k: enable support for AR9100 Gabor Juhos
@ 2009-01-07 10:29   ` Johannes Berg
  2009-01-07 14:37     ` Gabor Juhos
  0 siblings, 1 reply; 17+ messages in thread
From: Johannes Berg @ 2009-01-07 10:29 UTC (permalink / raw)
  To: Gabor Juhos
  Cc: John W. Linville, Luis R. Rodriguez, Jouni Malinen,
	ath9k-devel@lists.ath9k.org, linux-wireless@vger.kernel.org,
	Felix Fietkau, Christoph Hellwig, Sujith Manoharan, Imre Kaloz

[-- Attachment #1: Type: text/plain, Size: 184 bytes --]

On Wed, 2009-01-07 at 11:09 +0100, Gabor Juhos wrote:
> Because we have support for the AR9100 devices now, we can enable them.

should be later in the series, I think

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 08/11] ath9k: enable support for AR9100
  2009-01-07 10:29   ` Johannes Berg
@ 2009-01-07 14:37     ` Gabor Juhos
  0 siblings, 0 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 14:37 UTC (permalink / raw)
  To: Johannes Berg
  Cc: John W. Linville, Luis R. Rodriguez, Jouni Malinen,
	ath9k-devel@lists.ath9k.org, linux-wireless@vger.kernel.org,
	Felix Fietkau, Christoph Hellwig, Sujith Manoharan, Imre Kaloz

Johannes Berg =EDrta:
> On Wed, 2009-01-07 at 11:09 +0100, Gabor Juhos wrote:
>> Because we have support for the AR9100 devices now, we can enable th=
em.
>=20
> should be later in the series, I think

Yes. I will move it to the end of the series.

-Gabor
--
To unsubscribe from this list: send the line "unsubscribe linux-wireles=
s" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 04/11] ath9k: introduce bus specific cleanup routine
  2009-01-07 10:24   ` Johannes Berg
@ 2009-01-07 17:34     ` Gabor Juhos
  0 siblings, 0 replies; 17+ messages in thread
From: Gabor Juhos @ 2009-01-07 17:34 UTC (permalink / raw)
  To: Johannes Berg
  Cc: John W. Linville, Luis R. Rodriguez, Jouni Malinen,
	ath9k-devel@lists.ath9k.org, linux-wireless@vger.kernel.org,
	Felix Fietkau, Christoph Hellwig, Sujith Manoharan, Imre Kaloz

Johannes Berg =EDrta:
> On Wed, 2009-01-07 at 11:09 +0100, Gabor Juhos wrote:
>=20
>>  			/* Deinitialize the device */
>> -			ath_detach(sc);
>> -			if (to_pci_dev(sc->dev)->irq)
>> -				free_irq(to_pci_dev(sc->dev)->irq, sc);
>> -			pci_iounmap(to_pci_dev(sc->dev), sc->mem);
>> -			pci_release_region(to_pci_dev(sc->dev), 0);
>> -			pci_disable_device(to_pci_dev(sc->dev));
>> -			ieee80211_free_hw(sc->hw);
>> +			ath_bus_cleanup(sc);
>=20
> And how is ath_detach() or ieee80211_free_hw() bus specific? That sho=
uld
> not be in the bus specific function.
>=20
> johannes

You are right. I guess this looks better:

diff --git a/drivers/net/wireless/ath9k/core.h b/drivers/net/wireless/a=
th9k/core.h
index 8e93d11..f9fa5c6 100644
--- a/drivers/net/wireless/ath9k/core.h
+++ b/drivers/net/wireless/ath9k/core.h
@@ -695,6 +695,7 @@ enum PROT_MODE {
=20
 struct ath_bus_ops {
 	void		(*read_cachesize)(struct ath_softc *sc, int *csz);
+	void		(*cleanup)(struct ath_softc *sc);
 };
=20
 struct ath_softc {
@@ -704,6 +705,7 @@ struct ath_softc {
 	struct tasklet_struct bcon_tasklet;
 	struct ath_hal *sc_ah;
 	void __iomem *mem;
+	int irq;
 	spinlock_t sc_resetlock;
 	struct mutex mutex;
=20
@@ -760,4 +762,9 @@ static inline void ath_read_cachesize(struct ath_so=
ftc *sc, int *csz)
 	sc->bus_ops->read_cachesize(sc, csz);
 }
=20
+static inline void ath_bus_cleanup(struct ath_softc *sc)
+{
+	sc->bus_ops->cleanup(sc);
+}
+
 #endif /* CORE_H */
diff --git a/drivers/net/wireless/ath9k/main.c b/drivers/net/wireless/a=
th9k/main.c
index 15824c1..349ac17 100644
--- a/drivers/net/wireless/ath9k/main.c
+++ b/drivers/net/wireless/ath9k/main.c
@@ -39,6 +39,7 @@ static struct pci_device_id ath_pci_id_table[] __devi=
nitdata =3D {
 };
=20
 static void ath_detach(struct ath_softc *sc);
+static void ath_cleanup(struct ath_softc *sc);
=20
 /* return bus cachesize in 4B word units */
=20
@@ -1267,13 +1268,7 @@ static int ath_start_rfkill_poll(struct ath_soft=
c *sc)
 			rfkill_free(sc->rf_kill.rfkill);
=20
 			/* Deinitialize the device */
-			ath_detach(sc);
-			if (to_pci_dev(sc->dev)->irq)
-				free_irq(to_pci_dev(sc->dev)->irq, sc);
-			pci_iounmap(to_pci_dev(sc->dev), sc->mem);
-			pci_release_region(to_pci_dev(sc->dev), 0);
-			pci_disable_device(to_pci_dev(sc->dev));
-			ieee80211_free_hw(sc->hw);
+			ath_cleanup(sc);
 			return -EIO;
 		} else {
 			sc->sc_flags |=3D SC_OP_RFKILL_REGISTERED;
@@ -1284,6 +1279,16 @@ static int ath_start_rfkill_poll(struct ath_soft=
c *sc)
 }
 #endif /* CONFIG_RFKILL */
=20
+static void ath_cleanup(struct ath_softc *sc)
+{
+	struct pci_dev *pdev =3D to_pci_dev(sc->dev);
+
+	ath_detach(sc);
+	free_irq(sc->irq, sc);
+	ath_bus_cleanup(sc);
+	ieee80211_free_hw(sc->hw);
+}
+
 static void ath_detach(struct ath_softc *sc)
 {
 	struct ieee80211_hw *hw =3D sc->hw;
@@ -2529,8 +2534,18 @@ ath_rf_name(u16 rf_version)
 	return "????";
 }
=20
+static void ath_pci_cleanup(struct ath_softc *sc)
+{
+	struct pci_dev *pdev =3D to_pci_dev(sc->dev);
+
+	pci_iounmap(pdev, sc->mem);
+	pci_release_region(pdev, 0);
+	pci_disable_device(pdev);
+}
+
 static struct ath_bus_ops ath_pci_bus_ops =3D {
 	.read_cachesize =3D ath_pci_read_cachesize,
+	.cleanup =3D ath_pci_cleanup,
 };
=20
 static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device=
_id *id)
@@ -2637,6 +2652,8 @@ static int ath_pci_probe(struct pci_dev *pdev, co=
nst struct pci_device_id *id)
 		goto bad4;
 	}
=20
+	sc->irq =3D pdev->irq;
+
 	ah =3D sc->sc_ah;
 	printk(KERN_INFO
 	       "%s: Atheros AR%s MAC/BB Rev:%x "
@@ -2667,13 +2684,7 @@ static void ath_pci_remove(struct pci_dev *pdev)
 	struct ieee80211_hw *hw =3D pci_get_drvdata(pdev);
 	struct ath_softc *sc =3D hw->priv;
=20
-	ath_detach(sc);
-	if (pdev->irq)
-		free_irq(pdev->irq, sc);
-	pci_iounmap(pdev, sc->mem);
-	pci_release_region(pdev, 0);
-	pci_disable_device(pdev);
-	ieee80211_free_hw(hw);
+	ath_cleanup(sc);
 }
=20
 #ifdef CONFIG_PM
--
To unsubscribe from this list: send the line "unsubscribe linux-wireles=
s" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2009-01-07 17:35 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-07 10:09 [PATCH 00/11] ath9k: add preliminary support for the AR913x SoCs Gabor Juhos
2009-01-07 10:09 ` [PATCH 01/11] ath9k: convert to struct device Gabor Juhos
2009-01-07 10:09 ` [PATCH 02/11] ath9k: convert to use bus-agnostic DMA routines Gabor Juhos
2009-01-07 10:09 ` [PATCH 03/11] ath9k: introduce bus specific cache size routine Gabor Juhos
2009-01-07 10:09 ` [PATCH 04/11] ath9k: introduce bus specific cleanup routine Gabor Juhos
2009-01-07 10:24   ` Johannes Berg
2009-01-07 17:34     ` Gabor Juhos
2009-01-07 10:27   ` Johannes Berg
2009-01-07 10:09 ` [PATCH 05/11] ath9k: move PCI code into separate file Gabor Juhos
2009-01-07 10:09 ` [PATCH 06/11] ath9k: introduce platform driver for AHB bus support Gabor Juhos
2009-01-07 10:09 ` [PATCH 07/11] ath9k: get EEPROM contents from platform data on AHB bus Gabor Juhos
2009-01-07 10:09 ` [PATCH 08/11] ath9k: enable support for AR9100 Gabor Juhos
2009-01-07 10:29   ` Johannes Berg
2009-01-07 14:37     ` Gabor Juhos
2009-01-07 10:09 ` [PATCH 09/11] ath9k: remove (u16) casts from rtc register access Gabor Juhos
2009-01-07 10:09 ` [PATCH 10/11] ath9k: fix ar5416Addac_9100 values Gabor Juhos
2009-01-07 10:09 ` [PATCH 11/11] ath9k: fix null pointer dereference in ani monitor code Gabor Juhos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).