linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH 0/3] net: via-rhine: add support for on-chip Rhine controllers
       [not found] <1385227995-3956-1-git-send-email-alchark@gmail.com>
@ 2013-11-30 19:07 ` Alexey Charkov
  2014-01-27 11:51 ` [PATCH 0/3] Resubmit: " Alexey Charkov
  1 sibling, 0 replies; 25+ messages in thread
From: Alexey Charkov @ 2013-11-30 19:07 UTC (permalink / raw)
  To: Roger Luethi, netdev, devicetree, linux-kernel, Tony Prisk; +Cc: Alexey Charkov

2013/11/23, Alexey Charkov <alchark@gmail.com>:
> This series introduces platform bus (OpenFirmware) binding for via-rhine,
> as used in various ARM-based Systems-on-Chip by VIA/WonderMedia.
>
> This has been tested on a WM8950-based VIA APC Rock development board
>
> Alexey Charkov (3):
>   net: via-rhine: switch to generic DMA functions
>   net: via-rhine: reduce usage of the PCI-specific struct
>   net: via-rhine: add OF bus binding
>
>  .../devicetree/bindings/net/via-rhine.txt          |  18 +
>  drivers/net/ethernet/via/Kconfig                   |   2 +-
>  drivers/net/ethernet/via/via-rhine.c               | 403
> ++++++++++++---------
>  3 files changed, 260 insertions(+), 163 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/net/via-rhine.txt
>
> --
> 1.8.1.5
>

Dear all,

There hasn't been any feedback on this so far (which is
understandable, given that it came pretty early in the release cycle).

Is there any chance to get this reviewed, to be eventually included in
net-next for 3.14? That would be highly appreciated.

Thanks a lot,
Alexey

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

* [PATCH 0/3] Resubmit: net: via-rhine: add support for on-chip Rhine controllers
       [not found] <1385227995-3956-1-git-send-email-alchark@gmail.com>
  2013-11-30 19:07 ` [PATCH 0/3] net: via-rhine: add support for on-chip Rhine controllers Alexey Charkov
@ 2014-01-27 11:51 ` Alexey Charkov
  2014-01-27 11:51   ` [PATCH 1/3] net: via-rhine: switch to generic DMA functions Alexey Charkov
                     ` (3 more replies)
  1 sibling, 4 replies; 25+ messages in thread
From: Alexey Charkov @ 2014-01-27 11:51 UTC (permalink / raw)
  To: netdev, linux, devicetree, rl, linux-kernel; +Cc: Alexey Charkov

This series introduces platform bus (OpenFirmware) binding for 
via-rhine, as used in various ARM-based Systems-on-Chip by 
VIA/WonderMedia.

This has been tested in OF configuration by myself on a WM8950-based VIA 
APC Rock development board, and in PCI configuration by Roger.

Unfortunately, I can't find my original submission from 30 Nov in any of 
the mailing list archives (must have done something stupid while 
sending). However, Roger seems to have received the patches fine, tested 
them on PCI and signed off, so I'm including his Signed-off-by: with 
this submission along with my own.

Please note that this series does not include any ifdefs for either PCI 
or OF case, so in Roger's set-up the third patch increased module size 
from 39372 to 40868 bytes (+3.8%). I'm following the example of 
via-velocity here, which didn't have ifdefs either (and I believe it is 
cleaner this way).

Not sure if it's appropriate for 3.14 at this point, but getting it 
merged to -next would be much appreciated.

Best regards,
Alexey

Alexey Charkov (3):
  net: via-rhine: switch to generic DMA functions
  net: via-rhine: reduce usage of the PCI-specific struct
  net: via-rhine: add OF bus binding

 .../devicetree/bindings/net/via-rhine.txt          |  18 +
 drivers/net/ethernet/via/Kconfig                   |   2 +-
 drivers/net/ethernet/via/via-rhine.c               | 403 ++++++++++++---------
 3 files changed, 260 insertions(+), 163 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/via-rhine.txt

-- 
1.8.5.1


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

* [PATCH 1/3] net: via-rhine: switch to generic DMA functions
  2014-01-27 11:51 ` [PATCH 0/3] Resubmit: " Alexey Charkov
@ 2014-01-27 11:51   ` Alexey Charkov
  2014-01-27 14:49     ` Ben Hutchings
  2014-01-27 11:51   ` [PATCH 2/3] net: via-rhine: reduce usage of the PCI-specific struct Alexey Charkov
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 25+ messages in thread
From: Alexey Charkov @ 2014-01-27 11:51 UTC (permalink / raw)
  To: netdev, linux, devicetree, rl, linux-kernel; +Cc: Alexey Charkov

Remove legacy PCI DMA wrappers and instead use generic DMA functions
directly in preparation for OF bus binding

Signed-off-by: Alexey Charkov <alchark@gmail.com>
Signed-off-by: Roger Luethi <rl@hellgate.ch>
---
 drivers/net/ethernet/via/via-rhine.c | 56 +++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index ef312bc..fee8732 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -919,10 +919,10 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		goto err_out;
 
 	/* this should always be supported */
-	rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+	rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
 	if (rc) {
 		dev_err(&pdev->dev,
-			"32-bit PCI DMA addresses not supported by the card!?\n");
+			"32-bit DMA addresses not supported by the card!?\n");
 		goto err_out;
 	}
 
@@ -1094,20 +1094,22 @@ static int alloc_ring(struct net_device* dev)
 	void *ring;
 	dma_addr_t ring_dma;
 
-	ring = pci_alloc_consistent(rp->pdev,
+	ring = dma_alloc_coherent(&rp->pdev->dev,
 				    RX_RING_SIZE * sizeof(struct rx_desc) +
 				    TX_RING_SIZE * sizeof(struct tx_desc),
-				    &ring_dma);
+				    &ring_dma,
+					GFP_ATOMIC);
 	if (!ring) {
 		netdev_err(dev, "Could not allocate DMA memory\n");
 		return -ENOMEM;
 	}
 	if (rp->quirks & rqRhineI) {
-		rp->tx_bufs = pci_alloc_consistent(rp->pdev,
+		rp->tx_bufs = dma_alloc_coherent(&rp->pdev->dev,
 						   PKT_BUF_SZ * TX_RING_SIZE,
-						   &rp->tx_bufs_dma);
+						   &rp->tx_bufs_dma,
+						   GFP_ATOMIC);
 		if (rp->tx_bufs == NULL) {
-			pci_free_consistent(rp->pdev,
+			dma_free_coherent(&rp->pdev->dev,
 				    RX_RING_SIZE * sizeof(struct rx_desc) +
 				    TX_RING_SIZE * sizeof(struct tx_desc),
 				    ring, ring_dma);
@@ -1127,14 +1129,14 @@ static void free_ring(struct net_device* dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
 
-	pci_free_consistent(rp->pdev,
+	dma_free_coherent(&rp->pdev->dev,
 			    RX_RING_SIZE * sizeof(struct rx_desc) +
 			    TX_RING_SIZE * sizeof(struct tx_desc),
 			    rp->rx_ring, rp->rx_ring_dma);
 	rp->tx_ring = NULL;
 
 	if (rp->tx_bufs)
-		pci_free_consistent(rp->pdev, PKT_BUF_SZ * TX_RING_SIZE,
+		dma_free_coherent(&rp->pdev->dev, PKT_BUF_SZ * TX_RING_SIZE,
 				    rp->tx_bufs, rp->tx_bufs_dma);
 
 	rp->tx_bufs = NULL;
@@ -1172,8 +1174,8 @@ static void alloc_rbufs(struct net_device *dev)
 			break;
 
 		rp->rx_skbuff_dma[i] =
-			pci_map_single(rp->pdev, skb->data, rp->rx_buf_sz,
-				       PCI_DMA_FROMDEVICE);
+			dma_map_single(&rp->pdev->dev, skb->data, rp->rx_buf_sz,
+				       DMA_FROM_DEVICE);
 		if (dma_mapping_error(&rp->pdev->dev, rp->rx_skbuff_dma[i])) {
 			rp->rx_skbuff_dma[i] = 0;
 			dev_kfree_skb(skb);
@@ -1195,9 +1197,9 @@ static void free_rbufs(struct net_device* dev)
 		rp->rx_ring[i].rx_status = 0;
 		rp->rx_ring[i].addr = cpu_to_le32(0xBADF00D0); /* An invalid address. */
 		if (rp->rx_skbuff[i]) {
-			pci_unmap_single(rp->pdev,
+			dma_unmap_single(&rp->pdev->dev,
 					 rp->rx_skbuff_dma[i],
-					 rp->rx_buf_sz, PCI_DMA_FROMDEVICE);
+					 rp->rx_buf_sz, DMA_FROM_DEVICE);
 			dev_kfree_skb(rp->rx_skbuff[i]);
 		}
 		rp->rx_skbuff[i] = NULL;
@@ -1236,10 +1238,10 @@ static void free_tbufs(struct net_device* dev)
 		rp->tx_ring[i].addr = cpu_to_le32(0xBADF00D0); /* An invalid address. */
 		if (rp->tx_skbuff[i]) {
 			if (rp->tx_skbuff_dma[i]) {
-				pci_unmap_single(rp->pdev,
+				dma_unmap_single(&rp->pdev->dev,
 						 rp->tx_skbuff_dma[i],
 						 rp->tx_skbuff[i]->len,
-						 PCI_DMA_TODEVICE);
+						 DMA_TO_DEVICE);
 			}
 			dev_kfree_skb(rp->tx_skbuff[i]);
 		}
@@ -1693,8 +1695,8 @@ static netdev_tx_t rhine_start_tx(struct sk_buff *skb,
 						       rp->tx_bufs));
 	} else {
 		rp->tx_skbuff_dma[entry] =
-			pci_map_single(rp->pdev, skb->data, skb->len,
-				       PCI_DMA_TODEVICE);
+			dma_map_single(&rp->pdev->dev, skb->data, skb->len,
+				       DMA_TO_DEVICE);
 		if (dma_mapping_error(&rp->pdev->dev, rp->tx_skbuff_dma[entry])) {
 			dev_kfree_skb(skb);
 			rp->tx_skbuff_dma[entry] = 0;
@@ -1829,10 +1831,10 @@ static void rhine_tx(struct net_device *dev)
 		}
 		/* Free the original skb. */
 		if (rp->tx_skbuff_dma[entry]) {
-			pci_unmap_single(rp->pdev,
+			dma_unmap_single(&rp->pdev->dev,
 					 rp->tx_skbuff_dma[entry],
 					 rp->tx_skbuff[entry]->len,
-					 PCI_DMA_TODEVICE);
+					 DMA_TO_DEVICE);
 		}
 		dev_kfree_skb(rp->tx_skbuff[entry]);
 		rp->tx_skbuff[entry] = NULL;
@@ -1922,19 +1924,19 @@ static int rhine_rx(struct net_device *dev, int limit)
 			if (pkt_len < rx_copybreak)
 				skb = netdev_alloc_skb_ip_align(dev, pkt_len);
 			if (skb) {
-				pci_dma_sync_single_for_cpu(rp->pdev,
+				dma_sync_single_for_cpu(&rp->pdev->dev,
 							    rp->rx_skbuff_dma[entry],
 							    rp->rx_buf_sz,
-							    PCI_DMA_FROMDEVICE);
+							    DMA_FROM_DEVICE);
 
 				skb_copy_to_linear_data(skb,
 						 rp->rx_skbuff[entry]->data,
 						 pkt_len);
 				skb_put(skb, pkt_len);
-				pci_dma_sync_single_for_device(rp->pdev,
+				dma_sync_single_for_device(&rp->pdev->dev,
 							       rp->rx_skbuff_dma[entry],
 							       rp->rx_buf_sz,
-							       PCI_DMA_FROMDEVICE);
+							       DMA_FROM_DEVICE);
 			} else {
 				skb = rp->rx_skbuff[entry];
 				if (skb == NULL) {
@@ -1943,10 +1945,10 @@ static int rhine_rx(struct net_device *dev, int limit)
 				}
 				rp->rx_skbuff[entry] = NULL;
 				skb_put(skb, pkt_len);
-				pci_unmap_single(rp->pdev,
+				dma_unmap_single(&rp->pdev->dev,
 						 rp->rx_skbuff_dma[entry],
 						 rp->rx_buf_sz,
-						 PCI_DMA_FROMDEVICE);
+						 DMA_FROM_DEVICE);
 			}
 
 			if (unlikely(desc_length & DescTag))
@@ -1977,9 +1979,9 @@ static int rhine_rx(struct net_device *dev, int limit)
 			if (skb == NULL)
 				break;	/* Better luck next round. */
 			rp->rx_skbuff_dma[entry] =
-				pci_map_single(rp->pdev, skb->data,
+				dma_map_single(&rp->pdev->dev, skb->data,
 					       rp->rx_buf_sz,
-					       PCI_DMA_FROMDEVICE);
+					       DMA_FROM_DEVICE);
 			if (dma_mapping_error(&rp->pdev->dev, rp->rx_skbuff_dma[entry])) {
 				dev_kfree_skb(skb);
 				rp->rx_skbuff_dma[entry] = 0;
-- 
1.8.5.1


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

* [PATCH 2/3] net: via-rhine: reduce usage of the PCI-specific struct
  2014-01-27 11:51 ` [PATCH 0/3] Resubmit: " Alexey Charkov
  2014-01-27 11:51   ` [PATCH 1/3] net: via-rhine: switch to generic DMA functions Alexey Charkov
@ 2014-01-27 11:51   ` Alexey Charkov
  2014-01-27 11:51   ` [PATCH 3/3] net: via-rhine: add OF bus binding Alexey Charkov
  2014-04-22 15:28   ` [PATCH v2 0/3] net: via-rhine: add support for on-chip Rhine controllers Alexey Charkov
  3 siblings, 0 replies; 25+ messages in thread
From: Alexey Charkov @ 2014-01-27 11:51 UTC (permalink / raw)
  To: netdev, linux, devicetree, rl, linux-kernel; +Cc: Alexey Charkov

Use more generic data structures instead of struct pci_dev wherever
possible in preparation for OF bus binding

Signed-off-by: Alexey Charkov <alchark@gmail.com>
Signed-off-by: Roger Luethi <rl@hellgate.ch>
---
 drivers/net/ethernet/via/via-rhine.c | 116 +++++++++++++++++++----------------
 1 file changed, 62 insertions(+), 54 deletions(-)

diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index fee8732..95c2e93 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -446,7 +446,8 @@ struct rhine_private {
 	unsigned char *tx_bufs;
 	dma_addr_t tx_bufs_dma;
 
-	struct pci_dev *pdev;
+	int revision;
+	int irq;
 	long pioaddr;
 	struct net_device *dev;
 	struct napi_struct napi;
@@ -701,7 +702,7 @@ static void rhine_reload_eeprom(long pioaddr, struct net_device *dev)
 static void rhine_poll(struct net_device *dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
-	const int irq = rp->pdev->irq;
+	const int irq = rp->irq;
 
 	disable_irq(irq);
 	rhine_interrupt(irq, dev);
@@ -871,6 +872,8 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct net_device *dev;
 	struct rhine_private *rp;
+	struct device *hwdev = &pdev->dev;
+	int revision = pdev->revision;
 	int i, rc;
 	u32 quirks;
 	long pioaddr;
@@ -893,21 +896,19 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	phy_id = 0;
 	quirks = 0;
 	name = "Rhine";
-	if (pdev->revision < VTunknown0) {
+	if (revision < VTunknown0) {
 		quirks = rqRhineI;
 		io_size = 128;
-	}
-	else if (pdev->revision >= VT6102) {
+	} else if (revision >= VT6102) {
 		quirks = rqWOL | rqForceReset;
-		if (pdev->revision < VT6105) {
+		if (revision < VT6105) {
 			name = "Rhine II";
 			quirks |= rqStatusWBRace;	/* Rhine-II exclusive */
-		}
-		else {
+		} else {
 			phy_id = 1;	/* Integrated PHY, phy_id fixed to 1 */
-			if (pdev->revision >= VT6105_B0)
+			if (revision >= VT6105_B0)
 				quirks |= rq6patterns;
-			if (pdev->revision < VT6105M)
+			if (revision < VT6105M)
 				name = "Rhine III";
 			else
 				name = "Rhine III (Management Adapter)";
@@ -919,10 +920,9 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		goto err_out;
 
 	/* this should always be supported */
-	rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+	rc = dma_set_mask(hwdev, DMA_BIT_MASK(32));
 	if (rc) {
-		dev_err(&pdev->dev,
-			"32-bit DMA addresses not supported by the card!?\n");
+		dev_err(hwdev, "32-bit DMA addresses not supported by the card!?\n");
 		goto err_out;
 	}
 
@@ -930,7 +930,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if ((pci_resource_len(pdev, 0) < io_size) ||
 	    (pci_resource_len(pdev, 1) < io_size)) {
 		rc = -EIO;
-		dev_err(&pdev->dev, "Insufficient PCI resources, aborting\n");
+		dev_err(hwdev, "Insufficient PCI resources, aborting\n");
 		goto err_out;
 	}
 
@@ -944,13 +944,13 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		rc = -ENOMEM;
 		goto err_out;
 	}
-	SET_NETDEV_DEV(dev, &pdev->dev);
+	SET_NETDEV_DEV(dev, hwdev);
 
 	rp = netdev_priv(dev);
 	rp->dev = dev;
+	rp->revision = revision;
 	rp->quirks = quirks;
 	rp->pioaddr = pioaddr;
-	rp->pdev = pdev;
 	rp->msg_enable = netif_msg_init(debug, RHINE_MSG_DEFAULT);
 
 	rc = pci_request_regions(pdev, DRV_NAME);
@@ -960,9 +960,9 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	ioaddr = pci_iomap(pdev, bar, io_size);
 	if (!ioaddr) {
 		rc = -EIO;
-		dev_err(&pdev->dev,
+		dev_err(hwdev,
 			"ioremap failed for device %s, region 0x%X @ 0x%lX\n",
-			pci_name(pdev), io_size, memaddr);
+			dev_name(hwdev), io_size, memaddr);
 		goto err_out_free_res;
 	}
 
@@ -977,7 +977,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		unsigned char b = readb(ioaddr+reg);
 		if (a != b) {
 			rc = -EIO;
-			dev_err(&pdev->dev,
+			dev_err(hwdev,
 				"MMIO do not match PIO [%02x] (%02x != %02x)\n",
 				reg, a, b);
 			goto err_out_unmap;
@@ -986,6 +986,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 #endif /* USE_MMIO */
 
 	rp->base = ioaddr;
+	rp->irq = pdev->irq;
 
 	u64_stats_init(&rp->tx_stats.syncp);
 	u64_stats_init(&rp->rx_stats.syncp);
@@ -1030,7 +1031,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (rp->quirks & rqRhineI)
 		dev->features |= NETIF_F_SG|NETIF_F_HW_CSUM;
 
-	if (pdev->revision >= VT6105M)
+	if (rp->revision >= VT6105M)
 		dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
 				 NETIF_F_HW_VLAN_CTAG_RX |
 				 NETIF_F_HW_VLAN_CTAG_FILTER;
@@ -1047,9 +1048,9 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 #else
 		    (long)ioaddr,
 #endif
-		    dev->dev_addr, pdev->irq);
+		    dev->dev_addr, rp->irq);
 
-	pci_set_drvdata(pdev, dev);
+	dev_set_drvdata(hwdev, dev);
 
 	{
 		u16 mii_cmd;
@@ -1091,10 +1092,11 @@ err_out:
 static int alloc_ring(struct net_device* dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	void *ring;
 	dma_addr_t ring_dma;
 
-	ring = dma_alloc_coherent(&rp->pdev->dev,
+	ring = dma_alloc_coherent(hwdev,
 				    RX_RING_SIZE * sizeof(struct rx_desc) +
 				    TX_RING_SIZE * sizeof(struct tx_desc),
 				    &ring_dma,
@@ -1104,12 +1106,12 @@ static int alloc_ring(struct net_device* dev)
 		return -ENOMEM;
 	}
 	if (rp->quirks & rqRhineI) {
-		rp->tx_bufs = dma_alloc_coherent(&rp->pdev->dev,
+		rp->tx_bufs = dma_alloc_coherent(hwdev,
 						   PKT_BUF_SZ * TX_RING_SIZE,
 						   &rp->tx_bufs_dma,
 						   GFP_ATOMIC);
 		if (rp->tx_bufs == NULL) {
-			dma_free_coherent(&rp->pdev->dev,
+			dma_free_coherent(hwdev,
 				    RX_RING_SIZE * sizeof(struct rx_desc) +
 				    TX_RING_SIZE * sizeof(struct tx_desc),
 				    ring, ring_dma);
@@ -1128,15 +1130,16 @@ static int alloc_ring(struct net_device* dev)
 static void free_ring(struct net_device* dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 
-	dma_free_coherent(&rp->pdev->dev,
+	dma_free_coherent(hwdev,
 			    RX_RING_SIZE * sizeof(struct rx_desc) +
 			    TX_RING_SIZE * sizeof(struct tx_desc),
 			    rp->rx_ring, rp->rx_ring_dma);
 	rp->tx_ring = NULL;
 
 	if (rp->tx_bufs)
-		dma_free_coherent(&rp->pdev->dev, PKT_BUF_SZ * TX_RING_SIZE,
+		dma_free_coherent(hwdev, PKT_BUF_SZ * TX_RING_SIZE,
 				    rp->tx_bufs, rp->tx_bufs_dma);
 
 	rp->tx_bufs = NULL;
@@ -1146,6 +1149,7 @@ static void free_ring(struct net_device* dev)
 static void alloc_rbufs(struct net_device *dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	dma_addr_t next;
 	int i;
 
@@ -1174,9 +1178,9 @@ static void alloc_rbufs(struct net_device *dev)
 			break;
 
 		rp->rx_skbuff_dma[i] =
-			dma_map_single(&rp->pdev->dev, skb->data, rp->rx_buf_sz,
+			dma_map_single(hwdev, skb->data, rp->rx_buf_sz,
 				       DMA_FROM_DEVICE);
-		if (dma_mapping_error(&rp->pdev->dev, rp->rx_skbuff_dma[i])) {
+		if (dma_mapping_error(hwdev, rp->rx_skbuff_dma[i])) {
 			rp->rx_skbuff_dma[i] = 0;
 			dev_kfree_skb(skb);
 			break;
@@ -1190,6 +1194,7 @@ static void alloc_rbufs(struct net_device *dev)
 static void free_rbufs(struct net_device* dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	int i;
 
 	/* Free all the skbuffs in the Rx queue. */
@@ -1197,7 +1202,7 @@ static void free_rbufs(struct net_device* dev)
 		rp->rx_ring[i].rx_status = 0;
 		rp->rx_ring[i].addr = cpu_to_le32(0xBADF00D0); /* An invalid address. */
 		if (rp->rx_skbuff[i]) {
-			dma_unmap_single(&rp->pdev->dev,
+			dma_unmap_single(hwdev,
 					 rp->rx_skbuff_dma[i],
 					 rp->rx_buf_sz, DMA_FROM_DEVICE);
 			dev_kfree_skb(rp->rx_skbuff[i]);
@@ -1230,6 +1235,7 @@ static void alloc_tbufs(struct net_device* dev)
 static void free_tbufs(struct net_device* dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	int i;
 
 	for (i = 0; i < TX_RING_SIZE; i++) {
@@ -1238,7 +1244,7 @@ static void free_tbufs(struct net_device* dev)
 		rp->tx_ring[i].addr = cpu_to_le32(0xBADF00D0); /* An invalid address. */
 		if (rp->tx_skbuff[i]) {
 			if (rp->tx_skbuff_dma[i]) {
-				dma_unmap_single(&rp->pdev->dev,
+				dma_unmap_single(hwdev,
 						 rp->tx_skbuff_dma[i],
 						 rp->tx_skbuff[i]->len,
 						 DMA_TO_DEVICE);
@@ -1469,7 +1475,7 @@ static void init_registers(struct net_device *dev)
 
 	rhine_set_rx_mode(dev);
 
-	if (rp->pdev->revision >= VT6105M)
+	if (rp->revision >= VT6105M)
 		rhine_init_cam_filter(dev);
 
 	napi_enable(&rp->napi);
@@ -1581,16 +1587,15 @@ static int rhine_open(struct net_device *dev)
 	void __iomem *ioaddr = rp->base;
 	int rc;
 
-	rc = request_irq(rp->pdev->irq, rhine_interrupt, IRQF_SHARED, dev->name,
-			dev);
+	rc = request_irq(rp->irq, rhine_interrupt, IRQF_SHARED, dev->name, dev);
 	if (rc)
 		return rc;
 
-	netif_dbg(rp, ifup, dev, "%s() irq %d\n", __func__, rp->pdev->irq);
+	netif_dbg(rp, ifup, dev, "%s() irq %d\n", __func__, rp->irq);
 
 	rc = alloc_ring(dev);
 	if (rc) {
-		free_irq(rp->pdev->irq, dev);
+		free_irq(rp->irq, dev);
 		return rc;
 	}
 	alloc_rbufs(dev);
@@ -1659,6 +1664,7 @@ static netdev_tx_t rhine_start_tx(struct sk_buff *skb,
 				  struct net_device *dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	void __iomem *ioaddr = rp->base;
 	unsigned entry;
 
@@ -1695,9 +1701,9 @@ static netdev_tx_t rhine_start_tx(struct sk_buff *skb,
 						       rp->tx_bufs));
 	} else {
 		rp->tx_skbuff_dma[entry] =
-			dma_map_single(&rp->pdev->dev, skb->data, skb->len,
+			dma_map_single(hwdev, skb->data, skb->len,
 				       DMA_TO_DEVICE);
-		if (dma_mapping_error(&rp->pdev->dev, rp->tx_skbuff_dma[entry])) {
+		if (dma_mapping_error(hwdev, rp->tx_skbuff_dma[entry])) {
 			dev_kfree_skb(skb);
 			rp->tx_skbuff_dma[entry] = 0;
 			dev->stats.tx_dropped++;
@@ -1788,6 +1794,7 @@ static irqreturn_t rhine_interrupt(int irq, void *dev_instance)
 static void rhine_tx(struct net_device *dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	int txstatus = 0, entry = rp->dirty_tx % TX_RING_SIZE;
 
 	/* find and cleanup dirty tx descriptors */
@@ -1831,7 +1838,7 @@ static void rhine_tx(struct net_device *dev)
 		}
 		/* Free the original skb. */
 		if (rp->tx_skbuff_dma[entry]) {
-			dma_unmap_single(&rp->pdev->dev,
+			dma_unmap_single(hwdev,
 					 rp->tx_skbuff_dma[entry],
 					 rp->tx_skbuff[entry]->len,
 					 DMA_TO_DEVICE);
@@ -1863,6 +1870,7 @@ static inline u16 rhine_get_vlan_tci(struct sk_buff *skb, int data_size)
 static int rhine_rx(struct net_device *dev, int limit)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	int count;
 	int entry = rp->cur_rx % RX_RING_SIZE;
 
@@ -1924,7 +1932,7 @@ static int rhine_rx(struct net_device *dev, int limit)
 			if (pkt_len < rx_copybreak)
 				skb = netdev_alloc_skb_ip_align(dev, pkt_len);
 			if (skb) {
-				dma_sync_single_for_cpu(&rp->pdev->dev,
+				dma_sync_single_for_cpu(hwdev,
 							    rp->rx_skbuff_dma[entry],
 							    rp->rx_buf_sz,
 							    DMA_FROM_DEVICE);
@@ -1933,7 +1941,7 @@ static int rhine_rx(struct net_device *dev, int limit)
 						 rp->rx_skbuff[entry]->data,
 						 pkt_len);
 				skb_put(skb, pkt_len);
-				dma_sync_single_for_device(&rp->pdev->dev,
+				dma_sync_single_for_device(hwdev,
 							       rp->rx_skbuff_dma[entry],
 							       rp->rx_buf_sz,
 							       DMA_FROM_DEVICE);
@@ -1945,7 +1953,7 @@ static int rhine_rx(struct net_device *dev, int limit)
 				}
 				rp->rx_skbuff[entry] = NULL;
 				skb_put(skb, pkt_len);
-				dma_unmap_single(&rp->pdev->dev,
+				dma_unmap_single(hwdev,
 						 rp->rx_skbuff_dma[entry],
 						 rp->rx_buf_sz,
 						 DMA_FROM_DEVICE);
@@ -1979,10 +1987,11 @@ static int rhine_rx(struct net_device *dev, int limit)
 			if (skb == NULL)
 				break;	/* Better luck next round. */
 			rp->rx_skbuff_dma[entry] =
-				dma_map_single(&rp->pdev->dev, skb->data,
+				dma_map_single(hwdev, skb->data,
 					       rp->rx_buf_sz,
 					       DMA_FROM_DEVICE);
-			if (dma_mapping_error(&rp->pdev->dev, rp->rx_skbuff_dma[entry])) {
+			if (dma_mapping_error(hwdev,
+					      rp->rx_skbuff_dma[entry])) {
 				dev_kfree_skb(skb);
 				rp->rx_skbuff_dma[entry] = 0;
 				break;
@@ -2103,7 +2112,7 @@ static void rhine_set_rx_mode(struct net_device *dev)
 		/* Too many to match, or accept all multicasts. */
 		iowrite32(0xffffffff, ioaddr + MulticastFilter0);
 		iowrite32(0xffffffff, ioaddr + MulticastFilter1);
-	} else if (rp->pdev->revision >= VT6105M) {
+	} else if (rp->revision >= VT6105M) {
 		int i = 0;
 		u32 mCAMmask = 0;	/* 32 mCAMs (6105M and better) */
 		netdev_for_each_mc_addr(ha, dev) {
@@ -2125,7 +2134,7 @@ static void rhine_set_rx_mode(struct net_device *dev)
 		iowrite32(mc_filter[1], ioaddr + MulticastFilter1);
 	}
 	/* enable/disable VLAN receive filtering */
-	if (rp->pdev->revision >= VT6105M) {
+	if (rp->revision >= VT6105M) {
 		if (dev->flags & IFF_PROMISC)
 			BYTE_REG_BITS_OFF(BCR1_VIDFR, ioaddr + PCIBusConfig1);
 		else
@@ -2136,11 +2145,11 @@ static void rhine_set_rx_mode(struct net_device *dev)
 
 static void netdev_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
 {
-	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 
 	strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
 	strlcpy(info->version, DRV_VERSION, sizeof(info->version));
-	strlcpy(info->bus_info, pci_name(rp->pdev), sizeof(info->bus_info));
+	strlcpy(info->bus_info, dev_name(hwdev), sizeof(info->bus_info));
 }
 
 static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
@@ -2277,7 +2286,7 @@ static int rhine_close(struct net_device *dev)
 	/* Stop the chip's Tx and Rx processes. */
 	iowrite16(CmdStop, ioaddr + ChipCmd);
 
-	free_irq(rp->pdev->irq, dev);
+	free_irq(rp->irq, dev);
 	free_rbufs(dev);
 	free_tbufs(dev);
 	free_ring(dev);
@@ -2354,8 +2363,7 @@ static void rhine_shutdown (struct pci_dev *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int rhine_suspend(struct device *device)
 {
-	struct pci_dev *pdev = to_pci_dev(device);
-	struct net_device *dev = pci_get_drvdata(pdev);
+	struct net_device *dev = dev_get_drvdata(device);
 	struct rhine_private *rp = netdev_priv(dev);
 
 	if (!netif_running(dev))
@@ -2367,15 +2375,15 @@ static int rhine_suspend(struct device *device)
 
 	netif_device_detach(dev);
 
-	rhine_shutdown(pdev);
+	if (!strncmp(device->bus->name, "pci", 3))
+		rhine_shutdown(to_pci_dev(device));
 
 	return 0;
 }
 
 static int rhine_resume(struct device *device)
 {
-	struct pci_dev *pdev = to_pci_dev(device);
-	struct net_device *dev = pci_get_drvdata(pdev);
+	struct net_device *dev = dev_get_drvdata(device);
 	struct rhine_private *rp = netdev_priv(dev);
 
 	if (!netif_running(dev))
-- 
1.8.5.1


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

* [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-01-27 11:51 ` [PATCH 0/3] Resubmit: " Alexey Charkov
  2014-01-27 11:51   ` [PATCH 1/3] net: via-rhine: switch to generic DMA functions Alexey Charkov
  2014-01-27 11:51   ` [PATCH 2/3] net: via-rhine: reduce usage of the PCI-specific struct Alexey Charkov
@ 2014-01-27 11:51   ` Alexey Charkov
  2014-01-27 14:57     ` Ben Hutchings
  2014-01-27 15:56     ` Rob Herring
  2014-04-22 15:28   ` [PATCH v2 0/3] net: via-rhine: add support for on-chip Rhine controllers Alexey Charkov
  3 siblings, 2 replies; 25+ messages in thread
From: Alexey Charkov @ 2014-01-27 11:51 UTC (permalink / raw)
  To: netdev, linux, devicetree, rl, linux-kernel; +Cc: Alexey Charkov

This should make the driver usable with VIA/WonderMedia ARM-based
Systems-on-Chip integrated Rhine III adapters. Note that these
are always in MMIO mode, and don't have any known EEPROM.

Signed-off-by: Alexey Charkov <alchark@gmail.com>
Signed-off-by: Roger Luethi <rl@hellgate.ch>
---
 .../devicetree/bindings/net/via-rhine.txt          |  18 ++
 drivers/net/ethernet/via/Kconfig                   |   2 +-
 drivers/net/ethernet/via/via-rhine.c               | 293 +++++++++++++--------
 3 files changed, 200 insertions(+), 113 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/via-rhine.txt

diff --git a/Documentation/devicetree/bindings/net/via-rhine.txt b/Documentation/devicetree/bindings/net/via-rhine.txt
new file mode 100644
index 0000000..684dd3a
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/via-rhine.txt
@@ -0,0 +1,18 @@
+* VIA Rhine 10/100 Network Controller
+
+Required properties:
+- compatible : Should be "via,rhine"
+- reg : Address and length of the io space
+- interrupts : Should contain the controller interrupt line
+- rhine,revision : Rhine core revision, used to inform the
+	driver of quirks and capabilities to expect from
+	the device. Mimics the respective PCI attribute.
+
+Examples:
+
+ethernet@d8004000 {
+	compatible = "via,rhine";
+	reg = <0xd8004000 0x100>;
+	interrupts = <10>;
+	rhine,revision = <0x84>;
+};
diff --git a/drivers/net/ethernet/via/Kconfig b/drivers/net/ethernet/via/Kconfig
index 8a049a2..f66ddae 100644
--- a/drivers/net/ethernet/via/Kconfig
+++ b/drivers/net/ethernet/via/Kconfig
@@ -19,7 +19,7 @@ if NET_VENDOR_VIA
 
 config VIA_RHINE
 	tristate "VIA Rhine support"
-	depends on PCI
+	depends on (PCI || USE_OF)
 	select CRC32
 	select MII
 	---help---
diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index 95c2e93..1c609c0 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -94,6 +94,10 @@ static const int multicast_filter_limit = 32;
 #include <linux/ioport.h>
 #include <linux/interrupt.h>
 #include <linux/pci.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/of_irq.h>
+#include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
@@ -279,6 +283,11 @@ static DEFINE_PCI_DEVICE_TABLE(rhine_pci_tbl) = {
 };
 MODULE_DEVICE_TABLE(pci, rhine_pci_tbl);
 
+static struct of_device_id rhine_of_tbl[] = {
+	{ .compatible = "via,rhine" },
+	{ }	/* terminate list */
+};
+MODULE_DEVICE_TABLE(of, rhine_of_tbl);
 
 /* Offsets to the device registers. */
 enum register_offsets {
@@ -847,7 +856,8 @@ static void rhine_hw_init(struct net_device *dev, long pioaddr)
 		msleep(5);
 
 	/* Reload EEPROM controlled bytes cleared by soft reset */
-	rhine_reload_eeprom(pioaddr, dev);
+	if (!strncmp(dev->dev.parent->bus->name, "pci", 3))
+		rhine_reload_eeprom(pioaddr, dev);
 }
 
 static const struct net_device_ops rhine_netdev_ops = {
@@ -868,56 +878,13 @@ static const struct net_device_ops rhine_netdev_ops = {
 #endif
 };
 
-static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
+static int rhine_init_one_common(struct device *hwdev, int revision,
+				 long pioaddr, void __iomem *ioaddr, int irq)
 {
 	struct net_device *dev;
 	struct rhine_private *rp;
-	struct device *hwdev = &pdev->dev;
-	int revision = pdev->revision;
-	int i, rc;
-	u32 quirks;
-	long pioaddr;
-	long memaddr;
-	void __iomem *ioaddr;
-	int io_size, phy_id;
+	int i, rc, phy_id;
 	const char *name;
-#ifdef USE_MMIO
-	int bar = 1;
-#else
-	int bar = 0;
-#endif
-
-/* when built into the kernel, we only print version if device is found */
-#ifndef MODULE
-	pr_info_once("%s\n", version);
-#endif
-
-	io_size = 256;
-	phy_id = 0;
-	quirks = 0;
-	name = "Rhine";
-	if (revision < VTunknown0) {
-		quirks = rqRhineI;
-		io_size = 128;
-	} else if (revision >= VT6102) {
-		quirks = rqWOL | rqForceReset;
-		if (revision < VT6105) {
-			name = "Rhine II";
-			quirks |= rqStatusWBRace;	/* Rhine-II exclusive */
-		} else {
-			phy_id = 1;	/* Integrated PHY, phy_id fixed to 1 */
-			if (revision >= VT6105_B0)
-				quirks |= rq6patterns;
-			if (revision < VT6105M)
-				name = "Rhine III";
-			else
-				name = "Rhine III (Management Adapter)";
-		}
-	}
-
-	rc = pci_enable_device(pdev);
-	if (rc)
-		goto err_out;
 
 	/* this should always be supported */
 	rc = dma_set_mask(hwdev, DMA_BIT_MASK(32));
@@ -926,19 +893,6 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		goto err_out;
 	}
 
-	/* sanity check */
-	if ((pci_resource_len(pdev, 0) < io_size) ||
-	    (pci_resource_len(pdev, 1) < io_size)) {
-		rc = -EIO;
-		dev_err(hwdev, "Insufficient PCI resources, aborting\n");
-		goto err_out;
-	}
-
-	pioaddr = pci_resource_start(pdev, 0);
-	memaddr = pci_resource_start(pdev, 1);
-
-	pci_set_master(pdev);
-
 	dev = alloc_etherdev(sizeof(struct rhine_private));
 	if (!dev) {
 		rc = -ENOMEM;
@@ -949,44 +903,30 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	rp = netdev_priv(dev);
 	rp->dev = dev;
 	rp->revision = revision;
-	rp->quirks = quirks;
 	rp->pioaddr = pioaddr;
+	rp->base = ioaddr;
+	rp->irq = irq;
 	rp->msg_enable = netif_msg_init(debug, RHINE_MSG_DEFAULT);
 
-	rc = pci_request_regions(pdev, DRV_NAME);
-	if (rc)
-		goto err_out_free_netdev;
-
-	ioaddr = pci_iomap(pdev, bar, io_size);
-	if (!ioaddr) {
-		rc = -EIO;
-		dev_err(hwdev,
-			"ioremap failed for device %s, region 0x%X @ 0x%lX\n",
-			dev_name(hwdev), io_size, memaddr);
-		goto err_out_free_res;
-	}
-
-#ifdef USE_MMIO
-	enable_mmio(pioaddr, quirks);
-
-	/* Check that selected MMIO registers match the PIO ones */
-	i = 0;
-	while (mmio_verify_registers[i]) {
-		int reg = mmio_verify_registers[i++];
-		unsigned char a = inb(pioaddr+reg);
-		unsigned char b = readb(ioaddr+reg);
-		if (a != b) {
-			rc = -EIO;
-			dev_err(hwdev,
-				"MMIO do not match PIO [%02x] (%02x != %02x)\n",
-				reg, a, b);
-			goto err_out_unmap;
+	phy_id = 0;
+	name = "Rhine";
+	if (revision < VTunknown0) {
+		rp->quirks = rqRhineI;
+	} else if (revision >= VT6102) {
+		rp->quirks = rqWOL | rqForceReset;
+		if (revision < VT6105) {
+			name = "Rhine II";
+			rp->quirks |= rqStatusWBRace;	/* Rhine-II exclusive */
+		} else {
+			phy_id = 1;	/* Integrated PHY, phy_id fixed to 1 */
+			if (revision >= VT6105_B0)
+				rp->quirks |= rq6patterns;
+			if (revision < VT6105M)
+				name = "Rhine III";
+			else
+				name = "Rhine III (Management Adapter)";
 		}
 	}
-#endif /* USE_MMIO */
-
-	rp->base = ioaddr;
-	rp->irq = pdev->irq;
 
 	u64_stats_init(&rp->tx_stats.syncp);
 	u64_stats_init(&rp->rx_stats.syncp);
@@ -1039,16 +979,10 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	/* dev->name not defined before register_netdev()! */
 	rc = register_netdev(dev);
 	if (rc)
-		goto err_out_unmap;
+		goto err_out_free_netdev;
 
 	netdev_info(dev, "VIA %s at 0x%lx, %pM, IRQ %d\n",
-		    name,
-#ifdef USE_MMIO
-		    memaddr,
-#else
-		    (long)ioaddr,
-#endif
-		    dev->dev_addr, rp->irq);
+		    name, (long)ioaddr, dev->dev_addr, rp->irq);
 
 	dev_set_drvdata(hwdev, dev);
 
@@ -1079,16 +1013,118 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	return 0;
 
+err_out_free_netdev:
+	free_netdev(dev);
+err_out:
+	return rc;
+}
+
+static int rhine_init_one_pci(struct pci_dev *pdev,
+			      const struct pci_device_id *ent)
+{
+	struct device *hwdev = &pdev->dev;
+	int i, rc;
+	long pioaddr, memaddr;
+	void __iomem *ioaddr;
+	int io_size = pdev->revision < VTunknown0 ? 128 : 256;
+	u32 quirks = pdev->revision < VTunknown0 ? rqRhineI : 0;
+#ifdef USE_MMIO
+	int bar = 1;
+#else
+	int bar = 0;
+#endif
+
+/* when built into the kernel, we only print version if device is found */
+#ifndef MODULE
+	pr_info_once("%s\n", version);
+#endif
+
+	rc = pci_enable_device(pdev);
+	if (rc)
+		goto err_out;
+
+	/* sanity check */
+	if ((pci_resource_len(pdev, 0) < io_size) ||
+	    (pci_resource_len(pdev, 1) < io_size)) {
+		rc = -EIO;
+		dev_err(hwdev, "Insufficient PCI resources, aborting\n");
+		goto err_out;
+	}
+
+	pioaddr = pci_resource_start(pdev, 0);
+	memaddr = pci_resource_start(pdev, 1);
+
+	pci_set_master(pdev);
+
+	rc = pci_request_regions(pdev, DRV_NAME);
+	if (rc)
+		goto err_out;
+
+	ioaddr = pci_iomap(pdev, bar, io_size);
+	if (!ioaddr) {
+		rc = -EIO;
+		dev_err(hwdev,
+			"ioremap failed for device %s, region 0x%X @ 0x%lX\n",
+			dev_name(hwdev), io_size, memaddr);
+		goto err_out_free_res;
+	}
+
+#ifdef USE_MMIO
+	enable_mmio(pioaddr, quirks);
+
+	/* Check that selected MMIO registers match the PIO ones */
+	i = 0;
+	while (mmio_verify_registers[i]) {
+		int reg = mmio_verify_registers[i++];
+		unsigned char a = inb(pioaddr+reg);
+		unsigned char b = readb(ioaddr+reg);
+		if (a != b) {
+			rc = -EIO;
+			dev_err(hwdev,
+				"MMIO do not match PIO [%02x] (%02x != %02x)\n",
+				reg, a, b);
+			goto err_out_unmap;
+		}
+	}
+#endif /* USE_MMIO */
+
+	rc = rhine_init_one_common(&pdev->dev, pdev->revision,
+				   pioaddr, ioaddr, pdev->irq);
+	if (!rc)
+		return 0;
+
 err_out_unmap:
 	pci_iounmap(pdev, ioaddr);
 err_out_free_res:
 	pci_release_regions(pdev);
-err_out_free_netdev:
-	free_netdev(dev);
 err_out:
 	return rc;
 }
 
+static int rhine_init_one_platform(struct platform_device *pdev)
+{
+	const u32 *revision;
+	int irq;
+	struct resource *res;
+	void __iomem *ioaddr;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	ioaddr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ioaddr))
+		return PTR_ERR(ioaddr);
+
+	irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
+	if (!irq)
+		return -EINVAL;
+
+	revision = of_get_property(pdev->dev.of_node, "rhine,revision", NULL);
+	if (!revision)
+		return -EINVAL;
+
+	return rhine_init_one_common(&pdev->dev, *revision,
+				     (long)ioaddr, ioaddr, irq);
+}
+
 static int alloc_ring(struct net_device* dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
@@ -2295,7 +2331,7 @@ static int rhine_close(struct net_device *dev)
 }
 
 
-static void rhine_remove_one(struct pci_dev *pdev)
+static void rhine_remove_one_pci(struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
 	struct rhine_private *rp = netdev_priv(dev);
@@ -2309,7 +2345,21 @@ static void rhine_remove_one(struct pci_dev *pdev)
 	pci_disable_device(pdev);
 }
 
-static void rhine_shutdown (struct pci_dev *pdev)
+static int rhine_remove_one_platform(struct platform_device *pdev)
+{
+	struct net_device *dev = platform_get_drvdata(pdev);
+	struct rhine_private *rp = netdev_priv(dev);
+
+	unregister_netdev(dev);
+
+	iounmap(rp->base);
+
+	free_netdev(dev);
+
+	return 0;
+}
+
+static void rhine_shutdown_pci(struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
 	struct rhine_private *rp = netdev_priv(dev);
@@ -2376,7 +2426,7 @@ static int rhine_suspend(struct device *device)
 	netif_device_detach(dev);
 
 	if (!strncmp(device->bus->name, "pci", 3))
-		rhine_shutdown(to_pci_dev(device));
+		rhine_shutdown_pci(to_pci_dev(device));
 
 	return 0;
 }
@@ -2416,15 +2466,26 @@ static SIMPLE_DEV_PM_OPS(rhine_pm_ops, rhine_suspend, rhine_resume);
 
 #endif /* !CONFIG_PM_SLEEP */
 
-static struct pci_driver rhine_driver = {
+static struct pci_driver rhine_driver_pci = {
 	.name		= DRV_NAME,
 	.id_table	= rhine_pci_tbl,
-	.probe		= rhine_init_one,
-	.remove		= rhine_remove_one,
-	.shutdown	= rhine_shutdown,
+	.probe		= rhine_init_one_pci,
+	.remove		= rhine_remove_one_pci,
+	.shutdown	= rhine_shutdown_pci,
 	.driver.pm	= RHINE_PM_OPS,
 };
 
+static struct platform_driver rhine_driver_platform = {
+	.probe		= rhine_init_one_platform,
+	.remove		= rhine_remove_one_platform,
+	.driver = {
+		.name	= DRV_NAME,
+		.owner	= THIS_MODULE,
+		.of_match_table	= rhine_of_tbl,
+		.pm		= RHINE_PM_OPS,
+	}
+};
+
 static struct dmi_system_id rhine_dmi_table[] __initdata = {
 	{
 		.ident = "EPIA-M",
@@ -2445,6 +2506,8 @@ static struct dmi_system_id rhine_dmi_table[] __initdata = {
 
 static int __init rhine_init(void)
 {
+	int ret_pci, ret_platform;
+
 /* when a module, this is printed whether or not devices are found in probe */
 #ifdef MODULE
 	pr_info("%s\n", version);
@@ -2457,13 +2520,19 @@ static int __init rhine_init(void)
 	else if (avoid_D3)
 		pr_info("avoid_D3 set\n");
 
-	return pci_register_driver(&rhine_driver);
+	ret_pci = pci_register_driver(&rhine_driver_pci);
+	ret_platform = platform_driver_register(&rhine_driver_platform);
+	if ((ret_pci < 0) && (ret_platform < 0))
+		return ret_pci;
+
+	return 0;
 }
 
 
 static void __exit rhine_cleanup(void)
 {
-	pci_unregister_driver(&rhine_driver);
+	platform_driver_unregister(&rhine_driver_platform);
+	pci_unregister_driver(&rhine_driver_pci);
 }
 
 
-- 
1.8.5.1


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

* Re: [PATCH 1/3] net: via-rhine: switch to generic DMA functions
  2014-01-27 11:51   ` [PATCH 1/3] net: via-rhine: switch to generic DMA functions Alexey Charkov
@ 2014-01-27 14:49     ` Ben Hutchings
  2014-01-27 15:26       ` Alexey Charkov
  0 siblings, 1 reply; 25+ messages in thread
From: Ben Hutchings @ 2014-01-27 14:49 UTC (permalink / raw)
  To: Alexey Charkov; +Cc: netdev, linux, devicetree, rl, linux-kernel

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

On Mon, 2014-01-27 at 15:51 +0400, Alexey Charkov wrote:
> Remove legacy PCI DMA wrappers and instead use generic DMA functions
> directly in preparation for OF bus binding
> 
> Signed-off-by: Alexey Charkov <alchark@gmail.com>
> Signed-off-by: Roger Luethi <rl@hellgate.ch>
> ---
>  drivers/net/ethernet/via/via-rhine.c | 56 +++++++++++++++++++-----------------
>  1 file changed, 29 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
> index ef312bc..fee8732 100644
> --- a/drivers/net/ethernet/via/via-rhine.c
> +++ b/drivers/net/ethernet/via/via-rhine.c
> @@ -919,10 +919,10 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
>  		goto err_out;
>  
>  	/* this should always be supported */
> -	rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
> +	rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
>  	if (rc) {
>  		dev_err(&pdev->dev,
> -			"32-bit PCI DMA addresses not supported by the card!?\n");
> +			"32-bit DMA addresses not supported by the card!?\n");
>  		goto err_out;
>  	}
>  
> @@ -1094,20 +1094,22 @@ static int alloc_ring(struct net_device* dev)
>  	void *ring;
>  	dma_addr_t ring_dma;
>  
> -	ring = pci_alloc_consistent(rp->pdev,
> +	ring = dma_alloc_coherent(&rp->pdev->dev,
>  				    RX_RING_SIZE * sizeof(struct rx_desc) +
>  				    TX_RING_SIZE * sizeof(struct tx_desc),
> -				    &ring_dma);
> +				    &ring_dma,
> +					GFP_ATOMIC);
[...]

Indentation is messed up here (and in several other function calls
you're changing).  You should align the function arguments so each line
begins in the column after the opening parenthesis.

Ben.

-- 
Ben Hutchings
If at first you don't succeed, you're doing about average.

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

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

* Re: [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-01-27 11:51   ` [PATCH 3/3] net: via-rhine: add OF bus binding Alexey Charkov
@ 2014-01-27 14:57     ` Ben Hutchings
  2014-01-27 15:34       ` Alexey Charkov
  2014-01-27 15:56     ` Rob Herring
  1 sibling, 1 reply; 25+ messages in thread
From: Ben Hutchings @ 2014-01-27 14:57 UTC (permalink / raw)
  To: Alexey Charkov; +Cc: netdev, linux, devicetree, rl, linux-kernel

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

On Mon, 2014-01-27 at 15:51 +0400, Alexey Charkov wrote:
> This should make the driver usable with VIA/WonderMedia ARM-based
> Systems-on-Chip integrated Rhine III adapters. Note that these
> are always in MMIO mode, and don't have any known EEPROM.
[...]
> --- a/drivers/net/ethernet/via/Kconfig
> +++ b/drivers/net/ethernet/via/Kconfig
> @@ -19,7 +19,7 @@ if NET_VENDOR_VIA
>  
>  config VIA_RHINE
>         tristate "VIA Rhine support"
> -       depends on PCI
> +       depends on (PCI || USE_OF)
>         select CRC32
>         select MII
>         ---help---

This seems like the right thing to do, but it means you need to add
#ifdef CONFIG_PCI and #ifdef CONFIG_USE_OF around the driver structures
and related functions.

You should compile-test in configurations that have just one of those
dependencies enabled.

[...]
> --- a/drivers/net/ethernet/via/via-rhine.c
> +++ b/drivers/net/ethernet/via/via-rhine.c
[...]
> @@ -847,7 +856,8 @@ static void rhine_hw_init(struct net_device *dev, long pioaddr)
>  		msleep(5);
>  
>  	/* Reload EEPROM controlled bytes cleared by soft reset */
> -	rhine_reload_eeprom(pioaddr, dev);
> +	if (!strncmp(dev->dev.parent->bus->name, "pci", 3))
> +		rhine_reload_eeprom(pioaddr, dev);
[...]

Ew.  I think you should use dev_is_pci(), although you might also need
to guard that with #ifdef CONFIG_PCI.

Ben.

-- 
Ben Hutchings
If at first you don't succeed, you're doing about average.

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

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

* Re: [PATCH 1/3] net: via-rhine: switch to generic DMA functions
  2014-01-27 14:49     ` Ben Hutchings
@ 2014-01-27 15:26       ` Alexey Charkov
  2014-01-27 15:28         ` Ben Hutchings
  0 siblings, 1 reply; 25+ messages in thread
From: Alexey Charkov @ 2014-01-27 15:26 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: netdev, Tony Prisk, devicetree, Roger Luethi, linux-kernel

2014/1/27 Ben Hutchings <ben@decadent.org.uk>:
> On Mon, 2014-01-27 at 15:51 +0400, Alexey Charkov wrote:
>> Remove legacy PCI DMA wrappers and instead use generic DMA functions
>> directly in preparation for OF bus binding
>>
>> Signed-off-by: Alexey Charkov <alchark@gmail.com>
>> Signed-off-by: Roger Luethi <rl@hellgate.ch>
>> ---
>>  drivers/net/ethernet/via/via-rhine.c | 56 +++++++++++++++++++-----------------
>>  1 file changed, 29 insertions(+), 27 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
>> index ef312bc..fee8732 100644
>> --- a/drivers/net/ethernet/via/via-rhine.c
>> +++ b/drivers/net/ethernet/via/via-rhine.c
>> @@ -919,10 +919,10 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
>>               goto err_out;
>>
>>       /* this should always be supported */
>> -     rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
>> +     rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
>>       if (rc) {
>>               dev_err(&pdev->dev,
>> -                     "32-bit PCI DMA addresses not supported by the card!?\n");
>> +                     "32-bit DMA addresses not supported by the card!?\n");
>>               goto err_out;
>>       }
>>
>> @@ -1094,20 +1094,22 @@ static int alloc_ring(struct net_device* dev)
>>       void *ring;
>>       dma_addr_t ring_dma;
>>
>> -     ring = pci_alloc_consistent(rp->pdev,
>> +     ring = dma_alloc_coherent(&rp->pdev->dev,
>>                                   RX_RING_SIZE * sizeof(struct rx_desc) +
>>                                   TX_RING_SIZE * sizeof(struct tx_desc),
>> -                                 &ring_dma);
>> +                                 &ring_dma,
>> +                                     GFP_ATOMIC);
> [...]
>
> Indentation is messed up here (and in several other function calls
> you're changing).  You should align the function arguments so each line
> begins in the column after the opening parenthesis.

Ben, thanks for pointing out. I actually just tried to follow the
style of surrounding code, but happy to adjust if that's the preferred
option. From what I can see, these lines should still fit in below 80
cols even with increased indents...

Should we then also adjust other function calls within the driver with
similar indentation (if any), that are currently not touched by this
patch series?

Thanks,
Alexey

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

* Re: [PATCH 1/3] net: via-rhine: switch to generic DMA functions
  2014-01-27 15:26       ` Alexey Charkov
@ 2014-01-27 15:28         ` Ben Hutchings
  0 siblings, 0 replies; 25+ messages in thread
From: Ben Hutchings @ 2014-01-27 15:28 UTC (permalink / raw)
  To: Alexey Charkov; +Cc: netdev, Tony Prisk, devicetree, Roger Luethi, linux-kernel

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

On Mon, 2014-01-27 at 19:26 +0400, Alexey Charkov wrote:
> 2014/1/27 Ben Hutchings <ben@decadent.org.uk>:
> > On Mon, 2014-01-27 at 15:51 +0400, Alexey Charkov wrote:
[...]
> >> @@ -1094,20 +1094,22 @@ static int alloc_ring(struct net_device* dev)
> >>       void *ring;
> >>       dma_addr_t ring_dma;
> >>
> >> -     ring = pci_alloc_consistent(rp->pdev,
> >> +     ring = dma_alloc_coherent(&rp->pdev->dev,
> >>                                   RX_RING_SIZE * sizeof(struct rx_desc) +
> >>                                   TX_RING_SIZE * sizeof(struct tx_desc),
> >> -                                 &ring_dma);
> >> +                                 &ring_dma,
> >> +                                     GFP_ATOMIC);
> > [...]
> >
> > Indentation is messed up here (and in several other function calls
> > you're changing).  You should align the function arguments so each line
> > begins in the column after the opening parenthesis.
> 
> Ben, thanks for pointing out. I actually just tried to follow the
> style of surrounding code, but happy to adjust if that's the preferred
> option. From what I can see, these lines should still fit in below 80
> cols even with increased indents...
> 
> Should we then also adjust other function calls within the driver with
> similar indentation (if any), that are currently not touched by this
> patch series?

There is no need to do that at the same time, but it would be a nice bit
of cleanup.

Ben.

-- 
Ben Hutchings
If at first you don't succeed, you're doing about average.

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

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

* Re: [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-01-27 14:57     ` Ben Hutchings
@ 2014-01-27 15:34       ` Alexey Charkov
  2014-01-27 23:40         ` Ben Hutchings
  0 siblings, 1 reply; 25+ messages in thread
From: Alexey Charkov @ 2014-01-27 15:34 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: netdev, Tony Prisk, devicetree, Roger Luethi, linux-kernel

2014/1/27 Ben Hutchings <ben@decadent.org.uk>:
> On Mon, 2014-01-27 at 15:51 +0400, Alexey Charkov wrote:
>> This should make the driver usable with VIA/WonderMedia ARM-based
>> Systems-on-Chip integrated Rhine III adapters. Note that these
>> are always in MMIO mode, and don't have any known EEPROM.
> [...]
>> --- a/drivers/net/ethernet/via/Kconfig
>> +++ b/drivers/net/ethernet/via/Kconfig
>> @@ -19,7 +19,7 @@ if NET_VENDOR_VIA
>>
>>  config VIA_RHINE
>>         tristate "VIA Rhine support"
>> -       depends on PCI
>> +       depends on (PCI || USE_OF)
>>         select CRC32
>>         select MII
>>         ---help---
>
> This seems like the right thing to do, but it means you need to add
> #ifdef CONFIG_PCI and #ifdef CONFIG_USE_OF around the driver structures
> and related functions.

Frankly, I would like to avoid that if possible (as pointed out in the
cover email), as I believe we would get a cleaner driver without
#ifdef. This is also the way it was done in via-velocity, and it works
just fine.

> You should compile-test in configurations that have just one of those
> dependencies enabled.

This has been compile-tested and runtime-tested in OF-only
configuration on WM8950, and Roger also tested it in PCI-only
configuration, so it seems to work fine.

> [...]
>> --- a/drivers/net/ethernet/via/via-rhine.c
>> +++ b/drivers/net/ethernet/via/via-rhine.c
> [...]
>> @@ -847,7 +856,8 @@ static void rhine_hw_init(struct net_device *dev, long pioaddr)
>>               msleep(5);
>>
>>       /* Reload EEPROM controlled bytes cleared by soft reset */
>> -     rhine_reload_eeprom(pioaddr, dev);
>> +     if (!strncmp(dev->dev.parent->bus->name, "pci", 3))
>> +             rhine_reload_eeprom(pioaddr, dev);
> [...]
>
> Ew.  I think you should use dev_is_pci(), although you might also need
> to guard that with #ifdef CONFIG_PCI.

Oh, cool. Didn't realize it existed :) Will adjust, thanks.

I believe the #ifdef is not strictly required, though, as we include
the PCI header anyway (and the macro expands to just a simple test).
Any specific concerns why we should do that, apart from the +3.8%
module size increase?

Thanks,
Alexey

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

* Re: [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-01-27 11:51   ` [PATCH 3/3] net: via-rhine: add OF bus binding Alexey Charkov
  2014-01-27 14:57     ` Ben Hutchings
@ 2014-01-27 15:56     ` Rob Herring
  2014-01-28 18:27       ` Alexey Charkov
  1 sibling, 1 reply; 25+ messages in thread
From: Rob Herring @ 2014-01-27 15:56 UTC (permalink / raw)
  To: Alexey Charkov; +Cc: netdev, Tony Prisk, devicetree, rl, linux-kernel

On Mon, Jan 27, 2014 at 5:51 AM, Alexey Charkov <alchark@gmail.com> wrote:
> This should make the driver usable with VIA/WonderMedia ARM-based
> Systems-on-Chip integrated Rhine III adapters. Note that these
> are always in MMIO mode, and don't have any known EEPROM.
>
> Signed-off-by: Alexey Charkov <alchark@gmail.com>
> Signed-off-by: Roger Luethi <rl@hellgate.ch>
> ---
>  .../devicetree/bindings/net/via-rhine.txt          |  18 ++
>  drivers/net/ethernet/via/Kconfig                   |   2 +-
>  drivers/net/ethernet/via/via-rhine.c               | 293 +++++++++++++--------
>  3 files changed, 200 insertions(+), 113 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/net/via-rhine.txt
>
> diff --git a/Documentation/devicetree/bindings/net/via-rhine.txt b/Documentation/devicetree/bindings/net/via-rhine.txt
> new file mode 100644
> index 0000000..684dd3a
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/via-rhine.txt
> @@ -0,0 +1,18 @@
> +* VIA Rhine 10/100 Network Controller
> +
> +Required properties:
> +- compatible : Should be "via,rhine"

This should be more specific rather than...

> +- reg : Address and length of the io space
> +- interrupts : Should contain the controller interrupt line
> +- rhine,revision : Rhine core revision, used to inform the
> +       driver of quirks and capabilities to expect from
> +       the device. Mimics the respective PCI attribute.

having this property. The OF match table can then have the quirks set
based on compatible strings.

Rob

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

* Re: [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-01-27 15:34       ` Alexey Charkov
@ 2014-01-27 23:40         ` Ben Hutchings
  2014-01-28 18:31           ` Alexey Charkov
  0 siblings, 1 reply; 25+ messages in thread
From: Ben Hutchings @ 2014-01-27 23:40 UTC (permalink / raw)
  To: Alexey Charkov; +Cc: netdev, Tony Prisk, devicetree, Roger Luethi, linux-kernel

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

On Mon, 2014-01-27 at 19:34 +0400, Alexey Charkov wrote:
> 2014/1/27 Ben Hutchings <ben@decadent.org.uk>:
> > On Mon, 2014-01-27 at 15:51 +0400, Alexey Charkov wrote:
> >> This should make the driver usable with VIA/WonderMedia ARM-based
> >> Systems-on-Chip integrated Rhine III adapters. Note that these
> >> are always in MMIO mode, and don't have any known EEPROM.
> > [...]
> >> --- a/drivers/net/ethernet/via/Kconfig
> >> +++ b/drivers/net/ethernet/via/Kconfig
> >> @@ -19,7 +19,7 @@ if NET_VENDOR_VIA
> >>
> >>  config VIA_RHINE
> >>         tristate "VIA Rhine support"
> >> -       depends on PCI
> >> +       depends on (PCI || USE_OF)
> >>         select CRC32
> >>         select MII
> >>         ---help---
> >
> > This seems like the right thing to do, but it means you need to add
> > #ifdef CONFIG_PCI and #ifdef CONFIG_USE_OF around the driver structures
> > and related functions.
> 
> Frankly, I would like to avoid that if possible (as pointed out in the
> cover email), as I believe we would get a cleaner driver without
> #ifdef. This is also the way it was done in via-velocity, and it works
> just fine.

OK, I'm surprised that all the PCI functions have dummy definitions.

> > You should compile-test in configurations that have just one of those
> > dependencies enabled.
> 
> This has been compile-tested and runtime-tested in OF-only
> configuration on WM8950, and Roger also tested it in PCI-only
> configuration, so it seems to work fine.
[...]

Good, then I have no objection.

Ben.

-- 
Ben Hutchings
If at first you don't succeed, you're doing about average.

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

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

* Re: [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-01-27 15:56     ` Rob Herring
@ 2014-01-28 18:27       ` Alexey Charkov
  2014-01-29  3:44         ` Tony Prisk
  2014-01-29 13:46         ` Rob Herring
  0 siblings, 2 replies; 25+ messages in thread
From: Alexey Charkov @ 2014-01-28 18:27 UTC (permalink / raw)
  To: Rob Herring; +Cc: netdev, Tony Prisk, devicetree, Roger Luethi, linux-kernel

2014/1/27 Rob Herring <robherring2@gmail.com>:
> On Mon, Jan 27, 2014 at 5:51 AM, Alexey Charkov <alchark@gmail.com> wrote:
>> This should make the driver usable with VIA/WonderMedia ARM-based
>> Systems-on-Chip integrated Rhine III adapters. Note that these
>> are always in MMIO mode, and don't have any known EEPROM.
>>
>> Signed-off-by: Alexey Charkov <alchark@gmail.com>
>> Signed-off-by: Roger Luethi <rl@hellgate.ch>
>> ---
>>  .../devicetree/bindings/net/via-rhine.txt          |  18 ++
>>  drivers/net/ethernet/via/Kconfig                   |   2 +-
>>  drivers/net/ethernet/via/via-rhine.c               | 293 +++++++++++++--------
>>  3 files changed, 200 insertions(+), 113 deletions(-)
>>  create mode 100644 Documentation/devicetree/bindings/net/via-rhine.txt
>>
>> diff --git a/Documentation/devicetree/bindings/net/via-rhine.txt b/Documentation/devicetree/bindings/net/via-rhine.txt
>> new file mode 100644
>> index 0000000..684dd3a
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/net/via-rhine.txt
>> @@ -0,0 +1,18 @@
>> +* VIA Rhine 10/100 Network Controller
>> +
>> +Required properties:
>> +- compatible : Should be "via,rhine"
>
> This should be more specific rather than...
>
>> +- reg : Address and length of the io space
>> +- interrupts : Should contain the controller interrupt line
>> +- rhine,revision : Rhine core revision, used to inform the
>> +       driver of quirks and capabilities to expect from
>> +       the device. Mimics the respective PCI attribute.
>
> having this property. The OF match table can then have the quirks set
> based on compatible strings.

Sounds fair. Do you think something like the following would fly?

Required properties:
- compatible : Should be "via,rhine-soc-vt8500" for integrated Rhine
cores found in SoC's such as VIA VT8500, WonderMedia WM8950 and
possibly others. These are listed as 1106:3106 rev. 0x84 on the
virtual PCI bus under vendor-provided kernels.

Thanks,
Alexey

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

* Re: [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-01-27 23:40         ` Ben Hutchings
@ 2014-01-28 18:31           ` Alexey Charkov
  2014-01-31 14:24             ` Ben Hutchings
  0 siblings, 1 reply; 25+ messages in thread
From: Alexey Charkov @ 2014-01-28 18:31 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: netdev, Tony Prisk, devicetree, Roger Luethi, linux-kernel

2014/1/28 Ben Hutchings <ben@decadent.org.uk>:
> On Mon, 2014-01-27 at 19:34 +0400, Alexey Charkov wrote:
>> 2014/1/27 Ben Hutchings <ben@decadent.org.uk>:
>> > On Mon, 2014-01-27 at 15:51 +0400, Alexey Charkov wrote:
>> >> This should make the driver usable with VIA/WonderMedia ARM-based
>> >> Systems-on-Chip integrated Rhine III adapters. Note that these
>> >> are always in MMIO mode, and don't have any known EEPROM.
>> > [...]
>> >> --- a/drivers/net/ethernet/via/Kconfig
>> >> +++ b/drivers/net/ethernet/via/Kconfig
>> >> @@ -19,7 +19,7 @@ if NET_VENDOR_VIA
>> >>
>> >>  config VIA_RHINE
>> >>         tristate "VIA Rhine support"
>> >> -       depends on PCI
>> >> +       depends on (PCI || USE_OF)
>> >>         select CRC32
>> >>         select MII
>> >>         ---help---
>> >
>> > This seems like the right thing to do, but it means you need to add
>> > #ifdef CONFIG_PCI and #ifdef CONFIG_USE_OF around the driver structures
>> > and related functions.
>>
>> Frankly, I would like to avoid that if possible (as pointed out in the
>> cover email), as I believe we would get a cleaner driver without
>> #ifdef. This is also the way it was done in via-velocity, and it works
>> just fine.
>
> OK, I'm surprised that all the PCI functions have dummy definitions.
>
>> > You should compile-test in configurations that have just one of those
>> > dependencies enabled.
>>
>> This has been compile-tested and runtime-tested in OF-only
>> configuration on WM8950, and Roger also tested it in PCI-only
>> configuration, so it seems to work fine.
> [...]
>
> Good, then I have no objection.

Thanks Ben! Would it be fine to add your Reviewed-by at the next
iteration, once I fix indentation of function arguments and
dev_is_pci()?

Thanks,
Alexey

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

* Re: [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-01-28 18:27       ` Alexey Charkov
@ 2014-01-29  3:44         ` Tony Prisk
  2014-01-29  5:20           ` Alexey Charkov
  2014-01-29 13:46         ` Rob Herring
  1 sibling, 1 reply; 25+ messages in thread
From: Tony Prisk @ 2014-01-29  3:44 UTC (permalink / raw)
  To: Alexey Charkov, Rob Herring
  Cc: netdev, devicetree, Roger Luethi, linux-kernel

On 29/01/14 07:27, Alexey Charkov wrote:
> 2014/1/27 Rob Herring <robherring2@gmail.com>:
>> On Mon, Jan 27, 2014 at 5:51 AM, Alexey Charkov <alchark@gmail.com> wrote:
>>> This should make the driver usable with VIA/WonderMedia ARM-based
>>> Systems-on-Chip integrated Rhine III adapters. Note that these
>>> are always in MMIO mode, and don't have any known EEPROM.
>>>
>>> Signed-off-by: Alexey Charkov <alchark@gmail.com>
>>> Signed-off-by: Roger Luethi <rl@hellgate.ch>
>>> ---
>>>   .../devicetree/bindings/net/via-rhine.txt          |  18 ++
>>>   drivers/net/ethernet/via/Kconfig                   |   2 +-
>>>   drivers/net/ethernet/via/via-rhine.c               | 293 +++++++++++++--------
>>>   3 files changed, 200 insertions(+), 113 deletions(-)
>>>   create mode 100644 Documentation/devicetree/bindings/net/via-rhine.txt
>>>
>>> diff --git a/Documentation/devicetree/bindings/net/via-rhine.txt b/Documentation/devicetree/bindings/net/via-rhine.txt
>>> new file mode 100644
>>> index 0000000..684dd3a
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/net/via-rhine.txt
>>> @@ -0,0 +1,18 @@
>>> +* VIA Rhine 10/100 Network Controller
>>> +
>>> +Required properties:
>>> +- compatible : Should be "via,rhine"
>> This should be more specific rather than...
>>
>>> +- reg : Address and length of the io space
>>> +- interrupts : Should contain the controller interrupt line
>>> +- rhine,revision : Rhine core revision, used to inform the
>>> +       driver of quirks and capabilities to expect from
>>> +       the device. Mimics the respective PCI attribute.
>> having this property. The OF match table can then have the quirks set
>> based on compatible strings.
> Sounds fair. Do you think something like the following would fly?
>
> Required properties:
> - compatible : Should be "via,rhine-soc-vt8500" for integrated Rhine
> cores found in SoC's such as VIA VT8500, WonderMedia WM8950 and
> possibly others. These are listed as 1106:3106 rev. 0x84 on the
> virtual PCI bus under vendor-provided kernels.
Does it need a special name? I would have assumed they are using their 
own IP for the VT6105 or VT6106S.
Then you can use it to add quirks later on if needed.

Regards
Tony Prisk

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

* Re: [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-01-29  3:44         ` Tony Prisk
@ 2014-01-29  5:20           ` Alexey Charkov
  2014-01-29 14:59             ` Rob Herring
  0 siblings, 1 reply; 25+ messages in thread
From: Alexey Charkov @ 2014-01-29  5:20 UTC (permalink / raw)
  To: Tony Prisk; +Cc: Rob Herring, netdev, devicetree, Roger Luethi, linux-kernel

2014/1/29 Tony Prisk <linux@prisktech.co.nz>:
> On 29/01/14 07:27, Alexey Charkov wrote:
>>
>> 2014/1/27 Rob Herring <robherring2@gmail.com>:
>>>
>>> On Mon, Jan 27, 2014 at 5:51 AM, Alexey Charkov <alchark@gmail.com>
>>> wrote:
>>>>
>>>> This should make the driver usable with VIA/WonderMedia ARM-based
>>>> Systems-on-Chip integrated Rhine III adapters. Note that these
>>>> are always in MMIO mode, and don't have any known EEPROM.
>>>>
>>>> Signed-off-by: Alexey Charkov <alchark@gmail.com>
>>>> Signed-off-by: Roger Luethi <rl@hellgate.ch>
>>>> ---
>>>>   .../devicetree/bindings/net/via-rhine.txt          |  18 ++
>>>>   drivers/net/ethernet/via/Kconfig                   |   2 +-
>>>>   drivers/net/ethernet/via/via-rhine.c               | 293
>>>> +++++++++++++--------
>>>>   3 files changed, 200 insertions(+), 113 deletions(-)
>>>>   create mode 100644 Documentation/devicetree/bindings/net/via-rhine.txt
>>>>
>>>> diff --git a/Documentation/devicetree/bindings/net/via-rhine.txt
>>>> b/Documentation/devicetree/bindings/net/via-rhine.txt
>>>> new file mode 100644
>>>> index 0000000..684dd3a
>>>> --- /dev/null
>>>> +++ b/Documentation/devicetree/bindings/net/via-rhine.txt
>>>> @@ -0,0 +1,18 @@
>>>> +* VIA Rhine 10/100 Network Controller
>>>> +
>>>> +Required properties:
>>>> +- compatible : Should be "via,rhine"
>>>
>>> This should be more specific rather than...
>>>
>>>> +- reg : Address and length of the io space
>>>> +- interrupts : Should contain the controller interrupt line
>>>> +- rhine,revision : Rhine core revision, used to inform the
>>>> +       driver of quirks and capabilities to expect from
>>>> +       the device. Mimics the respective PCI attribute.
>>>
>>> having this property. The OF match table can then have the quirks set
>>> based on compatible strings.
>>
>> Sounds fair. Do you think something like the following would fly?
>>
>> Required properties:
>> - compatible : Should be "via,rhine-soc-vt8500" for integrated Rhine
>> cores found in SoC's such as VIA VT8500, WonderMedia WM8950 and
>> possibly others. These are listed as 1106:3106 rev. 0x84 on the
>> virtual PCI bus under vendor-provided kernels.
>
> Does it need a special name? I would have assumed they are using their own
> IP for the VT6105 or VT6106S.
> Then you can use it to add quirks later on if needed.

The problem is that I have no reliable source for the exact name of
the IP block. The lookup table within the driver says that rev. 0x83
is VT6105_B0, and rev. 0x8A is VT6105L (and it doesn't contain any
entry for 0x84, so our case gets treated as 0x83 currently).

If we only differentiate them by the compatible string, I would be
reluctant to call it vt6105 or vt6106 or whatever else without knowing
for sure. Otherwise, if at some point we need to add any quirks
specific to rev. 0x84, we wouldn't be able to do that without
side-effects.

Thoughts welcome :)

Thanks,
Alexey

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

* Re: [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-01-28 18:27       ` Alexey Charkov
  2014-01-29  3:44         ` Tony Prisk
@ 2014-01-29 13:46         ` Rob Herring
  1 sibling, 0 replies; 25+ messages in thread
From: Rob Herring @ 2014-01-29 13:46 UTC (permalink / raw)
  To: Alexey Charkov; +Cc: netdev, Tony Prisk, devicetree, Roger Luethi, linux-kernel

On Tue, Jan 28, 2014 at 12:27 PM, Alexey Charkov <alchark@gmail.com> wrote:
> 2014/1/27 Rob Herring <robherring2@gmail.com>:
>> On Mon, Jan 27, 2014 at 5:51 AM, Alexey Charkov <alchark@gmail.com> wrote:
>>> This should make the driver usable with VIA/WonderMedia ARM-based
>>> Systems-on-Chip integrated Rhine III adapters. Note that these
>>> are always in MMIO mode, and don't have any known EEPROM.
>>>
>>> Signed-off-by: Alexey Charkov <alchark@gmail.com>
>>> Signed-off-by: Roger Luethi <rl@hellgate.ch>
>>> ---
>>>  .../devicetree/bindings/net/via-rhine.txt          |  18 ++
>>>  drivers/net/ethernet/via/Kconfig                   |   2 +-
>>>  drivers/net/ethernet/via/via-rhine.c               | 293 +++++++++++++--------
>>>  3 files changed, 200 insertions(+), 113 deletions(-)
>>>  create mode 100644 Documentation/devicetree/bindings/net/via-rhine.txt
>>>
>>> diff --git a/Documentation/devicetree/bindings/net/via-rhine.txt b/Documentation/devicetree/bindings/net/via-rhine.txt
>>> new file mode 100644
>>> index 0000000..684dd3a
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/net/via-rhine.txt
>>> @@ -0,0 +1,18 @@
>>> +* VIA Rhine 10/100 Network Controller
>>> +
>>> +Required properties:
>>> +- compatible : Should be "via,rhine"
>>
>> This should be more specific rather than...
>>
>>> +- reg : Address and length of the io space
>>> +- interrupts : Should contain the controller interrupt line
>>> +- rhine,revision : Rhine core revision, used to inform the
>>> +       driver of quirks and capabilities to expect from
>>> +       the device. Mimics the respective PCI attribute.
>>
>> having this property. The OF match table can then have the quirks set
>> based on compatible strings.
>
> Sounds fair. Do you think something like the following would fly?
>
> Required properties:
> - compatible : Should be "via,rhine-soc-vt8500" for integrated Rhine
> cores found in SoC's such as VIA VT8500, WonderMedia WM8950 and
> possibly others. These are listed as 1106:3106 rev. 0x84 on the
> virtual PCI bus under vendor-provided kernels.

Yes, although the "soc" part seems a bit redundant. The usual pattern
is <vendor>,<chip/soc>-<device>. I would go with "via,vt8500-rhine".

Rob

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

* Re: [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-01-29  5:20           ` Alexey Charkov
@ 2014-01-29 14:59             ` Rob Herring
  0 siblings, 0 replies; 25+ messages in thread
From: Rob Herring @ 2014-01-29 14:59 UTC (permalink / raw)
  To: Alexey Charkov; +Cc: Tony Prisk, netdev, devicetree, Roger Luethi, linux-kernel

On Tue, Jan 28, 2014 at 11:20 PM, Alexey Charkov <alchark@gmail.com> wrote:
> 2014/1/29 Tony Prisk <linux@prisktech.co.nz>:
>> On 29/01/14 07:27, Alexey Charkov wrote:
>>>
>>> 2014/1/27 Rob Herring <robherring2@gmail.com>:
>>>>
>>>> On Mon, Jan 27, 2014 at 5:51 AM, Alexey Charkov <alchark@gmail.com>
>>>> wrote:
>>>>>
>>>>> This should make the driver usable with VIA/WonderMedia ARM-based
>>>>> Systems-on-Chip integrated Rhine III adapters. Note that these
>>>>> are always in MMIO mode, and don't have any known EEPROM.
>>>>>
>>>>> Signed-off-by: Alexey Charkov <alchark@gmail.com>
>>>>> Signed-off-by: Roger Luethi <rl@hellgate.ch>
>>>>> ---
>>>>>   .../devicetree/bindings/net/via-rhine.txt          |  18 ++
>>>>>   drivers/net/ethernet/via/Kconfig                   |   2 +-
>>>>>   drivers/net/ethernet/via/via-rhine.c               | 293
>>>>> +++++++++++++--------
>>>>>   3 files changed, 200 insertions(+), 113 deletions(-)
>>>>>   create mode 100644 Documentation/devicetree/bindings/net/via-rhine.txt
>>>>>
>>>>> diff --git a/Documentation/devicetree/bindings/net/via-rhine.txt
>>>>> b/Documentation/devicetree/bindings/net/via-rhine.txt
>>>>> new file mode 100644
>>>>> index 0000000..684dd3a
>>>>> --- /dev/null
>>>>> +++ b/Documentation/devicetree/bindings/net/via-rhine.txt
>>>>> @@ -0,0 +1,18 @@
>>>>> +* VIA Rhine 10/100 Network Controller
>>>>> +
>>>>> +Required properties:
>>>>> +- compatible : Should be "via,rhine"
>>>>
>>>> This should be more specific rather than...
>>>>
>>>>> +- reg : Address and length of the io space
>>>>> +- interrupts : Should contain the controller interrupt line
>>>>> +- rhine,revision : Rhine core revision, used to inform the
>>>>> +       driver of quirks and capabilities to expect from
>>>>> +       the device. Mimics the respective PCI attribute.
>>>>
>>>> having this property. The OF match table can then have the quirks set
>>>> based on compatible strings.
>>>
>>> Sounds fair. Do you think something like the following would fly?
>>>
>>> Required properties:
>>> - compatible : Should be "via,rhine-soc-vt8500" for integrated Rhine
>>> cores found in SoC's such as VIA VT8500, WonderMedia WM8950 and
>>> possibly others. These are listed as 1106:3106 rev. 0x84 on the
>>> virtual PCI bus under vendor-provided kernels.
>>
>> Does it need a special name? I would have assumed they are using their own
>> IP for the VT6105 or VT6106S.
>> Then you can use it to add quirks later on if needed.
>
> The problem is that I have no reliable source for the exact name of
> the IP block. The lookup table within the driver says that rev. 0x83
> is VT6105_B0, and rev. 0x8A is VT6105L (and it doesn't contain any
> entry for 0x84, so our case gets treated as 0x83 currently).
>
> If we only differentiate them by the compatible string, I would be
> reluctant to call it vt6105 or vt6106 or whatever else without knowing
> for sure. Otherwise, if at some point we need to add any quirks
> specific to rev. 0x84, we wouldn't be able to do that without
> side-effects.

If you don't know the IP rev, then you should assume it is different
and you should certainly know which chip it is in. This is why the soc
name is typically in the compatible string. You can always have
multiple compatible strings. You want to have a unique compatible
string so you can add quirks later if needed.

Rob

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

* Re: [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-01-28 18:31           ` Alexey Charkov
@ 2014-01-31 14:24             ` Ben Hutchings
  0 siblings, 0 replies; 25+ messages in thread
From: Ben Hutchings @ 2014-01-31 14:24 UTC (permalink / raw)
  To: Alexey Charkov; +Cc: netdev, Tony Prisk, devicetree, Roger Luethi, linux-kernel

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

On Tue, 2014-01-28 at 22:31 +0400, Alexey Charkov wrote:
> 2014/1/28 Ben Hutchings <ben@decadent.org.uk>:
> > On Mon, 2014-01-27 at 19:34 +0400, Alexey Charkov wrote:
> >> 2014/1/27 Ben Hutchings <ben@decadent.org.uk>:
> >> > On Mon, 2014-01-27 at 15:51 +0400, Alexey Charkov wrote:
> >> >> This should make the driver usable with VIA/WonderMedia ARM-based
> >> >> Systems-on-Chip integrated Rhine III adapters. Note that these
> >> >> are always in MMIO mode, and don't have any known EEPROM.
> >> > [...]
> >> >> --- a/drivers/net/ethernet/via/Kconfig
> >> >> +++ b/drivers/net/ethernet/via/Kconfig
> >> >> @@ -19,7 +19,7 @@ if NET_VENDOR_VIA
> >> >>
> >> >>  config VIA_RHINE
> >> >>         tristate "VIA Rhine support"
> >> >> -       depends on PCI
> >> >> +       depends on (PCI || USE_OF)
> >> >>         select CRC32
> >> >>         select MII
> >> >>         ---help---
> >> >
> >> > This seems like the right thing to do, but it means you need to add
> >> > #ifdef CONFIG_PCI and #ifdef CONFIG_USE_OF around the driver structures
> >> > and related functions.
> >>
> >> Frankly, I would like to avoid that if possible (as pointed out in the
> >> cover email), as I believe we would get a cleaner driver without
> >> #ifdef. This is also the way it was done in via-velocity, and it works
> >> just fine.
> >
> > OK, I'm surprised that all the PCI functions have dummy definitions.
> >
> >> > You should compile-test in configurations that have just one of those
> >> > dependencies enabled.
> >>
> >> This has been compile-tested and runtime-tested in OF-only
> >> configuration on WM8950, and Roger also tested it in PCI-only
> >> configuration, so it seems to work fine.
> > [...]
> >
> > Good, then I have no objection.
> 
> Thanks Ben! Would it be fine to add your Reviewed-by at the next
> iteration, once I fix indentation of function arguments and
> dev_is_pci()?

Sorry, I don't think I know enough to claim that I've reviewed the whole
thing properly.

Ben.

-- 
Ben Hutchings
It is easier to write an incorrect program than to understand a correct one.

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

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

* [PATCH v2 0/3] net: via-rhine: add support for on-chip Rhine controllers
  2014-01-27 11:51 ` [PATCH 0/3] Resubmit: " Alexey Charkov
                     ` (2 preceding siblings ...)
  2014-01-27 11:51   ` [PATCH 3/3] net: via-rhine: add OF bus binding Alexey Charkov
@ 2014-04-22 15:28   ` Alexey Charkov
  2014-04-22 15:28     ` [PATCH 1/3] net: via-rhine: switch to generic DMA functions Alexey Charkov
                       ` (3 more replies)
  3 siblings, 4 replies; 25+ messages in thread
From: Alexey Charkov @ 2014-04-22 15:28 UTC (permalink / raw)
  To: rl, netdev, devicetree, linux-kernel, linux, robh+dt, davem, ben
  Cc: Alexey Charkov

This series introduces platform bus (OpenFirmware) binding for 
via-rhine, as used in various ARM-based Systems-on-Chip by 
VIA/WonderMedia.

This has been tested in OF configuration by myself on a WM8950-based VIA 
APC Rock development board and on a WM8850-based netbook, and in PCI
configuration by Roger.

Please note that the initial version of these patches was signed off by
Roger, but some time has passed since then, so I'm not including his
sign-off until explicit notice.

David, could you please take these to net-next if appropriate?

Thanks a lot,
Alexey

Changes since v1:
 - Fixed indentation of function arguments
 - Switched to 'dev_is_pci' instead of string comparison on bus name
 - Dropped 'rhine,revision' DT attribute, put the revision into OF match
        table instead
 - Included actual device tree nodes where applicable

Alexey Charkov (3):
  net: via-rhine: switch to generic DMA functions
  net: via-rhine: reduce usage of the PCI-specific struct
  net: via-rhine: add OF bus binding

 .../devicetree/bindings/net/via-rhine.txt          |  17 +
 arch/arm/boot/dts/vt8500.dtsi                      |   6 +
 arch/arm/boot/dts/wm8650.dtsi                      |   6 +
 arch/arm/boot/dts/wm8850.dtsi                      |   6 +
 drivers/net/ethernet/via/Kconfig                   |   2 +-
 drivers/net/ethernet/via/via-rhine.c               | 444 ++++++++++++---------
 6 files changed, 302 insertions(+), 179 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/via-rhine.txt

-- 
1.9.1


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

* [PATCH 1/3] net: via-rhine: switch to generic DMA functions
  2014-04-22 15:28   ` [PATCH v2 0/3] net: via-rhine: add support for on-chip Rhine controllers Alexey Charkov
@ 2014-04-22 15:28     ` Alexey Charkov
  2014-04-22 15:28     ` [PATCH 2/3] net: via-rhine: reduce usage of the PCI-specific struct Alexey Charkov
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 25+ messages in thread
From: Alexey Charkov @ 2014-04-22 15:28 UTC (permalink / raw)
  To: rl, netdev, devicetree, linux-kernel, linux, robh+dt, davem, ben
  Cc: Alexey Charkov

Remove legacy PCI DMA wrappers and instead use generic DMA functions
directly in preparation for OF bus binding

Signed-off-by: Alexey Charkov <alchark@gmail.com>
---
 drivers/net/ethernet/via/via-rhine.c | 84 ++++++++++++++++++------------------
 1 file changed, 43 insertions(+), 41 deletions(-)

diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index f61dc2b..0674d0f 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -919,10 +919,10 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		goto err_out;
 
 	/* this should always be supported */
-	rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
+	rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
 	if (rc) {
 		dev_err(&pdev->dev,
-			"32-bit PCI DMA addresses not supported by the card!?\n");
+			"32-bit DMA addresses not supported by the card!?\n");
 		goto err_out_pci_disable;
 	}
 
@@ -1096,23 +1096,25 @@ static int alloc_ring(struct net_device* dev)
 	void *ring;
 	dma_addr_t ring_dma;
 
-	ring = pci_alloc_consistent(rp->pdev,
-				    RX_RING_SIZE * sizeof(struct rx_desc) +
-				    TX_RING_SIZE * sizeof(struct tx_desc),
-				    &ring_dma);
+	ring = dma_alloc_coherent(&rp->pdev->dev,
+				  RX_RING_SIZE * sizeof(struct rx_desc) +
+				  TX_RING_SIZE * sizeof(struct tx_desc),
+				  &ring_dma,
+				  GFP_ATOMIC);
 	if (!ring) {
 		netdev_err(dev, "Could not allocate DMA memory\n");
 		return -ENOMEM;
 	}
 	if (rp->quirks & rqRhineI) {
-		rp->tx_bufs = pci_alloc_consistent(rp->pdev,
-						   PKT_BUF_SZ * TX_RING_SIZE,
-						   &rp->tx_bufs_dma);
+		rp->tx_bufs = dma_alloc_coherent(&rp->pdev->dev,
+						 PKT_BUF_SZ * TX_RING_SIZE,
+						 &rp->tx_bufs_dma,
+						 GFP_ATOMIC);
 		if (rp->tx_bufs == NULL) {
-			pci_free_consistent(rp->pdev,
-				    RX_RING_SIZE * sizeof(struct rx_desc) +
-				    TX_RING_SIZE * sizeof(struct tx_desc),
-				    ring, ring_dma);
+			dma_free_coherent(&rp->pdev->dev,
+					  RX_RING_SIZE * sizeof(struct rx_desc) +
+					  TX_RING_SIZE * sizeof(struct tx_desc),
+					  ring, ring_dma);
 			return -ENOMEM;
 		}
 	}
@@ -1129,15 +1131,15 @@ static void free_ring(struct net_device* dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
 
-	pci_free_consistent(rp->pdev,
-			    RX_RING_SIZE * sizeof(struct rx_desc) +
-			    TX_RING_SIZE * sizeof(struct tx_desc),
-			    rp->rx_ring, rp->rx_ring_dma);
+	dma_free_coherent(&rp->pdev->dev,
+			  RX_RING_SIZE * sizeof(struct rx_desc) +
+			  TX_RING_SIZE * sizeof(struct tx_desc),
+			  rp->rx_ring, rp->rx_ring_dma);
 	rp->tx_ring = NULL;
 
 	if (rp->tx_bufs)
-		pci_free_consistent(rp->pdev, PKT_BUF_SZ * TX_RING_SIZE,
-				    rp->tx_bufs, rp->tx_bufs_dma);
+		dma_free_coherent(&rp->pdev->dev, PKT_BUF_SZ * TX_RING_SIZE,
+				  rp->tx_bufs, rp->tx_bufs_dma);
 
 	rp->tx_bufs = NULL;
 
@@ -1174,8 +1176,8 @@ static void alloc_rbufs(struct net_device *dev)
 			break;
 
 		rp->rx_skbuff_dma[i] =
-			pci_map_single(rp->pdev, skb->data, rp->rx_buf_sz,
-				       PCI_DMA_FROMDEVICE);
+			dma_map_single(&rp->pdev->dev, skb->data, rp->rx_buf_sz,
+				       DMA_FROM_DEVICE);
 		if (dma_mapping_error(&rp->pdev->dev, rp->rx_skbuff_dma[i])) {
 			rp->rx_skbuff_dma[i] = 0;
 			dev_kfree_skb(skb);
@@ -1197,9 +1199,9 @@ static void free_rbufs(struct net_device* dev)
 		rp->rx_ring[i].rx_status = 0;
 		rp->rx_ring[i].addr = cpu_to_le32(0xBADF00D0); /* An invalid address. */
 		if (rp->rx_skbuff[i]) {
-			pci_unmap_single(rp->pdev,
+			dma_unmap_single(&rp->pdev->dev,
 					 rp->rx_skbuff_dma[i],
-					 rp->rx_buf_sz, PCI_DMA_FROMDEVICE);
+					 rp->rx_buf_sz, DMA_FROM_DEVICE);
 			dev_kfree_skb(rp->rx_skbuff[i]);
 		}
 		rp->rx_skbuff[i] = NULL;
@@ -1238,10 +1240,10 @@ static void free_tbufs(struct net_device* dev)
 		rp->tx_ring[i].addr = cpu_to_le32(0xBADF00D0); /* An invalid address. */
 		if (rp->tx_skbuff[i]) {
 			if (rp->tx_skbuff_dma[i]) {
-				pci_unmap_single(rp->pdev,
+				dma_unmap_single(&rp->pdev->dev,
 						 rp->tx_skbuff_dma[i],
 						 rp->tx_skbuff[i]->len,
-						 PCI_DMA_TODEVICE);
+						 DMA_TO_DEVICE);
 			}
 			dev_kfree_skb(rp->tx_skbuff[i]);
 		}
@@ -1695,8 +1697,8 @@ static netdev_tx_t rhine_start_tx(struct sk_buff *skb,
 						       rp->tx_bufs));
 	} else {
 		rp->tx_skbuff_dma[entry] =
-			pci_map_single(rp->pdev, skb->data, skb->len,
-				       PCI_DMA_TODEVICE);
+			dma_map_single(&rp->pdev->dev, skb->data, skb->len,
+				       DMA_TO_DEVICE);
 		if (dma_mapping_error(&rp->pdev->dev, rp->tx_skbuff_dma[entry])) {
 			dev_kfree_skb_any(skb);
 			rp->tx_skbuff_dma[entry] = 0;
@@ -1831,10 +1833,10 @@ static void rhine_tx(struct net_device *dev)
 		}
 		/* Free the original skb. */
 		if (rp->tx_skbuff_dma[entry]) {
-			pci_unmap_single(rp->pdev,
+			dma_unmap_single(&rp->pdev->dev,
 					 rp->tx_skbuff_dma[entry],
 					 rp->tx_skbuff[entry]->len,
-					 PCI_DMA_TODEVICE);
+					 DMA_TO_DEVICE);
 		}
 		dev_consume_skb_any(rp->tx_skbuff[entry]);
 		rp->tx_skbuff[entry] = NULL;
@@ -1924,19 +1926,19 @@ static int rhine_rx(struct net_device *dev, int limit)
 			if (pkt_len < rx_copybreak)
 				skb = netdev_alloc_skb_ip_align(dev, pkt_len);
 			if (skb) {
-				pci_dma_sync_single_for_cpu(rp->pdev,
-							    rp->rx_skbuff_dma[entry],
-							    rp->rx_buf_sz,
-							    PCI_DMA_FROMDEVICE);
+				dma_sync_single_for_cpu(&rp->pdev->dev,
+							rp->rx_skbuff_dma[entry],
+							rp->rx_buf_sz,
+							DMA_FROM_DEVICE);
 
 				skb_copy_to_linear_data(skb,
 						 rp->rx_skbuff[entry]->data,
 						 pkt_len);
 				skb_put(skb, pkt_len);
-				pci_dma_sync_single_for_device(rp->pdev,
-							       rp->rx_skbuff_dma[entry],
-							       rp->rx_buf_sz,
-							       PCI_DMA_FROMDEVICE);
+				dma_sync_single_for_device(&rp->pdev->dev,
+							   rp->rx_skbuff_dma[entry],
+							   rp->rx_buf_sz,
+							   DMA_FROM_DEVICE);
 			} else {
 				skb = rp->rx_skbuff[entry];
 				if (skb == NULL) {
@@ -1945,10 +1947,10 @@ static int rhine_rx(struct net_device *dev, int limit)
 				}
 				rp->rx_skbuff[entry] = NULL;
 				skb_put(skb, pkt_len);
-				pci_unmap_single(rp->pdev,
+				dma_unmap_single(&rp->pdev->dev,
 						 rp->rx_skbuff_dma[entry],
 						 rp->rx_buf_sz,
-						 PCI_DMA_FROMDEVICE);
+						 DMA_FROM_DEVICE);
 			}
 
 			if (unlikely(desc_length & DescTag))
@@ -1979,9 +1981,9 @@ static int rhine_rx(struct net_device *dev, int limit)
 			if (skb == NULL)
 				break;	/* Better luck next round. */
 			rp->rx_skbuff_dma[entry] =
-				pci_map_single(rp->pdev, skb->data,
+				dma_map_single(&rp->pdev->dev, skb->data,
 					       rp->rx_buf_sz,
-					       PCI_DMA_FROMDEVICE);
+					       DMA_FROM_DEVICE);
 			if (dma_mapping_error(&rp->pdev->dev, rp->rx_skbuff_dma[entry])) {
 				dev_kfree_skb(skb);
 				rp->rx_skbuff_dma[entry] = 0;
-- 
1.9.1


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

* [PATCH 2/3] net: via-rhine: reduce usage of the PCI-specific struct
  2014-04-22 15:28   ` [PATCH v2 0/3] net: via-rhine: add support for on-chip Rhine controllers Alexey Charkov
  2014-04-22 15:28     ` [PATCH 1/3] net: via-rhine: switch to generic DMA functions Alexey Charkov
@ 2014-04-22 15:28     ` Alexey Charkov
  2014-04-22 15:28     ` [PATCH 3/3] net: via-rhine: add OF bus binding Alexey Charkov
  2014-04-23 19:26     ` [PATCH v2 0/3] net: via-rhine: add support for on-chip Rhine controllers David Miller
  3 siblings, 0 replies; 25+ messages in thread
From: Alexey Charkov @ 2014-04-22 15:28 UTC (permalink / raw)
  To: rl, netdev, devicetree, linux-kernel, linux, robh+dt, davem, ben
  Cc: Alexey Charkov

Use more generic data structures instead of struct pci_dev wherever
possible in preparation for OF bus binding

Signed-off-by: Alexey Charkov <alchark@gmail.com>
---
 drivers/net/ethernet/via/via-rhine.c | 116 +++++++++++++++++++----------------
 1 file changed, 62 insertions(+), 54 deletions(-)

diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index 0674d0f..20b83f1 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -446,7 +446,8 @@ struct rhine_private {
 	unsigned char *tx_bufs;
 	dma_addr_t tx_bufs_dma;
 
-	struct pci_dev *pdev;
+	int revision;
+	int irq;
 	long pioaddr;
 	struct net_device *dev;
 	struct napi_struct napi;
@@ -701,7 +702,7 @@ static void rhine_reload_eeprom(long pioaddr, struct net_device *dev)
 static void rhine_poll(struct net_device *dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
-	const int irq = rp->pdev->irq;
+	const int irq = rp->irq;
 
 	disable_irq(irq);
 	rhine_interrupt(irq, dev);
@@ -871,6 +872,8 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	struct net_device *dev;
 	struct rhine_private *rp;
+	struct device *hwdev = &pdev->dev;
+	int revision = pdev->revision;
 	int i, rc;
 	u32 quirks;
 	long pioaddr;
@@ -893,21 +896,19 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	phy_id = 0;
 	quirks = 0;
 	name = "Rhine";
-	if (pdev->revision < VTunknown0) {
+	if (revision < VTunknown0) {
 		quirks = rqRhineI;
 		io_size = 128;
-	}
-	else if (pdev->revision >= VT6102) {
+	} else if (revision >= VT6102) {
 		quirks = rqWOL | rqForceReset;
-		if (pdev->revision < VT6105) {
+		if (revision < VT6105) {
 			name = "Rhine II";
 			quirks |= rqStatusWBRace;	/* Rhine-II exclusive */
-		}
-		else {
+		} else {
 			phy_id = 1;	/* Integrated PHY, phy_id fixed to 1 */
-			if (pdev->revision >= VT6105_B0)
+			if (revision >= VT6105_B0)
 				quirks |= rq6patterns;
-			if (pdev->revision < VT6105M)
+			if (revision < VT6105M)
 				name = "Rhine III";
 			else
 				name = "Rhine III (Management Adapter)";
@@ -919,10 +920,9 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		goto err_out;
 
 	/* this should always be supported */
-	rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
+	rc = dma_set_mask(hwdev, DMA_BIT_MASK(32));
 	if (rc) {
-		dev_err(&pdev->dev,
-			"32-bit DMA addresses not supported by the card!?\n");
+		dev_err(hwdev, "32-bit DMA addresses not supported by the card!?\n");
 		goto err_out_pci_disable;
 	}
 
@@ -930,7 +930,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if ((pci_resource_len(pdev, 0) < io_size) ||
 	    (pci_resource_len(pdev, 1) < io_size)) {
 		rc = -EIO;
-		dev_err(&pdev->dev, "Insufficient PCI resources, aborting\n");
+		dev_err(hwdev, "Insufficient PCI resources, aborting\n");
 		goto err_out_pci_disable;
 	}
 
@@ -944,13 +944,13 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		rc = -ENOMEM;
 		goto err_out_pci_disable;
 	}
-	SET_NETDEV_DEV(dev, &pdev->dev);
+	SET_NETDEV_DEV(dev, hwdev);
 
 	rp = netdev_priv(dev);
 	rp->dev = dev;
+	rp->revision = revision;
 	rp->quirks = quirks;
 	rp->pioaddr = pioaddr;
-	rp->pdev = pdev;
 	rp->msg_enable = netif_msg_init(debug, RHINE_MSG_DEFAULT);
 
 	rc = pci_request_regions(pdev, DRV_NAME);
@@ -960,9 +960,9 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	ioaddr = pci_iomap(pdev, bar, io_size);
 	if (!ioaddr) {
 		rc = -EIO;
-		dev_err(&pdev->dev,
+		dev_err(hwdev,
 			"ioremap failed for device %s, region 0x%X @ 0x%lX\n",
-			pci_name(pdev), io_size, memaddr);
+			dev_name(hwdev), io_size, memaddr);
 		goto err_out_free_res;
 	}
 
@@ -977,7 +977,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		unsigned char b = readb(ioaddr+reg);
 		if (a != b) {
 			rc = -EIO;
-			dev_err(&pdev->dev,
+			dev_err(hwdev,
 				"MMIO do not match PIO [%02x] (%02x != %02x)\n",
 				reg, a, b);
 			goto err_out_unmap;
@@ -986,6 +986,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 #endif /* USE_MMIO */
 
 	rp->base = ioaddr;
+	rp->irq = pdev->irq;
 
 	u64_stats_init(&rp->tx_stats.syncp);
 	u64_stats_init(&rp->rx_stats.syncp);
@@ -1030,7 +1031,7 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (rp->quirks & rqRhineI)
 		dev->features |= NETIF_F_SG|NETIF_F_HW_CSUM;
 
-	if (pdev->revision >= VT6105M)
+	if (rp->revision >= VT6105M)
 		dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
 				 NETIF_F_HW_VLAN_CTAG_RX |
 				 NETIF_F_HW_VLAN_CTAG_FILTER;
@@ -1047,9 +1048,9 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 #else
 		    (long)ioaddr,
 #endif
-		    dev->dev_addr, pdev->irq);
+		    dev->dev_addr, rp->irq);
 
-	pci_set_drvdata(pdev, dev);
+	dev_set_drvdata(hwdev, dev);
 
 	{
 		u16 mii_cmd;
@@ -1093,10 +1094,11 @@ err_out:
 static int alloc_ring(struct net_device* dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	void *ring;
 	dma_addr_t ring_dma;
 
-	ring = dma_alloc_coherent(&rp->pdev->dev,
+	ring = dma_alloc_coherent(hwdev,
 				  RX_RING_SIZE * sizeof(struct rx_desc) +
 				  TX_RING_SIZE * sizeof(struct tx_desc),
 				  &ring_dma,
@@ -1106,12 +1108,12 @@ static int alloc_ring(struct net_device* dev)
 		return -ENOMEM;
 	}
 	if (rp->quirks & rqRhineI) {
-		rp->tx_bufs = dma_alloc_coherent(&rp->pdev->dev,
+		rp->tx_bufs = dma_alloc_coherent(hwdev,
 						 PKT_BUF_SZ * TX_RING_SIZE,
 						 &rp->tx_bufs_dma,
 						 GFP_ATOMIC);
 		if (rp->tx_bufs == NULL) {
-			dma_free_coherent(&rp->pdev->dev,
+			dma_free_coherent(hwdev,
 					  RX_RING_SIZE * sizeof(struct rx_desc) +
 					  TX_RING_SIZE * sizeof(struct tx_desc),
 					  ring, ring_dma);
@@ -1130,15 +1132,16 @@ static int alloc_ring(struct net_device* dev)
 static void free_ring(struct net_device* dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 
-	dma_free_coherent(&rp->pdev->dev,
+	dma_free_coherent(hwdev,
 			  RX_RING_SIZE * sizeof(struct rx_desc) +
 			  TX_RING_SIZE * sizeof(struct tx_desc),
 			  rp->rx_ring, rp->rx_ring_dma);
 	rp->tx_ring = NULL;
 
 	if (rp->tx_bufs)
-		dma_free_coherent(&rp->pdev->dev, PKT_BUF_SZ * TX_RING_SIZE,
+		dma_free_coherent(hwdev, PKT_BUF_SZ * TX_RING_SIZE,
 				  rp->tx_bufs, rp->tx_bufs_dma);
 
 	rp->tx_bufs = NULL;
@@ -1148,6 +1151,7 @@ static void free_ring(struct net_device* dev)
 static void alloc_rbufs(struct net_device *dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	dma_addr_t next;
 	int i;
 
@@ -1176,9 +1180,9 @@ static void alloc_rbufs(struct net_device *dev)
 			break;
 
 		rp->rx_skbuff_dma[i] =
-			dma_map_single(&rp->pdev->dev, skb->data, rp->rx_buf_sz,
+			dma_map_single(hwdev, skb->data, rp->rx_buf_sz,
 				       DMA_FROM_DEVICE);
-		if (dma_mapping_error(&rp->pdev->dev, rp->rx_skbuff_dma[i])) {
+		if (dma_mapping_error(hwdev, rp->rx_skbuff_dma[i])) {
 			rp->rx_skbuff_dma[i] = 0;
 			dev_kfree_skb(skb);
 			break;
@@ -1192,6 +1196,7 @@ static void alloc_rbufs(struct net_device *dev)
 static void free_rbufs(struct net_device* dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	int i;
 
 	/* Free all the skbuffs in the Rx queue. */
@@ -1199,7 +1204,7 @@ static void free_rbufs(struct net_device* dev)
 		rp->rx_ring[i].rx_status = 0;
 		rp->rx_ring[i].addr = cpu_to_le32(0xBADF00D0); /* An invalid address. */
 		if (rp->rx_skbuff[i]) {
-			dma_unmap_single(&rp->pdev->dev,
+			dma_unmap_single(hwdev,
 					 rp->rx_skbuff_dma[i],
 					 rp->rx_buf_sz, DMA_FROM_DEVICE);
 			dev_kfree_skb(rp->rx_skbuff[i]);
@@ -1232,6 +1237,7 @@ static void alloc_tbufs(struct net_device* dev)
 static void free_tbufs(struct net_device* dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	int i;
 
 	for (i = 0; i < TX_RING_SIZE; i++) {
@@ -1240,7 +1246,7 @@ static void free_tbufs(struct net_device* dev)
 		rp->tx_ring[i].addr = cpu_to_le32(0xBADF00D0); /* An invalid address. */
 		if (rp->tx_skbuff[i]) {
 			if (rp->tx_skbuff_dma[i]) {
-				dma_unmap_single(&rp->pdev->dev,
+				dma_unmap_single(hwdev,
 						 rp->tx_skbuff_dma[i],
 						 rp->tx_skbuff[i]->len,
 						 DMA_TO_DEVICE);
@@ -1471,7 +1477,7 @@ static void init_registers(struct net_device *dev)
 
 	rhine_set_rx_mode(dev);
 
-	if (rp->pdev->revision >= VT6105M)
+	if (rp->revision >= VT6105M)
 		rhine_init_cam_filter(dev);
 
 	napi_enable(&rp->napi);
@@ -1583,16 +1589,15 @@ static int rhine_open(struct net_device *dev)
 	void __iomem *ioaddr = rp->base;
 	int rc;
 
-	rc = request_irq(rp->pdev->irq, rhine_interrupt, IRQF_SHARED, dev->name,
-			dev);
+	rc = request_irq(rp->irq, rhine_interrupt, IRQF_SHARED, dev->name, dev);
 	if (rc)
 		return rc;
 
-	netif_dbg(rp, ifup, dev, "%s() irq %d\n", __func__, rp->pdev->irq);
+	netif_dbg(rp, ifup, dev, "%s() irq %d\n", __func__, rp->irq);
 
 	rc = alloc_ring(dev);
 	if (rc) {
-		free_irq(rp->pdev->irq, dev);
+		free_irq(rp->irq, dev);
 		return rc;
 	}
 	alloc_rbufs(dev);
@@ -1661,6 +1666,7 @@ static netdev_tx_t rhine_start_tx(struct sk_buff *skb,
 				  struct net_device *dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	void __iomem *ioaddr = rp->base;
 	unsigned entry;
 
@@ -1697,9 +1703,9 @@ static netdev_tx_t rhine_start_tx(struct sk_buff *skb,
 						       rp->tx_bufs));
 	} else {
 		rp->tx_skbuff_dma[entry] =
-			dma_map_single(&rp->pdev->dev, skb->data, skb->len,
+			dma_map_single(hwdev, skb->data, skb->len,
 				       DMA_TO_DEVICE);
-		if (dma_mapping_error(&rp->pdev->dev, rp->tx_skbuff_dma[entry])) {
+		if (dma_mapping_error(hwdev, rp->tx_skbuff_dma[entry])) {
 			dev_kfree_skb_any(skb);
 			rp->tx_skbuff_dma[entry] = 0;
 			dev->stats.tx_dropped++;
@@ -1790,6 +1796,7 @@ static irqreturn_t rhine_interrupt(int irq, void *dev_instance)
 static void rhine_tx(struct net_device *dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	int txstatus = 0, entry = rp->dirty_tx % TX_RING_SIZE;
 
 	/* find and cleanup dirty tx descriptors */
@@ -1833,7 +1840,7 @@ static void rhine_tx(struct net_device *dev)
 		}
 		/* Free the original skb. */
 		if (rp->tx_skbuff_dma[entry]) {
-			dma_unmap_single(&rp->pdev->dev,
+			dma_unmap_single(hwdev,
 					 rp->tx_skbuff_dma[entry],
 					 rp->tx_skbuff[entry]->len,
 					 DMA_TO_DEVICE);
@@ -1865,6 +1872,7 @@ static inline u16 rhine_get_vlan_tci(struct sk_buff *skb, int data_size)
 static int rhine_rx(struct net_device *dev, int limit)
 {
 	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 	int count;
 	int entry = rp->cur_rx % RX_RING_SIZE;
 
@@ -1926,7 +1934,7 @@ static int rhine_rx(struct net_device *dev, int limit)
 			if (pkt_len < rx_copybreak)
 				skb = netdev_alloc_skb_ip_align(dev, pkt_len);
 			if (skb) {
-				dma_sync_single_for_cpu(&rp->pdev->dev,
+				dma_sync_single_for_cpu(hwdev,
 							rp->rx_skbuff_dma[entry],
 							rp->rx_buf_sz,
 							DMA_FROM_DEVICE);
@@ -1935,7 +1943,7 @@ static int rhine_rx(struct net_device *dev, int limit)
 						 rp->rx_skbuff[entry]->data,
 						 pkt_len);
 				skb_put(skb, pkt_len);
-				dma_sync_single_for_device(&rp->pdev->dev,
+				dma_sync_single_for_device(hwdev,
 							   rp->rx_skbuff_dma[entry],
 							   rp->rx_buf_sz,
 							   DMA_FROM_DEVICE);
@@ -1947,7 +1955,7 @@ static int rhine_rx(struct net_device *dev, int limit)
 				}
 				rp->rx_skbuff[entry] = NULL;
 				skb_put(skb, pkt_len);
-				dma_unmap_single(&rp->pdev->dev,
+				dma_unmap_single(hwdev,
 						 rp->rx_skbuff_dma[entry],
 						 rp->rx_buf_sz,
 						 DMA_FROM_DEVICE);
@@ -1981,10 +1989,11 @@ static int rhine_rx(struct net_device *dev, int limit)
 			if (skb == NULL)
 				break;	/* Better luck next round. */
 			rp->rx_skbuff_dma[entry] =
-				dma_map_single(&rp->pdev->dev, skb->data,
+				dma_map_single(hwdev, skb->data,
 					       rp->rx_buf_sz,
 					       DMA_FROM_DEVICE);
-			if (dma_mapping_error(&rp->pdev->dev, rp->rx_skbuff_dma[entry])) {
+			if (dma_mapping_error(hwdev,
+					      rp->rx_skbuff_dma[entry])) {
 				dev_kfree_skb(skb);
 				rp->rx_skbuff_dma[entry] = 0;
 				break;
@@ -2105,7 +2114,7 @@ static void rhine_set_rx_mode(struct net_device *dev)
 		/* Too many to match, or accept all multicasts. */
 		iowrite32(0xffffffff, ioaddr + MulticastFilter0);
 		iowrite32(0xffffffff, ioaddr + MulticastFilter1);
-	} else if (rp->pdev->revision >= VT6105M) {
+	} else if (rp->revision >= VT6105M) {
 		int i = 0;
 		u32 mCAMmask = 0;	/* 32 mCAMs (6105M and better) */
 		netdev_for_each_mc_addr(ha, dev) {
@@ -2127,7 +2136,7 @@ static void rhine_set_rx_mode(struct net_device *dev)
 		iowrite32(mc_filter[1], ioaddr + MulticastFilter1);
 	}
 	/* enable/disable VLAN receive filtering */
-	if (rp->pdev->revision >= VT6105M) {
+	if (rp->revision >= VT6105M) {
 		if (dev->flags & IFF_PROMISC)
 			BYTE_REG_BITS_OFF(BCR1_VIDFR, ioaddr + PCIBusConfig1);
 		else
@@ -2138,11 +2147,11 @@ static void rhine_set_rx_mode(struct net_device *dev)
 
 static void netdev_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
 {
-	struct rhine_private *rp = netdev_priv(dev);
+	struct device *hwdev = dev->dev.parent;
 
 	strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
 	strlcpy(info->version, DRV_VERSION, sizeof(info->version));
-	strlcpy(info->bus_info, pci_name(rp->pdev), sizeof(info->bus_info));
+	strlcpy(info->bus_info, dev_name(hwdev), sizeof(info->bus_info));
 }
 
 static int netdev_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
@@ -2279,7 +2288,7 @@ static int rhine_close(struct net_device *dev)
 	/* Stop the chip's Tx and Rx processes. */
 	iowrite16(CmdStop, ioaddr + ChipCmd);
 
-	free_irq(rp->pdev->irq, dev);
+	free_irq(rp->irq, dev);
 	free_rbufs(dev);
 	free_tbufs(dev);
 	free_ring(dev);
@@ -2356,8 +2365,7 @@ static void rhine_shutdown (struct pci_dev *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int rhine_suspend(struct device *device)
 {
-	struct pci_dev *pdev = to_pci_dev(device);
-	struct net_device *dev = pci_get_drvdata(pdev);
+	struct net_device *dev = dev_get_drvdata(device);
 	struct rhine_private *rp = netdev_priv(dev);
 
 	if (!netif_running(dev))
@@ -2369,15 +2377,15 @@ static int rhine_suspend(struct device *device)
 
 	netif_device_detach(dev);
 
-	rhine_shutdown(pdev);
+	if (dev_is_pci(device))
+		rhine_shutdown(to_pci_dev(device));
 
 	return 0;
 }
 
 static int rhine_resume(struct device *device)
 {
-	struct pci_dev *pdev = to_pci_dev(device);
-	struct net_device *dev = pci_get_drvdata(pdev);
+	struct net_device *dev = dev_get_drvdata(device);
 	struct rhine_private *rp = netdev_priv(dev);
 
 	if (!netif_running(dev))
-- 
1.9.1


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

* [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-04-22 15:28   ` [PATCH v2 0/3] net: via-rhine: add support for on-chip Rhine controllers Alexey Charkov
  2014-04-22 15:28     ` [PATCH 1/3] net: via-rhine: switch to generic DMA functions Alexey Charkov
  2014-04-22 15:28     ` [PATCH 2/3] net: via-rhine: reduce usage of the PCI-specific struct Alexey Charkov
@ 2014-04-22 15:28     ` Alexey Charkov
  2014-04-22 15:46       ` Rob Herring
  2014-04-23 19:26     ` [PATCH v2 0/3] net: via-rhine: add support for on-chip Rhine controllers David Miller
  3 siblings, 1 reply; 25+ messages in thread
From: Alexey Charkov @ 2014-04-22 15:28 UTC (permalink / raw)
  To: rl, netdev, devicetree, linux-kernel, linux, robh+dt, davem, ben
  Cc: Alexey Charkov

This should make the driver usable with VIA/WonderMedia ARM-based
Systems-on-Chip integrated Rhine III adapters. Note that these
are always in MMIO mode, and don't have any known EEPROM.

Signed-off-by: Alexey Charkov <alchark@gmail.com>
---
 .../devicetree/bindings/net/via-rhine.txt          |  17 ++
 arch/arm/boot/dts/vt8500.dtsi                      |   6 +
 arch/arm/boot/dts/wm8650.dtsi                      |   6 +
 arch/arm/boot/dts/wm8850.dtsi                      |   6 +
 drivers/net/ethernet/via/Kconfig                   |   2 +-
 drivers/net/ethernet/via/via-rhine.c               | 307 +++++++++++++--------
 6 files changed, 229 insertions(+), 115 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/via-rhine.txt

diff --git a/Documentation/devicetree/bindings/net/via-rhine.txt b/Documentation/devicetree/bindings/net/via-rhine.txt
new file mode 100644
index 0000000..334eca2
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/via-rhine.txt
@@ -0,0 +1,17 @@
+* VIA Rhine 10/100 Network Controller
+
+Required properties:
+- compatible : Should be "via,vt8500-rhine" for integrated
+	Rhine controllers found in VIA VT8500, WonderMedia WM8950
+	and similar. These are listed as 1106:3106 rev. 0x84 on the
+	virtual PCI bus under vendor-provided kernels
+- reg : Address and length of the io space
+- interrupts : Should contain the controller interrupt line
+
+Examples:
+
+ethernet@d8004000 {
+	compatible = "via,vt8500-rhine";
+	reg = <0xd8004000 0x100>;
+	interrupts = <10>;
+};
diff --git a/arch/arm/boot/dts/vt8500.dtsi b/arch/arm/boot/dts/vt8500.dtsi
index 51d0e91..1929ad3 100644
--- a/arch/arm/boot/dts/vt8500.dtsi
+++ b/arch/arm/boot/dts/vt8500.dtsi
@@ -165,5 +165,11 @@
 			reg = <0xd8100000 0x10000>;
 			interrupts = <48>;
 		};
+
+		ethernet@d8004000 {
+			compatible = "via,vt8500-rhine";
+			reg = <0xd8004000 0x100>;
+			interrupts = <10>;
+		};
 	};
 };
diff --git a/arch/arm/boot/dts/wm8650.dtsi b/arch/arm/boot/dts/wm8650.dtsi
index 7525982..b1c59a7 100644
--- a/arch/arm/boot/dts/wm8650.dtsi
+++ b/arch/arm/boot/dts/wm8650.dtsi
@@ -218,5 +218,11 @@
 			reg = <0xd8100000 0x10000>;
 			interrupts = <48>;
 		};
+
+		ethernet@d8004000 {
+			compatible = "via,vt8500-rhine";
+			reg = <0xd8004000 0x100>;
+			interrupts = <10>;
+		};
 	};
 };
diff --git a/arch/arm/boot/dts/wm8850.dtsi b/arch/arm/boot/dts/wm8850.dtsi
index d98386d..8fbccfbe 100644
--- a/arch/arm/boot/dts/wm8850.dtsi
+++ b/arch/arm/boot/dts/wm8850.dtsi
@@ -298,5 +298,11 @@
 			bus-width = <4>;
 			sdon-inverted;
 		};
+
+		ethernet@d8004000 {
+			compatible = "via,vt8500-rhine";
+			reg = <0xd8004000 0x100>;
+			interrupts = <10>;
+                };
 	};
 };
diff --git a/drivers/net/ethernet/via/Kconfig b/drivers/net/ethernet/via/Kconfig
index 8a049a2..f66ddae 100644
--- a/drivers/net/ethernet/via/Kconfig
+++ b/drivers/net/ethernet/via/Kconfig
@@ -19,7 +19,7 @@ if NET_VENDOR_VIA
 
 config VIA_RHINE
 	tristate "VIA Rhine support"
-	depends on PCI
+	depends on (PCI || USE_OF)
 	select CRC32
 	select MII
 	---help---
diff --git a/drivers/net/ethernet/via/via-rhine.c b/drivers/net/ethernet/via/via-rhine.c
index 20b83f1..4fa9201 100644
--- a/drivers/net/ethernet/via/via-rhine.c
+++ b/drivers/net/ethernet/via/via-rhine.c
@@ -94,6 +94,10 @@ static const int multicast_filter_limit = 32;
 #include <linux/ioport.h>
 #include <linux/interrupt.h>
 #include <linux/pci.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/of_irq.h>
+#include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
@@ -279,6 +283,15 @@ static DEFINE_PCI_DEVICE_TABLE(rhine_pci_tbl) = {
 };
 MODULE_DEVICE_TABLE(pci, rhine_pci_tbl);
 
+/* OpenFirmware identifiers for platform-bus devices
+ * The .data field is currently only used to store chip revision
+ * (for quirks etc.)
+ */
+static struct of_device_id rhine_of_tbl[] = {
+	{ .compatible = "via,vt8500-rhine", .data = (void *)0x84 },
+	{ }	/* terminate list */
+};
+MODULE_DEVICE_TABLE(of, rhine_of_tbl);
 
 /* Offsets to the device registers. */
 enum register_offsets {
@@ -847,7 +860,8 @@ static void rhine_hw_init(struct net_device *dev, long pioaddr)
 		msleep(5);
 
 	/* Reload EEPROM controlled bytes cleared by soft reset */
-	rhine_reload_eeprom(pioaddr, dev);
+	if (dev_is_pci(dev->dev.parent))
+		rhine_reload_eeprom(pioaddr, dev);
 }
 
 static const struct net_device_ops rhine_netdev_ops = {
@@ -868,125 +882,55 @@ static const struct net_device_ops rhine_netdev_ops = {
 #endif
 };
 
-static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
+static int rhine_init_one_common(struct device *hwdev, int revision,
+				 long pioaddr, void __iomem *ioaddr, int irq)
 {
 	struct net_device *dev;
 	struct rhine_private *rp;
-	struct device *hwdev = &pdev->dev;
-	int revision = pdev->revision;
-	int i, rc;
-	u32 quirks;
-	long pioaddr;
-	long memaddr;
-	void __iomem *ioaddr;
-	int io_size, phy_id;
+	int i, rc, phy_id;
 	const char *name;
-#ifdef USE_MMIO
-	int bar = 1;
-#else
-	int bar = 0;
-#endif
-
-/* when built into the kernel, we only print version if device is found */
-#ifndef MODULE
-	pr_info_once("%s\n", version);
-#endif
-
-	io_size = 256;
-	phy_id = 0;
-	quirks = 0;
-	name = "Rhine";
-	if (revision < VTunknown0) {
-		quirks = rqRhineI;
-		io_size = 128;
-	} else if (revision >= VT6102) {
-		quirks = rqWOL | rqForceReset;
-		if (revision < VT6105) {
-			name = "Rhine II";
-			quirks |= rqStatusWBRace;	/* Rhine-II exclusive */
-		} else {
-			phy_id = 1;	/* Integrated PHY, phy_id fixed to 1 */
-			if (revision >= VT6105_B0)
-				quirks |= rq6patterns;
-			if (revision < VT6105M)
-				name = "Rhine III";
-			else
-				name = "Rhine III (Management Adapter)";
-		}
-	}
-
-	rc = pci_enable_device(pdev);
-	if (rc)
-		goto err_out;
 
 	/* this should always be supported */
 	rc = dma_set_mask(hwdev, DMA_BIT_MASK(32));
 	if (rc) {
 		dev_err(hwdev, "32-bit DMA addresses not supported by the card!?\n");
-		goto err_out_pci_disable;
-	}
-
-	/* sanity check */
-	if ((pci_resource_len(pdev, 0) < io_size) ||
-	    (pci_resource_len(pdev, 1) < io_size)) {
-		rc = -EIO;
-		dev_err(hwdev, "Insufficient PCI resources, aborting\n");
-		goto err_out_pci_disable;
+		goto err_out;
 	}
 
-	pioaddr = pci_resource_start(pdev, 0);
-	memaddr = pci_resource_start(pdev, 1);
-
-	pci_set_master(pdev);
-
 	dev = alloc_etherdev(sizeof(struct rhine_private));
 	if (!dev) {
 		rc = -ENOMEM;
-		goto err_out_pci_disable;
+		goto err_out;
 	}
 	SET_NETDEV_DEV(dev, hwdev);
 
 	rp = netdev_priv(dev);
 	rp->dev = dev;
 	rp->revision = revision;
-	rp->quirks = quirks;
 	rp->pioaddr = pioaddr;
+	rp->base = ioaddr;
+	rp->irq = irq;
 	rp->msg_enable = netif_msg_init(debug, RHINE_MSG_DEFAULT);
 
-	rc = pci_request_regions(pdev, DRV_NAME);
-	if (rc)
-		goto err_out_free_netdev;
-
-	ioaddr = pci_iomap(pdev, bar, io_size);
-	if (!ioaddr) {
-		rc = -EIO;
-		dev_err(hwdev,
-			"ioremap failed for device %s, region 0x%X @ 0x%lX\n",
-			dev_name(hwdev), io_size, memaddr);
-		goto err_out_free_res;
-	}
-
-#ifdef USE_MMIO
-	enable_mmio(pioaddr, quirks);
-
-	/* Check that selected MMIO registers match the PIO ones */
-	i = 0;
-	while (mmio_verify_registers[i]) {
-		int reg = mmio_verify_registers[i++];
-		unsigned char a = inb(pioaddr+reg);
-		unsigned char b = readb(ioaddr+reg);
-		if (a != b) {
-			rc = -EIO;
-			dev_err(hwdev,
-				"MMIO do not match PIO [%02x] (%02x != %02x)\n",
-				reg, a, b);
-			goto err_out_unmap;
+	phy_id = 0;
+	name = "Rhine";
+	if (revision < VTunknown0) {
+		rp->quirks = rqRhineI;
+	} else if (revision >= VT6102) {
+		rp->quirks = rqWOL | rqForceReset;
+		if (revision < VT6105) {
+			name = "Rhine II";
+			rp->quirks |= rqStatusWBRace;	/* Rhine-II exclusive */
+		} else {
+			phy_id = 1;	/* Integrated PHY, phy_id fixed to 1 */
+			if (revision >= VT6105_B0)
+				rp->quirks |= rq6patterns;
+			if (revision < VT6105M)
+				name = "Rhine III";
+			else
+				name = "Rhine III (Management Adapter)";
 		}
 	}
-#endif /* USE_MMIO */
-
-	rp->base = ioaddr;
-	rp->irq = pdev->irq;
 
 	u64_stats_init(&rp->tx_stats.syncp);
 	u64_stats_init(&rp->rx_stats.syncp);
@@ -1039,16 +983,10 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	/* dev->name not defined before register_netdev()! */
 	rc = register_netdev(dev);
 	if (rc)
-		goto err_out_unmap;
+		goto err_out_free_netdev;
 
 	netdev_info(dev, "VIA %s at 0x%lx, %pM, IRQ %d\n",
-		    name,
-#ifdef USE_MMIO
-		    memaddr,
-#else
-		    (long)ioaddr,
-#endif
-		    dev->dev_addr, rp->irq);
+		    name, (long)ioaddr, dev->dev_addr, rp->irq);
 
 	dev_set_drvdata(hwdev, dev);
 
@@ -1079,18 +1017,126 @@ static int rhine_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	return 0;
 
+err_out_free_netdev:
+	free_netdev(dev);
+err_out:
+	return rc;
+}
+
+static int rhine_init_one_pci(struct pci_dev *pdev,
+			      const struct pci_device_id *ent)
+{
+	struct device *hwdev = &pdev->dev;
+	int i, rc;
+	long pioaddr, memaddr;
+	void __iomem *ioaddr;
+	int io_size = pdev->revision < VTunknown0 ? 128 : 256;
+	u32 quirks = pdev->revision < VTunknown0 ? rqRhineI : 0;
+#ifdef USE_MMIO
+	int bar = 1;
+#else
+	int bar = 0;
+#endif
+
+/* when built into the kernel, we only print version if device is found */
+#ifndef MODULE
+	pr_info_once("%s\n", version);
+#endif
+
+	rc = pci_enable_device(pdev);
+	if (rc)
+		goto err_out;
+
+	/* sanity check */
+	if ((pci_resource_len(pdev, 0) < io_size) ||
+	    (pci_resource_len(pdev, 1) < io_size)) {
+		rc = -EIO;
+		dev_err(hwdev, "Insufficient PCI resources, aborting\n");
+		goto err_out_pci_disable;
+	}
+
+	pioaddr = pci_resource_start(pdev, 0);
+	memaddr = pci_resource_start(pdev, 1);
+
+	pci_set_master(pdev);
+
+	rc = pci_request_regions(pdev, DRV_NAME);
+	if (rc)
+		goto err_out_pci_disable;
+
+	ioaddr = pci_iomap(pdev, bar, io_size);
+	if (!ioaddr) {
+		rc = -EIO;
+		dev_err(hwdev,
+			"ioremap failed for device %s, region 0x%X @ 0x%lX\n",
+			dev_name(hwdev), io_size, memaddr);
+		goto err_out_free_res;
+	}
+
+#ifdef USE_MMIO
+	enable_mmio(pioaddr, quirks);
+
+	/* Check that selected MMIO registers match the PIO ones */
+	i = 0;
+	while (mmio_verify_registers[i]) {
+		int reg = mmio_verify_registers[i++];
+		unsigned char a = inb(pioaddr+reg);
+		unsigned char b = readb(ioaddr+reg);
+
+		if (a != b) {
+			rc = -EIO;
+			dev_err(hwdev,
+				"MMIO do not match PIO [%02x] (%02x != %02x)\n",
+				reg, a, b);
+			goto err_out_unmap;
+		}
+	}
+#endif /* USE_MMIO */
+
+	rc = rhine_init_one_common(&pdev->dev, pdev->revision,
+				   pioaddr, ioaddr, pdev->irq);
+	if (!rc)
+		return 0;
+
 err_out_unmap:
 	pci_iounmap(pdev, ioaddr);
 err_out_free_res:
 	pci_release_regions(pdev);
-err_out_free_netdev:
-	free_netdev(dev);
 err_out_pci_disable:
 	pci_disable_device(pdev);
 err_out:
 	return rc;
 }
 
+static int rhine_init_one_platform(struct platform_device *pdev)
+{
+	const struct of_device_id *match;
+	u32 revision;
+	int irq;
+	struct resource *res;
+	void __iomem *ioaddr;
+
+	match = of_match_device(rhine_of_tbl, &pdev->dev);
+	if (!match)
+		return -EINVAL;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	ioaddr = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(ioaddr))
+		return PTR_ERR(ioaddr);
+
+	irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
+	if (!irq)
+		return -EINVAL;
+
+	revision = (u32)match->data;
+	if (!revision)
+		return -EINVAL;
+
+	return rhine_init_one_common(&pdev->dev, revision,
+				     (long)ioaddr, ioaddr, irq);
+}
+
 static int alloc_ring(struct net_device* dev)
 {
 	struct rhine_private *rp = netdev_priv(dev);
@@ -2297,7 +2343,7 @@ static int rhine_close(struct net_device *dev)
 }
 
 
-static void rhine_remove_one(struct pci_dev *pdev)
+static void rhine_remove_one_pci(struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
 	struct rhine_private *rp = netdev_priv(dev);
@@ -2311,7 +2357,21 @@ static void rhine_remove_one(struct pci_dev *pdev)
 	pci_disable_device(pdev);
 }
 
-static void rhine_shutdown (struct pci_dev *pdev)
+static int rhine_remove_one_platform(struct platform_device *pdev)
+{
+	struct net_device *dev = platform_get_drvdata(pdev);
+	struct rhine_private *rp = netdev_priv(dev);
+
+	unregister_netdev(dev);
+
+	iounmap(rp->base);
+
+	free_netdev(dev);
+
+	return 0;
+}
+
+static void rhine_shutdown_pci(struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
 	struct rhine_private *rp = netdev_priv(dev);
@@ -2378,7 +2438,7 @@ static int rhine_suspend(struct device *device)
 	netif_device_detach(dev);
 
 	if (dev_is_pci(device))
-		rhine_shutdown(to_pci_dev(device));
+		rhine_shutdown_pci(to_pci_dev(device));
 
 	return 0;
 }
@@ -2418,15 +2478,26 @@ static SIMPLE_DEV_PM_OPS(rhine_pm_ops, rhine_suspend, rhine_resume);
 
 #endif /* !CONFIG_PM_SLEEP */
 
-static struct pci_driver rhine_driver = {
+static struct pci_driver rhine_driver_pci = {
 	.name		= DRV_NAME,
 	.id_table	= rhine_pci_tbl,
-	.probe		= rhine_init_one,
-	.remove		= rhine_remove_one,
-	.shutdown	= rhine_shutdown,
+	.probe		= rhine_init_one_pci,
+	.remove		= rhine_remove_one_pci,
+	.shutdown	= rhine_shutdown_pci,
 	.driver.pm	= RHINE_PM_OPS,
 };
 
+static struct platform_driver rhine_driver_platform = {
+	.probe		= rhine_init_one_platform,
+	.remove		= rhine_remove_one_platform,
+	.driver = {
+		.name	= DRV_NAME,
+		.owner	= THIS_MODULE,
+		.of_match_table	= rhine_of_tbl,
+		.pm		= RHINE_PM_OPS,
+	}
+};
+
 static struct dmi_system_id rhine_dmi_table[] __initdata = {
 	{
 		.ident = "EPIA-M",
@@ -2447,6 +2518,8 @@ static struct dmi_system_id rhine_dmi_table[] __initdata = {
 
 static int __init rhine_init(void)
 {
+	int ret_pci, ret_platform;
+
 /* when a module, this is printed whether or not devices are found in probe */
 #ifdef MODULE
 	pr_info("%s\n", version);
@@ -2459,13 +2532,19 @@ static int __init rhine_init(void)
 	else if (avoid_D3)
 		pr_info("avoid_D3 set\n");
 
-	return pci_register_driver(&rhine_driver);
+	ret_pci = pci_register_driver(&rhine_driver_pci);
+	ret_platform = platform_driver_register(&rhine_driver_platform);
+	if ((ret_pci < 0) && (ret_platform < 0))
+		return ret_pci;
+
+	return 0;
 }
 
 
 static void __exit rhine_cleanup(void)
 {
-	pci_unregister_driver(&rhine_driver);
+	platform_driver_unregister(&rhine_driver_platform);
+	pci_unregister_driver(&rhine_driver_pci);
 }
 
 
-- 
1.9.1


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

* Re: [PATCH 3/3] net: via-rhine: add OF bus binding
  2014-04-22 15:28     ` [PATCH 3/3] net: via-rhine: add OF bus binding Alexey Charkov
@ 2014-04-22 15:46       ` Rob Herring
  0 siblings, 0 replies; 25+ messages in thread
From: Rob Herring @ 2014-04-22 15:46 UTC (permalink / raw)
  To: Alexey Charkov
  Cc: Roger Luethi, netdev, devicetree, linux-kernel, Tony Prisk,
	Rob Herring, David Miller, ben

On Tue, Apr 22, 2014 at 10:28 AM, Alexey Charkov <alchark@gmail.com> wrote:
> This should make the driver usable with VIA/WonderMedia ARM-based
> Systems-on-Chip integrated Rhine III adapters. Note that these
> are always in MMIO mode, and don't have any known EEPROM.
>
> Signed-off-by: Alexey Charkov <alchark@gmail.com>

For the binding:

Acked-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v2 0/3] net: via-rhine: add support for on-chip Rhine controllers
  2014-04-22 15:28   ` [PATCH v2 0/3] net: via-rhine: add support for on-chip Rhine controllers Alexey Charkov
                       ` (2 preceding siblings ...)
  2014-04-22 15:28     ` [PATCH 3/3] net: via-rhine: add OF bus binding Alexey Charkov
@ 2014-04-23 19:26     ` David Miller
  3 siblings, 0 replies; 25+ messages in thread
From: David Miller @ 2014-04-23 19:26 UTC (permalink / raw)
  To: alchark; +Cc: rl, netdev, devicetree, linux-kernel, linux, robh+dt, ben

From: Alexey Charkov <alchark@gmail.com>
Date: Tue, 22 Apr 2014 19:28:06 +0400

> This series introduces platform bus (OpenFirmware) binding for 
> via-rhine, as used in various ARM-based Systems-on-Chip by 
> VIA/WonderMedia.
> 
> This has been tested in OF configuration by myself on a WM8950-based VIA 
> APC Rock development board and on a WM8850-based netbook, and in PCI
> configuration by Roger.
> 
> Please note that the initial version of these patches was signed off by
> Roger, but some time has passed since then, so I'm not including his
> sign-off until explicit notice.
> 
> David, could you please take these to net-next if appropriate?

Series applied to net-next, thanks Alexey.

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

end of thread, other threads:[~2014-04-23 19:26 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1385227995-3956-1-git-send-email-alchark@gmail.com>
2013-11-30 19:07 ` [PATCH 0/3] net: via-rhine: add support for on-chip Rhine controllers Alexey Charkov
2014-01-27 11:51 ` [PATCH 0/3] Resubmit: " Alexey Charkov
2014-01-27 11:51   ` [PATCH 1/3] net: via-rhine: switch to generic DMA functions Alexey Charkov
2014-01-27 14:49     ` Ben Hutchings
2014-01-27 15:26       ` Alexey Charkov
2014-01-27 15:28         ` Ben Hutchings
2014-01-27 11:51   ` [PATCH 2/3] net: via-rhine: reduce usage of the PCI-specific struct Alexey Charkov
2014-01-27 11:51   ` [PATCH 3/3] net: via-rhine: add OF bus binding Alexey Charkov
2014-01-27 14:57     ` Ben Hutchings
2014-01-27 15:34       ` Alexey Charkov
2014-01-27 23:40         ` Ben Hutchings
2014-01-28 18:31           ` Alexey Charkov
2014-01-31 14:24             ` Ben Hutchings
2014-01-27 15:56     ` Rob Herring
2014-01-28 18:27       ` Alexey Charkov
2014-01-29  3:44         ` Tony Prisk
2014-01-29  5:20           ` Alexey Charkov
2014-01-29 14:59             ` Rob Herring
2014-01-29 13:46         ` Rob Herring
2014-04-22 15:28   ` [PATCH v2 0/3] net: via-rhine: add support for on-chip Rhine controllers Alexey Charkov
2014-04-22 15:28     ` [PATCH 1/3] net: via-rhine: switch to generic DMA functions Alexey Charkov
2014-04-22 15:28     ` [PATCH 2/3] net: via-rhine: reduce usage of the PCI-specific struct Alexey Charkov
2014-04-22 15:28     ` [PATCH 3/3] net: via-rhine: add OF bus binding Alexey Charkov
2014-04-22 15:46       ` Rob Herring
2014-04-23 19:26     ` [PATCH v2 0/3] net: via-rhine: add support for on-chip Rhine controllers David Miller

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).