Skip to contentSkip to conversation

net: add calxeda xgmac ethernet driver

PATCH Superseded Rob Herring 6 participants 6 messages Oct 27, 2011 – Nov 4, 2011 1 message not in the archive

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: add calxeda xgmac ethernet driver

From: Rob Herring <[email protected]>

Add support for the XGMAC 10Gb ethernet device in the Calxeda Highbank SOC.

---
 .../devicetree/bindings/net/calxeda-xgmac.txt      |   16 +
 drivers/net/Kconfig                                |    7 +
 drivers/net/Makefile                               |    1 +
 drivers/net/calxeda_xgmac.c                        | 1910 ++++++++++++++++++++
 4 files changed, 1934 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/calxeda-xgmac.txt
 create mode 100644 drivers/net/calxeda_xgmac.c
Documentation/devicetree/bindings/net/calxeda-xgmac.txt new file +16 -0
new file mode 100644
index 0000000..acc9f07
@@ -0,0 +1,16 @@
+* Calxeda Highbank 10Gb XGMAC Ethernet
+
+Required properties:
+- compatible : Should be "calxeda,hb-xgmac"
+- reg : Address and length of the register set for the device
+- interrupts : Should contain 3 xgmac interrupts. The 1st is main interrupt. 
+  The 2nd is pwr mgt interrupt. The 3rd is low power state interrupt.
+
+Example:
+
+ethernet@fff50000 {
+        compatible = "calxeda,hb-xgmac";
+        reg = <0xfff50000 0x1000>;
+        interrupts = <0 77 4  0 78 4  0 79 4>;
+};
+
drivers/net/Kconfig +7 -0
index a44874e..bb7dfe7 100644
@@ -2584,6 +2584,13 @@ if NETDEV_10000
 config MDIO
 	tristate
 
+config CALXEDA_XGMAC
+	tristate "Calxeda 1G/10G XGMAC Ethernet driver"
+	select CRC32
+	help
+	  This is the driver for the XGMAC Ethernet IP block found on Calxeda
+	  Highbank platforms.
+
 config CHELSIO_T1
 	tristate "Chelsio 10Gb Ethernet support"
 	depends on PCI
drivers/net/Makefile +1 -0
index e1eca2a..53e15af5 100644
@@ -157,6 +157,7 @@ obj-$(CONFIG_XILINX_EMACLITE) += xilinx_emaclite.o
 obj-$(CONFIG_QLA3XXX) += qla3xxx.o
 obj-$(CONFIG_QLCNIC) += qlcnic/
 obj-$(CONFIG_QLGE) += qlge/
+obj-$(CONFIG_CALXEDA_XGMAC) += calxeda_xgmac.o
 
 obj-$(CONFIG_PPP) += ppp_generic.o
 obj-$(CONFIG_PPP_ASYNC) += ppp_async.o
drivers/net/calxeda_xgmac.c new file +1910 -0

1,910 lines not on this page · raw message

Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 2 lines · Rob Herring

Add support for the XGMAC 10Gb ethernet device in the Calxeda Highbank SOC.

Hi Rob, just trivia:

Most of the logging dev_<level> messages
should be netdev_<level>

Adding #define pr_fmt KBUILD_MODNAME ": " fmt
before any #include would be useful to prefix
the module name to pr_<level> output.

drivers/net/calxeda_xgmac.c line 510

Quoted 3 lines
drivers/net/calxeda_xgmac.c new file +3 -0
+static int desc_get_tx_status(struct xgmac_extra_stats *x,
+			      struct xgmac_dma_desc *p, void __iomem *ioaddr)
+{

[]

drivers/net/calxeda_xgmac.c line 518

Quoted 4 lines
drivers/net/calxeda_xgmac.c new file +4 -0
+	if (status & TXDESC_JABBER_TIMEOUT) {
+		pr_debug("\tjabber_timeout error\n");
+		x->tx_jabber++;
+	}

Adding pr_fmt, the output would become:
calxeda_xgmac: jabber_timeout error

[]

drivers/net/calxeda_xgmac.c line 693

Quoted 4 lines
drivers/net/calxeda_xgmac.c new file +3 -0
+static void xgmac_rx_refill(struct xgmac_priv *priv)
 
+		dev_dbg(priv->device, "rx ring: head %d, tail %d\n",
+			priv->rx_head, priv->rx_tail);
	netdev_dbg(priv->dev, "rx ring: head %d, tail %d\n",
		   etc...)

[]

Review

Quoted 2 lines
(quoted diff) +2 -0
+static int xgmac_open(struct net_device *dev)
+{

[]

drivers/net/calxeda_xgmac.c line 978

Quoted 4 lines
drivers/net/calxeda_xgmac.c new file +4 -0
+	if (!is_valid_ether_addr(dev->dev_addr)) {
+		random_ether_addr(dev->dev_addr);
+		dev_dbg(priv->device, "generated random MAC address %pM\n",
+			dev->dev_addr);
		netdev_dbg(dev, "generated random MAC address %pM\n",
			   dev->dev_addr);

etc...

cheers, Joe

#2 lore raw
In reply to Rob Herring

Hi Rob,
please note that ethernet drivers moved to drivers/net/ethernet.

here are more notes:

Quoted 1 line

+#define XGMAC_ADDR_HIGH(reg)   (0x00000040+(reg * 8))

please add brackets around reg

Quoted 1 line

+#define XGMAC_ADDR_LOW(reg)    (0x00000044+(reg * 8))

ditto

drivers/net/calxeda_xgmac.c line 331

Quoted 4 lines
drivers/net/calxeda_xgmac.c new file +4 -0
+#define XGMAC_HASH(n)          (0x00000300 + (n) * 4) /* HASH table regs */
+
+struct xgmac_dma_desc {
+       u32 flags;

please use __le32 for descriptors

drivers/net/calxeda_xgmac.c line 414

Quoted 12 lines

+       u32 buf_size;
+       u32 buf1_addr;          /* Buffer 1 Address Pointer */
+       u32 buf2_addr;          /* Buffer 2 Address Pointer */
+       u32 ext_status;
+       u32 res[3];

drivers/net/calxeda_xgmac.c new file +6 -0
+};
 
+/* XGMAC Descriptor Access Helpers */
+static inline void desc_set_buf_len(struct xgmac_dma_desc *p, u32 buf_sz)
+{
+       if (buf_sz > MAX_DESC_BUF_SZ)
+               p->buf_size = MAX_DESC_BUF_SZ |

you should use cpu_to_leX when accessing descriptors

drivers/net/calxeda_xgmac.c line 472

Quoted 7 lines

+                       (buf_sz - MAX_DESC_BUF_SZ) << DESC_BUFFER2_SZ_OFFSET;

drivers/net/calxeda_xgmac.c new file +3 -0
+static inline dma_addr_t desc_get_buf_addr(struct xgmac_dma_desc *p)
+{
+       return p->buf1_addr;

1. use le32_to_cpu()
2. your assuming that dma_addr_t is the same as u32 (or __le32), this might be true in your system, but drivers should be written in generic way

drivers/net/calxeda_xgmac.c line 505

Quoted 8 lines
drivers/net/calxeda_xgmac.c new file +8 -0
+}
+
+static void xgmac_dma_flush_tx_fifo(void __iomem *ioaddr)
+{
+       u32 reg = readl(ioaddr + XGMAC_OMR);
+       writel(reg | XGMAC_OMR_FTF, ioaddr + XGMAC_OMR);
+
+       do {} while (readl(ioaddr + XGMAC_OMR) & XGMAC_OMR_FTF);

1. change this to: while (read...);
2. that can lead to infinite loop. please consider using time/counter based limit.

Quoted 4 lines
drivers/net/calxeda_xgmac.c new file +3 -0
+}
+
+
 

drivers/net/calxeda_xgmac.c line 617

Quoted 10 lines
drivers/net/calxeda_xgmac.c new file +8 -0
 
 
+static void xgmac_set_mac_addr(void __iomem *ioaddr, unsigned char *addr,
+                                   int num)
+{
+       u32 reg = 0;
+
+       memcpy(&reg, &addr[4], 2);
+       reg |= num ? XGMAC_ADDR_AE : 0;
+       writel(reg, ioaddr + XGMAC_ADDR_HIGH(num));

I think this code won't work in big endian mode

Quoted 35 lines
drivers/net/calxeda_xgmac.c new file +34 -0
+
+       memcpy(&reg, addr, sizeof(reg));
+       writel(reg, ioaddr + XGMAC_ADDR_LOW(num));
+}
+
+static void xgmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
+                                   int num)
 
+
+/**
+ * init_xgmac_dma_desc_rings - init the RX/TX descriptor rings
+ * @dev: net device structure
+ * Description:  this function initializes the DMA RX/TX descriptors
+ * and allocates the socket buffers.
+ */
+static void xgmac_dma_desc_rings_init(struct net_device *dev)
+{
+       struct xgmac_priv *priv = netdev_priv(dev);
+       unsigned int bfsize;
+
+       /* Set the Buffer size according to the MTU;
+        * indeed, in case of jumbo we need to bump-up the buffer sizes.
+        */
+       bfsize = ALIGN(dev->mtu + ETH_HLEN + ETH_FCS_LEN + NET_IP_ALIGN + 64,
+                      64);
+
+       dev_dbg(priv->device, "mtu [%d] bfsize [%d]\n", dev->mtu, bfsize);
+
+       priv->rx_skbuff = kzalloc(sizeof(struct sk_buff *) * DMA_RX_RING_SZ,
+                                 GFP_KERNEL);
+       priv->dma_rx = dma_alloc_coherent(priv->device,
+                                         DMA_RX_RING_SZ *
+                                         sizeof(struct xgmac_dma_desc),
+                                         &priv->dma_rx_phy,
+                                         GFP_KERNEL);

drivers/net/calxeda_xgmac.c line 737

Quoted 10 lines
drivers/net/calxeda_xgmac.c new file +10 -0
+       priv->tx_skbuff = kzalloc(sizeof(struct sk_buff *) * DMA_TX_RING_SZ,
+                                 GFP_KERNEL);
+       priv->dma_tx = dma_alloc_coherent(priv->device,
+                                         DMA_TX_RING_SZ *
+                                         sizeof(struct xgmac_dma_desc),
+                                         &priv->dma_tx_phy,
+                                         GFP_KERNEL);
+       if ((priv->dma_rx == NULL) || (priv->dma_tx == NULL)) {
+               dev_err(priv->device, "ERROR allocating the DMA Tx/Rx desc\n");
+               return;

the rx descs are not freed when tx desc allocation fails.
no check done for tx_skbuff/rx_skbuff allocation, consider using deem_kzalloc

Quoted 1 line

+       }

#3 lore raw
In reply to Rob Herring
Quoted 6 lines · Rob Herring

From: Rob Herring <[email protected]>

Add support for the XGMAC 10Gb ethernet device in the Calxeda Highbank SOC.

Sinker question: is this a driver for an entirely new GMAC device (designed from scratch) or is it based on an existing IP block?

Quoted 9 lines
drivers/net/calxeda_xgmac.c new file +9 -0
+/**
+ * xgmac_init - Entry point for the driver
+ * Description: This function is the entry point for the driver.
+ */
+static int __init xgmac_init(void)
+{
+       return platform_driver_register(&xgmac_driver);
+}
+module_init(xgmac_init);

drivers/net/calxeda_xgmac.c line 1906

Quoted 10 lines
drivers/net/calxeda_xgmac.c new file +10 -0
+
+/**
+ * xgmac_cleanup_module - Cleanup routine for the driver
+ * Description: This function is the cleanup routine for the driver.
+ */
+static void __exit xgmac_exit(void)
+{
+       platform_driver_unregister(&xgmac_driver);
+}
+module_exit(xgmac_exit);

You can drop some boilerplate with module_platform_driver() now.

g.

#6 lore raw
In reply to a message not in the archive

Grant,

Quoted 11 lines · Grant Likely
Quoted 6 lines · Rob Herring

From: Rob Herring <rob.herring-bsGFqQB8/[email protected]>

Add support for the XGMAC 10Gb ethernet device in the Calxeda Highbank SOC.

Sinker question: is this a driver for an entirely new GMAC device (designed from scratch) or is it based on an existing IP block?

Of course I'd rather use a existing driver. It is a new IP block.

Quoted 13 lines
Quoted 13 lines
drivers/net/calxeda_xgmac.c new file +13 -0
+/**
+ * xgmac_init - Entry point for the driver
+ * Description: This function is the entry point for the driver.
+ */
+static int __init xgmac_init(void)
+{
+       return platform_driver_register(&xgmac_driver);
+}
+module_init(xgmac_init);
+
+/**
+ * xgmac_cleanup_module - Cleanup routine for the driver
+ * Description: This function is the cleanup routine for the driver.
Quoted 8 lines

drivers/net/calxeda_xgmac.c line 1906

Quoted 6 lines

+ */

drivers/net/calxeda_xgmac.c new file +5 -0
+static void __exit xgmac_exit(void)
+{
+       platform_driver_unregister(&xgmac_driver);
+}
+module_exit(xgmac_exit);

You can drop some boilerplate with module_platform_driver() now.

Okay.

Rob