Re: [PATCH v2 2/2] net/macb: merge at91_ether driver into macb driver

2015-03-06 Thread Alexandre Belloni
On 06/03/2015 at 07:13:59 +0100, Boris Brezillon wrote :
> From: Cyrille Pitchen 
> 
> macb and at91_ether drivers can be compiled as modules, but the at91_ether
> driver use some functions and variables defined in the macb one, thus
> creating a dependency on the macb driver.
> 
> Since these drivers are sharing the same logic we can easily merge
> at91_ether into macb.
> 
> In order to factorize common probing logic we've added an ->init() function
> to struct macb_config (the structure associated with the compatible
> string), and moved macb specific init code from macb_probe to macb_init.
> 
> Signed-off-by: Cyrille Pitchen 
> Signed-off-by: Boris Brezillon 
Tested-by: Alexandre Belloni 

> ---
>  drivers/net/ethernet/cadence/Kconfig  |   8 -
>  drivers/net/ethernet/cadence/Makefile |   1 -
>  drivers/net/ethernet/cadence/at91_ether.c | 481 --
>  drivers/net/ethernet/cadence/macb.c   | 641 
> ++
>  drivers/net/ethernet/cadence/macb.h   |  10 +-
>  5 files changed, 485 insertions(+), 656 deletions(-)
>  delete mode 100644 drivers/net/ethernet/cadence/at91_ether.c
> 
> diff --git a/drivers/net/ethernet/cadence/Kconfig 
> b/drivers/net/ethernet/cadence/Kconfig
> index 321d2ad..fb8d09b 100644
> --- a/drivers/net/ethernet/cadence/Kconfig
> +++ b/drivers/net/ethernet/cadence/Kconfig
> @@ -20,14 +20,6 @@ config NET_CADENCE
>  
>  if NET_CADENCE
>  
> -config ARM_AT91_ETHER
> - tristate "AT91RM9200 Ethernet support"
> - depends on HAS_DMA && (ARCH_AT91 || COMPILE_TEST)
> - select MACB
> - ---help---
> -   If you wish to compile a kernel for the AT91RM9200 and enable
> -   ethernet support, then you should always answer Y to this.
> -
>  config MACB
>   tristate "Cadence MACB/GEM support"
>   depends on HAS_DMA && (PLATFORM_AT32AP || ARCH_AT91 || ARCH_PICOXCELL 
> || ARCH_ZYNQ || MICROBLAZE || COMPILE_TEST)
> diff --git a/drivers/net/ethernet/cadence/Makefile 
> b/drivers/net/ethernet/cadence/Makefile
> index 9068b83..91f79b1 100644
> --- a/drivers/net/ethernet/cadence/Makefile
> +++ b/drivers/net/ethernet/cadence/Makefile
> @@ -2,5 +2,4 @@
>  # Makefile for the Atmel network device drivers.
>  #
>  
> -obj-$(CONFIG_ARM_AT91_ETHER) += at91_ether.o
>  obj-$(CONFIG_MACB) += macb.o
> diff --git a/drivers/net/ethernet/cadence/at91_ether.c 
> b/drivers/net/ethernet/cadence/at91_ether.c
> deleted file mode 100644
> index 7ef55f5..000
> --- a/drivers/net/ethernet/cadence/at91_ether.c
> +++ /dev/null
> @@ -1,481 +0,0 @@
> -/*
> - * Ethernet driver for the Atmel AT91RM9200 (Thunder)
> - *
> - *  Copyright (C) 2003 SAN People (Pty) Ltd
> - *
> - * Based on an earlier Atmel EMAC macrocell driver by Atmel and Lineo Inc.
> - * Initial version by Rick Bronson 01/11/2003
> - *
> - * This program is free software; you can redistribute it and/or
> - * modify it under the terms of the GNU General Public License
> - * as published by the Free Software Foundation; either version
> - * 2 of the License, or (at your option) any later version.
> - */
> -
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -
> -#include "macb.h"
> -
> -/* 1518 rounded up */
> -#define MAX_RBUFF_SZ 0x600
> -/* max number of receive buffers */
> -#define MAX_RX_DESCR 9
> -
> -/* Initialize and start the Receiver and Transmit subsystems */
> -static int at91ether_start(struct net_device *dev)
> -{
> - struct macb *lp = netdev_priv(dev);
> - dma_addr_t addr;
> - u32 ctl;
> - int i;
> -
> - lp->rx_ring = dma_alloc_coherent(&lp->pdev->dev,
> -  (MAX_RX_DESCR *
> -   sizeof(struct macb_dma_desc)),
> -  &lp->rx_ring_dma, GFP_KERNEL);
> - if (!lp->rx_ring)
> - return -ENOMEM;
> -
> - lp->rx_buffers = dma_alloc_coherent(&lp->pdev->dev,
> - MAX_RX_DESCR * MAX_RBUFF_SZ,
> - &lp->rx_buffers_dma, GFP_KERNEL);
> - if (!lp->rx_buffers) {
> - dma_free_coherent(&lp->pdev->dev,
> -   MAX_RX_DESCR * sizeof(struct macb_dma_desc),
> -   lp->rx_ring, lp->rx_ring_dma);
> - lp->rx_ring = NULL;
> - return -ENOMEM;
> - }
> -
> - addr = lp->rx_buffers_dma;
> - for (i = 0; i < MAX_RX_DESCR; i++) {
> - lp->rx_ring[i].addr = addr;
> - lp->rx_ring[i].ctrl = 0;
> - addr += MAX_RBUFF_SZ;
> - }
> -
> - /* Set the Wrap bit on the last descriptor */
> - lp->rx_ring[MAX_RX_DESCR - 1].addr |= MACB_BIT(RX_WRAP);
> -
> - /* Reset buffer index */
> - lp->rx_tail = 0;
> -
> - /* Program address of descriptor list in Rx Buffer Queue registe

[PATCH v2 2/2] net/macb: merge at91_ether driver into macb driver

2015-03-05 Thread Boris Brezillon
From: Cyrille Pitchen 

macb and at91_ether drivers can be compiled as modules, but the at91_ether
driver use some functions and variables defined in the macb one, thus
creating a dependency on the macb driver.

Since these drivers are sharing the same logic we can easily merge
at91_ether into macb.

In order to factorize common probing logic we've added an ->init() function
to struct macb_config (the structure associated with the compatible
string), and moved macb specific init code from macb_probe to macb_init.

Signed-off-by: Cyrille Pitchen 
Signed-off-by: Boris Brezillon 
---
 drivers/net/ethernet/cadence/Kconfig  |   8 -
 drivers/net/ethernet/cadence/Makefile |   1 -
 drivers/net/ethernet/cadence/at91_ether.c | 481 --
 drivers/net/ethernet/cadence/macb.c   | 641 ++
 drivers/net/ethernet/cadence/macb.h   |  10 +-
 5 files changed, 485 insertions(+), 656 deletions(-)
 delete mode 100644 drivers/net/ethernet/cadence/at91_ether.c

diff --git a/drivers/net/ethernet/cadence/Kconfig 
b/drivers/net/ethernet/cadence/Kconfig
index 321d2ad..fb8d09b 100644
--- a/drivers/net/ethernet/cadence/Kconfig
+++ b/drivers/net/ethernet/cadence/Kconfig
@@ -20,14 +20,6 @@ config NET_CADENCE
 
 if NET_CADENCE
 
-config ARM_AT91_ETHER
-   tristate "AT91RM9200 Ethernet support"
-   depends on HAS_DMA && (ARCH_AT91 || COMPILE_TEST)
-   select MACB
-   ---help---
- If you wish to compile a kernel for the AT91RM9200 and enable
- ethernet support, then you should always answer Y to this.
-
 config MACB
tristate "Cadence MACB/GEM support"
depends on HAS_DMA && (PLATFORM_AT32AP || ARCH_AT91 || ARCH_PICOXCELL 
|| ARCH_ZYNQ || MICROBLAZE || COMPILE_TEST)
diff --git a/drivers/net/ethernet/cadence/Makefile 
b/drivers/net/ethernet/cadence/Makefile
index 9068b83..91f79b1 100644
--- a/drivers/net/ethernet/cadence/Makefile
+++ b/drivers/net/ethernet/cadence/Makefile
@@ -2,5 +2,4 @@
 # Makefile for the Atmel network device drivers.
 #
 
-obj-$(CONFIG_ARM_AT91_ETHER) += at91_ether.o
 obj-$(CONFIG_MACB) += macb.o
diff --git a/drivers/net/ethernet/cadence/at91_ether.c 
b/drivers/net/ethernet/cadence/at91_ether.c
deleted file mode 100644
index 7ef55f5..000
--- a/drivers/net/ethernet/cadence/at91_ether.c
+++ /dev/null
@@ -1,481 +0,0 @@
-/*
- * Ethernet driver for the Atmel AT91RM9200 (Thunder)
- *
- *  Copyright (C) 2003 SAN People (Pty) Ltd
- *
- * Based on an earlier Atmel EMAC macrocell driver by Atmel and Lineo Inc.
- * Initial version by Rick Bronson 01/11/2003
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "macb.h"
-
-/* 1518 rounded up */
-#define MAX_RBUFF_SZ   0x600
-/* max number of receive buffers */
-#define MAX_RX_DESCR   9
-
-/* Initialize and start the Receiver and Transmit subsystems */
-static int at91ether_start(struct net_device *dev)
-{
-   struct macb *lp = netdev_priv(dev);
-   dma_addr_t addr;
-   u32 ctl;
-   int i;
-
-   lp->rx_ring = dma_alloc_coherent(&lp->pdev->dev,
-(MAX_RX_DESCR *
- sizeof(struct macb_dma_desc)),
-&lp->rx_ring_dma, GFP_KERNEL);
-   if (!lp->rx_ring)
-   return -ENOMEM;
-
-   lp->rx_buffers = dma_alloc_coherent(&lp->pdev->dev,
-   MAX_RX_DESCR * MAX_RBUFF_SZ,
-   &lp->rx_buffers_dma, GFP_KERNEL);
-   if (!lp->rx_buffers) {
-   dma_free_coherent(&lp->pdev->dev,
- MAX_RX_DESCR * sizeof(struct macb_dma_desc),
- lp->rx_ring, lp->rx_ring_dma);
-   lp->rx_ring = NULL;
-   return -ENOMEM;
-   }
-
-   addr = lp->rx_buffers_dma;
-   for (i = 0; i < MAX_RX_DESCR; i++) {
-   lp->rx_ring[i].addr = addr;
-   lp->rx_ring[i].ctrl = 0;
-   addr += MAX_RBUFF_SZ;
-   }
-
-   /* Set the Wrap bit on the last descriptor */
-   lp->rx_ring[MAX_RX_DESCR - 1].addr |= MACB_BIT(RX_WRAP);
-
-   /* Reset buffer index */
-   lp->rx_tail = 0;
-
-   /* Program address of descriptor list in Rx Buffer Queue register */
-   macb_writel(lp, RBQP, lp->rx_ring_dma);
-
-   /* Enable Receive and Transmit */
-   ctl = macb_readl(lp, NCR);
-   macb_writel(lp, NCR, ctl | MACB_BIT(RE) | MACB_BIT(TE));
-
-   return 0;
-}
-
-/* Open the ethernet interface */
-static int at91ether_open(struct ne